52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from engine.defs import DefRegistry
|
|
from engine.entity import EntityPosition
|
|
from resources.logic.spawning import spawn_npc
|
|
|
|
DEFS_DIR = Path(__file__).resolve().parent.parent / "resources" / "defs"
|
|
|
|
|
|
@pytest.fixture()
|
|
def registry():
|
|
return DefRegistry.load(DEFS_DIR)
|
|
|
|
|
|
def test_spawn_npc_builds_a_character_from_the_template(registry):
|
|
npc = spawn_npc(registry, "npc_reptilian", EntityPosition("field", 2, 2, 0))
|
|
assert npc.name == "Reptilian"
|
|
assert npc.def_id == "npc_reptilian"
|
|
assert npc.species_id == "reptilian_quad"
|
|
assert npc.position == EntityPosition("field", 2, 2, 0)
|
|
|
|
|
|
def test_spawn_npc_fills_the_ai_slot_from_the_templates_behavior(registry):
|
|
npc = spawn_npc(registry, "npc_reptilian", EntityPosition("field", 2, 2, 0))
|
|
assert npc.ai is not None
|
|
assert npc.ai.behavior_id == "wander"
|
|
|
|
|
|
def test_spawn_npc_leaves_the_ai_slot_none_without_a_behavior(registry):
|
|
npc = spawn_npc(registry, "npc_alien", EntityPosition("field", 2, 2, 0))
|
|
assert npc.ai is None
|
|
|
|
|
|
def test_spawn_npc_creates_an_inventory_when_the_template_declares_a_size(registry):
|
|
npc = spawn_npc(registry, "npc_reptilian", EntityPosition("field", 2, 2, 0))
|
|
assert npc.inventory is not None
|
|
assert (npc.inventory.width, npc.inventory.height) == (6, 5)
|
|
|
|
|
|
def test_spawn_npc_leaves_inventory_none_without_a_declared_size(registry):
|
|
npc = spawn_npc(registry, "companion_dog", EntityPosition("field", 2, 2, 0))
|
|
assert npc.inventory is None
|
|
|
|
|
|
def test_spawn_npc_gives_independent_ai_state_per_instance(registry):
|
|
a = spawn_npc(registry, "npc_reptilian", EntityPosition("field", 2, 2, 0))
|
|
b = spawn_npc(registry, "npc_reptilian", EntityPosition("field", 3, 3, 0))
|
|
a.ai.state["next_move_at"] = 5.0
|
|
assert b.ai.state == {}
|