示例#1
0
        /// <summary>
        /// Called when this character collides with a gameobject that represents item (= picking up an item)
        /// </summary>
        public void HitItem(UpgradeScript upg)
        {
            if (upg.item.CollectableByPlayer && !(this is Player))
            {
                return;
            }

            if (upg.item == null)
            {
                Debug.LogError("null item for " + upg.gameObject.name);
                return;
            }

            if (upg.item.OnPickup(this))
            {
                upg.DeleteMe(true);
                Data.UpdateInventory(Inventory);
                UpdateStats();
                return;
            }

            EquippableItem upgrade = upg.item as EquippableItem;

            if (upgrade != null)
            {
                if (upgrade.GoesIntoBasestatSlot)
                {
                    Message("You have absorbed " + upg.item.VisibleName + "");
                    Inventory.AddBasestatUpgrade(upgrade);
                    upg.DeleteMe(true);
                    Data.UpdateInventory(Inventory);
                    UpdateStats();
                }
                else if (AddItem(upgrade))
                {
                    upg.DeleteMe(true);
                    //EquipUpgrade(upg.upgrade);
                }
            }
            else
            {
                if (AddItem(upg.item))
                {
                    upg.DeleteMe(true);
                    //EquipUpgrade(upg.upgrade);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Gives this char an item to his inventory
        /// </summary>
        public void GiveItem(InventoryItem item)
        {
            if (item.CollectableByPlayer && !(this is Player))
            {
                return;
            }

            if (item.OnPickup(this))
            {
                Data.UpdateInventory(Inventory);
                UpdateStats();
                return;
            }

            EquippableItem upgrade = item as EquippableItem;

            if (upgrade != null)
            {
                if (upgrade.GoesIntoBasestatSlot)
                {
                    Message("You have absorbed " + item.VisibleName + "");
                    Inventory.AddBasestatUpgrade(upgrade);
                    Data.UpdateInventory(Inventory);
                    UpdateStats();
                }
                else if (AddItem(upgrade))
                {
                    //EquipUpgrade(upg.upgrade);
                }
            }
            else
            {
                if (AddItem(item))
                {
                    //EquipUpgrade(upg.upgrade);
                }
            }
        }