Some checks failed
Release / release (push) Has been cancelled
Full-stack dashboard for controlling, automating, and analyzing Artifacts MMO characters via the game's HTTP API. Backend (FastAPI): - Async Artifacts API client with rate limiting and retry - 6 automation strategies (combat, gathering, crafting, trading, task, leveling) - Automation engine with runner, manager, cooldown tracker, pathfinder - WebSocket relay (game server -> frontend) - Game data cache, character snapshots, price history, analytics - 9 API routers, 7 database tables, 3 Alembic migrations - 108 unit tests Frontend (Next.js 15 + shadcn/ui): - Live character dashboard with HP/XP bars and cooldowns - Character detail with stats, equipment, inventory, skills, manual actions - Automation management with live log streaming - Interactive canvas map with content-type coloring and zoom/pan - Bank management, Grand Exchange with price charts - Events, logs, analytics pages with Recharts - WebSocket auto-reconnect with query cache invalidation - Settings page, error boundaries, dark theme Infrastructure: - Docker Compose (dev + prod) - GitHub Actions CI/CD - Documentation (Architecture, Automation, Deployment, API)
102 lines
3.2 KiB
Python
102 lines
3.2 KiB
Python
"""Bank service providing enriched bank data with item details."""
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
from app.schemas.game import ItemSchema
|
|
from app.services.artifacts_client import ArtifactsClient
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class BankService:
|
|
"""High-level service for bank operations with enriched data."""
|
|
|
|
async def get_contents(
|
|
self,
|
|
client: ArtifactsClient,
|
|
items_cache: list[ItemSchema] | None = None,
|
|
) -> dict[str, Any]:
|
|
"""Return bank contents enriched with item details from the cache.
|
|
|
|
Parameters
|
|
----------
|
|
client:
|
|
The artifacts API client.
|
|
items_cache:
|
|
Optional list of all items from the game data cache.
|
|
If provided, bank items are enriched with name, type, level, etc.
|
|
|
|
Returns
|
|
-------
|
|
Dict with "details" (bank metadata) and "items" (enriched item list).
|
|
"""
|
|
details = await client.get_bank_details()
|
|
raw_items = await client.get_all_bank_items()
|
|
|
|
# Build item lookup if cache is provided
|
|
item_lookup: dict[str, ItemSchema] = {}
|
|
if items_cache:
|
|
item_lookup = {item.code: item for item in items_cache}
|
|
|
|
enriched_items: list[dict[str, Any]] = []
|
|
for bank_item in raw_items:
|
|
code = bank_item.get("code", "")
|
|
quantity = bank_item.get("quantity", 0)
|
|
|
|
enriched: dict[str, Any] = {
|
|
"code": code,
|
|
"quantity": quantity,
|
|
}
|
|
|
|
# Enrich with item details if available
|
|
item_data = item_lookup.get(code)
|
|
if item_data is not None:
|
|
enriched["name"] = item_data.name
|
|
enriched["type"] = item_data.type
|
|
enriched["subtype"] = item_data.subtype
|
|
enriched["level"] = item_data.level
|
|
enriched["description"] = item_data.description
|
|
enriched["effects"] = [
|
|
{"name": e.name, "value": e.value}
|
|
for e in item_data.effects
|
|
]
|
|
else:
|
|
enriched["name"] = code
|
|
enriched["type"] = ""
|
|
enriched["subtype"] = ""
|
|
enriched["level"] = 0
|
|
enriched["description"] = ""
|
|
enriched["effects"] = []
|
|
|
|
enriched_items.append(enriched)
|
|
|
|
return {
|
|
"details": details,
|
|
"items": enriched_items,
|
|
}
|
|
|
|
async def get_summary(
|
|
self,
|
|
client: ArtifactsClient,
|
|
) -> dict[str, Any]:
|
|
"""Return a summary of bank contents: gold, item count, total slots.
|
|
|
|
Returns
|
|
-------
|
|
Dict with "gold", "item_count", "used_slots", and "total_slots".
|
|
"""
|
|
details = await client.get_bank_details()
|
|
raw_items = await client.get_all_bank_items()
|
|
|
|
gold = details.get("gold", 0)
|
|
total_slots = details.get("slots", 0)
|
|
used_slots = len(raw_items)
|
|
item_count = sum(item.get("quantity", 0) for item in raw_items)
|
|
|
|
return {
|
|
"gold": gold,
|
|
"item_count": item_count,
|
|
"used_slots": used_slots,
|
|
"total_slots": total_slots,
|
|
}
|