예제 #1
0
    def test_parse(self):
        expr, text = dice.parse('/r 1d20+15 abcd')
        self.assertEqual(expr, '/r 1d20+15')
        self.assertEqual(text, 'abcd')

        expr, text = dice.parse('/roll 1d20+17/+12/+7 text text ')
        self.assertEqual(expr, '/roll 1d20+17/+12/+7')
        self.assertEqual(text, 'text text')

        expr, text = dice.parse('/invalid text')
        self.assertFalse(expr)
        self.assertEqual(text, '')
예제 #2
0
 def isACrit( self, croll=None ):
     if croll:
         self.rolls.append( croll )
     if len( self.rolls ) < 2:
         from dice import parse
         self.rolls.extend( parse( "1d20" ).sum( ) )
     #This will need to be fixed for situations where the att or AC changes based on the defender or attacker
     return ( self.rolls[ 1 ] != 1 ) and ( ( self.rolls[ 1 ] + self.tool.ATT ) > self.object.AC or ( self.rolls[ 1 ] ) == 20 )
예제 #3
0
 def __init__( self, character, levelnum, charlevelnum, characterclass, mods=None, feats=None ):
     super( D20CharacterLevel, self ).__init__( character, levelnum, charlevelnum, characterclass, mods, feats )
     from dice import parse
     if charlevelnum == 1:
         rollstring = characterclass.hitdice[ levelnum ]
     else:
         rollstring = "1d%s" % characterclass.hitdice[ levelnum ]
     self.hp = D20HP( 'Hit Points', parse( rollstring ).sum( ) )
     character.CON.modprovided.addTarget( self.hp, 'RANKS' )
     self.factories[ character.HP ] = ( self.hp.modprovided, 'Level Modifier', ( ) )
예제 #4
0
 def isACrit(self, croll=None):
     if croll:
         self.rolls.append(croll)
     if len(self.rolls) < 2:
         from dice import parse
         self.rolls.extend(parse("1d20").sum())
     #This will need to be fixed for situations where the att or AC changes based on the defender or attacker
     return (self.rolls[1] != 1) and (
         (self.rolls[1] + self.tool.ATT) > self.object.AC or
         (self.rolls[1]) == 20)
예제 #5
0
파일: bot.py 프로젝트: Vashy/MemeRollerBot
def handle(msg):
    content_type, _, chat_id, _, msg_id = telepot.glance(msg, long=True)
    logging.debug(
        f'Received message from {msg["from"]["username"]} ({chat_id})')

    if content_type == 'text':
        roll_expression, roll_desc = dice.parse(msg['text'])
        if roll_expression:
            result, steps = dice.roll(roll_expression)
            response = build_msg(msg['from']['username'], result, steps,
                                 roll_desc)
            BOT.sendMessage(chat_id,
                            response,
                            reply_to_message_id=msg_id,
                            parse_mode='markdown')
예제 #6
0
 def __init__(self,
              character,
              levelnum,
              charlevelnum,
              characterclass,
              mods=None,
              feats=None):
     super(D20CharacterLevel,
           self).__init__(character, levelnum, charlevelnum, characterclass,
                          mods, feats)
     from dice import parse
     if charlevelnum == 1:
         rollstring = characterclass.hitdice[levelnum]
     else:
         rollstring = "1d%s" % characterclass.hitdice[levelnum]
     self.hp = D20HP('Hit Points', parse(rollstring).sum())
     character.CON.modprovided.addTarget(self.hp, 'RANKS')
     self.factories[character.HP] = (self.hp.modprovided, 'Level Modifier',
                                     ())
예제 #7
0
파일: dice_test.py 프로젝트: kemayo/dice
 def testParse(self):
     self.assertEqual(dice.parse("10"), ([], 10))
     self.assertEqual(dice.parse("d6"), ([6], 0))
     self.assertEqual(dice.parse("4d6"), ([6, 6, 6, 6], 0))
     self.assertEqual(dice.parse("4d6+10"), ([6, 6, 6, 6], 10))
     self.assertEqual(dice.parse("4d6+d8"), ([6, 6, 6, 6, 8], 0))
     self.assertEqual(dice.parse("4d6+d8+12"), ([6, 6, 6, 6, 8], 12))
     self.assertEqual(dice.parse("4d6+d8+12+2"), ([6, 6, 6, 6, 8], 14))
     self.assertEqual(dice.parse("4d6-d8+12-2"), ([6, 6, 6, 6, -8], 10))
     self.assertEqual(dice.parse("4d16-d8+12-2"), ([16, 16, 16, 16, -8], 10))
     self.assertEqual(dice.parse("4d16-10d8+12-2"), ([16, 16, 16, 16, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8], 10))
     self.assertEqual(dice.parse("(2+2)d6"), ([6, 6, 6, 6], 0))
     self.assertEqual(dice.parse("(2+2)d6+(3-2d2)"), ([6, 6, 6, 6, -2, -2], 3))
     self.assertRaises(ValueError, dice.parse, "4d(2d3)")
예제 #8
0
 def roll( self ):
     from dice import parse
     return parse( self.ranks[ super( D20DamageRange, self ).__int__( ) ] )[ 0 ].sum( )
예제 #9
0
 def roll(self):
     from dice import parse
     return parse(self.ranks[super(D20DamageRange,
                                   self).__int__()])[0].sum()
예제 #10
0
    def test_parse(self):
        self.assertEqual(dice.parse("1d4"), ("1d4", 1, 4, 0))
        self.assertEqual(dice.parse("1d6"), ("1d6", 1, 6, 0))
        self.assertEqual(dice.parse("1d8"), ("1d8", 1, 8, 0))
        self.assertEqual(dice.parse("1d10"), ("1d10", 1, 10, 0))
        self.assertEqual(dice.parse("1d12"), ("1d12", 1, 12, 0))
        self.assertEqual(dice.parse("1d20"), ("1d20", 1, 20, 0))
        self.assertEqual(dice.parse("1d100"), ("1d100", 1, 100, 0))

        self.assertEqual(dice.parse("1d4+1"), ("1d4+1", 1, 4, 1))
        self.assertEqual(dice.parse("1d6+1"), ("1d6+1", 1, 6, 1))
        self.assertEqual(dice.parse("1d8+1"), ("1d8+1", 1, 8, 1))
        self.assertEqual(dice.parse("1d10+1"), ("1d10+1", 1, 10, 1))
        self.assertEqual(dice.parse("1d12+1"), ("1d12+1", 1, 12, 1))
        self.assertEqual(dice.parse("1d20+1"), ("1d20+1", 1, 20, 1))
        self.assertEqual(dice.parse("1d100+1"), ("1d100+1", 1, 100, 1))

        self.assertEqual(dice.parse("1d6+5"), ("1d6+5", 1, 6, 5))
        self.assertEqual(dice.parse("1d6+10"), ("1d6+10", 1, 6, 10))
        self.assertEqual(dice.parse("1d6+100"), ("1d6+100", 1, 6, 100))
        self.assertEqual(dice.parse("1d6+1000"), ("1d6+1000", 1, 6, 1000))

        self.assertEqual(dice.parse("1d6 1d4"), ())
        self.assertEqual(dice.parse("1d3"), ())
        self.assertEqual(dice.parse("1d60"), ())
        self.assertEqual(dice.parse("1d65"), ())
        self.assertEqual(dice.parse("1d69"), ())
        self.assertEqual(dice.parse("1d80"), ())
        self.assertEqual(dice.parse("1d1000"), ())
        self.assertEqual(dice.parse("1d1001"), ())
        self.assertEqual(dice.parse("1d1001"), ())
        self.assertEqual(dice.parse("1d6d10"), ())
        self.assertEqual(dice.parse("10d4d12"), ())
        self.assertEqual(dice.parse("d4"), ())
        self.assertEqual(dice.parse("1d6+5d"), ())
        self.assertEqual(dice.parse("1d6+10d"), ())
        self.assertEqual(dice.parse("1d6+100d"), ())
        self.assertEqual(dice.parse("1d6+1000d"), ())