fix round tie loop + improve tie ranking
This commit is contained in:
parent
60d8e6ca15
commit
f339498f97
6 changed files with 99 additions and 110 deletions
|
|
@ -15,9 +15,11 @@ def register_event(cls: Type[T]) -> Type[T]:
|
|||
class WarEvent:
|
||||
TYPE = "WarEvent"
|
||||
|
||||
def __init__(self, participant_id: str | None = None):
|
||||
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
|
||||
self.context_id = context_id
|
||||
self.timestamp: datetime = datetime.now()
|
||||
|
||||
def set_id(self, new_id: str) -> None:
|
||||
|
|
@ -34,6 +36,8 @@ class WarEvent:
|
|||
"type": self.TYPE,
|
||||
"id": self.id,
|
||||
"participant_id": self.participant_id,
|
||||
"context_type": self.context_type,
|
||||
"context_id": self.context_id,
|
||||
"timestamp": self.timestamp.isoformat(),
|
||||
}
|
||||
|
||||
|
|
@ -41,6 +45,8 @@ class WarEvent:
|
|||
def _base_fromDict(cls: Type[T], ev: T, data: Dict[str, Any]) -> T:
|
||||
ev.id = data["id"]
|
||||
ev.participant_id = data["participant_id"]
|
||||
ev.context_type = data["context_type"]
|
||||
ev.context_id = data["context_id"]
|
||||
ev.timestamp = datetime.fromisoformat(data["timestamp"])
|
||||
return ev
|
||||
|
||||
|
|
@ -58,21 +64,10 @@ class TieResolved(WarEvent):
|
|||
TYPE = "TieResolved"
|
||||
|
||||
def __init__(self, participant_id: str | None, context_type: str, context_id: str):
|
||||
super().__init__(participant_id)
|
||||
self.participant_id: str | None = (
|
||||
participant_id # winner or None (confirmed tie)
|
||||
)
|
||||
self.context_type = context_type # battle, round, campaign, war
|
||||
self.context_id = context_id
|
||||
super().__init__(participant_id, context_type, context_id)
|
||||
|
||||
def toDict(self) -> Dict[str, Any]:
|
||||
d = super().toDict()
|
||||
d.update(
|
||||
{
|
||||
"context_type": self.context_type,
|
||||
"context_id": self.context_id,
|
||||
}
|
||||
)
|
||||
return d
|
||||
|
||||
@classmethod
|
||||
|
|
@ -89,17 +84,17 @@ class TieResolved(WarEvent):
|
|||
class InfluenceGained(WarEvent):
|
||||
TYPE = "InfluenceGained"
|
||||
|
||||
def __init__(self, participant_id: str, amount: int, source: str):
|
||||
super().__init__(participant_id)
|
||||
def __init__(
|
||||
self, participant_id: str, amount: int, context_type: str, context_id: str
|
||||
):
|
||||
super().__init__(participant_id, context_type, context_id)
|
||||
self.amount = amount
|
||||
self.source = source # "battle", "tie_resolution", etc.
|
||||
|
||||
def toDict(self) -> Dict[str, Any]:
|
||||
d = super().toDict()
|
||||
d.update(
|
||||
{
|
||||
"amount": self.amount,
|
||||
"source": self.source,
|
||||
}
|
||||
)
|
||||
return d
|
||||
|
|
@ -108,8 +103,9 @@ class InfluenceGained(WarEvent):
|
|||
def fromDict(cls, data: Dict[str, Any]) -> InfluenceGained:
|
||||
ev = cls(
|
||||
data["participant_id"],
|
||||
data["amount"],
|
||||
data["source"],
|
||||
int(data["amount"]),
|
||||
data["context_type"],
|
||||
data["context_id"],
|
||||
)
|
||||
return cls._base_fromDict(ev, data)
|
||||
|
||||
|
|
@ -118,17 +114,17 @@ class InfluenceGained(WarEvent):
|
|||
class InfluenceSpent(WarEvent):
|
||||
TYPE = "InfluenceSpent"
|
||||
|
||||
def __init__(self, participant_id: str, amount: int, context_type: str):
|
||||
super().__init__(participant_id)
|
||||
def __init__(
|
||||
self, participant_id: str, amount: int, context_type: str, context_id: str
|
||||
):
|
||||
super().__init__(participant_id, context_type, context_id)
|
||||
self.amount = amount
|
||||
self.context_type = context_type # "battle_tie", "campaign_tie", etc.
|
||||
|
||||
def toDict(self) -> Dict[str, Any]:
|
||||
d = super().toDict()
|
||||
d.update(
|
||||
{
|
||||
"amount": self.amount,
|
||||
"context_type": self.context_type,
|
||||
}
|
||||
)
|
||||
return d
|
||||
|
|
@ -137,7 +133,8 @@ class InfluenceSpent(WarEvent):
|
|||
def fromDict(cls, data: Dict[str, Any]) -> InfluenceSpent:
|
||||
ev = cls(
|
||||
data["participant_id"],
|
||||
data["amount"],
|
||||
int(data["amount"]),
|
||||
data["context_type"],
|
||||
data["context_id"],
|
||||
)
|
||||
return cls._base_fromDict(ev, data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue