Small fixes for playtesting

This commit is contained in:
2024-04-26 16:07:57 +02:00
parent be993fd1be
commit 0487576a60
6 changed files with 104 additions and 33 deletions
+5 -2
View File
@@ -126,8 +126,11 @@ class ClientController:
case "heal":
return await self.player.turn.heal(message.data)
case "damage":
return await self.player.turn.damage(message.data)
case "damage_team":
return await self.player.turn.damage_team(message.data)
case "damage_champion":
return await self.player.turn.damage_champion(message.data)
case "end_turn":
return await self.player.turn.end_turn()
+32 -15
View File
@@ -1,7 +1,7 @@
from json import JSONDecodeError
from pathlib import Path
from pydantic import BaseModel, ValidationError
from typing import List, Dict
from typing import List, Dict, Optional
from model.card_validator import CardParser, EffectParser
from model.card import Effect, Card
@@ -42,14 +42,21 @@ def create_card(card: CardParser, effects: List[Effect]) -> Card:
)
def create_card_effects(card: CardParser) -> List[Effect]:
def create_card_effects(
card: CardParser, all_effects: Optional[List[Effect]] = None
) -> (List[Effect], List[Effect]):
if all_effects is None:
all_effects: List[Effect] = []
combined: List[Effect] = []
mutexes: Dict[int, List[Effect]] = {}
for mutex in set([c.mutex for c in card.effects if c.mutex is not None]):
mutexes[mutex] = []
for effect in card.effects:
real_effect = create_effect(effect)
real_effect, sub_effects = create_effect(effect)
for e in sub_effects:
all_effects.append(e)
all_effects.append(real_effect)
combined.append(real_effect)
if effect.mutex in mutexes:
mutexes[effect.mutex].append(real_effect)
@@ -58,29 +65,39 @@ def create_card_effects(card: CardParser) -> List[Effect]:
if effect.mutex in mutexes:
combined[index].mutex = mutexes[effect.mutex]
return combined
return combined, all_effects
def create_effect(effect: EffectParser) -> Effect:
def create_effect(
effect: EffectParser, all_effects: Optional[List[Effect]] = None
) -> (Effect, List[Effect]):
if all_effects is None:
all_effects: List[Effect] = []
sub_effects: List[Effect] = []
mutexes: Dict[int, List[Effect]] = {}
for mutex in set([c.mutex for c in effect.sub_effects if c.mutex is not None]):
mutexes[mutex] = []
for s in effect.sub_effects:
real_effect = create_effect(s)
real_effect, all_effects2 = create_effect(s, all_effects)
for e in all_effects2:
all_effects.append(e)
all_effects.append(real_effect)
sub_effects.append(real_effect)
if s.mutex in mutexes:
mutexes[s.mutex].append(real_effect)
for index, effect in enumerate(effect.sub_effects):
if effect.mutex in mutexes:
sub_effects[index].mutex = mutexes[effect.mutex]
for index, s in enumerate(effect.sub_effects):
if s.mutex in mutexes:
sub_effects[index].mutex = mutexes[s.mutex]
return Effect(
effect=effect.effect,
amount=effect.amount,
effect_type=effect.effect_type,
sub_effects=sub_effects,
times=effect.times,
return (
Effect(
effect=effect.effect,
amount=effect.amount,
effect_type=effect.effect_type,
sub_effects=sub_effects,
times=effect.times,
),
all_effects,
)
+1
View File
@@ -54,6 +54,7 @@ class EffectTimes(str, Enum):
PER_OTHER_CHAMPION = "per_other_champion"
PER_OTHER_GUARD = "per_other_guard"
PER_CARD_OF_SAME_FACTION = "per_card_of_same_faction"
PER_OTHER_CARD_OF_SAME_FACTION = "per_other_card_of_same_faction"
class EffectType(str, Enum):
+2 -2
View File
@@ -47,8 +47,8 @@ class Game(Serializable):
await self.distribute_market_cards()
async def instanciate_card(self, card_parser: CardParser) -> Card:
effects = create_card_effects(card_parser)
for e in effects:
effects, card_effects = create_card_effects(card_parser)
for e in card_effects:
self.effects.append(e)
await self.notify_controller("create", e.serialize())
card = create_card(card_parser, effects)
+2 -2
View File
@@ -83,7 +83,7 @@ class Player(Serializable):
random.shuffle(self.stack_pile)
async def start_turn(self):
self.turn.start_turn()
await self.turn.start_turn()
async def end_turn(self):
temp_board = [*self.board]
@@ -251,7 +251,7 @@ class Player(Serializable):
for p in self.game.players:
if p.team == self.team:
continue
card = self.game.search_card_in_pile(card.id, p.board)
card = self.game.search_card_in_pile(card_id, p.board)
if card is None:
continue
else:
+62 -12
View File
@@ -12,6 +12,7 @@ from model import (
CardEffects,
EffectType,
EffectTimes,
Team,
)
@@ -40,7 +41,7 @@ class Turn(Serializable):
self.damage_reserve = 0
self.heal_reserve = 0
self.gold_reserve = 0
self.champions_health: Dict[UUID, int] = {}
self.champions_health: Dict[str, int] = {}
self.effects_availables: List[Effect] = []
self.cards_locked: List[Card] = []
self.discard_markers = 0
@@ -75,6 +76,10 @@ class Turn(Serializable):
for c in self.player.board:
if c.faction == card.faction:
self.effects_availables.append(effect)
case EffectTimes.PER_OTHER_CARD_OF_SAME_FACTION:
for c in self.player.board:
if c.faction == card.faction and c != card:
self.effects_availables.append(effect)
case EffectTimes.PER_CHAMPION:
for c in self.player.board:
if c.card_role == CardType.CHAMPION:
@@ -100,19 +105,21 @@ class Turn(Serializable):
await self.player.game.notify_controller("update", self.serialize())
def discard_card(self, card_id: str):
async def discard_card(self, card_id: str):
if self.discard_markers <= 0:
return print("You don't have any discard markers!")
card = self.player.game.search_card_in_pile(card_id, self.cards_locked)
if card is not None:
return print("Cannot discard: card is locked")
return self.player.discard_card(card_id)
self.discard_markers -= 1
await self.player.game.notify_controller("update", self.serialize())
return await self.player.discard_card(card_id)
def sacrifice_card(self, card_id: str):
card = self.player.game.search_card_in_pile(card_id, self.cards_locked)
if card is not None:
return print("Cannot sacrifice : card is locked")
return self.player.discard_card(card_id)
return self.player.sacrifice_card(card_id)
async def use_effect_with_check(self, effect_id: str, target: Optional[str]):
if self.discard_markers > 0:
@@ -177,7 +184,9 @@ class Turn(Serializable):
self.effects_availables.remove(effect)
for e in effect.sub_effects:
self.effects_availables.append(e)
for _ in range(e.amount):
self.effects_availables.append(e)
print([str(e.uuid) for e in self.effects_availables])
await self.player.game.notify_controller("update", self.serialize())
async def use_effect(self, effect_id: str, target: str):
@@ -193,13 +202,13 @@ class Turn(Serializable):
match effect.effect:
case CardEffects.GOLD:
self.gold_reserve += effect.amount
self.gold_reserve += 1
success = True
case CardEffects.DAMAGE:
self.damage_reserve += effect.amount
self.damage_reserve += 1
success = True
case CardEffects.HEAL:
self.heal_reserve += effect.amount
self.heal_reserve += 1
success = True
case CardEffects.PERPARE:
success = self.prepare(target)
@@ -246,10 +255,12 @@ class Turn(Serializable):
self.effects_availables.append(e)
return True
def start_turn(self) -> None:
async def start_turn(self) -> None:
self.champions_health = {}
for c in self.player.board:
if c.card_type == CardType.CHAMPION:
self.champions_health[c.uuid] = c.defense
self.champions_health[str(c.uuid)] = c.defense
await self.player.game.notify_controller("update", self.serialize())
def serialize(self):
data = super().serialize() | {
@@ -268,7 +279,7 @@ class Turn(Serializable):
print("card is not a champion")
return False
else:
return await self.player.put_on_stack_from_discard(self, card)
return await self.player.put_on_stack_from_discard(card)
async def stack_next_card_bought_check(self, card: Card) -> bool:
@@ -314,7 +325,16 @@ class Turn(Serializable):
await self.player.game.notify_controller("update", self.serialize())
await self.player.game.notify_controller("update", self.player.team.serialize())
async def damage(self, target: str):
def check_for_guard(self, team: "Team"):
for p in self.player.game.players:
if p.team != team:
continue
for c in p.board:
if c.guard == True:
return True
return False
async def damage_team(self, target: str):
team = next(
(t for t in self.player.game.teams if str(t.uuid) == target),
None,
@@ -323,9 +343,39 @@ class Turn(Serializable):
return print("team not found")
if team == self.player.team:
return print("KYS!")
if self.check_for_guard(team):
return print("You cannot attack this team if a guard is present")
if self.damage_reserve > 0:
self.damage_reserve -= 1
team.health -= 1
await self.player.game.notify_controller("update", self.serialize())
await self.player.game.notify_controller("update", team.serialize())
async def damage_champion(self, target: str):
if self.damage_reserve <= 0:
print("No damage left to attack")
return
for p in self.player.game.players:
if self.player.team == p.team:
continue
for c in p.board:
if str(c.uuid) != target:
continue
if c.card_type != CardType.CHAMPION:
continue
if not c.guard and self.check_for_guard(p.team):
print("You cannot attack this champion if a guard is present")
return
self.damage_reserve -= 1
p.turn.champions_health[str(c.uuid)] -= 1
if p.turn.champions_health[str(c.uuid)] <= 0:
await self.player.stun(c.uuid)
await self.player.game.notify_controller("update", self.serialize())
await self.player.game.notify_controller("update", p.turn.serialize())
return
print("card not found")