Adds Death and Sickness systems
This commit is contained in:
1 parent
c22a173e52
commit
722bf6d55f
4 files changed
+46
-34
No files matched your search
+6
-14
@@ -37,19 +37,11 @@ class Capacity(BaseStat):
|
||||
pass
|
||||
|
||||
|
||||
class Tag(StrEnum):
|
||||
SICK = "SICK"
|
||||
DEAD = "DEAD"
|
||||
|
||||
|
||||
@dataclass
|
||||
class Tags:
|
||||
values: list = field(default_factory=list)
|
||||
|
||||
|
||||
class LocationType(StrEnum):
|
||||
NO_WHERE = "no_where"
|
||||
PADDOCK = "paddock"
|
||||
STORE = "store"
|
||||
INVENTORY = "inventory"
|
||||
|
||||
|
||||
@dataclass
|
||||
class Location:
|
||||
type: "LocationType" = LocationType.NO_WHERE
|
||||
id: int | None = None
|
||||
values: set[Tag] = field(default_factory=set)
|
||||
@@ -3,14 +3,13 @@ from dataclasses import dataclass, field
|
||||
from components import (
|
||||
Health,
|
||||
Satiety,
|
||||
Location,
|
||||
LocationType,
|
||||
Name,
|
||||
Hydration,
|
||||
Hygiene,
|
||||
Tags,
|
||||
)
|
||||
from ecs import World
|
||||
|
||||
from libs.ecs import World
|
||||
|
||||
|
||||
def create_pet(world: World, name: str):
|
||||
@@ -22,12 +21,3 @@ def create_pet(world: World, name: str):
|
||||
Hygiene(80),
|
||||
Tags(),
|
||||
)
|
||||
|
||||
|
||||
def move_pet_to(world: World, pet_id, container_entity=None) -> bool:
|
||||
component_map = world.get_components(pet_id, pop=True)
|
||||
if component_map is None:
|
||||
return False
|
||||
component_map[Location].id = container_entity
|
||||
component_map[Location].type = LocationType.PADDOCK
|
||||
return True
|
||||
+27
-2
@@ -1,5 +1,5 @@
|
||||
from components import Health, Hydration, Hygiene, Satiety
|
||||
from ecs import World
|
||||
from components import Health, Hydration, Hygiene, Satiety, Tag, Tags
|
||||
from libs.ecs import World
|
||||
|
||||
|
||||
class SatietySystem:
|
||||
@@ -39,3 +39,28 @@ class HygieneSystem:
|
||||
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)
|
||||
@@ -1,11 +1,19 @@
|
||||
from imp import World, create_pet
|
||||
from systems import SatietySystem, HydrationSystem, HygieneSystem
|
||||
from systems import (
|
||||
DeathSystem,
|
||||
SicknessSystem,
|
||||
SatietySystem,
|
||||
HydrationSystem,
|
||||
HygieneSystem,
|
||||
)
|
||||
|
||||
|
||||
def test_systems_tick():
|
||||
world = World()
|
||||
world.systems.extend(
|
||||
(
|
||||
DeathSystem,
|
||||
SicknessSystem,
|
||||
HydrationSystem,
|
||||
SatietySystem,
|
||||
HygieneSystem,
|
||||
@@ -14,12 +22,9 @@ def test_systems_tick():
|
||||
|
||||
entity = create_pet(world, "karabas")
|
||||
|
||||
for _ in range(81):
|
||||
for _ in range(81 + 35):
|
||||
world.tick()
|
||||
|
||||
components = world.get_components(entity)
|
||||
|
||||
print(components)
|
||||
print(world.registry)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user