2026-02-17 16:37:36 +01:00
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from warchron.controller.app_controller import AppController
|
|
|
|
|
from warchron.model.war import War
|
|
|
|
|
from warchron.model.campaign import Campaign
|
|
|
|
|
from warchron.model.round import Round
|
|
|
|
|
from warchron.model.closure_service import ClosureService
|
|
|
|
|
from warchron.model.tie_manager import TieResolver
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClosureWorkflow:
|
|
|
|
|
|
|
|
|
|
def __init__(self, controller: "AppController"):
|
|
|
|
|
self.app = controller
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RoundClosureWorkflow(ClosureWorkflow):
|
|
|
|
|
|
|
|
|
|
def start(self, war: War, campaign: Campaign, round: Round) -> None:
|
|
|
|
|
ClosureService.check_round_closable(round)
|
2026-02-20 11:01:25 +01:00
|
|
|
ties = TieResolver.find_battle_ties(war, round.id)
|
2026-02-17 16:37:36 +01:00
|
|
|
while ties:
|
2026-02-20 23:44:22 +01:00
|
|
|
bids_map = self.app.rounds.resolve_ties(war, ties)
|
2026-02-20 11:01:25 +01:00
|
|
|
for tie in ties:
|
2026-03-06 15:02:53 +01:00
|
|
|
bids = bids_map[tie.key()]
|
|
|
|
|
TieResolver.apply_bids(war, tie, bids)
|
2026-02-25 16:54:21 +01:00
|
|
|
TieResolver.resolve_tie_state(war, tie, bids)
|
2026-02-20 11:01:25 +01:00
|
|
|
ties = TieResolver.find_battle_ties(war, round.id)
|
2026-02-17 16:37:36 +01:00
|
|
|
for battle in round.battles.values():
|
|
|
|
|
ClosureService.apply_battle_outcomes(war, campaign, battle)
|
|
|
|
|
ClosureService.finalize_round(round)
|
|
|
|
|
|
2026-02-20 11:01:25 +01:00
|
|
|
|
|
|
|
|
class CampaignClosureWorkflow(ClosureWorkflow):
|
|
|
|
|
|
|
|
|
|
def start(self, war: War, campaign: Campaign) -> None:
|
|
|
|
|
ClosureService.check_campaign_closable(campaign)
|
|
|
|
|
ties = TieResolver.find_campaign_ties(war, campaign.id)
|
|
|
|
|
while ties:
|
2026-02-20 23:44:22 +01:00
|
|
|
bids_map = self.app.campaigns.resolve_ties(war, ties)
|
2026-02-20 11:01:25 +01:00
|
|
|
for tie in ties:
|
2026-03-06 15:02:53 +01:00
|
|
|
bids = bids_map[tie.key()]
|
|
|
|
|
TieResolver.apply_bids(war, tie, bids)
|
2026-02-25 16:54:21 +01:00
|
|
|
TieResolver.resolve_tie_state(war, tie, bids)
|
2026-02-20 11:01:25 +01:00
|
|
|
ties = TieResolver.find_campaign_ties(war, campaign.id)
|
2026-03-03 11:52:07 +01:00
|
|
|
for objective_id in war.objectives:
|
|
|
|
|
ties = TieResolver.find_campaign_objective_ties(
|
|
|
|
|
war,
|
|
|
|
|
campaign.id,
|
|
|
|
|
objective_id,
|
|
|
|
|
)
|
|
|
|
|
while ties:
|
|
|
|
|
bids_map = self.app.campaigns.resolve_ties(war, ties)
|
|
|
|
|
for tie in ties:
|
2026-03-06 15:02:53 +01:00
|
|
|
bids = bids_map[tie.key()]
|
|
|
|
|
TieResolver.apply_bids(war, tie, bids)
|
2026-03-03 11:52:07 +01:00
|
|
|
TieResolver.resolve_tie_state(war, tie, bids)
|
|
|
|
|
ties = TieResolver.find_campaign_objective_ties(
|
|
|
|
|
war,
|
|
|
|
|
campaign.id,
|
|
|
|
|
objective_id,
|
|
|
|
|
)
|
2026-02-20 11:01:25 +01:00
|
|
|
ClosureService.finalize_campaign(campaign)
|
2026-02-23 21:18:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class WarClosureWorkflow(ClosureWorkflow):
|
|
|
|
|
|
|
|
|
|
def start(self, war: War) -> None:
|
|
|
|
|
ClosureService.check_war_closable(war)
|
|
|
|
|
ties = TieResolver.find_war_ties(war)
|
|
|
|
|
while ties:
|
|
|
|
|
bids_map = self.app.wars.resolve_ties(war, ties)
|
|
|
|
|
for tie in ties:
|
2026-03-06 15:02:53 +01:00
|
|
|
bids = bids_map[tie.key()]
|
|
|
|
|
TieResolver.apply_bids(war, tie, bids)
|
2026-02-25 16:54:21 +01:00
|
|
|
TieResolver.resolve_tie_state(war, tie, bids)
|
2026-02-23 21:18:27 +01:00
|
|
|
ties = TieResolver.find_war_ties(war)
|
2026-03-03 11:52:07 +01:00
|
|
|
for objective_id in war.objectives:
|
|
|
|
|
ties = TieResolver.find_war_objective_ties(
|
|
|
|
|
war,
|
|
|
|
|
objective_id,
|
|
|
|
|
)
|
|
|
|
|
while ties:
|
|
|
|
|
bids_map = self.app.wars.resolve_ties(war, ties)
|
|
|
|
|
for tie in ties:
|
2026-03-06 15:02:53 +01:00
|
|
|
bids = bids_map[tie.key()]
|
|
|
|
|
TieResolver.apply_bids(war, tie, bids)
|
2026-03-03 11:52:07 +01:00
|
|
|
TieResolver.resolve_tie_state(war, tie, bids)
|
|
|
|
|
ties = TieResolver.find_war_objective_ties(
|
|
|
|
|
war,
|
|
|
|
|
objective_id,
|
|
|
|
|
)
|
2026-02-23 21:18:27 +01:00
|
|
|
ClosureService.finalize_war(war)
|