Spaces:
Sleeping
Sleeping
| """Entity status transitions and special location effects.""" | |
| from __future__ import annotations | |
| from datetime import datetime, timedelta | |
| from world.book_of_ages import create_entry | |
| from world.database import db_session | |
| from world.entities import add_tag, update_entity_status | |
| from world.locations import get_location_by_id | |
| from simulation.location_effects import effective_days_in_realm | |
| def process_lifecycle_updates(world_day: int) -> list[str]: | |
| """Run lifecycle checks. Returns list of milestone messages.""" | |
| milestones = [] | |
| with db_session() as conn: | |
| entities = conn.execute("SELECT * FROM entities").fetchall() | |
| for row in entities: | |
| entity = dict(row) | |
| location = get_location_by_id(entity["location_id"]) | |
| if entity["status"] == "active": | |
| last_active = datetime.fromisoformat(entity["last_active"]) | |
| if datetime.now() - last_active > timedelta(days=7): | |
| update_entity_status(entity["id"], "dormant") | |
| msg = f"{entity['name']} has grown quiet and entered dormancy." | |
| create_entry( | |
| world_day=world_day, | |
| entry_type="milestone", | |
| content=msg, | |
| entity_ids=[entity["id"]], | |
| is_milestone=True, | |
| title="Dormancy", | |
| ) | |
| milestones.append(msg) | |
| if entity["status"] == "dormant": | |
| last_active = datetime.fromisoformat(entity["last_active"]) | |
| days_dormant = (datetime.now() - last_active).days | |
| if days_dormant >= 30: | |
| update_entity_status(entity["id"], "legendary") | |
| msg = f"{entity['name']} has become Legendary β woven into the Realm's foundation." | |
| create_entry( | |
| world_day=world_day, | |
| entry_type="milestone", | |
| content=msg, | |
| entity_ids=[entity["id"]], | |
| is_milestone=True, | |
| title="Legendary Status", | |
| ) | |
| milestones.append(msg) | |
| entity["location_slug"] = location["slug"] if location else None | |
| eff_days = effective_days_in_realm(entity) | |
| if location and location["slug"] == "hollow-mountain": | |
| if eff_days >= 14 and not entity["wisdom_unlocked"]: | |
| add_tag(entity["id"], "wise") | |
| with db_session() as conn: | |
| conn.execute( | |
| "UPDATE entities SET wisdom_unlocked = 1 WHERE id = ?", | |
| (entity["id"],), | |
| ) | |
| msg = f"{entity['name']} earned wisdom in the Hollow Mountain." | |
| create_entry( | |
| world_day=world_day, | |
| entry_type="milestone", | |
| content=msg, | |
| entity_ids=[entity["id"]], | |
| is_milestone=True, | |
| title="Wisdom Earned", | |
| ) | |
| milestones.append(msg) | |
| return milestones | |