Added trading and quests, checkpoint push

This commit is contained in:
Joan
2026-02-08 20:18:42 +01:00
parent 8820cd897e
commit 70dc35b4b2
36 changed files with 3583 additions and 279 deletions

View File

@@ -33,7 +33,11 @@ from .routers import (
crafting,
loot,
statistics,
admin
statistics,
admin,
quests,
trade,
npcs
)
# Configure logging
@@ -79,7 +83,7 @@ async def lifespan(app: FastAPI):
print("✅ Redis listener started")
# Start background tasks (distributed via Redis locks)
tasks = await background_tasks.start_background_tasks(manager, LOCATIONS)
tasks = await background_tasks.start_background_tasks(manager, LOCATIONS, NPCS_DATA)
if tasks:
print(f"✅ Started {len(tasks)} background tasks in this worker")
else:
@@ -123,14 +127,43 @@ if IMAGES_DIR.exists():
else:
print(f"⚠️ Images directory not found: {IMAGES_DIR}")
# Initialize routers with game data dependencies
# Load Quests and NPCs Data at startup
QUESTS_DATA = {}
NPCS_DATA = {}
try:
print("🔄 Loading quests and NPCs...")
quests_path = Path("./gamedata/quests.json")
npcs_path = Path("./gamedata/static_npcs.json")
import json
if quests_path.exists():
with open(quests_path, "r") as f:
q_data = json.load(f)
QUESTS_DATA = q_data.get("quests", {})
print(f"✅ Loaded {len(QUESTS_DATA)} quests")
if npcs_path.exists():
with open(npcs_path, "r") as f:
n_data = json.load(f)
NPCS_DATA = n_data.get("static_npcs", {})
print(f"✅ Loaded {len(NPCS_DATA)} static NPCs")
except Exception as e:
print(f"❌ Error loading game data: {e}")
# Initialize routers with game data dependencies
game_routes.init_router_dependencies(LOCATIONS, ITEMS_MANAGER, WORLD, redis_manager)
combat.init_router_dependencies(LOCATIONS, ITEMS_MANAGER, WORLD, redis_manager)
combat.init_router_dependencies(LOCATIONS, ITEMS_MANAGER, WORLD, redis_manager, QUESTS_DATA)
equipment.init_router_dependencies(LOCATIONS, ITEMS_MANAGER, WORLD)
crafting.init_router_dependencies(LOCATIONS, ITEMS_MANAGER, WORLD)
loot.init_router_dependencies(LOCATIONS, ITEMS_MANAGER, WORLD)
statistics.init_router_dependencies(LOCATIONS, ITEMS_MANAGER, WORLD)
admin.init_router_dependencies(LOCATIONS, ITEMS_MANAGER, WORLD, IMAGES_DIR)
quests.init_router_dependencies(ITEMS_MANAGER, QUESTS_DATA, NPCS_DATA)
trade.init_router_dependencies(ITEMS_MANAGER, NPCS_DATA)
npcs.init_router_dependencies()
# Include all routers
app.include_router(auth.router)
@@ -142,6 +175,9 @@ app.include_router(crafting.router)
app.include_router(loot.router)
app.include_router(statistics.router)
app.include_router(admin.router)
app.include_router(quests.router)
app.include_router(trade.router)
app.include_router(npcs.router)
print("✅ All routers registered")