コード例 #1
0
ファイル: BaseInventory.cs プロジェクト: uvbs/Asda2-Server
        /// <summary>
        /// Tries to add a new item with the given template and amount ot the given slot.
        /// Make sure the given targetSlot is valid before calling this method.
        /// </summary>
        /// <returns>The result (InventoryError.OK in case that it worked)</returns>
        public InventoryError TryAdd(ItemTemplate template, ref int amount, int slot,
                                     ItemReceptionType reception = ItemReceptionType.Receive)
        {
            if (this.m_Items[slot] != null)
            {
                LogManager.GetCurrentClassLogger().Warn("Tried to add Item {0} to {1} in occupied slot {2}",
                                                        (object)template, (object)this, (object)slot);
                return(InventoryError.ITEM_DOESNT_GO_TO_SLOT);
            }

            InventoryError err = InventoryError.OK;

            this.CheckUniqueness((IMountableItem)template, ref amount, ref err, true);
            if (err == InventoryError.OK)
            {
                IItemSlotHandler handler = this.GetHandler(slot);
                if (handler != null)
                {
                    err = InventoryError.OK;
                    handler.CheckAdd(slot, amount, (IMountableItem)template, ref err);
                    if (err != InventoryError.OK)
                    {
                        return(err);
                    }
                }

                this.OnAdded(this.AddUnchecked(slot, template, amount, true), template, amount, reception);
            }

            return(err);
        }
コード例 #2
0
ファイル: BaseInventory.cs プロジェクト: uvbs/Asda2-Server
        /// <summary>
        ///
        /// </summary>
        /// <param name="slot"></param>
        /// <param name="item"></param>
        /// <param name="amount"></param>
        /// <returns></returns>
        public InventoryError CheckAdd(int slot, IMountableItem item, int amount)
        {
            IItemSlotHandler handler = this.GetHandler(slot);

            if (handler == null)
            {
                return(InventoryError.OK);
            }
            InventoryError err = InventoryError.OK;

            handler.CheckAdd(slot, amount, item, ref err);
            return(err);
        }
コード例 #3
0
        private bool CheckFreeSlots(IList <SimpleSlotId> myFreeSlots, Item[] items)
        {
            bool flag   = true;
            int  index1 = 0;

            for (int index2 = 0; index2 < 6; ++index2)
            {
                if (items[index2] != null)
                {
                    if (myFreeSlots.Count <= index1)
                    {
                        flag = false;
                        break;
                    }

                    int              slot      = myFreeSlots[index1].Slot;
                    BaseInventory    container = myFreeSlots[index1].Container;
                    IItemSlotHandler handler   = container.GetHandler(slot);
                    InventoryError   err       = InventoryError.OK;
                    handler.CheckAdd(slot, items[index2].Amount, items[index2], ref err);
                    if (err != InventoryError.OK)
                    {
                        flag = false;
                        break;
                    }

                    int amount = items[index2].Amount;
                    container.CheckUniqueness(items[index2], ref amount, ref err, true);
                    if (err != InventoryError.OK)
                    {
                        flag = false;
                        break;
                    }

                    ++index1;
                }
            }

            if (!flag)
            {
                m_chr.SendSystemMessage("You don't have enough free slots");
                m_otherWindow.m_chr.SendSystemMessage("Other party doesn't have enough free slots");
                SendStatus(TradeStatus.StateChanged, true);
            }

            return(flag);
        }
コード例 #4
0
ファイル: BaseInventory.cs プロジェクト: uvbs/Asda2-Server
        /// <summary>
        /// Tries to merge an item with the given template and amount to the stack at the given slot.
        /// If the given slot is empty it adds the item to the slot.
        /// Make sure the given targetSlot is valid before calling this method.
        /// </summary>
        /// <param name="amount">Set to the number of items actually added.</param>
        /// <returns>The result (InventoryError.OK in case that it worked)</returns>
        public InventoryError TryMerge(ItemTemplate template, ref int amount, int slot, bool isNew)
        {
            InventoryError err = InventoryError.OK;

            this.CheckUniqueness((IMountableItem)template, ref amount, ref err, isNew);
            if (err == InventoryError.OK)
            {
                IItemSlotHandler handler = this.GetHandler(slot);
                if (handler != null)
                {
                    err = InventoryError.OK;
                    handler.CheckAdd(slot, amount, (IMountableItem)template, ref err);
                    if (err != InventoryError.OK)
                    {
                        return(err);
                    }
                }

                this.MergeUnchecked(slot, template, ref amount, isNew);
            }

            return(err);
        }