card locking and event triggering WIP fix

This commit is contained in:
2024-04-25 00:33:02 +02:00
parent 8b397484cb
commit 898e58399e
4 changed files with 31 additions and 25 deletions
+1 -1
View File
@@ -117,7 +117,7 @@ class ClientController:
case "use_effect":
return await self.player.turn.use_effect(
message.data.effect_id, message.data.target
message.data.get("effect_id"), message.data.get("target")
)
case "buy":
+1 -1
View File
@@ -168,7 +168,7 @@ class Game(Serializable):
team_index = self.teams.index(self.current_turn)
self.current_turn = self.teams[(team_index + 1) % len(self.teams)]
for p in self.players:
p.start_turn()
await p.start_turn()
await self.notify_controller("update", self.serialize_guest())
def search_card_in_pile(self, card_id: str, pile: List[Card]):
+7 -8
View File
@@ -88,14 +88,13 @@ class Player(Serializable):
async def end_turn(self):
temp_board = [*self.board]
for c in self.board:
for c in self.board:
if c.card_type not in [
CardType.HERO,
CardType.HERO_ABILITY,
CardType.CHAMPION,
]:
temp_board.remove(c)
self.discard_pile.append(c)
if c.card_type not in [
CardType.HERO,
CardType.HERO_ABILITY,
CardType.CHAMPION,
]:
temp_board.remove(c)
self.discard_pile.append(c)
self.board = temp_board
+22 -15
View File
@@ -45,7 +45,7 @@ class Turn(Serializable):
self.cards_locked: List[Card] = []
self.discard_markers = 0
def end_turn(self) -> None:
async def end_turn(self) -> None:
"""Resets card champion health and card effects"""
if len(self.player.hand) > 0:
return print("You must play all your cards before ending a turn!")
@@ -56,9 +56,10 @@ class Turn(Serializable):
self.effects_availables = []
self.cards_locked = []
self.discard_markers = 0
self.player.end_turn()
await self.player.game.notify_controller("update", self.serialize())
await self.player.end_turn()
def lock_card(self, card_id: str):
async def lock_card(self, card_id: str):
if self.discard_markers > 0:
return print("You cannot lock a card while having discard markers")
card = self.player.game.search_card_in_pile(card_id, self.player.board)
@@ -97,6 +98,8 @@ class Turn(Serializable):
"EffectTimes " + effect.times + " not implemented"
)
await self.player.game.notify_controller("update", self.serialize())
def discard_card(self, card_id: str):
if self.discard_markers <= 0:
return print("You don't have any discard markers!")
@@ -122,7 +125,7 @@ class Turn(Serializable):
return print("Effect not available")
card = next(
(m for m in self.player.board if effect in m),
(m for m in self.player.board if effect in m.effects),
None,
)
if card is None:
@@ -134,7 +137,7 @@ class Turn(Serializable):
match effect.effect_type:
case EffectType.SUICIDE:
success = False
success = self.player.sacrifice_card(card.uuid)
success = await self.player.sacrifice_card(str(card.uuid))
if not success:
return print("something went wrong while trying to suicide a card")
for e in card.effects:
@@ -158,16 +161,16 @@ class Turn(Serializable):
success = False
match effect.effect_type:
match effect.effect:
case CardEffects.GOLD:
self.gold_reserve += effect.amount
success = False
self.gold_reserve += 1
success = True
case CardEffects.DAMAGE:
self.damage_reserve += effect.amount
success = False
self.damage_reserve += 1
success = True
case CardEffects.HEAL:
self.heal_reserve += effect.amount
success = False
self.heal_reserve += 1
success = True
case CardEffects.PERPARE:
success = await self.prepare(target)
case CardEffects.STUN:
@@ -192,6 +195,9 @@ class Turn(Serializable):
case CardEffects.PLAY_NEXT_CARD_BOUGHT:
success = await self.buy_card(target, self.player.buy_in_hand)
case _:
raise NotImplementedError(
"CardEffect " + effect.effect + " not implemented"
)
return
if not success:
@@ -200,7 +206,7 @@ class Turn(Serializable):
self.effects_availables.remove(effect)
for e in effect.sub_effects:
self.effects_availables.append(e)
self.player.game.notify_controller("update", self.serialize())
await self.player.game.notify_controller("update", self.serialize())
def prepare(self, card_id: str) -> bool:
card = next(
@@ -248,7 +254,7 @@ class Turn(Serializable):
print("Not enough gold to buy card!")
return False
return self.player.buy_on_stack(card)
return await self.player.buy_on_stack(card)
async def buy_card(
self, card_id: str, buy_function: Optional[Callable[[Card], bool]] = None
@@ -268,8 +274,9 @@ class Turn(Serializable):
print("Not enough gold to buy card!")
return False
if buy_function(card):
if await buy_function(card):
self.gold_reserve -= card.cost
await self.player.game.notify_controller("update", self.serialize())
return True
return False