async def status(self, ctx): if not self.ingame(ctx): return await ctx.send( "Uh oh! You friccin moron! You aren't in a game!") game = self.pdb[ctx.channel.id][ctx.author.id] if game.started == False: return await ctx.send( "Uh oh! You friccin moron! The game hasn't started yet!") return await ctx.send( file=discord.File(img.game_image(game), filename="board.png"))
async def inject(self, ctx, position, newpiece): if not self.ingame(ctx): return await ctx.send( "Uh oh! You friccin moron! You aren't in a game!") game = self.pdb[ctx.channel.id][ctx.author.id] pid = [i.id for i in game.players].index(ctx.author.id) if "debug" not in game.flags: return await ctx.send( "Uh oh! You friccin moron! This game is not debug enabled!") if game.started == False: return await ctx.send( "Uh oh! You friccin moron! The game hasn't started yet!") if pid != game.ply % 2: return await ctx.send( "Uh oh! You friccin moron! It's not your turn!") try: pos = self.convert_position(position.upper()) pos = (game.height - pos[0], pos[1]) except: return await ctx.send( "Uh oh! You friccin moron! Your position is invalid!") if not game.height > pos[0] >= 0 or not game.width > pos[1] >= 0: return await ctx.send( "Uh oh! You friccin moron! That position is out of bounds!") if game.board[pos[0]][pos[1]] is None: return await ctx.send( "Uh oh! You friccin moron! There's nothing on that square!") else: piece = game.board[pos[0]][pos[1]] #if piece.team != [-1, 1][pid]: # return await ctx.send("Uh oh! You friccin moron! That's not your piece!") if piece.team == -1: piece.move = mech.invert(mech.pieces[newpiece]) else: piece.move = mech.pieces[newpiece] await ctx.send( "Replaced the piece on {} (Previously {}) with {}".format( position, piece.name, newpiece)) piece.name = newpiece return await ctx.send( file=discord.File(img.game_image(game), filename="board.png"))
async def selfcreate(self, ctx, board_height: int, board_width: int, *, flags=""): if self.ingame(ctx): return await ctx.send( "Uh oh! You friccin moron! You're already in a game!") if not (20 >= board_height >= 4 and 20 >= board_width >= 4): return await ctx.send( "Uh oh! You friccin moron! Your dimensions must be in between four and twenty inclusive." ) try: self.pdb[ctx.channel.id][ctx.author.id] = (mech.Chesh(board_width, board_height, flags=flags)) except mech.FlagError: return await ctx.send( "Uh oh! You friccin moron! One of your flags was invalid!") game = self.pdb[ctx.channel.id][ctx.author.id] game.players.append(Player(ctx.author.id, True)) game.players.append(Player(ctx.author.id, False)) game.player_names = ["Player 1", "Player 2"] game.started = True game.selfgame = True await ctx.send("Game created!") m = await ctx.send( file=discord.File(img.game_image(game), filename="board.png")) game.urls.append(m.attachments[0].url) return m
async def join(self, ctx, user: str): if self.ingame(ctx): return await ctx.send( "Uh oh! You friccin moron! You're already in a game!") try: game = self.pdb[ctx.channel.id][ctx.message.mentions[0].id] except: return await ctx.send( "Uh oh! You friccin moron! That player doesn't have a game!") if len(game.players) == 2: return await ctx.send( "Uh oh! You friccin moron! This game has already started!") else: self.pdb[ctx.channel.id][ctx.author.id] = game game.players.append(Player(ctx.author.id, False)) game.player_names[1] = ctx.author.name game.started = True await ctx.send("You have joined " + user + "'s Game!") m = await ctx.send( file=discord.File(img.game_image(game), filename="board.png")) game.urls.append(m.attachments[0].url) return m
async def move(self, ctx, *positions): if not self.ingame(ctx): return await ctx.send( "Uh oh! You friccin moron! You aren't in a game!") game = self.pdb[ctx.channel.id][ctx.author.id] pid = [i.id for i in game.players].index(ctx.author.id) if game.selfgame: pid = game.ply % 2 if game.started == False: return await ctx.send( "Uh oh! You friccin moron! The game hasn't started yet!") if pid != game.ply % 2: return await ctx.send( "Uh oh! You friccin moron! It's not your turn!") try: positions = [self.convert_position(i.upper()) for i in positions] positions = [(game.height - i[0], i[1]) for i in positions] except: return await ctx.send( "Uh oh! You friccin moron! Your position is invalid!") for pos in positions: if not game.height > pos[0] >= 0 or not game.width > pos[1] >= 0: return await ctx.send( "Uh oh! You friccin moron! That position is out of bounds!" ) pl = game.position_lists(game.selected_piece, game.valid_moves) if positions not in pl: return await ctx.send( "Uh oh! You friccin moron! That move is not legal!") else: current_pos = game.selected_piece for p in positions: target = game.board[p[0]][p[1]] if target is not None: health_index = [0, 1, 0][target.team] if target.royal: game.healths[health_index] = max( 0, game.healths[health_index] - game.royal_value) else: game.healths[health_index] = max( 0, game.healths[health_index] - game.common_value) game.board[p[0]][p[1]] = game.board[current_pos[0]][ current_pos[1]] game.board[current_pos[0]][current_pos[1]] = None current_pos = p pc = game.board[current_pos[0]][current_pos[1]] pc.fatigue += game.fatigue_increment if pc.fatigue == game.max_fatigue: await ctx.send("**Your piece died due to fatigue!**") game.board[current_pos[0]][current_pos[1]] = None health_index = [0, 1, 0][pc.team] if pc.royal: game.healths[health_index] = max( 0, game.healths[health_index] - game.royal_value) else: game.healths[health_index] = max( 0, game.healths[health_index] - game.common_value) game.selected_piece = None game.valid_moves = [] game.ply += 1 game.turn = (game.turn + 1) % 2 await ctx.send("Piece Moved!") m = await ctx.send( file=discord.File(img.game_image(game), filename="board.png")) game.urls.append(m.attachments[0].url) if 0 in game.healths: for i in game.players: self.pdb[ctx.channel.id].pop(i.id, None) return await ctx.send( file=discord.File(img.game_gif(game), filename="game.gif"))
async def select(self, ctx, position): if not self.ingame(ctx): return await ctx.send( "Uh oh! You friccin moron! You aren't in a game!") game = self.pdb[ctx.channel.id][ctx.author.id] pid = [i.id for i in game.players].index(ctx.author.id) if game.started == False: return await ctx.send( "Uh oh! You friccin moron! The game hasn't started yet!") if game.selfgame: pid = game.ply % 2 if pid != game.ply % 2: return await ctx.send( "Uh oh! You friccin moron! It's not your turn!") try: pos = self.convert_position(position.upper()) pos = (game.height - pos[0], pos[1]) except: return await ctx.send( "Uh oh! You friccin moron! Your position is invalid!") if not game.height > pos[0] >= 0 or not game.width > pos[1] >= 0: return await ctx.send( "Uh oh! You friccin moron! That position is out of bounds!") if game.selected_piece is not None: return await ctx.send( "You can't select another piece! Move the one you've already selected!" ) if game.board[pos[0]][pos[1]] is None: return await ctx.send( "Uh oh! You friccin moron! There's nothing on that square!") else: for i in range(len(game.board)): for j in range(len(game.board[i])): p = game.board[i][j] if p is not None: if p.team == [-1, 1][pid] and pos != (i, j): p.fatigue = max(0, p.fatigue - game.fatigue_increment) piece = game.board[pos[0]][pos[1]] if piece.team != [-1, 1][pid]: return await ctx.send( "Uh oh! You friccin moron! That's not your piece!") game.selected_piece = pos game.valid_moves = piece.move(pos, game.board) m = await ctx.send( file=discord.File(img.game_image(game), filename="board.png")) game.urls.append(m.attachments[0].url) return m