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