예제 #1
0
 def add_known_spell(self, spell, dc: int = None, sab: int = None, mod: int = None):
     """Adds a spell to the character's known spell list."""
     if spell.name in self.spellbook:
         raise InvalidArgument("You already know this spell.")
     sbs = SpellbookSpell.from_spell(spell, dc, sab, mod)
     self.spellbook.spells.append(sbs)
     self.overrides.spells.append(sbs)
예제 #2
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)
예제 #3
0
    def get_spellbook(self):
        if self.character_data is None: raise Exception('You must call get_character() first.')
        potential_spells = [s 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

        spell_lists = {}  # list_id: (ab, dc, scam)
        for sl in self.character_data.get('spellLists', []):
            try:
                ab_calc = sl.get('attackBonus')
                ab = int(self.evaluator.eval(ab_calc))
                dc = int(self.evaluator.eval(sl.get('saveDC')))
                try:
                    scam = self.get_stats().get_mod(next(m for m in STAT_NAMES if m in ab_calc))
                except StopIteration:
                    scam = 0
                spell_lists[sl['_id']] = (ab, dc, scam)
            except:
                pass
        sab, dc, scam = sorted(spell_lists.values(), key=lambda k: k[0], reverse=True)[0] if spell_lists else (0, 0, 0)

        spells = []
        for spell in potential_spells:
            spell_list_id = spell['parent']['id']
            spell_ab, spell_dc, spell_mod = spell_lists.get(spell_list_id, (None, None, None))
            if spell_ab == sab:
                spell_ab = None
            if spell_dc == dc:
                spell_dc = None
            if spell_mod == scam:
                spell_mod = None

            result, strict = search(compendium.spells, spell['name'].strip(), lambda sp: sp.name, strict=True)
            if result and strict:
                spells.append(SpellbookSpell.from_spell(result, sab=spell_ab, dc=spell_dc, mod=spell_mod))
            else:
                spells.append(SpellbookSpell(spell['name'].strip(), sab=spell_ab, dc=spell_dc, mod=spell_mod))

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

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

        return spellbook
예제 #4
0
    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, 0)]  # ab, dc, scam
        for sl in self.character_data.get('spellLists', []):
            try:
                ab_calc = sl.get('attackBonus')
                ab = int(self.evaluator.eval(ab_calc))
                dc = int(self.evaluator.eval(sl.get('saveDC')))
                scam = self.get_stats().get_mod(
                    next(m for m in STAT_NAMES if m in ab_calc))
                spell_lists.append((ab, dc, scam))
            except:
                pass
        sab, dc, scam = sorted(spell_lists, key=lambda k: k[0],
                               reverse=True)[0]

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

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

        return spellbook
예제 #5
0
파일: beyond.py 프로젝트: MobiusMage/avrae
    def _get_spellbook(self):
        spellbook = self.character_data['spellbook']

        max_slots = {'1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0, '9': 0}
        slots = {'1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0, '9': 0}
        for slot in spellbook['slots']:
            slots[str(slot['level'])] = slot['remaining']
            max_slots[str(slot['level'])] = slot['available']

        dcs = []
        sabs = []
        mods = []
        spells = []

        for spell in spellbook['spells']:
            spell_ab = spell['sab']
            spell_dc = spell['dc']
            spell_mod = spell['mod']
            if spell_ab is not None:
                sabs.append(spell_ab)
            if spell_dc is not None:
                dcs.append(spell_dc)
            if spell_mod is not None:
                mods.append(spell_mod)

            result = next((s for s in compendium.spells if s.entity_id == spell['id']), None)

            if result:
                spells.append(SpellbookSpell.from_spell(result, sab=spell_ab, dc=spell_dc, mod=spell_mod))
            else:
                spells.append(SpellbookSpell(spell['name'].strip(), sab=spell_ab, dc=spell_dc, mod=spell_mod))

        dc = max(dcs, key=dcs.count, default=None)
        sab = max(sabs, key=sabs.count, default=None)
        smod = max(mods, key=mods.count, default=None)

        return Spellbook(slots, max_slots, spells, dc, sab, self._get_levels().total_level, smod)
예제 #6
0
파일: beyond.py 프로젝트: 1drturtle/avrae
    def _get_spellbook(self):
        spellbook = self.character_data['spellbook']

        max_slots = {
            '1': 0,
            '2': 0,
            '3': 0,
            '4': 0,
            '5': 0,
            '6': 0,
            '7': 0,
            '8': 0,
            '9': 0
        }
        slots = {
            '1': 0,
            '2': 0,
            '3': 0,
            '4': 0,
            '5': 0,
            '6': 0,
            '7': 0,
            '8': 0,
            '9': 0
        }
        for slot in spellbook['slots']:
            slots[str(slot['level'])] = slot['remaining']
            max_slots[str(slot['level'])] = slot['available']

        dcs = []
        sabs = []
        mods = []
        spells = []

        for spell in spellbook['spells']:
            spell_ab = spell['sab']
            spell_dc = spell['dc']
            spell_mod = spell['mod']
            spell_prepared = spell['prepared'] or 'noprep' in self.args
            if spell_ab is not None:
                sabs.append(spell_ab)
            if spell_dc is not None:
                dcs.append(spell_dc)
            if spell_mod is not None:
                mods.append(spell_mod)

            result = compendium.lookup_entity(gamedata.Spell.entity_type,
                                              spell['id'])

            if result:
                spells.append(
                    SpellbookSpell.from_spell(result,
                                              sab=spell_ab,
                                              dc=spell_dc,
                                              mod=spell_mod,
                                              prepared=spell_prepared))
            else:
                spells.append(
                    SpellbookSpell(spell['name'].strip(),
                                   sab=spell_ab,
                                   dc=spell_dc,
                                   mod=spell_mod,
                                   prepared=spell_prepared))

        dc = max(dcs, key=dcs.count, default=None)
        sab = max(sabs, key=sabs.count, default=None)
        smod = max(mods, key=mods.count, default=None)

        # assumption: a character will only ever have one pact slot level, with a given number of slots of that level
        pact_slot_level = None
        num_pact_slots = None
        max_pact_slots = None
        if spellbook['pactSlots']:
            pact_info = spellbook['pactSlots'][0]
            pact_slot_level = pact_info['level']
            max_pact_slots = pact_info['available']
            num_pact_slots = max_pact_slots - pact_info['used']

        return Spellbook(slots,
                         max_slots,
                         spells,
                         dc,
                         sab,
                         self._get_levels().total_level,
                         smod,
                         pact_slot_level=pact_slot_level,
                         num_pact_slots=num_pact_slots,
                         max_pact_slots=max_pact_slots)