61 lines
2.3 KiB
Python
61 lines
2.3 KiB
Python
import json
|
|
import asyncio
|
|
import os
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
|
from sqlalchemy import text
|
|
import time
|
|
|
|
async def main():
|
|
# Connect to DB using sqlalchemy
|
|
url = "postgresql+asyncpg://admin:password@echoes_of_the_ashes_db:5432/echoesoftheashes"
|
|
engine = create_async_engine(url)
|
|
|
|
try:
|
|
async with engine.begin() as conn:
|
|
# Get Jocaru ID
|
|
res = await conn.execute(text("SELECT id, location_id FROM characters WHERE name ILIKE 'Jocaru'"))
|
|
row = res.first()
|
|
if not row:
|
|
print("Jocaru not found.")
|
|
return
|
|
|
|
pid, loc = row[0], row[1]
|
|
print(f"Player Jocaru found (ID {pid}) at {loc}")
|
|
|
|
# Buff to level 50
|
|
await conn.execute(text("UPDATE characters SET level = 50, xp = 50000, max_hp = 500, hp = 500, max_stamina = 200, stamina = 200 WHERE id = :pid"), {"pid": pid})
|
|
print("Set Jocaru to level 50 metrics.")
|
|
|
|
# Give items directly via SQL
|
|
items = [
|
|
('reinforced_pack', 1),
|
|
('reinforced_bat', 1),
|
|
('combat_knife', 1),
|
|
('first_aid_kit', 10),
|
|
('mystery_pills', 5),
|
|
('energy_bar', 10)
|
|
]
|
|
for iid, qty in items:
|
|
await conn.execute(
|
|
text("INSERT INTO inventory (character_id, item_id, quantity) VALUES (:pid, :iid, :qty)"),
|
|
{"pid": pid, "iid": iid, "qty": qty}
|
|
)
|
|
print("Gave items to Jocaru.")
|
|
|
|
# Spawn enemies
|
|
now = time.time()
|
|
despawn = now + 86400
|
|
|
|
enemies = ['raider_scout'] * 5 + ['feral_dog'] * 5 + ['mutant_rat'] * 5 + ['test_boss'] * 2
|
|
for eid in enemies:
|
|
await conn.execute(
|
|
text("INSERT INTO wandering_enemies (npc_id, location_id, spawn_timestamp, despawn_timestamp) VALUES (:nid, :loc, :start, :end)"),
|
|
{"nid": eid, "loc": loc, "start": now, "end": despawn}
|
|
)
|
|
print(f"Spawned {len(enemies)} enemies at {loc}.")
|
|
|
|
except Exception as e:
|
|
print(f"Error accessing DB natively: {e}")
|
|
|
|
asyncio.run(main())
|