317 lines
12 KiB
GDScript
317 lines
12 KiB
GDScript
extends SceneTree
|
|
|
|
var main_scene: Node
|
|
var failures: Array[String] = []
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("_run")
|
|
|
|
|
|
func _run() -> void:
|
|
main_scene = load("res://main.tscn").instantiate()
|
|
root.add_child(main_scene)
|
|
await process_frame
|
|
await physics_frame
|
|
|
|
var simulation_manager := main_scene.get_node("SimulationManager")
|
|
var player := main_scene.get_node("Player")
|
|
player.villager_inspection_range = 0.0
|
|
var bush := (
|
|
main_scene.get_node("JajceWorld/WorldObjects/ResourceNodes/BerryBush_01") as ResourceNode
|
|
)
|
|
simulation_manager.set_process(false)
|
|
|
|
var bush_state: ResourceStateRecord = simulation_manager.get_resource_state(bush.node_id)
|
|
bush_state.set_amount_remaining(1.0)
|
|
_check(
|
|
simulation_manager.reserve_resource(bush.node_id, 999),
|
|
"Player contention setup should reserve the bush"
|
|
)
|
|
player.global_position = bush.interaction_point.global_position
|
|
var food_before: float = simulation_manager.village.food
|
|
player.try_interact()
|
|
|
|
_check(
|
|
is_equal_approx(bush_state.get_amount_remaining(), 0.0),
|
|
"Player should deplete the nearby bush into their hands"
|
|
)
|
|
var carried_after_gather: float = simulation_manager.get_player_state().get_inventory_amount(
|
|
SimulationIds.RESOURCE_FOOD
|
|
)
|
|
_check(
|
|
is_equal_approx(
|
|
simulation_manager.get_player_state().get_inventory_amount(SimulationIds.RESOURCE_FOOD),
|
|
1.0
|
|
),
|
|
"Player harvesting should carry exactly the bush's remaining food"
|
|
)
|
|
_check(bush_state.get_reserved_by() == -1, "Depletion should release the NPC reservation")
|
|
var player_extraction: EconomicEventRecord
|
|
var player_depletion: EconomicEventRecord
|
|
for event in simulation_manager.economic_events:
|
|
if int(event.data["actor_id"]) != -1 or StringName(event.data["source_id"]) != bush.node_id:
|
|
continue
|
|
if StringName(event.data["event_type"]) == SimulationIds.EVENT_RESOURCE_EXTRACTED:
|
|
player_extraction = event
|
|
elif StringName(event.data["event_type"]) == SimulationIds.EVENT_RESOURCE_DEPLETED:
|
|
player_depletion = event
|
|
var bush_event_position := bush.interaction_point.global_position
|
|
_check(player_extraction != null, "Player extraction should create a structured event")
|
|
_check(player_depletion != null, "Player depletion should create a structured event")
|
|
if player_extraction != null:
|
|
_check(
|
|
(
|
|
player_extraction.get_world_position().is_equal_approx(bush_event_position)
|
|
and (
|
|
StringName(player_extraction.data["destination_id"])
|
|
== SimulationIds.PLAYER_INVENTORY_ID
|
|
)
|
|
),
|
|
"Player extraction should preserve the interaction position and name the carried inventory"
|
|
)
|
|
if player_depletion != null:
|
|
_check(
|
|
player_depletion.get_world_position().is_equal_approx(bush_event_position),
|
|
"Player depletion should preserve the resource interaction position"
|
|
)
|
|
|
|
var pantry := (
|
|
main_scene.get_node("JajceWorld/WorldObjects/StorageSites/VillagePantry") as StorageNode
|
|
)
|
|
var pantry_state: StorageStateRecord = simulation_manager.get_pantry()
|
|
player.global_position = pantry.get_interaction_position()
|
|
player.try_interact()
|
|
_check(
|
|
(
|
|
is_equal_approx(simulation_manager.village.food, food_before + 1.0)
|
|
and is_equal_approx(
|
|
simulation_manager.get_player_state().get_inventory_amount(
|
|
SimulationIds.RESOURCE_FOOD
|
|
),
|
|
0.0
|
|
)
|
|
),
|
|
"Depositing at the pantry should move carried food into the village and empty the player"
|
|
)
|
|
|
|
var pantry_food_before := pantry_state.get_amount(SimulationIds.RESOURCE_FOOD)
|
|
player.try_interact()
|
|
_check(
|
|
(
|
|
pantry_state.get_amount(SimulationIds.RESOURCE_FOOD) < pantry_food_before
|
|
and simulation_manager.get_player_state().get_hunger() < 40.0
|
|
),
|
|
"Player should eat from the typed pantry StorageNode and ease their hunger"
|
|
)
|
|
|
|
pantry_state.deposit(SimulationIds.RESOURCE_FOOD, pantry_state.get_available_capacity())
|
|
simulation_manager.economy.sync_resource(SimulationIds.RESOURCE_FOOD)
|
|
bush_state.set_amount_remaining(1.0)
|
|
player.global_position = bush.interaction_point.global_position
|
|
player.try_interact()
|
|
player.global_position = pantry.get_interaction_position()
|
|
player.try_interact()
|
|
var food_after_first_deposit := pantry_state.get_amount(SimulationIds.RESOURCE_FOOD)
|
|
var food_carried_after_first: float = (
|
|
simulation_manager.get_player_state().get_inventory_amount(SimulationIds.RESOURCE_FOOD)
|
|
)
|
|
_check(
|
|
(
|
|
is_equal_approx(bush_state.get_amount_remaining(), 0.0)
|
|
and is_equal_approx(pantry_state.get_available_capacity(), 0.0)
|
|
and is_equal_approx(
|
|
simulation_manager.get_player_state().get_inventory_amount(
|
|
SimulationIds.RESOURCE_FOOD
|
|
),
|
|
1.0
|
|
)
|
|
),
|
|
"Player harvesting into a full pantry should leave the unaccepted overflow carried"
|
|
)
|
|
var guard_site := (
|
|
main_scene.get_node("JajceWorld/WorldObjects/ActivitySites/GuardPost") as ActivitySite
|
|
)
|
|
player.global_position = guard_site.get_interaction_position()
|
|
var adapter := main_scene.get_node("ActiveWorldAdapter") as ActiveWorldAdapter
|
|
var adapter_identity := adapter.get_context_identity()
|
|
_check(
|
|
adapter.configure_context_identity(
|
|
StringName(adapter_identity["context_id"]),
|
|
StringName(adapter_identity["world_id"]),
|
|
StringName(adapter_identity["location_id"])
|
|
),
|
|
"Activity registry ABA setup should create a clean first registry"
|
|
)
|
|
var guard_context := player.get_interaction_context() as PlayerInteractionResult
|
|
var stale_safety: float = simulation_manager.village.safety
|
|
var stale_woodpile := simulation_manager.get_woodpile() as StorageStateRecord
|
|
var stale_wood: float = stale_woodpile.get_amount(SimulationIds.RESOURCE_WOOD)
|
|
var stale_event_count: int = simulation_manager.economic_events.size()
|
|
_check(
|
|
(
|
|
guard_context != null
|
|
and adapter.configure_context_identity(
|
|
StringName(adapter_identity["context_id"]),
|
|
StringName(adapter_identity["world_id"]),
|
|
StringName(adapter_identity["location_id"])
|
|
)
|
|
and adapter.get_target_handle(guard_site.site_id) != null
|
|
and (
|
|
adapter.get_target_handle(guard_site.site_id).get_generation()
|
|
== guard_context.target_generation
|
|
)
|
|
),
|
|
"Activity registry replacement should recreate the same visible target generation"
|
|
)
|
|
simulation_manager.update_player_combatant(player.global_position)
|
|
var stale_result: ActionResult = simulation_manager.execute_player_activity_action(
|
|
guard_context.action_id,
|
|
guard_context.target_id,
|
|
guard_context.expected_state_revision,
|
|
guard_context.target_generation,
|
|
guard_context.target_context_id,
|
|
guard_context.target_registry_instance_id
|
|
)
|
|
var incomplete_result: ActionResult = simulation_manager.execute_player_activity_action(
|
|
guard_context.action_id, guard_context.target_id
|
|
)
|
|
_check(
|
|
(
|
|
stale_result != null
|
|
and not stale_result.did_succeed()
|
|
and stale_result.get_reason_code() == ActivityActionCommandService.REASON_STALE_TARGET
|
|
and is_equal_approx(simulation_manager.village.safety, stale_safety)
|
|
and is_equal_approx(stale_woodpile.get_amount(SimulationIds.RESOURCE_WOOD), stale_wood)
|
|
and simulation_manager.economic_events.size() == stale_event_count
|
|
and incomplete_result != null
|
|
and not incomplete_result.did_succeed()
|
|
and (
|
|
incomplete_result.get_reason_code()
|
|
== ActivityActionCommandService.REASON_STALE_TARGET
|
|
)
|
|
),
|
|
(
|
|
"A replaced registry and an incomplete direct call must reject without mutating "
|
|
+ "authority"
|
|
)
|
|
)
|
|
guard_context = player.get_interaction_context() as PlayerInteractionResult
|
|
var safety_before: float = simulation_manager.village.safety
|
|
var woodpile := simulation_manager.get_woodpile() as StorageStateRecord
|
|
var wood_before := woodpile.get_amount(SimulationIds.RESOURCE_WOOD)
|
|
var event_count_before: int = simulation_manager.economic_events.size()
|
|
player.try_interact()
|
|
var activity_event := simulation_manager.economic_events.back() as EconomicEventRecord
|
|
_check(
|
|
(
|
|
guard_context != null
|
|
and guard_context.kind == PlayerInteractionResult.KIND_ACTIVITY
|
|
and guard_context.action_id == SimulationIds.ACTION_PATROL
|
|
and guard_context.target_id == guard_site.site_id
|
|
and guard_context.expected_state_revision == event_count_before
|
|
and simulation_manager.village.safety > safety_before
|
|
and is_equal_approx(woodpile.get_amount(SimulationIds.RESOURCE_WOOD), wood_before - 1.0)
|
|
and simulation_manager.economic_events.size() == event_count_before + 1
|
|
and (
|
|
StringName(activity_event.data["event_type"])
|
|
== SimulationIds.EVENT_ACTIVITY_COMPLETED
|
|
)
|
|
and int(activity_event.data["actor_id"]) == SimulationIds.PLAYER_ACTOR_ID
|
|
and StringName(activity_event.data["source_id"]) == guard_site.site_id
|
|
and StringName(activity_event.data["action_id"]) == SimulationIds.ACTION_PATROL
|
|
and StringName(activity_event.data["metric_id"]) == &"safety"
|
|
and is_equal_approx(float(activity_event.data["metric_delta"]), 3.0)
|
|
and StringName(activity_event.data["cost_item_id"]) == SimulationIds.RESOURCE_WOOD
|
|
and is_equal_approx(float(activity_event.data["cost_amount"]), 1.0)
|
|
and StringName(activity_event.data["world_id"]) == SimulationIds.REGIONAL_WORLD_BOSNIA
|
|
and (
|
|
StringName(activity_event.data["location_id"])
|
|
== SimulationIds.REGIONAL_LOCATION_JAJCE
|
|
)
|
|
and simulation_manager.event_knowledge_system.knows_event(
|
|
SimulationIds.PLAYER_ACTOR_ID, int(activity_event.data["event_id"])
|
|
)
|
|
),
|
|
(
|
|
"Player activity should use the same revisioned command, cost, metric, fact, and "
|
|
+ "knowledge path as NPC work"
|
|
)
|
|
)
|
|
var activity_checksum: String = simulation_manager.get_state_checksum()
|
|
var activity_snapshot: String = simulation_manager.serialize_state()
|
|
_check(
|
|
(
|
|
simulation_manager.restore_state_from_json(activity_snapshot)
|
|
and simulation_manager.get_state_checksum() == activity_checksum
|
|
and simulation_manager.event_knowledge_system.knows_event(
|
|
SimulationIds.PLAYER_ACTOR_ID, int(activity_event.data["event_id"])
|
|
)
|
|
),
|
|
"Player activity facts and performed knowledge should survive exact save/restore"
|
|
)
|
|
woodpile = simulation_manager.get_woodpile()
|
|
woodpile.withdraw(SimulationIds.RESOURCE_WOOD, woodpile.get_amount(SimulationIds.RESOURCE_WOOD))
|
|
simulation_manager.economy.sync_resource(SimulationIds.RESOURCE_WOOD)
|
|
var blocked_guard_context := player.get_interaction_context() as PlayerInteractionResult
|
|
var blocked_guard_safety: float = simulation_manager.village.safety
|
|
var blocked_guard_events: int = simulation_manager.economic_events.size()
|
|
player.try_interact()
|
|
_check(
|
|
(
|
|
blocked_guard_context != null
|
|
and blocked_guard_context.kind == PlayerInteractionResult.KIND_ACTIVITY
|
|
and blocked_guard_context.target_id == guard_site.site_id
|
|
and not blocked_guard_context.is_available()
|
|
and "wood" in blocked_guard_context.blocked_reason.to_lower()
|
|
and is_equal_approx(simulation_manager.village.safety, blocked_guard_safety)
|
|
and simulation_manager.economic_events.size() == blocked_guard_events
|
|
),
|
|
"An unfunded authored activity offer should explain the cost without mutating authority"
|
|
)
|
|
woodpile.deposit(SimulationIds.RESOURCE_WOOD, 1.0)
|
|
simulation_manager.economy.sync_resource(SimulationIds.RESOURCE_WOOD)
|
|
var downed_context := player.get_interaction_context() as PlayerInteractionResult
|
|
var downed_wood := woodpile.get_amount(SimulationIds.RESOURCE_WOOD)
|
|
var downed_safety: float = simulation_manager.village.safety
|
|
var downed_event_count: int = simulation_manager.economic_events.size()
|
|
simulation_manager.get_player_state().take_damage(
|
|
simulation_manager.get_player_state().get_max_health()
|
|
)
|
|
var downed_result: ActionResult
|
|
if downed_context != null:
|
|
downed_result = simulation_manager.execute_player_activity_action(
|
|
downed_context.action_id,
|
|
downed_context.target_id,
|
|
downed_context.expected_state_revision,
|
|
downed_context.target_generation,
|
|
downed_context.target_context_id,
|
|
downed_context.target_registry_instance_id
|
|
)
|
|
_check(
|
|
(
|
|
downed_context != null
|
|
and downed_context.kind == PlayerInteractionResult.KIND_ACTIVITY
|
|
and downed_result != null
|
|
and not downed_result.did_succeed()
|
|
and is_equal_approx(woodpile.get_amount(SimulationIds.RESOURCE_WOOD), downed_wood)
|
|
and is_equal_approx(simulation_manager.village.safety, downed_safety)
|
|
and simulation_manager.economic_events.size() == downed_event_count
|
|
),
|
|
"A downed player must not work, consume cost, mutate metrics, or record a fact"
|
|
)
|
|
|
|
if failures.is_empty():
|
|
print("[TEST] ResourceNode player parity passed")
|
|
quit(0)
|
|
return
|
|
|
|
for failure in failures:
|
|
push_error("[TEST] " + failure)
|
|
quit(1)
|
|
|
|
|
|
func _check(condition: bool, message: String) -> void:
|
|
if not condition:
|
|
failures.append(message)
|