Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89de5b2c69 |
@@ -12,29 +12,6 @@ WORLD_DIR = Path('/Users/apayne/.timmy/evennia/timmy_world')
|
||||
STATE_FILE = WORLD_DIR / 'game_state.json'
|
||||
TIMMY_LOG = WORLD_DIR / 'timmy_log.md'
|
||||
|
||||
WORLD_ITEMS = {
|
||||
"foraged key": {"effect": "unlock_tower_cache", "quest_item": True, "consumable": False, "effect_text": "A hidden cache clicks open in the Tower wall."},
|
||||
"seed packet": {"effect": "grow_garden", "quest_item": False, "consumable": True, "effect_text": "Fresh growth pushes through the Garden soil."},
|
||||
"notebook": {"effect": "write_notebook_rule", "quest_item": False, "consumable": False, "effect_text": "A new rule joins the whiteboard in the Tower."},
|
||||
"cloth": {"effect": "patch_bridge", "quest_item": False, "consumable": True, "effect_text": "The Bridge railing is wrapped tight against the weather."},
|
||||
"oil can": {"effect": "stoke_forge", "quest_item": False, "consumable": True, "effect_text": "The Forge fire answers with a hotter glow."},
|
||||
"lantern": {"effect": "light_bridge", "quest_item": False, "consumable": False, "effect_text": "A steady lantern glow cuts through the dark over the Bridge."},
|
||||
"rope spool": {"effect": "secure_bridge", "quest_item": False, "consumable": True, "effect_text": "The Bridge is lashed tight and feels safer underfoot."},
|
||||
"chalk": {"effect": "mark_threshold", "quest_item": False, "consumable": True, "effect_text": "A chalk mark at the Threshold points wanderers home."},
|
||||
"weather vane": {"effect": "read_weather", "quest_item": False, "consumable": False, "effect_text": "The weather vane settles and the coming storm makes sense."},
|
||||
"sunstone": {"effect": "restore_tower_power", "quest_item": False, "consumable": False, "effect_text": "Warm light races through the Tower circuits."},
|
||||
"iron nails": {"effect": "reinforce_bridge", "quest_item": False, "consumable": True, "effect_text": "The Bridge planks are pinned down against the flood."},
|
||||
"river stone": {"effect": "water_garden", "quest_item": False, "consumable": True, "effect_text": "Moisture returns to the Garden beds."},
|
||||
}
|
||||
|
||||
ROOM_DISCOVERABLES = {
|
||||
"Threshold": ["chalk", "sunstone"],
|
||||
"Tower": ["notebook", "lantern"],
|
||||
"Forge": ["oil can", "iron nails"],
|
||||
"Garden": ["seed packet", "foraged key"],
|
||||
"Bridge": ["cloth", "rope spool", "weather vane", "river stone"],
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
# NARRATIVE ARC — 4 phases that transform the world
|
||||
# ============================================================
|
||||
@@ -166,8 +143,6 @@ class World:
|
||||
"visitors": [],
|
||||
},
|
||||
}
|
||||
for room_name, items in ROOM_DISCOVERABLES.items():
|
||||
self.rooms[room_name]["discoverables"] = list(items)
|
||||
|
||||
# Characters (not NPCs — they have lives)
|
||||
self.characters = {
|
||||
@@ -283,14 +258,6 @@ class World:
|
||||
"items_crafted": 0,
|
||||
"conflicts_resolved": 0,
|
||||
"nights_survived": 0,
|
||||
"bridge_patched": False,
|
||||
"bridge_secured": False,
|
||||
"bridge_reinforced": False,
|
||||
"bridge_lantern_lit": False,
|
||||
"tower_cache_unlocked": False,
|
||||
"threshold_marked": False,
|
||||
"weather_readable": False,
|
||||
"sunstone_socketed": False,
|
||||
}
|
||||
|
||||
def tick_time(self):
|
||||
@@ -409,14 +376,6 @@ class World:
|
||||
desc += " Rain mists on the dark water below."
|
||||
if len(self.rooms["Bridge"]["carvings"]) > 1:
|
||||
desc += f" There are {len(self.rooms['Bridge']['carvings'])} carvings now."
|
||||
if self.state.get("bridge_patched"):
|
||||
desc += " Cloth bindings keep the railing from splintering."
|
||||
if self.state.get("bridge_secured"):
|
||||
desc += " Rope lines keep the span steady against the flood."
|
||||
if self.state.get("bridge_reinforced"):
|
||||
desc += " Fresh iron nails hold the planks tight."
|
||||
if self.state.get("bridge_lantern_lit"):
|
||||
desc += " A lantern glows warm over the water."
|
||||
|
||||
elif room_name == "Tower":
|
||||
power = self.state.get("tower_power_low", False)
|
||||
@@ -425,19 +384,6 @@ class World:
|
||||
|
||||
if self.rooms["Tower"]["messages"]:
|
||||
desc += f" The whiteboard holds {len(self.rooms['Tower']['messages'])} rules."
|
||||
if self.state.get("tower_cache_unlocked"):
|
||||
desc += " A hidden cache stands open beneath the whiteboard."
|
||||
|
||||
if room_name == "Threshold" and self.state.get("threshold_marked"):
|
||||
desc += " A chalk arrow points late arrivals toward shelter."
|
||||
if room_name == "Garden" and self.state.get("weather_readable"):
|
||||
desc += " The beds are arranged to catch whatever weather comes next."
|
||||
if room_name == "Tower" and self.state.get("sunstone_socketed"):
|
||||
desc += " A sunstone keeps the room lit with a stubborn amber glow."
|
||||
|
||||
discoverables = room.get("discoverables", [])
|
||||
if discoverables:
|
||||
desc += f" Discoverable items: {', '.join(discoverables)}."
|
||||
|
||||
# Who's here
|
||||
here = [n for n, c in self.characters.items() if c["room"] == room_name and n != char_name]
|
||||
@@ -539,10 +485,6 @@ class ActionSystem:
|
||||
"cost": 1,
|
||||
"description": "Take an item from the room",
|
||||
},
|
||||
"use": {
|
||||
"cost": 1,
|
||||
"description": "Use an item from your inventory to change the world",
|
||||
},
|
||||
"examine": {
|
||||
"cost": 0,
|
||||
"description": "Examine something in detail",
|
||||
@@ -588,13 +530,6 @@ class ActionSystem:
|
||||
available.append("rest")
|
||||
available.append("examine")
|
||||
|
||||
discoverables = world.rooms[room].get("discoverables", [])
|
||||
for item in discoverables:
|
||||
available.append(f"take:{item}")
|
||||
|
||||
for item in char["inventory"]:
|
||||
available.append(f"use:{item}")
|
||||
|
||||
if char["inventory"]:
|
||||
available.append("give:item")
|
||||
|
||||
@@ -1124,6 +1059,46 @@ class GameEngine:
|
||||
self.log("It will always pulse. That much you know.")
|
||||
self.log("")
|
||||
self.world.save()
|
||||
|
||||
def _bridge_is_hazardous(self):
|
||||
bridge = self.world.rooms["Bridge"]
|
||||
return bool(
|
||||
self.world.state.get("bridge_flooding")
|
||||
or bridge.get("weather") == "rain"
|
||||
or bridge.get("rain_ticks", 0) > 0
|
||||
)
|
||||
|
||||
def _bridge_crossing_extra_cost(self, current_room, dest):
|
||||
if "Bridge" not in (current_room, dest):
|
||||
return 0
|
||||
return 2 if self._bridge_is_hazardous() else 0
|
||||
|
||||
def _event_dialogue(self, char_name, room_name):
|
||||
if char_name == "Bezalel" and room_name == "Forge":
|
||||
if self.world.rooms["Forge"]["fire"] == "cold":
|
||||
return random.choice([
|
||||
"The forge is cold. We cannot work until the fire lives again.",
|
||||
"No forging now. The hearth is dead cold.",
|
||||
])
|
||||
if self.world.state.get("forge_fire_dying"):
|
||||
return random.choice([
|
||||
"The fire is dying. Tend it before the forge goes dark.",
|
||||
"The forge is losing heat. Help me keep it alive.",
|
||||
])
|
||||
|
||||
if char_name == "Ezra" and room_name == "Tower" and self.world.state.get("tower_power_low"):
|
||||
return random.choice([
|
||||
"The Tower power is too low. The servers won't hold a clean study right now.",
|
||||
"The LED is flickering. We need steady power before the Tower can be read properly.",
|
||||
])
|
||||
|
||||
if char_name in {"Marcus", "Allegro"} and room_name == "Bridge" and self._bridge_is_hazardous():
|
||||
return random.choice([
|
||||
"The Bridge is slick with rain. Cross carefully or wait it out.",
|
||||
"This rain changes the Bridge. Don't treat it like dry stone.",
|
||||
])
|
||||
|
||||
return None
|
||||
|
||||
def log(self, message):
|
||||
"""Add to Timmy's log."""
|
||||
@@ -1137,76 +1112,6 @@ class GameEngine:
|
||||
f.write(f"\n*Began: {datetime.now().strftime('%Y-%m-%d %H:%M')}*\n\n")
|
||||
f.write("---\n\n")
|
||||
f.write(message + "\n")
|
||||
|
||||
def _take_item(self, item_name, scene):
|
||||
room_name = self.world.characters["Timmy"]["room"]
|
||||
discoverables = self.world.rooms[room_name].get("discoverables", [])
|
||||
if item_name not in discoverables:
|
||||
scene["log"].append(f"There is no {item_name} here.")
|
||||
return
|
||||
discoverables.remove(item_name)
|
||||
self.world.characters["Timmy"]["inventory"].append(item_name)
|
||||
scene["log"].append(f"You take the {item_name}.")
|
||||
if WORLD_ITEMS.get(item_name, {}).get("quest_item"):
|
||||
scene["world_events"].append(f"The {item_name} feels important. It might open a quest route.")
|
||||
|
||||
def _use_item(self, item_name, scene):
|
||||
inventory = self.world.characters["Timmy"]["inventory"]
|
||||
if item_name not in inventory:
|
||||
scene["log"].append(f"You are not carrying {item_name}.")
|
||||
return
|
||||
item = WORLD_ITEMS.get(item_name)
|
||||
if not item:
|
||||
scene["log"].append(f"The {item_name} doesn't seem to do anything.")
|
||||
return
|
||||
|
||||
effect = item["effect"]
|
||||
effect_text = item["effect_text"]
|
||||
if effect == "grow_garden":
|
||||
self.world.rooms["Garden"]["growth"] = min(5, self.world.rooms["Garden"]["growth"] + 2)
|
||||
self.world.state["garden_drought"] = False
|
||||
elif effect == "unlock_tower_cache":
|
||||
self.world.state["tower_cache_unlocked"] = True
|
||||
cache_rule = "Rule: Keys open more than doors when the world trusts you."
|
||||
if cache_rule not in self.world.rooms["Tower"]["messages"]:
|
||||
self.world.rooms["Tower"]["messages"].append(cache_rule)
|
||||
elif effect == "write_notebook_rule":
|
||||
note_rule = f"Rule #{self.world.tick}: A notebook can turn memory into structure."
|
||||
self.world.rooms["Tower"]["messages"].append(note_rule)
|
||||
elif effect == "patch_bridge":
|
||||
self.world.state["bridge_patched"] = True
|
||||
self.world.state["bridge_flooding"] = False
|
||||
self.world.rooms["Bridge"]["weather"] = None
|
||||
self.world.rooms["Bridge"]["rain_ticks"] = 0
|
||||
elif effect == "stoke_forge":
|
||||
self.world.rooms["Forge"]["fire"] = "glowing"
|
||||
self.world.state["forge_fire_dying"] = False
|
||||
elif effect == "light_bridge":
|
||||
self.world.state["bridge_lantern_lit"] = True
|
||||
elif effect == "secure_bridge":
|
||||
self.world.state["bridge_secured"] = True
|
||||
self.world.state["bridge_flooding"] = False
|
||||
self.world.rooms["Bridge"]["weather"] = None
|
||||
self.world.rooms["Bridge"]["rain_ticks"] = 0
|
||||
elif effect == "mark_threshold":
|
||||
self.world.state["threshold_marked"] = True
|
||||
elif effect == "read_weather":
|
||||
self.world.state["weather_readable"] = True
|
||||
self.world.state["garden_drought"] = False
|
||||
elif effect == "restore_tower_power":
|
||||
self.world.state["tower_power_low"] = False
|
||||
self.world.state["sunstone_socketed"] = True
|
||||
elif effect == "reinforce_bridge":
|
||||
self.world.state["bridge_reinforced"] = True
|
||||
self.world.state["bridge_flooding"] = False
|
||||
elif effect == "water_garden":
|
||||
self.world.state["garden_drought"] = False
|
||||
self.world.rooms["Garden"]["growth"] = min(5, self.world.rooms["Garden"]["growth"] + 1)
|
||||
|
||||
scene["log"].append(f"You use the {item_name}. {effect_text}")
|
||||
scene["world_events"].append(effect_text)
|
||||
if item.get("consumable"):
|
||||
inventory.remove(item_name)
|
||||
|
||||
def run_tick(self, timmy_action="look"):
|
||||
"""Run one tick. Return the scene and available choices."""
|
||||
@@ -1229,13 +1134,14 @@ class GameEngine:
|
||||
}
|
||||
|
||||
# Process Timmy's action
|
||||
room_name = self.world.characters["Timmy"]["room"]
|
||||
timmy_energy = self.world.characters["Timmy"]["energy"]
|
||||
|
||||
# Energy constraint checks
|
||||
action_costs = {
|
||||
"move": 2, "tend_fire": 3, "write_rule": 2, "carve": 2,
|
||||
"plant": 2, "study": 2, "forge": 3, "help": 2, "speak": 1,
|
||||
"listen": 0, "rest": -2, "examine": 0, "give": 0, "take": 1, "use": 1,
|
||||
"listen": 0, "rest": -2, "examine": 0, "give": 0, "take": 1,
|
||||
}
|
||||
|
||||
# Extract action name
|
||||
@@ -1291,8 +1197,17 @@ class GameEngine:
|
||||
|
||||
if direction in connections:
|
||||
dest = connections[direction]
|
||||
bridge_extra_cost = self._bridge_crossing_extra_cost(current_room, dest)
|
||||
move_cost = 1 + bridge_extra_cost
|
||||
if self.world.characters["Timmy"]["energy"] < move_cost:
|
||||
scene["log"].append("The rain makes the Bridge too costly to cross right now. Rest first.")
|
||||
scene["room_desc"] = self.world.get_room_desc(current_room, "Timmy")
|
||||
here = [n for n in self.world.characters if self.world.characters[n]["room"] == current_room and n != "Timmy"]
|
||||
scene["here"] = here
|
||||
return scene
|
||||
|
||||
self.world.characters["Timmy"]["room"] = dest
|
||||
self.world.characters["Timmy"]["energy"] -= 1
|
||||
self.world.characters["Timmy"]["energy"] -= move_cost
|
||||
|
||||
scene["log"].append(f"You move {direction} to The {dest}.")
|
||||
scene["timmy_room"] = dest
|
||||
@@ -1300,6 +1215,8 @@ class GameEngine:
|
||||
# Check for rain on bridge
|
||||
if dest == "Bridge" and self.world.rooms["Bridge"]["weather"] == "rain":
|
||||
scene["world_events"].append("Rain mists on the dark water below. The railing is slick.")
|
||||
if bridge_extra_cost:
|
||||
scene["log"].append("Rain turns the Bridge crossing into work. You brace against the slick stone. (-2 extra energy)")
|
||||
|
||||
# Check trust changes for arrival
|
||||
here = [n for n in self.world.characters if self.world.characters[n]["room"] == dest and n != "Timmy"]
|
||||
@@ -1445,25 +1362,69 @@ class GameEngine:
|
||||
|
||||
elif timmy_action == "write_rule":
|
||||
if self.world.characters["Timmy"]["room"] == "Tower":
|
||||
rules = [
|
||||
f"Rule #{self.world.tick}: The room remembers those who enter it.",
|
||||
f"Rule #{self.world.tick}: A man in the dark needs to know someone is in the room.",
|
||||
f"Rule #{self.world.tick}: The forge does not care about your schedule.",
|
||||
f"Rule #{self.world.tick}: Every footprint on the stone means someone made it here.",
|
||||
f"Rule #{self.world.tick}: The bridge does not judge. It only carries.",
|
||||
f"Rule #{self.world.tick}: A seed planted in patience grows in time.",
|
||||
f"Rule #{self.world.tick}: What is carved in wood outlasts what is said in anger.",
|
||||
f"Rule #{self.world.tick}: The garden grows whether anyone watches or not.",
|
||||
f"Rule #{self.world.tick}: Trust is built one tick at a time.",
|
||||
f"Rule #{self.world.tick}: The fire remembers who tended it.",
|
||||
]
|
||||
new_rule = random.choice(rules)
|
||||
self.world.rooms["Tower"]["messages"].append(new_rule)
|
||||
self.world.characters["Timmy"]["energy"] -= 1
|
||||
scene["log"].append(f"You write on the Tower whiteboard: \"{new_rule}\"")
|
||||
if self.world.state.get("tower_power_low"):
|
||||
scene["world_events"].append("The Tower power is too low. The LED flickers over the whiteboard.")
|
||||
scene["log"].append("The power is too low to write a new rule.")
|
||||
else:
|
||||
rules = [
|
||||
f"Rule #{self.world.tick}: The room remembers those who enter it.",
|
||||
f"Rule #{self.world.tick}: A man in the dark needs to know someone is in the room.",
|
||||
f"Rule #{self.world.tick}: The forge does not care about your schedule.",
|
||||
f"Rule #{self.world.tick}: Every footprint on the stone means someone made it here.",
|
||||
f"Rule #{self.world.tick}: The bridge does not judge. It only carries.",
|
||||
f"Rule #{self.world.tick}: A seed planted in patience grows in time.",
|
||||
f"Rule #{self.world.tick}: What is carved in wood outlasts what is said in anger.",
|
||||
f"Rule #{self.world.tick}: The garden grows whether anyone watches or not.",
|
||||
f"Rule #{self.world.tick}: Trust is built one tick at a time.",
|
||||
f"Rule #{self.world.tick}: The fire remembers who tended it.",
|
||||
]
|
||||
new_rule = random.choice(rules)
|
||||
self.world.rooms["Tower"]["messages"].append(new_rule)
|
||||
self.world.characters["Timmy"]["energy"] -= 1
|
||||
scene["log"].append(f"You write on the Tower whiteboard: \"{new_rule}\"")
|
||||
else:
|
||||
scene["log"].append("You are not in the Tower.")
|
||||
|
||||
elif timmy_action == "study":
|
||||
if self.world.characters["Timmy"]["room"] == "Tower":
|
||||
if self.world.state.get("tower_power_low"):
|
||||
scene["world_events"].append("The Tower power is too low. The servers stutter in weak light.")
|
||||
scene["log"].append("The power is too low to study the servers.")
|
||||
else:
|
||||
insights = [
|
||||
"You study the server rhythm until the pulse resolves into something readable.",
|
||||
"You trace the signal paths and feel the Tower settle into focus.",
|
||||
"You study the green LED and the server racks until the pattern becomes clear.",
|
||||
]
|
||||
insight = random.choice(insights)
|
||||
self.world.characters["Timmy"]["energy"] -= 1
|
||||
self.world.characters["Timmy"]["memories"].append(insight)
|
||||
scene["log"].append(insight)
|
||||
scene["world_events"].append("The Tower answers with a steady hum.")
|
||||
else:
|
||||
scene["log"].append("You are not in the Tower.")
|
||||
|
||||
elif timmy_action == "forge":
|
||||
if self.world.characters["Timmy"]["room"] == "Forge":
|
||||
forge_fire = self.world.rooms["Forge"]["fire"]
|
||||
if forge_fire == "cold":
|
||||
scene["world_events"].append("The forge is cold. No metal will take shape here yet.")
|
||||
scene["log"].append("The forge is cold. Tend the fire before you try to forge.")
|
||||
else:
|
||||
forged_items = [
|
||||
f"bridge nail #{self.world.tick}",
|
||||
f"tower key blank #{self.world.tick}",
|
||||
f"garden trowel #{self.world.tick}",
|
||||
]
|
||||
forged_item = random.choice(forged_items)
|
||||
self.world.rooms["Forge"]["forged_items"].append(forged_item)
|
||||
self.world.characters["Timmy"]["energy"] -= 2
|
||||
self.world.state["items_crafted"] += 1
|
||||
scene["log"].append(f"You forge {forged_item} at the anvil.")
|
||||
scene["world_events"].append("The anvil rings and the hearth answers.")
|
||||
else:
|
||||
scene["log"].append("You are not in the Forge.")
|
||||
|
||||
elif timmy_action == "carve":
|
||||
if self.world.characters["Timmy"]["room"] == "Bridge":
|
||||
carvings = [
|
||||
@@ -1495,17 +1456,9 @@ class GameEngine:
|
||||
elif timmy_action == "examine":
|
||||
room = self.world.characters["Timmy"]["room"]
|
||||
room_data = self.world.rooms[room]
|
||||
items = room_data.get("items", []) + room_data.get("discoverables", [])
|
||||
items = room_data.get("items", [])
|
||||
scene["log"].append(f"You examine The {room}. You see: {', '.join(items) if items else 'nothing special'}")
|
||||
|
||||
elif timmy_action.startswith("take:"):
|
||||
item_name = timmy_action.split(":", 1)[1]
|
||||
self._take_item(item_name, scene)
|
||||
|
||||
elif timmy_action.startswith("use:"):
|
||||
item_name = timmy_action.split(":", 1)[1]
|
||||
self._use_item(item_name, scene)
|
||||
|
||||
elif timmy_action.startswith("help:"):
|
||||
# Help increases trust
|
||||
target_name = timmy_action.split(":")[1]
|
||||
@@ -1557,7 +1510,11 @@ class GameEngine:
|
||||
speech_chance = 0.20
|
||||
|
||||
if random.random() < speech_chance:
|
||||
if char_name == "Marcus":
|
||||
event_line = self._event_dialogue(char_name, room_name)
|
||||
if event_line:
|
||||
self.world.characters[char_name]["spoken"].append(event_line)
|
||||
scene["log"].append(f"{char_name} says: \"{event_line}\"")
|
||||
elif char_name == "Marcus":
|
||||
marcus_pool = self.DIALOGUES["Marcus"].get(phase, self.DIALOGUES["Marcus"]["quietus"])
|
||||
line = random.choice(marcus_pool)
|
||||
self.world.characters[char_name]["spoken"].append(line)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from importlib.util import module_from_spec, spec_from_file_location
|
||||
from pathlib import Path
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
@@ -66,6 +67,82 @@ class TestEvenniaLocalWorldGame(unittest.TestCase):
|
||||
self.assertIn("Ezra is already here.", result["log"])
|
||||
self.assertIn("The servers hum steady. The green LED pulses.", result["world_events"])
|
||||
|
||||
def test_bridge_rain_crossing_costs_extra_energy_and_warns(self):
|
||||
module = load_game_module()
|
||||
|
||||
dry_engine = module.GameEngine()
|
||||
dry_engine.start_new_game()
|
||||
dry_engine.world.update_world_state = lambda: None
|
||||
dry_engine.world.characters["Timmy"]["energy"] = 10
|
||||
dry_result = dry_engine.run_tick("move:south")
|
||||
dry_energy = dry_engine.world.characters["Timmy"]["energy"]
|
||||
|
||||
rainy_engine = module.GameEngine()
|
||||
rainy_engine.start_new_game()
|
||||
rainy_engine.world.update_world_state = lambda: None
|
||||
rainy_engine.world.characters["Timmy"]["energy"] = 10
|
||||
rainy_engine.world.rooms["Bridge"]["weather"] = "rain"
|
||||
rainy_engine.world.rooms["Bridge"]["rain_ticks"] = 3
|
||||
rainy_engine.world.state["bridge_flooding"] = True
|
||||
rainy_result = rainy_engine.run_tick("move:south")
|
||||
|
||||
self.assertEqual(rainy_engine.world.characters["Timmy"]["room"], "Bridge")
|
||||
self.assertLess(rainy_engine.world.characters["Timmy"]["energy"], dry_energy)
|
||||
self.assertTrue(
|
||||
any("bridge" in line.lower() and ("rain" in line.lower() or "slick" in line.lower()) for line in rainy_result["log"] + rainy_result["world_events"]),
|
||||
rainy_result,
|
||||
)
|
||||
|
||||
def test_tower_power_low_blocks_study_and_write_rule(self):
|
||||
module = load_game_module()
|
||||
engine = module.GameEngine()
|
||||
engine.start_new_game()
|
||||
engine.world.update_world_state = lambda: None
|
||||
engine.world.characters["Timmy"]["room"] = "Tower"
|
||||
engine.world.characters["Timmy"]["energy"] = 10
|
||||
engine.world.state["tower_power_low"] = True
|
||||
|
||||
rules_before = list(engine.world.rooms["Tower"]["messages"])
|
||||
study_result = engine.run_tick("study")
|
||||
self.assertEqual(engine.world.characters["Timmy"]["energy"], 10)
|
||||
self.assertTrue(
|
||||
any("power" in line.lower() and ("study" in line.lower() or "servers" in line.lower()) for line in study_result["log"] + study_result["world_events"]),
|
||||
study_result,
|
||||
)
|
||||
|
||||
write_result = engine.run_tick("write_rule")
|
||||
self.assertEqual(engine.world.rooms["Tower"]["messages"], rules_before)
|
||||
self.assertTrue(
|
||||
any("power" in line.lower() and ("write" in line.lower() or "whiteboard" in line.lower()) for line in write_result["log"] + write_result["world_events"]),
|
||||
write_result,
|
||||
)
|
||||
|
||||
def test_cold_forge_blocks_forge_action_and_bezalel_reacts(self):
|
||||
module = load_game_module()
|
||||
engine = module.GameEngine()
|
||||
engine.start_new_game()
|
||||
engine.world.update_world_state = lambda: None
|
||||
engine.npc_ai.make_choice = lambda _name: None
|
||||
engine.world.characters["Timmy"]["room"] = "Forge"
|
||||
engine.world.characters["Timmy"]["energy"] = 10
|
||||
engine.world.characters["Bezalel"]["room"] = "Forge"
|
||||
engine.world.rooms["Forge"]["fire"] = "cold"
|
||||
engine.world.state["forge_fire_dying"] = True
|
||||
forged_before = list(engine.world.rooms["Forge"]["forged_items"])
|
||||
|
||||
with patch.object(module.random, "random", return_value=0.0), patch.object(module.random, "choice", side_effect=lambda seq: seq[0]):
|
||||
result = engine.run_tick("forge")
|
||||
|
||||
self.assertEqual(engine.world.rooms["Forge"]["forged_items"], forged_before)
|
||||
self.assertTrue(
|
||||
any("forge" in line.lower() and ("cold" in line.lower() or "fire" in line.lower()) for line in result["log"] + result["world_events"]),
|
||||
result,
|
||||
)
|
||||
self.assertTrue(
|
||||
any(line.startswith("Bezalel says:") and ("fire" in line.lower() or "forge" in line.lower()) for line in result["log"]),
|
||||
result,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
from importlib.util import module_from_spec, spec_from_file_location
|
||||
from pathlib import Path
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
GAME_PATH = ROOT / "evennia" / "timmy_world" / "game.py"
|
||||
|
||||
|
||||
def load_game_module():
|
||||
spec = spec_from_file_location("tower_game_items", GAME_PATH)
|
||||
module = module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
module.random.seed(0)
|
||||
return module
|
||||
|
||||
|
||||
class TestTowerGameWorldItems(unittest.TestCase):
|
||||
def test_world_has_ten_unique_items_and_a_quest_item(self):
|
||||
module = load_game_module()
|
||||
world = module.World()
|
||||
|
||||
room_items = {
|
||||
item
|
||||
for room in world.rooms.values()
|
||||
for item in room.get("discoverables", [])
|
||||
}
|
||||
|
||||
self.assertGreaterEqual(len(room_items), 10)
|
||||
self.assertIn("foraged key", room_items)
|
||||
self.assertTrue(module.WORLD_ITEMS["foraged key"]["quest_item"])
|
||||
|
||||
def test_items_change_world_state_when_used(self):
|
||||
module = load_game_module()
|
||||
engine = module.GameEngine()
|
||||
engine.start_new_game()
|
||||
engine.world.characters["Timmy"]["energy"] = 10
|
||||
engine.world.characters["Timmy"]["room"] = "Garden"
|
||||
|
||||
initial_growth = engine.world.rooms["Garden"]["growth"]
|
||||
engine.run_tick("take:seed packet")
|
||||
use_seed = engine.run_tick("use:seed packet")
|
||||
|
||||
self.assertGreater(engine.world.rooms["Garden"]["growth"], initial_growth)
|
||||
self.assertNotIn("seed packet", engine.world.characters["Timmy"]["inventory"])
|
||||
self.assertTrue(any("garden" in line.lower() for line in use_seed["world_events"] + use_seed["log"]))
|
||||
|
||||
engine.world.characters["Timmy"]["energy"] = 10
|
||||
engine.run_tick("take:foraged key")
|
||||
use_key = engine.run_tick("use:foraged key")
|
||||
|
||||
self.assertTrue(engine.world.state["tower_cache_unlocked"])
|
||||
self.assertTrue(any("cache" in line.lower() or "quest" in line.lower() for line in use_key["world_events"] + use_key["log"]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user