Пример #1
0
        /// <summary>
        /// Wear one object. Optional replacement of existing objects.
        /// Restructured a bit to allow for specifying body location and
        /// added support for layering on certain body locations
        /// </summary>
        public static void WearItem(this CharacterInstance ch, ObjectInstance obj, bool replace, ItemWearFlags wearFlag)
        {
            obj.Split();
            if (ch.Trust < obj.Level)
            {
                ch.Printf("You must be level %d to use this object.", obj.Level);
                comm.act(ATTypes.AT_ACTION, "$n tries to use $p, but is too inexperienced.", ch, obj, null, ToTypes.Room);
                return;
            }

            if (!ch.IsImmortal() && !ch.IsAllowedToUseObject(obj))
            {
                comm.act(ATTypes.AT_MAGIC, "You are forbidden to use that item.", ch, null, null, ToTypes.Character);
                comm.act(ATTypes.AT_ACTION, "$n tries to use $p, but is forbidden to do so.", ch, obj, null, ToTypes.Room);
                return;
            }

            if (obj.ExtraFlags.IsSet((int)ItemExtraFlags.Personal) && ch.Name.EqualsIgnoreCase(obj.Owner))
            {
                ch.SendTo("That item is personalized and belongs to someone else.");
                if (obj.CarriedBy != null)
                {
                    obj.RemoveFrom();
                }
                ch.CurrentRoom.AddTo(obj);
                return;
            }

            // TODO Is this going to replace an item already equipped?

            /*int bit;
             * if (wear_bit > -1)
             * {
             *  bit = wear_bit;
             *  if (!obj.WearFlags.IsSet(1 << bit))
             *  {
             *      if (replace)
             *      {
             *          switch (1 << bit)
             *          {
             *              case (int)ItemWearFlags.Hold:
             *                  ch.SetColor("You cannot hold that.\r\n", ch);
             *                  break;
             *              case (int)ItemWearFlags.Wield:
             *              case (int)ItemWearFlags.MissileWield:
             *                  ch.SetColor("You cannot wield that.\r\n", ch);
             *                  break;
             *              default:
             *                  color.ch_printf(ch, "You cannot wear that on your %s.\r\n", BuilderConstants.w_flags[bit]);
             *                  break;
             *          }
             *      }
             *      return;
             *  }
             * }
             * else
             * {
             *  bit = -1;
             *  for (int x = 1; x < 31; x++)
             *  {
             *      if (obj.WearFlags.IsSet(1 << x))
             *      {
             *          bit = x;
             *          break;
             *      }
             *  }
             * }*/

            if (obj.ItemType == ItemTypes.Light)
            {
                if (!ch.RemoveFrom(WearLocations.Light, replace))
                {
                    return;
                }
                if (!MudProgHandler.ExecuteObjectProg(MudProgTypes.Use, ch, obj, null, null))
                {
                    comm.act(ATTypes.AT_ACTION, "$n holds $p as a light.", ch, obj, null, ToTypes.Room);
                    comm.act(ATTypes.AT_ACTION, "You hold $p as your light.", ch, obj, null, ToTypes.Character);
                }

                ch.Equip(obj, WearLocations.Light);
                MudProgHandler.ExecuteObjectProg(MudProgTypes.Wear, ch, obj);
                return;
            }

            /*if (bit == -1)
             * {
             *  if (replace)
             *      ch.SetColor("You can't wear, wield, or hold that.\r\n", ch);
             *  return;
             * }*/

            if (ItemWearMap.ContainsKey(wearFlag))
            {
                ItemWearMap[wearFlag].Invoke(obj, ch, replace);
            }
            else
            {
                if (wearFlag == ItemWearFlags.Wield || wearFlag == ItemWearFlags.MissileWield)
                {
                    ItemWearWield(obj, ch, replace, wearFlag);
                }
                else
                {
                    LogManager.Instance.Bug("Unknown/Unused ItemWearFlag {0}", wearFlag);
                    if (replace)
                    {
                        ch.SendTo("You can't wear, wield, or hold that.");
                    }
                }
            }
        }
Пример #2
0
        private static void ItemWearWield(ObjectInstance obj, CharacterInstance ch, bool replace, ItemWearFlags wearFlag)
        {
            var strWieldMod = (int)LookupManager.Instance.GetStatMod("Strength", ch.GetCurrentStrength(),
                                                                     StrengthModTypes.Wield);

            if (!ch.CouldDualWield())
            {
                if (!ch.RemoveFrom(WearLocations.WieldMissile, replace) ||
                    !ch.RemoveFrom(WearLocations.Wield, replace))
                {
                    return;
                }
            }
            else
            {
                var tobj = ch.GetEquippedItem(WearLocations.Wield);
                var mw   = ch.GetEquippedItem(WearLocations.WieldMissile);
                var dw   = ch.GetEquippedItem(WearLocations.DualWield);
                var hd   = ch.GetEquippedItem(WearLocations.Hold);
                var sd   = ch.GetEquippedItem(WearLocations.Shield);

                if (CheckFunctions.CheckIfTrue(ch, hd != null && sd != null,
                                               "You are already holding something and wearing a shield."))
                {
                    return;
                }

                if (tobj != null)
                {
                    if (!ch.CanDualWield())
                    {
                        return;
                    }

                    if (CheckFunctions.CheckIfTrue(ch,
                                                   obj.GetWeight() + tobj.GetWeight() > strWieldMod, "It is too heavy for you to wield."))
                    {
                        return;
                    }

                    if (CheckFunctions.CheckIfTrue(ch, hd != null || sd != null,
                                                   "You're already wielding a weapon AND holding something."))
                    {
                        return;
                    }

                    if (!MudProgHandler.ExecuteObjectProg(MudProgTypes.Use, ch, obj, null, null))
                    {
                        comm.act(ATTypes.AT_ACTION, "$n dual-wields $p.", ch, obj, null, ToTypes.Room);
                        comm.act(ATTypes.AT_ACTION, "You dual-wield $p.", ch, obj, null, ToTypes.Character);
                    }

                    ch.Equip(obj, wearFlag == ItemWearFlags.MissileWield
                        ? WearLocations.WieldMissile : WearLocations.DualWield);
                    MudProgHandler.ExecuteObjectProg(MudProgTypes.Wear, ch, obj);
                    return;
                }

                if (mw != null)
                {
                    ItemEquipMissileWeapon(obj, ch, mw, dw, hd, sd);
                    return;
                }
            }

            if (CheckFunctions.CheckIfTrue(ch, obj.GetWeight() > strWieldMod, "It is too heavy for you to wield."))
            {
                return;
            }

            if (!MudProgHandler.ExecuteObjectProg(MudProgTypes.Use, ch, obj, null, null))
            {
                comm.act(ATTypes.AT_ACTION, "$n wields $p.", ch, obj, null, ToTypes.Room);
                comm.act(ATTypes.AT_ACTION, "You wield $p.", ch, obj, null, ToTypes.Character);
            }

            ch.Equip(obj, wearFlag == ItemWearFlags.MissileWield ? WearLocations.WieldMissile : WearLocations.Wield);
            MudProgHandler.ExecuteObjectProg(MudProgTypes.Wear, ch, obj);
        }