def command_roll(message): num = message.text.split(' ') if len(num) == 1: my_roll = functions.roll() bot.reply_to(message, my_roll) elif len(num) == 2: num = num[-1] my_roll = functions.roll(int(num)) bot.reply_to(message, my_roll) else: bot.reply_to(message, 'Invalid syntax! Try: "/roll {number}"')
def parse_input(inputstr): """ Parse the input """ word_list = inputstr.split() if word_list[0] == 'roll': functions.roll(word_list[1:]) elif word_list[0] == 'search': api.search(word_list[1:]) elif word_list[0] == 'load': return functions.load_char(word_list[1:])
def attack(self, enemy): best_weapon = None max_dmg = 0 for i in self.inventory: if isinstance(i, items.Weapon): if i.damage > max_dmg: max_dmg = i.damage best_weapon = i attack_roll = sum(roll(1, 20)) + self.str_mod attack_roll = attack_roll + 5 if self.godmode else attack_roll print('') print(f"You attack {enemy.name} with your {best_weapon.name}.") if attack_roll > 10: damage = best_weapon.damage + self.str_mod print(f"You inflict {damage} units of drainage upon the creature!") enemy.hp -= best_weapon.damage if not enemy.is_alive(): if not self.godmode: print(f"You have murdered {enemy.name}.") self.level += random.randint(1, 40) xp = random.randint(1, 1000) print("gained {}XP".format(xp)) self.xp += xp print("LEVEL UP!") else: print(f"You have freed {enemy.name} from its mortal coil.") else: print( f"{enemy.name}'s wellness deteriorates to {enemy.hp} vitality units." ) else: print("You missed!") print('')
def determine_ability_scores(self, method): #Sets ability scores by either 4d6 drop lowest method or by the standard array in random order self.abilities = { "Strength": 0, "Dexterity": 0, "Constitution": 0, "Charisma": 0, "Intelligence": 0, "Wisdom ": 0 } if method == "roll": for i in self.abilities: scores = roll(4, 6) scores.sort() scores = scores[1::] self.abilities[i] = sum(scores) elif method == "array": scores = [8, 10, 12, 13, 14, 15] for i in self.abilities: rand_index = random.randint(0, len(scores) - 1) self.abilities[i] = scores[rand_index] scores.pop(rand_index) #Add racial modifier # for i in self.abilities: # self.abilities[i] += self.race.abilities[i] for a in self.abilities: print(a, "\t", self.abilities[a], flush=True) time.sleep(0.05)
async def dice(self, ctx: commands.Context, a: Union[int, str, None], b: int = 0): """Roll a dice or provide custom range to get a random number""" if not a: await ctx.send(roll()) return if isinstance(a, str): if a == 'frantic': a, b = 84, 779 else: raise commands.BadArgument(f'Cannot use "{a}" as an argument.') await ctx.send(roll(a, b))
def main(): while True: choice = input("Do you want to register or login?") if choice == "register": functions.register() elif choice == 'login': print("Player 1 please login") player1 = functions.login() print("Player 2 please login") player2 = functions.login() Player1Roll = functions.roll(player1) Player2Roll = functions.roll(player2) functions.decisive(Player1Roll, Player2Roll, player1, player2) else: print('Wrong keyword, please try again.')
async def roll(ctx, roll="1d6"): roll_list = roll.strip().lower().split("d") f.log(ctx.message.author, ctx.message.content) try: roll, times = int(roll_list[0]), int(roll_list[1]) result = f.roll(roll, times) await ctx.send(result) except: await ctx.send("You did something stupid. Cut that out.")
def roll(self, simulation=False): print("\n\t\tRolling for {}\n".format(self._name)) this_turn = roll() print("You got %d, %d, %d, %d, %d" % this_turn) score = process_roll(self, this_turn, simulation) if self.get_score() == 0: if score > 500: self._score += score else: print("Get at least 500 to get on the board") else: self._score += score if self.__can__ == True: self.can_roll = False
def attacked(self,by,to,wep,hand=None): ar = by.strength / 4 dr = 0 bleed = False #Add bonuses based on weapon type #While we're here, calculate damage if wep in ['lhand','rhand']: action = ['punch','punches'] ar += by.skills['handtohand'] dam = functions.roll(1,by.skills['handtohand']) dr += by.skills['handtohand'] elif wep.category in ['knife','ssword']: action = ['stab','stabs'] bleed = True ar += by.skills['smallblades'] ar += wep.attack dam = functions.roll(1,by.skills['smallblades']) dam += functions.roll(1,wep.attack) if hand: handcon = (10-by.condition[hand[0]+'arm']) armcon = (10-by.condition[hand]) if armcon: var._c.log('Your %s hurts.' % words.translate[hand]) if handcon: var._c.log('Your %s hurts.' % (words.translate[hand[0]+'arm'])) dam -= armcon #Find defense rating if self.alert: dr += self.defense * 4 #Random number + roll n = random.randint(1,100) if ar+n > dr or self.alert == False: #Did we hit the target area? roll = random.randint(1,50) if roll >= self.accuracy[to]: pass else: _acc = dict(self.accuracy) del _acc[to] to = random.choice([a for a in _acc.iterkeys()]) #Subtract damage from armor if self.wearing[to]: dam -= functions.roll(1,self.wearing[to].defense - ((self.wearing[to].defense/2)*(not self.alert))) #Correct damage if dam <= 0: if by == var.player and self.wearing[to]: var._c.log('%s\'s %s absorbs your hit.' % (self.name[0],self.wearing[to].name)) #else: # var._c.log('You are unharmed.') return False if by == var.player: _dam = dam*float(self.multiplier[to]) var._c.log('You %s %s in the %s for %s damage.' % (action[0],self.name[0],words.translate[to],_dam)) if bleed: self.bleeding[to] = dam/2 self.condition[to] -= dam self.hp -= _dam else: _dam = dam*float(self.multiplier[to]) by.say('%s you in the %s for %s damage' % (action[1],words.translate[to],_dam),action=True) if bleed: self.bleeding[to] = dam/2 self.condition[to] -= dam self.hp -= _dam else: if self == var.player: var._c.log('You block %s\'s %s' % (by.name[0],action[0])) else: self.say('blocks your %s' % action[0],action=True)
def draw(): global player, actions, current_scene, can_attack, can_place_cards, redjob_activated, bluejob_activated, end_turn_img, turn, reroll_amount, \ bluetrap_lifespan, redtrap_lifespan, bot_graveyard_state, player_graveyard_state, player_mobster_field_state, bot_mobster_field_state, end_turn_img_highlight, \ play_card_img, play_card_img_highlight, attack_img, attack_img_highlight, background_colour_image, \ dice_white_1, dice_white_2, dice_white_3, dice_white_4, dice_white_5, dice_white_6, dice_red_1, dice_red_2, dice_red_3, dice_red_4, dice_red_5, dice_red_6, \ back_img, back_img_highlight, bot_deck, bot_held_mobster_cards, bot_held_trap_cards, bot_held_job_cards, bot_held_cards # Draws the background image(background_colour_image, 0, 0) # Loads in the correct board for the Bot, playerboard will be the physical board of his choosing if CardSelectorMaffia.current_card_page == "Blue_bot": image(loadImage("TutorialBotDesignFed.png"), 0, 0) if current_scene == "Attack" or current_scene == "Reroll" or current_scene == "Reroll2" or current_scene == "Safe Dice": if functions.white_dice == 1: image(dice_white_1, 0, 0) elif functions.white_dice == 2: image(dice_white_2, 0, 0) elif functions.white_dice == 3: image(dice_white_3, 0, 0) elif functions.white_dice == 4: image(dice_white_4, 0, 0) elif functions.white_dice == 5: image(dice_white_5, 0, 0) elif functions.white_dice == 6: image(dice_white_6, 0, 0) if functions.red_dice == 1: image(dice_red_1, 0, 0) elif functions.red_dice == 2: image(dice_red_2, 0, 0) elif functions.red_dice == 3: image(dice_red_3, 0, 0) elif functions.red_dice == 4: image(dice_red_4, 0, 0) elif functions.red_dice == 5: image(dice_red_5, 0, 0) elif functions.red_dice == 6: image(dice_red_6, 0, 0) # Scales the cards to the right sizes. scale(0.3) # Show that there are still cards in the Bot_Deck if len(bot_deck) > 0: image(loadImage("CardBackBlueSideWays.png"), 325, 2650) # Shows that there are cards in the graveyard if len(TutorialBot.bot_graveyard) > 0: image(loadImage("CardBackBlueSideWays.png"), 325, 1800) # Shows that there are cards in the bot his hands if len(bot_held_cards) > 0: x = 1727 y = -180 for i in range(len(bot_held_cards)): image(loadImage("CardBackBlue.png"), x, y) x = x + 210 # Shows the trap card on the field if len(TutorialBot.bot_trap_field_cards) > 0: image(loadImage("CardBackBlueSideWays.png"), 3260, 1380) # Shows the job card on the field if len(TutorialBot.bot_job_field_cards) > 0: image(loadImage("CardBackBlueSideWays.png"), 2080, 1380) # Loads in the correct board for the Bot, playerboard will be the physical board of his choosing if CardSelectorFed.current_card_page == "Red_bot": image(loadImage("TutorialBotDesignMafia.png"), 0, 0) if current_scene == "Attack" or current_scene == "Reroll" or current_scene == "Reroll2" or current_scene == "Safe Dice": if functions.white_dice == 1: image(dice_white_1, 0, 0) elif functions.white_dice == 2: image(dice_white_2, 0, 0) elif functions.white_dice == 3: image(dice_white_3, 0, 0) elif functions.white_dice == 4: image(dice_white_4, 0, 0) elif functions.white_dice == 5: image(dice_white_5, 0, 0) elif functions.white_dice == 6: image(dice_white_6, 0, 0) if functions.red_dice == 1: image(dice_red_1, 0, 0) elif functions.red_dice == 2: image(dice_red_2, 0, 0) elif functions.red_dice == 3: image(dice_red_3, 0, 0) elif functions.red_dice == 4: image(dice_red_4, 0, 0) elif functions.red_dice == 5: image(dice_red_5, 0, 0) elif functions.red_dice == 6: image(dice_red_6, 0, 0) # Scales the cards to the right sizes. scale(0.3) # Show that there are still cards in the Bot_Deck if len(bot_deck) > 0: image(loadImage("CardBackRedSideWays.png"), 325, 2650) # Shows that there are cards in the graveyard if len(TutorialBot.bot_graveyard) > 0: image(loadImage("CardBackRedSideWays.png"), 325, 1800) # Shows that there are cards in the bot his hands if len(bot_held_cards) > 0: x = 1727 y = -180 for i in range(len(bot_held_cards)): image(loadImage("CardBackRed.png"), x, y) x = x + 210 # Shows the trap card on the field if len(TutorialBot.bot_trap_field_cards) > 0: image(loadImage("CardBackRedSideWays.png"), 3260, 1380) # Shows the job card on the field if len(TutorialBot.bot_job_field_cards) > 0: image(loadImage("CardBackRedSideWays.png"), 2080, 1380) # Shows the mobster card(s) in the field if len(TutorialBot.bot_mobster_field_cards) > 0: x = 1913 y = 2350 for i in range(len(TutorialBot.bot_mobster_field_cards)): TutorialBot.bot_mobster_field_cards[i].display(x, y) x = x + 890 # Activates card effects functions.cardEffectActivator() # Checks player turn, if it is not the players turn than executes bot discission maker if player == 1: if current_scene == "Decissions": scale(3.333333333) functions.backgroundTint() if turn > 2 and can_attack == True: image(attack_img, 0, 0) if functions.isMouseWithinSpace2(552, 976, 238, 100): image(attack_img_highlight, 0, 0) if can_place_card == True: image(play_card_img, 0, 0) if functions.isMouseWithinSpace2(829, 973, 238, 100): image(play_card_img_highlight, 0, 0) image(end_turn_img, 0, 0) if functions.isMouseWithinSpace2(1114, 969, 238, 100): image(end_turn_img_highlight, 0, 0) if current_scene == "Attack": scale(3.333333333) functions.backgroundTint() image(back_img, 0, 0) if functions.isMouseWithinSpace2(10, 980, 95, 1070): image(back_img_highlight, 0, 0) if can_reroll == True: image(reroll_img, 0, 0) if functions.isMouseWithinSpace2(552, 976, 238, 100): image(reroll_img_highlight, 0, 0) scale(0.6) x = 100 y = 450 for i in range(len(TutorialBot.bot_mobster_field_cards)): if functions.total == TutorialBot.bot_mobster_field_cards[ i].hp1 or functions.total == TutorialBot.bot_mobster_field_cards[ i].hp2 or functions.total == TutorialBot.bot_mobster_field_cards[ i].hp3: TutorialBot.bot_mobster_field_cards[i].display(x, y) x += 700 if current_scene == "Reroll": scale(3.333333333) functions.backgroundTint() image(back_img, 0, 0) if functions.isMouseWithinSpace2(10, 980, 95, 1070): image(back_img_highlight, 0, 0) if can_reroll == True: image(reroll_img, 0, 0) if functions.isMouseWithinSpace2(552, 976, 238, 100): image(reroll_img_highlight, 0, 0) scale(0.6) x = 100 y = 450 for i in range(len(TutorialBot.bot_mobster_field_cards)): if functions.total == TutorialBot.bot_mobster_field_cards[ i].hp1 or functions.total == TutorialBot.bot_mobster_field_cards[ i].hp2 or functions.total == TutorialBot.bot_mobster_field_cards[ i].hp3: TutorialBot.bot_mobster_field_cards[i].display(x, y) x += 700 if current_scene == "Reroll2": scale(3.333333333) functions.backgroundTint() image(back_img, 0, 0) if functions.isMouseWithinSpace2(10, 980, 95, 1070): image(back_img_highlight, 0, 0) if can_reroll == True: image(reroll_img, 0, 0) if functions.isMouseWithinSpace2(552, 976, 238, 100): image(reroll_img_highlight, 0, 0) scale(0.6) x = 100 y = 450 for i in range(len(TutorialBot.bot_mobster_field_cards)): if functions.total == TutorialBot.bot_mobster_field_cards[ i].hp1 or functions.total == TutorialBot.bot_mobster_field_cards[ i].hp2 or functions.total == TutorialBot.bot_mobster_field_cards[ i].hp3: TutorialBot.bot_mobster_field_cards[i].display(x, y) x += 700 if current_scene == "Play card": scale(3.333333) image(back_img, 0, 0) if functions.isMouseWithinSpace2(10, 980, 95, 1070): image(back_img_highlight, 0, 0) scale(0.3) x = 100 y = 450 for i in range(len(TutorialBot.player_deck)): if i == 9: x = 100 y = 1550 TutorialBot.player_deck[i].display(x, y) x += 700 if current_scene == "Safe Dice": scale(3.333333333) functions.backgroundTint() if current_scene == "Select_deathcard": scale(3.33333) functions.backgroundTint() x = 500 y = 666 scale(0.6) for i in range(len(TutorialBot.bot_mobster_field_cards)): TutorialBot.bot_mobster_field_cards[i].display(x, y) x += 700 if current_scene == "TOAAY": scale(3.33333) functions.backgroundTint() x = 500 y = 666 scale(0.6) for i in TutorialBot.player_mobster_field_cards: if i.hp1 == 0 or i.hp2 == 0 or i.hp3 == 0: i.display(x, y) x += 700 if current_scene == "Sacrifice": scale(3.33333) functions.backgroundTint() x = 500 y = 666 scale(0.6) for i in TutorialBot.player_mobster_field_cards: if i.hp1 > 0 or i.hp2 > 0 or i.hp3 > 0: i.display(x, y) x += 700 if current_scene == "Retaliate": scale(3.33333) functions.backgroundTint() x = 500 y = 666 scale(0.6) for i in range(len(TutorialBot.player_mobster_field_cards)): TutorialBot.player_mobster_field_cards[i].display(x, y) x += 700 else: # Checks if the bot can get a card if len(bot_deck) > 0: num = int(random(0, len(bot_deck) - 1)) bot_held_cards.append(bot_deck[num]) bot_deck.pop(num) # play Mobstercard check if len(TutorialBot.bot_mobster_field_cards) < 3 and len( bot_held_mobster_cards) > 0 and len( bot_held_cards) > 0 and int(random(0, 10)) < 5: num = int(random(0, len(bot_held_mobster_cards) - 1)) if bot_held_mobster_cards[num] in bot_held_cards: TutorialBot.bot_mobster_field_cards.append( bot_held_mobster_cards[num]) bot_held_cards.remove(bot_held_mobster_cards[num]) bot_held_mobster_cards.pop(num) # Play Trapcard check if len(TutorialBot.bot_trap_field_cards) < 1 and len( bot_held_trap_cards) > 0 and len( bot_held_cards) > 0 and random(0, 10) < 5: num = int(random(0, len(bot_held_trap_cards) - 1)) if bot_held_trap_cards[num] in bot_held_cards: TutorialBot.bot_trap_field_cards.append( bot_held_trap_cards[num]) bot_held_cards.remove(bot_held_trap_cards[num]) bot_held_trap_cards.pop(num) # Play Jobcard check if len(TutorialBot.bot_job_field_cards) < 1 and len( bot_held_job_cards) > 0 and len(bot_held_cards) > 0 and random( 0, 10) < 5: num = int(random(0, len(bot_held_job_cards) - 1)) if bot_held_job_cards[num] in bot_held_cards: TutorialBot.bot_job_field_cards.append(bot_held_job_cards[num]) bot_held_cards.remove(bot_held_job_cards[num]) bot_held_job_cards.pop(num) # Attack check if turn > 2 and len(TutorialBot.player_mobster_field_cards ) > 0 and can_attack == True and int(random( 0, 1)) == 1: # if attack check is True than attacks functions.roll() # checks if the rolled total is the same as the hp of a card if functions.total == TutorialBot.player_mobster_field_cards[ 0].hp1 or functions.total == TutorialBot.player_mobster_field_cards[ 0].hp2 or functions.total == TutorialBot.player_mobster_field_cards[ 0].hp3: if functions.total == TutorialBot.player_mobster_field_cards[ 0].hp1: TutorialBot.player_mobster_field_cards[0].hp1 = 0 elif functions.total == TutorialBot.player_mobster_field_cards[ 0].hp2: TutorialBot.player_mobster_field_cards[0].hp2 = 0 elif functions.total == TutorialBot.player_mobster_field_cards[ 0].hp3: TutorialBot.player_mobster_field_cards[0].hp3 = 0 nextPlayerTurn() elif len(TutorialBot.player_mobster_field_cards) >= 1 and ( functions.total == TutorialBot.player_mobster_field_cards[1].hp1 or functions.total == TutorialBot.player_mobster_field_cards[1].hp2 or functions.total == TutorialBot.player_mobster_field_cards[2].hp3): if functions.total == TutorialBot.player_mobster_field_cards[ 0].hp1: TutorialBot.player_mobster_field_cards[1].hp1 = 0 elif functions.total == TutorialBot.player_mobster_field_cards[ 0].hp2: TutorialBot.player_mobster_field_cards[1].hp2 = 0 elif functions.total == TutorialBot.player_mobster_field_cards[ 0].hp3: TutorialBot.player_mobster_field_cards[1].hp3 = 0 nextPlayerTurn() elif len(TutorialBot.player_mobster_field_cards) == 2 and ( functions.total == TutorialBot.player_mobster_field_cards[2].hp1 or functions.total == TutorialBot.player_mobster_field_cards[2].hp2 or functions.total == TutorialBot.player_mobster_field_cards[2].hp3): if functions.total == TutorialBot.player_mobster_field_cards[ 0].hp1: TutorialBot.player_mobster_field_cards[2].hp1 = 0 elif functions.total == TutorialBot.player_mobster_field_cards[ 0].hp2: TutorialBot.player_mobster_field_cards[2].hp2 = 0 elif functions.total == TutorialBot.player_mobster_field_cards[ 0].hp3: TutorialBot.player_mobster_field_cards[2].hp3 = 0 nextPlayerTurn() else: if reroll_amount > 0: functions.reroll() if functions.total == TutorialBot.player_mobster_field_cards[ 0].hp1 or functions.total == TutorialBot.player_mobster_field_cards[ 0].hp2 or functions.total == TutorialBot.player_mobster_field_cards[ 0].hp3: reroll_amount = 0 if functions.total == TutorialBot.player_mobster_field_cards[ 0].hp1: TutorialBot.player_mobster_field_cards[0].hp1 = 0 elif functions.total == TutorialBot.player_mobster_field_cards[ 0].hp2: TutorialBot.player_mobster_field_cards[0].hp2 = 0 elif functions.total == TutorialBot.player_mobster_field_cards[ 0].hp3: TutorialBot.player_mobster_field_cards[0].hp3 = 0 nextPlayerTurn() elif len(TutorialBot.player_mobster_field_cards) >= 1 and ( functions.total == TutorialBot.player_mobster_field_cards[1].hp1 or functions.total == TutorialBot.player_mobster_field_cards[1].hp2 or functions.total == TutorialBot.player_mobster_field_cards[1].hp3): reroll_amount = 0 if functions.total == TutorialBot.player_mobster_field_cards[ 0].hp1: TutorialBot.player_mobster_field_cards[1].hp1 = 0 elif functions.total == TutorialBot.player_mobster_field_cards[ 0].hp2: TutorialBot.player_mobster_field_cards[1].hp2 = 0 elif functions.total == TutorialBot.player_mobster_field_cards[ 0].hp3: TutorialBot.player_mobster_field_cards[1].hp3 = 0 nextPlayerTurn() elif len(TutorialBot.player_mobster_field_cards) == 2 and ( functions.total == TutorialBot.player_mobster_field_cards[2].hp1 or functions.total == TutorialBot.player_mobster_field_cards[2].hp2 or functions.total == TutorialBot.player_mobster_field_cards[2].hp3): reroll_amount = 0 if functions.total == TutorialBot.player_mobster_field_cards[ 0].hp1: TutorialBot.player_mobster_field_cards[2].hp1 = 0 elif functions.total == TutorialBot.player_mobster_field_cards[ 0].hp2: TutorialBot.player_mobster_field_cards[2].hp2 = 0 elif functions.total == TutorialBot.player_mobster_field_cards[ 0].hp3: TutorialBot.player_mobster_field_cards[2].hp3 = 0 nextPlayerTurn() else: reroll_amount = 0 can_attack = False nextPlayerTurn() else: nextPlayerTurn()