Difference between revisions of "Modding:Game state queries"
Pathoschild (talk | contribs) (remove repeat info in overview, group format sections) |
Pathoschild (talk | contribs) (→Overview: + Queries versus Content Patcher conditions) |
||
Line 15: | Line 15: | ||
You can add quotes to keep spaces within an argument. For example, <code>BUILDINGS_CONSTRUCTED Here "Junimo Hut"</code> passes <code>Junimo Hut</code> as one argument. You can escape inner quotes with backslashes like <code>ANY "BUILDINGS_CONSTRUCTED Here \"Junimo Hut\""</code>. Remember that quotes and backslashes inside JSON strings need to be escaped too, like <code>"Condition": "BUILDINGS_CONSTRUCTED Here \"Junimo Hut\""</code>. | You can add quotes to keep spaces within an argument. For example, <code>BUILDINGS_CONSTRUCTED Here "Junimo Hut"</code> passes <code>Junimo Hut</code> as one argument. You can escape inner quotes with backslashes like <code>ANY "BUILDINGS_CONSTRUCTED Here \"Junimo Hut\""</code>. Remember that quotes and backslashes inside JSON strings need to be escaped too, like <code>"Condition": "BUILDINGS_CONSTRUCTED Here \"Junimo Hut\""</code>. | ||
+ | |||
+ | ===Queries versus Content Patcher conditions=== | ||
+ | [[Modding:Content Patcher|Content Patcher packs]] can have conditions using either game state queries or Content Patcher's <samp>When</samp> conditions. | ||
+ | |||
+ | Which you use is mainly a performance tradeoff: | ||
+ | * Content Patcher's <samp>When</samp> conditions are highly optimized and cached, so thousands of patches can check the same condition without impacting performance and the resulting changes are written once to the asset. Then there's no performance impact after the asset edit, since it's just plain unconditional data. However the asset is reloaded when patches are added/removed, which may impact performance if they change often in some cases (like reloading a map or indoor/outdoor NPC appearance). | ||
+ | * A game state query has no caching, so it can significantly affect performance when it's checked often. For example, a thousand game state queries checked each update tick means sixty thousand condition evaluations per second. On the other hand, game state queries are faster in cases where the conditions are checked rarely and doing so avoids reloading textures or maps (like <samp>ChooseAppearance</samp> in <samp>Data/Characters</samp> or <samp>Music</samp> in <samp>Data/Locations</samp>). | ||
==Built-in queries== | ==Built-in queries== |
Revision as of 22:48, 4 November 2023
← Index
This page documents game state queries, a built-in way to specify conditions in some of the game's data assets inspired by Content Patcher's conditions.
Overview
Query format
A query consists of a comma-delimited list of conditions in the form <type>
[arguments]
. The type can be prefixed with !
to negate it. The query is true if it's null/blank, or if every listed condition exists and is true. For example, !SEASON Spring, WEATHER Here Sun
is true on sunny non-spring days.
⚠ Game state queries are partly case-sensitive. While some values are case-insensitive (e.g. both SEASON Spring
and SEASON spring
will work), this isn't consistent. Using the exact capitalization is recommended to avoid issues.
Argument format
Game state queries take space-delimited arguments. For example, BUILDINGS_CONSTRUCTED Here Cabins
has two arguments: Here
and Cabins
.
You can add quotes to keep spaces within an argument. For example, BUILDINGS_CONSTRUCTED Here "Junimo Hut"
passes Junimo Hut
as one argument. You can escape inner quotes with backslashes like ANY "BUILDINGS_CONSTRUCTED Here \"Junimo Hut\""
. Remember that quotes and backslashes inside JSON strings need to be escaped too, like "Condition": "BUILDINGS_CONSTRUCTED Here \"Junimo Hut\""
.
Queries versus Content Patcher conditions
Content Patcher packs can have conditions using either game state queries or Content Patcher's When conditions.
Which you use is mainly a performance tradeoff:
- Content Patcher's When conditions are highly optimized and cached, so thousands of patches can check the same condition without impacting performance and the resulting changes are written once to the asset. Then there's no performance impact after the asset edit, since it's just plain unconditional data. However the asset is reloaded when patches are added/removed, which may impact performance if they change often in some cases (like reloading a map or indoor/outdoor NPC appearance).
- A game state query has no caching, so it can significantly affect performance when it's checked often. For example, a thousand game state queries checked each update tick means sixty thousand condition evaluations per second. On the other hand, game state queries are faster in cases where the conditions are checked rarely and doing so avoids reloading textures or maps (like ChooseAppearance in Data/Characters or Music in Data/Locations).
Built-in queries
Meta
Condition | effect |
---|---|
ANY <query> +
|
Get whether at least one of the listed game state queries match, where each argument is a query. For example, ANY "SEASON Winter" "SEASON Spring, DAY_OF_WEEK Friday" is true if (a) it's winter or (b) it's a spring Friday. You can list any number of queries to check.
|
Date & time
Condition | effect |
---|---|
DAY_OF_MONTH <day> +
|
The day of month. This can be an integer between 1 and 28, or even/odd to match on any even/odd day. You can specify multiple values to match any of them. |
DAY_OF_WEEK <day> +
|
The day of week. This can be an integer between 0 (Sunday) and 6 (Saturday), three-letter English name (like Fri), or full English name (like Friday). You can specify multiple values to match any of them (like DAY_OF_WEEK Monday Tuesday for Monday or Tuesday). |
DAYS_PLAYED <min> [max]
|
Whether <min> to [max] (default unlimited) days have been played in the current save (including the current one). This always increments in sync with the date in the base game, but when mods change the in-game date, they may or may not update this value.
|
IS_FESTIVAL_DAY [day offset]
|
Whether there's a festival today, with an optional [day offset] (e.g. 1 for tomorrow).
|
IS_PASSIVE_FESTIVAL_OPEN <id>
|
Whether a passive festival with the given ID is active today, and the current time is within its opening hours. |
IS_PASSIVE_FESTIVAL_TODAY <id>
|
Whether a passive festival with the given ID is active today. |
SEASON <season> +
|
The season (one of spring, summer, fall, or winter). You can specify multiple values to match any of them (like SEASON spring summer for spring or summer). |
SEASON_DAY [<season> <day> ]+
|
The season (in the same format as SEASON) and day (an integer between 1 and 28). You can specify multiple values to match any of them (like SEASON_DAY fall 15 winter 20 for fall 15 or winter 20). |
TIME <min> [max]
|
Whether the current time is between <min> and [max] (default unlimited) inclusively, specified in 26-hour time.
|
YEAR <min> [max]
|
Whether the current year is between <min> and [max] (default unlimited) inclusively.
|
Events
Condition | effect |
---|---|
EVENT_ID <event ID> +
|
Whether one of the the given event IDs are currently playing. |
World
Condition | effect | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
BUILDINGS_CONSTRUCTED <locations> [building type] [min] [max] [count unbuilt]
|
Whether the number of matching buildings is within a range.
For example:
Arguments:
| ||||||||||||||||||||||||||
CAN_BUILD_CABIN | Whether players can build more cabins (i.e. they haven't reached the maximum number of player slots yet). | ||||||||||||||||||||||||||
CAN_BUILD_FOR_CABINS <building ID>
|
Whether there are fewer of the given building constructed than there are cabins. | ||||||||||||||||||||||||||
FARM_CAVE <type>
|
The current farm cave (one of Bats, Mushrooms, or None). | ||||||||||||||||||||||||||
FARM_NAME <name>
|
The name of the farm. | ||||||||||||||||||||||||||
FARM_TYPE <type>
|
The farm type. The <type> can be one of...
| ||||||||||||||||||||||||||
FOUND_ALL_LOST_BOOKS | Whether all the Lost Books for the museum have been found. | ||||||||||||||||||||||||||
IS_COMMUNITY_CENTER_COMPLETE | Whether the community center has been repaired. | ||||||||||||||||||||||||||
IS_CUSTOM_FARM_TYPE | Whether the farm type is a custom one created by a mod. (This returns false for mods which edit/replace a vanilla farm type.) | ||||||||||||||||||||||||||
IS_HOST | Whether the current player is the main/host player. | ||||||||||||||||||||||||||
IS_ISLAND_NORTH_BRIDGE_FIXED | Whether the North Ginger Island bridge to the dig site has been repaired. | ||||||||||||||||||||||||||
IS_JOJA_MART_COMPLETE | Whether the Joja warehouse has been built. | ||||||||||||||||||||||||||
IS_MULTIPLAYER | Whether the game is currently in multiplayer mode (regardless of whether there's multiple players connected). | ||||||||||||||||||||||||||
IS_VISITING_ISLAND <name>
|
Whether the named NPC is visiting Ginger Island today. | ||||||||||||||||||||||||||
LOCATION_ACCESSIBLE <name>
|
Whether the given location is accessible. For vanilla locations, this is relevant to CommunityCenter, JojaMart, or Railroad; any other location will return true unless a mod customizes the query. | ||||||||||||||||||||||||||
LOCATION_CONTEXT <location>
|
The location context name for the given location. | ||||||||||||||||||||||||||
LOCATION_IS_INDOORS <location> LOCATION_IS_OUTDOORS <location> LOCATION_IS_MINES <location> LOCATION_IS_SKULL_CAVE <location>
|
Whether the given location is indoors, outdoors, in the mines, or in the Skull Cavern. | ||||||||||||||||||||||||||
LOCATION_NAME <location> <name> LOCATION_UNIQUE_NAME <location> <name>
|
Whether the given location has the specified name or unique instanced name (you can see both names in-game using the Debug Mode mod). | ||||||||||||||||||||||||||
LOCATION_SEASON <location> [<season> ]+
|
Whether the given location is in one of the given seasons (which can be spring, summer, fall, or winter). This accounts for the SeasonOverride field in the location's context data.
For example, this is valid in spring or summer: | ||||||||||||||||||||||||||
MUSEUM_DONATIONS <min count> [max count] [object type] +
|
Whether all players have donated a total of <min count> to [max count] (default unlimited) inclusively to the museum. This can optionally be filtered by the object type field, like MUSEUM_DONATIONS 40 Arch Minerals to require at least 40 artifacts and minerals combined. You can omit the max count and still specify a filter.
| ||||||||||||||||||||||||||
WEATHER <location> <weather>
|
The weather ID in the given location. The weather can be one of Festival, Rain, Snow, Storm, Sun, Wind, or a custom weather ID. | ||||||||||||||||||||||||||
WORLD_STATE_FIELD <name> <value>
|
Whether a property on Game1.netWorldState has the given value. If the property is numeric, this is the minimum value. Some useful values not covered by their own query:
For example, the Traveling Cart shop uses a | ||||||||||||||||||||||||||
WORLD_STATE_FIELD <name> <min> [max]
|
For numeric properties only, whether a property on Game1.netWorldState has a value between <min> and [max] (default unlimited). If [max] is omitted or the properties isn't numeric, the previous form is used. See the previous entry for a list of useful properties.
| ||||||||||||||||||||||||||
WORLD_STATE_ID <id>
|
Whether any world state flag with the given <id> is set.
|
Player info & progress
Condition | effect | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
MINE_LOWEST_LEVEL_REACHED <min> [max]
|
Whether any player has reached a level between <min> and [max] (default unlimited) inclusively in the mines.
| ||||||||||
PLAYER_COMBAT_LEVEL <player> <min> [max] PLAYER_FARMING_LEVEL <player> <min> [max] PLAYER_FISHING_LEVEL <player> <min> [max] PLAYER_FORAGING_LEVEL <player> <min> [max] PLAYER_LUCK_LEVEL <player> <min> [max] PLAYER_MINING_LEVEL <player> <min> [max]
|
Whether the specified player(s) have a skill level between <min> and [max] (default unlimited) inclusively, including the effects of buffs which raise them.
| ||||||||||
PLAYER_CURRENT_MONEY <player> <min> [max]
|
Whether the specified player(s) have between <min> and [max] (default unlimited) gold inclusively.
| ||||||||||
PLAYER_FARMHOUSE_UPGRADE <player> <min> [max]
|
Whether the specified player(s) have upgraded their farmhouse or cabin to a level between <min> and [max] (default unlimited) inclusively. See possible levels.
| ||||||||||
PLAYER_GENDER <player> <gender>
|
Whether the specified player(s) are Male or Female. | ||||||||||
PLAYER_HAS_ACHIEVEMENT <player> <achievement id>
|
Whether the specified player(s) have unlocked a specific achievement ID. The valid IDs are listed in Data/Achievements, plus a few Steam achievement IDs that aren't listed. | ||||||||||
PLAYER_HAS_ALL_ACHIEVEMENTS <player>
|
Whether the specified player(s) have unlocked every achievement listed in Data/Achievements. This doesn't count the extra Steam achievement IDs that aren't listed in that file. | ||||||||||
PLAYER_HAS_CAUGHT_FISH <player> <id>
|
Whether the specified player(s) have caught at least one fish with the given ID. | ||||||||||
PLAYER_HAS_CONVERSATION_TOPIC <player> <id>
|
Whether the specified player(s) have a conversation topic with the ID <id> active.
| ||||||||||
PLAYER_HAS_CRAFTING_RECIPE <player> <recipe name> PLAYER_HAS_COOKING_RECIPE <player> <recipe name>
|
Whether the specified player(s) know the crafting/cooking recipe identified by its internal name (spaces allowed). For example, PLAYER_HAS_CRAFTING_RECIPE Current Field Snack .
| ||||||||||
PLAYER_HAS_DIALOGUE_ANSWER <player> <id>
|
Whether the specified player(s) have chosen the given dialogue answer in a previous dialogue. | ||||||||||
PLAYER_HAS_FLAG <player> <id>
|
Whether the specified player(s) have the given mail flag set (with spaces allowed in the <id> ).
| ||||||||||
PLAYER_HAS_ITEM <player> <item> [min] [max]
|
Whether the specified player(s) have between [min] and [max] (default unlimited) matching items in their inventory, inclusively. The <item> can be 858 or (O)858 (Qi Gems), 73 or (O)73 (Walnuts), or the qualified or unqualified item ID.
| ||||||||||
PLAYER_HAS_PROFESSION <player> <profession id>
|
Whether the specified player(s) have the given profession ID. | ||||||||||
PLAYER_HAS_READ_LETTER <player> <id>
|
Whether the specified player(s) have read a letter, where <id> is the internal mail ID (spaces allowed). For example, PLAYER_HAS_READ_LETTER Any Visited_Island .
| ||||||||||
PLAYER_HAS_SECRET_NOTE <player> <id>
|
Whether the specified player(s) have read a secret note, where <id> is the secret note's integer ID.
| ||||||||||
PLAYER_HAS_SEEN_EVENT <player> <id>
|
Whether the specified player(s) have seen the event with given <id> .
| ||||||||||
PLAYER_HAS_TOWN_KEY <player>
|
Whether the specified player(s) have the town key. | ||||||||||
PLAYER_HAS_TRASH_CAN_LEVEL <player> <min> [max]
|
Whether the specified player(s) have a trash can upgrade level between <min> and [max] (default unlimited) inclusively. The <level> can be 0 (base), 1 (copper), 2 (steel), 3 (gold), or 4 (iridium).
| ||||||||||
PLAYER_LOCATION_CONTEXT <player> <location context>
|
Whether the specified player(s) are in the given location context. | ||||||||||
PLAYER_LOCATION_NAME <player> <location name> PLAYER_LOCATION_UNIQUE_NAME <player> <location name>
|
Whether the specified player(s) are in the given location, using the name or unique instanced name (you can see both names in-game using the Debug Mode mod). The <location name> value doesn't recognize target location keywords like Here.
| ||||||||||
PLAYER_MOD_DATA <player> <key> <value>
|
Whether the specified player(s) have a player.modData entry added by a mod with the given <key> and <value> .
| ||||||||||
PLAYER_MONEY_EARNED <player> <min> [max]
|
Whether the specified player(s) have earned between <min> and [max] (default unlimited) gold inclusively.
| ||||||||||
PLAYER_SHIPPED_BASIC_ITEM <player> <item ID> [min count] [max count]
|
Whether the specified player(s) have shipped the given item between [min count] (default 1) and [max count] (default unlimited) times inclusively. This only works for the items tracked by the game for shipping stats (shown in the shipping collections menu).
| ||||||||||
PLAYER_SPECIAL_ORDER_ACTIVE <player> <order id>
|
Whether the specified player(s) have the given special order active. | ||||||||||
PLAYER_SPECIAL_ORDER_RULE_ACTIVE <player> <rule id>
|
Whether the specified player(s) have a special rule active for a special order. Some vanilla rules are...
| ||||||||||
PLAYER_STAT <player> <stat name> <min value> [max value]
|
Whether a stat counter for the specified player(s) has a value between <min value> and [max value] (default unlimited) inclusively. The available stat names are...
|
Player relationships
Condition | effect |
---|---|
PLAYER_HAS_CHILDREN <player> [min] [max]
|
Whether the specified player(s) have a number of children between [min] (default 1) and [max] (default unlimited) inclusively.
|
PLAYER_HAS_PET <player>
|
Whether the specified player(s) have a pet. |
PLAYER_HEARTS <player> <npc> <min hearts> [max hearts]
|
Whether the specified player(s) have a friend with a friendship level between <min hearts> and [max hearts] (default unlimited) inclusively. The <npc> can be an NPC's internal name, Any (check every NPC), or AnyDateable (check every romanceable NPC).
|
PLAYER_HAS_MET <player> <npc>
|
Whether the specified player(s) have talked to an NPC at least once. The <npc> is an NPC's internal name.
|
PLAYER_IS_DATING <player> <npc> PLAYER_IS_ENGAGED <player> <target> PLAYER_IS_MARRIED <player> <target> PLAYER_IS_DIVORCED <player> <npc>
|
Whether the specified player(s) have this relationship status with an NPC. The player is dating after giving the NPC a bouquet, and engaged after giving a Mermaid's Pendant but before the marriage. The <npc> can be an NPC's internal name, or Any (check every romanceable NPC).
|
PLAYER_IS_ROOMMATE <player> <target>
|
Whether the specified player(s) have a roommate. The <target> can be an NPC's internal name, Any (with any NPC), or Player (always false).
|
PLAYER_PREFERRED_PET <player> <pet>
|
Whether the preferred pet for the specified player(s) is Cat, Dog, or a specified custom pet type. |
Randomization
Condition | effect |
---|---|
RANDOM <chance> [@addDailyLuck]
|
A random probability check which is re-rolled each time it's called. For example, RANDOM 0.4 is true 40% of the time.
If the exact text @addDailyLuck is specified, the current player's daily luck is added to the probability. |
SYNCED_CHOICE <interval> <key> <min> <max> <choices> +
|
Choose a random integer between <min> and <max> inclusively, and check whether it matches one of the <choices> . The result will be identical for all queries with the same <key> value during the given <interval> (one of tick, day, season, or year), including between players in multiplayer mode.
For example, SYNCED_CHOICE day example_key 1 5 1 2 chooses a random value between 1 and 5, and checks if it's either 1 or 2. This is mainly useful in cases where you need to pick between a number of discrete cases. For regular probability checks, see SYNCED_RANDOM instead. |
SYNCED_RANDOM <interval> <key> <chance> [@addDailyLuck]
|
A random probability check. The result will be identical for all queries with the same <key> value during the given <interval> (one of tick, day, season, or year), including between players in multiplayer mode.
For example, SYNCED_RANDOM day cart_rare_seed 0.4 has a 40% chance to be true the first time it's called that day, and will always be the same value if called again with the same key on the same day. If the exact text @addDailyLuck is specified, the current player's daily luck is added to the probability. |
SYNCED_SUMMER_RAIN_RANDOM <base chance> <day multiplier>
|
A specialized variant of SYNCED_DAY_RANDOM used to calculate the chance of rain in summer, which increases with the day number. |
For items only
These queries apply in cases where there's an item (e.g. machine recipes, shops, etc); they'll return false if not applicable. They take a <type>
argument which can be Input (the machine input item) or Target (the machine output, tree fruit, shop item, etc).
Condition | effect |
---|---|
ITEM_HAS_EDIBILITY <target> [min] [max]
|
Whether the item's edibility is between [min] (default -299) and [max] (default unlimited) inclusively. A value of -300 is inedible, so ITEM_HAS_EDIBILITY <target> without min/max values checks if the item is edible.
|
ITEM_HAS_TAG <target> <tags>
|
Whether the item has all of the given space-delimited tags. For example, ITEM_HAS_TAG Target bone_item marine_item will only match items with both tags.
|
ITEM_ID <target> <item ID>
|
Whether the item has the given qualified or unqualified item ID. The item ID is qualified before checking, so 128 will match pufferfish ((O)128) but not mushroom boxes ((BC)128). |
ITEM_QUALITY <target> <min> [max]
|
Whether the item's quality is between <min> and [max] (default unlimited) inclusively. The possible values are 0 (normal), 1 (silver), 2 (gold), or 4 (iridium).
|
ITEM_STACK <target> <min> [max]
|
Whether the item stack size is between <min> and [max] (default unlimited) inclusively. Note that this only applies to the target item, it doesn't include other stacks in the inventory.
|
ITEM_TYPE <target> <type>
|
Whether the item's type definition ID matches the given value. For example, ITEM_TYPE Target (BC) matches bigcraftables. |
Immutable
Condition | effect |
---|---|
TRUE | A condition which always matches. |
FALSE | A condition which never matches. |
Common values
Target location
Some conditions have a <location>
argument. This can be one of...
value | result |
---|---|
Here | The location containing the current player (regardless of the target player). |
Target | The location containing the in-game entity being edited (e.g. the machine for Data/Machines or fruit tree for Data/FruitTrees).
If the asset being edited isn't tied to a location, this is the location of the target player (if set), else equivalent to Here. |
any other | The location ID (i.e. internal name) for the location to check. |
Target player
Some conditions have a <player>
argument. This can be one of...
value | result | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Any | At least one player must match the condition, regardless of whether they're online. | ||||||||||||
All | Every player must match the condition, regardless of whether they're online. | ||||||||||||
Current | The local player. | ||||||||||||
Host | The main player. | ||||||||||||
Target | This value depends on the context:
| ||||||||||||
any other | The unique multiplayer ID for the player to check. |
For C# mod authors
Using queries elsewhere
C# code can use the GameStateQuery class to work with queries, like GameStateQuery.CheckConditions(query)
.
You can also use game state queries in event preconditions using the new G condition flag, like some_event_id/G !SEASON Spring, WEATHER Here Sun
.
Extensibility
C# mods can check if a query exists using GameStateQuery.Exists("Example.ModId_ConditionName")
, and define custom conditions using GameStateQuery.Register("Example.ModId_ConditionName", handleQueryMethod)
. To avoid conflicts, prefixing custom condition names with your mod ID is strongly recommended.