40 lines
1.8 KiB
Python
40 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
from engine.character import Character
|
|
from engine.defs import DefRegistry
|
|
|
|
|
|
def apply_bleeding_tick(character: Character, registry: DefRegistry, ticks: int) -> None:
|
|
"""Every body part that's been lost (removed=True) bleeds at its def's bleeding_speed per
|
|
tick, and so does one with a causes_bleeding ailment (e.g. a synthetic's popped_fluid_hose -
|
|
see AilmentDef.causes_bleeding), scaled by the ailment's own severity. Either source is
|
|
silenced by bandaging the part (see BodyPart.bandaged / resources/logic/medical.py::
|
|
treat_bleeding) - a bandaged severed limb doesn't bleed, and neither does a bandaged wound.
|
|
"""
|
|
if ticks <= 0:
|
|
return
|
|
total_loss = 0.0
|
|
for part in character.body_parts:
|
|
if part.bandaged:
|
|
continue
|
|
part_def = registry.get_body_part_def(part.part_def_id)
|
|
if part.removed:
|
|
total_loss += part_def.bleeding_speed * ticks
|
|
continue
|
|
for ailment in part.ailments:
|
|
ailment_def = registry.get_ailment_def(ailment.id)
|
|
if ailment_def is not None and ailment_def.causes_bleeding:
|
|
total_loss += ailment_def.bleed_rate * ailment.severity * ticks
|
|
if total_loss:
|
|
character.blood_percentage = max(0.0, character.blood_percentage - total_loss)
|
|
|
|
|
|
def apply_boost_expiry_tick(character: Character, now: float) -> None:
|
|
"""Clears any Character.active_boosts (e.g. a consumed stimulant - see resources/logic/
|
|
abilities.py::cast_adrenablend) whose boost_expirations time has passed.
|
|
"""
|
|
expired = [stat for stat, expires_at in character.boost_expirations.items() if now >= expires_at]
|
|
for stat in expired:
|
|
character.active_boosts.pop(stat, None)
|
|
character.boost_expirations.pop(stat, None)
|