fix ignored campaign NP tie-break when closing war

This commit is contained in:
Maxime Réaux 2026-03-06 15:02:53 +01:00
parent b1bde76319
commit 72f80563f1
16 changed files with 314 additions and 219 deletions

View file

@ -3,6 +3,8 @@ from typing import Dict, Any, TypeVar, Type, cast
from datetime import datetime
from uuid import uuid4
from warchron.model.json_helper import JsonHelper
T = TypeVar("T", bound="WarEvent")
EVENT_REGISTRY: Dict[str, Type["WarEvent"]] = {}
@ -15,7 +17,12 @@ def register_event(cls: Type[T]) -> Type[T]:
class WarEvent:
TYPE = "WarEvent"
def __init__(self, participant_id: str | None, context_type: str, context_id: str):
def __init__(
self,
participant_id: str | None,
context_type: str,
context_id: str,
):
self.id: str = str(uuid4())
self.participant_id: str | None = participant_id
self.context_type = context_type # battle, round, campaign, war
@ -69,15 +76,18 @@ class TieResolved(WarEvent):
context_type: str,
context_id: str,
score_value: int | None = None,
objective_id: str | None = None,
):
super().__init__(participant_id, context_type, context_id)
self.score_value = score_value
self.objective_id = objective_id
def toDict(self) -> Dict[str, Any]:
d = super().toDict()
d.update(
{
"score_value": self.score_value or None,
"objective_id": self.objective_id or None,
}
)
return d
@ -85,10 +95,11 @@ class TieResolved(WarEvent):
@classmethod
def fromDict(cls, data: Dict[str, Any]) -> TieResolved:
ev = cls(
data["participant_id"] or None,
JsonHelper.none_if_empty(data["participant_id"]),
data["context_type"],
data["context_id"],
data["score_value"] or None,
JsonHelper.none_if_empty(data["score_value"]),
JsonHelper.none_if_empty(data["objective_id"]),
)
return cls._base_fromDict(ev, data)
@ -98,9 +109,17 @@ class InfluenceGained(WarEvent):
TYPE = "InfluenceGained"
def __init__(
self, participant_id: str, amount: int, context_type: str, context_id: str
self,
participant_id: str,
amount: int,
context_type: str,
context_id: str,
):
super().__init__(participant_id, context_type, context_id)
super().__init__(
participant_id,
context_type,
context_id,
)
self.amount = amount
def toDict(self) -> Dict[str, Any]:
@ -128,16 +147,23 @@ class InfluenceSpent(WarEvent):
TYPE = "InfluenceSpent"
def __init__(
self, participant_id: str, amount: int, context_type: str, context_id: str
self,
participant_id: str,
amount: int,
context_type: str,
context_id: str,
objective_id: str | None = None,
):
super().__init__(participant_id, context_type, context_id)
self.amount = amount
self.objective_id = objective_id
def toDict(self) -> Dict[str, Any]:
d = super().toDict()
d.update(
{
"amount": self.amount,
"objective_id": self.objective_id,
}
)
return d
@ -149,5 +175,6 @@ class InfluenceSpent(WarEvent):
int(data["amount"]),
data["context_type"],
data["context_id"],
JsonHelper.none_if_empty(data["objective_id"]),
)
return cls._base_fromDict(ev, data)