# Difference between revisions of "Expressions"

Jump to navigation
Jump to search

(→Functions: Added greaterThan and lessThan) |
(→Variables: More explanation of SEASON) |
||

(3 intermediate revisions by the same user not shown) | |||

Line 69: | Line 69: | ||

|- | |- | ||

| COUNT || COUNT.target || How many matches were made for the given target || Often used in the effect.info.aiPriority field to make give AOE attacks higher priority if they hit more targets. Also used in the [[Outcomes#Damage|Damage Outcome]] for multi-target abilities, to divide stunt chance among the targets. | | COUNT || COUNT.target || How many matches were made for the given target || Often used in the effect.info.aiPriority field to make give AOE attacks higher priority if they hit more targets. Also used in the [[Outcomes#Damage|Damage Outcome]] for multi-target abilities, to divide stunt chance among the targets. | ||

|- | |||

| EXISTS || EXISTS.target || 1 if at least one match was made for the given target, 0 otherwise || | |||

|- | |- | ||

| ASPECT_PARAM0 || self.ASPECT_PARAM0.extraDamageAspect || The value of the nth parameter || Tries to get a parameter value from an aspect on a given role. This can be done for up to a 9th parameter (ASPECT_PARAM0, ASPECT_PARAM1, etc.) | | ASPECT_PARAM0 || self.ASPECT_PARAM0.extraDamageAspect || The value of the nth parameter || Tries to get a parameter value from an aspect on a given role. This can be done for up to a 9th parameter (ASPECT_PARAM0, ASPECT_PARAM1, etc.) | ||

Line 81: | Line 83: | ||

|- | |- | ||

| TURN_NUMBER || TURN_NUMBER || The current mission turn number || | | TURN_NUMBER || TURN_NUMBER || The current mission turn number || | ||

|- | |||

| SEASON || SEASON || The current season (1=Winter, 2=Spring, 3=Summer, 4=Fall) || Generally, you'll want to do something like isMatch(SEASON, 1) to check if it's Winter | |||

|- | |||

| YEAR || YEAR || The current year || | |||

|- | |||

| DAY_OF_MONTH || DAY_OF_MONTH || day of the current season || | |||

|- | |- | ||

| distanceTo || target.distanceTo.targetTile || In a mission, the distance between two roles (can be entities or tiles) || Used to calculate the extra damage dealt from knockback attacks, and certain other edge cases like making sure the Thrixl Thrusk is still in range to attack again after its first attack (e.g. if the defender has Riposte and a knockback weapon) | | distanceTo || target.distanceTo.targetTile || In a mission, the distance between two roles (can be entities or tiles) || Used to calculate the extra damage dealt from knockback attacks, and certain other edge cases like making sure the Thrixl Thrusk is still in range to attack again after its first attack (e.g. if the defender has Riposte and a knockback weapon) | ||

Line 127: | Line 135: | ||

|- | |- | ||

| THREAT_STRENGTH_BASE || || The base threat strength, not including strength from infestations or extra chapter cards || | | THREAT_STRENGTH_BASE || || The base threat strength, not including strength from infestations or extra chapter cards || | ||

|- | |||

| THREAT_CALAMITIES || foes.THREAT_CALAMITIES || The number of calamity cards that have been drawn for the given threat. (Useful if you have an event that takes away a calamity, and you want to be sure it'll be able to) || | |||

|- | |- | ||

| raw || raw.POTENCY || The raw stat (a float, not converted to an integer) || | | raw || raw.POTENCY || The raw stat (a float, not converted to an integer) || |

## Latest revision as of 12:05, 17 November 2021

Most places that require you to enter a value (when making Effects, most commonly) do so through the use of Expressions. These can be made up of regular numbers, addition, subtraction, multiplication, and division, in addition to the functions and variables listed below.

## Functions

function | example | returns | explanation/usage |
---|---|---|---|

abs(x) | abs(-5) | 5 | The absolute value of the input value |

atan2(x, y) | atan2(1, 1)*180/3.14 | 45.02 | atan2 of the given x, y position. Good for angles! |

boolean(x) | boolean(5) | 1 | Returns 0 if the given expression evaluates to 0, 1 otherwise |

ceil(x) | ceil(2.7) | 3 | Rounds up |

floor(x) | floor(2.7) | 2 | Rounds down |

round(x) | round(2.7) | 3 | Rounds to nearest |

max(x, y, z...) | max(2, 3, 8, 6) | 8 | Returns the max of any number of parameters |

min(x, y, z...) | min(2, 3, 8, 6) | 2 | Returns the min of any number of parameters |

pow(x, e) | pow(2, 3) | 8 | Returns the first parameter to the power of the second parameter |

sqrt(x) | sqrt(16) | 4 | Returns the square root |

sin(x) | sin(3.14/2) | 1 | |

cos(x) | cos(3.14/2) | 0 | |

sign(x) | sign(5) | 1 | Returns the signum; zero if the argument is zero, 1 if the argument is greater than zero, -1 if the argument is less than zero. |

smoothstep(x) | smoothstep(0.75) | 0.84 | Given a number between 0 and 1, returns that number put into the smoothstep function (x*x*(3-2*x)) |

smootherstep(x) | smootherstep(0.75) | 0.89 | Given a number between 0 and 1, returns that number put into the smootherstep function (x*x*x*(10+x*(6*x-15))) |

isMatch(x, y, z...) | isMatch(5+2, 7) | 1 | Returns 1 if all given parameters equal the same value, 0 otherwise. |

length(x, y, [z]) | length(5, 5) | 7.071 | Returns the length (magnitude) of a given Vector2 or Vector3 |

lerp(a, b, t) | lerp(0, 100, 0.8) | 80 | Linearly interpolates between a and b by t (where t is clamped to 0 - 1), where t=0 returns a, t=1 returns b, and t=0.5 returns a value 50% of the way from a to b, etc. |

greaterThan(a, b) | greaterThan(5, 7) | 0 | Returns 1 if a is greater than b, 0 otherwise |

lessThan(a, b) | lessThan(5, 7) | 1 | Returns 1 if a is less than b, 0 otherwise |

## Variables

variable | example | returns | explanation/usage |
---|---|---|---|

EVENT_ROLL | A number between 1 and 100 | Used in choice target tests, in the Chose Outcome, generally seen together with roll_one, roll_two, roll_three, etc. expressions | |

IS_FLANKING | 1 if flanking, 0 otherwise | If this event contains attack info (e.g. a DAMAGE_ROLL, DAMAGE_ROLL_INCOMING, DAMAGE_ROLL_AFTER_ARMOR), returns whether or not the attack is flanking. | |

THIS_ASPECT | The integer value of this event's parent aspect | If this event has a parent aspect, returns the value of that aspect. | |

TOWN_POPULATION_LIMIT | The population limit for all towns (200) | ||

RECRUIT_COST_ADJUSTMENT | -1 if company size < 3, 0 if >= 3, 1 if >= 6, 2 if >= 8, 3 if >= 10 |
Adjustment for recruit cost based on company size. This is used to make recruits cheaper if you have fewer of them, and more expensive if you have more. | |

RECRUIT_ENCOUNTER_SCORE_OFFSET | If chapter 1, returns 0.5 if company size=3, 2 if size=2, 4 if size=1. If chapter > 1, returns 0.5 if company size=4, 2 if size=3, 4 if size=2, 9 if size=1. Returns 0 otherwise. |
An offset for recruit encounters that makes it so the encounter is more likely to happen if you have a smaller company. This is used in events that give you recruits. | |

isDefender | isDefender.hero | 1 if the given role is the current defender of an AttackRoll Outcome, 0 otherwise | Generally used if you want different damage for one enemy in an attack than for others. (See how fireleash works, dealing half damage to defenders that aren't on the target tile) |

RESOURCE | RESOURCE.legacyPoints | The amount of the given resource | Can be used to find the amount of any resource: legacyPoints, heartwoods, hides, ingots, fabrics, and spellthreads |

COUNT | COUNT.target | How many matches were made for the given target | Often used in the effect.info.aiPriority field to make give AOE attacks higher priority if they hit more targets. Also used in the Damage Outcome for multi-target abilities, to divide stunt chance among the targets. |

EXISTS | EXISTS.target | 1 if at least one match was made for the given target, 0 otherwise | |

ASPECT_PARAM0 | self.ASPECT_PARAM0.extraDamageAspect | The value of the nth parameter | Tries to get a parameter value from an aspect on a given role. This can be done for up to a 9th parameter (ASPECT_PARAM0, ASPECT_PARAM1, etc.) |

ITEM_CATEGORY | weapon.ITEM_CATEGORY.bow | 1 if the given item is of the given category (bow, sword, spear, etc), 0 otherwise | |

WEAPON_TIER | WEAPON_TIER.weapon | The tier of the given weapon, or -1 if there isn't one or it isn't a weapon | |

hasItem | hero.hasItem.spearBone | 1 if the given role has (or is) an item with the given item id, 0 otherwise | |

canEquip | hero.canEquip.item | 1 if the given role can equip the second role, 0 otherwise | |

TURN_NUMBER | TURN_NUMBER | The current mission turn number | |

SEASON | SEASON | The current season (1=Winter, 2=Spring, 3=Summer, 4=Fall) | Generally, you'll want to do something like isMatch(SEASON, 1) to check if it's Winter |

YEAR | YEAR | The current year | |

DAY_OF_MONTH | DAY_OF_MONTH | day of the current season | |

distanceTo | target.distanceTo.targetTile | In a mission, the distance between two roles (can be entities or tiles) | Used to calculate the extra damage dealt from knockback attacks, and certain other edge cases like making sure the Thrixl Thrusk is still in range to attack again after its first attack (e.g. if the defender has Riposte and a knockback weapon) |

ticksPerTurn | 2 | Used along with timeCostPerStep for movement abilities | |

SIZE | source.SIZE | Number of tiles a mission entity takes up, or its max footprint dimension | Used in Splinterblast to give larger objects greater AOE |

AGE_IN_YEARS | The age of the current target. | ||

MIN_ATTACK_RANGE | self.MIN_ATTACK_RANGE | The minimum range at which the given target can attack. | Used for movement abilities to determine whether to show the dotted-line attack suggestion. |

MAX_ATTACK_RANGE | self.MAX_ATTACK_RANGE | The maximum range at which the given target can attack. | Used for movement abilities to determine whether to show the dotted-line attack suggestion. |

MAX_MELEE_ATTACK_RANGE | self.MAX_MELEE_ATTACK_RANGE | The maximum range at which the given target can melee attack. | Used for guarding abilities to show range feedback. |

maxValue | self.maxValue.gorgonCorruptedTileRel | The maximum value of any aspects the given target has starting with the given string | |

totalValue | self.totalValue.myParameterizedAspect | The total value of any aspects the given target has starting with the given string | |

HAS_FRIEND | 1 if the current target has a friend, 0 otherwise | Used in events when we want to match a target that has a friend | |

HAS_LOVER | 1 if the current target has a lover, 0 otherwise | Used in events when we want to match a target that has a lover | |

HAS_RIVAL | 1 if the current target has a rival, 0 otherwise | Used in events when we want to match a target that has a rival | |

HAS_FAMILY | 1 if the current target has family (a parent, child, grandparent, etc), 0 otherwise | ||

HAS_PARENT | 1 if the current target has a parent, 0 otherwise | ||

HAS_CHILD | 1 if the current target has a child, 0 otherwise | ||

HAS_SIBLING | 1 if the current target has a sibling, 0 otherwise | ||

CAN_FORM_ROMANCE | 1 if the current target can form a romance (no existing lover, no npc lover, not a skeleton, doesn't have random romances disabled), 0 otherwise | ||

LEVEL | self.LEVEL | The level of the given hero target, or 0 if none | Generally used in abilities when we want the ability's power to scale with level |

THREAT_STRENGTH | foes.THREAT_STRENGTH | The full "strength", or number of cards, of a threat | Used to show threat strength in attackSite blurb |

THREAT_STRENGTH_FROM_INFESTATION | The strength being added to a threat from infested tiles | ||

THREAT_STRENGTH_FROM_EXTRA_CHAPTER_CARDS | The strength being added to a threat from extra chapter cards, added during the interval | ||

THREAT_STRENGTH_FROM_INCURSION_SIZE | The strength being added to a threat from the incursion size | ||

THREAT_STRENGTH_BASE | The base threat strength, not including strength from infestations or extra chapter cards | ||

THREAT_CALAMITIES | foes.THREAT_CALAMITIES | The number of calamity cards that have been drawn for the given threat. (Useful if you have an event that takes away a calamity, and you want to be sure it'll be able to) | |

raw | raw.POTENCY | The raw stat (a float, not converted to an integer) | |

CAN_ROMANCE | CAN_ROMANCE.hook | 1 if the current target can romance the given target, 0 otherwise | Must be mutually attracted, not already have lovers, and non-family |

CAN_RIVAL | CAN_RIVAL.hook | 1 if the current target can be rivals with the given target, 0 otherwise | Must not already have rivals |

SHIP_WITH | SHIP_WITH.hook | The tier of the relationship between the current target and the given target | This can be any kind of relationship; lovers, rivals, or friends |

FRIEND_WITH | FRIEND_WITH.hook | The tier of the friendship between the current target and the given target, 0 if not friends | |

LOVER_WITH | LOVER_WITH.hook | The tier of the romance between the current target and the given target, 0 if not lovers | |

RIVAL_WITH | RIVAL_WITH.hook | The tier of the rivalry between the current target and the given target, 0 if not rivals | |

FAMILY_WITH | FAMILY_WITH.hook | 1 if the current target is family with the given target, 0 otherwise | |

PARENT_OF | PARENT_OF.hook | 1 if the current target is the parent of the given target, 0 otherwise | |

CHILD_OF | CHILD_OF.hook | 1 if the current target is the child of the given target, 0 otherwise | |

SIBLING_OF | SIBLING_OF.hook | 1 if the current target is a sibling of the given target, 0 otherwise | |

NOT_FAMILY_WITH | NOT_FAMILY_WITH.hook | 0 if the current target is family with the given target, 1 otherwise. | NOT_FAMILY_WITH.hook is equivalent to (1 - FAMILY_WITH.hook) |