Exemplo n.º 1
0
        /// <summary>
        /// When overridden in the derived class, handles when an item has been removed.
        /// </summary>
        /// <param name="item">The item the event is related to.</param>
        /// <param name="slot">The slot of the item the event is related to.</param>
        protected override void OnUnequipped(ItemEntity item, EquipmentSlot slot)
        {
            if (_ignoreEquippedBaseEvents)
            {
                return;
            }

            Debug.Assert(item != null);

            if (IsPersistent)
            {
                DbController.GetQuery <DeleteCharacterEquippedItemQuery>().Execute(Character.ID, slot);
            }

            SendSlotUpdate(slot, null);

            // Do not try working with a disposed ItemEntity! Instead, just let it die off.
            if (item.IsDisposed)
            {
                return;
            }

            var remainder = Character.Inventory.TryAdd(item);

            if (remainder != null)
            {
                const string errmsg =
                    "Character `{0}` removed equipped item `{1}` from slot `{2}`, " +
                    "but not all could be added back to their Inventory.";
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat(errmsg, Character, item, slot);
                }

                // Make the Character drop the remainder
                Character.DropItem(remainder);
            }

            _paperDoll.NotifyRemoved(slot);

            // Make sure we dispose of items where the amount hit 0
            if (item.Amount == 0)
            {
                item.Destroy();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Makes the Character drop an item from their Inventory.
        /// </summary>
        /// <param name="slot">Slot of the item to drop.</param>
        /// <param name="amount">The maximum amount of the item to drop.</param>
        /// <returns>True if the item was successfully dropped, else false.</returns>
        public bool Drop(InventorySlot slot, byte amount)
        {
            // Get the item to drop
            var dropItem = this[slot];

            // Check for an invalid item
            if (dropItem == null)
            {
                const string errmsg = "Could not drop item since no item exists at slot `{0}`.";
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat(errmsg, slot);
                }
                return(false);
            }

            // If the amount to drop is greater than or equal to the amount available, drop it all
            if (dropItem.Amount <= amount)
            {
                // Remove the item from the inventory
                RemoveAt(slot, false);

                // Drop the item
                Character.DropItem(dropItem);
            }
            else
            {
                // Only drop some of the item
                var dropPart = dropItem.Split(amount);

                // Drop the portion of the item
                Character.DropItem(dropPart);
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Makes the Character drop an item from their Inventory.
        /// </summary>
        /// <param name="slot">Slot of the item to drop.</param>
        /// <returns>True if the item was successfully dropped, else false.</returns>
        public bool Drop(InventorySlot slot)
        {
            // Get the item to drop
            var dropItem = this[slot];

            // Check for an invalid item
            if (dropItem == null)
            {
                const string errmsg = "Could not drop item since no item exists at slot `{0}`.";
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat(errmsg, slot);
                }
                return(false);
            }

            // Remove the item from the inventory
            RemoveAt(slot, false);

            // Drop the item
            Character.DropItem(dropItem);

            return(true);
        }