feat: add player sword combat, dash, and hostile wolf/raider visuals

This commit is contained in:
Rijad Zuzo
2026-08-11 20:49:43 +02:00
parent 292cdd9153
commit b62f7b86cc
12 changed files with 564 additions and 1 deletions
+124
View File
@@ -0,0 +1,124 @@
extends SceneTree
var failures: Array[String] = []
func _initialize() -> void:
call_deferred("_run")
func _run() -> void:
var main_scene: Node = load("res://main.tscn").instantiate()
root.add_child(main_scene)
await process_frame
for _frame in 12:
await physics_frame
var simulation_manager: Node = main_scene.get_node("SimulationManager")
simulation_manager.set_process(false)
var combat_view: Node = main_scene.get_node("CombatPresentation")
var player := main_scene.get_node("Player") as Node3D
var controller := main_scene.get_node("Player/PlayerCombatController")
await process_frame
await process_frame
_check(
combat_view.hostiles.size() >= 1,
"Authored wolves should spawn as hostile visuals in the loaded world"
)
var hostiles: Array = simulation_manager.get_living_hostile_combatants()
_check(not hostiles.is_empty(), "The simulation should own at least one living hostile")
if hostiles.is_empty():
main_scene.queue_free()
_finish()
return
var wolf: CombatantStateRecord = hostiles[0]
_check(
combat_view.hostiles.has(wolf.get_combatant_id()),
"The hostile visual should bind to the authoritative combatant record"
)
_check(
(
wolf.get_kind() == SimulationIds.COMBATANT_KIND_WOLF
and wolf.is_hostile()
and wolf.get_faction_id() == SimulationIds.FACTION_TRIBE
),
"Spawned wolves should be hostile tribe-affiliated combatants"
)
var wolf_visual: Node3D = combat_view.hostiles[wolf.get_combatant_id()]
player.global_position = wolf_visual.global_position + Vector3(-2.0, 0.0, 0.0)
player.look_at(wolf_visual.global_position, Vector3.UP)
player.rotation.x = 0.0
var wolf_health: float = wolf.get_health()
controller.call("_perform_attack")
_check(
wolf.get_health() < wolf_health,
"A player sword strike should damage the hostile wolf through the simulation"
)
var struck := 0
for _attempt in 6:
if not wolf.is_alive():
break
controller.call("_perform_attack")
struck += 1
await process_frame
_check(not wolf.is_alive(), "Repeated sword strikes should kill the hostile wolf")
await process_frame
await process_frame
_check(
not combat_view.hostiles.has(wolf.get_combatant_id()),
"Killing a hostile should remove its presentation visual"
)
_check(
_has_event(simulation_manager, SimulationIds.EVENT_COMBATANT_KILLED),
"The player's kill should be recorded as a combatant_killed fact"
)
var tribe: FactionStateRecord = simulation_manager.get_faction(SimulationIds.FACTION_TRIBE)
_check(
(
simulation_manager.get_village_defender_count() >= 0
and tribe != null
and (
simulation_manager.get_tribe_war_plan()
in [
SimulationIds.WAR_PLAN_NONE,
SimulationIds.WAR_PLAN_PLANNED,
SimulationIds.WAR_PLAN_RAIDING,
SimulationIds.WAR_PLAN_ABORTED,
]
)
),
"The runtime should expose village defense and the tribe war plan"
)
if failures.is_empty():
print("[TEST] Jajce combat presentation passed: wolves -> sword -> kill -> cleanup")
quit(0)
return
for failure in failures:
push_error("[TEST] " + failure)
quit(1)
func _has_event(manager: Node, event_type: StringName) -> bool:
for event in manager.economic_events:
if StringName(event.data["event_type"]) == event_type:
return true
return false
func _check(condition: bool, message: String) -> void:
if not condition:
failures.append(message)
func _finish() -> void:
if failures.is_empty():
print("[TEST] Jajce combat presentation passed: wolves -> sword -> kill -> cleanup")
quit(0)
return
for failure in failures:
push_error("[TEST] " + failure)
quit(1)