# Path: DnD/modules/lib/exceptionsLib.py
# class OutOfSpells(SpellError):
#     def __init__(self, spell):
#         self.spell = spell
# 
#     def __str__(self):
#         formatstr = 'You have no spell slots of level {lv} remaining.'
#         return formatstr.format(lv=(self.spell if isinstance(self.spell, int)
#                                     else self.spell.level))
# 
# class OutOfItems(DnDError):
#     def __init__(self, name):
#         self.name = name
# 
#     def __str__(self):
#         formatstr = 'You have no {item}s remaining.'
#         return formatstr.format(item=self.name)
# 
# class LowOnResource(DnDError):
#     def __init__(self, resource):
#         self.resource = resource
# 
#     def __str__(self):
#         formatstr = 'You have no {rs} remaining.'
#         return formatstr.format(rs=self.resource.name)
# 
# Path: DnD/modules/lib/settingsLib.py
# class Settings:
#     def __init__(self, jf: JsonInterface):
#         self.record = jf
# 
#     @property
#     def healing(self) -> 'HealingMode':
#         return self.record.get('/HEALING') or HealingMode.VANILLA
# 
#     @healing.setter
#     def healing(self, value: 'HealingMode'):
#         self.record.set('/HEALING', value)
# 
#     @property
#     def spellPoints(self) -> bool:
#         return self.record.get('/SPELL_POINTS') or False
# 
#     @spellPoints.setter
#     def spellPoints(self, value: bool):
#         self.record.set('/SPELL_POINTS', value)
# 
#     @property
#     def proficiencyDice(self) -> bool:
#         return self.record.get('/PROFICIENCY_DICE') or False
# 
#     @proficiencyDice.setter
#     def proficiencyDice(self, value: bool):
#         self.record.set('/PROFICIENCY_DICE', value)
# 
#     def serialize(self):
#         rv = {}
#         if self.healing != HealingMode.VANILLA:
#             rv['HEALING'] = self.healing
#         if self.spellPoints:
#             rv['SPELL_POINTS'] = True
#         if self.proficiencyDice:
#             rv['PROFICIENCY_DICE'] = True
#         return rv


import re
import dndice as r
from collections import OrderedDict
from functools import wraps
from math import ceil
from . import helpers as h
from . import interface as iface
from .exceptionsLib import OutOfSpells, OutOfItems, LowOnResource
from .settingsLib import Settings
                return False

    def register_attacks(self):
        rv = {}
        for item in self.inventory:
            if isinstance(item.obj, Attack):
                rv[item.name] = item
        for sp in self.spells:
            if isinstance(sp, SpellAttack):
                rv[sp.name] = sp
        return rv

    def spell_spend(self, spell):
        if isinstance(spell, int):
            lv = spell
            path = '/spell_slots/' + str(spell)
        else:
            lv = spell.level
            path = '/spell_slots/' + str(spell.level)
        num = self.record.get(path)
        if num > 0:
            self.record.set(path, num - 1)
        else:
            for val in range(lv, len(self.spell_slots)):
                path = '/spell_slots/' + str(val)
                num = self.record.get(path)
                if num is not None and num > 0:
                    self.record.set(path, num - 1)
                    return None
            # If it fails to find a spell slot, you're out of spells

# Path: DnD/modules/lib/exceptionsLib.py
# class OutOfSpells(SpellError):
#     def __init__(self, spell):
#         self.spell = spell
# 
#     def __str__(self):
#         formatstr = 'You have no spell slots of level {lv} remaining.'
#         return formatstr.format(lv=(self.spell if isinstance(self.spell, int)
#                                     else self.spell.level))
# 
# class OutOfItems(DnDError):
#     def __init__(self, name):
#         self.name = name
# 
#     def __str__(self):
#         formatstr = 'You have no {item}s remaining.'
#         return formatstr.format(item=self.name)
# 
# class LowOnResource(DnDError):
#     def __init__(self, resource):
#         self.resource = resource
# 
#     def __str__(self):
#         formatstr = 'You have no {rs} remaining.'
#         return formatstr.format(rs=self.resource.name)
# 
# Path: DnD/modules/lib/settingsLib.py
# class Settings:
#     def __init__(self, jf: JsonInterface):
#         self.record = jf
# 
#     @property
#     def healing(self) -> 'HealingMode':
#         return self.record.get('/HEALING') or HealingMode.VANILLA
# 
#     @healing.setter
#     def healing(self, value: 'HealingMode'):
#         self.record.set('/HEALING', value)
# 
#     @property
#     def spellPoints(self) -> bool:
#         return self.record.get('/SPELL_POINTS') or False
# 
#     @spellPoints.setter
#     def spellPoints(self, value: bool):
#         self.record.set('/SPELL_POINTS', value)
# 
#     @property
#     def proficiencyDice(self) -> bool:
#         return self.record.get('/PROFICIENCY_DICE') or False
# 
#     @proficiencyDice.setter
#     def proficiencyDice(self, value: bool):
#         self.record.set('/PROFICIENCY_DICE', value)
# 
#     def serialize(self):
#         rv = {}
#         if self.healing != HealingMode.VANILLA:
#             rv['HEALING'] = self.healing
#         if self.spellPoints:
#             rv['SPELL_POINTS'] = True
#         if self.proficiencyDice:
#             rv['PROFICIENCY_DICE'] = True
#         return rv


# Path: DnD/modules/lib/classes.py
import re
import dndice as r
from collections import OrderedDict
from functools import wraps
from math import ceil
from . import helpers as h
from . import interface as iface
from .exceptionsLib import OutOfSpells, OutOfItems, LowOnResource
from .settingsLib import Settings

                return False

    def register_attacks(self):
        rv = {}
        for item in self.inventory:
            if isinstance(item.obj, Attack):
                rv[item.name] = item
        for sp in self.spells:
            if isinstance(sp, SpellAttack):
                rv[sp.name] = sp
        return rv

    def spell_spend(self, spell):
        if isinstance(spell, int):
            lv = spell
            path = '/spell_slots/' + str(spell)
        else:
            lv = spell.level
            path = '/spell_slots/' + str(spell.level)
        num = self.record.get(path)
        if num > 0:
            self.record.set(path, num - 1)
        else:
            for val in range(lv, len(self.spell_slots)):
                path = '/spell_slots/' + str(val)
                num = self.record.get(path)
                if num is not None and num > 0:
                    self.record.set(path, num - 1)
                    return None
            # If it fails to find a spell slot, you're out of spells

            raise (OutOfSpells(spell))