Mi2dRPGamEng/tests/test_adrenablend.py

108 lines
3.6 KiB
Python

from pathlib import Path
import pytest
from engine.character import Character
from engine.defs import DefRegistry
from engine.entity import EntityPosition
from engine.inventory import Inventory
from engine.map import Map
from engine.tile import Tile, TileLayerInstance
from engine.world import World
from resources.logic.abilities import (
ADRENABLEND_BRAIN_FOG_SEVERITY,
ADRENABLEND_SPEED_MULTIPLIER,
ADRENABLEND_STRENGTH_MULTIPLIER,
cast_adrenablend,
)
from resources.logic.actions import activate_hand
from resources.logic.contagion import has_ailment
DEFS_DIR = Path(__file__).resolve().parent.parent / "resources" / "defs"
@pytest.fixture()
def registry():
return DefRegistry.load(DEFS_DIR)
def make_world(registry):
field = Map("field", 5, 5, 1)
for x in range(5):
for y in range(5):
field.set_tile(x, y, 0, Tile(flooring=TileLayerInstance("grass")))
world = World(registry=registry)
world.add_map(field)
return world
def make_human(registry, **kwargs) -> Character:
return Character(
species_id="human", position=EntityPosition("field", 2, 2, 0),
default_body_parts=registry.new_default_body_parts("human"), **kwargs
)
# --- cast_adrenablend --------------------------------------------------------------------------
def test_cast_adrenablend_boosts_strength_and_speed(registry):
human = make_human(registry)
cast_adrenablend(human, World(registry=registry), now=10.0)
assert human.active_boosts["strength"] == ADRENABLEND_STRENGTH_MULTIPLIER
assert human.active_boosts["speed"] == ADRENABLEND_SPEED_MULTIPLIER
assert human.effective_strength(registry) > 10.0 * (1.0) # baseline strength=10, boosted
def test_cast_adrenablend_sets_an_expiration_after_now(registry):
human = make_human(registry)
cast_adrenablend(human, World(registry=registry), now=10.0, duration=20.0)
assert human.boost_expirations["strength"] == 30.0
assert human.boost_expirations["speed"] == 30.0
def test_cast_adrenablend_causes_brain_fog(registry):
human = make_human(registry)
cast_adrenablend(human, World(registry=registry), now=0.0)
assert has_ailment(human, "brain_fog")
head = human.get_body_part("head")
fog = next(a for a in head.ailments if a.id == "brain_fog")
assert fog.severity == ADRENABLEND_BRAIN_FOG_SEVERITY
def test_repeated_casts_refresh_rather_than_stack_brain_fog(registry):
human = make_human(registry)
cast_adrenablend(human, World(registry=registry), now=0.0)
cast_adrenablend(human, World(registry=registry), now=1.0)
head = human.get_body_part("head")
matching = [a for a in head.ailments if a.id == "brain_fog"]
assert len(matching) == 1
# --- consumable item wiring via activate_hand --------------------------------------------------
def test_activating_a_consumable_ability_item_unwields_it(registry):
world = make_world(registry)
human = make_human(registry)
human.inventory = Inventory(4, 4)
human.wield_item("right_hand", "adrenablend", registry)
world.add_entity(human)
result = activate_hand(human, world, registry, "right_hand", (0, 1, 0), now=5.0)
assert result is human
assert human.get_held_item("right_hand") is None
assert human.active_boosts["strength"] == ADRENABLEND_STRENGTH_MULTIPLIER
def test_activating_a_non_consumable_ability_item_stays_wielded(registry):
world = make_world(registry)
human = make_human(registry)
human.wield_item("right_hand", "chronowand", registry)
world.add_entity(human)
activate_hand(human, world, registry, "right_hand", (0, 1, 0), now=5.0)
assert human.get_held_item("right_hand") is not None