Exemplo n.º 1
0
    public void OpenBag()
    {
        //OpenPlayers bag

        Debug.Log("Attempting to open bag.");

        foreach (var item in INVContent.GetComponentsInChildren <Transform>())
        {
            if (item == INVContent.transform)
            {
                continue;
            }

            Destroy(item.gameObject);
        }

        Player player = FindObjectOfType <Player>();

        if (player)
        {
            foreach (var item in player.inventory.items.ToArray())
            {
                GameObject invItem = Instantiate(new GameObject(), INVContent.transform) as GameObject;

                invItem.name = item.name;

                invItem.AddComponent <Image>().sprite = item.image;

                invItem.AddComponent <Button>().onClick.AddListener(delegate { RemoveItemFromBag(item); });
            }
        }
        else
        {
            INVPanel.SetActive(false);
        }
    }
Exemplo n.º 2
0
    public void RemoveItemFromBag(ItemDefinition itemToRemove)
    {
        Player player = FindObjectOfType <Player>();

        if (player)
        {
            bool use = false;

            switch (itemToRemove.Effect)
            {
            case GameManager.States.Normal:
                break;

            case GameManager.States.GrossOut:
                break;

            case GameManager.States.Burn:
                break;

            case GameManager.States.Freeze:
                break;

            case GameManager.States.Paralysis:
                break;

            case GameManager.States.Poison:
                break;

            case GameManager.States.Confusion:
                break;

            case GameManager.States.Heal:
                use = true;
                break;

            case GameManager.States.Taunt:
                break;

            case GameManager.States.Protection:
                break;

            default:
                break;
            }

            if (use == true)
            {
                player.inventory.items.Remove(itemToRemove);

                foreach (var item in INVContent.GetComponentsInChildren <Transform>())
                {
                    if (item == INVContent.transform)
                    {
                        continue;
                    }

                    if (item.name == itemToRemove.name)
                    {
                        GameManager.playerCombat.CurrentHealth += (int)(10 * itemToRemove.ChanceOfEffect);

                        DialogueManager.instance.DisplayMessage($"Used {itemToRemove.name}.", 1);

                        itemToRemove.count -= 1;

                        if (itemToRemove.count <= 0)
                        {
                            Destroy(item.gameObject);
                        }
                    }
                }
            }
            else
            {
                DialogueManager.instance.DisplayMessage("You can't use that here!", 1);
            }
        }
        else
        {
            INVPanel.SetActive(false);
        }
    }