def get_consumable(self, name):
     """Returns the dict object of the consumable, or raises NoConsumable."""
     custom_counters = self.character.get('consumables',
                                          {}).get('custom', {})
     counter = custom_counters.get(name)
     if counter is None: raise ConsumableNotFound()
     return counter
    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.º 3
0
 def delete_consumable(self, name):
     """Deletes a consumable. Returns the Character object."""
     custom_counters = self.character.get('consumables', {}).get('custom', {})
     try:
         del custom_counters[name]
     except KeyError:
         raise ConsumableNotFound()
     self.character['consumables']['custom'] = custom_counters
     return self
Exemplo n.º 4
0
 async def select_consumable(self, ctx, name):
     """@:param name (str): The name of the consumable to search for.
     @:returns dict - the consumable.
     @:raises ConsumableNotFound if the consumable does not exist."""
     custom_counters = self.character.get('consumables', {}).get('custom', {})
     choices = [(cname, counter) for cname, counter in custom_counters.items() if cname.lower() == name.lower()]
     if not choices:
         choices = [(cname, counter) for cname, counter in custom_counters.items() if name.lower() in cname.lower()]
     if not choices:
         raise ConsumableNotFound()
     else:
         return await get_selection(ctx, choices, return_name=True)