Beispiel #1
0
        public bool Remove(GameSession session, long uid, short slot, int amount, out Item outItem)
        {
            outItem = null;
            if (session.Player.Inventory.Items.ContainsKey(slot))
            {
                return(false);
            }

            int outItemIndex = Array.FindIndex(Items, 0, Items.Length, x => x != null && x.Uid == uid);

            outItem = Items[outItemIndex];
            if (amount >= outItem.Amount)
            {
                Items[outItemIndex] = null;
                session.Send(StorageInventory.Remove(uid));
                return(true);
            }

            if (outItem.TrySplit(amount, out Item splitItem))
            {
                outItem.Amount -= amount;
                session.Send(StorageInventory.Add(outItem, slot));
                outItem = splitItem;
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        public void Add(GameSession session, long uid, int amount, short slot)
        {
            Item item = session.Player.Inventory.Items[uid];

            if (amount < item.Amount)
            {
                item.TrySplit(amount, out Item splitItem);
                session.Send(ItemInventoryPacket.Update(uid, item.Amount));
                item = splitItem;
            }
            else
            {
                InventoryController.Remove(session, uid, out Item removedItem);
                item = removedItem;
            }

            if (slot >= 0)
            {
                if (Items[slot] == null)
                {
                    Items[slot] = item;
                    session.Send(StorageInventory.Add(item, slot));
                    return;
                }
                else
                {
                    slot = -1;
                }
            }

            if (slot == -1)
            {
                for (slot = 0; slot < Items.Length; slot++)
                {
                    if (Items[slot] != null)
                    {
                        continue;
                    }
                    Items[slot] = item;
                    session.Send(StorageInventory.Add(item, slot));
                    return;
                }
            }
        }