detect and resolve battle tie with influence_token
This commit is contained in:
parent
115ddf8d50
commit
818d2886f4
23 changed files with 808 additions and 172 deletions
|
|
@ -3,6 +3,7 @@ from uuid import uuid4
|
|||
from datetime import datetime
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from warchron.model.war_event import WarEvent, InfluenceGained, InfluenceSpent
|
||||
from warchron.model.exception import ForbiddenOperation
|
||||
from warchron.model.war_participant import WarParticipant
|
||||
from warchron.model.objective import Objective
|
||||
|
|
@ -25,6 +26,7 @@ class War:
|
|||
self.participants: Dict[str, WarParticipant] = {}
|
||||
self.objectives: Dict[str, Objective] = {}
|
||||
self.campaigns: List[Campaign] = []
|
||||
self.events: List[WarEvent] = []
|
||||
self.is_over: bool = False
|
||||
|
||||
def set_id(self, new_id: str) -> None:
|
||||
|
|
@ -53,6 +55,9 @@ class War:
|
|||
def set_influence_token(self, new_state: bool) -> None:
|
||||
if self.is_over:
|
||||
raise ForbiddenOperation("Can't set influence token of a closed war.")
|
||||
# TODO raise RequiresConfirmation
|
||||
# * disable: cleanup if any token has already been gained/spent
|
||||
# * enable: retrigger battle_outcomes and resolve tie again if any draw
|
||||
self.influence_token = new_state
|
||||
|
||||
def set_state(self, new_state: bool) -> None:
|
||||
|
|
@ -69,6 +74,7 @@ class War:
|
|||
"participants": [part.toDict() for part in self.participants.values()],
|
||||
"objectives": [obj.toDict() for obj in self.objectives.values()],
|
||||
"campaigns": [camp.toDict() for camp in self.campaigns],
|
||||
"events": [ev.toDict() for ev in self.events],
|
||||
"is_over": self.is_over,
|
||||
}
|
||||
|
||||
|
|
@ -87,6 +93,8 @@ class War:
|
|||
war.objectives[obj.id] = obj
|
||||
for camp_data in data.get("campaigns", []):
|
||||
war.campaigns.append(Campaign.fromDict(camp_data))
|
||||
for ev_data in data.get("events", []):
|
||||
war.events.append(WarEvent.fromDict(ev_data))
|
||||
war.set_state(data.get("is_over", False))
|
||||
return war
|
||||
|
||||
|
|
@ -439,3 +447,18 @@ class War:
|
|||
camp = self.get_campaign_by_round(round_id)
|
||||
if camp is not None:
|
||||
camp.remove_battle(round_id, sector_id)
|
||||
|
||||
# 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue