wip close round/campaign/war + refacto json None
This commit is contained in:
parent
4c8086caf4
commit
6cbb7c6534
26 changed files with 474 additions and 108 deletions
|
|
@ -1,6 +1,12 @@
|
|||
from __future__ import annotations
|
||||
from typing import Any, Dict
|
||||
from uuid import uuid4
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from warchron.model.war import War
|
||||
from warchron.model.war_event import WarEvent, InfluenceSpent, InfluenceGained
|
||||
from warchron.model.score_service import ScoreService
|
||||
|
||||
|
||||
class WarParticipant:
|
||||
|
|
@ -8,6 +14,7 @@ class WarParticipant:
|
|||
self.id: str = str(uuid4())
|
||||
self.player_id: str = player_id # ref to Model.players
|
||||
self.faction: str = faction
|
||||
self.events: list[WarEvent] = []
|
||||
|
||||
def set_id(self, new_id: str) -> None:
|
||||
self.id = new_id
|
||||
|
|
@ -33,3 +40,16 @@ class WarParticipant:
|
|||
)
|
||||
part.set_id(data["id"])
|
||||
return part
|
||||
|
||||
# Computed properties
|
||||
|
||||
def influence_tokens(self) -> int:
|
||||
gained = sum(e.amount for e in self.events if isinstance(e, InfluenceGained))
|
||||
spent = sum(e.amount for e in self.events if isinstance(e, InfluenceSpent))
|
||||
return gained - spent
|
||||
|
||||
def victory_points(self, war: "War") -> int:
|
||||
return ScoreService.compute_victory_points_for_participant(war, self.id)
|
||||
|
||||
def narrative_points(self, war: "War") -> Dict[str, int]:
|
||||
return ScoreService.compute_narrative_points_for_participant(war, self.id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue