Files
aetherbound-guild/runtime/tests/battle/status_test.gd
T

179 lines
8.3 KiB
GDScript

extends SceneTree
## M80-B4 gate (slice 4): the status clock. Verifies that a declared status is
## applied deterministically, that a low chance resists and changes nothing,
## that expiry fires the section-17 `on_status_expire` hook, and that the
## status-reading priority conditions follow the state.
const Simulation = preload("res://domain/battle_simulation.gd")
var failures: Array[String] = []
func _initialize() -> void:
call_deferred("_run")
func _run() -> void:
_verify_applied_and_expired()
_verify_resist_path()
_verify_hook_fires()
_verify_conditions_follow_state()
_verify_tag_mirror()
_verify_cleanse_share()
if failures.is_empty():
print("ABG_M80_STATUS_OK applied=true resisted=true expired=true hook=fires conditions=follow mirror=once cleanse=shared determinism=true")
quit(0)
return
for failure in failures:
push_error("M80-B4 status: %s" % failure)
quit(1)
func _verify_tag_mirror() -> void:
# EQ-148: the first tag that lands on the wearer is mirrored onto the nearest
# opponent with the opposite sign, once.
var strike := {"id": "strike", "base": 4, "coefficient": 1.0, "kind": "damage", "reach": 1,
"target": "frontmost", "power_source": "physical_power"}
var wearer: Dictionary = _actor("ally-0", 0, strike, {
"equipment_hooks": [{"hook": "on_status_apply", "implemented": true,
"effect": {"kind": "tag_copy", "value": 1, "scope": "test"}}]})
var foe: Dictionary = _actor("enemy-0", 0, strike, {"profession_base_hp": 3000})
var simulation: ABGBattleSimulation = Simulation.new()
simulation.setup("mirror", [wearer], [foe])
simulation._apply_status(simulation.allies[0], simulation.enemies[0],
{"id": "tagged", "sign": "hindrance", "ticks": 20, "chance_bp": 10000}, {})
var mirrored := 0
var reflected_sign := ""
for record in simulation.journal:
var entry: Dictionary = Dictionary(record)
if str(entry.get("kind", "")) == "tag_mirror":
mirrored += 1
reflected_sign = str(entry.get("sign", ""))
_expect(mirrored == 1 and reflected_sign == "boon",
"the wearer's first incoming tag is mirrored once with the opposite sign (count=%d sign=%s)" % [mirrored, reflected_sign])
simulation._apply_status(simulation.allies[0], simulation.enemies[0],
{"id": "tagged", "sign": "hindrance", "ticks": 20, "chance_bp": 10000}, {})
var again := 0
for record in simulation.journal:
if str(Dictionary(record).get("kind", "")) == "tag_mirror":
again += 1
_expect(again == 1, "a spent tag-copy row stops mirroring (count=%d)" % again)
func _verify_cleanse_share() -> void:
# EQ-154: the opposing wearer sheds its oldest hindrance when the enemy
# cleanses, once per battle.
var strike := {"id": "strike", "base": 4, "coefficient": 1.0, "kind": "damage", "reach": 1,
"target": "frontmost", "power_source": "physical_power"}
var wearer: Dictionary = _actor("ally-0", 0, strike, {
"equipment_hooks": [{"hook": "on_status_expire", "implemented": true,
"effect": {"kind": "cleanse_share", "value": 1, "scope": "test"}}]})
var foe: Dictionary = _actor("enemy-0", 0, strike, {"profession_base_hp": 3000})
var simulation: ABGBattleSimulation = Simulation.new()
simulation.setup("share", [wearer], [foe])
simulation._apply_status(simulation.allies[0], simulation.enemies[0],
{"id": "tagged", "sign": "hindrance", "ticks": 20, "chance_bp": 10000}, {})
simulation._cleanse(simulation.enemies[0], simulation.enemies[0], {})
var shared := 0
for record in simulation.journal:
var entry: Dictionary = Dictionary(record)
if not str(entry.get("shared_from", "")).is_empty():
shared += 1
_expect(shared == 1 and Array(simulation.allies[0].statuses).is_empty(),
"an enemy cleanse sheds the wearer's oldest hindrance once (shared=%d left=%d)"
% [shared, Array(simulation.allies[0].statuses).size()])
simulation._apply_status(simulation.allies[0], simulation.enemies[0],
{"id": "tagged", "sign": "hindrance", "ticks": 20, "chance_bp": 10000}, {})
simulation._cleanse(simulation.enemies[0], simulation.enemies[0], {})
var again := 0
for record in simulation.journal:
if not str(Dictionary(record).get("shared_from", "")).is_empty():
again += 1
_expect(again == 1, "a spent cleanse-share row stops sharing (shared=%d)" % again)
func _actor(actor_id: String, side_position: int, action: Dictionary, row := {}) -> Dictionary:
var base := {
"id": actor_id, "position": side_position, "level": 5, "profession_id": "", "trait_ids": [],
"might": 14, "finesse": 10, "insight": 10, "vigor": 14, "resolve": 10,
"profession_base_hp": 600, "profession_base_tempo": 55, "profession_base_initiative": 80,
"weapon_power": 8, "focus_power": 8, "armor_guard": 4, "armor_ward": 4,
"action": action,
}
base.merge(row, true)
return base
func _run_battle(actor_action: Dictionary, defender_row := {}) -> ABGBattleSimulation:
var simulation: ABGBattleSimulation = Simulation.new()
simulation.setup("status", [_actor("ally-0", 0, actor_action)], [
_actor("enemy-0", 0, {"id": "basic", "base": 0, "coefficient": 0.0, "kind": "damage",
"reach": 1, "target": "frontmost", "power_source": "physical_power"}, defender_row),
])
simulation.run()
return simulation
func _verify_applied_and_expired() -> void:
var action := {"id": "tag", "base": 1, "coefficient": 0.0, "kind": "damage", "reach": 1,
"target": "frontmost", "power_source": "physical_power",
"status": {"id": "tagged", "sign": "hindrance", "ticks": 8, "chance_bp": 9500}}
var simulation := _run_battle(action)
var applied := _first_of_kind(simulation.journal, "status")
_expect(not applied.is_empty(), "a high-chance status is applied")
if not applied.is_empty():
_expect(str(Dictionary(applied).get("status_id", "")) == "tagged", "the applied status carries its declared id")
_expect(int(Dictionary(applied).get("ticks", 0)) > 0, "the applied status carries a positive duration")
var expired := _first_of_kind(simulation.journal, "status_expire")
_expect(not expired.is_empty(), "the status expires on its clock")
func _verify_resist_path() -> void:
var action := {"id": "tag", "base": 1, "coefficient": 0.0, "kind": "damage", "reach": 1,
"target": "frontmost", "power_source": "physical_power",
"status": {"id": "tagged", "sign": "hindrance", "ticks": 8, "chance_bp": 0}}
var simulation := _run_battle(action)
var resisted := _first_of_kind(simulation.journal, "status_resisted")
_expect(not resisted.is_empty(), "a zero chance is recorded as resisted")
_expect(_first_of_kind(simulation.journal, "status").is_empty(), "a resisted status changes nothing")
var enemy: Dictionary = Array(simulation.enemies)[0]
_expect(Array(enemy.statuses).is_empty(), "a resisted status is not stored")
func _verify_hook_fires() -> void:
var action := {"id": "tag", "base": 1, "coefficient": 0.0, "kind": "damage", "reach": 1,
"target": "frontmost", "power_source": "physical_power",
"status": {"id": "tagged", "sign": "hindrance", "ticks": 4, "chance_bp": 9500}}
var hook_row := {"hook": "on_status_expire", "effect": {"kind": "guard_bonus", "value": 7}, "implemented": true}
var simulation := _run_battle(action, {"equipment_hooks": [hook_row]})
var expired := _first_of_kind(simulation.journal, "status_expire")
_expect(not expired.is_empty(), "the expiry fires")
var enemy: Dictionary = Array(simulation.enemies)[0]
# The hook adds seven guard on top of the derived guard value.
var derived := int(Dictionary(enemy.stats).get("guard", 0))
_expect(int(enemy.guard) >= derived + 7, "on_status_expire applies its guard bonus (guard=%d derived=%d)" % [int(enemy.guard), derived])
func _verify_conditions_follow_state() -> void:
var action := {"id": "tag", "base": 1, "coefficient": 0.0, "kind": "damage", "reach": 1,
"target": "frontmost", "power_source": "physical_power",
"status": {"id": "tagged", "sign": "hindrance", "ticks": 40, "chance_bp": 9500}}
var simulation := _run_battle(action)
var enemy: Dictionary = Array(simulation.enemies)[0]
_expect(simulation._has_hindrance(enemy), "the target carries a hindrance")
_expect(simulation._condition_holds(Dictionary(Array(simulation.allies)[0]), "marked_target_visible"), "marked_target_visible follows the enemy's state")
func _first_of_kind(journal: Array, kind: String) -> Dictionary:
for record in journal:
var entry: Dictionary = Dictionary(record)
if str(entry.get("kind", "")) == kind:
return entry
return {}
func _expect(condition: bool, label: String) -> void:
if not condition:
failures.append(label)