fix campaign tie loop + dynamic tie dialog
This commit is contained in:
parent
f339498f97
commit
c9407f9407
5 changed files with 120 additions and 222 deletions
|
|
@ -16,14 +16,6 @@ class TieContext:
|
|||
participants: List[str] # war_participant_ids
|
||||
|
||||
|
||||
@dataclass
|
||||
class TieState:
|
||||
winner: str | None
|
||||
tied_players: List[str]
|
||||
eliminated: List[str]
|
||||
# is_final: bool
|
||||
|
||||
|
||||
class TieResolver:
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -65,16 +57,23 @@ class TieResolver:
|
|||
buckets: DefaultDict[int, List[str]] = defaultdict(list)
|
||||
for pid, score in scores.items():
|
||||
buckets[score.victory_points].append(pid)
|
||||
ties = []
|
||||
for participants in buckets.values():
|
||||
if len(participants) > 1:
|
||||
ties.append(
|
||||
TieContext(
|
||||
context_type=ContextType.CAMPAIGN,
|
||||
context_id=campaign_id,
|
||||
participants=participants,
|
||||
)
|
||||
ties: List[TieContext] = []
|
||||
for score_value, participants in buckets.items():
|
||||
if len(participants) <= 1:
|
||||
continue
|
||||
tie_id = f"{campaign_id}:score:{score_value}"
|
||||
if TieResolver.is_tie_resolved(war, ContextType.CAMPAIGN, tie_id):
|
||||
continue
|
||||
if not TieResolver.can_tie_be_resolved(war, participants):
|
||||
war.events.append(TieResolved(None, ContextType.CAMPAIGN, tie_id))
|
||||
continue
|
||||
ties.append(
|
||||
TieContext(
|
||||
context_type=ContextType.CAMPAIGN,
|
||||
context_id=tie_id,
|
||||
participants=participants,
|
||||
)
|
||||
)
|
||||
return ties
|
||||
|
||||
@staticmethod
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue