Files

49 lines
2.3 KiB
GDScript

extends GutTest
const AttributesType = preload("res://scripts/domain/entities/attributes.gd")
const PlayerStateType = preload("res://scripts/domain/entities/player_state.gd")
const StatusEffectType = preload("res://scripts/domain/combat/status_effect.gd")
const ConditionEngineType = preload("res://scripts/domain/combat/condition_engine.gd")
func test_data_backed_primary_attributes_skills_and_derived_resources() -> void:
var attributes := AttributesType.new({"end": 6, "wil": 7, "str_": 5})
var player := PlayerStateType.new({"attributes": attributes, "skills": {"traps": 4}, "level": 3})
assert_eq(player.max_hp(), 102)
assert_eq(player.max_focus(), 56)
assert_eq(player.effective_attribute(&"str_"), 5)
assert_eq(player.effective_skill(&"traps"), 4)
func test_effective_attributes_combine_equipment_and_active_status_modifiers() -> void:
var player := PlayerStateType.new({"attributes": {"str_": 4}})
player.equipment_attribute_modifiers = {&"str_": 3}
player.apply_status(StatusEffectType.new(&"wounded", 2))
player.apply_status(StatusEffectType.new(&"strengthened", 2))
assert_eq(player.effective_attribute(&"str_"), 8)
func test_condition_engine_evaluates_content_conditions_and_reports_unknown_conditions() -> void:
var player := PlayerStateType.new({"attributes": {"per": 6}, "skills": {"traps": 8}, "level": 4})
player.flags[&"terminal_open"] = true
var engine := ConditionEngineType.new()
var context := {"player": player, "payload": {"method": "ranged", "tags": ["narrative"]}}
assert_true(engine.evaluate({"type": "all", "conds": [
{"type": "attr", "attr": "per", "min": 6},
{"type": "skill", "skill": "traps", "min": 8},
{"type": "level", "min": 4},
{"type": "flag", "flag": "terminal_open", "equals": true},
{"type": "payload_equals", "key": "method", "value": "ranged"},
{"type": "payload_contains", "key": "tags", "value": "narrative"},
]}, context))
engine.apply_effects([
{"type": "set_flag", "flag": "rewarded"},
{"type": "add_attr", "attr": "per", "amount": 1},
{"type": "add_skill", "skill": "traps", "amount": 1},
], context)
assert_true(player.flags[&"rewarded"])
assert_eq(player.effective_attribute(&"per"), 7)
assert_eq(player.effective_skill(&"traps"), 9)
assert_false(engine.evaluate({"type": "not_a_content_condition"}, context))
assert_true(engine.diagnostics.find("Unknown condition type: not_a_content_condition") >= 0)