# Engine test: modifiers applied layer by layer (static modifiers, a content item's modifier that
# is active only while equipped, a temporary modifier that expires on an event, and layer 0).
game: modifiers
label: Modifiers (test)
num_players: 1
mode: competitive
description: >
  Test game for modifiers. The attack value (base 3) passes through four layers: 1 curse sets it
  to 1; 2 strength +2 (plus sword +1 and a temporary bonus +3); 3 doubling; 4 a cap of 20. They are
  deliberately listed in a different order in the model; the engine must follow the layers. Each
  `measure` appends the current value to `log`.
constants: {BASE: 3}
state:
  vars:
    curse: {scope: global, type: bool, init: false}
    log: {scope: global, type: list, init_x: "[]"}
  zones:
    equipment: {kind: set, owner: global, visibility: public}
modifiers:
  - {id: double, source: rule, stat: attack, layer: 3, change: "×2", change_x: "value * 2"}
  - {id: cap, source: rule, stat: attack, layer: 4, change: "at most 20", change_x: "min(value, 20)"}
  - {id: curse, source: curse, stat: attack, layer: 1, if_x: "curse", change: "becomes 1", change_x: "1"}
  - {id: strength, source: rule, stat: attack, layer: 2, change: "+2", change_x: "value + 2"}
content:
  equipment:
    sword:
      id: sword
      label: Sword
      status: verified
      active_x: "'sword' in equipment"
      modifiers: [{stat: attack, layer: 2, change: "+1", change_x: "value + 1"}]
flow:
  id: root
  kind: sequence
  children:
    - {id: m1, kind: step, do: measure}
    - {id: s2, kind: step, do: apply_curse}
    - {id: m2, kind: step, do: measure}
    - {id: s3, kind: step, do: take_sword}
    - {id: m3, kind: step, do: measure}
    - {id: s4, kind: step, do: lift_curse_and_bonus}
    - {id: m4, kind: step, do: measure}
    - {id: s5, kind: step, do: end_of_round}
    - {id: m5, kind: step, do: measure}
    - {id: s6, kind: step, do: big_bonus}
    - {id: m6, kind: step, do: measure}
actions:
  measure: {effect: [{op: set, var: log, value_x: "log + [modified('attack', BASE)]"}]}
  apply_curse: {effect: [{op: set, var: curse, value: true}]}
  take_sword: {effect: [{op: create, what: sword, what_x: "'sword'", to: equipment}]}
  lift_curse_and_bonus:
    effect:
      - {op: set, var: curse, value: false}
      - {op: modify, stat: attack, layer: 2, change: "+3 until end of round", change_x: "value + 3", until: end_of_round}
  end_of_round: {effect: [{op: emit, event: end_of_round}]}
  big_bonus: {effect: [{op: modify, stat: attack, layer: 0, change: "+10 before everything else", change_x: "value + 10"}]}
end:
  - {id: done, if_x: "len(log) == 6", result: score, returns_x: "[log[-1]]"}
