fix unique participant in war & campaign
This commit is contained in:
parent
49bf6d7ea8
commit
87670329c2
3 changed files with 15 additions and 10 deletions
|
|
@ -54,11 +54,16 @@ class Campaign:
|
|||
def has_participant(self, participant_id: str) -> bool:
|
||||
return participant_id in self.participants
|
||||
|
||||
def has_war_participant(self, war_participant_id: str) -> bool:
|
||||
return any(
|
||||
part.war_participant_id == war_participant_id
|
||||
for part in self.participants.values()
|
||||
)
|
||||
|
||||
def add_campaign_participant(
|
||||
self, war_participant_id: str, leader: str, theme: str
|
||||
) -> CampaignParticipant:
|
||||
## TODO change lookup id target
|
||||
if war_participant_id in self.participants:
|
||||
if self.has_war_participant(war_participant_id):
|
||||
raise ValueError("Player already registered in this campaign")
|
||||
participant = CampaignParticipant(
|
||||
war_participant_id=war_participant_id, leader=leader, theme=theme
|
||||
|
|
|
|||
|
|
@ -123,7 +123,6 @@ class Model:
|
|||
return war
|
||||
raise KeyError(f"Objective {objective_id} not found in any War")
|
||||
|
||||
# TODO don't use this method as participant with same ID (player) can be in several wars!
|
||||
def get_war_by_war_participant(self, participant_id: str) -> War:
|
||||
for war in self.wars.values():
|
||||
if war.has_participant(participant_id):
|
||||
|
|
@ -174,9 +173,7 @@ class Model:
|
|||
def get_available_players(self, war_id: str) -> list[Player]:
|
||||
war = self.get_war(war_id)
|
||||
return [
|
||||
player
|
||||
for player in self.players.values()
|
||||
if not war.has_participant(player.id)
|
||||
player for player in self.players.values() if not war.has_player(player.id)
|
||||
]
|
||||
|
||||
def add_war_participant(
|
||||
|
|
|
|||
|
|
@ -81,11 +81,14 @@ class War:
|
|||
def get_all_war_participants_ids(self) -> set[str]:
|
||||
return set(self.participants.keys())
|
||||
|
||||
def has_participant(self, player_id: str) -> bool:
|
||||
return player_id in self.participants
|
||||
def has_participant(self, participant_id: str) -> bool:
|
||||
return participant_id in self.participants
|
||||
|
||||
def has_player(self, player_id: str) -> bool:
|
||||
return any(part.player_id == player_id for part in self.participants.values())
|
||||
|
||||
def add_war_participant(self, player_id: str, faction: str) -> WarParticipant:
|
||||
if player_id in self.participants:
|
||||
if self.has_player(player_id):
|
||||
raise ValueError("Player already registered in this war")
|
||||
participant = WarParticipant(player_id=player_id, faction=faction)
|
||||
self.participants[participant.id] = participant
|
||||
|
|
@ -207,7 +210,7 @@ class War:
|
|||
return [
|
||||
part
|
||||
for part in self.participants.values()
|
||||
if not camp.has_participant(part.id)
|
||||
if not camp.has_war_participant(part.id)
|
||||
]
|
||||
|
||||
def add_campaign_participant(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue