Пример #1
0
        public void Add(InventoryType inventory, short slot, GW_ItemSlotBase item)
        {
            aChangeLog.Add(new InventoryOperationAdd(inventory, slot, item));

            if (slot < 0 && slot > -200)
            {
                Broadcast_UserAvatarModified = true;
            }
        }
Пример #2
0
        public static void CreateDropItem(CField field, TagPoint pStartPos, int dwOwnerID, GW_ItemSlotBase pItem)
        {
            var drop = new CDrop(pStartPos, dwOwnerID)
            {
                Item   = pItem,
                ItemId = pItem.nItemID
            };

            drop.Position.X = drop.StartPosX;
            drop.CalculateY(field, drop.StartPosY);

            field.Drops.Add(drop);
        }
Пример #3
0
        public static COutPacket ItemMegaphonePacket(string sMsg, byte nChannelNo, bool bWhisperIcon, GW_ItemSlotBase pItem)
        {
            var p = new COutPacket(SendOps.LP_BroadcastMsg);

            p.Encode1((byte)(pItem is null
                ? BroadcastMsgType.SpeakerBridge
                : BroadcastMsgType.ItemMegaphone));
            p.EncodeString(sMsg);
            p.Encode1(nChannelNo);
            p.Encode1(bWhisperIcon);
            p.Encode1(pItem is object);
            pItem?.RawEncode(p);
            return(p);
        }
Пример #4
0
        /// <summary>
        /// Adds an item to the proper inventory.
        /// Does not handle inserting items into equipped inventories.
        /// </summary>
        /// <param name="pChar"></param>
        /// <param name="item"></param>
        /// <returns>Slot of newly created item.</returns>
        public static short InsertInto(Character pChar, GW_ItemSlotBase item)        //, short nPOS = 0) // specifying the item pos is a pain -- make a separate function if its required in the future
        {
            if (item is null)
            {
                Log.Info($"{pChar} trying to add null item to slot {0}.");
                return(0);
            }

            if (item.InvType == InventoryType.Equip)
            {
                var inv = pChar.InventoryEquip;

                var nSlot = inv.GetFreeSlot();

                if (nSlot <= 0)
                {
                    return(0);
                }

                inv.Add(nSlot, item as GW_ItemSlotEquip);
                pChar.Modify.Inventory(ctx => ctx.Add(item.InvType, nSlot, item));

                return(nSlot);
            }
            else
            {
                var inv = GetInventory(pChar, item.InvType);

                if (item.IsRechargeable || item.liSN != 0)
                {
                    var nSlot = inv.GetFreeSlot();

                    if (nSlot > 0)
                    {
                        inv.Add(nSlot, item as GW_ItemSlotBundle);

                        pChar.Modify.Inventory(ctx =>
                        {
                            ctx.Add(item.InvType, nSlot, item);
                        });
                    }

                    return(nSlot);
                }
                else                 // item is allowed to be merged
                {
                    var nSlot = inv.GetFreeSlot(item.nItemID);

                    if (nSlot == 0)
                    {
                        return(0);
                    }

                    var nRemainingCount = item.nNumber;

                    pChar.Modify.Inventory(ctx =>
                    {
                        while (nRemainingCount > 0)
                        {
                            var existingItem = inv.Get(nSlot);

                            if (existingItem is null)                             // slot is empty
                            {
                                inv.Add(nSlot, item as GW_ItemSlotBundle);
                                ctx.Add(item.InvType, nSlot, item);
                                break;
                            }

                            var diff = (short)(existingItem.SlotMax - existingItem.nNumber);

                            if (diff > nRemainingCount)                             // incoming count fits in item slot
                            {
                                existingItem.nNumber += nRemainingCount;
                                ctx.UpdateQuantity(item.InvType, nSlot, existingItem.nNumber);
                                break;
                            }
                            else                             // incoming count does not fit in item slot
                            {
                                existingItem.nNumber = existingItem.SlotMax;
                                ctx.UpdateQuantity(item.InvType, nSlot, existingItem.nNumber);
                                item.nNumber -= diff;

                                nRemainingCount -= diff;

                                nSlot = inv.GetFreeSlot(item.nItemID);
                            }
                        }
                    });

                    return(nSlot);                    // itll return the last modified slot, we really only check if this is 0 if were adding consumable anyway tho we might wanna alter this in the future
                }
            }
        }
Пример #5
0
 public InventoryOperationAdd(InventoryType inventory, short slot, GW_ItemSlotBase item)
     : base(InventoryOperationType.Add, inventory, slot)
 {
     m_item = item;
 }