예제 #1
0
    def set_slots(self, level: int, value: int, pact=True):
        """
        Sets the remaining number of spell slots (pact+non-pact) of a given level. If *pact* is True (default), will
        also modify *num_pact_slots* if applicable, otherwise will only affect *slots*.
        """
        if not 0 < level < 10:
            raise InvalidSpellLevel()
        lmax = self.get_max_slots(level)
        if value < 0:
            raise CounterOutOfBounds(
                f"You do not have enough remaining level {level} spell slots.")
        elif value > lmax:
            raise CounterOutOfBounds(
                f"You may not have this many level {level} spell slots (max {lmax})."
            )

        delta = value - self.get_slots(level)
        self.slots[str(level)] = value

        if pact and level == self.pact_slot_level and self.max_pact_slots is not None:  # attempt to modify pact first
            self.num_pact_slots = max(
                min(self.num_pact_slots + delta, self.max_pact_slots), 0)
        elif level == self.pact_slot_level and self.max_pact_slots is not None:  # make sure pact slots are valid
            self.num_pact_slots = max(min(self.num_pact_slots, value),
                                      value - (lmax - self.max_pact_slots))
예제 #2
0
 def set_slots(self, level: int, value: int):
     """
     Sets the remaining number of spell slots of a given level.
     """
     if not 0 < level < 10:
         raise InvalidSpellLevel()
     if not 0 <= value <= self.get_max_slots(level):
         raise CounterOutOfBounds()
     self.slots[str(level)] = value
 def get_remaining_slots(self, level: int):
     """@:param level - The spell level.
     @:returns the integer value representing the number of spellslots remaining."""
     try:
         assert 0 <= level < 10
     except AssertionError:
         raise InvalidSpellLevel()
     if level == 0: return 1  # cantrips
     return int(self.get_spellslots()[str(level)]['value'])
예제 #4
0
 def set_remaining_slots(self, level: int, value: int):
     """
     Sets the actor's remaining spell slots of level level.
     :param level - The spell level.
     :param value - The number of remaining spell slots.
     """
     if not 0 < level < 10:
         raise InvalidSpellLevel()
     if not 0 <= value <= self.spellbook.get_max_slots(level):
         raise CounterOutOfBounds()
     self.spellbook.set_slots(level, value)
 def use_slot(self, level: int):
     """Uses one spell slot of level level.
     @:returns self
     @:raises CounterOutOfBounds if there are no remaining slots of the requested level."""
     try:
         assert 0 <= level < 10
     except AssertionError:
         raise InvalidSpellLevel()
     if level == 0: return self
     ss = self.get_spellslots()
     val = ss[str(level)]['value'] - 1
     if val < ss[str(level)]['min']: raise CounterOutOfBounds()
     self.set_remaining_slots(level, val)
     return self
예제 #6
0
    def use_slot(self, level: int):
        """Uses one spell slot of level level.
        :raises CounterOutOfBounds if there are no remaining slots of the requested level."""
        if level == 0:
            return
        if not 0 < level < 10:
            raise InvalidSpellLevel()

        val = self.spellbook.get_slots(level) - 1
        if val < 0:
            raise CounterOutOfBounds(
                "You do not have any spell slots of this level remaining.")

        self.set_remaining_slots(level, val)
예제 #7
0
파일: spellcasting.py 프로젝트: avrae/avrae
    def use_slot(self, level: int, pact=True):
        """
        Uses one spell slot of level level. Does nothing if level is 0.

        :raises CounterOutOfBounds if there are no remaining slots of the requested level.
        """
        if level == 0:
            return
        if not 0 < level < 10:
            raise InvalidSpellLevel()

        val = self.get_slots(level) - 1
        if val < 0:
            raise CounterOutOfBounds(f"You do not have any level {level} spell slots remaining.")

        self.set_slots(level, val, pact=pact)
예제 #8
0
    def set_remaining_slots(self, level: int, value: int, sync: bool = True):
        """Sets the character's remaining spell slots of level level.
        @:param level - The spell level.
        @:param value - The number of remaining spell slots.
        @:returns self"""
        try:
            assert 0 < level < 10
        except AssertionError:
            raise InvalidSpellLevel()
        try:
            assert 0 <= value <= self.get_max_spellslots(level)
        except AssertionError:
            raise CounterOutOfBounds()

        self._initialize_spellslots()
        self.character['consumables']['spellslots'][str(level)]['value'] = int(value)

        if self.live and sync:
            self._sync_slots()

        return self