Exemplo n.º 1
0
    public void handleTreeDestroy(Trees t, int index = -1)
    {
        int treeIndex;

        if (index > -1)                     // is the index of the tree in the aliveTrees already known (index >= 0) or need it be checked now?
        {
            treeIndex = index;
        }
        else
        {
            //Debug.Log($"In DestroyVegetation because of {t}.");
            treeIndex = aliveTrees.BinarySearch(t, tC);
            //Debug.Log($"Found {t} at position {treeIndex}.");
        }
        if (treeIndex >= 0)
        {
            if (!t.lDis.isDissolving)
            {
                t.Interact();
            }
            if (t.status == TREE_STAGE.ALIVE2)
            {
                float substractionValue = Trees.startingNatureValue / 100f * 30f;      // gets reduced by 30% from original value
                //Debug.Log("StartingNatureVal: " + Trees.startingNatureValue + "Trees.startingNatureValue/100f*30f: " + substractionValue);
                t.personalNatureValue -= substractionValue;
                LevelBalancing.SetNatureValue(substractionValue);
            }
            if (t.status == TREE_STAGE.BETWEEN1 || t.status == TREE_STAGE.BETWEEN2)
            {
                float substractionValue = Trees.startingNatureValue / 100f * 20f; // gets reduced by 20% from original value
                t.personalNatureValue -= substractionValue;
                LevelBalancing.SetNatureValue(substractionValue);
            }
            else if (t.status == TREE_STAGE.DEAD)
            {
                aliveTrees.RemoveAt(treeIndex);
                deadTrees.Add(t);
                deadTrees.Sort(tC);
                LevelBalancing.SetNatureValue(t.personalNatureValue);            // gets reduced by remaining 30% from original value
                t.personalNatureValue = 0f;
                if (deadTrees.Count == 1)
                {
                    state.SwitchFirstTreeDestroyed();
                }
            }
        }
    }
Exemplo n.º 2
0
    private void Update()
    {
        if (Input.GetKeyUp(keyInteract))
        {
            if (target != null)
            {
                switch (targetTag)
                {
                case "Seedbag":
                    Seedbag seedbag = target.GetComponent <Seedbag>();
                    if (seedbag != null && product == null)
                    {
                        seedbag.Interact(crop, hasCan, this);
                    }
                    break;

                case "Field":
                    Field field = target.GetComponent <Field>();
                    if (field != null && product == null)
                    {
                        field.Interact(crop, hasCan, this);
                    }
                    break;

                case "Can":
                    Can can = target.GetComponent <Can>();
                    if (can != null && product == null)
                    {
                        can.Interact(crop, hasCan, this);
                    }
                    break;

                case "Table":
                    Table table = target.GetComponent <Table>();
                    if (table != null)
                    {
                        table.Interact(crop, product, hasCan, this);
                    }
                    break;

                case "Trash":
                    Trash trash = target.GetComponent <Trash>();
                    if (trash != null)
                    {
                        trash.Interact(crop, product, hasCan, this);
                    }
                    break;

                case "Tree":
                    Trees tree = target.GetComponent <Trees>();
                    if (tree != null)
                    {
                        tree.Interact(crop, hasCan, this);
                    }
                    break;

                case "ProductionB":
                    ProductionBuilding building = target.GetComponent <ProductionBuilding>();
                    if (building != null)
                    {
                        if (crop != null)
                        {
                            product = crop.MakeProductFromCrop();
                            if (product != null)
                            {
                                building.Interact(product, this);
                            }
                        }
                        else if (product != null)
                        {
                            building.Interact(product, this);
                        }
                        else if (crop == null)
                        {
                            building.Interact(null, this);
                        }
                    }
                    break;

                case "SpawnedItems":
                    SpawnItems items = target.GetComponent <SpawnItems>();
                    if (items != null && product == null)
                    {
                        items.Interact(crop, hasCan, this);
                    }
                    break;

                case "Well":
                    Well well = target.GetComponent <Well>();
                    if (well != null && product == null)
                    {
                        well.Interact(crop, hasCan, this);
                    }
                    break;

                case "TargetPoint":
                    TargetPoint point = target.GetComponent <TargetPoint>();
                    if (point != null)
                    {
                        if (crop != null)
                        {
                            product = crop.MakeProductFromCrop();
                        }
                        if (product != null)
                        {
                            point.Interact(product, this);
                        }
                    }
                    break;
                }
            }
            else if (hasCan) //for placing the can
            {
                can.GetComponent <Can>().Interact(crop, hasCan, this);
            }
        }
    }