Example #1
0
        private bool WearItem(IEquipable item, bool replace) // equivalent to wear_obj in act_obj.C:1467
        {
            // TODO: check level
            WearLocations wearLocation = item.WearLocation;

            if (wearLocation == WearLocations.None)
            {
                Log.Default.WriteLine(LogLevels.Warning, "Item {0} cannot be equiped", item.DebugName);
                if (replace) // replace means, only item is trying to be worn
                {
                    Act(ActOptions.ToCharacter, "{0} cannot be worn.", item);
                }
                return(false);
            }
            EquipedItem equipmentSlot = SearchEquipmentSlot(item, replace);

            if (equipmentSlot == null)
            {
                if (replace) // we dont' want to spam if character is trying to wear all, replace is set to true only when wearing one item
                {
                    Act(ActOptions.ToCharacter, "You cannot wear {0}.", item);
                }
                return(false);
            }
            if (replace && equipmentSlot.Item != null)
            {
                IEquipable removeItem = equipmentSlot.Item;
                //Act(ActOptions.ToCharacter, "You remove {0}.", removeItem);
                //Act(ActOptions.ToRoom, "{0} removes {1}.", this, removeItem);
                Act(ActOptions.ToAll, "{0:N} remove{0:v} {1}.", this, removeItem);
                //equipmentSlot.Item = null  already done by ChangeEquipedBy
                removeItem.ChangeEquipedBy(null);
                removeItem.ChangeContainer(this);
            }
            // TODO: different phrase depending on wear location
            //Act(ActOptions.ToCharacter, "You wear {0}.", item);
            //Act(ActOptions.ToRoom, "{0} wears {1}.", this, item);
            Act(ActOptions.ToAll, "{0:N} wear{0:v} {1}.", this, item);
            equipmentSlot.Item = item;  // equip
            item.ChangeContainer(null); // remove from inventory
            item.ChangeEquipedBy(this); // set as equiped by this
            return(true);
        }
Example #2
0
        public static bool RemoveFrom(this CharacterInstance ch, WearLocations location, bool replace)
        {
            var obj = ch.GetEquippedItem(location);

            if (obj == null)
            {
                return(true);
            }

            if (!replace && ch.CarryNumber + obj.ObjectNumber > ch.CanCarryN())
            {
                comm.act(ATTypes.AT_PLAIN, "$d: you can't carry that many items.", ch, null, obj.ShortDescription,
                         ToTypes.Character);
                return(false);
            }

            if (!replace)
            {
                return(false);
            }

            if (obj.ExtraFlags.IsSet((int)ItemExtraFlags.NoRemove))
            {
                comm.act(ATTypes.AT_PLAIN, "You can't remove $p.", ch, obj, null, ToTypes.Character);
                return(false);
            }

            var tObj = ch.GetEquippedItem(WearLocations.DualWield);

            if (obj == ch.GetEquippedItem(WearLocations.Wield) && tObj != null)
            {
                tObj.WearLocation = WearLocations.Wield;
            }

            ch.Unequip(obj);

            comm.act(ATTypes.AT_ACTION, "$n stop using $p.", ch, obj, null, ToTypes.Room);
            comm.act(ATTypes.AT_ACTION, "You stop using $p.", ch, obj, null, ToTypes.Character);
            MudProgHandler.ExecuteObjectProg(MudProgTypes.Remove, ch, obj);

            return(ch.GetEquippedItem(location) == null);
        }