示例#1
0
    def get_spellbook(self):
        if self.character is None:
            raise Exception('You must call get_character() first.')
        spellbook = {'spellslots': {}, 'spells': [], 'dc': 0, 'attackBonus': 0}

        for lvl in range(1, 10):
            try:
                numSlots = int(self.character.get(f"SlotsTot{lvl}") or 0)
            except ValueError:
                numSlots = 0
            spellbook['spellslots'][str(lvl)] = numSlots

        spellnames = set([
            self.character.get(f"Spells{n}") for n in range(1, 101)
            if self.character.get(f"Spells{n}")
        ])

        for spell in spellnames:
            s = fuzzy_search(c.spells, 'name', spell.strip())
            if s:
                spellbook['spells'].append(s.get('name'))

        try:
            spellbook['dc'] = int(self.character.get('SpellSaveDC', 0) or 0)
        except ValueError:
            pass

        try:
            spellbook['attackBonus'] = int(self.character.get('SAB', 0) or 0)
        except ValueError:
            pass

        log.debug(f"Completed parsing spellbook: {spellbook}")
        return spellbook
示例#2
0
    async def monster_atk(self,
                          ctx,
                          monster_name,
                          atk_name='list',
                          *,
                          args=''):
        """Rolls a monster's attack.
        Attack name can be "list" for a list of all of the monster's attacks.
        Valid Arguments: adv/dis
                         -ac [target ac]
                         -b [to hit bonus]
                         -d [damage bonus]
                         -d# [applies damage to the first # hits]
                         -rr [times to reroll]
                         -t [target]
                         -phrase [flavor text]
                         crit (automatically crit)"""

        try:
            await self.bot.delete_message(ctx.message)
        except:
            pass

        monster = await select_monster_full(ctx, monster_name)
        self.bot.rdb.incr('monsters_looked_up_life')
        attacks = monster.attacks
        monster_name = monster.get_title_name()
        if atk_name == 'list':
            attacks_string = '\n'.join(
                "**{0}:** +{1} To Hit, {2} damage.".format(
                    a['name'], a['attackBonus'], a['damage'] or 'no')
                for a in attacks)
            return await self.bot.say("{}'s attacks:\n{}".format(
                monster_name, attacks_string))
        attack = fuzzy_search(attacks, 'name', atk_name)
        if attack is None:
            return await self.bot.say("No attack with that name found.",
                                      delete_after=15)

        args = shlex.split(args)
        args = argparse(args)
        args['name'] = [monster_name]
        args['image'] = args.get('image') or [monster.get_image_url()]
        attack['details'] = attack.get('desc') or attack.get('details')

        result = sheet_attack(attack, args)
        embed = result['embed']
        embed.colour = random.randint(0, 0xffffff)
        embeds.add_fields_from_args(embed, args.get('f'))

        if monster.source == 'homebrew':
            embed.set_footer(text="Homebrew content.",
                             icon_url="https://avrae.io/static/homebrew.png")

        await self.bot.say(embed=embed)
示例#3
0
    def get_spellbook(self):
        if self.character is None:
            raise Exception('You must call get_character() first.')
        spellbook = {
            'spellslots': {},
            'spells': [],
            'dc':
            0,
            'attackBonus':
            0,
            'dicecloud_id':
            next((sl['_id'] for sl in self.character.get('spellLists', [])
                  if not sl.get('removed')), None)
        }

        spells = self.character.get('spells', [])
        spellnames = [
            s.get('name', '') for s in spells if not s.get('removed', False)
        ]

        for lvl in range(1, 10):
            numSlots = self.calculate_stat(f"level{lvl}SpellSlots")
            spellbook['spellslots'][str(lvl)] = numSlots

        for spell in spellnames:
            s = fuzzy_search(c.spells, 'name', spell.strip())
            if s:
                spellbook['spells'].append(s.get('name'))

        sls = [(0, 0)]  # ab, dc
        for sl in self.character.get('spellLists', []):
            try:
                ab = int(self.evaluator.eval(sl.get('attackBonus')))
                dc = int(self.evaluator.eval(sl.get('saveDC')))
                sls.append((ab, dc))
            except:
                pass
        sl = sorted(sls, key=lambda k: k[0], reverse=True)[0]
        spellbook['attackBonus'] = sl[0]
        spellbook['dc'] = sl[1]

        log.debug(f"Completed parsing spellbook: {spellbook}")

        return spellbook
示例#4
0
    def get_spellbook(self):
        if self.character is None: raise Exception('You must call get_character() first.')
        spellbook = {'spellslots': {},
                     'spells': [],  # C96:AH143 - gah.
                     'dc': 0,
                     'attackBonus': 0}

        spellslots = {'1': int(self.character.cell('AK101').value or 0),
                      '2': int(self.character.cell('E107').value or 0),
                      '3': int(self.character.cell('AK113').value or 0),
                      '4': int(self.character.cell('E119').value or 0),
                      '5': int(self.character.cell('AK124').value or 0),
                      '6': int(self.character.cell('E129').value or 0),
                      '7': int(self.character.cell('AK134').value or 0),
                      '8': int(self.character.cell('E138').value or 0),
                      '9': int(self.character.cell('AK142').value or 0)}
        spellbook['spellslots'] = spellslots

        potential_spells = self.character.range('C96:AH143')
        spells = set()

        for col in potential_spells:
            for cell in col:
                if cell.value and not cell.value in ('MAX', 'SLOTS'):
                    s = fuzzy_search(c.spells, 'name', cell.value.strip())
                    if s:
                        spells.add(s.get('name'))

        spellbook['spells'] = list(spells)

        try:
            spellbook['dc'] = int(self.character.cell('AB91').value or 0)
        except ValueError:
            pass

        try:
            spellbook['attackBonus'] = int(self.character.cell('AI91').value or 0)
        except ValueError:
            pass

        log.debug(f"Completed parsing spellbook: {spellbook}")
        return spellbook