def attacks(): hit_roller = Roller('d20') dmg_seed = arg_value('dmg_seed', 2) attacker = Attack([ Roller("d{dmg}".format(dmg=dmg_seed)) for _ in range(arg_value('n_dmg_rollers', 1)) ], damage_modifier=arg_value('dmg_modifier', 0)) attacks = attacker.attacks(hit_roller, arg_value('n_attacks', 1), risk_buffer=arg_value('risk_buffer', 0), dc=arg_value('dc', 0), modifier=arg_value('hit_modifier', 0), critical=arg_value('critical', 20)) return jsonify({'return': attacker.html_attacks(attacks)}), 200
def check(): seed = arg_value('seed', 20, type=int) roller = Roller(seed) dc = arg_value('dc', 0, type=int) roll, beats_dc = roller.check(dc=dc, modifier=arg_value('modifier', 0, type=int), critical=arg_value('critical', 20, type=int)) succeeds = "" if dc == 0 else "Succeeds" if beats_dc else "Fails" return jsonify( {'return': "{roll} {succeeds}".format(roll=roll, succeeds=succeeds)}), 200
def processCommand(self, whole_command): """ Method: processCommand Interpret a command """ command_split = whole_command.split(" ") command_word = command_split[0] if command_word == "roll": if len(command_split) == 2: roller_string = command_split[1] roller = Roller(roller_string) return roller.roll() else: raise ClindException( "Error: roll requires exactly one argument") elif command_word == "exit": pass elif command_word == "name": with open("src/names.txt") as names_file: names = list(names_file) return random.choice(names).strip() + " " + random.choice( names).strip() elif command_word == "info": if len(command_split) == 2: topic = command_split[1] endpoint = Info.topics[topic] return Info(endpoint).listResults() else: return Info.listTopics() else: raise ClindException( "Error: command {} not recognized".format(command_word))
def game(): prompt = '' while prompt != 'n': prompt = input('Would you like to roll some dice? y/n ') if (prompt.lower() == 'y'): dice_str = input('Enter a dice value in the format XdY\n' ' where x is the number of die and\n' ' y is the number of sides per die\n') pattern = re.compile(r'\d+d\d+') if pattern.match(dice_str) != None: dice = dice_str.split('d') dice_sides = abs(int(dice[1])) num_dice = abs(int(dice[0])) if (dice_sides < 100 and num_dice < 100): roller = Roller(num_dice, dice_sides) print('Rolling . . .\n') sleep(1) roller.roll() print('Here are your rolls\n') print(roller) else: print('Your values are too big, try again') else: print('Try again. The format is XdY')
from parser import Parser from dice_symbols import dice_symbol_table, dice_token_gen from lis import Environment, standard_env, exec from roller import Roller roller = Roller() parser = Parser(dice_token_gen, dice_symbol_table()) def dice_env(): env = Environment((), (), standard_env()) env.update({ 'd': roller.d_roll, 'z': roller.z_roll, '+': lambda left, right: roller.math(left, right, '+'), '-': lambda left, right: roller.math(left, right, '-'), '*': lambda left, right: roller.math(left, right, '*'), '/': lambda left, right: roller.math(left, right, '/'), '/+': lambda left, right: roller.math(left, right, '/+'), '/-': lambda left, right: roller.math(left, right, '/-'), '<': lambda left, right: roller.compare(left, right, '<'), '<=': lambda left, right: roller.compare(left, right, '<='), '>': lambda left, right: roller.compare(left, right, '>'), '>=': lambda left, right: roller.compare(left, right, '>='), '=': lambda left, right: roller.compare(left, right, '='), '==': lambda left, right: roller.compare(left, right, '=='), '!=': lambda left, right: roller.compare(left, right, '!='), "H": roller.highest, "L": roller.lowest, "finalize": roller.finalize }) return env
import os import discord import re from roller import Roller PREFIX = "::" # The prefix used for commands client = discord.Client() # The bot client roller = Roller() # The roller @client.event async def on_message(message): """ Handle messages to initialize the roller message - the message that was sent """ # Convert message to lower case and strip whitespace command = message.content.lower() command = re.sub("\\s+", "", command) if command == PREFIX + "roll": # Main command to start the roller await roller.start_roll(message.channel) elif command == PREFIX + "ping": # Ping command to check if the bot is still alive await message.channel.send("Pong!")
from random import randint from roller import Roller from attack import Attack x = Attack([Roller('d6'), Roller('d6'), Roller('d6')], damage_modifier=2) hit_roller = Roller('d20') for i in x.attacks(hit_roller, 10, dc=0, modifier=3, critical=18): print(i)