61 lines
2.1 KiB
Python
61 lines
2.1 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from engine.character import BodyPart, Character
|
|
from engine.defs import DefRegistry
|
|
from resources.logic.health_ticks import apply_bleeding_tick
|
|
|
|
DEFS_DIR = Path(__file__).resolve().parent.parent / "resources" / "defs"
|
|
|
|
|
|
@pytest.fixture()
|
|
def registry():
|
|
return DefRegistry.load(DEFS_DIR)
|
|
|
|
|
|
def test_no_bleeding_when_no_parts_removed(registry):
|
|
character = Character(default_body_parts=registry.new_default_body_parts("human"))
|
|
apply_bleeding_tick(character, registry, ticks=5)
|
|
assert character.blood_percentage == pytest.approx(100.0)
|
|
|
|
|
|
def test_removed_part_bleeds_at_its_defs_rate_per_tick(registry):
|
|
character = Character(
|
|
default_body_parts=registry.new_default_body_parts("human"),
|
|
body_parts=[BodyPart("left_arm", "human_left_arm", removed=True)],
|
|
)
|
|
# human_left_arm bleeding_speed is 2.0/tick
|
|
apply_bleeding_tick(character, registry, ticks=3)
|
|
assert character.blood_percentage == pytest.approx(100.0 - 2.0 * 3)
|
|
|
|
|
|
def test_multiple_removed_parts_stack_bleeding(registry):
|
|
character = Character(
|
|
default_body_parts=registry.new_default_body_parts("human"),
|
|
body_parts=[
|
|
BodyPart("left_leg", "human_left_leg", removed=True), # 3.0/tick
|
|
BodyPart("right_leg", "human_right_leg", removed=True), # 3.0/tick
|
|
],
|
|
)
|
|
apply_bleeding_tick(character, registry, ticks=2)
|
|
assert character.blood_percentage == pytest.approx(100.0 - (3.0 + 3.0) * 2)
|
|
|
|
|
|
def test_blood_percentage_does_not_go_below_zero(registry):
|
|
character = Character(
|
|
default_body_parts=registry.new_default_body_parts("human"),
|
|
body_parts=[BodyPart("torso", "human_torso", removed=True)], # 6.0/tick
|
|
)
|
|
apply_bleeding_tick(character, registry, ticks=100)
|
|
assert character.blood_percentage == 0.0
|
|
|
|
|
|
def test_zero_ticks_is_a_no_op(registry):
|
|
character = Character(
|
|
default_body_parts=registry.new_default_body_parts("human"),
|
|
body_parts=[BodyPart("left_arm", "human_left_arm", removed=True)],
|
|
)
|
|
apply_bleeding_tick(character, registry, ticks=0)
|
|
assert character.blood_percentage == pytest.approx(100.0)
|