Compare commits
11 Commits
17e15b47eb
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 0ea67f62e2 | |||
| 2690d538f4 | |||
| c9afd53ca7 | |||
| 5ff452ba2c | |||
| 0217d6636f | |||
| 3d6b1927bf | |||
| ab5a05aa69 | |||
| 23106bca28 | |||
| aa6125d8ad | |||
| adc2873260 | |||
| ed27f338a2 |
18
activate_with_env.sh
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Helper script to activate venv and set MariaDB environment variables
|
||||||
|
|
||||||
|
# Activate virtual environment
|
||||||
|
source .venv/bin/activate
|
||||||
|
|
||||||
|
# Find and set MARIADB_CONFIG
|
||||||
|
MARIADB_CONFIG_PATH=$(find /opt/homebrew -name mariadb_config 2>/dev/null | head -1)
|
||||||
|
|
||||||
|
if [ -n "$MARIADB_CONFIG_PATH" ]; then
|
||||||
|
export MARIADB_CONFIG="$MARIADB_CONFIG_PATH"
|
||||||
|
echo "✓ MARIADB_CONFIG set to: $MARIADB_CONFIG_PATH"
|
||||||
|
else
|
||||||
|
echo "⚠ Warning: mariadb_config not found. Install with: brew install mariadb-connector-c"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Virtual environment activated and ready to use!"
|
||||||
|
|
||||||
53
api.py
@@ -1,53 +0,0 @@
|
|||||||
from flask import Flask, redirect, url_for, render_template, session, request, copy_current_request_context, jsonify
|
|
||||||
from datetime import timedelta
|
|
||||||
import os
|
|
||||||
from basegame import *
|
|
||||||
|
|
||||||
|
|
||||||
import flask
|
|
||||||
|
|
||||||
app = flask.Flask(__name__)
|
|
||||||
app.config["DEBUG"] = True
|
|
||||||
app.secret_key = "hi"
|
|
||||||
playerNameList = []
|
|
||||||
|
|
||||||
@app.route('/', methods=['GET'])
|
|
||||||
def home():
|
|
||||||
return "<a href=\"login\">Login</a>"
|
|
||||||
|
|
||||||
@app.route('/playerlist', methods=['GET'])
|
|
||||||
def playerlist():
|
|
||||||
fuckyou = json.dumps(playerNameList)
|
|
||||||
print(fuckyou)
|
|
||||||
return fuckyou
|
|
||||||
|
|
||||||
@app.route("/login", methods=["POST", "GET"])
|
|
||||||
def login():
|
|
||||||
if request.method == "POST":
|
|
||||||
session.permanent = True # <--- makes the permanent session
|
|
||||||
user = request.form["nm"]
|
|
||||||
session["name"] = user
|
|
||||||
playerNameList.append(user)
|
|
||||||
return redirect(url_for("playerlist"))
|
|
||||||
else:
|
|
||||||
if "name" in session:
|
|
||||||
return redirect(url_for("playerlist"))
|
|
||||||
|
|
||||||
return render_template("login.html")
|
|
||||||
|
|
||||||
@app.route("/user")
|
|
||||||
def user():
|
|
||||||
if "user" in session:
|
|
||||||
user = session["user"]
|
|
||||||
return f"<h1>{user}</h1>"
|
|
||||||
else:
|
|
||||||
return redirect(url_for("login"))
|
|
||||||
|
|
||||||
@app.route("/logout")
|
|
||||||
def logout():
|
|
||||||
session.pop("user", None)
|
|
||||||
return redirect(url_for("login"))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.run(debug=True, host='0.0.0.0')
|
|
||||||
23352
b0-valeria-card-kingdoms-rulebook.pdf
Normal file
399
cards.py
Normal file
@@ -0,0 +1,399 @@
|
|||||||
|
def _coerce_int(val, default=0):
|
||||||
|
if val is None:
|
||||||
|
return default
|
||||||
|
if isinstance(val, bool):
|
||||||
|
return int(val)
|
||||||
|
try:
|
||||||
|
return int(val)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
class Card:
|
||||||
|
def __init__(self):
|
||||||
|
self.name = ""
|
||||||
|
self.is_visible = False
|
||||||
|
self.is_accessible = False
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return {
|
||||||
|
"name": self.name,
|
||||||
|
"is_visible": self.is_visible,
|
||||||
|
"is_accessible": self.is_accessible,
|
||||||
|
}
|
||||||
|
|
||||||
|
def toggle_visibility(self, toggle: bool = True):
|
||||||
|
self.is_visible = toggle
|
||||||
|
|
||||||
|
def toggle_accessibility(self, toggle: bool = True):
|
||||||
|
self.is_accessible = toggle
|
||||||
|
|
||||||
|
|
||||||
|
class Starter(Card):
|
||||||
|
def __init__(self, starter_id, name, roll_match1, roll_match2, gold_payout_on_turn, gold_payout_off_turn,
|
||||||
|
strength_payout_on_turn, strength_payout_off_turn, magic_payout_on_turn, magic_payout_off_turn,
|
||||||
|
has_special_payout_on_turn, has_special_payout_off_turn, special_payout_on_turn,
|
||||||
|
special_payout_off_turn, expansion):
|
||||||
|
super().__init__()
|
||||||
|
self.starter_id = starter_id
|
||||||
|
self.name = name
|
||||||
|
self.roll_match1 = roll_match1
|
||||||
|
self.roll_match2 = roll_match2
|
||||||
|
self.gold_payout_on_turn = gold_payout_on_turn
|
||||||
|
self.gold_payout_off_turn = gold_payout_off_turn
|
||||||
|
self.strength_payout_on_turn = strength_payout_on_turn
|
||||||
|
self.strength_payout_off_turn = strength_payout_off_turn
|
||||||
|
self.magic_payout_on_turn = magic_payout_on_turn
|
||||||
|
self.magic_payout_off_turn = magic_payout_off_turn
|
||||||
|
self.has_special_payout_on_turn = has_special_payout_on_turn
|
||||||
|
self.has_special_payout_off_turn = has_special_payout_off_turn
|
||||||
|
self.special_payout_on_turn = special_payout_on_turn
|
||||||
|
self.special_payout_off_turn = special_payout_off_turn
|
||||||
|
self.expansion = expansion
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return {
|
||||||
|
"starter_id": self.starter_id,
|
||||||
|
"name": self.name,
|
||||||
|
"roll_match1": self.roll_match1,
|
||||||
|
"roll_match2": self.roll_match2,
|
||||||
|
"gold_payout_on_turn": self.gold_payout_on_turn,
|
||||||
|
"gold_payout_off_turn": self.gold_payout_off_turn,
|
||||||
|
"strength_payout_on_turn": self.strength_payout_on_turn,
|
||||||
|
"strength_payout_off_turn": self.strength_payout_off_turn,
|
||||||
|
"magic_payout_on_turn": self.magic_payout_on_turn,
|
||||||
|
"magic_payout_off_turn": self.magic_payout_off_turn,
|
||||||
|
"has_special_payout_on_turn": self.has_special_payout_on_turn,
|
||||||
|
"has_special_payout_off_turn": self.has_special_payout_off_turn,
|
||||||
|
"special_payout_on_turn": self.special_payout_on_turn,
|
||||||
|
"special_payout_off_turn": self.special_payout_off_turn,
|
||||||
|
"expansion": self.expansion
|
||||||
|
}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, data):
|
||||||
|
return cls(data["starter_id"], data["name"], data["roll_match1"], data["roll_match2"],
|
||||||
|
data["gold_payout_on_turn"], data["gold_payout_off_turn"], data["strength_payout_on_turn"],
|
||||||
|
data["strength_payout_off_turn"], data["magic_payout_on_turn"], data["magic_payout_off_turn"],
|
||||||
|
data["has_special_payout_on_turn"], data["has_special_payout_off_turn"],
|
||||||
|
data["special_payout_on_turn"],
|
||||||
|
data["special_payout_off_turn"], data["expansion"])
|
||||||
|
|
||||||
|
|
||||||
|
class Citizen(Card):
|
||||||
|
def __init__(self, citizen_id, name, gold_cost, roll_match1, roll_match2, shadow_count, holy_count, soldier_count,
|
||||||
|
worker_count, gold_payout_on_turn, gold_payout_off_turn, strength_payout_on_turn,
|
||||||
|
strength_payout_off_turn, magic_payout_on_turn, magic_payout_off_turn, has_special_payout_on_turn,
|
||||||
|
has_special_payout_off_turn, special_payout_on_turn, special_payout_off_turn, special_citizen,
|
||||||
|
expansion, is_flipped=False):
|
||||||
|
super().__init__()
|
||||||
|
self.citizen_id = citizen_id
|
||||||
|
self.name = name
|
||||||
|
self.gold_cost = gold_cost
|
||||||
|
self.roll_match1 = roll_match1
|
||||||
|
self.roll_match2 = roll_match2
|
||||||
|
self.shadow_count = _coerce_int(shadow_count)
|
||||||
|
self.holy_count = _coerce_int(holy_count)
|
||||||
|
self.soldier_count = _coerce_int(soldier_count)
|
||||||
|
self.worker_count = _coerce_int(worker_count)
|
||||||
|
self.gold_payout_on_turn = gold_payout_on_turn
|
||||||
|
self.gold_payout_off_turn = gold_payout_off_turn
|
||||||
|
self.strength_payout_on_turn = strength_payout_on_turn
|
||||||
|
self.strength_payout_off_turn = strength_payout_off_turn
|
||||||
|
self.magic_payout_on_turn = magic_payout_on_turn
|
||||||
|
self.magic_payout_off_turn = magic_payout_off_turn
|
||||||
|
self.has_special_payout_on_turn = has_special_payout_on_turn
|
||||||
|
self.has_special_payout_off_turn = has_special_payout_off_turn
|
||||||
|
self.special_payout_on_turn = special_payout_on_turn
|
||||||
|
self.special_payout_off_turn = special_payout_off_turn
|
||||||
|
self.special_citizen = special_citizen
|
||||||
|
self.expansion = expansion
|
||||||
|
self.is_flipped = bool(is_flipped)
|
||||||
|
|
||||||
|
def get_special_payout_on_turn(self):
|
||||||
|
return self.special_payout_on_turn
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
base_dict = super().to_dict()
|
||||||
|
return {**base_dict,
|
||||||
|
"is_flipped": bool(getattr(self, "is_flipped", False)),
|
||||||
|
"citizen_id": self.citizen_id,
|
||||||
|
"gold_cost": self.gold_cost,
|
||||||
|
"roll_match1": self.roll_match1,
|
||||||
|
"roll_match2": self.roll_match2,
|
||||||
|
"shadow_count": self.shadow_count,
|
||||||
|
"holy_count": self.holy_count,
|
||||||
|
"soldier_count": self.soldier_count,
|
||||||
|
"worker_count": self.worker_count,
|
||||||
|
"roles": {
|
||||||
|
"shadow": self.shadow_count,
|
||||||
|
"holy": self.holy_count,
|
||||||
|
"soldier": self.soldier_count,
|
||||||
|
"worker": self.worker_count,
|
||||||
|
},
|
||||||
|
"gold_payout_on_turn": self.gold_payout_on_turn,
|
||||||
|
"gold_payout_off_turn": self.gold_payout_off_turn,
|
||||||
|
"strength_payout_on_turn": self.strength_payout_on_turn,
|
||||||
|
"strength_payout_off_turn": self.strength_payout_off_turn,
|
||||||
|
"magic_payout_on_turn": self.magic_payout_on_turn,
|
||||||
|
"magic_payout_off_turn": self.magic_payout_off_turn,
|
||||||
|
"has_special_payout_on_turn": self.has_special_payout_on_turn,
|
||||||
|
"has_special_payout_off_turn": self.has_special_payout_off_turn,
|
||||||
|
"special_payout_on_turn": self.special_payout_on_turn,
|
||||||
|
"special_payout_off_turn": self.special_payout_off_turn,
|
||||||
|
"special_citizen": self.special_citizen,
|
||||||
|
"expansion": self.expansion}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, dict_):
|
||||||
|
return cls(citizen_id=dict_["citizen_id"],
|
||||||
|
name=dict_["name"],
|
||||||
|
gold_cost=dict_["gold_cost"],
|
||||||
|
roll_match1=dict_["roll_match1"],
|
||||||
|
roll_match2=dict_["roll_match2"],
|
||||||
|
shadow_count=dict_.get("shadow_count"),
|
||||||
|
holy_count=dict_.get("holy_count"),
|
||||||
|
soldier_count=dict_.get("soldier_count"),
|
||||||
|
worker_count=dict_.get("worker_count"),
|
||||||
|
gold_payout_on_turn=dict_["gold_payout_on_turn"],
|
||||||
|
gold_payout_off_turn=dict_["gold_payout_off_turn"],
|
||||||
|
strength_payout_on_turn=dict_["strength_payout_on_turn"],
|
||||||
|
strength_payout_off_turn=dict_["strength_payout_off_turn"],
|
||||||
|
magic_payout_on_turn=dict_["magic_payout_on_turn"],
|
||||||
|
magic_payout_off_turn=dict_["magic_payout_off_turn"],
|
||||||
|
has_special_payout_on_turn=dict_["has_special_payout_on_turn"],
|
||||||
|
has_special_payout_off_turn=dict_["has_special_payout_off_turn"],
|
||||||
|
special_payout_on_turn=dict_["special_payout_on_turn"],
|
||||||
|
special_payout_off_turn=dict_["special_payout_off_turn"],
|
||||||
|
special_citizen=dict_["special_citizen"],
|
||||||
|
expansion=dict_["expansion"],
|
||||||
|
is_flipped=bool(dict_.get("is_flipped", False)))
|
||||||
|
|
||||||
|
|
||||||
|
class Domain(Card):
|
||||||
|
def __init__(self, domain_id, name, gold_cost, shadow_count, holy_count, soldier_count, worker_count, vp_reward,
|
||||||
|
has_activation_effect, has_passive_effect, passive_effect, activation_effect, text, expansion,
|
||||||
|
acquired_turn_number=None):
|
||||||
|
super().__init__()
|
||||||
|
self.domain_id = domain_id
|
||||||
|
self.name = name
|
||||||
|
self.gold_cost = gold_cost
|
||||||
|
self.shadow_count = _coerce_int(shadow_count)
|
||||||
|
self.holy_count = _coerce_int(holy_count)
|
||||||
|
self.soldier_count = _coerce_int(soldier_count)
|
||||||
|
self.worker_count = _coerce_int(worker_count)
|
||||||
|
self.vp_reward = vp_reward
|
||||||
|
self.has_activation_effect = has_activation_effect
|
||||||
|
self.has_passive_effect = has_passive_effect
|
||||||
|
self.passive_effect = passive_effect
|
||||||
|
self.activation_effect = activation_effect
|
||||||
|
self.text = text
|
||||||
|
self.expansion = expansion
|
||||||
|
self.acquired_turn_number = acquired_turn_number
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return {
|
||||||
|
**super().to_dict(),
|
||||||
|
"domain_id": self.domain_id,
|
||||||
|
"name": self.name,
|
||||||
|
"gold_cost": self.gold_cost,
|
||||||
|
"shadow_count": self.shadow_count,
|
||||||
|
"holy_count": self.holy_count,
|
||||||
|
"soldier_count": self.soldier_count,
|
||||||
|
"worker_count": self.worker_count,
|
||||||
|
"roles": {
|
||||||
|
"shadow": self.shadow_count,
|
||||||
|
"holy": self.holy_count,
|
||||||
|
"soldier": self.soldier_count,
|
||||||
|
"worker": self.worker_count,
|
||||||
|
},
|
||||||
|
"vp_reward": self.vp_reward,
|
||||||
|
"has_activation_effect": self.has_activation_effect,
|
||||||
|
"has_passive_effect": self.has_passive_effect,
|
||||||
|
"passive_effect": self.passive_effect,
|
||||||
|
"activation_effect": self.activation_effect,
|
||||||
|
"text": self.text,
|
||||||
|
"expansion": self.expansion,
|
||||||
|
"acquired_turn_number": getattr(self, "acquired_turn_number", None),
|
||||||
|
}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, dict_):
|
||||||
|
return cls(
|
||||||
|
domain_id=dict_['domain_id'],
|
||||||
|
name=dict_['name'],
|
||||||
|
gold_cost=dict_['gold_cost'],
|
||||||
|
shadow_count=dict_.get('shadow_count'),
|
||||||
|
holy_count=dict_.get('holy_count'),
|
||||||
|
soldier_count=dict_.get('soldier_count'),
|
||||||
|
worker_count=dict_.get('worker_count'),
|
||||||
|
vp_reward=dict_['vp_reward'],
|
||||||
|
has_activation_effect=dict_['has_activation_effect'],
|
||||||
|
has_passive_effect=dict_['has_passive_effect'],
|
||||||
|
passive_effect=dict_['passive_effect'],
|
||||||
|
activation_effect=dict_['activation_effect'],
|
||||||
|
text=dict_['text'],
|
||||||
|
expansion=dict_['expansion'],
|
||||||
|
acquired_turn_number=dict_.get('acquired_turn_number'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Monster(Card):
|
||||||
|
def __init__(self, monster_id, name, area, monster_type, order, strength_cost, magic_cost, vp_reward, gold_reward,
|
||||||
|
strength_reward, magic_reward, has_special_reward, special_reward, has_special_cost, special_cost,
|
||||||
|
is_extra, expansion):
|
||||||
|
super().__init__()
|
||||||
|
self.monster_id = monster_id
|
||||||
|
self.name = name
|
||||||
|
self.area = area
|
||||||
|
self.monster_type = monster_type
|
||||||
|
self.order = order
|
||||||
|
self.strength_cost = strength_cost
|
||||||
|
self.magic_cost = magic_cost
|
||||||
|
self.vp_reward = vp_reward
|
||||||
|
self.gold_reward = gold_reward
|
||||||
|
self.strength_reward = strength_reward
|
||||||
|
self.magic_reward = magic_reward
|
||||||
|
self.has_special_reward = has_special_reward
|
||||||
|
self.special_reward = special_reward
|
||||||
|
self.has_special_cost = has_special_cost
|
||||||
|
self.special_cost = special_cost
|
||||||
|
self.is_extra = is_extra
|
||||||
|
self.expansion = expansion
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
card_dict = super().to_dict()
|
||||||
|
monster_dict = {
|
||||||
|
"monster_id": self.monster_id,
|
||||||
|
"area": self.area,
|
||||||
|
"monster_type": self.monster_type,
|
||||||
|
"order": self.order,
|
||||||
|
"strength_cost": self.strength_cost,
|
||||||
|
"magic_cost": self.magic_cost,
|
||||||
|
"vp_reward": self.vp_reward,
|
||||||
|
"gold_reward": self.gold_reward,
|
||||||
|
"strength_reward": self.strength_reward,
|
||||||
|
"magic_reward": self.magic_reward,
|
||||||
|
"has_special_reward": self.has_special_reward,
|
||||||
|
"special_reward": self.special_reward,
|
||||||
|
"has_special_cost": self.has_special_cost,
|
||||||
|
"special_cost": self.special_cost,
|
||||||
|
"is_extra": self.is_extra,
|
||||||
|
"expansion": self.expansion,
|
||||||
|
}
|
||||||
|
return {**card_dict, **monster_dict}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, d):
|
||||||
|
return cls(
|
||||||
|
d['monster_id'],
|
||||||
|
d['name'],
|
||||||
|
d['area'],
|
||||||
|
d['monster_type'],
|
||||||
|
d['order'],
|
||||||
|
d['strength_cost'],
|
||||||
|
d['magic_cost'],
|
||||||
|
d['vp_reward'],
|
||||||
|
d['gold_reward'],
|
||||||
|
d['strength_reward'],
|
||||||
|
d['magic_reward'],
|
||||||
|
d['has_special_reward'],
|
||||||
|
d['special_reward'],
|
||||||
|
d['has_special_cost'],
|
||||||
|
d['special_cost'],
|
||||||
|
d['is_extra'],
|
||||||
|
d['expansion'],
|
||||||
|
)
|
||||||
|
|
||||||
|
def add_strength_cost(self, added_strength):
|
||||||
|
self.strength_cost = self.strength_cost + added_strength
|
||||||
|
|
||||||
|
def add_magic_cost(self, added_magic):
|
||||||
|
self.magic_cost = self.magic_cost + added_magic
|
||||||
|
|
||||||
|
|
||||||
|
class Duke(Card):
|
||||||
|
def __init__(self, duke_id, name, gold_mult, strength_mult, magic_mult, shadow_mult, holy_mult, soldier_mult,
|
||||||
|
worker_mult, monster_mult, citizen_mult, domain_mult, boss_mult, minion_mult, beast_mult, titan_mult,
|
||||||
|
expansion):
|
||||||
|
super().__init__()
|
||||||
|
self.duke_id = duke_id
|
||||||
|
self.name = name
|
||||||
|
self.gold_multiplier = gold_mult
|
||||||
|
self.strength_multiplier = strength_mult
|
||||||
|
self.magic_multiplier = magic_mult
|
||||||
|
self.shadow_multiplier = shadow_mult
|
||||||
|
self.holy_multiplier = holy_mult
|
||||||
|
self.soldier_multiplier = soldier_mult
|
||||||
|
self.worker_multiplier = worker_mult
|
||||||
|
self.monster_multiplier = monster_mult
|
||||||
|
self.citizen_multiplier = citizen_mult
|
||||||
|
self.domain_multiplier = domain_mult
|
||||||
|
self.boss_multiplier = boss_mult
|
||||||
|
self.minion_multiplier = minion_mult
|
||||||
|
self.beast_multiplier = beast_mult
|
||||||
|
self.titan_multiplier = titan_mult
|
||||||
|
self.expansion = expansion
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return {
|
||||||
|
**super().to_dict(),
|
||||||
|
"duke_id": self.duke_id,
|
||||||
|
"gold_multiplier": self.gold_multiplier,
|
||||||
|
"strength_multiplier": self.strength_multiplier,
|
||||||
|
"magic_multiplier": self.magic_multiplier,
|
||||||
|
"shadow_multiplier": self.shadow_multiplier,
|
||||||
|
"holy_multiplier": self.holy_multiplier,
|
||||||
|
"soldier_multiplier": self.soldier_multiplier,
|
||||||
|
"worker_multiplier": self.worker_multiplier,
|
||||||
|
"monster_multiplier": self.monster_multiplier,
|
||||||
|
"citizen_multiplier": self.citizen_multiplier,
|
||||||
|
"domain_multiplier": self.domain_multiplier,
|
||||||
|
"boss_multiplier": self.boss_multiplier,
|
||||||
|
"minion_multiplier": self.minion_multiplier,
|
||||||
|
"beast_multiplier": self.beast_multiplier,
|
||||||
|
"titan_multiplier": self.titan_multiplier,
|
||||||
|
"expansion": self.expansion
|
||||||
|
}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, data):
|
||||||
|
duke_id = data["duke_id"]
|
||||||
|
name = data["name"]
|
||||||
|
gold_mult = data["gold_multiplier"]
|
||||||
|
strength_mult = data["strength_multiplier"]
|
||||||
|
magic_mult = data["magic_multiplier"]
|
||||||
|
shadow_mult = data["shadow_multiplier"]
|
||||||
|
holy_mult = data["holy_multiplier"]
|
||||||
|
soldier_mult = data["soldier_multiplier"]
|
||||||
|
worker_mult = data["worker_multiplier"]
|
||||||
|
monster_mult = data["monster_multiplier"]
|
||||||
|
citizen_mult = data["citizen_multiplier"]
|
||||||
|
domain_mult = data["domain_multiplier"]
|
||||||
|
boss_mult = data["boss_multiplier"]
|
||||||
|
minion_mult = data["minion_multiplier"]
|
||||||
|
beast_mult = data["beast_multiplier"]
|
||||||
|
titan_mult = data["titan_multiplier"]
|
||||||
|
expansion = data["expansion"]
|
||||||
|
return cls(duke_id, name, gold_mult, strength_mult, magic_mult, shadow_mult, holy_mult, soldier_mult,
|
||||||
|
worker_mult, monster_mult, citizen_mult, domain_mult, boss_mult, minion_mult, beast_mult,
|
||||||
|
titan_mult, expansion)
|
||||||
|
|
||||||
|
|
||||||
|
class Exhausted(Card):
|
||||||
|
def __init__(self, exhausted_id):
|
||||||
|
super().__init__()
|
||||||
|
self.exhausted_id = exhausted_id
|
||||||
|
self.name = "Exhausted"
|
||||||
|
self.toggle_visibility(True)
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return {
|
||||||
|
**super().to_dict(),
|
||||||
|
"exhausted_id": self.exhausted_id,
|
||||||
|
"name": self.name,
|
||||||
|
}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, d):
|
||||||
|
return cls(d["exhausted_id"])
|
||||||
40
check_db_server.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Simple script to check if MariaDB/MySQL server is running
|
||||||
|
Doesn't require mariadb module - just checks if port is open
|
||||||
|
"""
|
||||||
|
|
||||||
|
import socket
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def check_database_server():
|
||||||
|
"""Check if database server is listening on port 3306"""
|
||||||
|
print("Checking if MariaDB/MySQL server is accessible on localhost:3306...")
|
||||||
|
print("=" * 50)
|
||||||
|
print("(Make sure SSH port forwarding is active: ssh -L 3306:localhost:3306 lukesau.com)")
|
||||||
|
|
||||||
|
host = '127.0.0.1'
|
||||||
|
port = 3306
|
||||||
|
|
||||||
|
try:
|
||||||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
sock.settimeout(2)
|
||||||
|
result = sock.connect_ex((host, port))
|
||||||
|
sock.close()
|
||||||
|
|
||||||
|
if result == 0:
|
||||||
|
print(f"✓ Database server is accessible at {host}:{port}")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print(f"✗ Cannot reach {host}:{port}")
|
||||||
|
print("\nMake sure SSH port forwarding is active:")
|
||||||
|
print(" ssh -L 3306:localhost:3306 lukesau.com")
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
print(f"✗ Error checking server: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
success = check_database_server()
|
||||||
|
sys.exit(0 if success else 1)
|
||||||
|
|
||||||
337
client.py
@@ -1,337 +0,0 @@
|
|||||||
import wx
|
|
||||||
import socket
|
|
||||||
from common import *
|
|
||||||
|
|
||||||
|
|
||||||
class ClientVCKO(wx.App):
|
|
||||||
def OnInit(self):
|
|
||||||
self.connection_status = False
|
|
||||||
self.player_id = ""
|
|
||||||
self.player_name = ""
|
|
||||||
self.lobby = []
|
|
||||||
self.in_lobby = False
|
|
||||||
self.in_game = False
|
|
||||||
self.game_id = ""
|
|
||||||
self.game = None
|
|
||||||
self.debug_frame = DebugFrame(self)
|
|
||||||
self.lobby_frame = LobbyFrame(self)
|
|
||||||
self.game_frame = GameFrame(self)
|
|
||||||
self.last_lobby_state = ""
|
|
||||||
self.last_game_state = ""
|
|
||||||
self.debug_frame.set_connection_status()
|
|
||||||
return True
|
|
||||||
|
|
||||||
def parse_response(self, response):
|
|
||||||
if len(response) > 1000:
|
|
||||||
print(f"{response[:1000]}...")
|
|
||||||
else:
|
|
||||||
print(response)
|
|
||||||
first_word = response.split()[0]
|
|
||||||
full_command = response.split()
|
|
||||||
match first_word:
|
|
||||||
case "lobby":
|
|
||||||
if full_command[1] == "joined" and len(full_command) == 3:
|
|
||||||
self.player_id = full_command[2]
|
|
||||||
self.in_lobby = True
|
|
||||||
elif full_command[1] == "state":
|
|
||||||
json_response = ' '.join(full_command[2:])
|
|
||||||
new_lobby_state = json.loads(json_response)
|
|
||||||
if new_lobby_state != self.lobby:
|
|
||||||
self.lobby = new_lobby_state
|
|
||||||
self.lobby_frame.get_lobby_status()
|
|
||||||
else:
|
|
||||||
print("Couldn't understand that response")
|
|
||||||
case "game":
|
|
||||||
if full_command[1] == "joined" and len(full_command) == 3:
|
|
||||||
self.game_id = full_command[2]
|
|
||||||
self.in_game = True
|
|
||||||
self.in_lobby = False
|
|
||||||
self.lobby_frame.enter_game()
|
|
||||||
elif full_command[1] == "state":
|
|
||||||
json_response = ' '.join(full_command[2:])
|
|
||||||
new_game_state = json.loads(json_response)
|
|
||||||
if new_game_state == self.last_game_state:
|
|
||||||
return
|
|
||||||
self.last_game_state = new_game_state
|
|
||||||
|
|
||||||
def update_lobby_status(self):
|
|
||||||
return self.in_lobby
|
|
||||||
|
|
||||||
|
|
||||||
class GameFrame(wx.Frame):
|
|
||||||
def __init__(self, app):
|
|
||||||
super().__init__(parent=None, title='VCK Online', size=Constants.large_window_size)
|
|
||||||
self.app = app
|
|
||||||
self.panel = wx.Panel(self)
|
|
||||||
|
|
||||||
# Create a static box sizer with padding
|
|
||||||
vbox = wx.StaticBoxSizer(wx.StaticBox(self.panel, label=""), wx.VERTICAL)
|
|
||||||
vbox.AddSpacer(10) # Add a bit of padding at the top
|
|
||||||
|
|
||||||
# Wrap the list control widget inside a scrolled window
|
|
||||||
sw = wx.ScrolledWindow(vbox.GetStaticBox(), style=wx.VSCROLL)
|
|
||||||
sw.SetScrollbars(1, 1, 1, 1) # Show the scrollbars
|
|
||||||
self.game_state_list = wx.ListCtrl(sw, style=wx.LC_REPORT | wx.LC_SINGLE_SEL)
|
|
||||||
sw.SetSizer(wx.BoxSizer(wx.VERTICAL))
|
|
||||||
sw.GetSizer().Add(self.game_state_list, proportion=1, flag=wx.EXPAND | wx.ALL, border=10)
|
|
||||||
|
|
||||||
vbox.Add(sw, proportion=1, flag=wx.EXPAND | wx.ALL, border=10) # Add the scrolled window to the sizer
|
|
||||||
|
|
||||||
vbox.AddSpacer(10) # Add a bit of padding at the bottom
|
|
||||||
|
|
||||||
# Set the sizer for the panel
|
|
||||||
self.panel.SetSizer(vbox)
|
|
||||||
|
|
||||||
self.SetMinSize(Constants.medium_window_size)
|
|
||||||
self.last_game_state = ""
|
|
||||||
self.timer_interval = 500
|
|
||||||
self.timer = wx.Timer(self)
|
|
||||||
self.Bind(wx.EVT_TIMER, self.get_game_status, self.timer)
|
|
||||||
self.timer.Start(self.timer_interval)
|
|
||||||
|
|
||||||
def get_game_status(self, event=None):
|
|
||||||
if self.app.in_game and connection_check():
|
|
||||||
self.app.parse_response(send(f"game get_status {self.app.game_id}"))
|
|
||||||
if self.last_game_state == self.app.last_game_state:
|
|
||||||
if self.timer_interval < 9500:
|
|
||||||
self.timer_interval += 500
|
|
||||||
self.timer.Start(self.timer_interval)
|
|
||||||
# If the current game state is the same as the last one, don't update the list control
|
|
||||||
return
|
|
||||||
pretty_json_str = json.dumps(self.app.last_game_state, indent=4, sort_keys=False)
|
|
||||||
self.game_state_list.ClearAll()
|
|
||||||
self.game_state_list.InsertColumn(0, "Game State")
|
|
||||||
for idx, state in enumerate(pretty_json_str.split('\n')):
|
|
||||||
self.game_state_list.InsertItem(idx, state.strip())
|
|
||||||
self.game_state_list.SetColumnWidth(0, wx.LIST_AUTOSIZE)
|
|
||||||
# Save the new game state
|
|
||||||
self.last_game_state = self.app.last_game_state
|
|
||||||
|
|
||||||
|
|
||||||
class LobbyFrame(wx.Frame):
|
|
||||||
def __init__(self, app):
|
|
||||||
super().__init__(parent=None, title='VCK Online Lobby', size=Constants.medium_window_size)
|
|
||||||
self.app = app
|
|
||||||
|
|
||||||
self.timer_interval = 500
|
|
||||||
self.timer = wx.Timer(self)
|
|
||||||
self.Bind(wx.EVT_TIMER, self.get_lobby_status, self.timer)
|
|
||||||
self.timer.Start(self.timer_interval)
|
|
||||||
|
|
||||||
self.panel = wx.Panel(self)
|
|
||||||
self.vertical_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
||||||
|
|
||||||
splitter = wx.SplitterWindow(self.panel)
|
|
||||||
|
|
||||||
left_panel = wx.Panel(splitter)
|
|
||||||
left_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
||||||
text = wx.StaticText(left_panel, label='Enter name:')
|
|
||||||
self.name_field = wx.TextCtrl(left_panel, style=wx.TE_PROCESS_ENTER, value='')
|
|
||||||
submit_button = wx.Button(left_panel, label='Submit')
|
|
||||||
submit_button.Bind(wx.EVT_BUTTON, self.on_submit)
|
|
||||||
self.name_field.Bind(wx.EVT_TEXT_ENTER, self.on_text_enter)
|
|
||||||
left_sizer.Add(text, 0, wx.ALL, 5)
|
|
||||||
left_sizer.Add(self.name_field, 0, wx.EXPAND | wx.ALL, 5)
|
|
||||||
left_sizer.Add(submit_button, 0, wx.ALL | wx.CENTER, 5)
|
|
||||||
left_panel.SetSizer(left_sizer)
|
|
||||||
|
|
||||||
self.last_lobby_state = []
|
|
||||||
self.current_player_index = None
|
|
||||||
|
|
||||||
# Create the list control and columns
|
|
||||||
right_panel = wx.Panel(splitter)
|
|
||||||
self.list_ctrl = wx.ListCtrl(right_panel, style=wx.LC_REPORT)
|
|
||||||
self.list_ctrl.InsertColumn(0, "Player Name")
|
|
||||||
self.list_ctrl.InsertColumn(1, "Ready Status", format=wx.LIST_FORMAT_RIGHT)
|
|
||||||
self.get_lobby_status()
|
|
||||||
# Create the ready button
|
|
||||||
ready_button = wx.Button(right_panel, label="Ready Up")
|
|
||||||
ready_button.Bind(wx.EVT_BUTTON, self.on_ready_up)
|
|
||||||
self.list_ctrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.highlight_current_player)
|
|
||||||
# Add the list control and ready button to the vertical sizer
|
|
||||||
right_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
||||||
right_sizer.Add(self.list_ctrl, 1, wx.ALL | wx.EXPAND, 5)
|
|
||||||
right_sizer.Add(ready_button, 0, wx.ALL | wx.CENTER, 5)
|
|
||||||
right_panel.SetSizer(right_sizer)
|
|
||||||
|
|
||||||
splitter.SplitVertically(left_panel, right_panel)
|
|
||||||
splitter.SetMinimumPaneSize(250)
|
|
||||||
splitter.SetSashGravity(0.0)
|
|
||||||
|
|
||||||
self.vertical_sizer.Add(splitter, 1, wx.EXPAND)
|
|
||||||
self.panel.SetSizer(self.vertical_sizer)
|
|
||||||
|
|
||||||
self.SetMinSize(Constants.small_window_size)
|
|
||||||
|
|
||||||
# Bind the size event to adjust the column widths
|
|
||||||
self.Bind(wx.EVT_SIZE, self.on_size)
|
|
||||||
self.Bind(wx.EVT_CLOSE, self.on_close)
|
|
||||||
|
|
||||||
self.timer_interval = 500
|
|
||||||
self.timer = wx.Timer(self)
|
|
||||||
self.Bind(wx.EVT_TIMER, self.get_lobby_status, self.timer)
|
|
||||||
self.timer.Start(self.timer_interval)
|
|
||||||
self.Show()
|
|
||||||
|
|
||||||
def on_size(self, event):
|
|
||||||
# Calculate the width of each column based on the width of the list control
|
|
||||||
width = self.list_ctrl.GetSize()[0]
|
|
||||||
col_width = width // 2
|
|
||||||
self.list_ctrl.SetColumnWidth(0, col_width)
|
|
||||||
self.list_ctrl.SetColumnWidth(1, col_width)
|
|
||||||
event.Skip()
|
|
||||||
|
|
||||||
def on_submit(self, event):
|
|
||||||
name = self.name_field.GetValue()
|
|
||||||
if not name:
|
|
||||||
print("You didn't enter anything!")
|
|
||||||
else:
|
|
||||||
# Check if the player has already joined the lobby
|
|
||||||
player_exists = False
|
|
||||||
for player in self.last_lobby_state:
|
|
||||||
if player['player_id'] == self.app.player_id:
|
|
||||||
player_exists = True
|
|
||||||
break
|
|
||||||
if player_exists:
|
|
||||||
# If the player already exists, rename them
|
|
||||||
self.app.parse_response(send(f"lobby rename {self.app.player_id} {name}"))
|
|
||||||
else:
|
|
||||||
# If the player doesn't exist, join the lobby
|
|
||||||
self.app.parse_response(send(f"lobby join {name}"))
|
|
||||||
self.name_field.SetValue("")
|
|
||||||
|
|
||||||
def on_text_enter(self, event):
|
|
||||||
self.on_submit(event)
|
|
||||||
|
|
||||||
def api_call(self, message):
|
|
||||||
if connection_check():
|
|
||||||
self.app.parse_response(send(message))
|
|
||||||
self.name_field.SetValue("")
|
|
||||||
|
|
||||||
def get_lobby_status(self, event=None):
|
|
||||||
if connection_check():
|
|
||||||
self.app.parse_response(send(f"lobby get_status {self.app.player_id}"))
|
|
||||||
if self.app.lobby == self.last_lobby_state:
|
|
||||||
# If the current lobby state is the same as the last one, don't update the list control
|
|
||||||
if self.timer_interval < 9500:
|
|
||||||
self.timer_interval += 500
|
|
||||||
self.timer.Start(self.timer_interval)
|
|
||||||
return
|
|
||||||
self.list_ctrl.DeleteAllItems()
|
|
||||||
for index, player in enumerate(self.app.lobby):
|
|
||||||
self.list_ctrl.InsertItem(index, player['name'])
|
|
||||||
self.list_ctrl.SetItem(index, 1, "Ready" if player['is_ready'] else "Not Ready")
|
|
||||||
if player['player_id'] == self.app.player_id:
|
|
||||||
self.current_player_index = index
|
|
||||||
self.list_ctrl.SetItemState(index, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)
|
|
||||||
else:
|
|
||||||
self.list_ctrl.SetItemState(index, 0, wx.LIST_STATE_SELECTED)
|
|
||||||
# Save the new lobby state
|
|
||||||
self.last_lobby_state = self.app.lobby
|
|
||||||
|
|
||||||
def highlight_current_player(self, event=None):
|
|
||||||
if self.current_player_index is not None:
|
|
||||||
self.list_ctrl.Select(self.current_player_index)
|
|
||||||
else:
|
|
||||||
self.list_ctrl.Select(-1)
|
|
||||||
|
|
||||||
def on_ready_up(self, event):
|
|
||||||
for player in self.app.lobby:
|
|
||||||
if player['player_id'] == self.app.player_id:
|
|
||||||
if player['is_ready']:
|
|
||||||
if connection_check():
|
|
||||||
self.app.parse_response(send(f"lobby unready {self.app.player_id}"))
|
|
||||||
else:
|
|
||||||
if connection_check():
|
|
||||||
self.app.parse_response(send(f"lobby ready {self.app.player_id}"))
|
|
||||||
break
|
|
||||||
|
|
||||||
def enter_game(self, event=None):
|
|
||||||
self.app.game_frame.Show()
|
|
||||||
self.Hide()
|
|
||||||
|
|
||||||
def on_close(self, event):
|
|
||||||
self.app.parse_response(send(f"lobby leave {self.app.player_id}"))
|
|
||||||
self.Destroy()
|
|
||||||
|
|
||||||
|
|
||||||
class DebugFrame(wx.Frame):
|
|
||||||
def __init__(self, app):
|
|
||||||
super().__init__(parent=None, title='VCKO Debug Console', size=Constants.small_window_size)
|
|
||||||
self.app = app
|
|
||||||
self.panel = wx.Panel(self)
|
|
||||||
self.vertical_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
||||||
self.status_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
||||||
self.message_field = wx.TextCtrl(self.panel, style=wx.TE_PROCESS_ENTER)
|
|
||||||
self.connection_status_indicator = wx.StaticText(self.panel, label="Connection Status")
|
|
||||||
self.my_btn = wx.Button(self.panel, label="Send call")
|
|
||||||
self.my_btn.Bind(wx.EVT_BUTTON, self.on_press)
|
|
||||||
self.message_field.Bind(wx.EVT_TEXT_ENTER, self.on_text_enter)
|
|
||||||
# Create a horizontal sizer to hold the connection_status StaticText
|
|
||||||
self.status_sizer.AddStretchSpacer()
|
|
||||||
self.status_sizer.Add(wx.StaticText(self.panel), 0, wx.EXPAND | wx.RIGHT, 5)
|
|
||||||
self.status_sizer.Add(self.connection_status_indicator, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 5)
|
|
||||||
self.status_sizer.Add(wx.StaticText(self.panel), 0, wx.EXPAND | wx.LEFT, 5)
|
|
||||||
# Add the text field, button, and status sizer to the vertical sizer
|
|
||||||
self.vertical_sizer.Add(self.message_field, 0, wx.ALL | wx.EXPAND, 5)
|
|
||||||
self.vertical_sizer.Add(self.my_btn, 0, wx.ALL | wx.CENTER, 5)
|
|
||||||
self.vertical_sizer.AddStretchSpacer()
|
|
||||||
self.vertical_sizer.Add(self.status_sizer, 0, wx.ALIGN_LEFT | wx.BOTTOM, 5)
|
|
||||||
self.panel.SetSizer(self.vertical_sizer)
|
|
||||||
self.SetMinSize(Constants.small_window_size)
|
|
||||||
self.Show()
|
|
||||||
# Create a timer to call the connection_check method every 2 seconds
|
|
||||||
self.timer = wx.Timer(self)
|
|
||||||
self.Bind(wx.EVT_TIMER, self.set_connection_status, self.timer)
|
|
||||||
self.timer.Start(10000)
|
|
||||||
|
|
||||||
def set_connection_status(self, event=None):
|
|
||||||
if connection_check():
|
|
||||||
self.connection_status_indicator.SetLabel("Connected")
|
|
||||||
self.connection_status_indicator.SetForegroundColour(Constants.green)
|
|
||||||
else:
|
|
||||||
self.connection_status_indicator.SetLabel("Not Connected")
|
|
||||||
self.connection_status_indicator.SetForegroundColour(Constants.red)
|
|
||||||
|
|
||||||
def on_press(self, event):
|
|
||||||
message = self.message_field.GetValue()
|
|
||||||
if not message:
|
|
||||||
print("You didn't enter anything!")
|
|
||||||
else:
|
|
||||||
self.api_call(message)
|
|
||||||
|
|
||||||
def on_text_enter(self, event):
|
|
||||||
self.on_press(event)
|
|
||||||
|
|
||||||
def api_call(self, message):
|
|
||||||
if connection_check():
|
|
||||||
self.app.parse_response(send(message))
|
|
||||||
self.message_field.SetValue("")
|
|
||||||
|
|
||||||
|
|
||||||
def connection_check():
|
|
||||||
try:
|
|
||||||
response = send("connection_check")
|
|
||||||
if response == "received":
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
except ConnectionRefusedError:
|
|
||||||
return False
|
|
||||||
except BrokenPipeError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def send(message):
|
|
||||||
client_socket = socket.socket()
|
|
||||||
client_socket.connect((Constants.host, Constants.port))
|
|
||||||
message_bytes = message.encode(Constants.encoding)
|
|
||||||
send_data(client_socket, message_bytes)
|
|
||||||
response = receive_data(client_socket)
|
|
||||||
client_socket.close()
|
|
||||||
return response.decode(Constants.encoding)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
the_app = ClientVCKO()
|
|
||||||
the_app.MainLoop()
|
|
||||||
824
common.py
@@ -1,824 +0,0 @@
|
|||||||
import json
|
|
||||||
import time
|
|
||||||
from json import JSONEncoder, JSONDecoder
|
|
||||||
import random
|
|
||||||
from typing import List, Dict
|
|
||||||
from constants import *
|
|
||||||
import shortuuid
|
|
||||||
import uuid
|
|
||||||
|
|
||||||
|
|
||||||
class Card:
|
|
||||||
def __init__(self):
|
|
||||||
self.name = ""
|
|
||||||
self.is_visible = False
|
|
||||||
self.is_accessible = False
|
|
||||||
|
|
||||||
def to_dict(self):
|
|
||||||
return {
|
|
||||||
"name": self.name,
|
|
||||||
"is_visible": self.is_visible,
|
|
||||||
"is_accessible": self.is_accessible,
|
|
||||||
}
|
|
||||||
|
|
||||||
def toggle_visibility(self, toggle: bool = True):
|
|
||||||
self.is_visible = toggle
|
|
||||||
|
|
||||||
def toggle_accessibility(self, toggle: bool = True):
|
|
||||||
self.is_accessible = toggle
|
|
||||||
|
|
||||||
|
|
||||||
class Player:
|
|
||||||
def __init__(self, player_id, name):
|
|
||||||
self.player_id = player_id
|
|
||||||
self.name = name
|
|
||||||
self.owned_starters = []
|
|
||||||
self.owned_citizens = []
|
|
||||||
self.owned_domains = []
|
|
||||||
self.owned_dukes = []
|
|
||||||
self.owned_monsters = []
|
|
||||||
self.gold_score = 2
|
|
||||||
self.strength_score = 0
|
|
||||||
self.magic_score = 1
|
|
||||||
self.victory_score = 0
|
|
||||||
self.is_first = False
|
|
||||||
self.shadow_count = 0
|
|
||||||
self.holy_count = 0
|
|
||||||
self.soldier_count = 0
|
|
||||||
self.worker_count = 0
|
|
||||||
self.effects = {
|
|
||||||
"roll_phase": [],
|
|
||||||
"harvest_phase": [],
|
|
||||||
"action_phase": []
|
|
||||||
}
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_dict(cls, data):
|
|
||||||
player_id = data['player_id']
|
|
||||||
name = data['name']
|
|
||||||
player = cls(player_id, name)
|
|
||||||
player.owned_starters = [Starter.from_dict(s) for s in data['owned_starters']]
|
|
||||||
player.owned_citizens = [Citizen.from_dict(c) for c in data['owned_citizens']]
|
|
||||||
player.owned_domains = [Domain.from_dict(d) for d in data['owned_domains']]
|
|
||||||
player.owned_dukes = [Duke.from_dict(d) for d in data['owned_dukes']]
|
|
||||||
player.owned_monsters = [Monster.from_dict(m) for m in data['owned_monsters']]
|
|
||||||
player.gold_score = data['gold_score']
|
|
||||||
player.strength_score = data['strength_score']
|
|
||||||
player.magic_score = data['magic_score']
|
|
||||||
player.victory_score = data['victory_score']
|
|
||||||
player.is_first = data['is_first']
|
|
||||||
player.shadow_count = data['shadow_count']
|
|
||||||
player.holy_count = data['holy_count']
|
|
||||||
player.soldier_count = data['soldier_count']
|
|
||||||
player.worker_count = data['worker_count']
|
|
||||||
player.effects = data['effects']
|
|
||||||
return player
|
|
||||||
|
|
||||||
def calc_roles(self):
|
|
||||||
shadow_count = 0
|
|
||||||
holy_count = 0
|
|
||||||
soldier_count = 0
|
|
||||||
worker_count = 0
|
|
||||||
for citizen in self.owned_citizens:
|
|
||||||
shadow_count = shadow_count + citizen.shadow_count
|
|
||||||
holy_count = holy_count + citizen.holy_count
|
|
||||||
soldier_count = soldier_count + citizen.soldier_count
|
|
||||||
worker_count = worker_count + citizen.worker_count
|
|
||||||
for domain in self.owned_domains:
|
|
||||||
shadow_count = shadow_count + domain.shadow_count
|
|
||||||
holy_count = holy_count + domain.holy_count
|
|
||||||
soldier_count = soldier_count + domain.soldier_count
|
|
||||||
worker_count = worker_count + domain.worker_count
|
|
||||||
roles_dict = {
|
|
||||||
"shadow_count": shadow_count,
|
|
||||||
"holy_count": holy_count,
|
|
||||||
"soldier_count": soldier_count,
|
|
||||||
"worker_count": worker_count
|
|
||||||
}
|
|
||||||
return roles_dict
|
|
||||||
|
|
||||||
|
|
||||||
class Starter(Card):
|
|
||||||
def __init__(self, starter_id, name, roll_match1, roll_match2, gold_payout_on_turn, gold_payout_off_turn,
|
|
||||||
strength_payout_on_turn, strength_payout_off_turn, magic_payout_on_turn, magic_payout_off_turn,
|
|
||||||
has_special_payout_on_turn, has_special_payout_off_turn, special_payout_on_turn,
|
|
||||||
special_payout_off_turn, expansion):
|
|
||||||
super().__init__()
|
|
||||||
self.starter_id = starter_id
|
|
||||||
self.name = name
|
|
||||||
self.roll_match1 = roll_match1
|
|
||||||
self.roll_match2 = roll_match2
|
|
||||||
self.gold_payout_on_turn = gold_payout_on_turn
|
|
||||||
self.gold_payout_off_turn = gold_payout_off_turn
|
|
||||||
self.strength_payout_on_turn = strength_payout_on_turn
|
|
||||||
self.strength_payout_off_turn = strength_payout_off_turn
|
|
||||||
self.magic_payout_on_turn = magic_payout_on_turn
|
|
||||||
self.magic_payout_off_turn = magic_payout_off_turn
|
|
||||||
self.has_special_payout_on_turn = has_special_payout_on_turn
|
|
||||||
self.has_special_payout_off_turn = has_special_payout_off_turn
|
|
||||||
self.special_payout_on_turn = special_payout_on_turn
|
|
||||||
self.special_payout_off_turn = special_payout_off_turn
|
|
||||||
self.expansion = expansion
|
|
||||||
|
|
||||||
def to_dict(self):
|
|
||||||
return {
|
|
||||||
"starter_id": self.starter_id,
|
|
||||||
"name": self.name,
|
|
||||||
"roll_match1": self.roll_match1,
|
|
||||||
"roll_match2": self.roll_match2,
|
|
||||||
"gold_payout_on_turn": self.gold_payout_on_turn,
|
|
||||||
"gold_payout_off_turn": self.gold_payout_off_turn,
|
|
||||||
"strength_payout_on_turn": self.strength_payout_on_turn,
|
|
||||||
"strength_payout_off_turn": self.strength_payout_off_turn,
|
|
||||||
"magic_payout_on_turn": self.magic_payout_on_turn,
|
|
||||||
"magic_payout_off_turn": self.magic_payout_off_turn,
|
|
||||||
"has_special_payout_on_turn": self.has_special_payout_on_turn,
|
|
||||||
"has_special_payout_off_turn": self.has_special_payout_off_turn,
|
|
||||||
"special_payout_on_turn": self.special_payout_on_turn,
|
|
||||||
"special_payout_off_turn": self.special_payout_off_turn,
|
|
||||||
"expansion": self.expansion
|
|
||||||
}
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_dict(cls, data):
|
|
||||||
return cls(data["starter_id"], data["name"], data["roll_match1"], data["roll_match2"],
|
|
||||||
data["gold_payout_on_turn"], data["gold_payout_off_turn"], data["strength_payout_on_turn"],
|
|
||||||
data["strength_payout_off_turn"], data["magic_payout_on_turn"], data["magic_payout_off_turn"],
|
|
||||||
data["has_special_payout_on_turn"], data["has_special_payout_off_turn"],
|
|
||||||
data["special_payout_on_turn"],
|
|
||||||
data["special_payout_off_turn"], data["expansion"])
|
|
||||||
|
|
||||||
|
|
||||||
class Citizen(Card):
|
|
||||||
def __init__(self, citizen_id, name, gold_cost, roll_match1, roll_match2, shadow_count, holy_count, soldier_count,
|
|
||||||
worker_count, gold_payout_on_turn, gold_payout_off_turn, strength_payout_on_turn,
|
|
||||||
strength_payout_off_turn, magic_payout_on_turn, magic_payout_off_turn, has_special_payout_on_turn,
|
|
||||||
has_special_payout_off_turn, special_payout_on_turn, special_payout_off_turn, special_citizen,
|
|
||||||
expansion):
|
|
||||||
super().__init__()
|
|
||||||
self.citizen_id = citizen_id
|
|
||||||
self.name = name
|
|
||||||
self.gold_cost = gold_cost
|
|
||||||
self.roll_match1 = roll_match1
|
|
||||||
self.roll_match2 = roll_match2
|
|
||||||
self.shadow_count = shadow_count
|
|
||||||
self.holy_count = holy_count
|
|
||||||
self.soldier_count = soldier_count
|
|
||||||
self.worker_count = worker_count
|
|
||||||
self.gold_payout_on_turn = gold_payout_on_turn
|
|
||||||
self.gold_payout_off_turn = gold_payout_off_turn
|
|
||||||
self.strength_payout_on_turn = strength_payout_on_turn
|
|
||||||
self.strength_payout_off_turn = strength_payout_off_turn
|
|
||||||
self.magic_payout_on_turn = magic_payout_on_turn
|
|
||||||
self.magic_payout_off_turn = magic_payout_off_turn
|
|
||||||
self.has_special_payout_on_turn = has_special_payout_on_turn
|
|
||||||
self.has_special_payout_off_turn = has_special_payout_off_turn
|
|
||||||
self.special_payout_on_turn = special_payout_on_turn
|
|
||||||
self.special_payout_off_turn = special_payout_off_turn
|
|
||||||
self.special_citizen = special_citizen
|
|
||||||
self.expansion = expansion
|
|
||||||
|
|
||||||
def get_special_payout_on_turn(self):
|
|
||||||
return self.special_payout_on_turn
|
|
||||||
|
|
||||||
def to_dict(self):
|
|
||||||
base_dict = super().to_dict()
|
|
||||||
return {**base_dict,
|
|
||||||
"citizen_id": self.citizen_id,
|
|
||||||
"gold_cost": self.gold_cost,
|
|
||||||
"roll_match1": self.roll_match1,
|
|
||||||
"roll_match2": self.roll_match2,
|
|
||||||
"shadow_count": self.shadow_count,
|
|
||||||
"holy_count": self.holy_count,
|
|
||||||
"soldier_count": self.soldier_count,
|
|
||||||
"worker_count": self.worker_count,
|
|
||||||
"gold_payout_on_turn": self.gold_payout_on_turn,
|
|
||||||
"gold_payout_off_turn": self.gold_payout_off_turn,
|
|
||||||
"strength_payout_on_turn": self.strength_payout_on_turn,
|
|
||||||
"strength_payout_off_turn": self.strength_payout_off_turn,
|
|
||||||
"magic_payout_on_turn": self.magic_payout_on_turn,
|
|
||||||
"magic_payout_off_turn": self.magic_payout_off_turn,
|
|
||||||
"has_special_payout_on_turn": self.has_special_payout_on_turn,
|
|
||||||
"has_special_payout_off_turn": self.has_special_payout_off_turn,
|
|
||||||
"special_payout_on_turn": self.special_payout_on_turn,
|
|
||||||
"special_payout_off_turn": self.special_payout_off_turn,
|
|
||||||
"special_citizen": self.special_citizen,
|
|
||||||
"expansion": self.expansion}
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_dict(cls, dict_):
|
|
||||||
return cls(citizen_id=dict_["citizen_id"],
|
|
||||||
name=dict_["name"],
|
|
||||||
gold_cost=dict_["gold_cost"],
|
|
||||||
roll_match1=dict_["roll_match1"],
|
|
||||||
roll_match2=dict_["roll_match2"],
|
|
||||||
shadow_count=dict_["shadow_count"],
|
|
||||||
holy_count=dict_["holy_count"],
|
|
||||||
soldier_count=dict_["soldier_count"],
|
|
||||||
worker_count=dict_["worker_count"],
|
|
||||||
gold_payout_on_turn=dict_["gold_payout_on_turn"],
|
|
||||||
gold_payout_off_turn=dict_["gold_payout_off_turn"],
|
|
||||||
strength_payout_on_turn=dict_["strength_payout_on_turn"],
|
|
||||||
strength_payout_off_turn=dict_["strength_payout_off_turn"],
|
|
||||||
magic_payout_on_turn=dict_["magic_payout_on_turn"],
|
|
||||||
magic_payout_off_turn=dict_["magic_payout_off_turn"],
|
|
||||||
has_special_payout_on_turn=dict_["has_special_payout_on_turn"],
|
|
||||||
has_special_payout_off_turn=dict_["has_special_payout_off_turn"],
|
|
||||||
special_payout_on_turn=dict_["special_payout_on_turn"],
|
|
||||||
special_payout_off_turn=dict_["special_payout_off_turn"],
|
|
||||||
special_citizen=dict_["special_citizen"],
|
|
||||||
expansion=dict_["expansion"])
|
|
||||||
|
|
||||||
|
|
||||||
class Domain(Card):
|
|
||||||
def __init__(self, domain_id, name, gold_cost, shadow_count, holy_count, soldier_count, worker_count, vp_reward,
|
|
||||||
has_activation_effect, has_passive_effect, passive_effect, activation_effect, text, expansion):
|
|
||||||
super().__init__()
|
|
||||||
self.domain_id = domain_id
|
|
||||||
self.name = name
|
|
||||||
self.gold_cost = gold_cost
|
|
||||||
self.shadow_count = shadow_count
|
|
||||||
self.holy_count = holy_count
|
|
||||||
self.soldier_count = soldier_count
|
|
||||||
self.worker_count = worker_count
|
|
||||||
self.vp_reward = vp_reward
|
|
||||||
self.has_activation_effect = has_activation_effect
|
|
||||||
self.has_passive_effect = has_passive_effect
|
|
||||||
self.passive_effect = passive_effect
|
|
||||||
self.activation_effect = activation_effect
|
|
||||||
self.text = text
|
|
||||||
self.expansion = expansion
|
|
||||||
|
|
||||||
def to_dict(self):
|
|
||||||
return {
|
|
||||||
**super().to_dict(),
|
|
||||||
"domain_id": self.domain_id,
|
|
||||||
"name": self.name,
|
|
||||||
"gold_cost": self.gold_cost,
|
|
||||||
"shadow_count": self.shadow_count,
|
|
||||||
"holy_count": self.holy_count,
|
|
||||||
"soldier_count": self.soldier_count,
|
|
||||||
"worker_count": self.worker_count,
|
|
||||||
"vp_reward": self.vp_reward,
|
|
||||||
"has_activation_effect": self.has_activation_effect,
|
|
||||||
"has_passive_effect": self.has_passive_effect,
|
|
||||||
"passive_effect": self.passive_effect,
|
|
||||||
"activation_effect": self.activation_effect,
|
|
||||||
"text": self.text,
|
|
||||||
"expansion": self.expansion
|
|
||||||
}
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_dict(cls, dict_):
|
|
||||||
return cls(
|
|
||||||
domain_id=dict_['domain_id'],
|
|
||||||
name=dict_['name'],
|
|
||||||
gold_cost=dict_['gold_cost'],
|
|
||||||
shadow_count=dict_['shadow_count'],
|
|
||||||
holy_count=dict_['holy_count'],
|
|
||||||
soldier_count=dict_['soldier_count'],
|
|
||||||
worker_count=dict_['worker_count'],
|
|
||||||
vp_reward=dict_['vp_reward'],
|
|
||||||
has_activation_effect=dict_['has_activation_effect'],
|
|
||||||
has_passive_effect=dict_['has_passive_effect'],
|
|
||||||
passive_effect=dict_['passive_effect'],
|
|
||||||
activation_effect=dict_['activation_effect'],
|
|
||||||
text=dict_['text'],
|
|
||||||
expansion=dict_['expansion']
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Monster(Card):
|
|
||||||
def __init__(self, monster_id, name, area, monster_type, order, strength_cost, magic_cost, vp_reward, gold_reward,
|
|
||||||
strength_reward, magic_reward, has_special_reward, special_reward, has_special_cost, special_cost,
|
|
||||||
is_extra, expansion):
|
|
||||||
super().__init__()
|
|
||||||
self.monster_id = monster_id
|
|
||||||
self.name = name
|
|
||||||
self.area = area
|
|
||||||
self.monster_type = monster_type
|
|
||||||
self.order = order
|
|
||||||
self.strength_cost = strength_cost
|
|
||||||
self.magic_cost = magic_cost
|
|
||||||
self.vp_reward = vp_reward
|
|
||||||
self.gold_reward = gold_reward
|
|
||||||
self.strength_reward = strength_reward
|
|
||||||
self.magic_reward = magic_reward
|
|
||||||
self.has_special_reward = has_special_reward
|
|
||||||
self.special_reward = special_reward
|
|
||||||
self.has_special_cost = has_special_cost
|
|
||||||
self.special_cost = special_cost
|
|
||||||
self.is_extra = is_extra
|
|
||||||
self.expansion = expansion
|
|
||||||
|
|
||||||
def to_dict(self):
|
|
||||||
card_dict = super().to_dict()
|
|
||||||
monster_dict = {
|
|
||||||
"monster_id": self.monster_id,
|
|
||||||
"area": self.area,
|
|
||||||
"monster_type": self.monster_type,
|
|
||||||
"order": self.order,
|
|
||||||
"strength_cost": self.strength_cost,
|
|
||||||
"magic_cost": self.magic_cost,
|
|
||||||
"vp_reward": self.vp_reward,
|
|
||||||
"gold_reward": self.gold_reward,
|
|
||||||
"strength_reward": self.strength_reward,
|
|
||||||
"magic_reward": self.magic_reward,
|
|
||||||
"has_special_reward": self.has_special_reward,
|
|
||||||
"special_reward": self.special_reward,
|
|
||||||
"has_special_cost": self.has_special_cost,
|
|
||||||
"special_cost": self.special_cost,
|
|
||||||
"is_extra": self.is_extra,
|
|
||||||
"expansion": self.expansion,
|
|
||||||
}
|
|
||||||
return {**card_dict, **monster_dict}
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_dict(cls, d):
|
|
||||||
return cls(
|
|
||||||
d['monster_id'],
|
|
||||||
d['name'],
|
|
||||||
d['area'],
|
|
||||||
d['monster_type'],
|
|
||||||
d['order'],
|
|
||||||
d['strength_cost'],
|
|
||||||
d['magic_cost'],
|
|
||||||
d['vp_reward'],
|
|
||||||
d['gold_reward'],
|
|
||||||
d['strength_reward'],
|
|
||||||
d['magic_reward'],
|
|
||||||
d['has_special_reward'],
|
|
||||||
d['special_reward'],
|
|
||||||
d['has_special_cost'],
|
|
||||||
d['special_cost'],
|
|
||||||
d['is_extra'],
|
|
||||||
d['expansion'],
|
|
||||||
)
|
|
||||||
|
|
||||||
def add_strength_cost(self, added_strength):
|
|
||||||
self.strength_cost = self.strength_cost + added_strength
|
|
||||||
|
|
||||||
def add_magic_cost(self, added_magic):
|
|
||||||
self.magic_cost = self.magic_cost + added_magic
|
|
||||||
|
|
||||||
|
|
||||||
class Duke(Card):
|
|
||||||
def __init__(self, duke_id, name, gold_mult, strength_mult, magic_mult, shadow_mult, holy_mult, soldier_mult,
|
|
||||||
worker_mult, monster_mult, citizen_mult, domain_mult, boss_mult, minion_mult, beast_mult, titan_mult,
|
|
||||||
expansion):
|
|
||||||
super().__init__()
|
|
||||||
self.duke_id = duke_id
|
|
||||||
self.name = name
|
|
||||||
self.gold_multiplier = gold_mult
|
|
||||||
self.strength_multiplier = strength_mult
|
|
||||||
self.magic_multiplier = magic_mult
|
|
||||||
self.shadow_multiplier = shadow_mult
|
|
||||||
self.holy_multiplier = holy_mult
|
|
||||||
self.soldier_multiplier = soldier_mult
|
|
||||||
self.worker_multiplier = worker_mult
|
|
||||||
self.monster_multiplier = monster_mult
|
|
||||||
self.citizen_multiplier = citizen_mult
|
|
||||||
self.domain_multiplier = domain_mult
|
|
||||||
self.boss_multiplier = boss_mult
|
|
||||||
self.minion_multiplier = minion_mult
|
|
||||||
self.beast_multiplier = beast_mult
|
|
||||||
self.titan_multiplier = titan_mult
|
|
||||||
self.expansion = expansion
|
|
||||||
|
|
||||||
def to_dict(self):
|
|
||||||
return {
|
|
||||||
**super().to_dict(),
|
|
||||||
"duke_id": self.duke_id,
|
|
||||||
"gold_multiplier": self.gold_multiplier,
|
|
||||||
"strength_multiplier": self.strength_multiplier,
|
|
||||||
"magic_multiplier": self.magic_multiplier,
|
|
||||||
"shadow_multiplier": self.shadow_multiplier,
|
|
||||||
"holy_multiplier": self.holy_multiplier,
|
|
||||||
"soldier_multiplier": self.soldier_multiplier,
|
|
||||||
"worker_multiplier": self.worker_multiplier,
|
|
||||||
"monster_multiplier": self.monster_multiplier,
|
|
||||||
"citizen_multiplier": self.citizen_multiplier,
|
|
||||||
"domain_multiplier": self.domain_multiplier,
|
|
||||||
"boss_multiplier": self.boss_multiplier,
|
|
||||||
"minion_multiplier": self.minion_multiplier,
|
|
||||||
"beast_multiplier": self.beast_multiplier,
|
|
||||||
"titan_multiplier": self.titan_multiplier,
|
|
||||||
"expansion": self.expansion
|
|
||||||
}
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_dict(cls, data):
|
|
||||||
duke_id = data["duke_id"]
|
|
||||||
name = data["name"]
|
|
||||||
gold_mult = data["gold_multiplier"]
|
|
||||||
strength_mult = data["strength_multiplier"]
|
|
||||||
magic_mult = data["magic_multiplier"]
|
|
||||||
shadow_mult = data["shadow_multiplier"]
|
|
||||||
holy_mult = data["holy_multiplier"]
|
|
||||||
soldier_mult = data["soldier_multiplier"]
|
|
||||||
worker_mult = data["worker_multiplier"]
|
|
||||||
monster_mult = data["monster_multiplier"]
|
|
||||||
citizen_mult = data["citizen_multiplier"]
|
|
||||||
domain_mult = data["domain_multiplier"]
|
|
||||||
boss_mult = data["boss_multiplier"]
|
|
||||||
minion_mult = data["minion_multiplier"]
|
|
||||||
beast_mult = data["beast_multiplier"]
|
|
||||||
titan_mult = data["titan_multiplier"]
|
|
||||||
expansion = data["expansion"]
|
|
||||||
return cls(duke_id, name, gold_mult, strength_mult, magic_mult, shadow_mult, holy_mult, soldier_mult,
|
|
||||||
worker_mult, monster_mult, citizen_mult, domain_mult, boss_mult, minion_mult, beast_mult,
|
|
||||||
titan_mult, expansion)
|
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
|
||||||
def __init__(self, game_state):
|
|
||||||
self.game_id = game_state['game_id']
|
|
||||||
self.player_list = game_state['player_list']
|
|
||||||
self.monster_grid = game_state['monster_grid']
|
|
||||||
self.citizen_grid = game_state['citizen_grid']
|
|
||||||
self.domain_grid = game_state['domain_grid']
|
|
||||||
self.die_one = game_state['die_one']
|
|
||||||
self.die_two = game_state['die_two']
|
|
||||||
self.die_sum = game_state['die_sum']
|
|
||||||
self.exhausted_count = game_state['exhausted_count']
|
|
||||||
self.effects = game_state['effects']
|
|
||||||
self.action_required = game_state['action_required']
|
|
||||||
|
|
||||||
def roll_phase(self):
|
|
||||||
self.die_one = random.randint(1, 6)
|
|
||||||
self.die_two = random.randint(1, 6)
|
|
||||||
self.die_sum = self.die_one + self.die_two
|
|
||||||
print(f"{self.die_one} | {self.die_two} | {self.die_sum}")
|
|
||||||
# check for player effects that are able to change roll
|
|
||||||
# check for board effects that trigger from rolls
|
|
||||||
|
|
||||||
def harvest_phase(self):
|
|
||||||
# steal activates first
|
|
||||||
for starter in self.player_list[0].owned_starters:
|
|
||||||
if (starter.roll_match1 == self.die_one) or (starter.roll_match1 == self.die_two) or (
|
|
||||||
starter.roll_match1 == self.die_sum) or (starter.roll_match2 == self.die_sum):
|
|
||||||
count = 1
|
|
||||||
if starter.roll_match1 == self.die_one == self.die_two:
|
|
||||||
count = 2
|
|
||||||
print(f"Payout for {self.player_list[0].name}: Starter {starter.name}{' x2' if count == 2 else ''}")
|
|
||||||
for i in range(count):
|
|
||||||
self.player_list[0].gold_score = self.player_list[0].gold_score + starter.gold_payout_on_turn
|
|
||||||
self.player_list[0].strength_score = self.player_list[
|
|
||||||
0].strength_score + starter.strength_payout_on_turn
|
|
||||||
self.player_list[0].magic_score = self.player_list[0].magic_score + starter.magic_payout_on_turn
|
|
||||||
if starter.has_special_payout_on_turn:
|
|
||||||
payout = self.execute_special_payout(starter.special_payout_on_turn,
|
|
||||||
self.player_list[0].player_id)
|
|
||||||
self.player_list[0].gold_score = self.player_list[0].gold_score + payout[0]
|
|
||||||
self.player_list[0].strength_score = self.player_list[0].strength_score + payout[1]
|
|
||||||
self.player_list[0].magic_score = self.player_list[0].magic_score + payout[2]
|
|
||||||
for citizen in self.player_list[0].owned_citizens:
|
|
||||||
if (citizen.roll_match1 == self.die_one) or (citizen.roll_match1 == self.die_two) or (
|
|
||||||
citizen.roll_match1 == self.die_sum) or (citizen.roll_match2 == self.die_sum):
|
|
||||||
count = 1
|
|
||||||
if citizen.roll_match1 == self.die_one == self.die_two:
|
|
||||||
count = 2
|
|
||||||
print(f"Payout for {self.player_list[0].name}: Citizen {citizen.name}{' x2' if count == 2 else ''}")
|
|
||||||
for i in range(count):
|
|
||||||
self.player_list[0].gold_score = self.player_list[0].gold_score + citizen.gold_payout_on_turn
|
|
||||||
self.player_list[0].strength_score = self.player_list[
|
|
||||||
0].strength_score + citizen.strength_payout_on_turn
|
|
||||||
self.player_list[0].magic_score = self.player_list[0].magic_score + citizen.magic_payout_on_turn
|
|
||||||
if citizen.has_special_payout_on_turn:
|
|
||||||
print(f"Citizen {citizen.name} special payout text: {citizen.special_payout_on_turn}")
|
|
||||||
payout = self.execute_special_payout(citizen.special_payout_on_turn,
|
|
||||||
self.player_list[0].player_id)
|
|
||||||
print(f"right after running execute special payout {payout}")
|
|
||||||
self.player_list[0].gold_score = self.player_list[0].gold_score + payout[0]
|
|
||||||
self.player_list[0].strength_score = self.player_list[0].strength_score + payout[1]
|
|
||||||
self.player_list[0].magic_score = self.player_list[0].magic_score + payout[2]
|
|
||||||
|
|
||||||
list_iterator = iter(self.player_list) # skip first player when paying out the rest of the board
|
|
||||||
next(list_iterator)
|
|
||||||
for player in list_iterator:
|
|
||||||
for starter in player.owned_starters:
|
|
||||||
if (starter.roll_match1 == self.die_one) or (starter.roll_match1 == self.die_two) or (
|
|
||||||
starter.roll_match1 == self.die_sum) or (starter.roll_match2 == self.die_sum):
|
|
||||||
count = 1
|
|
||||||
if starter.roll_match1 == self.die_one == self.die_two:
|
|
||||||
count = 2
|
|
||||||
print(f"Payout for {player.name}: Starter {starter.name}{' x2' if count == 2 else ''}")
|
|
||||||
for i in range(count):
|
|
||||||
player.gold_score = player.gold_score + starter.gold_payout_off_turn
|
|
||||||
player.strength_score = player.strength_score + starter.strength_payout_off_turn
|
|
||||||
player.magic_score = player.magic_score + starter.magic_payout_off_turn
|
|
||||||
if starter.has_special_payout_off_turn:
|
|
||||||
payout = self.execute_special_payout(starter.special_payout_off_turn, player.player_id)
|
|
||||||
player.gold_score = player.gold_score + payout[0]
|
|
||||||
player.strength_score = player.strength_score + payout[1]
|
|
||||||
player.magic_score = player.magic_score + payout[2]
|
|
||||||
|
|
||||||
for citizen in player.owned_citizens:
|
|
||||||
if (citizen.roll_match1 == self.die_one) or (citizen.roll_match1 == self.die_two) or (
|
|
||||||
citizen.roll_match1 == self.die_sum) or (citizen.roll_match2 == self.die_sum):
|
|
||||||
count = 1
|
|
||||||
if citizen.roll_match1 == self.die_one == self.die_two:
|
|
||||||
count = 2
|
|
||||||
print(f"Payout for {player.name}: Citizen {citizen.name}{' x2' if count == 2 else ''}")
|
|
||||||
for i in range(count):
|
|
||||||
player.gold_score = player.gold_score + citizen.gold_payout_off_turn
|
|
||||||
player.strength_score = player.strength_score + citizen.strength_payout_off_turn
|
|
||||||
player.magic_score = player.magic_score + citizen.magic_payout_off_turn
|
|
||||||
if citizen.has_special_payout_off_turn:
|
|
||||||
print("special payout off turn triggered")
|
|
||||||
print(citizen.special_payout_off_turn)
|
|
||||||
payout = self.execute_special_payout(citizen.special_payout_off_turn, player.player_id)
|
|
||||||
player.gold_score = player.gold_score + payout[0]
|
|
||||||
player.strength_score = player.strength_score + payout[1]
|
|
||||||
player.magic_score = player.magic_score + payout[2]
|
|
||||||
for player in self.player_list:
|
|
||||||
print(f"Player {player.name}: {player.gold_score} G, {player.strength_score} S, {player.magic_score} M,"
|
|
||||||
f" {player.victory_score} VP, Monsters: {len(player.owned_monsters)}, "
|
|
||||||
f"Citizens: {len(player.owned_citizens)}, Domains {len(player.owned_domains)}")
|
|
||||||
|
|
||||||
def execute_special_payout(self, command, player_id):
|
|
||||||
print("executing special payout")
|
|
||||||
payout = [0, 0, 0, 0] # gp, sp, mp, vp, todo: citizen, monster, domain
|
|
||||||
split_command = command.split()
|
|
||||||
first_word = split_command[0]
|
|
||||||
second_word = split_command[1]
|
|
||||||
third_word = split_command[2]
|
|
||||||
fourth_word = split_command[3]
|
|
||||||
match first_word:
|
|
||||||
case "count":
|
|
||||||
print("Matched count")
|
|
||||||
match second_word:
|
|
||||||
case "owned_shadow":
|
|
||||||
self.update_payout_for_role('shadow_count', player_id, payout, split_command)
|
|
||||||
case "owned_holy":
|
|
||||||
self.update_payout_for_role('holy_count', player_id, payout, split_command)
|
|
||||||
case "owned_soldier":
|
|
||||||
self.update_payout_for_role('soldier_count', player_id, payout, split_command)
|
|
||||||
case "owned_worker":
|
|
||||||
|
|
||||||
self.update_payout_for_role('worker_count', player_id, payout, split_command)
|
|
||||||
case "owned_monsters":
|
|
||||||
self.update_payout_for_role('owned_monsters', player_id, payout, split_command)
|
|
||||||
case "owned_citizens":
|
|
||||||
self.update_payout_for_role('owned_citizens', player_id, payout, split_command)
|
|
||||||
case "owned_domains":
|
|
||||||
self.update_payout_for_role('owned_domains', player_id, payout, split_command)
|
|
||||||
case _:
|
|
||||||
payout[0] = -9999
|
|
||||||
case "exchange":
|
|
||||||
print("Matched exchange")
|
|
||||||
match second_word:
|
|
||||||
case 'g':
|
|
||||||
payout[0] = payout[0] - int(third_word)
|
|
||||||
case 's':
|
|
||||||
payout[1] = payout[1] - int(third_word)
|
|
||||||
case 'm':
|
|
||||||
payout[2] = payout[2] - int(third_word)
|
|
||||||
case 'v':
|
|
||||||
payout[3] = payout[3] - int(third_word)
|
|
||||||
case _:
|
|
||||||
payout[0] = -9999
|
|
||||||
match fourth_word:
|
|
||||||
case 'g':
|
|
||||||
payout[0] = payout[0] + int(split_command[4])
|
|
||||||
case 's':
|
|
||||||
payout[1] = payout[1] + int(split_command[4])
|
|
||||||
case 'm':
|
|
||||||
payout[2] = payout[2] + int(split_command[4])
|
|
||||||
case 'v':
|
|
||||||
payout[3] = payout[3] + int(split_command[4])
|
|
||||||
case _:
|
|
||||||
payout[0] = -9999
|
|
||||||
case "choose":
|
|
||||||
print("Matched choose")
|
|
||||||
self.action_required['player_id'] = player_id
|
|
||||||
self.action_required['action'] = command
|
|
||||||
# need to pause execution here until we get player input
|
|
||||||
while self.action_required['player_id'] != self.game_id:
|
|
||||||
time.sleep(1)
|
|
||||||
choice = []
|
|
||||||
match self.action_required['action']:
|
|
||||||
case 'choose 1':
|
|
||||||
choice = [second_word, third_word]
|
|
||||||
case 'choose 2':
|
|
||||||
choice = [fourth_word, split_command[4]]
|
|
||||||
case 'choose 3':
|
|
||||||
choice = [split_command[5], split_command[6]] # [sixth_word, seventh_word]
|
|
||||||
case _:
|
|
||||||
payout[0] = -9999
|
|
||||||
match choice[0]:
|
|
||||||
case 'g':
|
|
||||||
payout[0] = payout[0] + choice[1]
|
|
||||||
case 's':
|
|
||||||
payout[1] = payout[1] + choice[1]
|
|
||||||
case 'm':
|
|
||||||
payout[2] = payout[2] + choice[1]
|
|
||||||
case 'v':
|
|
||||||
payout[3] = payout[3] + choice[1]
|
|
||||||
case _:
|
|
||||||
payout[0] = -9999
|
|
||||||
case _:
|
|
||||||
payout[0] = -9999
|
|
||||||
print(payout)
|
|
||||||
return payout
|
|
||||||
|
|
||||||
def update_payout_for_role(self, role_name, player_id, payout, split_command):
|
|
||||||
role_count = 0
|
|
||||||
for player in self.player_list:
|
|
||||||
if player.player_id == player_id:
|
|
||||||
role_count = player.calc_roles()[role_name]
|
|
||||||
break
|
|
||||||
if role_count > 0:
|
|
||||||
match split_command[2]:
|
|
||||||
case 'g':
|
|
||||||
payout[0] = int(split_command[3]) * role_count
|
|
||||||
case 's':
|
|
||||||
payout[1] = int(split_command[3]) * role_count
|
|
||||||
case 'm':
|
|
||||||
payout[2] = int(split_command[3]) * role_count
|
|
||||||
case 'v':
|
|
||||||
payout[3] = int(split_command[3]) * role_count
|
|
||||||
case _:
|
|
||||||
payout[0] = -9999
|
|
||||||
else:
|
|
||||||
payout[0] = -9999
|
|
||||||
|
|
||||||
def hire_citizen(self, player_id, citizen_id, gp, mp=0):
|
|
||||||
for citizen_stack in self.citizen_grid:
|
|
||||||
for citizen in citizen_stack:
|
|
||||||
if citizen.citizen_id == citizen_id and citizen.is_accessible:
|
|
||||||
for player in self.player_list:
|
|
||||||
if player.player_id == player_id:
|
|
||||||
player.gold_score = player.gold_score - gp
|
|
||||||
player.magic_score = player.magic_score - mp
|
|
||||||
player.owned_citizens.append(citizen_stack.pop(-1))
|
|
||||||
citizen_stack[-1].toggle_accessibility(True)
|
|
||||||
|
|
||||||
def slay_monster(self, player_id, monster_id, sp, mp=0):
|
|
||||||
for monster_stack in self.monster_grid:
|
|
||||||
for monster in monster_stack:
|
|
||||||
if monster.monster_id == monster_id and monster.is_accessible:
|
|
||||||
for player in self.player_list:
|
|
||||||
if player.player_id == player_id:
|
|
||||||
player.strength_score = player.strength_score - sp
|
|
||||||
player.magic_score = player.magic_score - mp
|
|
||||||
player.owned_monsters.append(monster_stack.pop(-1))
|
|
||||||
monster_stack[-1].toggle_accessibility(True)
|
|
||||||
|
|
||||||
def buy_domain(self, player_id, domain_id, gp, mp=0):
|
|
||||||
for domain_stack in self.domain_grid:
|
|
||||||
for domain in domain_stack:
|
|
||||||
if domain.domain_id == domain_id and domain.is_accessible:
|
|
||||||
for player in self.player_list:
|
|
||||||
if player.player_id == player_id:
|
|
||||||
player.gold_score = player.gold_score - gp
|
|
||||||
player.magic_score = player.magic_score - mp
|
|
||||||
player.owned_domains.append(domain_stack.pop(-1))
|
|
||||||
domain_stack[-1].toggle_accessibility(True)
|
|
||||||
|
|
||||||
def action_phase(self):
|
|
||||||
return
|
|
||||||
|
|
||||||
def play_turn(self):
|
|
||||||
self.roll_phase()
|
|
||||||
self.harvest_phase()
|
|
||||||
self.action_phase()
|
|
||||||
|
|
||||||
def end_check(self):
|
|
||||||
if self.exhausted_count <= (len(self.player_list) * 2):
|
|
||||||
return False
|
|
||||||
|
|
||||||
def prompt(self):
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
class SummaryEncoder(JSONEncoder):
|
|
||||||
def default(self, obj):
|
|
||||||
if isinstance(obj, Player):
|
|
||||||
return {
|
|
||||||
'player_id': obj.player_id,
|
|
||||||
'name': obj.name,
|
|
||||||
'owned_citizens': len(obj.owned_citizens),
|
|
||||||
'owned_domains': len(obj.owned_domains),
|
|
||||||
'owned_monsters': len(obj.owned_monsters),
|
|
||||||
'gold_score': obj.gold_score,
|
|
||||||
'strength_score': obj.strength_score,
|
|
||||||
'magic_score': obj.magic_score,
|
|
||||||
'victory_score': obj.victory_score,
|
|
||||||
'is_first': obj.is_first
|
|
||||||
}
|
|
||||||
elif isinstance(obj, LobbyMember):
|
|
||||||
return {
|
|
||||||
"player_name": obj.name,
|
|
||||||
"player_id": obj.player_id,
|
|
||||||
"is_ready": obj.is_ready
|
|
||||||
}
|
|
||||||
elif isinstance(obj, GameMember):
|
|
||||||
return {
|
|
||||||
"player_name": obj.name,
|
|
||||||
"player_id": obj.player_id
|
|
||||||
}
|
|
||||||
elif isinstance(obj, Game):
|
|
||||||
return {
|
|
||||||
"game_id": obj.game_id,
|
|
||||||
"player_list": obj.player_list
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
return super().default(obj)
|
|
||||||
|
|
||||||
|
|
||||||
class GameObjectEncoder(JSONEncoder):
|
|
||||||
def default(self, obj):
|
|
||||||
if isinstance(obj, Player):
|
|
||||||
return {
|
|
||||||
'player_id': obj.player_id,
|
|
||||||
'name': obj.name,
|
|
||||||
'owned_starters': [starter.starter_id for starter in obj.owned_starters],
|
|
||||||
'owned_citizens': [citizen.citizen_id for citizen in obj.owned_citizens],
|
|
||||||
'owned_domains': [domain.domain_id for domain in obj.owned_domains],
|
|
||||||
'owned_dukes': [duke.duke_id for duke in obj.owned_dukes],
|
|
||||||
'owned_monsters': [monster.monster_id for monster in obj.owned_monsters],
|
|
||||||
'gold_score': obj.gold_score,
|
|
||||||
'strength_score': obj.strength_score,
|
|
||||||
'magic_score': obj.magic_score,
|
|
||||||
'victory_score': obj.victory_score,
|
|
||||||
'is_first': obj.is_first,
|
|
||||||
'shadow_count': obj.shadow_count,
|
|
||||||
'holy_count': obj.holy_count,
|
|
||||||
'soldier_count': obj.soldier_count,
|
|
||||||
'worker_count': obj.worker_count,
|
|
||||||
'effects': obj.effects
|
|
||||||
}
|
|
||||||
elif isinstance(obj, Duke):
|
|
||||||
return obj.to_dict()
|
|
||||||
elif isinstance(obj, Monster):
|
|
||||||
return obj.to_dict()
|
|
||||||
elif isinstance(obj, Starter):
|
|
||||||
return obj.to_dict()
|
|
||||||
elif isinstance(obj, Citizen):
|
|
||||||
return obj.to_dict()
|
|
||||||
elif isinstance(obj, Domain):
|
|
||||||
return obj.to_dict()
|
|
||||||
elif isinstance(obj, Game):
|
|
||||||
return {
|
|
||||||
"game_id": obj.game_id,
|
|
||||||
"player_list": obj.player_list,
|
|
||||||
"monster_grid": obj.monster_grid,
|
|
||||||
"citizen_grid": obj.citizen_grid,
|
|
||||||
"domain_grid": obj.domain_grid,
|
|
||||||
"die_one": obj.die_one,
|
|
||||||
"die_two": obj.die_two,
|
|
||||||
"die_sum": obj.die_sum,
|
|
||||||
"exhausted_count": obj.exhausted_count,
|
|
||||||
"effects": obj.effects,
|
|
||||||
"action_required": obj.action_required
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
return super().default(obj)
|
|
||||||
|
|
||||||
|
|
||||||
def send_data(conn, data):
|
|
||||||
header = f"{len(data):<{Constants.header_size}}"
|
|
||||||
conn.send(header.encode(Constants.encoding))
|
|
||||||
offset = 0
|
|
||||||
while offset < len(data):
|
|
||||||
chunk = data[offset:offset + Constants.buffer_size]
|
|
||||||
conn.send(chunk)
|
|
||||||
offset += Constants.buffer_size
|
|
||||||
|
|
||||||
|
|
||||||
def receive_data(conn):
|
|
||||||
# Read the header to determine the message length
|
|
||||||
header = b""
|
|
||||||
while len(header) < Constants.header_size:
|
|
||||||
chunk = conn.recv(Constants.header_size - len(header))
|
|
||||||
if not chunk:
|
|
||||||
raise ConnectionError("Connection closed by server")
|
|
||||||
header += chunk
|
|
||||||
msg_length = int(header.decode(Constants.encoding).strip())
|
|
||||||
|
|
||||||
# Read the message in chunks until the entire message is received
|
|
||||||
data = b""
|
|
||||||
while len(data) < msg_length:
|
|
||||||
chunk_size = min(Constants.buffer_size, msg_length - len(data))
|
|
||||||
chunk = conn.recv(chunk_size)
|
|
||||||
if not chunk:
|
|
||||||
raise ConnectionError("Connection closed by server")
|
|
||||||
data += chunk
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
class LobbyMember:
|
|
||||||
def __init__(self, player_name, player_id):
|
|
||||||
self.name = player_name
|
|
||||||
self.player_id = player_id
|
|
||||||
self.is_ready = False
|
|
||||||
self.last_active_time = 0
|
|
||||||
|
|
||||||
|
|
||||||
class GameMember:
|
|
||||||
def __init__(self, player_id, player_name, game_id):
|
|
||||||
self.name = player_name
|
|
||||||
self.player_id = player_id
|
|
||||||
self.game_id = game_id
|
|
||||||
@@ -2,8 +2,8 @@ class Constants:
|
|||||||
green = (106, 171, 115)
|
green = (106, 171, 115)
|
||||||
red = (219, 92, 92)
|
red = (219, 92, 92)
|
||||||
server_host = '192.168.1.99'
|
server_host = '192.168.1.99'
|
||||||
host = "lukesau.com"
|
# host = "lukesau.com"
|
||||||
# host = "127.0.1.1"
|
host = "127.0.1.1"
|
||||||
port = 8328
|
port = 8328
|
||||||
text_format = "utf-8"
|
text_format = "utf-8"
|
||||||
small_window_size = (300, 150)
|
small_window_size = (300, 150)
|
||||||
@@ -12,3 +12,5 @@ class Constants:
|
|||||||
header_size = 512
|
header_size = 512
|
||||||
buffer_size = 4096
|
buffer_size = 4096
|
||||||
encoding = "utf-8"
|
encoding = "utf-8"
|
||||||
|
areas = ['Hills', 'Ruins', 'Forest', 'Valley', 'Mountains']
|
||||||
|
types = ['Minion', 'Titan', 'Warden', 'Boss', 'Beast']
|
||||||
|
|||||||
13
docs/README.md
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# VCK Online Docs
|
||||||
|
|
||||||
|
This folder contains developer documentation for the VCK Online dev/test server and game engine.
|
||||||
|
|
||||||
|
## Start here
|
||||||
|
|
||||||
|
- `README_SERVER.md`: how to run the FastAPI server and use the dev HTML client
|
||||||
|
- `dev-setup.md`: local environment setup (venv + MariaDB connector)
|
||||||
|
- `database.md`: database expectations, SSH tunnel, and stored procedure setup
|
||||||
|
- `server.md`: FastAPI server architecture and API surface
|
||||||
|
- `game.md`: game engine model and the DB-backed game bootstrap flow
|
||||||
|
- `testing.md`: how to run the included test scripts
|
||||||
|
|
||||||
79
docs/README_SERVER.md
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
# VCK Online FastAPI Server
|
||||||
|
|
||||||
|
Simple REST API server for developing and testing the Valeria Card Kingdoms Online game.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
1. Install dependencies:
|
||||||
|
```bash
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Make sure database is accessible (SSH tunnel if needed):
|
||||||
|
```bash
|
||||||
|
ssh -L 3306:localhost:3306 lukesau.com
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running the Server
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 server.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Or with uvicorn directly:
|
||||||
|
```bash
|
||||||
|
uvicorn server:app --host 0.0.0.0 --port 8000 --reload
|
||||||
|
```
|
||||||
|
|
||||||
|
The server will start on `http://localhost:8000`
|
||||||
|
|
||||||
|
## API Endpoints
|
||||||
|
|
||||||
|
### Lobby
|
||||||
|
|
||||||
|
- `POST /api/lobby/join` - Join lobby with name
|
||||||
|
```json
|
||||||
|
{"name": "Player Name"}
|
||||||
|
```
|
||||||
|
Returns: `{"player_id": "...", "message": "Joined lobby"}`
|
||||||
|
|
||||||
|
- `POST /api/lobby/ready` - Mark player as ready
|
||||||
|
```json
|
||||||
|
{"player_id": "..."}
|
||||||
|
```
|
||||||
|
Returns game info if all players ready
|
||||||
|
|
||||||
|
- `POST /api/lobby/unready` - Mark player as not ready
|
||||||
|
- `POST /api/lobby/leave?player_id=...` - Leave lobby
|
||||||
|
- `GET /api/lobby/status?player_id=...` - Get lobby status
|
||||||
|
|
||||||
|
### Game
|
||||||
|
|
||||||
|
- `GET /api/game/{game_id}/state` - Get current game state
|
||||||
|
- `POST /api/game/{game_id}/action` - Perform game action
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"player_id": "...",
|
||||||
|
"action_type": "hire_citizen|build_domain|slay_monster|act_on_required_action|roll_phase|harvest_phase|play_turn",
|
||||||
|
"citizen_id": 123, // for hire_citizen
|
||||||
|
"domain_id": 456, // for build_domain
|
||||||
|
"monster_id": 789, // for slay_monster
|
||||||
|
"gold_cost": 5, // for hire_citizen/build_domain
|
||||||
|
"strength_cost": 3, // for slay_monster
|
||||||
|
"magic_cost": 0, // optional
|
||||||
|
"action": "choose 1" // for act_on_required_action
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Web Client
|
||||||
|
|
||||||
|
Visit `http://localhost:8000` for a simple HTML client to test the API.
|
||||||
|
|
||||||
|
## Development Notes
|
||||||
|
|
||||||
|
- Games are stored in-memory (will be lost on server restart)
|
||||||
|
- Inactive games are cleaned up after 3 minutes of no activity
|
||||||
|
- Inactive lobby players are removed after 60 seconds
|
||||||
|
- This is a development/testing server, not production-ready
|
||||||
|
|
||||||
|
|
||||||
64
docs/database.md
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
# Database
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
The game bootstrap in `game.py` loads card data from a MariaDB database named `vckonline` using stored procedures to select card sets and randomize stacks.
|
||||||
|
|
||||||
|
The code assumes it can connect to:
|
||||||
|
|
||||||
|
- host: `127.0.0.1`
|
||||||
|
- port: `3306`
|
||||||
|
- user: `vckonline`
|
||||||
|
- password: `vckonline`
|
||||||
|
- database: `vckonline`
|
||||||
|
|
||||||
|
This is designed to work with an SSH tunnel that forwards the remote DB to local port 3306.
|
||||||
|
|
||||||
|
## SSH tunnel
|
||||||
|
|
||||||
|
Keep an SSH port forward running while using the DB locally:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ssh -L 3306:localhost:3306 lukesau.com
|
||||||
|
```
|
||||||
|
|
||||||
|
## Stored procedures
|
||||||
|
|
||||||
|
The server/game code expects these procedures to exist:
|
||||||
|
|
||||||
|
- `select_base1_monsters()`
|
||||||
|
- `select_base1_citizens()`
|
||||||
|
- `select_base2_monsters()`
|
||||||
|
- `select_base2_citizens()`
|
||||||
|
- `select_random_domains()`
|
||||||
|
- `select_random_dukes()`
|
||||||
|
|
||||||
|
To install all procedures:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./sql/run_sql.sh sql/create_all_stored_procedures.sql
|
||||||
|
```
|
||||||
|
|
||||||
|
See `sql/INSTALL_PROCEDURES.md` for additional options (mysql client, interactive MariaDB session, installing individually).
|
||||||
|
|
||||||
|
## User / grants setup
|
||||||
|
|
||||||
|
If you have authentication or permissions problems, use:
|
||||||
|
|
||||||
|
- `sql/USER_SETUP_GUIDE.md`: investigation and fix commands (create users for `localhost`, `127.0.0.1`, `%`, and grant privileges)
|
||||||
|
- `sql/fix_user_setup.sql`: a convenience SQL script in this repo (if you prefer to run a script vs copy/paste commands)
|
||||||
|
|
||||||
|
## Verifying the DB
|
||||||
|
|
||||||
|
Quick port-level check (no Python deps):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 check_db_server.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Full end-to-end check (Python + DB + tables + stored procs):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 test_database.py
|
||||||
|
```
|
||||||
|
|
||||||
33
docs/dev-setup.md
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# Dev setup
|
||||||
|
|
||||||
|
## Python environment
|
||||||
|
|
||||||
|
This repo expects a Python venv in `.venv/`.
|
||||||
|
|
||||||
|
The easiest path on macOS is to use the helper script:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./setup_venv.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
That script:
|
||||||
|
|
||||||
|
- Creates (or reuses) `.venv/`
|
||||||
|
- Tries to locate `mariadb_config` under `/opt/homebrew`
|
||||||
|
- Installs `mariadb-connector-c` via Homebrew if needed
|
||||||
|
- Exports `MARIADB_CONFIG` and runs `pip install -r requirements.txt`
|
||||||
|
|
||||||
|
If you already have `.venv/` created and just want to activate with the MariaDB environment variable:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
source ./activate_with_env.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
Dependencies are listed in `requirements.txt` and include:
|
||||||
|
|
||||||
|
- `fastapi` + `uvicorn` (API server)
|
||||||
|
- `mariadb` (DB access; requires MariaDB Connector/C to build)
|
||||||
|
- `shortuuid` (player id generation)
|
||||||
|
|
||||||
181
docs/effect-strings.md
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
# Effect String Syntax
|
||||||
|
|
||||||
|
This document covers how effect strings work across the three card tables (citizens, domains, monsters), where the syntax currently diverges, and the proposed unified grammar.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Current state by table
|
||||||
|
|
||||||
|
### Citizens — `special_payout_on_turn` / `special_payout_off_turn`
|
||||||
|
|
||||||
|
| Card | String | Meaning |
|
||||||
|
|---|---|---|
|
||||||
|
| Merchant | `choose g 2 m 2` | Pick one: +2g or +2m |
|
||||||
|
| Mercenary | `exchange s 1 g 2` | Pay 1s, gain 2g |
|
||||||
|
| Champion | `exchange g 1 s 4` | Pay 1g, gain 4s |
|
||||||
|
| Paladin | `exchange s 1 m 3` | Pay 1s, gain 3m |
|
||||||
|
| Butcher | `count owned_worker g 2` | Gain 2g per owned Worker citizen |
|
||||||
|
|
||||||
|
### Domains — `activation_effect`
|
||||||
|
|
||||||
|
| Card | String | Meaning |
|
||||||
|
|---|---|---|
|
||||||
|
| Ancient Tomb | `action.modify_monster_strength +3` | Prompt: add 3 to a monster's strength cost |
|
||||||
|
| Pretorius Conclave | `choose <citizens>` | Prompt: take any citizen from the board |
|
||||||
|
| Cursed Cavern | `m 4 + concurrent_flip_one_citizen` | Gain 4m; all players flip a citizen |
|
||||||
|
| Darktide Harbour | `choose <citizens where role==shadow>` | Prompt: take a shadow citizen |
|
||||||
|
| Cloudrider's Camp | `s 3 + choose <citizens where role==soldier and gold_cost<=2>` | Gain 3s; prompt: take a soldier citizen worth ≤2g |
|
||||||
|
| Wisborg | `manipulate_resources mode=self_convert pay=g:3 gain=v:3 optional=true` | Optionally pay 3g to gain 3vp |
|
||||||
|
|
||||||
|
### Domains — `passive_effect`
|
||||||
|
|
||||||
|
| Card | String | Meaning |
|
||||||
|
|---|---|---|
|
||||||
|
| Jousting Field | `harvest.gain_per_owned_citizen_name Knight g 1` | Harvest phase: gain 1g per Knight owned |
|
||||||
|
| Foxgrove Palisade | `roll.set_one_die target=6 cost=g:2` | Roll phase: pay 2g to set a die to 6 |
|
||||||
|
| The Desert Orchid | `roll.set_one_die target=1 cost=g_per_owned_role:holy_citizen` | Roll phase: pay 1g per holy citizen to set a die to 1 |
|
||||||
|
| Emerald Stronghold | `effect.add action.emeraldstronghold` | Flag: ignore + when buying citizens |
|
||||||
|
| Pratchett's Plateau | `effect.add action.pratchettsplateau` | Flag: domains cost 1g less |
|
||||||
|
| Shelley Commons | `action.end manipulate_resources mode=pay_to_player gain=v:1 pay=g:1 optional=true` | End of action: optionally pay 1g to a player for 1vp |
|
||||||
|
| Cathedral of St Aquila | `action.end manipulate_resources mode=take_from_player take=g:1 optional=true` | End of action: optionally take 1g from a player |
|
||||||
|
| King Tower | `action.end manipulate_resources mode=pay_to_player gain=v:1 pay=m:1 optional=true` | End of action: optionally pay 1m to a player for 1vp |
|
||||||
|
| The Orb of Urdr | `action.end manipulate_resources mode=take_from_player take=m:1 optional=true` | End of action: optionally take 1m from a player |
|
||||||
|
|
||||||
|
### Monsters — `special_reward`
|
||||||
|
|
||||||
|
| Card | String | Meaning |
|
||||||
|
|---|---|---|
|
||||||
|
| Goblin Mage | `choose g 1 m 1` | Pick one: +1g or +1m |
|
||||||
|
| Goblin Bomber | `choose g 2 m 2 s 2` | Pick one: +2g, +2m, or +2s |
|
||||||
|
| Goblin King | `count area Hills g 1` | Gain 1g per Hills monster slain |
|
||||||
|
| Skeleton King | `count area Ruins g 2` | Gain 2g per Ruins monster slain |
|
||||||
|
| Bane Spider | `choose g 3 <citizens where name==Knight>` | Pick one: +3g or take a Knight citizen |
|
||||||
|
| Ettercap | `choose <citizens where gold_cost<=2>` | Take a citizen worth ≤2g |
|
||||||
|
| Spider Queen | `choose <count area Forest g 2> <citizens + v 1>` | Pick one: 2g per Forest monster slain, or take a citizen and gain 1vp |
|
||||||
|
| Satyr Mage | `choose g 5 m 5 s 5` | Pick one: +5g, +5m, or +5s |
|
||||||
|
| Troll | `count area Valley m 2` | Gain 2m per Valley monster slain |
|
||||||
|
| Dire Bear | `choose g 2 m 2` | Pick one: +2g or +2m |
|
||||||
|
| Orc Warrior | `choose <citizens where gold_cost<=3>` | Take a citizen worth ≤3g |
|
||||||
|
| Orc Batrider | `choose <citizens>` | Take any citizen |
|
||||||
|
| Orc Chieftain | `count area Mountain g 2` | Gain 2g per Mountain monster slain |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Where the syntax diverges
|
||||||
|
|
||||||
|
### 1. Resource notation — two forms
|
||||||
|
|
||||||
|
Citizens and monsters use positional shorthand; domain KV pairs use colon notation:
|
||||||
|
|
||||||
|
```
|
||||||
|
# positional (citizens, monsters)
|
||||||
|
choose g 2 m 2
|
||||||
|
count owned_worker g 2
|
||||||
|
|
||||||
|
# colon inside KV values (domain passives)
|
||||||
|
action.end manipulate_resources mode=pay_to_player gain=v:1 pay=g:1
|
||||||
|
manipulate_resources mode=self_convert pay=g:3 gain=v:3
|
||||||
|
roll.set_one_die cost=g:2
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. `count` — same structure, different second word
|
||||||
|
|
||||||
|
The two count patterns are syntactically parallel but semantically distinct. No unification needed beyond being aware they share a parser.
|
||||||
|
|
||||||
|
```
|
||||||
|
count owned_worker g 2 # count by citizen role owned
|
||||||
|
count area Hills g 1 # count by monster area slain
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. `choose` — brackets sometimes, not always
|
||||||
|
|
||||||
|
The bracket vs no-bracket distinction does carry real meaning and is worth keeping:
|
||||||
|
|
||||||
|
```
|
||||||
|
choose g 1 m 1 # pick one of these resource amounts
|
||||||
|
choose g 3 <citizens where name==Knight> # pick a resource amount OR an entity
|
||||||
|
choose <citizens where gold_cost<=2> # pick an entity from a filtered set
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. `exchange` — only exists in citizens
|
||||||
|
|
||||||
|
No equivalent pattern in domains or monsters. Could be expressed as a compound but `exchange` is readable:
|
||||||
|
|
||||||
|
```
|
||||||
|
exchange s 1 g 2 # pay 1s, receive 2g
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. `.` is doing three different jobs
|
||||||
|
|
||||||
|
```
|
||||||
|
harvest.gain_per_owned_citizen_name ... # dot = phase separator (phase.verb)
|
||||||
|
roll.set_one_die ... # dot = phase separator (phase.verb)
|
||||||
|
action.end manipulate_resources ... # dot = phase separator, then space, then verb
|
||||||
|
action.modify_monster_strength +3 # dot = namespace separator, not timing
|
||||||
|
effect.add action.emeraldstronghold # dot = verb separator, then dot = namespace
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6. `manipulate_resources` wrapper verbosity
|
||||||
|
|
||||||
|
The `mode=` value is doing the same work as a first-word verb. The wrapper adds noise:
|
||||||
|
|
||||||
|
```
|
||||||
|
# current
|
||||||
|
action.end manipulate_resources mode=pay_to_player gain=v:1 pay=g:1 optional=true
|
||||||
|
|
||||||
|
# without the wrapper — same information
|
||||||
|
action.end pay_to_player g 1 v 1 optional
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Proposed unified grammar
|
||||||
|
|
||||||
|
### Core rules
|
||||||
|
|
||||||
|
1. **`.` means phase prefix only.** The left side is always a timing trigger (`harvest`, `roll`, `action.end`). Bare verbs have no dot.
|
||||||
|
2. **Resource amounts are always positional: `g N`.** Colon notation (`g:N`) only appears inside `=` assignments in KV strings where a space would be ambiguous.
|
||||||
|
3. **`choose` uses brackets for entity picks, bare words for resource picks.** Mixed is allowed: `choose g 3 <citizens where name==Knight>`.
|
||||||
|
4. **Compound effects use ` + `.** Each leg is a self-contained effect: `m 4 + concurrent_flip_one_citizen`.
|
||||||
|
|
||||||
|
### Proposed rewrites
|
||||||
|
|
||||||
|
**Domain activation:**
|
||||||
|
|
||||||
|
```
|
||||||
|
# before → after
|
||||||
|
action.modify_monster_strength +3 → modify_monster_strength 3
|
||||||
|
m 4 + concurrent_flip_one_citizen → no change
|
||||||
|
manipulate_resources mode=self_convert pay=g:3 gain=v:3 ... → self_convert g 3 v 3 optional
|
||||||
|
choose <citizens where role==shadow> → no change
|
||||||
|
s 3 + choose <citizens where role==soldier and gold_cost<=2> → no change
|
||||||
|
```
|
||||||
|
|
||||||
|
**Domain passive:**
|
||||||
|
|
||||||
|
```
|
||||||
|
# before → after
|
||||||
|
action.end manipulate_resources mode=pay_to_player gain=v:1 pay=g:1 optional=true → action.end pay_to_player g 1 v 1 optional
|
||||||
|
action.end manipulate_resources mode=take_from_player take=g:1 optional=true → action.end take_from_player g 1 optional
|
||||||
|
action.end manipulate_resources mode=pay_to_player gain=v:1 pay=m:1 optional=true → action.end pay_to_player m 1 v 1 optional
|
||||||
|
action.end manipulate_resources mode=take_from_player take=m:1 optional=true → action.end take_from_player m 1 optional
|
||||||
|
|
||||||
|
harvest.gain_per_owned_citizen_name Knight g 1 → no change
|
||||||
|
roll.set_one_die target=6 cost=g:2 → no change
|
||||||
|
effect.add action.emeraldstronghold → no change
|
||||||
|
```
|
||||||
|
|
||||||
|
**Citizens and monsters:** no changes needed — syntax is already consistent within each table and the proposed rules codify what they already do.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## What stays as parsed strings vs opaque keys
|
||||||
|
|
||||||
|
All effects in the tables above are **parsed strings** — a new card with different numbers works without any code change.
|
||||||
|
|
||||||
|
The only candidates for opaque keys are effects with branching prompt logic unique to a single card that cannot be generalized with different parameters:
|
||||||
|
|
||||||
|
- `concurrent_flip_one_citizen` (Cursed Cavern) — multi-player concurrent event
|
||||||
|
- `modify_monster_strength 3` (Ancient Tomb) — board-state mutation prompt
|
||||||
|
|
||||||
|
Even these stay as strings under the unified grammar; they just dispatch to named functions rather than an inline parsing branch. The DB string is the key; the function is the implementation.
|
||||||
121
docs/game.md
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
# Game engine (`game.py`)
|
||||||
|
|
||||||
|
## Key types
|
||||||
|
|
||||||
|
`game.py` defines the core runtime objects used by the server:
|
||||||
|
|
||||||
|
- `Game`: contains the current game board state and implements actions/phases
|
||||||
|
- `Player`: per-player scores and owned cards
|
||||||
|
- `LobbyMember` / `GameMember`: lightweight records used by the server for lobby/game membership
|
||||||
|
|
||||||
|
It also provides:
|
||||||
|
|
||||||
|
- `load_game_data(...)`: builds an initial `game_state` dict by pulling data from MariaDB and dealing stacks
|
||||||
|
- `SummaryEncoder` and `GameObjectEncoder`: JSON encoders used by the server to serialize game state
|
||||||
|
|
||||||
|
## Game lifecycle
|
||||||
|
|
||||||
|
At runtime (via the server):
|
||||||
|
|
||||||
|
- `server.py` calls `load_game_data(game_id, preset, game_gamers)` to create a starting `game_state`
|
||||||
|
- The server wraps that dict in a `Game` object: `Game(game_state)`
|
||||||
|
- The server exposes the game via `/api/game/{game_id}/state` and `/api/game/{game_id}/action`
|
||||||
|
|
||||||
|
The `Game` object tracks:
|
||||||
|
|
||||||
|
- `player_list`
|
||||||
|
- `monster_grid`, `citizen_grid`, `domain_grid`
|
||||||
|
- dice: `die_one`, `die_two`, `die_sum`
|
||||||
|
- `effects`
|
||||||
|
- `action_required` (used to block on per-player, sequential “choose …” actions)
|
||||||
|
- `concurrent_action` (used to block on non-ordered, multi-player prompts; see “Concurrent actions” below)
|
||||||
|
- `last_active_time` (used by the server for cleanup)
|
||||||
|
|
||||||
|
## DB-backed bootstrap (`load_game_data`)
|
||||||
|
|
||||||
|
`load_game_data` is responsible for:
|
||||||
|
|
||||||
|
- Fetching cards using stored procedures:
|
||||||
|
- citizens/monsters depend on the `preset` (e.g. `"base1"` / `"base2"`)
|
||||||
|
- domains and dukes are randomized via procedures
|
||||||
|
- starters are selected via a direct `SELECT * FROM starters`
|
||||||
|
- Creating `Player` instances from the lobby/game membership list
|
||||||
|
- Randomizing player order and dealing initial cards
|
||||||
|
- Dealing stacks onto the board:
|
||||||
|
- monsters grouped by area, then 5 areas selected
|
||||||
|
- citizens grouped by roll match, placed into 10 stacks (special-cased for roll 11)
|
||||||
|
- domains dealt into 5 stacks of 3, with the top visible/accessible
|
||||||
|
|
||||||
|
This function currently assumes local DB connectivity via `127.0.0.1:3306` (typically via SSH port forward).
|
||||||
|
|
||||||
|
See `docs/database.md` for DB setup and stored procedure installation.
|
||||||
|
|
||||||
|
## Actions & phases
|
||||||
|
|
||||||
|
The server routes map `action_type` strings to methods on `Game`.
|
||||||
|
|
||||||
|
Common paths:
|
||||||
|
|
||||||
|
- `roll_phase()` rolls two dice and computes a sum
|
||||||
|
- `harvest_phase()` pays out from owned starters/citizens for all players based on the roll
|
||||||
|
- `hire_citizen(...)`, `build_domain(...)`, `slay_monster(...)` mutate board stacks and player resources
|
||||||
|
|
||||||
|
### “choose …” actions
|
||||||
|
|
||||||
|
Some special payouts set `action_required` and start a background thread that waits until `act_on_required_action` updates `action_required` with a choice.
|
||||||
|
|
||||||
|
This is a dev-oriented approach; it allows the REST API to supply a follow-up choice via `act_on_required_action` while the game engine waits.
|
||||||
|
|
||||||
|
## Concurrent actions (non-ordered prompts)
|
||||||
|
|
||||||
|
Some prompts are not turn-based: every participating player should be able to
|
||||||
|
respond at the same time, in any order, and the game must wait until **all**
|
||||||
|
of them have submitted before progressing. The starting duke selection is the
|
||||||
|
first example — every player simultaneously discards down to one of the dukes
|
||||||
|
they were dealt.
|
||||||
|
|
||||||
|
These are modeled with `Game.concurrent_action`, which is independent from
|
||||||
|
`action_required`:
|
||||||
|
|
||||||
|
```
|
||||||
|
concurrent_action = {
|
||||||
|
"kind": "choose_duke", # routes to a handler in CONCURRENT_HANDLERS
|
||||||
|
"pending": ["pid1", "pid3"],
|
||||||
|
"completed": ["pid2"],
|
||||||
|
"responses": { "pid2": <opaque payload> },
|
||||||
|
"data": { ... } # handler-specific extras (often empty)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Engine semantics:
|
||||||
|
|
||||||
|
- While `concurrent_action.pending` is non-empty, `advance_tick()` returns
|
||||||
|
`False`. No phase transitions happen, no harvest progresses, and no
|
||||||
|
per-player turn actions are accepted. `is_blocked_on_concurrent_action()`
|
||||||
|
exposes the same predicate.
|
||||||
|
- Players submit via `Game.submit_concurrent_action(player_id, response, kind=...)`.
|
||||||
|
The handler's `apply()` validates and applies that player's response
|
||||||
|
immediately (so per-player effects don't have to wait for the others).
|
||||||
|
- When the last pending player submits, the handler's `finalize()` runs
|
||||||
|
(for any cross-player resolution), `concurrent_action` is cleared, and
|
||||||
|
if the engine was sitting in setup it advances forward.
|
||||||
|
|
||||||
|
### Adding a new concurrent action kind
|
||||||
|
|
||||||
|
1. Implement a handler class with:
|
||||||
|
- `apply(self, game, player_id, response)` — validate + apply per-player
|
||||||
|
side effects. Raise `ValueError` to reject a submission (the player
|
||||||
|
stays in `pending`).
|
||||||
|
- `finalize(self, game)` — optional; runs once after every participant
|
||||||
|
has submitted.
|
||||||
|
2. Register it in `CONCURRENT_HANDLERS` keyed by `kind`.
|
||||||
|
3. Build the prompt with `_new_concurrent_action(kind, participant_ids, data=...)`
|
||||||
|
and assign it to `game.concurrent_action` at the point in the engine
|
||||||
|
where the gate should appear.
|
||||||
|
4. On the client, register a renderer in the `CONCURRENT_RENDERERS` map in
|
||||||
|
the dev client (server.py HTML) keyed on the same `kind`.
|
||||||
|
|
||||||
|
Because the engine itself only knows "block while pending is non-empty",
|
||||||
|
the concurrent gate is fully reusable — no engine changes are required to
|
||||||
|
add new kinds (mulligan, simultaneous discard, voting, etc.).
|
||||||
|
|
||||||
88
docs/server.md
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
# Server (`server.py`)
|
||||||
|
|
||||||
|
## What it is
|
||||||
|
|
||||||
|
`server.py` is a FastAPI development server that:
|
||||||
|
|
||||||
|
- Maintains an in-memory lobby (`lobby`)
|
||||||
|
- Starts games when all lobby players are ready
|
||||||
|
- Stores active games in-memory (`games`)
|
||||||
|
- Exposes REST endpoints for lobby operations and game actions
|
||||||
|
- Serves a simple HTML test client at `/`
|
||||||
|
|
||||||
|
This server is intended for development/testing, not production.
|
||||||
|
|
||||||
|
## In-memory state
|
||||||
|
|
||||||
|
The server keeps three top-level collections:
|
||||||
|
|
||||||
|
- `lobby`: list of `LobbyMember` (players waiting to start a game)
|
||||||
|
- `games`: dict of `game_id -> Game`
|
||||||
|
- `gamers`: list of `GameMember` (player_id/name/game_id records for in-game players)
|
||||||
|
|
||||||
|
There is no persistence; restarting the server resets everything.
|
||||||
|
|
||||||
|
## Lobby flow
|
||||||
|
|
||||||
|
High-level flow:
|
||||||
|
|
||||||
|
- `POST /api/lobby/join`: creates a `LobbyMember` with a `shortuuid` `player_id`
|
||||||
|
- `POST /api/lobby/ready`: marks the player ready; when all lobby players are ready (and there are at least 2), it starts a game:
|
||||||
|
- generates a new `game_id` (uuid4)
|
||||||
|
- moves ready lobby members into `gamers` for that `game_id`
|
||||||
|
- calls `load_game_data(game_id, "base1", game_gamers)` and constructs `Game(game_state)`
|
||||||
|
- `GET /api/lobby/status`: returns lobby members + whether the requesting player is already in a game
|
||||||
|
|
||||||
|
Lobby cleanup:
|
||||||
|
|
||||||
|
- `GET /api/lobby/status` prunes lobby members inactive for > 60 seconds
|
||||||
|
|
||||||
|
## Game API
|
||||||
|
|
||||||
|
- `GET /api/game/{game_id}/state`: returns the current game state encoded using `GameObjectEncoder` (from `game.py`)
|
||||||
|
- `POST /api/game/{game_id}/action`: performs a game action and returns the updated game state
|
||||||
|
|
||||||
|
Supported `action_type` values currently include:
|
||||||
|
|
||||||
|
- `hire_citizen`
|
||||||
|
- `build_domain`
|
||||||
|
- `slay_monster`
|
||||||
|
- `take_resource`
|
||||||
|
- `harvest_card`
|
||||||
|
- `act_on_required_action` (sequential, single-player follow-ups)
|
||||||
|
- `submit_concurrent_action` (non-ordered, multi-player prompts; see below)
|
||||||
|
- `roll_phase`
|
||||||
|
- `harvest_phase`
|
||||||
|
- `play_turn`
|
||||||
|
|
||||||
|
### `submit_concurrent_action`
|
||||||
|
|
||||||
|
Used to respond to a `concurrent_action` gate (see `docs/game.md`). The
|
||||||
|
serialized game state exposes a `concurrent_action` object with `kind`,
|
||||||
|
`pending`, and `completed` lists; while `pending` is non-empty no other
|
||||||
|
turn-based action will succeed. Request body:
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"player_id": "<pid>",
|
||||||
|
"action_type": "submit_concurrent_action",
|
||||||
|
"kind": "choose_duke", // optional sanity check
|
||||||
|
"response": "<opaque string>" // handler-specific payload
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The server validates that the player is in `pending` and that `kind`
|
||||||
|
(if provided) matches the active gate. Players may submit in any order;
|
||||||
|
when the last pending player submits, the engine auto-advances out of
|
||||||
|
the setup gate.
|
||||||
|
|
||||||
|
## Game cleanup
|
||||||
|
|
||||||
|
On startup, a background task deletes games inactive for > 180 seconds and prunes the corresponding `gamers` entries.
|
||||||
|
|
||||||
|
## Dev HTML client
|
||||||
|
|
||||||
|
The root route `/` serves a simple HTML page that calls the lobby endpoints and can fetch a game state.
|
||||||
|
|
||||||
|
For run instructions, see `docs/README_SERVER.md`.
|
||||||
|
|
||||||
31
docs/testing.md
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# Testing & diagnostics
|
||||||
|
|
||||||
|
## Database connectivity
|
||||||
|
|
||||||
|
### Port-level check
|
||||||
|
|
||||||
|
`check_db_server.py` checks whether `127.0.0.1:3306` is reachable (useful to verify your SSH tunnel).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 check_db_server.py
|
||||||
|
```
|
||||||
|
|
||||||
|
### End-to-end DB validation
|
||||||
|
|
||||||
|
`test_database.py` does a more complete validation:
|
||||||
|
|
||||||
|
- imports `mariadb`
|
||||||
|
- connects to the DB
|
||||||
|
- checks required tables exist
|
||||||
|
- prints row counts and card contents (citizens/monsters/domains/dukes/starters)
|
||||||
|
- checks required stored procedures exist
|
||||||
|
- calls stored procedures and prints returned rows
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 test_database.py
|
||||||
|
```
|
||||||
|
|
||||||
|
## API server smoke test
|
||||||
|
|
||||||
|
See `docs/README_SERVER.md` to run the FastAPI server and use the built-in HTML client at `/`.
|
||||||
|
|
||||||
90
game_models.py
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
from cards import Citizen, Domain, Duke, Monster, Starter
|
||||||
|
|
||||||
|
|
||||||
|
class Player:
|
||||||
|
def __init__(self, player_id, name):
|
||||||
|
self.player_id = player_id
|
||||||
|
self.name = name
|
||||||
|
self.owned_starters = []
|
||||||
|
self.owned_citizens = []
|
||||||
|
self.owned_domains = []
|
||||||
|
self.owned_dukes = []
|
||||||
|
self.owned_monsters = []
|
||||||
|
self.gold_score = 2
|
||||||
|
self.strength_score = 0
|
||||||
|
self.magic_score = 1
|
||||||
|
self.victory_score = 0
|
||||||
|
self.is_first = False
|
||||||
|
self.shadow_count = 0
|
||||||
|
self.holy_count = 0
|
||||||
|
self.soldier_count = 0
|
||||||
|
self.worker_count = 0
|
||||||
|
self.effects = {
|
||||||
|
"roll_phase": [],
|
||||||
|
"harvest_phase": [],
|
||||||
|
"action_phase": [],
|
||||||
|
}
|
||||||
|
self.harvest_delta = {"gold": 0, "strength": 0, "magic": 0, "victory": 0}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, data):
|
||||||
|
player_id = data["player_id"]
|
||||||
|
name = data["name"]
|
||||||
|
player = cls(player_id, name)
|
||||||
|
player.owned_starters = [Starter.from_dict(s) for s in data["owned_starters"]]
|
||||||
|
player.owned_citizens = [Citizen.from_dict(c) for c in data["owned_citizens"]]
|
||||||
|
player.owned_domains = [Domain.from_dict(d) for d in data["owned_domains"]]
|
||||||
|
player.owned_dukes = [Duke.from_dict(d) for d in data["owned_dukes"]]
|
||||||
|
player.owned_monsters = [Monster.from_dict(m) for m in data["owned_monsters"]]
|
||||||
|
player.gold_score = data["gold_score"]
|
||||||
|
player.strength_score = data["strength_score"]
|
||||||
|
player.magic_score = data["magic_score"]
|
||||||
|
player.victory_score = data["victory_score"]
|
||||||
|
player.is_first = data["is_first"]
|
||||||
|
player.effects = data["effects"]
|
||||||
|
player.harvest_delta = data.get("harvest_delta", {"gold": 0, "strength": 0, "magic": 0, "victory": 0})
|
||||||
|
roles = player.calc_roles()
|
||||||
|
player.shadow_count = roles["shadow_count"]
|
||||||
|
player.holy_count = roles["holy_count"]
|
||||||
|
player.soldier_count = roles["soldier_count"]
|
||||||
|
player.worker_count = roles["worker_count"]
|
||||||
|
return player
|
||||||
|
|
||||||
|
def calc_roles(self):
|
||||||
|
shadow_count = 0
|
||||||
|
holy_count = 0
|
||||||
|
soldier_count = 0
|
||||||
|
worker_count = 0
|
||||||
|
for citizen in self.owned_citizens:
|
||||||
|
shadow_count = shadow_count + citizen.shadow_count
|
||||||
|
holy_count = holy_count + citizen.holy_count
|
||||||
|
soldier_count = soldier_count + citizen.soldier_count
|
||||||
|
worker_count = worker_count + citizen.worker_count
|
||||||
|
for domain in self.owned_domains:
|
||||||
|
shadow_count = shadow_count + domain.shadow_count
|
||||||
|
holy_count = holy_count + domain.holy_count
|
||||||
|
soldier_count = soldier_count + domain.soldier_count
|
||||||
|
worker_count = worker_count + domain.worker_count
|
||||||
|
roles_dict = {
|
||||||
|
"shadow_count": shadow_count,
|
||||||
|
"holy_count": holy_count,
|
||||||
|
"soldier_count": soldier_count,
|
||||||
|
"worker_count": worker_count,
|
||||||
|
}
|
||||||
|
return roles_dict
|
||||||
|
|
||||||
|
|
||||||
|
class LobbyMember:
|
||||||
|
def __init__(self, player_name, player_id):
|
||||||
|
self.name = player_name
|
||||||
|
self.player_id = player_id
|
||||||
|
self.is_ready = False
|
||||||
|
self.debug_starting_resources = False
|
||||||
|
self.last_active_time = 0
|
||||||
|
|
||||||
|
|
||||||
|
class GameMember:
|
||||||
|
def __init__(self, player_id, player_name, game_id):
|
||||||
|
self.name = player_name
|
||||||
|
self.player_id = player_id
|
||||||
|
self.game_id = game_id
|
||||||
116
game_serialization.py
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
from json import JSONEncoder
|
||||||
|
|
||||||
|
from cards import Citizen, Domain, Duke, Exhausted, Monster, Starter
|
||||||
|
from game_models import GameMember, LobbyMember, Player
|
||||||
|
|
||||||
|
|
||||||
|
class SummaryEncoder(JSONEncoder):
|
||||||
|
def default(self, obj):
|
||||||
|
if isinstance(obj, Player):
|
||||||
|
return {
|
||||||
|
"player_id": obj.player_id,
|
||||||
|
"name": obj.name,
|
||||||
|
"owned_citizens": len(obj.owned_citizens),
|
||||||
|
"owned_domains": len(obj.owned_domains),
|
||||||
|
"owned_monsters": len(obj.owned_monsters),
|
||||||
|
"gold_score": obj.gold_score,
|
||||||
|
"strength_score": obj.strength_score,
|
||||||
|
"magic_score": obj.magic_score,
|
||||||
|
"victory_score": obj.victory_score,
|
||||||
|
"is_first": obj.is_first,
|
||||||
|
}
|
||||||
|
if isinstance(obj, LobbyMember):
|
||||||
|
return {
|
||||||
|
"player_name": obj.name,
|
||||||
|
"player_id": obj.player_id,
|
||||||
|
"is_ready": obj.is_ready,
|
||||||
|
}
|
||||||
|
if isinstance(obj, GameMember):
|
||||||
|
return {
|
||||||
|
"player_name": obj.name,
|
||||||
|
"player_id": obj.player_id,
|
||||||
|
}
|
||||||
|
if hasattr(obj, "game_id") and hasattr(obj, "player_list"):
|
||||||
|
return {
|
||||||
|
"game_id": obj.game_id,
|
||||||
|
"player_list": obj.player_list,
|
||||||
|
}
|
||||||
|
return super().default(obj)
|
||||||
|
|
||||||
|
|
||||||
|
class GameObjectEncoder(JSONEncoder):
|
||||||
|
def default(self, obj):
|
||||||
|
if isinstance(obj, Player):
|
||||||
|
roles = obj.calc_roles()
|
||||||
|
return {
|
||||||
|
"player_id": obj.player_id,
|
||||||
|
"name": obj.name,
|
||||||
|
"owned_starters": [starter.to_dict() for starter in obj.owned_starters],
|
||||||
|
"owned_citizens": [citizen.to_dict() for citizen in obj.owned_citizens],
|
||||||
|
"owned_domains": [domain.to_dict() for domain in obj.owned_domains],
|
||||||
|
"owned_dukes": [duke.to_dict() for duke in obj.owned_dukes],
|
||||||
|
"owned_monsters": [monster.to_dict() for monster in obj.owned_monsters],
|
||||||
|
"gold_score": obj.gold_score,
|
||||||
|
"strength_score": obj.strength_score,
|
||||||
|
"magic_score": obj.magic_score,
|
||||||
|
"victory_score": obj.victory_score,
|
||||||
|
"is_first": obj.is_first,
|
||||||
|
"shadow_count": roles["shadow_count"],
|
||||||
|
"holy_count": roles["holy_count"],
|
||||||
|
"soldier_count": roles["soldier_count"],
|
||||||
|
"worker_count": roles["worker_count"],
|
||||||
|
"effects": obj.effects,
|
||||||
|
"harvest_delta": getattr(obj, "harvest_delta", {"gold": 0, "strength": 0, "magic": 0, "victory": 0}),
|
||||||
|
}
|
||||||
|
if isinstance(obj, Duke):
|
||||||
|
return obj.to_dict()
|
||||||
|
if isinstance(obj, Monster):
|
||||||
|
return obj.to_dict()
|
||||||
|
if isinstance(obj, Starter):
|
||||||
|
return obj.to_dict()
|
||||||
|
if isinstance(obj, Citizen):
|
||||||
|
return obj.to_dict()
|
||||||
|
if isinstance(obj, Domain):
|
||||||
|
return obj.to_dict()
|
||||||
|
if isinstance(obj, Exhausted):
|
||||||
|
return obj.to_dict()
|
||||||
|
if hasattr(obj, "game_id") and hasattr(obj, "player_list") and hasattr(obj, "monster_grid"):
|
||||||
|
ca_raw = getattr(obj, "concurrent_action", None)
|
||||||
|
ca_enc = ca_raw
|
||||||
|
if isinstance(ca_raw, dict) and not (ca_raw.get("pending") or []):
|
||||||
|
ca_enc = None
|
||||||
|
return {
|
||||||
|
"game_id": obj.game_id,
|
||||||
|
"player_list": obj.player_list,
|
||||||
|
"monster_grid": obj.monster_grid,
|
||||||
|
"citizen_grid": obj.citizen_grid,
|
||||||
|
"domain_grid": obj.domain_grid,
|
||||||
|
"die_one": obj.die_one,
|
||||||
|
"die_two": obj.die_two,
|
||||||
|
"die_sum": obj.die_sum,
|
||||||
|
"rolled_die_one": getattr(obj, "rolled_die_one", obj.die_one),
|
||||||
|
"rolled_die_two": getattr(obj, "rolled_die_two", obj.die_two),
|
||||||
|
"rolled_die_sum": getattr(obj, "rolled_die_sum", obj.die_sum),
|
||||||
|
"pending_roll": getattr(obj, "pending_roll", None),
|
||||||
|
"exhausted_count": obj.exhausted_count,
|
||||||
|
"exhausted_stack_size": len(getattr(obj, "exhausted_stack", None) or []),
|
||||||
|
"end_game_triggered": getattr(obj, "end_game_triggered", False),
|
||||||
|
"final_scores": getattr(obj, "final_scores", None),
|
||||||
|
"effects": obj.effects,
|
||||||
|
"action_required": obj.action_required,
|
||||||
|
"pending_required_choice": getattr(obj, "pending_required_choice", None),
|
||||||
|
"pending_action_end_queue": getattr(obj, "pending_action_end_queue", None) or [],
|
||||||
|
"concurrent_action": ca_enc,
|
||||||
|
"tick_id": getattr(obj, "tick_id", 0),
|
||||||
|
"turn_number": getattr(obj, "turn_number", 1),
|
||||||
|
"turn_index": getattr(obj, "turn_index", 0),
|
||||||
|
"phase": getattr(obj, "phase", "roll"),
|
||||||
|
"actions_remaining": getattr(obj, "actions_remaining", 0),
|
||||||
|
"active_player_id": obj.current_player_id() if hasattr(obj, "current_player_id") else None,
|
||||||
|
"harvest_player_order": getattr(obj, "harvest_player_order", None),
|
||||||
|
"harvest_player_idx": getattr(obj, "harvest_player_idx", 0),
|
||||||
|
"harvest_consumed": getattr(obj, "harvest_consumed", {}) or {},
|
||||||
|
"harvest_prompt_slots": obj.harvest_slots_for_api() if hasattr(obj, "harvest_slots_for_api") else [],
|
||||||
|
"game_log": list(getattr(obj, "game_log", None) or []),
|
||||||
|
}
|
||||||
|
return super().default(obj)
|
||||||
288
game_setup.py
Normal file
@@ -0,0 +1,288 @@
|
|||||||
|
import random
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from cards import Citizen, Domain, Duke, Exhausted, Monster, Starter
|
||||||
|
from game_models import Player
|
||||||
|
|
||||||
|
|
||||||
|
def load_game_data(game_id, preset, player_list_from_lobby, debug_starting_resources=False):
|
||||||
|
import mariadb
|
||||||
|
|
||||||
|
monster_query = ""
|
||||||
|
monster_stack = []
|
||||||
|
citizen_query = ""
|
||||||
|
citizen_stack = []
|
||||||
|
domain_query = "select_random_domains"
|
||||||
|
domain_stack = []
|
||||||
|
duke_query = "select_random_dukes"
|
||||||
|
duke_stack = []
|
||||||
|
exhausted_stack = [Exhausted(i) for i in range(len(player_list_from_lobby) * 2)]
|
||||||
|
starter_query = "SELECT * FROM starters"
|
||||||
|
starter_stack = []
|
||||||
|
player_list = []
|
||||||
|
citizen_grid: List[List[Citizen]] = [[] for _ in range(10)]
|
||||||
|
domain_grid: List[List[Domain]] = [[] for _ in range(5)]
|
||||||
|
monster_grid: List[List[Monster]] = [[] for _ in range(5)]
|
||||||
|
die_one = 0
|
||||||
|
die_two = 0
|
||||||
|
die_sum = 0
|
||||||
|
exhausted_count = 0
|
||||||
|
effects = {
|
||||||
|
"roll_phase": [],
|
||||||
|
"harvest_phase": [],
|
||||||
|
"action_phase": [],
|
||||||
|
}
|
||||||
|
action_required = {
|
||||||
|
"id": "",
|
||||||
|
"action": "",
|
||||||
|
}
|
||||||
|
tick_id = 0
|
||||||
|
turn_number = 1
|
||||||
|
turn_index = 0
|
||||||
|
# Start in setup; if no setup actions are needed the engine will advance into roll.
|
||||||
|
phase = "setup"
|
||||||
|
actions_remaining = 0
|
||||||
|
harvest_processed = False
|
||||||
|
pending_harvest_choices = []
|
||||||
|
match preset:
|
||||||
|
case "base1":
|
||||||
|
monster_query = "select_base1_monsters"
|
||||||
|
citizen_query = "select_base1_citizens"
|
||||||
|
case "base2":
|
||||||
|
monster_query = "select_base2_monsters"
|
||||||
|
citizen_query = "select_base2_citizens"
|
||||||
|
try:
|
||||||
|
my_connect = mariadb.connect(
|
||||||
|
user="vckonline", password="vckonline", host="127.0.0.1", database="vckonline", port=3306
|
||||||
|
)
|
||||||
|
my_cursor = my_connect.cursor(dictionary=True)
|
||||||
|
|
||||||
|
my_cursor.callproc(monster_query)
|
||||||
|
|
||||||
|
results = my_cursor.fetchall()
|
||||||
|
for row in results:
|
||||||
|
my_monster = Monster(
|
||||||
|
row["id_monsters"],
|
||||||
|
row["name"],
|
||||||
|
row["area"],
|
||||||
|
row["monster_type"],
|
||||||
|
row["monster_order"],
|
||||||
|
row["strength_cost"],
|
||||||
|
row["magic_cost"],
|
||||||
|
row["vp_reward"],
|
||||||
|
row["gold_reward"],
|
||||||
|
row["strength_reward"],
|
||||||
|
row["magic_reward"],
|
||||||
|
row["has_special_reward"],
|
||||||
|
row["special_reward"],
|
||||||
|
row["has_special_cost"],
|
||||||
|
row["special_cost"],
|
||||||
|
row["is_extra"],
|
||||||
|
row["expansion"],
|
||||||
|
)
|
||||||
|
monster_stack.append(my_monster)
|
||||||
|
|
||||||
|
my_cursor.callproc(citizen_query)
|
||||||
|
citizen_count = 5
|
||||||
|
if len(player_list_from_lobby) == 5:
|
||||||
|
citizen_count = 6
|
||||||
|
results = my_cursor.fetchall()
|
||||||
|
for row in results:
|
||||||
|
for _ in range(citizen_count):
|
||||||
|
my_citizen = Citizen(
|
||||||
|
row["id_citizens"],
|
||||||
|
row["name"],
|
||||||
|
row["gold_cost"],
|
||||||
|
row["roll_match1"],
|
||||||
|
row["roll_match2"],
|
||||||
|
row["shadow_count"],
|
||||||
|
row["holy_count"],
|
||||||
|
row["soldier_count"],
|
||||||
|
row["worker_count"],
|
||||||
|
row["gold_payout_on_turn"],
|
||||||
|
row["gold_payout_off_turn"],
|
||||||
|
row["strength_payout_on_turn"],
|
||||||
|
row["strength_payout_off_turn"],
|
||||||
|
row["magic_payout_on_turn"],
|
||||||
|
row["magic_payout_off_turn"],
|
||||||
|
row["has_special_payout_on_turn"],
|
||||||
|
row["has_special_payout_off_turn"],
|
||||||
|
row["special_payout_on_turn"],
|
||||||
|
row["special_payout_off_turn"],
|
||||||
|
row["special_citizen"],
|
||||||
|
row["expansion"],
|
||||||
|
)
|
||||||
|
citizen_stack.append(my_citizen)
|
||||||
|
|
||||||
|
my_cursor.callproc(domain_query)
|
||||||
|
results = my_cursor.fetchall()
|
||||||
|
for row in results:
|
||||||
|
my_domain = Domain(
|
||||||
|
row["id_domains"],
|
||||||
|
row["name"],
|
||||||
|
row["gold_cost"],
|
||||||
|
row["shadow_count"],
|
||||||
|
row["holy_count"],
|
||||||
|
row["soldier_count"],
|
||||||
|
row["worker_count"],
|
||||||
|
row["vp_reward"],
|
||||||
|
row["has_activation_effect"],
|
||||||
|
row["has_passive_effect"],
|
||||||
|
row["passive_effect"],
|
||||||
|
row["activation_effect"],
|
||||||
|
row["text"],
|
||||||
|
row["expansion"],
|
||||||
|
)
|
||||||
|
domain_stack.append(my_domain)
|
||||||
|
|
||||||
|
my_cursor.callproc(duke_query)
|
||||||
|
results = my_cursor.fetchall()
|
||||||
|
for row in results:
|
||||||
|
my_duke = Duke(
|
||||||
|
row["id_dukes"],
|
||||||
|
row["name"],
|
||||||
|
row["gold_mult"],
|
||||||
|
row["strength_mult"],
|
||||||
|
row["magic_mult"],
|
||||||
|
row["shadow_mult"],
|
||||||
|
row["holy_mult"],
|
||||||
|
row["soldier_mult"],
|
||||||
|
row["worker_mult"],
|
||||||
|
row["monster_mult"],
|
||||||
|
row["citizen_mult"],
|
||||||
|
row["domain_mult"],
|
||||||
|
row["boss_mult"],
|
||||||
|
row["minion_mult"],
|
||||||
|
row["beast_mult"],
|
||||||
|
row["titan_mult"],
|
||||||
|
row["expansion"],
|
||||||
|
)
|
||||||
|
duke_stack.append(my_duke)
|
||||||
|
|
||||||
|
my_cursor.execute(starter_query)
|
||||||
|
my_result = my_cursor.fetchall()
|
||||||
|
for row in my_result:
|
||||||
|
my_starter = Starter(
|
||||||
|
row["id_starters"],
|
||||||
|
row["name"],
|
||||||
|
row["roll_match1"],
|
||||||
|
row["roll_match2"],
|
||||||
|
row["gold_payout_on_turn"],
|
||||||
|
row["gold_payout_off_turn"],
|
||||||
|
row["strength_payout_on_turn"],
|
||||||
|
row["strength_payout_off_turn"],
|
||||||
|
row["magic_payout_on_turn"],
|
||||||
|
row["magic_payout_off_turn"],
|
||||||
|
row["has_special_payout_on_turn"],
|
||||||
|
row["has_special_payout_off_turn"],
|
||||||
|
row["special_payout_on_turn"],
|
||||||
|
row["special_payout_off_turn"],
|
||||||
|
row["expansion"],
|
||||||
|
)
|
||||||
|
starter_stack.append(my_starter)
|
||||||
|
my_cursor.close()
|
||||||
|
my_connect.close()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error: {e}")
|
||||||
|
# create players and determine order
|
||||||
|
if not all([player_list_from_lobby, starter_query, monster_stack, citizen_stack, domain_stack, duke_stack]):
|
||||||
|
raise ValueError("One or more required lists are empty.")
|
||||||
|
else:
|
||||||
|
for player in player_list_from_lobby:
|
||||||
|
my_player = Player(player.player_id, player.name)
|
||||||
|
if debug_starting_resources:
|
||||||
|
my_player.gold_score = 100
|
||||||
|
my_player.strength_score = 100
|
||||||
|
my_player.magic_score = 100
|
||||||
|
player_list.append(my_player)
|
||||||
|
random.shuffle(player_list)
|
||||||
|
player_list[0].is_first = True
|
||||||
|
# give players starters and dukes
|
||||||
|
for player in player_list:
|
||||||
|
player.owned_starters.append(starter_stack[0])
|
||||||
|
player.owned_starters.append(starter_stack[1])
|
||||||
|
for _ in range(2):
|
||||||
|
player.owned_dukes.append(duke_stack.pop())
|
||||||
|
# deal monsters onto the board
|
||||||
|
grouped_monsters = {}
|
||||||
|
for monster in monster_stack:
|
||||||
|
area = monster.area
|
||||||
|
if area in grouped_monsters:
|
||||||
|
grouped_monsters[area].append(monster)
|
||||||
|
else:
|
||||||
|
grouped_monsters[area] = [monster]
|
||||||
|
for area, monsters in grouped_monsters.items():
|
||||||
|
monsters.sort(key=lambda item: item.order, reverse=True)
|
||||||
|
areas = list(grouped_monsters.keys())
|
||||||
|
chosen_areas = random.sample(areas, 5)
|
||||||
|
for i, area in enumerate(chosen_areas):
|
||||||
|
monsters = grouped_monsters[area]
|
||||||
|
monster_grid[i].extend(monsters)
|
||||||
|
for stack in monster_grid:
|
||||||
|
for monster in stack:
|
||||||
|
monster.toggle_visibility(True)
|
||||||
|
stack[-1].toggle_accessibility(True)
|
||||||
|
# deal citizens onto the board
|
||||||
|
citizens_by_roll = {roll: [] for roll in [1, 2, 3, 4, 5, 6, 7, 8, 9, 11]}
|
||||||
|
for citizen in citizen_stack:
|
||||||
|
citizen.toggle_visibility()
|
||||||
|
citizens_by_roll[citizen.roll_match1].append(citizen)
|
||||||
|
for roll in citizens_by_roll:
|
||||||
|
index = roll - 1 if roll < 11 else 9
|
||||||
|
citizens = citizens_by_roll[roll]
|
||||||
|
citizen_grid[index].extend(list(citizens))
|
||||||
|
citizen_grid[index][-1].toggle_accessibility(True)
|
||||||
|
if debug_starting_resources:
|
||||||
|
for player in player_list:
|
||||||
|
for stack in citizen_grid:
|
||||||
|
c = stack.pop(-1)
|
||||||
|
c.is_flipped = False
|
||||||
|
c.toggle_visibility(True)
|
||||||
|
c.toggle_accessibility(True)
|
||||||
|
player.owned_citizens.append(c)
|
||||||
|
if stack:
|
||||||
|
stack[-1].toggle_accessibility(True)
|
||||||
|
# deal the domains into stacks
|
||||||
|
for i in range(5):
|
||||||
|
stack = domain_grid[i]
|
||||||
|
for j in range(3):
|
||||||
|
if j == 2:
|
||||||
|
domain = domain_stack.pop()
|
||||||
|
domain.toggle_visibility(True)
|
||||||
|
domain.toggle_accessibility(True)
|
||||||
|
stack.append(domain)
|
||||||
|
else:
|
||||||
|
domain = domain_stack.pop()
|
||||||
|
stack.append(domain)
|
||||||
|
|
||||||
|
game_state = {
|
||||||
|
"game_id": game_id,
|
||||||
|
"pending_required_choice": None,
|
||||||
|
"player_list": player_list,
|
||||||
|
"monster_grid": monster_grid,
|
||||||
|
"citizen_grid": citizen_grid,
|
||||||
|
"domain_grid": domain_grid,
|
||||||
|
"die_one": die_one,
|
||||||
|
"die_two": die_two,
|
||||||
|
"die_sum": die_sum,
|
||||||
|
"exhausted_count": exhausted_count,
|
||||||
|
"exhausted_stack": exhausted_stack,
|
||||||
|
"end_game_triggered": False,
|
||||||
|
"final_scores": None,
|
||||||
|
"effects": effects,
|
||||||
|
"action_required": action_required,
|
||||||
|
"concurrent_action": None,
|
||||||
|
"tick_id": tick_id,
|
||||||
|
"turn_number": turn_number,
|
||||||
|
"turn_index": turn_index,
|
||||||
|
"phase": phase,
|
||||||
|
"actions_remaining": actions_remaining,
|
||||||
|
"harvest_processed": harvest_processed,
|
||||||
|
"pending_harvest_choices": pending_harvest_choices,
|
||||||
|
"harvest_player_order": None,
|
||||||
|
"harvest_player_idx": 0,
|
||||||
|
"harvest_consumed": {},
|
||||||
|
"game_log": [],
|
||||||
|
"pending_action_end_queue": [],
|
||||||
|
}
|
||||||
|
return game_state
|
||||||
BIN
images/.DS_Store
vendored
Normal file
BIN
images/citizens/citizen_01_cleric.jpg
Normal file
|
After Width: | Height: | Size: 51 KiB |
BIN
images/citizens/citizen_02_merchant.jpg
Normal file
|
After Width: | Height: | Size: 62 KiB |
BIN
images/citizens/citizen_03_mercenary.jpg
Normal file
|
After Width: | Height: | Size: 56 KiB |
BIN
images/citizens/citizen_04_archer.jpg
Normal file
|
After Width: | Height: | Size: 53 KiB |
BIN
images/citizens/citizen_05_peasant.jpg
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
images/citizens/citizen_06_knight.jpg
Normal file
|
After Width: | Height: | Size: 60 KiB |
BIN
images/citizens/citizen_07_rogue.jpg
Normal file
|
After Width: | Height: | Size: 52 KiB |
BIN
images/citizens/citizen_08_champion.jpg
Normal file
|
After Width: | Height: | Size: 63 KiB |
BIN
images/citizens/citizen_09_paladin.jpg
Normal file
|
After Width: | Height: | Size: 63 KiB |
BIN
images/citizens/citizen_10_butcher.jpg
Normal file
|
After Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 546 KiB After Width: | Height: | Size: 546 KiB |
BIN
images/domains/domain_01_jousting_field.jpg
Normal file
|
After Width: | Height: | Size: 86 KiB |
BIN
images/domains/domain_02_ancient_tomb.jpg
Normal file
|
After Width: | Height: | Size: 62 KiB |
BIN
images/domains/domain_03_foxgrove_palisade.jpg
Normal file
|
After Width: | Height: | Size: 92 KiB |
BIN
images/domains/domain_04_the_desert_orchid.jpg
Normal file
|
After Width: | Height: | Size: 91 KiB |
BIN
images/domains/domain_05_pretorius_conclave.jpg
Normal file
|
After Width: | Height: | Size: 96 KiB |
BIN
images/domains/domain_06_emerald_stronghold.jpg
Normal file
|
After Width: | Height: | Size: 91 KiB |
BIN
images/domains/domain_07_pratchetts_plateau.jpg
Normal file
|
After Width: | Height: | Size: 89 KiB |
BIN
images/domains/domain_08_shelley_commons.jpg
Normal file
|
After Width: | Height: | Size: 79 KiB |
BIN
images/domains/domain_09_cathedral_of_st_aquila.jpg
Normal file
|
After Width: | Height: | Size: 88 KiB |
BIN
images/domains/domain_10_cursed_cavern.jpg
Normal file
|
After Width: | Height: | Size: 83 KiB |
BIN
images/domains/domain_11_darktide_harbor.jpg
Normal file
|
After Width: | Height: | Size: 84 KiB |
BIN
images/domains/domain_12_king_tower.jpg
Normal file
|
After Width: | Height: | Size: 64 KiB |
BIN
images/domains/domain_13_cloudriders_camp.jpg
Normal file
|
After Width: | Height: | Size: 90 KiB |
BIN
images/domains/domain_14_the_orb_of_urdr.jpg
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
images/domains/domain_15_wisborg.jpg
Normal file
|
After Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 509 KiB After Width: | Height: | Size: 509 KiB |
BIN
images/domains/domain_r01c01.jpg
Normal file
|
After Width: | Height: | Size: 72 KiB |
BIN
images/domains/domain_r01c03.jpg
Normal file
|
After Width: | Height: | Size: 72 KiB |
BIN
images/domains/domain_r01c04.jpg
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
images/domains/domain_r01c05.jpg
Normal file
|
After Width: | Height: | Size: 78 KiB |
BIN
images/domains/domain_r01c07.jpg
Normal file
|
After Width: | Height: | Size: 76 KiB |
BIN
images/domains/domain_r01c09.jpg
Normal file
|
After Width: | Height: | Size: 85 KiB |
BIN
images/domains/domain_r01c10.jpg
Normal file
|
After Width: | Height: | Size: 78 KiB |
BIN
images/domains/domain_r02c01.jpg
Normal file
|
After Width: | Height: | Size: 104 KiB |
BIN
images/domains/domain_r02c02.jpg
Normal file
|
After Width: | Height: | Size: 83 KiB |
BIN
images/domains/domain_r02c03.jpg
Normal file
|
After Width: | Height: | Size: 73 KiB |
BIN
images/domains/domain_r02c05.jpg
Normal file
|
After Width: | Height: | Size: 88 KiB |
BIN
images/domains/domain_r02c06.jpg
Normal file
|
After Width: | Height: | Size: 92 KiB |
BIN
images/domains/domain_r03c01.jpg
Normal file
|
After Width: | Height: | Size: 69 KiB |
BIN
images/domains/domain_r03c02.jpg
Normal file
|
After Width: | Height: | Size: 91 KiB |
BIN
images/domains/domain_r03c03.jpg
Normal file
|
After Width: | Height: | Size: 83 KiB |
BIN
images/domains/domain_r03c04.jpg
Normal file
|
After Width: | Height: | Size: 84 KiB |
BIN
images/domains/domain_r03c05.jpg
Normal file
|
After Width: | Height: | Size: 96 KiB |
BIN
images/domains/domain_r03c06.jpg
Normal file
|
After Width: | Height: | Size: 91 KiB |
BIN
images/domains/domain_r03c07.jpg
Normal file
|
After Width: | Height: | Size: 87 KiB |
BIN
images/domains/domain_r03c09.jpg
Normal file
|
After Width: | Height: | Size: 95 KiB |
BIN
images/domains/domain_r03c10.jpg
Normal file
|
After Width: | Height: | Size: 97 KiB |
BIN
images/domains/domain_r04c01.jpg
Normal file
|
After Width: | Height: | Size: 95 KiB |
BIN
images/domains/domain_r04c02.jpg
Normal file
|
After Width: | Height: | Size: 73 KiB |
BIN
images/domains/domain_r04c03.jpg
Normal file
|
After Width: | Height: | Size: 87 KiB |
BIN
images/domains/domain_r04c04.jpg
Normal file
|
After Width: | Height: | Size: 86 KiB |
BIN
images/domains/domain_r04c05.jpg
Normal file
|
After Width: | Height: | Size: 90 KiB |
BIN
images/domains/domain_r04c06.jpg
Normal file
|
After Width: | Height: | Size: 87 KiB |
BIN
images/domains/domain_r04c07.jpg
Normal file
|
After Width: | Height: | Size: 81 KiB |
BIN
images/domains/domain_r04c08.jpg
Normal file
|
After Width: | Height: | Size: 107 KiB |
BIN
images/domains/domain_r04c09.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
images/domains/domain_r04c10.jpg
Normal file
|
After Width: | Height: | Size: 89 KiB |
BIN
images/domains/domain_r05c01.jpg
Normal file
|
After Width: | Height: | Size: 81 KiB |
BIN
images/domains/domain_r05c02.jpg
Normal file
|
After Width: | Height: | Size: 85 KiB |
BIN
images/domains/domain_r05c03.jpg
Normal file
|
After Width: | Height: | Size: 72 KiB |
BIN
images/domains/domain_r05c04.jpg
Normal file
|
After Width: | Height: | Size: 83 KiB |
BIN
images/domains/domain_r05c05.jpg
Normal file
|
After Width: | Height: | Size: 87 KiB |
BIN
images/domains/domain_r05c06.jpg
Normal file
|
After Width: | Height: | Size: 85 KiB |
BIN
images/domains/domain_r05c07.jpg
Normal file
|
After Width: | Height: | Size: 76 KiB |
BIN
images/domains/domain_r05c08.jpg
Normal file
|
After Width: | Height: | Size: 84 KiB |
BIN
images/domains/domain_r05c10.jpg
Normal file
|
After Width: | Height: | Size: 77 KiB |
BIN
images/domains/domain_r06c01.jpg
Normal file
|
After Width: | Height: | Size: 84 KiB |
BIN
images/domains/domain_r06c02.jpg
Normal file
|
After Width: | Height: | Size: 80 KiB |
BIN
images/domains/domain_r06c03.jpg
Normal file
|
After Width: | Height: | Size: 85 KiB |
BIN
images/domains/domain_r06c05.jpg
Normal file
|
After Width: | Height: | Size: 75 KiB |
BIN
images/domains/domain_r06c06.jpg
Normal file
|
After Width: | Height: | Size: 76 KiB |
BIN
images/domains/domain_r06c07.jpg
Normal file
|
After Width: | Height: | Size: 83 KiB |
BIN
images/domains/domain_r06c09.jpg
Normal file
|
After Width: | Height: | Size: 92 KiB |
BIN
images/domains/domain_r06c10.jpg
Normal file
|
After Width: | Height: | Size: 91 KiB |
BIN
images/domains/domain_r07c01.jpg
Normal file
|
After Width: | Height: | Size: 93 KiB |