148 lines
4.8 KiB
GDScript
148 lines
4.8 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")
|
|
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"
|
|
)
|
|
_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()
|
|
_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 safety_before: float = simulation_manager.village.safety
|
|
player.try_interact()
|
|
_check(
|
|
simulation_manager.village.safety > safety_before,
|
|
"Player should help guard from the typed GuardPost ActivitySite"
|
|
)
|
|
|
|
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)
|