Esempio n. 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);
        }
Esempio n. 2
0
        /// <summary>
        /// This method is used to get anything in our posession.   Inventory in main or any packs,
        /// </summary>
        public virtual WorldObject GetInventoryItem(ObjectGuid objectGuid)
        {
            // first search me for this item..
            if (InventoryObjects.ContainsKey(objectGuid))
            {
                if (InventoryObjects.TryGetValue(objectGuid, out var inventoryItem))
                {
                    return(inventoryItem);
                }
            }

            // continue searching other packs..
            // 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)
            {
                if ((container.Value as Container).GetInventoryItem(objectGuid) != null)
                {
                    if ((container.Value as Container).GetInventoryItem(objectGuid) != null)
                    {
                        return((container.Value as Container).GetInventoryItem(objectGuid));
                    }
                }
            }

            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// This method is used to get anything in our posession.   Inventory in main or any packs,
        /// as well as wielded items.   If we have it, this will return it.
        /// </summary>
        /// <param name="objectGuid"></param>
        /// <returns></returns>
        public virtual WorldObject GetInventoryItem(ObjectGuid objectGuid)
        {
            WorldObject inventoryItem;

            if (InventoryObjects.TryGetValue(objectGuid, out inventoryItem))
            {
                return(inventoryItem);
            }

            WorldObject item       = null;
            var         containers = InventoryObjects.Where(wo => wo.Value.WeenieType == WeenieType.Container).ToList();

            foreach (var container in containers)
            {
                if (container.Value.InventoryObjects.TryGetValue(objectGuid, out item))
                {
                    break;
                }
            }

            // It is not in inventory - main pack or container - last check the wielded items.
            if (item == null)
            {
                WieldedObjects.TryGetValue(objectGuid, out item);
            }

            return(item);
        }
Esempio n. 4
0
    void Awake()
    {
        EquippedInventory = new InventoryObjects();
        isAlive           = true;

        if (player == null)
        {
            player = GameObject.FindGameObjectWithTag("Player");
        }
        if (player != null)
        {
            playerStartPosition = player.transform.position;
            SetupPlayerConnections();
        }

        StartCoroutine(Regen());

        // Get weapon / armor / item gameobject
        if (weaponSlot != null && ShowInInventoryBeforePickup != null)
        {
            Items = GameObject.FindGameObjectWithTag("PlayerItem");

            // Start by filling up inventory
            EquippedInventory.Weapons = GetAllChildrenWithInventoryTrue(weaponSlot.transform);
            EquippedInventory.Items   = GetAllChildrenWithInventoryTrue(Items.transform);

            //for (int i = 0; i < ShowInInventoryBeforePickup.Weapons.Count; i++) { EquipedInventory.Weapons.Add(ShowInInventoryBeforePickup.Weapons[i]); }
            for (int i = 0; i < ShowInInventoryBeforePickup.Items.Count; i++)
            {
                EquippedInventory.Items.Add(ShowInInventoryBeforePickup.Items[i]);
            }
        }
    }
Esempio n. 5
0
    /// <summary>
    /// New inventory menu toggle prefabs and adds to menu
    /// </summary>
    public void AddItemToMenu(InventoryObjects inventoryObjectToAdd)
    {
        GameObject clone = Instantiate(inventoryMenuItemTogglePrefab, inventoryListContentArea);
        InventoryMenuItemToggle toggle = clone.GetComponent <InventoryMenuItemToggle>();

        toggle.AssociatedInventoryObject = inventoryObjectToAdd;
    }
Esempio n. 6
0
 public void ShowPanel(InventoryObjects invObject)
 {
     bigArticleImg.sprite = invObject.shopSprite;
     description.text     = invObject.Description;
     confirmation.text    = invObject.Named + "\n" + invObject.price + " " + loadXmlScript.MiscClass.gold + "\n" + loadXmlScript.MiscClass.shopConfirmation;
     acceptScript.InvObj  = invObject;
 }
Esempio n. 7
0
        public bool HasItem(ObjectGuid itemGuid)
        {
            bool foundItem = InventoryObjects.ContainsKey(itemGuid) || WieldedObjects.ContainsKey(itemGuid);

            if (foundItem)
            {
                return(true);
            }

            var containers = InventoryObjects.Where(wo => wo.Value.WeenieType == WeenieType.Container).ToList();

            return(containers.Any(cnt => (cnt.Value).InventoryObjects.ContainsKey(itemGuid)));
        }
Esempio n. 8
0
        /// <summary>
        /// Gets Free Pack
        /// </summary>
        public virtual uint GetFreePackLocation()
        {
            // do I have enough space ?
            if (usedPackSlots <= maxPackSlots)
            {
                return(Guid.Full);
            }

            // do any of my other containers have enough space ?
            var containers = InventoryObjects.Where(wo => wo.Value.WeenieType == WeenieType.Container).ToList();

            foreach (var container in containers)
            {
                if ((container.Value as Container).GetFreePackLocation() != 0)
                {
                    return((container.Value as Container).GetFreePackLocation());
                }
            }
            return(0);
        }
Esempio n. 9
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);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// This method is used to get all inventory items of Coin in this container (example of usage get all items of coin on player)
        /// </summary>
        public virtual List <WorldObject> GetInventoryItemsOfTypeWeenieType(WeenieType type)
        {
            List <WorldObject> items = new List <WorldObject>();

            // first search me / add all items of type.
            var localInventory = InventoryObjects.Where(wo => wo.Value.WeenieType == type).ToList();

            foreach (var wo in localInventory)
            {
                items.Add(wo.Value);
            }

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

            foreach (var container in containers)
            {
                items.AddRange((container.Value as Container).GetInventoryItemsOfTypeWeenieType(type));
            }

            return(items);
        }
Esempio n. 11
0
 private void OnInventoryMenuItemSelected(InventoryObjects inventoryObjectThatWasSelected)
 {
     itemLabelText.text       = inventoryObjectThatWasSelected.ObjectName;
     descriptionAreaText.text = inventoryObjectThatWasSelected.Description;
 }