Example #1
0
 def wear(self):
     """Tries to wear our apparel and wield our weapons. Raises EquipErrors."""
     try:
         self.owner_character.undress()
     except CombatError as err:
         raise EquipError(
             str(err) + "\nUndress failed. " + self.equipped_msg)
     except EquipError as err:
         pass
     wield_err, wear_err, = "", ""
     try:
         to_wield = list(
             self.weapons.filter(
                 modusornamenta__slot__istartswith='primary').distinct())
         if to_wield:
             self.owner_character.equip_or_remove("wield", list(to_wield))
     except EquipError as err:
         wield_err = str(err)
     try:
         to_wear = list(self.apparel)
         sheathed = list(
             self.weapons.exclude(
                 modusornamenta__slot__istartswith='primary').distinct())
         to_wear.extend(sheathed)
         if to_wear:
             self.owner_character.equip_or_remove("wear", to_wear)
     except EquipError as err:
         wear_err = str(err)
     if wield_err or wear_err:
         msg = "\n".join(
             [ob for ob in (wield_err, wear_err, self.equipped_msg) if ob])
         raise EquipError(msg)
     else:
         self.owner_character.msg(self.equipped_msg)
Example #2
0
 def at_pre_wear(self, wearer):
     """Hook called before wearing for any checks."""
     if self.is_worn:
         raise EquipError("already worn")
     if self.location != wearer:
         raise EquipError("misplaced")
     self.slot_check(wearer)
Example #3
0
 def at_pre_wield(self, wielder):
     """Hook called before wielding for any checks."""
     if self.is_wielded:
         raise EquipError("already wielded")
     if self.location != wielder:
         raise EquipError("misplaced")
     if any(wielder.wielded):
         raise EquipError("other weapon in use")
     if self.is_worn:
         self.remove(wielder)
Example #4
0
    def equip_or_remove(self, verb, item_list=None):
        """
        A list of items is worn, wielded, or removed from a character.

            Args:
                verb (str): the method to call
                item_list (list): objects we attempt to call method in

        Will try to call the method matching our verb for each list item. If no
        list is given, we build list from character contents. A message is
        crafted for success or exception (failure). Total success means results
        are messaged to self. Otherwise result is raised as an EquipError.
        """
        cscript = self.location.ndb.combat_manager
        if (cscript and cscript.ndb.phase != 1
                and cscript.check_character_is_combatant(self)):
            from typeclasses.scripts.combat.combat_settings import CombatError

            raise CombatError(
                "Equipment changes are only allowed in combat's setup phase.")
        if verb in ("wear", "sheathe"):
            alt = verb if verb == "sheathe" else "put on"
            verb = "wear"
        elif verb == "wield":
            alt = "brandish"
        else:
            verb, alt = "remove", "remove"
        if not item_list:
            item_list = self.get_item_list_to_equip(verb)
            if not item_list:
                raise EquipError("You have nothing to %s." % verb)
        successes, failures = [], []
        for item in item_list:
            try:
                getattr(item, verb)(self)
            except AttributeError:
                failures.append("%s |w(wrong item type)|n" % item)
            except EquipError as err:
                failures.append("%s |w(%s)|n" % (item, err))
            else:
                successes.append(str(item))
        msg = ""
        if failures:
            msg += "Could not %s %s.\n" % (
                alt, list_to_string(failures, endsep="or"))
        if successes:
            msg += "You %s %s." % (alt, list_to_string(successes))
        elif len(item_list
                 ) > 1:  # no successes and also multiple items attempted
            msg += "|yYou %s nothing.|n" % alt
        if failures:
            raise EquipError(msg)
        else:
            self.msg(msg)
Example #5
0
 def slot_check(self, wearer):
     if self.decorative:
         super(Wieldable, self).slot_check(wearer)
     else:
         sheathed = wearer.sheathed
         if len(sheathed) >= self.SHEATHED_LIMIT:
             raise EquipError("sheathed limit reached")
Example #6
0
 def remove(self):
     """Tries to remove all our fashion_items. Raises EquipErrors."""
     try:
         self.owner_character.equip_or_remove(
             "remove", list(self.fashion_items.all()))
     except (CombatError, EquipError) as err:
         raise EquipError(err)
Example #7
0
 def remove(self, wearer):
     """
     Takes off the armor
     """
     if not self.is_worn:
         raise EquipError("not equipped")
     self.is_worn = False
     self.at_post_remove(wearer)
Example #8
0
 def equip_or_remove_outfit(self):
     from world.fashion.fashion_commands import get_caller_outfit_from_args
     outfit = get_caller_outfit_from_args(self.caller, self.args)
     if not outfit.is_carried:
         raise EquipError(
             "Outfit components must be on your person and not in any containers."
         )
     getattr(outfit, self.cmdstring.lower())()
Example #9
0
 def func(self):
     from typeclasses.scripts.combat.combat_settings import CombatError
     try:
         if not self.args:
             raise EquipError("What are you trying to %s?" % self.cmdstring.lower())
         self.wield_or_sheathe_item()
     except (CombatError, EquipError) as err:
         self.msg(err)
Example #10
0
 def func(self):
     cmdstr = self.cmdstring.lower()
     undress = cmdstr in self.undress_cmds
     remove_all = all((cmdstr == "remove", self.args, self.args == "all"))
     from typeclasses.scripts.combat.combat_settings import CombatError
     from world.fashion.exceptions import FashionError
     try:
         if undress or remove_all:
             self.caller.undress()
             return
         elif not self.args:
             raise EquipError("What are you trying to %s?" % cmdstr)
         if "outfit" in self.switches or "outfits" in self.switches:
             self.equip_or_remove_outfit()
         else:
             self.wear_or_remove_item()
     except (CombatError, EquipError, FashionError) as err:
         self.msg(err)
Example #11
0
 def slot_check(self, wearer):
     slot, slot_limit = self.slot, self.slot_limit
     if slot and slot_limit:
         worn = [ob for ob in wearer.worn if ob.slot == slot]
         if len(worn) >= slot_limit:
             raise EquipError(f"{slot} slot full. Worn there: {worn}")
Example #12
0
 def slot_check(self, wearer):
     slot, slot_limit = self.slot, self.slot_limit
     if slot and slot_limit:
         worn = [ob for ob in wearer.worn if ob.slot == slot]
         if len(worn) >= slot_limit:
             raise EquipError("%s slot full" % slot)