Beispiel #1
0
        /// <summary>
        /// Adds a new item to the inventory collection AND NOTHING ELSE.  will not send updates to the client.  The
        /// primary use case here is as a helper function or for adding items prior to login (ie, char gen)
        /// </summary>
        public virtual void AddToInventoryEx(WorldObject inventoryItem, int placement = 0)
        {
            if (InventoryObjects.ContainsKey(inventoryItem.Guid))
            {
                // if item exists in the list, we are going to shift everything greater than the moving item down 1 to reflect its removal
                if (inventoryItem.UseBackpackSlot)
                {
                    InventoryObjects.Where(i => InventoryObjects[inventoryItem.Guid].PlacementPosition != null &&
                                           i.Value.PlacementPosition > (uint)InventoryObjects[inventoryItem.Guid].PlacementPosition &&
                                           i.Value.UseBackpackSlot).ToList().ForEach(i => i.Value.PlacementPosition--);
                }
                else
                {
                    InventoryObjects.Where(i => InventoryObjects[inventoryItem.Guid].PlacementPosition != null &&
                                           i.Value.PlacementPosition > (uint)InventoryObjects[inventoryItem.Guid].PlacementPosition &&
                                           !i.Value.UseBackpackSlot).ToList().ForEach(i => i.Value.PlacementPosition--);
                }

                InventoryObjects.Remove(inventoryItem.Guid);
            }
            // If not going on the very end (next open slot), make a hole.
            if (inventoryItem.UseBackpackSlot)
            {
                InventoryObjects.Where(i => i.Value.PlacementPosition >= placement && i.Value.UseBackpackSlot).ToList().ForEach(i => i.Value.PlacementPosition++);
            }
            else
            {
                InventoryObjects.Where(i => i.Value.PlacementPosition >= placement && !i.Value.UseBackpackSlot).ToList().ForEach(i => i.Value.PlacementPosition++);
            }

            inventoryItem.PlacementPosition = placement;
            inventoryItem.Location          = null;
            InventoryObjects.Add(inventoryItem.Guid, inventoryItem);
        }
Beispiel #2
0
        public virtual void RemoveWorldObjectFromInventory(ObjectGuid objectguid)
        {
            // first search me / add all items of type.
            if (InventoryObjects.ContainsKey(objectguid))
            {
                // defrag the pack
                int placement = InventoryObjects[objectguid].PlacementPosition ?? 0;
                InventoryObjects.Where(i => i.Value.PlacementPosition > placement).ToList().ForEach(i => -- i.Value.PlacementPosition);

                // todo calculate burdon / value / container properly

                // clear objects out maybe for db ?
                InventoryObjects[objectguid].ContainerId       = null;
                InventoryObjects[objectguid].PlacementPosition = null;

                Burden -= InventoryObjects[objectguid].Burden;

                log.Debug($"Remove {InventoryObjects[objectguid].Name} in inventory, removing {InventoryObjects[objectguid].Burden}, current Burden = {Burden}");

                // TODO: research, should this only be done for pyreal and trade notes?   Does the value of your items add to the container value?   I am not sure.
                Value -= InventoryObjects[objectguid].Value;

                // decrease pack counter if item is not a container!
                if (InventoryObjects[objectguid].WeenieType != WeenieType.Container)
                {
                    usedPackSlots -= 1;
                }

                InventoryObjects.Remove(objectguid);
                return;
            }

            // next search all containers for item.. run function again for each container.
            var containers = InventoryObjects.Where(wo => wo.Value.WeenieType == WeenieType.Container).ToList();

            foreach (var container in containers)
            {
                ((Container)container.Value).RemoveWorldObjectFromInventory(objectguid);
            }
        }