async def endPlus4(self, player, card) -> str: ''' Plays the given colored plus 4. If stacking is enabled, then it is added to.\n Also checks if the next player can add to the stack. If they cannot, then the stack is closed via stack.endStack().\n #### Assumes that the card is valid and that playCardGeneric NOT was already run.\n Parameters: - player: Player; The player playing the card - card: Card; The card being played\n Returns: str; The status message of the player drawing cards ''' rules = getRules(self.channelID) user = await client.fetch_user(player.playerID) self.currentCard = card self.incrementTurn() if not rules["stacking"]: currentPlayer = self.players[self.turnIndex] currentUser = await client.fetch_user(currentPlayer.playerID) self.player.drawCard(count=4, drawToMatch=False, canPlay=False) self.incrementTurn() statusMessage = f"{user.name} chose {card.color}, and {currentUser.name} drew 4 cards" else: #Do stack stuff currentPlayer = self.players[self.turnIndex] currentUser = await client.fetch_user(currentPlayer.playerID) print("Can stack? " + str(self.stack.canStack(currentPlayer))) if self.stack.canStack(currentPlayer): messageClasses.StackMessage(currentPlayer, self) await currentPlayer.stackMessage.sendMessage() statusMessage = f"{currentUser.name} started a stack!" else: await self.stack.endStack() statusMessage = f"{currentUser.name} drew {self.stack.amount} cards" return statusMessage
async def startPlus4(self, player, card) -> str: ''' Plays the given plus 4. If stacking is enabled and no stack is found, then a new one is started. If a stack is found, then it is added to.\n Also checks if the next player can add to the stack. If they cannot, then the stack is closed via stack.endStack().\n #### Assumes that the card is valid and that playCardGeneric NOT was already run.\n Parameters: - player: Player; The player playing the card - card: Card; The card being played\n Returns: str; The status message of the player choosing a color ''' rules = getRules(self.channelID) user = await client.fetch_user(player.playerID) player.hand.remove(card) self.deck.returnCard( self.currentCard) #Returns the top card to the deck self.currentCard = card if len(player.hand) == 0: await self.gameWon(player) return messageClasses.Plus4Message(player=player, game=self) client.loop.create_task(player.handMessage.updateMessage(amount=0)) client.loop.create_task(player.wildMessage.sendMessage()) statusMessage = f"{user.name} is choosing a color" #TODO - If card is a plus card, check stack rule then start stack, or if source is stack then add to the current stack if self.stackActive: self.stack.addStack(card) elif rules["stacking"]: self.stack = Stack(self) self.stack.startStack(card) return statusMessage
def cardsEmbed(self): rules = getRules(self.game.channelID) if rules["drawToMatch"]: if rules["forceplay"]: description = f"You were forced to play {self.cards[-1].emoji}" else: description = f"Would you like to play {self.cards[-1].emoji}?" embed = discord.Embed(title = f"You drew {len(self.cards)} cards", description = description, color = 4802889) embed.add_field(name = "Cards:", value = "".join([card.emoji for card in self.cards])) else: description = self.cards[0].emoji embed = discord.Embed(title = f"You drew a card", description = description, color = 4802889) return embed
async def start(self): #Create hand for player i = 0 while i < getRules(self.game.channelID)["startingCards"]: self.hand.append(self.game.deck.drawCard()) i += 1 user = await client.fetch_user(self.playerID ) #Get the user from discord gameMessage = await user.send(embed=await self.game.gameStateEmbed( isDM=True, player=self, statusMessage="Game started")) #Send the user the game message self.gameMessageID = gameMessage.id #Set the players game message ID self.handMessage = messageClasses.HandMessage(self, self.game) await self.handMessage.sendMessage() self.game.playerStartedCount += 1
async def drawCard(self): if not self.game.players[self.game.turnIndex].playerID == self.player.playerID: client.loop.create_task(GenericMessage("It's not your turn.", self.player).sendMessage()) return rules = getRules(self.game.channelID) if self.player.drewCard == True: #Stop if the player has already drawn a card before they play a card statusMessage = await self.game.passTurn(player = self.player) await self.game.updateGameMessages(statusMessage) return if rules["drawToMatch"]: #If draw to match rule is on await self.player.drawCard(count = 0, drawToMatch = True) else: await self.player.drawCard(count = 1, drawToMatch = False) self.player.drewCard = True
async def playPlus2(self, card) -> str: ''' Plays the given plus 2. If stacking is enabled and no stack is found, then a new one is started. If a stack is found, then it is added to.\n Also checks if the next player can add to the stack. If they cannot, then the stack is closed via stack.endStack().\n #### Assumes that the card is valid and that playCardGeneric was already run.\n Parameters: - card: Card; The card being played\n Returns: str; The status message of the player drawing cards ''' rules = getRules(self.channelID) if not rules["stacking"]: #If stacking is off currentPlayer = self.players[self.turnIndex] currentUser = await client.fetch_user(currentPlayer.playerID) self.player.drawCard( client, count=2, drawToMatch=False, canPlay=False) #Make the current player draw 2 cards self.incrementTurn() #Then skip their turn statusMessage = f"{currentUser.name} drew 2 cards" else: #Do stack stuff if self.stackActive: #If a stack is already running self.stack.addStack(card) #Add to it else: self.stack = Stack(self) #Create a new stack self.stack.startStack(card) #Start the stack currentPlayer = self.players[self.turnIndex] currentUser = await client.fetch_user(currentPlayer.playerID) print("Can stack? " + str(self.stack.canStack(currentPlayer))) if self.stack.canStack(currentPlayer): messageClasses.StackMessage(currentPlayer, self) await currentPlayer.stackMessage.sendMessage() statusMessage = f"{currentUser.name} started a stack!" else: await self.stack.endStack() statusMessage = f"{currentUser.name} drew {self.stack.amount} cards" return statusMessage
async def sendMessage(self, canPlay = True): self.player.state = "draw" self.canPlay = canPlay rules = getRules(self.game.channelID) user = await client.fetch_user(self.userID) message = await user.send(embed = self.cardsEmbed()) self.messageID = message.id reactionMessageIDs[self.messageID] = self if rules["drawToMatch"] and canPlay: if not rules["forceplay"]: client.loop.create_task(message.add_reaction("✅")) client.loop.create_task(message.add_reaction("❎")) client.loop.create_task(self.autoDismiss()) self.canPlay = True else: self.playCard() client.loop.create_task(message.add_reaction("❎")) client.loop.create_task(self.autoDismiss()) self.canPlay = False else: client.loop.create_task(message.add_reaction("❎")) client.loop.create_task(self.autoDismiss()) self.canPlay = False await self.player.handMessage.updateMessage(0)