feat: add full attributes and conditions
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
extends GutTest
|
||||
|
||||
const GameScene = preload("res://scenes/Game.tscn")
|
||||
|
||||
func test_current_game_event_and_hud_remain_available_with_attributes_domain_loaded() -> void:
|
||||
var game := GameScene.instantiate() as Game
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
|
||||
var state := game.get_game_state()
|
||||
state.enemies[&"goblin"].cell = state.player.cell + Vector2i.RIGHT
|
||||
game.submit_test_action(Vector2i.RIGHT)
|
||||
await get_tree().process_frame
|
||||
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
assert_eq(state.enemies[&"goblin"].hit_points, 3)
|
||||
assert_true(game.get_run_state().recent_events(2).any(func(event: GameEvent) -> bool: return event.kind == &"melee"))
|
||||
assert_true(hud.player_health_label.text.contains("Player HP:"))
|
||||
assert_true(hud.event_log.get_parsed_text().contains("You strike the goblin"))
|
||||
@@ -0,0 +1 @@
|
||||
uid://cglna5tkvvmyo
|
||||
@@ -0,0 +1,21 @@
|
||||
extends GutTest
|
||||
|
||||
const Attributes = preload("res://scripts/domain/entities/attributes.gd")
|
||||
const PlayerState = preload("res://scripts/domain/entities/player_state.gd")
|
||||
const ActorState = preload("res://scripts/domain/actor_state.gd")
|
||||
const GameState = preload("res://scripts/domain/game_state.gd")
|
||||
const GridMapState = preload("res://scripts/domain/grid_map_state.gd")
|
||||
|
||||
func test_player_state_adapter_preserves_actor_and_game_state_contract() -> void:
|
||||
var player := PlayerState.new({"id": &"player", "cell": Vector2i(2, 2), "attributes": Attributes.new({"end": 5})})
|
||||
var actor := player.as_actor_state(3)
|
||||
var map := GridMapState.new(Vector2i(5, 5), GridMapState.CellKind.FLOOR)
|
||||
var state := GameState.new(map, actor, {})
|
||||
|
||||
assert_true(actor is ActorState)
|
||||
assert_eq(actor.id, &"player")
|
||||
assert_eq(actor.cell, Vector2i(2, 2))
|
||||
assert_eq(actor.hit_points, player.hit_points)
|
||||
assert_eq(actor.max_hit_points, player.max_hp())
|
||||
assert_eq(actor.attack_damage, 3)
|
||||
assert_eq(state.player, actor)
|
||||
@@ -0,0 +1 @@
|
||||
uid://1rgi8tkrgnlu
|
||||
@@ -0,0 +1,48 @@
|
||||
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)
|
||||
@@ -0,0 +1 @@
|
||||
uid://b45kschi80lx7
|
||||
@@ -0,0 +1,37 @@
|
||||
extends GutTest
|
||||
|
||||
const PlayerStateType = preload("res://scripts/domain/entities/player_state.gd")
|
||||
const StatusEffectType = preload("res://scripts/domain/combat/status_effect.gd")
|
||||
|
||||
func test_status_uses_data_default_duration_and_refreshes_without_stacking() -> void:
|
||||
var player := PlayerStateType.new()
|
||||
player.apply_status(StatusEffectType.new(&"poison"))
|
||||
player.apply_status(StatusEffectType.new(&"poison", 6, 5))
|
||||
|
||||
assert_eq(player.status_effects.size(), 1)
|
||||
assert_eq(player.status_effects[0].duration, 6)
|
||||
assert_eq(player.status_effects[0].magnitude, 5)
|
||||
|
||||
func test_status_tick_applies_effect_before_expiring_and_reports_tick() -> void:
|
||||
var player := PlayerStateType.new({"attributes": {"end": 4}})
|
||||
player.hit_points = 20
|
||||
player.apply_status(StatusEffectType.new(&"poison", 2))
|
||||
player.apply_status(StatusEffectType.new(&"regenerating", 1))
|
||||
|
||||
var ticks := player.tick_status_effects()
|
||||
|
||||
assert_eq(player.hit_points, 21)
|
||||
assert_eq(ticks.size(), 2)
|
||||
assert_eq(ticks[0]["hit_point_delta"], -3)
|
||||
assert_eq(ticks[1]["hit_point_delta"], 4)
|
||||
assert_eq(player.status_effects.size(), 1)
|
||||
assert_eq(player.status_effects[0].key, &"poison")
|
||||
assert_eq(player.status_effects[0].duration, 1)
|
||||
|
||||
func test_expired_status_is_removed_after_its_final_tick() -> void:
|
||||
var player := PlayerStateType.new()
|
||||
player.apply_status(StatusEffectType.new(&"stunned", 1))
|
||||
|
||||
player.tick_status_effects()
|
||||
|
||||
assert_false(player.has_status(&"stunned"))
|
||||
@@ -0,0 +1 @@
|
||||
uid://jbbilbj72nq4
|
||||
Reference in New Issue
Block a user