Пример #1
0
    public void Consume()
    {
        switch (_clickedItemType)
        {
        case ItemType.Consumable:
            int indexAtConsumableList = _clickedItemIndex - _inventory.ammo.Count;

            // We instantiate the consumable in front of us
            CollectableConsumable collectableConsumable = _inventory.consumables[indexAtConsumableList].item.collectableConsumable;
            if (collectableConsumable != null)
            {
                InventoryConsumable consumable = collectableConsumable.consumableMount.item;
                if (consumable != null)
                {
                    // We play the drop consumable sound
                    if (consumable.consumeSound != null && GoneWrong.AudioManager.instance != null)
                    {
                        GoneWrong.AudioManager.instance.PlayOneShotSound(consumable.consumeSound, 1, 0, 0);
                    }

                    if (_healthSharedFloat != null)
                    {
                        float newHealth = _healthSharedFloat.value += consumable.healthAterlation;

                        if (newHealth < 0)
                        {
                            newHealth = 0f;
                        }
                        if (newHealth > 100)
                        {
                            newHealth = 100;
                        }

                        _healthSharedFloat.value = newHealth;
                    }

                    if (_staminaSharedFloat != null)
                    {
                        float newStamina = _staminaSharedFloat.value += consumable.staminaAlteration;

                        if (newStamina < 0)
                        {
                            newStamina = 0f;
                        }
                        if (newStamina > 100)
                        {
                            newStamina = 100;
                        }

                        _staminaSharedFloat.value = newStamina;
                    }

                    if (_infectionSharedFloat != null)
                    {
                        float newInfection = _infectionSharedFloat.value += consumable.infectionAlteration;

                        if (newInfection < 0)
                        {
                            newInfection = 0f;
                        }
                        if (newInfection > 100)
                        {
                            newInfection = 100;
                        }

                        _infectionSharedFloat.value = newInfection;
                    }


                    _inventory.consumables[indexAtConsumableList].item = null;
                    _inventory.consumables.RemoveAt(indexAtConsumableList);
                }
            }
            break;
        }

        _clickedItemIndex = -1;
        _clickedItemType  = ItemType.None;

        // Deselect all items
        for (int i = 0; i < _itemInfos.Count; i++)
        {
            OnItemPointerExit(i);
        }

        Repaint(false);
    }
Пример #2
0
    public void ChangeGeneralDescription(int index)
    {
        if (_weaponInfos.Count > index && _hoverdItemType == ItemType.Weapon)
        {
            if (_weaponInfos[index].weaponMount != null && _weaponInfos[index].weaponMount.item != null)
            {
                _clickedItemType = ItemType.Weapon;

                InventoryWeapon weapon = _weaponInfos[index].weaponMount.item;
                if (_generalDescriptionPanel.descriptionImage != null)
                {
                    _generalDescriptionPanel.descriptionImage.gameObject.SetActive(true);
                    _generalDescriptionPanel.descriptionImage.sprite = weapon.image;
                }

                if (_generalDescriptionPanel.descriptionNameText != null)
                {
                    _generalDescriptionPanel.descriptionNameText.text = weapon.itemName;
                }

                if (_generalDescriptionPanel.decriptionText != null)
                {
                    _generalDescriptionPanel.decriptionText.text = weapon.itemDescription;
                }

                if (_generalDescriptionPanel.actionButton1 != null)
                {
                    _generalDescriptionPanel.actionButton1.gameObject.SetActive(true);
                    _generalDescriptionPanel.actionButton1.GetComponentInChildren <Text>().text = weapon.actionButton1Text;
                    _generalDescriptionPanel.actionButton1.gameObject.SetActive(true);
                }

                if (_generalDescriptionPanel.actionButton2 != null)
                {
                    _generalDescriptionPanel.actionButton2.GetComponentInChildren <Text>().text = weapon.actionButton2Text;
                }

                if (_generalDescriptionPanel.actionButton2 != null)
                {
                    _generalDescriptionPanel.actionButton2.gameObject.SetActive(weapon.showActionButton2);
                }
            }
        }


        if (_itemInfos.Count > index && _hoverdItemType == ItemType.Ammo)
        {
            if (_itemInfos[index].ammoMount.item != null)
            {
                _clickedItemType = ItemType.Ammo;

                InventoryAmmo ammo = _itemInfos[index].ammoMount.item;

                if (_generalDescriptionPanel.descriptionImage != null)
                {
                    _generalDescriptionPanel.descriptionImage.gameObject.SetActive(true);
                    _generalDescriptionPanel.descriptionImage.sprite = ammo.image;
                }

                if (_generalDescriptionPanel.descriptionNameText != null)
                {
                    _generalDescriptionPanel.descriptionNameText.text = ammo.itemName;
                }

                if (_generalDescriptionPanel.decriptionText != null)
                {
                    _generalDescriptionPanel.decriptionText.text = _itemInfos[index].ammoMount.rounds + "/" + _itemInfos[index].ammoMount.item.capacity;
                }

                if (_generalDescriptionPanel.actionButton1 != null)
                {
                    _generalDescriptionPanel.actionButton1.gameObject.SetActive(true);
                    _generalDescriptionPanel.actionButton1.GetComponentInChildren <Text>().text = ammo.actionButton1Text;
                    _generalDescriptionPanel.actionButton1.gameObject.SetActive(true);
                }

                if (_generalDescriptionPanel.actionButton2 != null)
                {
                    _generalDescriptionPanel.actionButton2.GetComponentInChildren <Text>().text = ammo.actionButton2Text;
                }

                if (_generalDescriptionPanel.actionButton2 != null)
                {
                    _generalDescriptionPanel.actionButton2.gameObject.SetActive(ammo.showActionButton2);
                }
            }
        }

        if (_itemInfos.Count > index && _hoverdItemType == ItemType.Consumable)
        {
            if (_itemInfos[index].consumableMount.item != null)
            {
                _clickedItemType = ItemType.Consumable;

                InventoryConsumable consumable = _itemInfos[index].consumableMount.item;

                if (_generalDescriptionPanel.descriptionImage != null)
                {
                    _generalDescriptionPanel.descriptionImage.gameObject.SetActive(true);
                    _generalDescriptionPanel.descriptionImage.sprite = consumable.image;
                }

                if (_generalDescriptionPanel.descriptionNameText != null)
                {
                    _generalDescriptionPanel.descriptionNameText.text = consumable.itemName;
                }

                if (_generalDescriptionPanel.decriptionText != null)
                {
                    _generalDescriptionPanel.decriptionText.text = _itemInfos[index].consumableMount.item.itemDescription;
                }

                if (_generalDescriptionPanel.actionButton1 != null)
                {
                    _generalDescriptionPanel.actionButton1.gameObject.SetActive(true);
                    _generalDescriptionPanel.actionButton1.GetComponentInChildren <Text>().text = consumable.actionButton1Text;

                    _generalDescriptionPanel.actionButton1.gameObject.SetActive(consumable.canBeDropped);
                }

                if (_generalDescriptionPanel.actionButton2 != null)
                {
                    _generalDescriptionPanel.actionButton2.GetComponentInChildren <Text>().text = consumable.actionButton2Text;
                }

                if (_generalDescriptionPanel.actionButton2 != null)
                {
                    _generalDescriptionPanel.actionButton2.gameObject.SetActive(consumable.showActionButton2);
                }
            }
        }
    }