detect and resolve battle tie with influence_token
This commit is contained in:
parent
115ddf8d50
commit
818d2886f4
23 changed files with 808 additions and 172 deletions
|
|
@ -1,16 +1,27 @@
|
|||
from typing import List, TYPE_CHECKING
|
||||
from typing import List, Dict, TYPE_CHECKING
|
||||
|
||||
from PyQt6.QtWidgets import QDialog, QMessageBox
|
||||
from PyQt6.QtWidgets import QDialog
|
||||
from PyQt6.QtWidgets import QMessageBox
|
||||
|
||||
from warchron.constants import ItemType, RefreshScope, Icons, IconName
|
||||
from warchron.model.exception import ForbiddenOperation, DomainError
|
||||
from warchron.model.round import Round
|
||||
from warchron.model.war import War
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from warchron.controller.app_controller import AppController
|
||||
from warchron.controller.dtos import ParticipantOption, SectorDTO, ChoiceDTO, BattleDTO
|
||||
from warchron.model.closure_service import ClosureService
|
||||
|
||||
from warchron.controller.dtos import (
|
||||
ParticipantOption,
|
||||
SectorDTO,
|
||||
ChoiceDTO,
|
||||
BattleDTO,
|
||||
TieContext,
|
||||
)
|
||||
from warchron.controller.closure_workflow import RoundClosureWorkflow
|
||||
from warchron.view.choice_dialog import ChoiceDialog
|
||||
from warchron.view.battle_dialog import BattleDialog
|
||||
from warchron.view.tie_dialog import TieDialog
|
||||
|
||||
|
||||
class RoundController:
|
||||
|
|
@ -123,26 +134,47 @@ class RoundController:
|
|||
if not round_id:
|
||||
return
|
||||
rnd = self.app.model.get_round(round_id)
|
||||
if rnd.is_over:
|
||||
return
|
||||
camp = self.app.model.get_campaign_by_round(round_id)
|
||||
war = self.app.model.get_war_by_round(round_id)
|
||||
workflow = RoundClosureWorkflow(self.app)
|
||||
try:
|
||||
ties = ClosureService.close_round(rnd)
|
||||
except RuntimeError as e:
|
||||
QMessageBox.warning(self.app.view, "Cannot close round", str(e))
|
||||
return
|
||||
if ties:
|
||||
QMessageBox.information(
|
||||
workflow.start(war, camp, rnd)
|
||||
except DomainError as e:
|
||||
QMessageBox.warning(
|
||||
self.app.view,
|
||||
"Tie detected",
|
||||
"Round has unresolved ties. Resolution system not implemented yet.",
|
||||
"Deletion forbidden",
|
||||
str(e),
|
||||
)
|
||||
return
|
||||
self.app.is_dirty = True
|
||||
self.app.navigation.refresh(RefreshScope.CURRENT_SELECTION_DETAILS)
|
||||
self.app.navigation.refresh_and_select(
|
||||
RefreshScope.WARS_TREE, item_type=ItemType.ROUND, item_id=round_id
|
||||
)
|
||||
|
||||
def resolve_ties(
|
||||
self, war: War, contexts: List[TieContext]
|
||||
) -> Dict[str, Dict[str, bool]]:
|
||||
bids_map = {}
|
||||
for ctx in contexts:
|
||||
players = [
|
||||
ParticipantOption(
|
||||
id=pid,
|
||||
name=self.app.model.get_participant_name(pid),
|
||||
)
|
||||
for pid in ctx.participants
|
||||
]
|
||||
counters = [war.get_influence_tokens(pid) for pid in ctx.participants]
|
||||
dialog = TieDialog(
|
||||
parent=self.app.view,
|
||||
players=players,
|
||||
counters=counters,
|
||||
context_id=ctx.context_id,
|
||||
)
|
||||
if not dialog.exec():
|
||||
raise ForbiddenOperation("Tie resolution cancelled")
|
||||
bids_map[ctx.context_id] = dialog.get_bids()
|
||||
return bids_map
|
||||
|
||||
# Choice methods
|
||||
|
||||
def edit_round_choice(self, choice_id: str) -> None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue