Exemplo n.º 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))
Exemplo n.º 2
0
 async def game_spellslot(self, ctx, level: int = None, value: str = None):
     """Views or sets your remaining spell slots."""
     if level is not None:
         try:
             assert 0 < level < 10
         except AssertionError:
             return await ctx.send("Invalid spell level.")
     character: Character = await Character.from_ctx(ctx)
     embed = EmbedWithCharacter(character)
     embed.set_footer(text="\u25c9 = Available / \u3007 = Used")
     if level is None and value is None:  # show remaining
         embed.description = f"__**Remaining Spell Slots**__\n{character.spellbook.slots_str()}"
     elif value is None:
         embed.description = f"__**Remaining Level {level} Spell Slots**__\n" \
                             f"{character.spellbook.slots_str(level)}"
     else:
         try:
             if value.startswith(('+', '-')):
                 value = character.spellbook.get_slots(level) + int(value)
             else:
                 value = int(value)
         except ValueError:
             return await ctx.send(f"{value} is not a valid integer.")
         try:
             assert 0 <= value <= character.spellbook.get_max_slots(level)
         except AssertionError:
             raise CounterOutOfBounds()
         character.spellbook.set_slots(level, value)
         await character.commit(ctx)
         embed.description = f"__**Remaining Level {level} Spell Slots**__\n" \
                             f"{character.spellbook.slots_str(level)}"
     await ctx.send(embed=embed)
    def set_consumable(self, name, newValue: int, strict=False):
        """Sets the value of a character's consumable, returning the Character object.
        Raises CounterOutOfBounds if newValue is out of bounds."""
        self._initialize_custom_counters()
        try:
            assert self.character['consumables']['custom'].get(
                name) is not None
        except AssertionError:
            raise ConsumableNotFound()
        try:
            _min = self.evaluate_cvar(
                self.character['consumables']['custom'][name].get(
                    'min', str(-(2**32))))
            _max = self.evaluate_cvar(
                self.character['consumables']['custom'][name].get(
                    'max', str(2**32 - 1)))
            if strict:
                assert _min <= int(newValue) <= _max
            else:
                newValue = min(max(_min, int(newValue)), _max)

        except AssertionError:
            raise CounterOutOfBounds()
        self.character['consumables']['custom'][name]['value'] = int(newValue)

        if self.character['consumables']['custom'][name].get(
                'live') and self.live:
            used = _max - newValue
            self._sync_consumable(
                self.character['consumables']['custom'][name], used)

        return self
Exemplo n.º 4
0
 def cast(self, spell, level, pact=True):
     if spell.name.lower() in [s.lower() for s in self.at_will]:
         return
     elif (daily_key := next((k for k in self.daily if spell.name.lower() == k.lower()), None)) is not None:
         if self.daily[daily_key] > 0:
             self.daily[daily_key] -= 1
         else:
             raise CounterOutOfBounds(f"You do not have any remaining casts of {spell.name}.")
Exemplo n.º 5
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
Exemplo n.º 6
0
    def set(self, new_value: int, strict=False):
        minv = self.get_min()
        maxv = self.get_max()

        if strict:
            if new_value < minv:
                raise CounterOutOfBounds(
                    f"You do not have enough remaining uses of {self.name}.")
            elif new_value > maxv:
                raise CounterOutOfBounds(
                    f"{self.name} cannot be set to {new_value} (max {maxv}).")

        new_value = int(min(max(minv, new_value), maxv))
        old_value = self._value
        self._value = new_value

        if self.live_id and new_value != old_value:
            self._character.sync_consumable(self)
        return self._value
Exemplo n.º 7
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)
Exemplo n.º 8
0
    def set(self, new_value: int, strict=False):
        minv = self.get_min()
        maxv = self.get_max()

        if strict and not minv <= new_value <= maxv:
            raise CounterOutOfBounds()

        new_value = min(max(minv, new_value), maxv)
        self._value = new_value

        if self.live_id:
            self._character.sync_consumable(self)
 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
Exemplo n.º 10
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)
Exemplo n.º 11
0
    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)
Exemplo n.º 12
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