API merge final

This commit is contained in:
KuMiShi
2026-01-30 16:11:47 +01:00
parent e655de8f54
commit 351f676611
9 changed files with 370 additions and 105 deletions

View File

@@ -1,18 +1,26 @@
# Game imports
from dice import Dice
from game import Game
from serializable import Serializable
from events.event import Event
# Native imports
from typing import Any, Dict
import logging
import httpx
from mcp.server.fastmcp import FastMCP
from dice import Dice
from player import Player
from item import Item
from game import Game
from npc import NPC
from serializable import Serializable
import json
import os
# Constants
HISTORY_FILE = "game_history.json"
SAVE_PATH = "save_"
# Global Parameters
mcp = FastMCP("wyvern-castle")
game: Game = None
# Logging config
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
@@ -21,10 +29,7 @@ logging.basicConfig(
]
)
# Constants
HISTORY_FILE = "game_history.json"
SAVE_PATH = "save_"
# SAVING & LOADING GAME STATE
@mcp.tool()
async def load_game(slot:int):
"""Loads an already existing game.
@@ -69,6 +74,7 @@ async def save_game(slot:int):
"error": str(e)
}
@DeprecationWarning
def append_to_history(event: Dict[str, Any]):
"""Append a game event to the history file."""
history = []
@@ -82,6 +88,7 @@ def append_to_history(event: Dict[str, Any]):
with open(HISTORY_FILE, "w", encoding="utf-8") as f:
json.dump(history, f, ensure_ascii=False, indent=2)
@DeprecationWarning
def read_history() -> list:
"""Read the game history from the file."""
if os.path.exists(HISTORY_FILE):
@@ -92,6 +99,26 @@ def read_history() -> list:
return []
return []
# EVENTS TOOLS
@mcp.tool()
async def start_event(location:str, initial_description:str, entity_list:list[str]):
new_event = Event(location=location, initial_description=initial_description, entities=entity_list)
game.add_event(new_event)
@mcp.tool()
async def perform_action():
pass
# ITEM TOOLS
@mcp.tool()
async def create_item():
pass
@mcp.tool()
async def add_item_to_entity():
pass
# OTHER UTILS
@mcp.tool()
async def throw_a_dice(n_faces: int) -> Any:
"""Throw a dice with n faces. If n==2 its a coin toss.
@@ -111,7 +138,9 @@ async def throw_a_dice(n_faces: int) -> Any:
else:
return dice.roll()
@mcp.tool()
async def get_entity_status():
pass
@mcp.tool()
async def create_player(name: str, strength: int, dexterity: int, intelligence: int, wisdom: int, charisma: int, hp: int, armor: int, speed: int, item: str = "") -> Dict[str, Any]: