def do_attack(self, attack, show=False): try: attack = attack.lower() to_hit = roll.roll("1d20%s" % (self.attacks[attack]["attack"]),) damage = roll.roll(self.attacks[attack]["damage"]) if show: print "%s hit AC %d for %d damage" % (attack.title(), to_hit, damage) return (to_hit, damage) except KeyError: print "Attack '%s' not available." % (attack.title(),)
def setstats(self): self.intelligence=roll(3,6) self.strength=roll(3,6) self.wisdom=roll(3,6) self.agility=roll(3,6) self.luck=roll(3,6) self.charisma=roll(3,6) self.dexterity=roll(3,6) self.tenacity=roll(3,6)
def visit_roll(self, n, c): if self.debug: print('roll: %s'%(c.results)) res = c.results return roll.roll( int(res['sides'][0]), count=int(res.get('count', [1])[0]), take_size=int(res.get('take_size', [0])[0]), take_higest=res.get('take_high', []) != [] )
def roll_stat(self, stat, show=False): try: mod = (self.stats[stat]-10)/2 if mod > 0: mod = "+%d" % (mod,) check = roll.roll("1d20%s" % (mod,)) if show: print "%s rolled a %s for %s" % (self.name, stat.title(), check) except KeyError: print "Stat '%s' not available." % (stat.title(),)
def _generate_law_level(self): return max(0, min(10, roll(2) - 7 + self.government))
def _generate_size(self): return roll(2) - 2
def _generate_population(self): return roll(2) - 2
def coatofarms_gen(): """Generates a random coat of arms""" # Should someday take some sort of seed value to modify it. attitudes = ['Rampant', 'Passant', 'Sejant', 'Couchant', 'Courant', 'Dormant', 'Salient', 'Statant', 'Sejant Erect'] attitudemod = ['Guardant', 'Regardant'] colors = ['Black', 'Silver', 'Gray', 'Green', 'Gold', 'Red', 'Orange', 'Blue', 'Purple', 'Sky-blue'] animals = [ 'Dragon', 'Lion', 'Stag', 'Wolf', 'Griffon', 'Eagle', 'Hawk', 'Owl', 'Raven', 'Horse', 'Elephant', 'Pegasus', 'Unicorn', 'Dog', 'Cockatrice', 'Snake', 'Pike', 'Trout', 'Kraken', 'Leopard', 'Bear', 'Boar' ] symbols = ['Oak', 'Aspen', 'River', 'Sword', 'Axe', 'Key', 'Crown', 'Wheat', 'Rose', 'Sun', 'Boat'] divisions = ['Fess', 'Pale', 'Bend', 'Bend sinister', 'Saltire', 'Cross', 'Chevron', 'Pall'] # party per # divisionmods = ['Wavy', 'Indented', 'Engrailed', 'Invected', 'Nebuly', 'Embattled', 'Dovetailed', 'Potenty'] bends = ['Bend', 'Bendlet', 'Baton', 'Riband', 'Bendy of Six', 'Bend Cotised'] f = roll(1,10) if f <= 4: # Do an animal set up. animal = random.choice(animals) colour = random.choice(colors) attitude = random.choice(attitudes) if f <= 2: attitude = attitude + " " + random.choice(attitudemod) # Do background: e = roll(1,6) if e == 1: # Bend set up background = random.choice(colors) + " a " + random.choice(bends) + " on " + random.choice(colors) elif e == 2: # Divided. background = "party per " + random.choice(divisions) + " " + random.choice(colors) + " and " +\ random.choice(colors) else: # Solid background = random.choice(colors) fullcoat = "a " + colour + " " + attitude + " " + animal + " on " + background elif f <= 8: # Do a bend set up. background = random.choice(colors) + " a " + random.choice(bends) + " " + random.choice(colors) fullcoat = background else: # Do a symbol set up symbol = random.choice(symbols) colour = random.choice(colors) attitude = random.choice(attitudes) if f <= 2: attitude += " " + random.choice(attitudemod) # Do background: e = roll(1,6) if e == 1: # Bend set up background = random.choice(colors) + " a " + random.choice(bends) + " " + random.choice(colors) elif e == 2: # Divided. background = "party per " + random.choice(divisions) + " " + random.choice(colors) + " and " +\ random.choice(colors) else: # Solid background = random.choice(colors) fullcoat = "a " + colour + " " + symbol + " on " + background return fullcoat
def gen_name(gender, race): """Returns a random name given gender and race""" try: all = yaml.safe_load(open('races/' + race + '.yml').read()) male_names_common = all["male common names"] male_names_uncommon = all["male uncommon names"] lastnames = all["lastnames"] female_names_common = all["female common names"] female_names_uncommon = all["female uncommon names"] except: return '"Bob" Dobbs' # MALE NAMES if gender == 'm': # Roll 1d100 to see if you get a standard first name or not. if roll(1,100) <= 60: # standard first name firstname = random.choice(male_names_common) else: # unusual first name firstname = random.choice(male_names_uncommon) # FEMALE NAMES else: # Roll 1d100 to see if you get a standard first name or not. if roll(1,100) <= 60: # standard first name firstname = random.choice(female_names_common) else: # unusual first name firstname = random.choice(female_names_uncommon) # A quick section to make some first names stupid, like Eddard instead of Edward. if roll(1,10) <= 3: q = 0 while True: leng = len(list(firstname)) leng = roll(1, leng) cletters = 'bcdfghjklmnprstvwz' #print(leng) if list(firstname)[leng-1] in cletters: #print(list(firstname)[leng-1]) firstname = firstname[:leng-1] + random.choice(list(cletters)) + firstname[leng:] break else: q += 1 if q >= 100: break if roll(1,10) <= 3: q = 0 while True: leng = len(list(firstname)) leng = roll(1, leng) cletters = 'aeiuy' #print(leng) if list(firstname)[leng-1] in cletters: #print(list(firstname)[leng-1]) firstname = firstname[:leng-1] + random.choice(list(cletters)) + firstname[leng:] break else: q += 1 if q >= 100: break # LAST NAMES if roll(1,100) <= 50: lastname = random.choice(lastnames) else: lastname = random.choice(male_names_uncommon) if roll(1,10) < 4: lastname = lastname + random.choice(all["endings"]) fullname = firstname + " " + lastname #fullname = "x" + fullname[roll(1,len(list(fullname))):] return fullname
def test_interpret_dice(): assert roll('d20') in range(1, 21)
def test_inception_dice1(): assert roll('1d7d4d6') in range(1, 169)
def test_inception_dice_with_parens3(): assert roll('4d(10d7d8)') in range(10, 2241)
def test_mul_b4_add1(): assert roll('2+6*4') == 26
def test_inception_dice_with_parens1(): assert roll('(1d4)d6') in range(1, 25)
def test_inception_dice_with_parens2(): assert roll('1d(1d20)') in range(1, 21)
def test_inception_dice4(): assert roll('2d4d6d8') in range(2, 385)
def test_inception_dice3(): assert roll('10d2d4') in range(10, 81)
def test_inception_dice2(): assert roll('7d4d20') in range(7, 561)
from roll import roll results = [] for x in range(0, 6): statroll = roll('4d6') print(statroll) statroll.sort() del statroll[0] results.append(sum(statroll)) modifiers = [] for stat in results: stat = stat - 10 modifiers.append(stat // 2) print(results) print('total modifiers:', sum(modifiers))
def test_default_case(self): default_result = roll() self.assertTrue(1 <= default_result <= 6)
# Increase event index by one at the beginning of a new event if TURN == 1: SCORE[0] = SCORE[0] + 1 if ARGS.verbose: # Insert a blank line for new events when in verbose if TURN == 1: print("") print("Current Event: " + str(SCORE[0])) print("Current Scene: " + str(current)) print("Turn: Player " + str(TURN)) # Rolling for happening modifier (ignored in simulation) if TURN == 1: # Only occurs at the beginning of each Event. h1 = roll(4) h2 = roll(12) if ARGS.verbose: print("Happening modifiers: " + str(h1) + " & " + str(h2)) # Incomplete AI: Use tiers to inform the next three decisions # Decide to go for Reputation or Madness rpmd = randrange(0, 2) if ARGS.verbose: if rpmd == 0: print("Rolling for Madness!") else: print("Rolling for Reputation!") # Calculate PC dice tier and roll
def test_d6_plus_d8(): assert roll('d6 + d8') in range(1, 14)
def test_div_b4_sub1(): assert roll('100 - 21 / 7') == 97
def test_1d8_plus_3d6(): assert roll('1d8 + 3d6') in range(4, 26)
def calcHP(self, CON): HP = roll( str(self.level - 1) + 'd' + str(self.hd) + '+' + str((self.level) * CON + self.hd)) return HP
def coatofarms_gen(): """Generates a random coat of arms""" # Should someday take some sort of seed value to modify it. attitudes = [ 'Rampant', 'Passant', 'Sejant', 'Couchant', 'Courant', 'Dormant', 'Salient', 'Statant', 'Sejant Erect' ] attitudemod = ['Guardant', 'Regardant'] colors = [ 'Black', 'Silver', 'Gray', 'Green', 'Gold', 'Red', 'Orange', 'Blue', 'Purple', 'Sky-blue' ] animals = [ 'Dragon', 'Lion', 'Stag', 'Wolf', 'Griffon', 'Eagle', 'Hawk', 'Owl', 'Raven', 'Horse', 'Elephant', 'Pegasus', 'Unicorn', 'Dog', 'Cockatrice', 'Snake', 'Pike', 'Trout', 'Kraken', 'Leopard', 'Bear', 'Boar' ] symbols = [ 'Oak', 'Aspen', 'River', 'Sword', 'Axe', 'Key', 'Crown', 'Wheat', 'Rose', 'Sun', 'Boat' ] divisions = [ 'Fess', 'Pale', 'Bend', 'Bend sinister', 'Saltire', 'Cross', 'Chevron', 'Pall' ] # party per # divisionmods = ['Wavy', 'Indented', 'Engrailed', 'Invected', 'Nebuly', 'Embattled', 'Dovetailed', 'Potenty'] bends = [ 'Bend', 'Bendlet', 'Baton', 'Riband', 'Bendy of Six', 'Bend Cotised' ] f = roll(1, 10) if f <= 4: # Do an animal set up. animal = random.choice(animals) colour = random.choice(colors) attitude = random.choice(attitudes) if f <= 2: attitude = attitude + " " + random.choice(attitudemod) # Do background: e = roll(1, 6) if e == 1: # Bend set up background = random.choice(colors) + " a " + random.choice( bends) + " on " + random.choice(colors) elif e == 2: # Divided. background = "party per " + random.choice(divisions) + " " + random.choice(colors) + " and " +\ random.choice(colors) else: # Solid background = random.choice(colors) fullcoat = "a " + colour + " " + attitude + " " + animal + " on " + background elif f <= 8: # Do a bend set up. background = random.choice(colors) + " a " + random.choice( bends) + " " + random.choice(colors) fullcoat = background else: # Do a symbol set up symbol = random.choice(symbols) colour = random.choice(colors) attitude = random.choice(attitudes) if f <= 2: attitude += " " + random.choice(attitudemod) # Do background: e = roll(1, 6) if e == 1: # Bend set up background = random.choice(colors) + " a " + random.choice( bends) + " " + random.choice(colors) elif e == 2: # Divided. background = "party per " + random.choice(divisions) + " " + random.choice(colors) + " and " +\ random.choice(colors) else: # Solid background = random.choice(colors) fullcoat = "a " + colour + " " + symbol + " on " + background return fullcoat
def name_gen_eng(gender): """Generates a random and rather vanilla medieval english sounding name""" # http://www.infernaldreams.com/names/Europe/Medieval/England.htm male_names_common = ['Adam', 'Geoffrey', 'Gilbert', 'Henry', 'Hugh', 'John', 'Nicholas', 'Peter', 'Ralf', 'Richard', 'Robert', 'Roger', 'Simon', 'Thomas', 'Walter', 'William'] male_names_uncommon = [ 'Alard', 'Ademar', 'Adelard', 'Aldous', 'Alphonse', 'Ancel', 'Arnold', 'Bardol', 'Bernard', 'Bartram', 'Botolf', 'Charles', 'Clarenbald', 'Conrad', 'Curtis', 'Diggory', 'Drogo', 'Droyn', 'Dreue', 'Ernis', 'Ernisius', 'Eude', 'Edon','Everard', 'Faramond', 'Ferand','Frank', 'Frederick', 'Fawkes', 'Foulque', 'Gaillard', 'Gerald', 'Gerard', 'Gervase', 'Godfrey', 'Guy', 'Hamett', 'Harvey', 'Henry', 'Herman', 'Hubert', 'Yngerame', 'Lance', 'Louis', 'Louve', 'Manfred', 'Miles', 'Norman', 'Otto', 'Percival', 'Randal', 'Raymond', 'Reynard', 'Sagard', 'Serlo', 'Talbot', 'Theodoric', 'Wymond' ] lastnames = [ 'Smith', 'Cooper', 'Cook', 'Hill', 'Underhill', 'Wright', 'Taylor', 'Chapman', 'Barker', 'Tanner', 'Fiddler', 'Puttock', 'Arkwright', 'Mason', 'Carpenter', 'Dymond', 'Armstrong', 'Black', 'White', 'Green', 'Gray', 'Sykes', 'Attwood', 'Miller' ] female_names_common = [ 'Emma', 'Agnes' , 'Alice', 'Avice', 'Beatrice', 'Cecily', 'Isabella', 'Joan', 'Juliana', 'Margery', 'Matilda', 'Rohesia' ] female_names_uncommon = [ 'Adelaide', 'Ada', 'Aubrey', 'Alice', 'Alison', 'Avelina', 'Eleanor', 'Ella', 'Galiena', 'Giselle', 'Griselda', 'Matilda', 'Millicent', 'Yvonne', 'Elizabeth', 'Eva', 'Gabella', 'Jacqueline', 'Sapphira', 'Tyffany', 'Bridget', 'Guinevere', 'Isolda', 'Alexandra', 'Cassandra', 'Denise', 'Sibyl' ] # MALE NAMES if gender == 'm': # Roll 1d100 to see if you get a standard first name or not. if roll(1,100) <= 60: # standard first name firstname = random.choice(male_names_common) else: # unusual first name firstname = random.choice(male_names_uncommon) # FEMALE NAMES else: # Roll 1d100 to see if you get a standard first name or not. if roll(1,100) <= 60: # standard first name firstname = random.choice(female_names_common) else: # unusual first name firstname = random.choice(female_names_uncommon) # LAST NAMES if roll(1,100) <= 50: lastname = random.choice(lastnames) else: lastname = random.choice(male_names_uncommon) if roll(1,10) < 4: lastname = lastname + "son" fullname = firstname + " " + lastname return fullname
def name_gen_eng(gender): """Generates a random and rather vanilla medieval english sounding name""" # http://www.infernaldreams.com/names/Europe/Medieval/England.htm male_names_common = [ 'Adam', 'Geoffrey', 'Gilbert', 'Henry', 'Hugh', 'John', 'Nicholas', 'Peter', 'Ralf', 'Richard', 'Robert', 'Roger', 'Simon', 'Thomas', 'Walter', 'William' ] male_names_uncommon = [ 'Alard', 'Ademar', 'Adelard', 'Aldous', 'Alphonse', 'Ancel', 'Arnold', 'Bardol', 'Bernard', 'Bartram', 'Botolf', 'Charles', 'Clarenbald', 'Conrad', 'Curtis', 'Diggory', 'Drogo', 'Droyn', 'Dreue', 'Ernis', 'Ernisius', 'Eude', 'Edon', 'Everard', 'Faramond', 'Ferand', 'Frank', 'Frederick', 'Fawkes', 'Foulque', 'Gaillard', 'Gerald', 'Gerard', 'Gervase', 'Godfrey', 'Guy', 'Hamett', 'Harvey', 'Henry', 'Herman', 'Hubert', 'Yngerame', 'Lance', 'Louis', 'Louve', 'Manfred', 'Miles', 'Norman', 'Otto', 'Percival', 'Randal', 'Raymond', 'Reynard', 'Sagard', 'Serlo', 'Talbot', 'Theodoric', 'Wymond' ] lastnames = [ 'Smith', 'Cooper', 'Cook', 'Hill', 'Underhill', 'Wright', 'Taylor', 'Chapman', 'Barker', 'Tanner', 'Fiddler', 'Puttock', 'Arkwright', 'Mason', 'Carpenter', 'Dymond', 'Armstrong', 'Black', 'White', 'Green', 'Gray', 'Sykes', 'Attwood', 'Miller' ] female_names_common = [ 'Emma', 'Agnes', 'Alice', 'Avice', 'Beatrice', 'Cecily', 'Isabella', 'Joan', 'Juliana', 'Margery', 'Matilda', 'Rohesia' ] female_names_uncommon = [ 'Adelaide', 'Ada', 'Aubrey', 'Alice', 'Alison', 'Avelina', 'Eleanor', 'Ella', 'Galiena', 'Giselle', 'Griselda', 'Matilda', 'Millicent', 'Yvonne', 'Elizabeth', 'Eva', 'Gabella', 'Jacqueline', 'Sapphira', 'Tyffany', 'Bridget', 'Guinevere', 'Isolda', 'Alexandra', 'Cassandra', 'Denise', 'Sibyl' ] # MALE NAMES if gender == 'm': # Roll 1d100 to see if you get a standard first name or not. if roll(1, 100) <= 60: # standard first name firstname = random.choice(male_names_common) else: # unusual first name firstname = random.choice(male_names_uncommon) # FEMALE NAMES else: # Roll 1d100 to see if you get a standard first name or not. if roll(1, 100) <= 60: # standard first name firstname = random.choice(female_names_common) else: # unusual first name firstname = random.choice(female_names_uncommon) # LAST NAMES if roll(1, 100) <= 50: lastname = random.choice(lastnames) else: lastname = random.choice(male_names_uncommon) if roll(1, 10) < 4: lastname = lastname + "son" fullname = firstname + " " + lastname return fullname
# # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. from roll import roll from world import World class Sector(object): def __init__(self): pass if __name__ == "__main__": # testing: for i in range(1, 8): for j in range(1, 10): if roll() >= 4: w = World() print("{:16} {:02d}{:02d} {} {} {:44} {}".format( w.name, i, j, w.uwp, w.bases, w.trade_classes, w.gas_giant))
def gen_name(gender, race): """Returns a random name given gender and race""" try: all = yaml.safe_load(open('races/' + race + '.yml').read()) male_names_common = all["male common names"] male_names_uncommon = all["male uncommon names"] lastnames = all["lastnames"] female_names_common = all["female common names"] female_names_uncommon = all["female uncommon names"] except: return '"Bob" Dobbs' # MALE NAMES if gender == 'm': # Roll 1d100 to see if you get a standard first name or not. if roll(1, 100) <= 60: # standard first name firstname = random.choice(male_names_common) else: # unusual first name firstname = random.choice(male_names_uncommon) # FEMALE NAMES else: # Roll 1d100 to see if you get a standard first name or not. if roll(1, 100) <= 60: # standard first name firstname = random.choice(female_names_common) else: # unusual first name firstname = random.choice(female_names_uncommon) # A quick section to make some first names stupid, like Eddard instead of Edward. if roll(1, 10) <= 3: q = 0 while True: leng = len(list(firstname)) leng = roll(1, leng) cletters = 'bcdfghjklmnprstvwz' #print(leng) if list(firstname)[leng - 1] in cletters: #print(list(firstname)[leng-1]) firstname = firstname[:leng - 1] + random.choice( list(cletters)) + firstname[leng:] break else: q += 1 if q >= 100: break if roll(1, 10) <= 3: q = 0 while True: leng = len(list(firstname)) leng = roll(1, leng) cletters = 'aeiuy' #print(leng) if list(firstname)[leng - 1] in cletters: #print(list(firstname)[leng-1]) firstname = firstname[:leng - 1] + random.choice( list(cletters)) + firstname[leng:] break else: q += 1 if q >= 100: break # LAST NAMES if roll(1, 100) <= 50: lastname = random.choice(lastnames) else: lastname = random.choice(male_names_uncommon) if roll(1, 10) < 4: lastname = lastname + random.choice(all["endings"]) fullname = firstname + " " + lastname #fullname = "x" + fullname[roll(1,len(list(fullname))):] return fullname
def _generate_atmosphere(self): result = roll(2) - 7 + self.size if self.size == 0: return 0 return max(0, min(result, 12))
def __init__(self, fighters: List[mob.Mob], unitType, faction, initiative): self.fighters = fighters self.type = unitType self.faction = faction self.initiative = roll(20) + initiative
def _generate_government(self): return max(0, min(14, roll(2) - 7 + self.population))
def __init__(self): self.hp = 100 self.speed = roll.roll(2,6)
def search(self, unread_messages): for message in unread_messages: time.sleep(0.10) self.bot.messages.markAsRead(message_ids=int(message['mid'])) if message['uid'] == 179033736: self.cotsman(message) key = self.mailer.kind_mail_reply(self.get_screen_name_from_id(message)) if key: self.bot.messages.send(user_id=key, message = u'Вот ответ', forward_messages = message['mid']) if 'chat_id' in message: if u'кикни' in message['body'].lower() and (message['chat_id'] == 6): text = self.kicker.kick_it(message['body'], message['uid']) self.send_to_chat(message, text) if u'покинул' in message['body'].lower() and u'беседу' in message['body'].lower() and ('users_count' in message): if message['users_count'] != self.chats_lenth[message['chat_id']] : self.chats_lenth[message['chat_id']] = message['users_count'] self.send_to_chat(message, u'Если это существо прийдёт еще раз, я думаю Я НЕ БУДУ ВЫБИРАТЬ ВЫРАЖЕНИЯ') if u'вернул' in message['body'].lower() and u'беседу' in message['body'].lower() and ('users_count' in message): if message['users_count'] != self.chats_lenth[message['chat_id']] : self.chats_lenth[message['chat_id']] = message['users_count'] self.send_to_chat(message, u'Мы следим за тобой, ничтожество') if u'пригласил' in message['body'].lower() and ('users_count' in message): if message['users_count'] != self.chats_lenth[message['chat_id']] : self.chats_lenth[message['chat_id']] = message['users_count'] if message['chat_id'] == 6: self.come_back(message) else: name = message['body'].split() text = u'Дальше вы не пройдете пока не получити бумаги ' + name[-1] + ' ' + name[-2] self.send_to_chat(message, text) if u'исключил' in message['body'].lower() and ('users_count' in message): if message['users_count'] != self.chats_lenth[message['chat_id']] : self.chats_lenth[message['chat_id']] = message['users_count'] self.send_to_chat(message, u'Так и нужно этому псу') if u'имперец' in message['body'].lower(): if u'инфа' in message['body'].lower() or u'вероятность' in message['body'].lower(): self.send_to_chat(message,info(),reply=1) elif u'реквизиты' in message['body'].lower(): kiwi = '+380977112941' webua = 'U368244412318' text = u'Вы можете выразить вашу благодарность денюшкой. КиВи кошелек - %s, WebMoney UA - %s. Я лично, и мой идиот создатель, будем очень вам благодарны' % (kiwi,webua) self.send_to_chat(message, text=text) elif u'привет' in message['body'].lower(): self.send_to_chat(message, u'Под этим солнцем и небом мы тепло преветствуем тебя!', reply=1) elif u'ролл' in message['body'].lower(): try: text = roll.roll(message['body'].lower()) except: text = u'Что то пошло не так, еще раз давай. Давай, чо ты. Еще раз какую то херню пришли, маргинал' self.send_to_chat(message, text, reply = 1) elif u'извинися' in message['body'].lower(): self.send_to_chat(message, u'Я прошу прощения за свои слова',reply=1) elif u'спасибо' in message['body'].lower(): self.send_to_chat(message, u'Ваша благодарность - высшая награда',reply=1) elif u'спокойной ночи' in message['body'].lower(): self.send_to_chat(message, u'Пускай АЛЬМСИВИ охраняют твой сон!',reply=1) elif u'доброе утро' in message['body'].lower(): self.send_to_chat(message, u'Доброе утро! Говорите свободно!',reply=1) elif u'лицо' in message['body'].lower(): text_face=your_face(message,self.id,self.faces) self.send_to_chat(message, text_face[0], attachment=text_face[1]) elif u'помощь' in message['body'].lower(): self.send_to_chat(message=message,text=self.help_file) elif u'кто здесь' in message['body'].lower(): self.send_to_chat(message,who_is_who(message,self.bot),reply=1) elif u'мперец, покажи' in message['body'].lower(): attachment = self.image_handler.get_image_from_internet(message['body'].lower()[16:]) self.send_to_chat(message, 'Вот чё я нарыл',attachment=attachment) elif u'любовь' in message['body'].lower(): self.send_to_chat(message,love(message,self.bot),reply=1) elif u'мперец, вики' in message['body'].lower(): self.wiki(message) elif u'цитата' in message['body'].lower(): attachment = self.image_handler.create_qoute(message['body'].lower()) self.send_to_chat(message, text="О как", attachment=attachment) elif u'мперец, видео' in message['body'].lower(): text = self.image_handler.video_from_internet(message['body'].lower()[15:]) text = 'Смари %s' % text self.send_to_chat(message, text) elif u'мперец, покажи' in message['body'].lower(): attachment = self.image_handler.get_image_from_internet(message['body'].lower()[16:]) self.send_to_chat(message, 'Вот чё я нарыл',attachment=attachment) elif u'комикс' in message['body'].lower(): self.choose_comic(message) elif u'репост' in message['body'].lower(): self.send_to_chat(message,text=u'Вот тебе', attachment= repost(self.bot)) elif u'погода' in message['body'].lower(): text = message['body'].lower() text = text.replace('имперец','') text = text.replace(',','') text = text.replace('погода','') self.send_to_chat(message, text =weather.get_weather(text)) elif u'оцени' in message['body'].lower() or (u'как тебе') in message['body'].lower(): responce = how_is_it(message,self.id) self.send_to_chat(message,responce[0],responce[1],responce[2]) if u'как вам' in message['body'].lower(): reply = [u'Норм',u'Мне не нравится',u'Лучше умереть за Императора, чем эта фигня',u'У меня нету четкого мнения по этому поводу',u'Гавно собачье, жопа',u'Отлично, и это до поправочки пивчанским', u'Ну такое, ночем'] text = choice(reply) self.send_to_chat(message, text=text) if u'добропочта%' in message['body'].lower(): text = self.mailer.kind_mail_send(message['body'], message['uid']) self.send_to_chat(message,text) if u' или ' in message['body'].lower(): self.send_to_chat(message,text=choice(choose_or(message['body'].lower()))) for i in [u'хочу',u'хотел',u'хотелось',u'желаю',u'мечтаю']: if i in message['body'].lower(): text = choice(self.responce_to_wish) self.send_to_chat(message, text=text, reply=1) break
from roll import roll lastcommand = 'd20' while 1 == 1: command = input('What do you want to roll? (' + lastcommand + ') ') if command == '': command = lastcommand else: lastcommand = command results = roll(command) for r in results: print(r) print('Total:', sum(results))
import argparse import npc_gen from roll import roll # test imports - delete after reading from npc_gen.get_rand import get_wrand parser = argparse.ArgumentParser() parser.add_argument("command") parser.add_argument("data", default='', nargs='?') args = parser.parse_args() commands = { 'npc': npc_gen.char, 'goal': npc_gen.directive, 'loc': npc_gen.loc, 'town': npc_gen.town, 'test': get_wrand, 'roll': lambda: roll(args.data), } cmd_func = commands.get(args.command, lambda: "command not recognised") # the below assumes that all functions used here return a printable string print(cmd_func())
#是否以自己为目标 if target == uid: return HttpResponse(simplejson.dumps({'success':True}), mimetype = 'application/json') iValue = ifPCInGame(uid) if iValue >0: gstatue = getGameStatue(iValue) if gstatue: if gstatue==2 : gturn = checkPCTurn(uid) if gturn["RollToken"]: try: rollValue = roll(request,target,iValue,gturn["rndID"],gturn)#gturn["RollTurnInfo"]["gFlag"]) except Exception,data: debugLog("call roll() error:"+str(Exception)+":"+str(data)) return HttpResponse(simplejson.dumps({'success':False}), mimetype = 'application/json') if rollValue["errmsg"] == '': del rollValue["errmsg"] del rollValue["info"]["rtime"] ct = simplejson.dumps(rollValue) dt = datetime.datetime.now() insertMsg( ct, uid, dt, "ROLL", target,"gam", gturn["gid"]) #gid return HttpResponse(simplejson.dumps({'success':True}), mimetype = 'application/json') else:
def pick_feat(tags, character_file): # tags is a list """Picks a feat using score rankings on the list. Returns feat as single entry list""" # Not super efficient, so don't call it too much # characterfile = yaml.safe_load(str(character_file)) feats = yaml.safe_load(open("feats.yml")) random.shuffle(feats) ranktobeat = 0 finalchoice = "Toughness" # just so it has a default. # Load the feats there are now for later use try: charfeats = character_file["feats"] except: charfeats = [] for f in feats: ## rank f rank = f["score"] # make sure its not already picked try: if f["name"] in character_file["feats"]: continue except: pass # if its a fighter bonus, then it must hold if "fighter bonus" in tags and "fighter bonus" not in f["tags"]: continue ## check prereqs try: if f["prereqs"]["caster level"] > cfunc.get_caster_level(character_file): continue except: pass passing = [True, ] # any falses in the list fails everything # Check stat prereqs try: for s in f["prereqs"]["stats"]: z = check_stat_prereqs(str(s), character_file) if z: rank += 5 else: pass passing.append(z) except: pass if False in passing: continue # Check Base attack prereq try: if f["prereqs"]["base attack"] >= character_file["base attack"]: stupidcrap = f + " wut?" # FIXME I have no idea what this does... # if you remove stupid crap here...the whole thing breaks when # a feat has a base attack requirement? what the actual f**k? continue else: rank += 5 except: pass # but make sure base attack is set before calling this! # Check Feats prereqs preqs = [] try: preqs = f["prereqs"]["feats"] except: pass # there are no feat prereqs, keep rolling passing = [True, ] # any falses in the list fails everything for x in preqs: if x in charfeats: rank += 20 else: passing.append(False) if False in passing: continue ## end of prereq checking for x in tags: # moved all but the first entry here in to this loop. Not sure why they were out of # the loop, but maybe there was a reason. In any case, they are in now, so any odd errors # might be traced to here I guess. if x in f["tags"]: rank += 10 # add ten for every matching tag. # add twenty if the class is called out. if character_file["class"] in f["tags"]: rank += 20 # if the name of the feat is tagged, probably want to give it to them if f["name"] in tags: rank += 175 ## end of rankings, make call if rank > ranktobeat: finalchoice = f["name"] ranktobeat = rank elif rank < ranktobeat: pass else: # pick randomly if roll.roll(1, 3) >= 1: finalchoice = f["name"] return [finalchoice, ]
from random import randint from roll import roll NumOfRooms = sum(roll('3d6')) grid = [] rooms = [] class Room: def __init__(self): self.horiz = sum(roll('4d4')) self.vert = sum(roll('4d4')) self.tlc = (0, 0) def position(self): global grid self.trynewloc = True while self.trynewloc: self.testgrid = [] self.tlc = (randint(0, 100), randint(0, 100)) self.h = self.horiz + 2 self.v = self.vert + 2 for x in range(-1, self.v - 1): for y in range(-1, self.h - 1): self.testgrid.append((self.tlc[0] + y, self.tlc[1] + x)) self.trynewloc = False for coord in self.testgrid: if coord in grid: self.trynewloc = True break else: pass for x in range(0, self.vert):
def initiative(self): return roll.roll("1d20%s" % (self.init,))
def __init__(self): self.horiz = sum(roll('4d4')) self.vert = sum(roll('4d4')) self.tlc = (0, 0)
def rollFunc(msg): _, roll_text = roll.roll(msg.txt) msg.send(roll_text, parse_mode='Markdown')
def test_parens(): assert roll('(1 + 4) / 5') == 1