コード例 #1
0
        public Inventory CreateItem(InventoryItem newItem, Character character)
        {
            short Slot = -1;
            IEnumerable <InventoryItem> slotfree = null;
            Inventory inv = null;

            if (ServerManager.GetItem(newItem.ItemVNum).Type != 0)
            {
                slotfree = character.LoadBySlotAllowed(newItem.ItemVNum, newItem.Amount);
                inv      = getFirstSlot(slotfree);
            }
            bool      modified     = false;
            Inventory newInventory = null;

            if (inv != null)
            {
                Slot           = inv.Slot;
                newItem.Amount = (short)(newItem.Amount + inv.InventoryItem.Amount);
                modified       = true;
            }
            else
            {
                Slot = getFirstPlace(ServerManager.GetItem(newItem.ItemVNum).Type, character.BackPack, newItem);
            }
            if (Slot != -1)
            {
                if (modified == false)
                {
                    newInventory = new Inventory()
                    {
                        CharacterId     = character.CharacterId,
                        InventoryItemId = newItem.InventoryItemId,
                        Slot            = Slot,
                        Type            = ServerManager.GetItem(newItem.ItemVNum).Type,
                        InventoryItem   = newItem,
                        InventoryId     = generateInventoryId(),
                    }
                }
                ;
                else
                {
                    newInventory = new Inventory()
                    {
                        CharacterId     = character.CharacterId,
                        InventoryItemId = newItem.InventoryItemId,
                        Slot            = Slot,
                        Type            = ServerManager.GetItem(newItem.ItemVNum).Type,
                        InventoryItem   = newItem,
                        InventoryId     = inv.InventoryId,
                    }
                };
                InsertOrUpdate(ref newInventory);
            }
            return(newInventory);
        }
コード例 #2
0
ファイル: InventoryList.cs プロジェクト: Martazza/OpenNos
        public Inventory CreateItem(InventoryItem newItem, Character character)
        {
            short Slot = -1;
            IEnumerable<InventoryItem> slotfree = null;
            Inventory inv = null;
            if (ServerManager.GetItem(newItem.ItemVNum).Type != 0)
            {
                slotfree = character.LoadBySlotAllowed(newItem.ItemVNum, newItem.Amount);
                inv = getFirstSlot(slotfree);
            }
            bool modified = false;
            Inventory newInventory = null;
            if (inv != null)
            {
                Slot = inv.Slot;
                newItem.Amount = (short)(newItem.Amount + inv.InventoryItem.Amount);
                modified = true;
            }
            else
                Slot = getFirstPlace(ServerManager.GetItem(newItem.ItemVNum).Type, character.BackPack, newItem);
            if (Slot != -1)
            {

                if (modified == false)
                    newInventory = new Inventory()
                    {
                        CharacterId = character.CharacterId,
                        InventoryItemId = newItem.InventoryItemId,
                        Slot = Slot,
                        Type = ServerManager.GetItem(newItem.ItemVNum).Type,
                        InventoryItem = newItem,
                        InventoryId = generateInventoryId(),
                    };
                else
                    newInventory = new Inventory()
                    {
                        CharacterId = character.CharacterId,
                        InventoryItemId = newItem.InventoryItemId,
                        Slot = Slot,
                        Type = ServerManager.GetItem(newItem.ItemVNum).Type,
                        InventoryItem = newItem,
                        InventoryId = inv.InventoryId,
                    };
                InsertOrUpdate(ref newInventory);

            }
            return newInventory;
        }