Example #1
0
    public bool OnItemUse(ItemBase item)
    {
        bool isSuccess = false;

        if (placedItem)
        {
            if (GameManager.Get().playerRef.GetComponent <InventoryManager>().AddToInventory(placedItem))
            {
                placedItem = item;
                isSuccess  = true;
            }
        }
        else
        {
            placedItem = item;
            isSuccess  = true;
        }

        //Create the selected inventory prefab and delete the old one
        GameObject newItemPrefab = Instantiate(placedItem.itemModel, itemPosition);

        Destroy(itemPrefab);

        //Add InventoryPrefab component for spin effect
        newItemPrefab.AddComponent <InventoryPrefab>();
        newItemPrefab.GetComponent <Rigidbody>().isKinematic = true;

        itemPrefab = newItemPrefab;

        itemPrefab.GetComponent <Pickupable>().PickupEvent += Item_PickupEvent;

        UseItem?.Invoke();
        return(isSuccess);
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        if (fpsController.enabled)
        {
            EquipSystem equipSystem = GetComponent <EquipSystem>();
            if (CrossPlatformInputManager.GetButtonDown("Interact") && itemInView != null)
            {
                //Interacting with objects in the world
                itemInView.GetComponent <InteractableBase>().OnInteract();
            }
            else if (equipSystem && equipSystem.currentEquippedItem)
            {
                Pickupable pickupable = equipSystem.currentEquippedItem.GetComponent <Pickupable>();
                if (pickupable)
                {
                    //Using item that the player has equipped
                    if (CrossPlatformInputManager.GetButtonDown("Fire1"))
                    {
                        pickupable.OnUse();
                        UseItem?.Invoke(pickupable);
                    }
                    else if (CrossPlatformInputManager.GetButtonDown("DropItem"))
                    {
                        equipSystem.DropItem(pickupable.item);
                    }
                }
            }
        }

        if (CrossPlatformInputManager.GetButtonDown("Cancel"))
        {
            CancelAction?.Invoke();
        }
    }
Example #3
0
 public override void OnInteract()
 {
     if (placedItem && GameManager.Get().playerRef.GetComponent <InventoryManager>().AddToInventory(placedItem))
     {
         Item_PickupEvent();
         UseItem?.Invoke();
     }
 }
Example #4
0
        protected override bool ProcessKeyPressed(AsciiKey key)
        {
            switch (key.Key)
            {
            case Keys.U:
                UseItem?.Invoke(this, EventArgs.Empty);
                return(true);

            case Keys.E:
                EquipItem?.Invoke(this, EventArgs.Empty);
                return(true);

            case Keys.Z:
                EquipHoldableItemLeft?.Invoke(this, EventArgs.Empty);
                return(true);

            case Keys.X:
                EquipHoldableItemRight?.Invoke(this, EventArgs.Empty);
                return(true);

            case Keys.T:
                TakeOffItem?.Invoke(this, EventArgs.Empty);
                return(true);

            case Keys.D:
                DropItem?.Invoke(this, EventArgs.Empty);
                return(true);

            case Keys.A:
                DropStack?.Invoke(this, EventArgs.Empty);
                return(true);

            case Keys.C:
                CheckScroll?.Invoke(this, EventArgs.Empty);
                return(true);
            }
            return(base.ProcessKeyPressed(key));
        }
