def and_repeat(roll, num_repeats, author_id): first_roll = dice.roll(roll) # Cover these cases in the 1st roll since we'll get the same for the 2nd if first_roll == "too high": return TOO_HIGH.format(author_id=author_id) elif first_roll == "wrong": return WRONG.format(author_id=author_id) list_of_rolls = [first_roll] for _ in range(num_repeats - 1): list_of_rolls.append(dice.roll(roll)) main_rolls, ending = gen_utils.format_repeated_rolls(list_of_rolls) outputs = ([f"<@{author_id}>'s Roll:", "```fix", f"You rolled {roll}."] + main_rolls + ["```" + ending]) return "\n".join(outputs)
def normally(roll, author_id): roll = dice.roll(roll) if roll == "too high": return TOO_HIGH.format(author_id=author_id) elif roll == "wrong": return WRONG.format(author_id=author_id) else: return f"<@{author_id}>'s Roll:\n```fix\nYou rolled a {roll['user_roll']}.\nYou got: \n{gen_utils.format_rolls(roll['rolls'])}\nYour modifier is: {str(roll['modifier'])}```Your total roll is: **{str(roll['total'])}**"
def play(self, dice): method = input('which method you chooese? 1.card 2.dice') if method == 1: pass elif method == 2: moveSteps = dice.roll(1) return self.direction*moveSteps
def with_advantage_or_disadvantage(roll, advantage_or_disadvantage, author_id): first_roll = dice.roll(roll) # Cover these cases in the 1st roll since we'll get the same for the 2nd if first_roll == "too high": return TOO_HIGH.format(author_id=author_id) elif first_roll == "wrong": return WRONG.format(author_id=author_id) second_roll = dice.roll(roll) base_string = f"<@{author_id}>:\n Attempt 1:\n```fix\nYou rolled a {first_roll['user_roll']}.\nYou got: \n{gen_utils.format_rolls(first_roll['rolls'])}\nYour modifier is: {str(first_roll['modifier'])}\nYour total roll is: {str(first_roll['total'])}```Attempt 2:\n```fix\nYou rolled a {second_roll['user_roll']}.\nYou got: \n{gen_utils.format_rolls(second_roll['rolls'])}\nYour modifier is: {str(second_roll['modifier'])}\nYour total roll is: {str(second_roll['total'])}```" if advantage_or_disadvantage == "a": return ( base_string + f"Your final roll is: **{max(first_roll['total'], second_roll['total'])}**." ) else: return ( base_string + f"Your final roll is: **{min(first_roll['total'], second_roll['total'])}**." )
def player_order(): order_of_game = [] tmp = [] for i in players: die = dice.roll(i) order_of_game.append([sum(die), i]) return list(reversed(sorted(order_of_game))) # def player_options():
async def roll_initiative(context, npc_count=None, npc_name_template=None): roll_initiative_message = await context.send( f"React with 👍 to add to the initiative order or 🛑 to start rolling" ) await roll_initiative_message.add_reaction("👍") await roll_initiative_message.add_reaction("🛑") def check(reaction, user): return user != client.user count = 0 players_to_roll_for = set() server = context.guild.id if npc_count: npc_character_count = int(npc_count) npc_character_name = "NPC" if npc_name_template: npc_character_name = npc_name_template if len(npc_character_name) > 29: npc_character_name = npc_character_name[:30] if npc_character_count > 10: npc_character_count = 10 await context.send("Max of 10 NPC's allowed") for i in range(npc_character_count): players_to_roll_for.add(f"{npc_character_name} {i+1}") while count < 2: try: reaction, reaction_user = await client.wait_for( "reaction_add", timeout=60, check=check ) if str(reaction.emoji) == "👍": user = get_user_id(str(reaction_user.id)) current = users[server][user].get("active") if current: character_name = characters[current].get_name() players_to_roll_for.add(str(character_name)) else: players_to_roll_for.add(str(reaction_user.name)) elif str(reaction.emoji) == "🛑": if reaction_user == context.author: count = 10 else: await context.send( f"Only <@{context.author.id}> can start the roll" ) except asyncio.TimeoutError: break if len(players_to_roll_for) != 0: roll_list = [] display_output = "Roll Order:\n```\n+------+----------------------------------+\n| Roll | Player Name |\n+------+----------------------------------+" for x in players_to_roll_for: result = {"player": x, "roll": dice.roll("1d20")["total"]} roll_list.append(result) for player_roll in sorted(roll_list, key=lambda x: x["roll"], reverse=True): roll = player_roll["roll"] player_name = player_roll["player"] if len(str(roll)) == 1: roll = f" {roll}" if len(player_name) < 32: for i in range(32 - len(player_name)): player_name += " " display_output += f"\n| {roll} | {player_name} |" await context.send( display_output + "\n+------+----------------------------------+```" ) else: await context.send("Thank you for wasting my time :)")
def turn(player, diceList: list): currentscore = 0 player.alive = True print( '\n\n###################################################################################\nTurn for' ) print(player) while player.alive: print('current score: ' + str(currentscore) + '\nDICE:') print(*diceList) #find Choices from first throw choices = findChoices(diceList) #no choices means bad luck turn over already if len(choices) == 0: print('BAD LUCK!\nNothing to save on this throw!\n') break #while choices available while len(choices): choices = findChoices(diceList) if choices[0][0] == 6: currentscore += choices[0][1] choices = [] continue playerPick = -1 while not -1 < playerPick < len(choices): playerPick = askPick(choices) #asking player for choice and removing same dice choice form choices numDice, score, face, choices = pick(playerPick, choices) #saving the choice score currentscore += score #setting dice to saved for element in diceList: if element.sideUp == face and numDice: numDice -= element.save(face) #if there are more choices ask player to pick another? while not playerPick == "y" and not playerPick == "n" and len( choices): playerPick = input('Do you want to pick another? (y/n): ') if playerPick == "y": continue elif playerPick == "n": break #counting number of free dice freeDice = sum(map(lambda dice: int(not dice.saved), diceList)) #no free dice means you HAVE to roll again (rules of the game) if not freeDice or freeDice == 6: print('Rolling 6 dice again!') diceList = [dice.rollSaved() for dice in diceList] #else the player can choose to stop and save, if player is on table or currentscore is over 1000 else: rollAgain = None print('player on table: ' + str(player.onTable())) print(int(currentscore)) if player.onTable() or currentscore > 999: while not rollAgain == "y" and not rollAgain == "n": rollAgain = input('Do you want to roll remaining ' + str(freeDice) + '? (y/n): ') else: print(player) print( 'Is not on table yet, and current score is less than 1000, have to roll again.\n' ) print('') if not rollAgain == "n": print('Rolling ' + str(freeDice) + ' again!') diceList = [dice.roll() for dice in diceList] else: break #turn done saving and showing results player.addScore(currentscore) print('turn done for ' + str(player)) #rolling for next player diceList = [dice.rollSaved() for dice in diceList]
from dice.dice import roll #because dice is a package print(roll()) print(roll()) print(roll())