2026-01-28 16:25:40 +01:00
|
|
|
from __future__ import annotations
|
2026-02-02 14:33:31 +01:00
|
|
|
from uuid import uuid4
|
2026-01-19 18:55:07 +01:00
|
|
|
from datetime import datetime
|
2026-02-04 16:10:53 +01:00
|
|
|
from typing import Any, Dict, List
|
2026-01-19 18:55:07 +01:00
|
|
|
|
2026-02-17 16:37:36 +01:00
|
|
|
from warchron.model.war_event import WarEvent, InfluenceGained, InfluenceSpent
|
2026-02-13 11:38:59 +01:00
|
|
|
from warchron.model.exception import ForbiddenOperation
|
2026-02-05 08:42:38 +01:00
|
|
|
from warchron.model.war_participant import WarParticipant
|
|
|
|
|
from warchron.model.objective import Objective
|
|
|
|
|
from warchron.model.campaign_participant import CampaignParticipant
|
|
|
|
|
from warchron.model.sector import Sector
|
|
|
|
|
from warchron.model.campaign import Campaign
|
|
|
|
|
from warchron.model.round import Round
|
|
|
|
|
from warchron.model.choice import Choice
|
|
|
|
|
from warchron.model.battle import Battle
|
2026-01-19 18:55:07 +01:00
|
|
|
|
2026-01-28 16:25:40 +01:00
|
|
|
|
2026-01-19 18:55:07 +01:00
|
|
|
class War:
|
2026-02-04 16:10:53 +01:00
|
|
|
def __init__(self, name: str, year: int) -> None:
|
2026-01-28 16:25:40 +01:00
|
|
|
self.id: str = str(uuid4())
|
|
|
|
|
self.name: str = name
|
|
|
|
|
self.year: int = year
|
2026-02-10 16:26:49 +01:00
|
|
|
self.major_value: int = 2
|
|
|
|
|
self.minor_value: int = 1
|
|
|
|
|
self.influence_token: bool = True
|
2026-02-04 16:10:53 +01:00
|
|
|
self.participants: Dict[str, WarParticipant] = {}
|
|
|
|
|
self.objectives: Dict[str, Objective] = {}
|
|
|
|
|
self.campaigns: List[Campaign] = []
|
2026-02-17 16:37:36 +01:00
|
|
|
self.events: List[WarEvent] = []
|
2026-01-28 16:25:40 +01:00
|
|
|
self.is_over: bool = False
|
2026-01-19 18:55:07 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def set_id(self, new_id: str) -> None:
|
2026-01-19 18:55:07 +01:00
|
|
|
self.id = new_id
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def set_name(self, new_name: str) -> None:
|
2026-01-19 18:55:07 +01:00
|
|
|
self.name = new_name
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def set_year(self, new_year: int) -> None:
|
2026-01-19 18:55:07 +01:00
|
|
|
self.year = new_year
|
2026-02-02 14:33:31 +01:00
|
|
|
|
2026-02-13 16:12:43 +01:00
|
|
|
def set_major_value(self, new_value: int) -> None:
|
|
|
|
|
if self.is_over:
|
|
|
|
|
raise ForbiddenOperation("Can't set major value of a closed war.")
|
2026-02-10 16:26:49 +01:00
|
|
|
if new_value < self.minor_value:
|
2026-02-13 16:12:43 +01:00
|
|
|
raise ValueError("Can' set major value < minor value")
|
2026-02-10 16:26:49 +01:00
|
|
|
self.major_value = new_value
|
|
|
|
|
|
2026-02-13 16:12:43 +01:00
|
|
|
def set_minor_value(self, new_value: int) -> None:
|
|
|
|
|
if self.is_over:
|
|
|
|
|
raise ForbiddenOperation("Can't set minor value of a closed war.")
|
2026-02-10 16:26:49 +01:00
|
|
|
if new_value > self.major_value:
|
2026-02-13 16:12:43 +01:00
|
|
|
raise ValueError("Can't set minor value > major value")
|
2026-02-10 16:26:49 +01:00
|
|
|
self.minor_value = new_value
|
|
|
|
|
|
2026-02-13 16:12:43 +01:00
|
|
|
def set_influence_token(self, new_state: bool) -> None:
|
|
|
|
|
if self.is_over:
|
|
|
|
|
raise ForbiddenOperation("Can't set influence token of a closed war.")
|
2026-02-17 16:37:36 +01:00
|
|
|
# TODO raise RequiresConfirmation
|
|
|
|
|
# * disable: cleanup if any token has already been gained/spent
|
|
|
|
|
# * enable: retrigger battle_outcomes and resolve tie again if any draw
|
2026-02-10 16:26:49 +01:00
|
|
|
self.influence_token = new_state
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def set_state(self, new_state: bool) -> None:
|
2026-01-19 18:55:07 +01:00
|
|
|
self.is_over = new_state
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def toDict(self) -> Dict[str, Any]:
|
2026-01-19 18:55:07 +01:00
|
|
|
return {
|
2026-02-02 14:33:31 +01:00
|
|
|
"id": self.id,
|
|
|
|
|
"name": self.name,
|
|
|
|
|
"year": self.year,
|
2026-02-10 16:26:49 +01:00
|
|
|
"major_value": self.major_value,
|
|
|
|
|
"minor_value": self.minor_value,
|
|
|
|
|
"influence_token": self.influence_token,
|
2026-02-06 09:59:54 +01:00
|
|
|
"participants": [part.toDict() for part in self.participants.values()],
|
|
|
|
|
"objectives": [obj.toDict() for obj in self.objectives.values()],
|
2026-01-21 08:31:48 +01:00
|
|
|
"campaigns": [camp.toDict() for camp in self.campaigns],
|
2026-02-17 16:37:36 +01:00
|
|
|
"events": [ev.toDict() for ev in self.events],
|
2026-02-02 14:33:31 +01:00
|
|
|
"is_over": self.is_over,
|
2026-01-19 18:55:07 +01:00
|
|
|
}
|
2026-02-02 14:33:31 +01:00
|
|
|
|
2026-01-19 18:55:07 +01:00
|
|
|
@staticmethod
|
2026-02-04 16:10:53 +01:00
|
|
|
def fromDict(data: Dict[str, Any]) -> War:
|
2026-01-22 23:42:47 +01:00
|
|
|
war = War(name=data["name"], year=data["year"])
|
2026-01-21 08:31:48 +01:00
|
|
|
war.set_id(data["id"])
|
2026-02-13 16:12:43 +01:00
|
|
|
war.set_major_value(data["major_value"])
|
|
|
|
|
war.set_minor_value(data["minor_value"])
|
|
|
|
|
war.set_influence_token(data["influence_token"])
|
2026-02-06 09:59:54 +01:00
|
|
|
for part_data in data.get("participants", []):
|
|
|
|
|
part = WarParticipant.fromDict(part_data)
|
|
|
|
|
war.participants[part.id] = part
|
|
|
|
|
for obj_data in data.get("objectives", []):
|
|
|
|
|
obj = Objective.fromDict(obj_data)
|
|
|
|
|
war.objectives[obj.id] = obj
|
2026-01-21 08:31:48 +01:00
|
|
|
for camp_data in data.get("campaigns", []):
|
|
|
|
|
war.campaigns.append(Campaign.fromDict(camp_data))
|
2026-02-17 16:37:36 +01:00
|
|
|
for ev_data in data.get("events", []):
|
|
|
|
|
war.events.append(WarEvent.fromDict(ev_data))
|
2026-01-21 08:31:48 +01:00
|
|
|
war.set_state(data.get("is_over", False))
|
|
|
|
|
return war
|
|
|
|
|
|
2026-02-02 14:33:31 +01:00
|
|
|
# Objective methods
|
2026-01-28 16:25:40 +01:00
|
|
|
|
2026-02-11 19:22:43 +01:00
|
|
|
def add_objective(self, name: str, description: str | None) -> Objective:
|
2026-02-13 11:38:59 +01:00
|
|
|
if self.is_over:
|
|
|
|
|
raise ForbiddenOperation("Can't add objective in a closed war.")
|
2026-01-30 00:34:22 +01:00
|
|
|
obj = Objective(name, description)
|
|
|
|
|
self.objectives[obj.id] = obj
|
|
|
|
|
return obj
|
2026-01-28 16:25:40 +01:00
|
|
|
|
|
|
|
|
def get_objective(self, id: str) -> Objective:
|
|
|
|
|
return self.objectives[id]
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def get_all_objectives(self) -> List[Objective]:
|
2026-01-28 16:25:40 +01:00
|
|
|
return list(self.objectives.values())
|
|
|
|
|
|
2026-01-30 00:34:22 +01:00
|
|
|
def get_objective_name(self, objective_id: str | None) -> str:
|
|
|
|
|
if objective_id is None:
|
|
|
|
|
return ""
|
|
|
|
|
obj = self.objectives.get(objective_id)
|
|
|
|
|
return obj.name if obj else ""
|
2026-02-02 14:33:31 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def update_objective(
|
2026-02-11 19:22:43 +01:00
|
|
|
self, objective_id: str, *, name: str, description: str | None
|
2026-02-04 16:10:53 +01:00
|
|
|
) -> None:
|
2026-02-13 11:38:59 +01:00
|
|
|
if self.is_over:
|
|
|
|
|
raise ForbiddenOperation("Can't update objective in a closed war.")
|
2026-01-28 16:25:40 +01:00
|
|
|
obj = self.get_objective(objective_id)
|
|
|
|
|
obj.set_name(name)
|
|
|
|
|
obj.set_description(description)
|
2026-02-02 14:33:31 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def remove_objective(self, objective_id: str) -> None:
|
2026-02-13 11:38:59 +01:00
|
|
|
if self.is_over:
|
|
|
|
|
raise ForbiddenOperation("Can't remove objective in a closed war.")
|
2026-02-05 16:17:18 +01:00
|
|
|
camp_using_obj: List[str] = []
|
|
|
|
|
for camp in self.campaigns:
|
|
|
|
|
if camp.has_sector_with_objective(objective_id):
|
|
|
|
|
camp_using_obj.append(camp.name)
|
|
|
|
|
if camp_using_obj:
|
|
|
|
|
camps_str = ", ".join(camp_using_obj)
|
2026-02-13 11:38:59 +01:00
|
|
|
raise ForbiddenOperation(
|
2026-02-05 16:17:18 +01:00
|
|
|
f"This objective is used in campaign(s) sector(s): {camps_str}.\n"
|
|
|
|
|
"Remove it from campaign(s) first."
|
|
|
|
|
)
|
2026-01-28 16:25:40 +01:00
|
|
|
del self.objectives[objective_id]
|
|
|
|
|
|
2026-02-02 14:33:31 +01:00
|
|
|
# War participant methods
|
2026-01-28 16:25:40 +01:00
|
|
|
|
|
|
|
|
def get_all_war_participants_ids(self) -> set[str]:
|
|
|
|
|
return set(self.participants.keys())
|
|
|
|
|
|
2026-02-03 09:01:17 +01:00
|
|
|
def has_participant(self, participant_id: str) -> bool:
|
|
|
|
|
return participant_id in self.participants
|
|
|
|
|
|
|
|
|
|
def has_player(self, player_id: str) -> bool:
|
|
|
|
|
return any(part.player_id == player_id for part in self.participants.values())
|
2026-01-28 16:25:40 +01:00
|
|
|
|
|
|
|
|
def add_war_participant(self, player_id: str, faction: str) -> WarParticipant:
|
2026-02-13 11:38:59 +01:00
|
|
|
if self.is_over:
|
|
|
|
|
raise ForbiddenOperation("Can't add participant in a closed war.")
|
2026-02-03 09:01:17 +01:00
|
|
|
if self.has_player(player_id):
|
2026-01-28 16:25:40 +01:00
|
|
|
raise ValueError("Player already registered in this war")
|
2026-02-03 08:25:25 +01:00
|
|
|
participant = WarParticipant(player_id=player_id, faction=faction)
|
2026-01-28 16:25:40 +01:00
|
|
|
self.participants[participant.id] = participant
|
|
|
|
|
return participant
|
|
|
|
|
|
|
|
|
|
def get_war_participant(self, id: str) -> WarParticipant:
|
|
|
|
|
return self.participants[id]
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def get_all_war_participants(self) -> List[WarParticipant]:
|
2026-01-28 16:25:40 +01:00
|
|
|
return list(self.participants.values())
|
|
|
|
|
|
2026-02-05 16:17:18 +01:00
|
|
|
def update_war_participant(self, participant_id: str, *, faction: str) -> None:
|
2026-02-13 11:38:59 +01:00
|
|
|
if self.is_over:
|
|
|
|
|
raise ForbiddenOperation("Can't update participant in a closed war.")
|
2026-02-05 16:17:18 +01:00
|
|
|
part = self.get_war_participant(participant_id)
|
2026-02-03 08:25:25 +01:00
|
|
|
# Can't change referred Model.players
|
2026-01-28 16:25:40 +01:00
|
|
|
part.set_faction(faction)
|
|
|
|
|
|
2026-02-05 16:17:18 +01:00
|
|
|
def remove_war_participant(self, participant_id: str) -> None:
|
2026-02-13 11:38:59 +01:00
|
|
|
if self.is_over:
|
|
|
|
|
raise ForbiddenOperation("Can't remove participant in a closed war.")
|
2026-02-05 16:17:18 +01:00
|
|
|
camp_using_part: List[str] = []
|
|
|
|
|
for camp in self.campaigns:
|
|
|
|
|
if camp.has_war_participant(participant_id):
|
|
|
|
|
camp_using_part.append(camp.name)
|
|
|
|
|
if camp_using_part:
|
|
|
|
|
camps_str = ", ".join(camp_using_part)
|
2026-02-13 11:38:59 +01:00
|
|
|
raise ForbiddenOperation(
|
2026-02-05 16:17:18 +01:00
|
|
|
f"This war participant is used in campaign(s): {camps_str}.\n"
|
|
|
|
|
"Remove it from campaign(s) first."
|
|
|
|
|
)
|
|
|
|
|
del self.participants[participant_id]
|
2026-01-28 16:25:40 +01:00
|
|
|
|
2026-02-02 14:33:31 +01:00
|
|
|
# Campaign methods
|
2026-01-28 16:25:40 +01:00
|
|
|
|
|
|
|
|
def has_campaign(self, campaign_id: str) -> bool:
|
|
|
|
|
return any(c.id == campaign_id for c in self.campaigns)
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def get_default_campaign_values(self) -> Dict[str, Any]:
|
2026-02-02 14:33:31 +01:00
|
|
|
return {"month": datetime.now().month}
|
|
|
|
|
|
2026-02-13 11:38:59 +01:00
|
|
|
def has_finished_campaign(self) -> bool:
|
|
|
|
|
return any(c.is_over for c in self.campaigns)
|
|
|
|
|
|
|
|
|
|
def has_finished_round(self) -> bool:
|
|
|
|
|
return any(c.has_finished_round() for c in self.campaigns)
|
|
|
|
|
|
|
|
|
|
def has_finished_battle(self) -> bool:
|
|
|
|
|
return any(c.has_finished_battle() for c in self.campaigns)
|
|
|
|
|
|
2026-02-11 19:22:43 +01:00
|
|
|
def all_campaigns_finished(self) -> bool:
|
|
|
|
|
return all(c.is_over for c in self.campaigns)
|
|
|
|
|
|
2026-01-22 23:42:47 +01:00
|
|
|
def add_campaign(self, name: str, month: int | None = None) -> Campaign:
|
2026-02-13 11:38:59 +01:00
|
|
|
if self.is_over:
|
|
|
|
|
raise ForbiddenOperation("Can't add campaign in a closed war.")
|
2026-01-22 23:42:47 +01:00
|
|
|
if month is None:
|
|
|
|
|
month = self.get_default_campaign_values()["month"]
|
|
|
|
|
campaign = Campaign(name, month)
|
2026-01-21 07:43:04 +01:00
|
|
|
self.campaigns.append(campaign)
|
|
|
|
|
return campaign
|
|
|
|
|
|
2026-01-28 16:25:40 +01:00
|
|
|
def get_campaign(self, campaign_id: str) -> Campaign:
|
2026-01-22 23:42:47 +01:00
|
|
|
for camp in self.campaigns:
|
|
|
|
|
if camp.id == campaign_id:
|
|
|
|
|
return camp
|
|
|
|
|
raise KeyError(f"Campaign {campaign_id} not found in War {self.id}")
|
2026-01-21 07:43:04 +01:00
|
|
|
|
2026-02-05 16:17:18 +01:00
|
|
|
# TODO replace multiloops by internal has_* method
|
2026-02-05 10:19:14 +01:00
|
|
|
def get_campaign_by_round(self, round_id: str) -> Campaign | None:
|
2026-01-22 23:42:47 +01:00
|
|
|
for camp in self.campaigns:
|
|
|
|
|
for rnd in camp.rounds:
|
|
|
|
|
if rnd.id == round_id:
|
|
|
|
|
return camp
|
2026-02-05 10:19:14 +01:00
|
|
|
return None
|
2026-01-22 23:42:47 +01:00
|
|
|
|
2026-02-05 16:17:18 +01:00
|
|
|
# TODO replace multiloops by internal has_* method
|
2026-01-30 00:34:22 +01:00
|
|
|
def get_campaign_by_sector(self, sector_id: str) -> Campaign:
|
|
|
|
|
for camp in self.campaigns:
|
|
|
|
|
for sect in camp.sectors.values():
|
|
|
|
|
if sect.id == sector_id:
|
|
|
|
|
return camp
|
|
|
|
|
raise KeyError(f"Sector {sector_id} not found in any Campaign")
|
|
|
|
|
|
2026-02-16 10:45:34 +01:00
|
|
|
def get_campaign_by_campaign_participant(
|
|
|
|
|
self, participant_id: str
|
|
|
|
|
) -> Campaign | None:
|
2026-01-30 00:34:22 +01:00
|
|
|
for camp in self.campaigns:
|
2026-02-02 14:33:31 +01:00
|
|
|
if camp.has_participant(participant_id):
|
|
|
|
|
return camp
|
2026-02-16 10:45:34 +01:00
|
|
|
return None
|
2026-01-30 00:34:22 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def update_campaign(self, campaign_id: str, *, name: str, month: int) -> None:
|
2026-02-13 11:38:59 +01:00
|
|
|
if self.is_over:
|
|
|
|
|
raise ForbiddenOperation("Can't update campaign in a closed war.")
|
2026-01-22 23:42:47 +01:00
|
|
|
camp = self.get_campaign(campaign_id)
|
2026-02-13 15:44:28 +01:00
|
|
|
if camp.is_over:
|
|
|
|
|
raise ForbiddenOperation("Can't update a closed campaign.")
|
2026-01-22 23:42:47 +01:00
|
|
|
camp.set_name(name)
|
|
|
|
|
camp.set_month(month)
|
2026-02-02 14:33:31 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def get_all_campaigns(self) -> List[Campaign]:
|
2026-01-21 07:43:04 +01:00
|
|
|
return list(self.campaigns)
|
2026-02-02 14:33:31 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def remove_campaign(self, campaign_id: str) -> None:
|
2026-02-13 11:38:59 +01:00
|
|
|
if self.is_over:
|
|
|
|
|
raise ForbiddenOperation("Can't remove campaign in a closed war.")
|
2026-01-22 23:42:47 +01:00
|
|
|
camp = self.get_campaign(campaign_id)
|
2026-02-13 11:38:59 +01:00
|
|
|
if camp:
|
|
|
|
|
if camp.is_over:
|
|
|
|
|
raise ForbiddenOperation("Can't remove closed campaign.")
|
|
|
|
|
if camp.has_finished_round():
|
|
|
|
|
raise ForbiddenOperation(
|
|
|
|
|
"Can't remove campaign with finished round(s)."
|
|
|
|
|
)
|
|
|
|
|
if camp.has_finished_battle():
|
|
|
|
|
raise ForbiddenOperation(
|
|
|
|
|
"Can't remove campaign with finished battle(s) in round(s)."
|
|
|
|
|
)
|
2026-01-28 16:25:40 +01:00
|
|
|
self.campaigns.remove(camp)
|
|
|
|
|
|
2026-02-02 14:33:31 +01:00
|
|
|
# Sector methods
|
|
|
|
|
|
|
|
|
|
def add_sector(
|
|
|
|
|
self,
|
2026-02-04 16:10:53 +01:00
|
|
|
campaign_id: str,
|
2026-02-02 14:33:31 +01:00
|
|
|
name: str,
|
|
|
|
|
round_id: str,
|
|
|
|
|
major_id: str,
|
|
|
|
|
minor_id: str,
|
|
|
|
|
influence_id: str,
|
2026-02-12 09:10:03 +01:00
|
|
|
mission: str,
|
|
|
|
|
description: str,
|
2026-02-02 14:33:31 +01:00
|
|
|
) -> Sector:
|
2026-01-30 00:34:22 +01:00
|
|
|
camp = self.get_campaign(campaign_id)
|
2026-02-12 09:10:03 +01:00
|
|
|
return camp.add_sector(
|
|
|
|
|
name, round_id, major_id, minor_id, influence_id, mission, description
|
|
|
|
|
)
|
2026-01-30 00:34:22 +01:00
|
|
|
|
2026-02-05 16:17:18 +01:00
|
|
|
# TODO replace multiloops by internal has_* method
|
2026-02-04 16:10:53 +01:00
|
|
|
def get_sector(self, sector_id: str) -> Sector:
|
|
|
|
|
for camp in self.campaigns:
|
|
|
|
|
for sect in camp.sectors.values():
|
|
|
|
|
if sect.id == sector_id:
|
|
|
|
|
return sect
|
|
|
|
|
raise KeyError("Sector not found")
|
2026-01-30 00:34:22 +01:00
|
|
|
|
2026-02-02 14:33:31 +01:00
|
|
|
def update_sector(
|
|
|
|
|
self,
|
|
|
|
|
sector_id: str,
|
|
|
|
|
*,
|
|
|
|
|
name: str,
|
2026-02-11 19:22:43 +01:00
|
|
|
round_id: str | None,
|
|
|
|
|
major_id: str | None,
|
|
|
|
|
minor_id: str | None,
|
|
|
|
|
influence_id: str | None,
|
2026-02-12 09:10:03 +01:00
|
|
|
mission: str | None,
|
|
|
|
|
description: str | None,
|
2026-02-04 16:10:53 +01:00
|
|
|
) -> None:
|
2026-01-30 15:32:44 +01:00
|
|
|
camp = self.get_campaign_by_sector(sector_id)
|
2026-02-02 14:33:31 +01:00
|
|
|
camp.update_sector(
|
|
|
|
|
sector_id,
|
|
|
|
|
name=name,
|
|
|
|
|
round_id=round_id,
|
|
|
|
|
major_id=major_id,
|
|
|
|
|
minor_id=minor_id,
|
|
|
|
|
influence_id=influence_id,
|
2026-02-12 09:10:03 +01:00
|
|
|
mission=mission,
|
|
|
|
|
description=description,
|
2026-02-02 14:33:31 +01:00
|
|
|
)
|
2026-01-30 15:32:44 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def remove_sector(self, sector_id: str) -> None:
|
2026-01-30 00:34:22 +01:00
|
|
|
camp = self.get_campaign_by_sector(sector_id)
|
|
|
|
|
camp.remove_sector(sector_id)
|
2026-02-02 14:33:31 +01:00
|
|
|
|
|
|
|
|
# Campaign participant methods
|
2026-01-30 00:34:22 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def get_available_war_participants(self, campaign_id: str) -> List[WarParticipant]:
|
2026-01-30 00:34:22 +01:00
|
|
|
camp = self.get_campaign(campaign_id)
|
|
|
|
|
return [
|
|
|
|
|
part
|
|
|
|
|
for part in self.participants.values()
|
2026-02-03 09:01:17 +01:00
|
|
|
if not camp.has_war_participant(part.id)
|
2026-01-30 00:34:22 +01:00
|
|
|
]
|
|
|
|
|
|
2026-02-02 14:33:31 +01:00
|
|
|
def add_campaign_participant(
|
|
|
|
|
self, campaign_id: str, participant_id: str, leader: str, theme: str
|
|
|
|
|
) -> CampaignParticipant:
|
2026-01-30 00:34:22 +01:00
|
|
|
camp = self.get_campaign(campaign_id)
|
2026-02-02 14:33:31 +01:00
|
|
|
return camp.add_campaign_participant(participant_id, leader, theme)
|
2026-01-30 00:34:22 +01:00
|
|
|
|
2026-02-05 16:17:18 +01:00
|
|
|
# TODO replace multiloops by internal has_* method
|
2026-02-04 16:10:53 +01:00
|
|
|
def get_campaign_participant(self, participant_id: str) -> CampaignParticipant:
|
|
|
|
|
for camp in self.campaigns:
|
2026-01-30 00:34:22 +01:00
|
|
|
for part in camp.participants.values():
|
|
|
|
|
if part.id == participant_id:
|
|
|
|
|
return part
|
|
|
|
|
raise KeyError("Participant not found")
|
|
|
|
|
|
2026-02-02 14:33:31 +01:00
|
|
|
def update_campaign_participant(
|
|
|
|
|
self, participant_id: str, *, leader: str, theme: str
|
2026-02-04 16:10:53 +01:00
|
|
|
) -> None:
|
2026-01-30 00:34:22 +01:00
|
|
|
camp = self.get_campaign_by_campaign_participant(participant_id)
|
2026-02-16 10:45:34 +01:00
|
|
|
if camp is not None:
|
|
|
|
|
camp.update_campaign_participant(participant_id, leader=leader, theme=theme)
|
2026-01-30 00:34:22 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def remove_campaign_participant(self, participant_id: str) -> None:
|
2026-01-30 00:34:22 +01:00
|
|
|
camp = self.get_campaign_by_campaign_participant(participant_id)
|
2026-02-16 10:45:34 +01:00
|
|
|
if camp is not None:
|
|
|
|
|
camp.remove_campaign_participant(participant_id)
|
2026-01-30 00:34:22 +01:00
|
|
|
|
2026-02-02 14:33:31 +01:00
|
|
|
# Round methods
|
2026-01-30 15:32:44 +01:00
|
|
|
|
|
|
|
|
def add_round(self, campaign_id: str) -> Round:
|
|
|
|
|
camp = self.get_campaign(campaign_id)
|
|
|
|
|
return camp.add_round()
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def remove_round(self, round_id: str) -> None:
|
2026-01-30 15:32:44 +01:00
|
|
|
camp = self.get_campaign_by_round(round_id)
|
2026-02-05 10:19:14 +01:00
|
|
|
if camp is not None:
|
|
|
|
|
camp.remove_round(round_id)
|
2026-01-30 15:32:44 +01:00
|
|
|
|
2026-02-02 14:33:31 +01:00
|
|
|
# Choice methods
|
2026-01-30 15:32:44 +01:00
|
|
|
|
|
|
|
|
def create_choice(self, round_id: str, participant_id: str) -> Choice:
|
|
|
|
|
camp = self.get_campaign_by_round(round_id)
|
2026-02-05 10:19:14 +01:00
|
|
|
if camp is not None:
|
|
|
|
|
return camp.create_choice(round_id, participant_id)
|
|
|
|
|
raise KeyError("Campaign with round {round_id} doesn't exist")
|
2026-02-02 14:33:31 +01:00
|
|
|
|
|
|
|
|
def update_choice(
|
|
|
|
|
self,
|
|
|
|
|
round_id: str,
|
|
|
|
|
participant_id: str,
|
|
|
|
|
priority_sector_id: str | None,
|
|
|
|
|
secondary_sector_id: str | None,
|
|
|
|
|
comment: str | None,
|
2026-02-04 16:10:53 +01:00
|
|
|
) -> None:
|
2026-02-02 10:41:16 +01:00
|
|
|
camp = self.get_campaign_by_round(round_id)
|
2026-02-05 10:19:14 +01:00
|
|
|
if camp is not None:
|
|
|
|
|
camp.update_choice(
|
|
|
|
|
round_id,
|
|
|
|
|
participant_id,
|
|
|
|
|
priority_sector_id,
|
|
|
|
|
secondary_sector_id,
|
|
|
|
|
comment,
|
|
|
|
|
)
|
2026-01-30 15:32:44 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def remove_choice(self, round_id: str, participant_id: str) -> None:
|
2026-01-30 15:32:44 +01:00
|
|
|
camp = self.get_campaign_by_round(round_id)
|
2026-02-05 10:19:14 +01:00
|
|
|
if camp is not None:
|
|
|
|
|
camp.remove_choice(round_id, participant_id)
|
2026-01-30 15:32:44 +01:00
|
|
|
|
2026-02-02 14:33:31 +01:00
|
|
|
# Battle methods
|
2026-01-30 18:55:39 +01:00
|
|
|
|
2026-02-19 14:17:42 +01:00
|
|
|
# TODO replace multiloops by internal has_* method
|
|
|
|
|
def get_battle(self, battle_id: str) -> Battle:
|
|
|
|
|
for camp in self.campaigns:
|
|
|
|
|
for rnd in camp.rounds:
|
|
|
|
|
for bat in rnd.battles.values():
|
|
|
|
|
if bat.sector_id == battle_id:
|
|
|
|
|
return bat
|
|
|
|
|
raise KeyError("Round not found")
|
|
|
|
|
|
2026-01-30 18:55:39 +01:00
|
|
|
def create_battle(self, round_id: str, sector_id: str) -> Battle:
|
|
|
|
|
camp = self.get_campaign_by_round(round_id)
|
2026-02-05 10:19:14 +01:00
|
|
|
if camp is not None:
|
|
|
|
|
return camp.create_battle(round_id, sector_id)
|
|
|
|
|
raise KeyError("Campaign with round {round_id} doesn't exist")
|
2026-01-30 18:55:39 +01:00
|
|
|
|
2026-02-02 14:33:31 +01:00
|
|
|
def update_battle(
|
|
|
|
|
self,
|
|
|
|
|
round_id: str,
|
|
|
|
|
sector_id: str,
|
|
|
|
|
player_1_id: str | None,
|
|
|
|
|
player_2_id: str | None,
|
|
|
|
|
winner_id: str | None,
|
|
|
|
|
score: str | None,
|
|
|
|
|
victory_condition: str | None,
|
|
|
|
|
comment: str | None,
|
2026-02-04 16:10:53 +01:00
|
|
|
) -> None:
|
2026-02-02 10:41:16 +01:00
|
|
|
camp = self.get_campaign_by_round(round_id)
|
2026-02-05 10:19:14 +01:00
|
|
|
if camp is not None:
|
|
|
|
|
camp.update_battle(
|
|
|
|
|
round_id,
|
|
|
|
|
sector_id,
|
|
|
|
|
player_1_id,
|
|
|
|
|
player_2_id,
|
|
|
|
|
winner_id,
|
|
|
|
|
score,
|
|
|
|
|
victory_condition,
|
|
|
|
|
comment,
|
|
|
|
|
)
|
2026-02-02 10:41:16 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def remove_battle(self, round_id: str, sector_id: str) -> None:
|
2026-01-30 18:55:39 +01:00
|
|
|
camp = self.get_campaign_by_round(round_id)
|
2026-02-05 10:19:14 +01:00
|
|
|
if camp is not None:
|
|
|
|
|
camp.remove_battle(round_id, sector_id)
|
2026-02-17 16:37:36 +01:00
|
|
|
|
|
|
|
|
# Event methods
|
|
|
|
|
|
|
|
|
|
def get_influence_tokens(self, participant_id: str) -> int:
|
|
|
|
|
gained = sum(
|
|
|
|
|
e.amount
|
|
|
|
|
for e in self.events
|
|
|
|
|
if isinstance(e, InfluenceGained) and e.participant_id == participant_id
|
|
|
|
|
)
|
|
|
|
|
spent = sum(
|
|
|
|
|
e.amount
|
|
|
|
|
for e in self.events
|
|
|
|
|
if isinstance(e, InfluenceSpent) and e.participant_id == participant_id
|
|
|
|
|
)
|
|
|
|
|
return gained - spent
|