Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        controls.calculate();


        if (actionLocked)
        {
            return;
        }


        //----------------------------------------------------------------------------------------------------------------------------------------
        switch (state_selector)
        {
        case 0:     // nada seleccionado
            if (Input.GetButtonDown("Fire1"))
            {
                if (!cursorNode.nodeOculto && cursorNode.isThereAUnitHere())
                {
                    selectedUnit = cursorNode.unitInThisNode;
                    if (!selectedUnit.alreadyMoved)
                    {
                        selectedUnit.listMovementRange();
                        selectedUnit.selected = true;
                        state_selector        = 1;
                        //Debug.Log("found unit");
                    }
                    else
                    {
                        selectedUnit = null;
                        //Debug.Log("unit already moved");
                    }
                }
                else
                {
                    if (!cursorNode.nodeOculto && cursorNode.isThereAnEnemyHere())
                    {
                        selectedEnemy = cursorNode.enemyInThisNode;
                        selectedEnemy.listMovementRange();
                        selectedEnemy.selected = true;
                        state_selector         = 1;
                    }
                    else
                    {
                        if (!cursorNode.nodeOculto && cursorNode.tiletype.Equals("HQ"))
                        {
                            state_selector       = 6;
                            unitHQ_code.selected = true;
                            showCreationMenu();
                        }
                        else
                        {
                            //Debug.Log("no unit");
                        }
                    }
                }
            }

            //abrir menu de stage
            if (Input.GetButtonDown("Fire2"))
            {
                showStageMenu();
            }
            break;

        //--------------------------
        case 1:     //unidad seleccionada
            if ((selectedUnit != null) && (selectedUnit.selected))
            {
                //if (selectedUnit.checkDistanceWalk(cursorNode, selectedUnit.thisNode, selectedUnit.thisNode, 0)) {
                if (selectedUnit.highLightMoveableNodes(cursorNode))
                {
                    lastPath     = pathToCursor;
                    pathToCursor = pathToAlert(cursorNode, selectedUnit.thisNode, 100);
                    if (lastPath != null)
                    {
                        foreach (Node pathnode in lastPath)
                        {
                            pathnode.pathmember = false;
                        }
                    }
                    foreach (Node pathnode in pathToCursor)
                    {
                        pathnode.pathmember = true;
                    }
                }

                if (Input.GetButtonDown("Fire1"))
                {
                    if (selectedUnit.highLightMoveableNodes(cursorNode))
                    {
                        /*Debug.Log("move here!");
                         * //selectedUnit.lastNode = selectedUnit.thisNode;
                         * //selectedUnit.thisNode = this.cursorNode;
                         * //selectedUnit.updatePosition();
                         * selectedUnit.nextNode = this.cursorNode;
                         * selectedUnit.previewPosition();
                         *
                         * //disengage code
                         * selectedUnit.selected = false;
                         * selectedUnit.alreadyMoved = true;
                         * selectedUnit = null;
                         * actionLocked = false;
                         * state_selector = 0;
                         * if (lastPath != null) {
                         *  foreach (Node pathnode in lastPath) {
                         *      pathnode.pathmember = false;
                         *  }
                         * }
                         * //open action menu
                         * //actionLocked = true;
                         * state_selector = 2;*/



                        //Debug.Log("move here!");
                        selectedUnit.nextNode = this.cursorNode;
                        selectedUnit.previewPosition();
                        state_selector = 2;
                        showBattleMenu();
                    }
                }

                //cancel movement
                if (Input.GetButtonDown("Fire2"))
                {
                    battleMenuCancelHighlightMovement();
                }
            }

            if ((selectedEnemy != null) && (selectedEnemy.selected))
            {
                //cancel movement
                if (Input.GetButtonDown("Fire2"))
                {
                    enemyCancelHighlight();
                }
            }



            break;

        case 2:
            //durante este estado el menu esta abierto
            //cancel

            /*if (Input.GetButtonDown("Fire2")) {
             *  battleMenuCancelMovement();
             * }*/
            break;

        case 3:
            //drill
            if (Input.GetButtonDown("Fire1"))
            {
                if ((selectedUnit != null) && (selectedUnit.selected))
                {
                    if (selectedUnit.checkDrillTargets(this.cursorNode, true) && this.cursorNode.nodeOculto)
                    {
                        this.cursorNode.revealNode();
                        GameObject dust = Instantiate((GameObject)Resources.Load("dust_ps"));    //, cursorNode.gridPoint, Quaternion.identity, gridMaster.groupUnit
                        dust.transform.position = new Vector3(cursorNode.gridPoint.x, cursorNode.gridPoint.y, -1);
                        Destroy(dust, 1.0f);
                        //disengage code
                        selectedUnit.lastNode = selectedUnit.thisNode;
                        selectedUnit.thisNode = selectedUnit.nextNode;
                        if (selectedUnit.heldRelic != null)
                        {
                            selectedUnit.heldRelic.thisNode = selectedUnit.thisNode;
                        }
                        ////gridMaster.addGas(-selectedUnit.temp_gas_usage);
                        selectedUnit.updatePosition();
                        selectedUnit.selected     = false;
                        selectedUnit.alreadyMoved = true;
                        selectedUnit   = null;
                        actionLocked   = false;
                        state_selector = 0;
                        //gridMaster.addGas(-globals.action_cost_drill);
                        if (lastPath != null)
                        {
                            foreach (Node pathnode in lastPath)
                            {
                                pathnode.pathmember = false;
                            }
                        }
                    }
                }
            }
            //cancel
            if (Input.GetButtonDown("Fire2"))
            {
                battleMenuCancelAction();
            }
            break;

        case 4:
            //attack
            if (Input.GetButtonDown("Fire1"))
            {
                if ((selectedUnit != null) && (selectedUnit.selected))
                {
                    selectedUnit.savedAttackTargets = selectedUnit.listAttackNodes();
                    if (selectedUnit.checkAttackTargets(this.cursorNode, true) && this.cursorNode.isThereAnEnemyHere())
                    {
                        enemy_parent target = this.cursorNode.enemyInThisNode;
                        target.health -= selectedUnit.attackPower;
                        if (target.health <= 0)
                        {
                            //Destroy(target.gameObject);
                            target.getRekt();
                        }
                        //disengage code
                        selectedUnit.lastNode = selectedUnit.thisNode;
                        selectedUnit.thisNode = selectedUnit.nextNode;
                        if (selectedUnit.heldRelic != null)
                        {
                            selectedUnit.heldRelic.thisNode = selectedUnit.thisNode;
                        }
                        ////gridMaster.addGas(-selectedUnit.temp_gas_usage);
                        selectedUnit.updatePosition();
                        selectedUnit.selected     = false;
                        selectedUnit.alreadyMoved = true;
                        selectedUnit   = null;
                        actionLocked   = false;
                        state_selector = 0;
                        //gridMaster.addGas(-globals.action_cost_attack);
                        if (lastPath != null)
                        {
                            foreach (Node pathnode in lastPath)
                            {
                                pathnode.pathmember = false;
                            }
                        }
                    }
                }
            }
            //cancel
            if (Input.GetButtonDown("Fire2"))
            {
                battleMenuCancelAction();
            }
            break;

        case 5:    //hold
            if (Input.GetButtonDown("Fire1"))
            {
                if ((selectedUnit != null) && (selectedUnit.selected))
                {
                    if (selectedUnit.checkHoldTargets(this.cursorNode, true) && this.cursorNode.isThereAnItemHere())
                    {
                        relic targetrelic = (relic)cursorNode.itemInThisNode;
                        selectedUnit.heldRelic = targetrelic;
                        targetrelic.onTake(true);
                        targetrelic.transform.position = selectedUnit.transform.position;
                        //disengage code
                        selectedUnit.lastNode = selectedUnit.thisNode;
                        selectedUnit.thisNode = selectedUnit.nextNode;
                        if (selectedUnit.heldRelic != null)
                        {
                            selectedUnit.heldRelic.thisNode = selectedUnit.thisNode;
                        }
                        ////gridMaster.addGas(-selectedUnit.temp_gas_usage);
                        selectedUnit.updatePosition();
                        selectedUnit.selected     = false;
                        selectedUnit.alreadyMoved = true;
                        selectedUnit   = null;
                        actionLocked   = false;
                        state_selector = 0;
                        //gridMaster.addGas(-globals.action_cost_hold);
                        if (lastPath != null)
                        {
                            foreach (Node pathnode in lastPath)
                            {
                                pathnode.pathmember = false;
                            }
                        }
                        gridMaster.wakeUpStatues();    //only for wake up boss check
                    }
                }
            }
            //cancel
            if (Input.GetButtonDown("Fire2"))
            {
                battleMenuCancelAction();
            }
            break;

        case 6:    //create unit
            //buffer state
            //create unit menu active
            break;

        case 7:
            //set created unit in place
            if (Input.GetButtonDown("Fire1"))
            {
                if ((unitHQ_code != null) && unitHQ_code.selected && unitHQ_code.checkCreationSpaces(this.cursorNode, true) && (create_selector != 0))
                {
                    int         createcost             = globals.drill_create_cost;
                    unit_parent selected_creation_unit = gridMaster.unit_drill_prefab;
                    switch (create_selector)
                    {
                    case 1:
                        createcost             = globals.drill_create_cost;
                        selected_creation_unit = gridMaster.unit_drill_prefab;
                        break;

                    case 2:
                        createcost             = globals.tank_create_cost;
                        selected_creation_unit = gridMaster.unit_tank_prefab;
                        break;

                    case 3:
                        createcost             = globals.scout_create_cost;
                        selected_creation_unit = gridMaster.unit_scout_prefab;
                        break;

                    case 4:
                        createcost             = globals.bomb_create_cost;
                        selected_creation_unit = gridMaster.unit_bomb_prefab;
                        break;

                    case 5:
                        createcost             = globals.tank_create_cost;
                        selected_creation_unit = gridMaster.unit_armoredS_prefab;
                        break;
                    }

                    if (gridMaster.recursoDinero >= 0)
                    {
                        //create unit
                        unit_parent new_creation_unit = Instantiate(selected_creation_unit, new Vector3(cursorNode.gridPoint.x, cursorNode.gridPoint.y, 0), Quaternion.identity, gridMaster.groupUnit);
                        new_creation_unit.alreadyMoved = true;
                        gridMaster.addDinero(-createcost);
                        gridMaster.updateActors();

                        //unset state
                        unitHQ_code.selected     = false;
                        unitHQ_code.alreadyMoved = true;
                        actionLocked             = false;
                        state_selector           = 0;
                    }
                }
            }

            //cancel
            if (Input.GetButtonDown("Fire2"))
            {
                creationMenuCancelCreation();
            }
            break;

        case 8:    //drop
            if (Input.GetButtonDown("Fire1"))
            {
                if ((selectedUnit != null) && (selectedUnit.selected))
                {
                    if (selectedUnit.checkDropTargets(cursorNode, true))
                    {
                        if (cursorNode.tiletype.Equals("HQ"))
                        {
                            selectedUnit.heldRelic.transform.position = new Vector3(cursorNode.gridPoint.x, cursorNode.gridPoint.y, 0);
                            selectedUnit.heldRelic.onSave();
                            selectedUnit.heldRelic = null;
                        }
                        else
                        {
                            selectedUnit.heldRelic.transform.position = new Vector3(cursorNode.gridPoint.x, cursorNode.gridPoint.y, 0);
                            selectedUnit.heldRelic.onReveal();
                            selectedUnit.heldRelic = null;
                        }
                        //disengage code
                        selectedUnit.lastNode = selectedUnit.thisNode;
                        selectedUnit.thisNode = selectedUnit.nextNode;
                        if (selectedUnit.heldRelic != null)
                        {
                            selectedUnit.heldRelic.thisNode = selectedUnit.thisNode;
                        }
                        ////gridMaster.addGas(-selectedUnit.temp_gas_usage);
                        selectedUnit.updatePosition();
                        selectedUnit.selected     = false;
                        selectedUnit.alreadyMoved = true;
                        selectedUnit   = null;
                        actionLocked   = false;
                        state_selector = 0;
                        if (lastPath != null)
                        {
                            foreach (Node pathnode in lastPath)
                            {
                                pathnode.pathmember = false;
                            }
                        }
                    }
                }
            }
            //cancel
            if (Input.GetButtonDown("Fire2"))
            {
                battleMenuCancelAction();
            }
            break;

        case 9:
            //go bomb
            if (Input.GetButtonDown("Fire1"))
            {
                if ((selectedUnit != null) && (selectedUnit.selected))
                {
                    //this.cursorNode.revealNode();
                    GameObject explotion_inst = Instantiate((GameObject)Resources.Load("bomb_explotion"), selectedUnit.transform.position, Quaternion.identity, gridMaster.groupUnit);
                    Destroy(explotion_inst, 1.0f);
                    //GameObject dust = Instantiate((GameObject)Resources.Load("dust_ps2"));
                    //dust.transform.position = new Vector3(selectedUnit.nextNode.gridPoint.x, selectedUnit.nextNode.gridPoint.y, -1);
                    //Destroy(dust, 2.0f);

                    foreach (Node nnn in selectedUnit.listBombNodes())
                    {
                        if (nnn.nodeOculto)
                        {
                            nnn.revealNode();
                        }
                        else
                        {
                            if (nnn.isThereAnEnemyHere())
                            {
                                nnn.enemyInThisNode.health -= globals.bombExplodeStat;
                                if (nnn.enemyInThisNode.health <= 0)
                                {
                                    nnn.enemyInThisNode.getRekt();
                                }
                            }
                            //friendly fire off is more fun

                            /*if (nnn.isThereAUnitHere()) {
                             *  nnn.unitInThisNode.health -= globals.bombExplodeStat;
                             *  if (nnn.unitInThisNode.health <= 0) {
                             *      nnn.unitInThisNode.getRekt();
                             *  }
                             * }*/
                        }
                    }
                    //disengage code
                    selectedUnit.lastNode = selectedUnit.thisNode;
                    selectedUnit.thisNode = selectedUnit.nextNode;
                    if (selectedUnit.heldRelic != null)
                    {
                        selectedUnit.heldRelic.thisNode = selectedUnit.thisNode;
                    }
                    ////gridMaster.addGas(-selectedUnit.temp_gas_usage);
                    selectedUnit.updatePosition();
                    selectedUnit.selected     = false;
                    selectedUnit.alreadyMoved = true;
                    unit_parent tempunit = selectedUnit;
                    selectedUnit   = null;
                    actionLocked   = false;
                    state_selector = 0;
                    //gridMaster.addGas(-globals.action_cost_base_bomb);

                    //destroy bomb
                    tempunit.detonate();

                    if (lastPath != null)
                    {
                        foreach (Node pathnode in lastPath)
                        {
                            pathnode.pathmember = false;
                        }
                    }
                }
            }
            //cancel
            if (Input.GetButtonDown("Fire2"))
            {
                battleMenuCancelAction();
            }
            break;

        case 10:
            //scanplace
            movementLocked = true;
            if ((selectedUnit != null) && (selectedUnit.selected) && (controls.horizontal != 0 || controls.vertical != 0))
            {
                if (controls.horizontal == -1 && controls.vertical == 0)
                {
                    selectedUnit.scanDirection    = 0;
                    selectedUnit.savedScanTargets = selectedUnit.getScanTargets2();
                }
                if (controls.horizontal == 0 && controls.vertical == -1)
                {
                    selectedUnit.scanDirection    = 1;
                    selectedUnit.savedScanTargets = selectedUnit.getScanTargets2();
                }
                if (controls.horizontal == 1 && controls.vertical == 0)
                {
                    selectedUnit.scanDirection    = 2;
                    selectedUnit.savedScanTargets = selectedUnit.getScanTargets2();
                }
                if (controls.horizontal == 0 && controls.vertical == 1)
                {
                    selectedUnit.scanDirection    = 3;
                    selectedUnit.savedScanTargets = selectedUnit.getScanTargets2();
                }
            }


            if (Input.GetButtonDown("Fire1"))
            {
                if ((selectedUnit != null) && (selectedUnit.selected))
                {
                    int enemyScan       = 0;
                    int enemyStrongScan = 0;
                    int relicScan       = 0;
                    int nestScan        = 0;

                    //disengage part 1
                    selectedUnit.lastNode = selectedUnit.thisNode;
                    selectedUnit.thisNode = selectedUnit.nextNode;
                    if (selectedUnit.heldRelic != null)
                    {
                        selectedUnit.heldRelic.thisNode = selectedUnit.nextNode;
                    }
                    ////gridMaster.addGas(-selectedUnit.temp_gas_usage);
                    selectedUnit.updatePosition();

                    selectedUnit.savedScanTargets = selectedUnit.getScanTargets2();
                    foreach (Node nnn in selectedUnit.savedScanTargets)
                    {
                        if (nnn.isThereAnEnemyHere())
                        {
                            if (nnn.enemyInThisNode.GetComponent <enemy_parent>().enemyClass.Equals(globals.nestName))
                            {
                                nestScan++;
                            }
                            else
                            {
                                if (nnn.enemyInThisNode.GetComponent <enemy_parent>().maxHealth > 20)
                                {
                                    enemyStrongScan++;
                                }
                                else
                                {
                                    enemyScan++;
                                }
                            }
                        }
                        if (nnn.isThereAnItemHere() && !nnn.isHQhere() && (!nnn.isThereAUnitHere() || (nnn.isThereAUnitHere() && nnn.itemInThisNode.state != 2)))
                        {
                            relicScan++;
                        }
                    }


                    state_selector = 11;
                    //actionLocked = true;
                    movementLocked = false;
                    menuScanResult.gameObject.SetActive(true);
                    menuScanResult.setValues(selectedUnit, enemyScan, enemyStrongScan, nestScan, relicScan);
                    //Debug.Log("Enemy: " + enemyScan + "Big-Enemy: " + enemyStrongScan + " Nest: " + nestScan + " Relic: " + relicScan);

                    //TODO
                    //mostrar enemigos y relics contados


                    //disengage code part 2

                    /*selectedUnit.selected = false;
                     * selectedUnit = null;
                     * actionLocked = false;
                     * //gridMaster.addGas(-globals.action_cost_scan);
                     * if (lastPath != null) {
                     *  foreach (Node pathnode in lastPath) {
                     *      pathnode.pathmember = false;
                     *  }
                     * }*/
                }
            }
            //cancel
            if (Input.GetButtonDown("Fire2"))
            {
                movementLocked = false;
                battleMenuCancelAction();
            }
            break;

        case 11:
            /*if (Input.GetButtonDown("Fire1") || Input.GetButtonDown("Fire2")) {
             *  closeScanMenu();
             * }*/
            break;
        }

        //Check if we have a non-zero value for horizontal or vertical

        int G_horizontal = 0;
        int G_vertical   = 0;

        if (!movementLocked)
        {
            if (controls.horizontal != 0 || controls.vertical != 0)
            {
                G_horizontal = controls.horizontal;
                G_vertical   = controls.vertical;
                //Debug.Log("horizontal: " + horizontal + " vertical: " + vertical);
            }



            if (G_horizontal == -1 && G_vertical == 0 && nextDirection(0))
            {
                //changeIcon();
                cursorNode         = cursorNode.leftNode;
                transform.position = new Vector3(cursorNode.gridPoint.x, cursorNode.gridPoint.y, 0);
                //camScript.alignCamera(cursorNode, false);
            }
            if (G_horizontal == 0 && G_vertical == -1 && nextDirection(1))
            {
                //changeIcon();
                cursorNode         = cursorNode.downNode;
                transform.position = new Vector3(cursorNode.gridPoint.x, cursorNode.gridPoint.y, 0);
                //camScript.alignCamera(cursorNode, false);
            }
            if (G_horizontal == 1 && G_vertical == 0 && nextDirection(2))
            {
                //changeIcon();
                cursorNode         = cursorNode.rightNode;
                transform.position = new Vector3(cursorNode.gridPoint.x, cursorNode.gridPoint.y, 0);
                //camScript.alignCamera(cursorNode, false);
            }
            if (G_horizontal == 0 && G_vertical == 1 && nextDirection(3))
            {
                //changeIcon();
                cursorNode         = cursorNode.upNode;
                transform.position = new Vector3(cursorNode.gridPoint.x, cursorNode.gridPoint.y, 0);
                //camScript.alignCamera(cursorNode, false);
            }
        }


        /*if (controls.vertical != 0 ||
         *      controls.horizontal != 0 ||
         *      Input.GetButtonDown("Fire1") ||
         *      Input.GetButtonDown("Fire2")
         *  ) {
         *  gridMaster.updateAllNodes();
         * }*/

        //updategui();
    }