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
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Tag(StrEnum):
|
||||||
|
SICK = "SICK"
|
||||||
|
DEAD = "DEAD"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Tags:
|
class Tags:
|
||||||
values: list = field(default_factory=list)
|
values: set[Tag] = field(default_factory=set)
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
@@ -3,14 +3,13 @@ from dataclasses import dataclass, field
|
|||||||
from components import (
|
from components import (
|
||||||
Health,
|
Health,
|
||||||
Satiety,
|
Satiety,
|
||||||
Location,
|
|
||||||
LocationType,
|
|
||||||
Name,
|
Name,
|
||||||
Hydration,
|
Hydration,
|
||||||
Hygiene,
|
Hygiene,
|
||||||
Tags,
|
Tags,
|
||||||
)
|
)
|
||||||
from ecs import World
|
|
||||||
|
from libs.ecs import World
|
||||||
|
|
||||||
|
|
||||||
def create_pet(world: World, name: str):
|
def create_pet(world: World, name: str):
|
||||||
@@ -22,12 +21,3 @@ def create_pet(world: World, name: str):
|
|||||||
Hygiene(80),
|
Hygiene(80),
|
||||||
Tags(),
|
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 components import Health, Hydration, Hygiene, Satiety, Tag, Tags
|
||||||
from ecs import World
|
from libs.ecs import World
|
||||||
|
|
||||||
|
|
||||||
class SatietySystem:
|
class SatietySystem:
|
||||||
@@ -39,3 +39,28 @@ class HygieneSystem:
|
|||||||
hygiene.value = 0
|
hygiene.value = 0
|
||||||
else:
|
else:
|
||||||
hygiene.value -= 1
|
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 imp import World, create_pet
|
||||||
from systems import SatietySystem, HydrationSystem, HygieneSystem
|
from systems import (
|
||||||
|
DeathSystem,
|
||||||
|
SicknessSystem,
|
||||||
|
SatietySystem,
|
||||||
|
HydrationSystem,
|
||||||
|
HygieneSystem,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_systems_tick():
|
def test_systems_tick():
|
||||||
world = World()
|
world = World()
|
||||||
world.systems.extend(
|
world.systems.extend(
|
||||||
(
|
(
|
||||||
|
DeathSystem,
|
||||||
|
SicknessSystem,
|
||||||
HydrationSystem,
|
HydrationSystem,
|
||||||
SatietySystem,
|
SatietySystem,
|
||||||
HygieneSystem,
|
HygieneSystem,
|
||||||
@@ -14,12 +22,9 @@ def test_systems_tick():
|
|||||||
|
|
||||||
entity = create_pet(world, "karabas")
|
entity = create_pet(world, "karabas")
|
||||||
|
|
||||||
for _ in range(81):
|
for _ in range(81 + 35):
|
||||||
world.tick()
|
world.tick()
|
||||||
|
print(world.registry)
|
||||||
components = world.get_components(entity)
|
|
||||||
|
|
||||||
print(components)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in new issue
Block a user