Archived
Some game actions work
This commit is contained in:
@@ -81,11 +81,19 @@ class ClientController(ClientControllerInterface):
|
||||
if self.player.team != self.game_controller.game.turn:
|
||||
return await self.send_error("it is not your turn to play!")
|
||||
if message.type == "action":
|
||||
print("message.data_type")
|
||||
if message.data_type == "buy":
|
||||
for c in message.data:
|
||||
await self.player.buy_card(c)
|
||||
## TODO : pydantic type check for message.data
|
||||
await self.player.buy_cards(message.data)
|
||||
elif message.data_type == "play_cards":
|
||||
await self.player.play_cards(message.data)
|
||||
elif message.data_type == "discard":
|
||||
await self.player.discard_cards(message.data)
|
||||
elif message.data_type == "draw":
|
||||
await self.player.draw(message.data)
|
||||
elif message.data_type == "end_turn":
|
||||
|
||||
await self.player.end_turn()
|
||||
|
||||
@vibe_check(LoginMessage)
|
||||
async def login_context(self, message: LoginMessage):
|
||||
@@ -149,4 +157,3 @@ class ClientController(ClientControllerInterface):
|
||||
self.player.ready = bool(message.data)
|
||||
if all(p.ready for p in self.game_controller.game.players):
|
||||
await self.game_controller.start_game()
|
||||
self.on_message = self.game_context
|
||||
|
||||
@@ -106,6 +106,8 @@ class GameController(GameControllerInterface):
|
||||
|
||||
async def start_game(self):
|
||||
await self.game.start_game()
|
||||
for c in self.clients:
|
||||
c.on_message = c.game_context
|
||||
await self.broadcast(
|
||||
Message(type="context", data_type="game_context_id", data="game")
|
||||
)
|
||||
|
||||
@@ -5,6 +5,8 @@ from model import Card, Serializable
|
||||
class BoardCard(Serializable):
|
||||
"""Represents a card on a player's board during a game turn"""
|
||||
|
||||
card: Card
|
||||
|
||||
def __init__(self, card: Card):
|
||||
super().__init__()
|
||||
self.card = card
|
||||
|
||||
@@ -189,3 +189,8 @@ class Game(Serializable):
|
||||
+ " players : "
|
||||
+ ", ".join([p.username for p in self.players])
|
||||
)
|
||||
|
||||
async def end_turn(self):
|
||||
team_index = self.teams.index(self.turn)
|
||||
self.turn = self.teams[(team_index + 1) % len(self.teams)]
|
||||
await self.notify_controller("update", self.serialize_guest())
|
||||
|
||||
+50
-24
@@ -115,10 +115,30 @@ class Player(Serializable):
|
||||
self.hand.remove(card)
|
||||
await self.notify_update()
|
||||
|
||||
async def discard_card(self, cards_ids: List[str]):
|
||||
pass
|
||||
async def discard_cards(self, cards_ids: List[str]):
|
||||
for s in cards_ids:
|
||||
card = next(
|
||||
(m for m in self.hand if str(m.uuid) == s),
|
||||
None,
|
||||
)
|
||||
if card is not None:
|
||||
self.discard_pile.append(card)
|
||||
self.hand.remove(card)
|
||||
else:
|
||||
board_card = next(
|
||||
(m for m in self.board if str(m.card.uuid) == s),
|
||||
None,
|
||||
)
|
||||
if board_card is not None:
|
||||
self.discard_pile.append(board_card.card)
|
||||
self.board.remove(board_card)
|
||||
else:
|
||||
print("Card not found in board or hand")
|
||||
continue
|
||||
await self.notify_update()
|
||||
|
||||
async def end_turn(self):
|
||||
temp_board = [*self.board]
|
||||
for c in self.board:
|
||||
if c.card.card_type in [
|
||||
CardType.HERO,
|
||||
@@ -127,44 +147,50 @@ class Player(Serializable):
|
||||
]:
|
||||
c.reset()
|
||||
else:
|
||||
self.board.remove(c)
|
||||
temp_board.remove(c)
|
||||
self.discard_pile.append(c.card)
|
||||
|
||||
self.board = temp_board
|
||||
|
||||
for c in self.hand:
|
||||
self.hand.remove(c)
|
||||
self.discard_pile.append(c)
|
||||
self.hand = []
|
||||
|
||||
await self.draw(5)
|
||||
await self.game.end_turn()
|
||||
|
||||
async def buy_card(self, card_id: str):
|
||||
card = next(
|
||||
(
|
||||
m
|
||||
for m in [f for f in self.game.market if f is not None]
|
||||
if str(m.uuid) == card_id
|
||||
),
|
||||
None,
|
||||
)
|
||||
if card is not None:
|
||||
index = self.game.market.index(card)
|
||||
self.game.market[index] = None
|
||||
self.discard_pile.append(card)
|
||||
await self.game.distribute_market_cards()
|
||||
else:
|
||||
async def buy_cards(self, card_ids: List[str]):
|
||||
for card_id in card_ids:
|
||||
card = next(
|
||||
(
|
||||
m
|
||||
for m in [f for f in self.game.gem_stack if f is not None]
|
||||
for m in [f for f in self.game.market if f is not None]
|
||||
if str(m.uuid) == card_id
|
||||
),
|
||||
None,
|
||||
)
|
||||
if card is not None:
|
||||
self.game.gem_stack.remove(card)
|
||||
index = self.game.market.index(card)
|
||||
self.game.market[index] = None
|
||||
self.discard_pile.append(card)
|
||||
await self.game.notify_controller("update", self.game.serialize_guest())
|
||||
await self.game.distribute_market_cards()
|
||||
else:
|
||||
print("Card not found in market or gem_stack")
|
||||
return
|
||||
card = next(
|
||||
(
|
||||
m
|
||||
for m in [f for f in self.game.gem_stack if f is not None]
|
||||
if str(m.uuid) == card_id
|
||||
),
|
||||
None,
|
||||
)
|
||||
if card is not None:
|
||||
self.game.gem_stack.remove(card)
|
||||
self.discard_pile.append(card)
|
||||
await self.game.notify_controller(
|
||||
"update", self.game.serialize_guest()
|
||||
)
|
||||
else:
|
||||
print("Card not found in market or gem_stack")
|
||||
continue
|
||||
|
||||
await self.notify_update()
|
||||
|
||||
Reference in New Issue
Block a user