コード例 #1
0
 def add_known_spell(self, spell):
     """Adds a spell to the character's known spell list.
     :param spell (Spell) - the Spell.
     :returns self"""
     if spell.name in self.spellbook:
         raise InvalidArgument("You already know this spell.")
     sbs = SpellbookSpell.from_spell(spell)
     self.spellbook.spells.append(sbs)
     self.overrides.spells.append(sbs)
コード例 #2
0
ファイル: dicecloud.py プロジェクト: danielberes/avrae
    def get_spellbook(self):
        if self.character_data is None:
            raise Exception('You must call get_character() first.')
        spellnames = [
            s.get('name', '') for s in self.character_data.get('spells', [])
            if not s.get('removed', False)
        ]

        slots = {}
        for lvl in range(1, 10):
            num_slots = int(self.calculate_stat(f"level{lvl}SpellSlots"))
            slots[str(lvl)] = num_slots

        spells = []
        for spell in spellnames:
            result = search(compendium.spells, spell.strip(),
                            lambda sp: sp.name)
            if result and result[0] and result[1]:
                spells.append(SpellbookSpell.from_spell(result[0]))
            else:
                spells.append(SpellbookSpell(spell.strip()))

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

        spellbook = Spellbook(slots, slots, spells, dc, sab,
                              self.get_levels().total_level)

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

        return spellbook