Example #5
0
    public bool OnItemUse(ItemBase item)
    {
        if (!allKeysInInventory)
        {
            bool isCorrectKey = keysNeeded.Contains(item);

            //Remove key if it is correct
            if (isCorrectKey)
            {
                keysNeeded.Remove(item);
            }

            //Unlock door and play message if there are no more keys needed
            if (isLocked && keysNeeded.Count == 0)
            {
                isLocked = false;
                if (OnKeyDoorUnlocked != null)
                {
                    OnKeyDoorUnlocked();
                }
            }

            UseItem?.Invoke();
            return(isCorrectKey);
        }
        else
        {
            List <int>       correctKeysIndex = new List <int>();
            InventoryManager inventoryManager = GameManager.Get().playerRef.GetComponent <InventoryManager>();
            for (int i = 0; i < inventoryManager.currentInventory.maxSlots; i++)
            {
                bool isCorrectKey = keysNeeded.Contains(inventoryManager.currentInventory.inventory[i].item);
                if (isCorrectKey)
                {
                    correctKeysIndex.Add(i);
                }
            }

            if (correctKeysIndex.Count >= keysNeeded.Count)
            {
                List <ItemBase> itemsToDelete = new List <ItemBase>();

                for (int i = 0; i < correctKeysIndex.Count; i++)
                {
                    itemsToDelete.Add(inventoryManager.currentInventory.inventory[correctKeysIndex[i]].item);
                }

                for (int i = 0; i < itemsToDelete.Count; i++)
                {
                    inventoryManager.RemoveFromInventory(itemsToDelete[i], 1);
                }
                itemsToDelete.Clear();
                EquipSystem equipSystem = GameManager.Get().playerRef.GetComponent <EquipSystem>();
                Destroy(equipSystem.currentEquippedItem.gameObject);
                correctKeysIndex.Clear();

                isLocked = false;

                if (OnKeyDoorUnlocked != null)
                {
                    OnKeyDoorUnlocked();
                }

                return(true);
            }
            else
            {
                correctKeysIndex.Clear();
                return(false);
            }
        }
    }
Example #6
0
        private void InitializeControls()
        {
            checkScrollButton = new StandardButton(20)
            {
                Position = new Point(Width - 30, 40),
                Text     = "[C] Check Scroll"
            };
            checkScrollButton.Click += (sender, args) => CheckScroll?.Invoke(this, EventArgs.Empty);
            Add(checkScrollButton);

            useItemButton = new StandardButton(20)
            {
                Position = new Point(Width - 52, 40),
                Text     = "[U] Use"
            };
            useItemButton.Click += (sender, args) => UseItem?.Invoke(this, EventArgs.Empty);
            Add(useItemButton);

            equipItemButton = new StandardButton(20)
            {
                Position = new Point(Width - 52, 40),
                Text     = "[E] Equip"
            };
            equipItemButton.Click += (sender, args) => EquipItem?.Invoke(this, EventArgs.Empty);
            Add(equipItemButton);

            equipLeftHoldableButton = new StandardButton(20)
            {
                Position = new Point(Width - 52, 40),
                Text     = "[Z] Equip Left"
            };
            equipLeftHoldableButton.Click += (sender, args) => EquipHoldableItemLeft?.Invoke(this, EventArgs.Empty);
            Add(equipLeftHoldableButton);

            equipRightHoldableButton = new StandardButton(20)
            {
                Position = new Point(Width - 31, 40),
                Text     = "[X] Equip Right"
            };
            equipRightHoldableButton.Click += (sender, args) => EquipHoldableItemRight?.Invoke(this, EventArgs.Empty);
            Add(equipRightHoldableButton);

            takeOffItemButton = new StandardButton(20)
            {
                Position = new Point(Width - 52, 40),
                Text     = "[T] Take Off"
            };
            takeOffItemButton.Click += (sender, args) => TakeOffItem?.Invoke(this, EventArgs.Empty);
            Add(takeOffItemButton);

            dropItemButton = new StandardButton(20)
            {
                Position = new Point(Width - 52, 43),
                Text     = "[D] Drop"
            };
            dropItemButton.Click += (sender, args) => DropItem?.Invoke(this, EventArgs.Empty);
            Add(dropItemButton);

            dropAllItemsButton = new StandardButton(20)
            {
                Position = new Point(Width - 52, 46),
                Text     = "[A] Drop All"
            };
            dropAllItemsButton.Click += (sender, args) => DropStack?.Invoke(this, EventArgs.Empty);
            Add(dropAllItemsButton);
        }
 private void OnUseItem(EventData eventData)
 {
     UseItem?.Invoke(eventData);
 }
Example #8
0
 /// <summary>
 /// Called from listener when placed item is picked up
 /// </summary>
 private void Item_PickupEvent()
 {
     placedItem = null;
     UseItem?.Invoke();
 }