67 lines
2.0 KiB
Python
67 lines
2.0 KiB
Python
from components import Health, Hydration, Hygiene, Satiety, Tag, Tags
|
|
from libs.ecs import World
|
|
|
|
|
|
class SatietySystem:
|
|
@classmethod
|
|
def process(cls, world: World):
|
|
for _, component_map in world.query(Satiety):
|
|
health: Health = component_map[Health]
|
|
hunger: Satiety = component_map[Satiety]
|
|
if hunger.value <= 0:
|
|
health.value -= 1
|
|
hunger.value = 0
|
|
else:
|
|
hunger.value -= 1
|
|
|
|
|
|
class HydrationSystem:
|
|
@classmethod
|
|
def process(cls, world: World):
|
|
for _, component_map in world.query(Hydration):
|
|
health: Health = component_map[Health]
|
|
hydration: Hydration = component_map[Hydration]
|
|
if hydration.value <= 0:
|
|
health.value -= 1
|
|
hydration.value = 0
|
|
else:
|
|
hydration.value -= 1
|
|
|
|
|
|
class HygieneSystem:
|
|
@classmethod
|
|
def process(cls, world: World):
|
|
for _, component_map in world.query(Hygiene):
|
|
health: Health = component_map[Health]
|
|
hygiene: Hygiene = component_map[Hygiene]
|
|
if hygiene.value <= 0:
|
|
health.value -= 1
|
|
hygiene.value = 0
|
|
else:
|
|
hygiene.value -= 1
|
|
|
|
|
|
class SicknessSystem:
|
|
@classmethod
|
|
def process(cls, world: World):
|
|
for _, component_map in world.query(Health, Tags):
|
|
health = component_map[Health]
|
|
tags = component_map[Tags]
|
|
if Tag.SICK in tags.values and health.value > 0:
|
|
health.value -= 1
|
|
if health.value <= 0:
|
|
health.value = 0
|
|
tags.values.add(Tag.DEAD)
|
|
|
|
|
|
class DeathSystem:
|
|
@classmethod
|
|
def process(cls, world: World):
|
|
marked = set()
|
|
for entity, component_map in world.query(Health, Tags):
|
|
tags = component_map[Tags]
|
|
if Tag.DEAD in tags.values:
|
|
marked.add(entity)
|
|
for entity in marked:
|
|
world.get_components(entity, pop=True)
|