From 097823fab09dd4d5d8193f3c0917d809b27f61a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20R=C3=A9aux?= Date: Tue, 24 Feb 2026 10:04:16 +0100 Subject: [PATCH] fix canceled tie spent tokens --- .../controller/campaign_controller.py | 2 +- src/warchron/controller/war_controller.py | 2 +- src/warchron/model/result_checker.py | 1 - src/warchron/model/tie_manager.py | 23 +++++++++++++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/warchron/controller/campaign_controller.py b/src/warchron/controller/campaign_controller.py index 9228a97..d66154e 100644 --- a/src/warchron/controller/campaign_controller.py +++ b/src/warchron/controller/campaign_controller.py @@ -186,7 +186,6 @@ class CampaignController: RefreshScope.WARS_TREE, item_type=ItemType.CAMPAIGN, item_id=campaign_id ) - # TODO fix spent tokens on tie cancel def resolve_ties( self, war: War, contexts: List[TieContext] ) -> Dict[str, Dict[str, bool]]: @@ -208,6 +207,7 @@ class CampaignController: context_id=ctx.context_id, ) if not dialog.exec(): + TieResolver.cancel_tie_break(war, ContextType.CAMPAIGN, ctx.context_id) raise ForbiddenOperation("Tie resolution cancelled") bids_map[ctx.context_id] = dialog.get_bids() return bids_map diff --git a/src/warchron/controller/war_controller.py b/src/warchron/controller/war_controller.py index 3fd8a2d..54f28f6 100644 --- a/src/warchron/controller/war_controller.py +++ b/src/warchron/controller/war_controller.py @@ -161,7 +161,6 @@ class WarController: RefreshScope.WARS_TREE, item_type=ItemType.WAR, item_id=war_id ) - # TODO fix spent tokens on tie cancel # TODO fix ignored campaign tie-breaks def resolve_ties( self, war: War, contexts: List[TieContext] @@ -184,6 +183,7 @@ class WarController: context_id=ctx.context_id, ) if not dialog.exec(): + TieResolver.cancel_tie_break(war, ContextType.WAR, ctx.context_id) raise ForbiddenOperation("Tie resolution cancelled") bids_map[ctx.context_id] = dialog.get_bids() return bids_map diff --git a/src/warchron/model/result_checker.py b/src/warchron/model/result_checker.py index 978b0ce..d69003a 100644 --- a/src/warchron/model/result_checker.py +++ b/src/warchron/model/result_checker.py @@ -28,7 +28,6 @@ class ResultChecker: and ev.context_id == context_id ): return ev.participant_id # None if confirmed draw - return None @staticmethod diff --git a/src/warchron/model/tie_manager.py b/src/warchron/model/tie_manager.py index 8ea0e75..c398592 100644 --- a/src/warchron/model/tie_manager.py +++ b/src/warchron/model/tie_manager.py @@ -130,6 +130,29 @@ class TieResolver: ) ) + @staticmethod + def cancel_tie_break( + war: War, + context_type: ContextType, + context_id: str, + ) -> None: + war.events = [ + ev + for ev in war.events + if not ( + ( + isinstance(ev, InfluenceSpent) + and ev.context_type == context_type + and ev.context_id == context_id + ) + or ( + isinstance(ev, TieResolved) + and ev.context_type == context_type + and ev.context_id == context_id + ) + ) + ] + @staticmethod def rank_by_tokens( war: War,