public void updateUnit(unit_parent _unit)
    {
        unitpanel.SetActive(true);
        displayClass.text  = "" + _unit.unitClass;
        displayHealth.text = _unit.health + " / " + _unit.maxHealth;
        displayRange.text  = "Range: " + _unit.maxWalkDistance;
        displayExtra.text  = "Cost: " + _unit.basecost + " Atk: " + _unit.attackPower;
        switch (_unit.unitClass)
        {
        case globals.drillname:
            imageUnit.sprite = allsprites[8];
            break;

        case globals.tankname:
            imageUnit.sprite = allsprites[9];
            break;

        case globals.scoutname:
            imageUnit.sprite = allsprites[10];
            break;

        case globals.bombname:
            imageUnit.sprite = allsprites[3];
            break;
        }
    }
Exemple #2
0
    //----------------

    public void turnOnUnit()
    {
        if (selectedUnit != null)
        {
            selectedUnit.alreadyMoved = true;
            selectedUnit.isActive     = true;
            selectedUnit.selected     = false;
            selectedUnit   = null;
            actionLocked   = false;
            state_selector = 0;
        }
    }
    public void setValues(unit_parent _caster, int _enemyCount, int _enemyStrongCount, int _nestCount, int _relicCount)
    {
        caster = _caster;

        enemyCount       = _enemyCount;
        enemyStrongCount = _enemyStrongCount;
        nestCount        = _nestCount;
        relicCount       = _relicCount;

        enemyN.text   = "" + enemyCount;
        enemyS.text   = "" + enemyStrongCount;
        Nest.text     = "" + nestCount;
        Treasure.text = "" + relicCount;
    }
Exemple #4
0
    public bool isThereAUnitHere()
    {
        bool result = false;

        GameObject[] units = gridMaster.units;
        foreach (GameObject unit in units)
        {
            unit_parent unitcode = (unit_parent)unit.GetComponent(typeof(unit_parent));
            if (unitcode.thisNode.Equals(this))
            {
                unitInThisNode = unitcode;
                result         = true;
            }
        }
        return(result);
    }
Exemple #5
0
 public void closeScanMenu()
 {
     //state 10 disengage code part 2
     selectedUnit.alreadyMoved = true;
     selectedUnit.selected     = false;
     selectedUnit   = null;
     actionLocked   = false;
     state_selector = 0;
     //gridMaster.addGas(-globals.action_cost_scan);
     if (lastPath != null)
     {
         foreach (Node pathnode in lastPath)
         {
             pathnode.pathmember = false;
         }
     }
 }
Exemple #6
0
 public void battleMenuCancelHighlightMovement()
 {
     if (selectedUnit != null)
     {
         selectedUnit.selected = false;
         selectedUnit          = null;
         //Debug.Log("unit unselected");
         state_selector = 0;
         if (lastPath != null)
         {
             foreach (Node pathnode in lastPath)
             {
                 pathnode.pathmember = false;
             }
         }
     }
     else
     {
         //Debug.Log("no unit asigned");
     }
 }
Exemple #7
0
 public void turnOffUnit()
 {
     if ((selectedUnit != null) && (selectedUnit.selected))
     {
         selectedUnit.lastNode = selectedUnit.thisNode;
         selectedUnit.thisNode = selectedUnit.nextNode;
         ////gridMaster.addGas(-selectedUnit.temp_gas_usage);
         selectedUnit.updatePosition();
         selectedUnit.selected     = false;
         selectedUnit.alreadyMoved = true;
         selectedUnit.isActive     = false; //main effect.
         selectedUnit   = null;
         actionLocked   = false;
         state_selector = 0;
         if (lastPath != null)
         {
             foreach (Node pathnode in lastPath)
             {
                 pathnode.pathmember = false;
             }
         }
     }
 }
Exemple #8
0
 public void battleMenuWait()
 {
     if ((selectedUnit != null) && (selectedUnit.selected))
     {
         //disengage code
         selectedUnit.lastNode = selectedUnit.thisNode;
         //selectedUnit.thisNode = this.cursorNode;
         selectedUnit.thisNode = selectedUnit.nextNode;
         ////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;
             }
         }
     }
 }
    public override IEnumerator enemysturn()
    {
        enemyDone = false;
        if (recovering)
        {
            respawnIn--;
            if (!thisNode.nodeOculto)
            {
                selector.camScript.focusedObject = this.gameObject;
            }
            else
            {
                selector.camScript.focusedObject = null;
            }
            if (respawnIn <= 0)
            {
                health     = maxHealth;
                recovering = false;
            }
            animateHead(respawnIn);
            animateMain("sphinx_rest");
            yield return(new WaitForSeconds(1.5f));
        }
        else
        {
            //normal enemy ai
            //take relic if at the spot
            if (thisNode.isThereAnItemHere())
            {
                relic targetrelic = (relic)thisNode.itemInThisNode.GetComponent <relic>();
                heldRelic = targetrelic;
                targetrelic.onTake(false);
                targetrelic.transform.position = transform.position;
            }

            //is this enemy active
            unit_parent prey = null;
            listMovementRange();
            Debug.Log(this.gameObject.name + ">>>>>>");
            selector.camScript.focusedObject = this.gameObject; //NEW

            //step 1: get target unit
            //obtener lista de objetivos
            List <unit_parent> allUnits = new List <unit_parent>();
            foreach (GameObject unit in gridMaster.units)
            {
                allUnits.Add((unit_parent)unit.GetComponent(typeof(unit_parent)));
            }
            //restablecer aggro
            foreach (unit_parent upa in allUnits)
            {
                upa.aggro = 0;
            }
            if (allUnits.Count >= 1)
            {
                //añadir aggro segun criterio
                allUnits.OrderBy(item => item.health).FirstOrDefault().aggro++;
                foreach (unit_parent upa in allUnits)
                {
                    if (upa.heldRelic != null)
                    {
                        upa.aggro += 10;
                    }

                    if (upa.health < this.UnitPower)
                    {
                        upa.aggro += 2;
                    }
                    if (upa.health == upa.maxHealth)
                    {
                        upa.aggro += 1;
                    }

                    if (highLightAttackableNodes(upa.thisNode))
                    {
                        upa.aggro += 4;
                    }
                }
                //el de mas aggro es el objetivo
                //prey = allUnits.LastOrDefault();
                prey = allUnits.OrderByDescending(item => item.aggro).FirstOrDefault();
            }


            //step 2: make path to target
            if (prey != null)
            {
                List <Node> attackPath = null;
                attackPath = pathToUnit(prey.thisNode, this.thisNode, 100, true);
                Debug.Log(this.gameObject.name + " path asigned");

                if (attackPath != null && attackPath.Count() > 0)
                {
                    int i = 0;
                    //step 3: move there
                    while ((i < attackPath.Count) && (i < maxWalkDistance + 1))
                    {
                        //Debug.Log(this.gameObject.name + " moving to prey[" + attackPath[i].gridPoint + "]");
                        animateMain("sphinx_walk");
                        this.thisNode = attackPath[i];
                        if (!thisNode.nodeOculto)
                        {
                            selector.camScript.focusedObject = this.gameObject;
                        }
                        else
                        {
                            selector.camScript.focusedObject = null;
                        }
                        this.updatePosition();
                        //wait a bit between movements
                        float time = 0.2f;
                        float ix   = 0.0f;
                        float rate = 4.0f / time;
                        while (ix < 4.0f)
                        {
                            ix += Time.deltaTime * rate;
                            yield return(null);
                        }
                        //yield return new WaitForSeconds(1);
                        i++;
                    }
                }
                else
                {
                    if (attackPath == null)
                    {
                        Debug.Log(this.gameObject.name + " attackPath null");
                    }
                    else
                    {
                        Debug.Log(this.gameObject.name + " attackPath count " + attackPath.Count);
                    }
                }

                //step 4: attack
                if (
                    (thisNode.upNode != null && thisNode.upNode.Equals(prey.thisNode)) ||
                    (thisNode.leftNode != null && thisNode.leftNode.Equals(prey.thisNode)) ||
                    (thisNode.rightNode != null && thisNode.rightNode.Equals(prey.thisNode)) ||
                    (thisNode.downNode != null && thisNode.downNode.Equals(prey.thisNode))

                    )
                {
                    selector.camScript.focusedObject = this.gameObject;
                    if (thisNode.nodeOculto)
                    {
                        thisNode.revealNode();
                    }
                    prey.health -= UnitPower;
                    prey.gameObject.GetComponent <Animator>().Play("unitHitAnimation");
                    if (prey.health <= 0)
                    {
                        Node preynode = prey.thisNode;
                        prey.getRekt();
                        preynode.burryNode();
                    }
                    animateMain("sphinx_attack");
                    yield return(new WaitForSeconds(0.5f));

                    selector.camScript.focusedObject = null;
                }
                else
                {
                    // como la esfinge prioriza al que tenga una reliquia tiende a ignorar enemigos en la via, asi que se le da un target secundario
                    //prey is out of range but attack something else if there is
                    unit_parent secondprey = null;
                    foreach (Node nn in thisNode.getVecinos())
                    {
                        if (nn.isThereAUnitHere())
                        {
                            if (secondprey == null)
                            {
                                secondprey = nn.unitInThisNode;
                            }
                            else
                            {
                                if (nn.unitInThisNode.health < secondprey.health)
                                {
                                    secondprey = nn.unitInThisNode;
                                }
                            }
                        }
                    }
                    if (secondprey != null)
                    {
                        if (thisNode.nodeOculto)
                        {
                            thisNode.revealNode();
                        }
                        secondprey.health -= UnitPower;
                        secondprey.gameObject.GetComponent <Animator>().Play("unitHitAnimation");
                        if (secondprey.health <= 0)
                        {
                            Node preynode = secondprey.thisNode;
                            secondprey.getRekt();
                            preynode.burryNode();
                        }
                        yield return(new WaitForSeconds(0.5f));
                    }
                }
                animateMain("sphinx_ok");
            }

            yield return(null);

            enemyDone = true;
        }
        yield return(null);

        enemyDone = true;
        selector.camScript.focusedObject = null;
    }
Exemple #10
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();
    }
Exemple #11
0
    public void makeOptions()
    {
        List <battleOption> allOptions = new List <battleOption>();

        if (gridMaster.selector.selectedUnit != null)
        {
            unit_parent currentUnit = gridMaster.selector.selectedUnit;

            currentUnit.savedScanTargets   = currentUnit.getScanTargets2();
            currentUnit.savedAttackTargets = currentUnit.listAttackNodes();

            if (currentUnit.isActive)
            {
                if (currentUnit.checkAttackTargets(currentUnit.thisNode, false))
                {
                    allOptions.Add(new battleOption(0, "Attack", globals.action_cost_attack));
                }
                if (currentUnit.checkDrillTargets(currentUnit.thisNode, false))
                {
                    allOptions.Add(new battleOption(1, "Drill", globals.action_cost_drill));
                }
                if (currentUnit.checkHoldTargets(currentUnit.thisNode, false))
                {
                    allOptions.Add(new battleOption(2, "Take", globals.action_cost_hold));
                }
                if (currentUnit.checkScanTargets(currentUnit.thisNode, false))
                {
                    allOptions.Add(new battleOption(8, "Scan", globals.action_cost_scan));
                }
                if (currentUnit.checkDropTargets(currentUnit.thisNode, false))
                {
                    allOptions.Add(new battleOption(6, "Drop", 0));
                }
                allOptions.Add(new battleOption(3, "Wait", 0));
                if (currentUnit.checkBombTargets(currentUnit.thisNode, false))
                {
                    allOptions.Add(new battleOption(7, "Detonate", 0));
                }
                allOptions.Add(new battleOption(5, "Turn Off", 0));
            }

            if (!currentUnit.isActive)
            {
                allOptions.Add(new battleOption(4, "Turn On", 0));
            }
        }

        allOptions.Add(new battleOption(10, "Cancel", 0));


        foreach (Transform child in content.transform)
        {
            Destroy(child.gameObject);
        }

        highlighter      = Instantiate(highlighterPrefab, Vector3.zero, Quaternion.identity, content.transform);
        highlighter.name = "highlighter battle";

        /*highlighter.anchorMin = new Vector2(0, 1);
         * highlighter.anchorMax = new Vector2(0, 1);
         * highlighter.pivot = new Vector2(0, 0);
         * highlighter.sizeDelta = new Vector2(400, 30);*/
        highlighter.localPosition    = new Vector3(5, -33, 0);
        highlighter.localEulerAngles = new Vector3(0, 0, 0);
        highlighter.localScale       = new Vector3(1, 1, 1);

        int iteration = 0;

        foreach (battleOption option in allOptions)
        {
            GameObject gogo = Resources.Load("UIbutton_OPs") as GameObject;
            //Button bb = (Button) gogo.GetComponent<Button>();

            GameObject button = Instantiate(gogo, Vector3.zero, Quaternion.identity) as GameObject;

            //button.GetComponent<Button>().onClick.AddListener(optionSelected );
            button.GetComponent <Button>().onClick.AddListener(delegate { optionSelected(option.code); });
            if (option.cost == 0)
            {
                button.gameObject.GetComponentInChildren <Text>().text = option.name;
            }
            else
            {
                button.gameObject.GetComponentInChildren <Text>().text = option.name + " - " + option.cost + " Gas";
            }
            Transform rectTransform = button.GetComponent <RectTransform>();
            rectTransform.SetParent(content.transform);
            rectTransform.localPosition    = new Vector3(5, -33 - (iteration * 30), 0);
            rectTransform.localEulerAngles = new Vector3(0, 0, 0);
            rectTransform.localScale       = new Vector3(1, 1, 1);
            iteration++;
            buttonArray.Add(button);
            maxOptions = iteration;
        }
        content.GetComponent <RectTransform>().sizeDelta = new Vector2(0, maxOptions * 30);
    }
Exemple #12
0
    //Update
    public void Update()
    {
        nodeSquare.GetComponent <SpriteRenderer>().sprite = defaultSprite;
        nodeSquare.GetComponent <SpriteRenderer>().color  = Color.white;

        /*
         *      if (gridMaster.cursorCode.cursorNode.Equals (gridMaster.cursorCode.playerCode.playerNode)) {
         *              if(gridMaster.cursorCode.highLightMoveableNodes(this)){
         *                      nodeSquare.GetComponent<SpriteRenderer> ().color = Color.blue;
         *              }
         *      }
         *      foreach (GameObject enemy in gridMaster.enemies) {
         *              EnemyParent enemyCode = (EnemyParent) enemy.GetComponent(typeof(EnemyParent));
         *              if(enemyCode.highLightSeenNodes(this)){
         *                      nodeSquare.GetComponent<SpriteRenderer> ().color = Color.red;
         *              }
         *      }
         *      //cursor potential sound
         *      if(gridMaster.cursorCode.highLightSoundNodes(this)){
         *              nodeSquare.GetComponent<SpriteRenderer> ().color = Color.green;
         *      }
         *
         */

        foreach (GameObject unit in gridMaster.units)
        {
            unit_parent unit_code = (unit_parent)unit.GetComponent(typeof(unit_parent));
            if (unit_code.selected)
            {
                switch (gridMaster.selector.state_selector)
                {
                case 11:
                    if (unit_code.checkScanTargets(this, true))
                    {
                        nodeSquare.GetComponent <SpriteRenderer>().sprite = focusedSprite;
                        nodeSquare.GetComponent <SpriteRenderer>().color  = Color.green;
                    }
                    break;

                case 10:
                    if (unit_code.checkScanTargets(this, true))
                    {
                        nodeSquare.GetComponent <SpriteRenderer>().sprite = focusedSprite;
                        nodeSquare.GetComponent <SpriteRenderer>().color  = Color.green;
                    }
                    break;

                case 9:
                    if (unit_code.checkBombTargets(this, true))
                    {
                        nodeSquare.GetComponent <SpriteRenderer>().sprite = focusedSprite;
                        nodeSquare.GetComponent <SpriteRenderer>().color  = Color.green;
                    }
                    break;

                case 8:
                    if (unit_code.checkDropTargets(this, true))
                    {
                        nodeSquare.GetComponent <SpriteRenderer>().sprite = focusedSprite;
                        nodeSquare.GetComponent <SpriteRenderer>().color  = Color.green;
                    }
                    break;

                case 5:
                    if (unit_code.checkHoldTargets(this, true))
                    {
                        nodeSquare.GetComponent <SpriteRenderer>().sprite = focusedSprite;
                        nodeSquare.GetComponent <SpriteRenderer>().color  = Color.green;
                    }
                    break;

                case 4:
                    if (unit_code.checkAttackTargets(this, true))
                    {
                        nodeSquare.GetComponent <SpriteRenderer>().sprite = focusedSprite;
                        nodeSquare.GetComponent <SpriteRenderer>().color  = Color.green;
                    }
                    break;

                case 3:
                    if (unit_code.checkDrillTargets(this, true))
                    {
                        nodeSquare.GetComponent <SpriteRenderer>().sprite = focusedSprite;
                        nodeSquare.GetComponent <SpriteRenderer>().color  = Color.green;
                    }
                    break;

                default:
                    if (unit_code.highLightMoveableNodes(this))
                    {
                        nodeSquare.GetComponent <SpriteRenderer>().sprite = focusedSprite;
                        nodeSquare.GetComponent <SpriteRenderer>().color  = Color.green;
                    }
                    if (pathmember)
                    {
                        nodeSquare.GetComponent <SpriteRenderer>().sprite = focusedSprite;
                        nodeSquare.GetComponent <SpriteRenderer>().color  = Color.red;
                    }
                    break;
                }
            }
        }


        if (unitHQ_code.selected)
        {
            if (gridMaster.selector.state_selector == 7)
            {
                if (unitHQ_code.checkCreationSpaces(this, true))
                {
                    nodeSquare.GetComponent <SpriteRenderer>().sprite = focusedSprite;
                    nodeSquare.GetComponent <SpriteRenderer>().color  = Color.green;
                }
            }
        }

        foreach (GameObject enemy in gridMaster.enemies)
        {
            enemy_parent enemy_code = (enemy_parent)enemy.GetComponent(typeof(enemy_parent));
            if (enemy_code.selected && !nodeOculto)
            {
                if (enemy_code.highLightAttackableNodes(this))
                {
                    nodeSquare.GetComponent <SpriteRenderer>().sprite = focusedSprite;
                    nodeSquare.GetComponent <SpriteRenderer>().color  = Color.magenta;
                }
                if (enemy_code.highLightMoveableNodes(this))
                {
                    nodeSquare.GetComponent <SpriteRenderer>().sprite = focusedSprite;
                    nodeSquare.GetComponent <SpriteRenderer>().color  = Color.red;
                }
            }
        }

        /*
         * if (pathmember) {
         *  nodeSquare.GetComponent<SpriteRenderer>().sprite = focusedSprite;
         *  nodeSquare.GetComponent<SpriteRenderer>().color = Color.red;
         * }*/
    }
Exemple #13
0
    public virtual IEnumerator enemysturn()
    {
        enemyDone = false;
        animateHead(1);
        animateBody(true);

        //take relic if at the spot
        if (thisNode.isThereAnItemHere())
        {
            relic targetrelic = (relic)thisNode.itemInThisNode.GetComponent <relic>();
            heldRelic = targetrelic;
            targetrelic.onTake(false);
            targetrelic.transform.position = transform.position;
        }

        //is this enemy active
        if (!thisNode.nodeOculto)
        {
            unit_parent prey = null;
            listMovementRange();
            Debug.Log(this.gameObject.name + ">>>>>>");
            selector.camScript.focusedObject = this.gameObject; //NEW

            //step 1: get target unit
            //obtener lista de objetivos
            List <unit_parent> allUnits = new List <unit_parent>();
            foreach (GameObject unit in gridMaster.units)
            {
                allUnits.Add((unit_parent)unit.GetComponent(typeof(unit_parent)));
            }
            //restablecer aggro
            foreach (unit_parent upa in allUnits)
            {
                upa.aggro = 0;
            }
            if (allUnits.Count >= 1)
            {
                //añadir aggro segun criterio
                allUnits.OrderBy(item => item.health).FirstOrDefault().aggro++;
                foreach (unit_parent upa in allUnits)
                {
                    if (upa.heldRelic != null)
                    {
                        upa.aggro += 3;
                    }

                    if (upa.health < this.UnitPower)
                    {
                        upa.aggro += 2;
                    }

                    if (highLightAttackableNodes(upa.thisNode))
                    {
                        upa.aggro += 7;
                    }
                }
                //el de mas aggro es el objetivo
                //prey = allUnits.LastOrDefault();
                prey = allUnits.OrderByDescending(item => item.aggro).FirstOrDefault();
            }


            //step 2: make path to target
            if (prey != null)
            {
                List <Node> attackPath = null;
                attackPath = pathToUnit(prey.thisNode, this.thisNode, 100, true);
                Debug.Log(this.gameObject.name + " path asigned");

                if (attackPath != null && attackPath.Count() > 0)
                {
                    int i = 0;
                    //step 3: move there
                    while ((i < attackPath.Count) && (i < maxWalkDistance + 1))
                    {
                        //Debug.Log(this.gameObject.name + " moving to prey[" + attackPath[i].gridPoint + "]");
                        this.thisNode = attackPath[i];
                        this.updatePosition();
                        //wait a bit between movements
                        float time = 0.2f;
                        float ix   = 0.0f;
                        float rate = 4.0f / time;
                        while (ix < 4.0f)
                        {
                            ix += Time.deltaTime * rate;
                            yield return(null);
                        }
                        //yield return new WaitForSeconds(1);
                        i++;
                    }
                }
                else
                {
                    if (attackPath == null)
                    {
                        Debug.Log(this.gameObject.name + " attackPath null");
                    }
                    else
                    {
                        Debug.Log(this.gameObject.name + " attackPath count " + attackPath.Count);
                    }
                }

                //step 4: attack
                if (
                    (thisNode.upNode != null && thisNode.upNode.Equals(prey.thisNode)) ||
                    (thisNode.leftNode != null && thisNode.leftNode.Equals(prey.thisNode)) ||
                    (thisNode.rightNode != null && thisNode.rightNode.Equals(prey.thisNode)) ||
                    (thisNode.downNode != null && thisNode.downNode.Equals(prey.thisNode))
                    )
                {
                    animateHead(2);
                    prey.health -= UnitPower;
                    prey.gameObject.GetComponent <Animator>().Play("unitHitAnimation");
                    if (prey.health <= 0)
                    {
                        //Destroy(prey.gameObject);
                        prey.getRekt();
                    }
                    yield return(new WaitForSeconds(0.5f));
                }
            }
        }
        else
        {
            Debug.Log(this.gameObject.name + " sleeping");
        }
        yield return(null);

        enemyDone = true;
        selector.camScript.focusedObject = null;
        animateHead(0);
        animateBody(false);
    }
Exemple #14
0
    public override IEnumerator enemysturn()
    {
        enemyDone = false;
        animateHead(1);

        //take relic if at the spot
        //turns out having the roaming enemy hold a relic wasnt a good idea

        /*if (thisNode.isThereAnItemHere()) {
         *  relic targetrelic = (relic)thisNode.itemInThisNode.GetComponent<relic>();
         *  heldRelic = targetrelic;
         *  targetrelic.onTake(false);
         *  targetrelic.transform.position = transform.position;
         * }*/

        //thief walks trough walls
        if (true)
        {
            unit_parent prey = null;
            unit_HQ     HQ   = selector.unitHQ_code;
            listMovementRange();
            Debug.Log(this.gameObject.name + ">>>>>>");

            /*if (!thisNode.nodeOculto) {
             *  selector.camScript.focusedObject = this.gameObject;
             * }*/

            //step 1: get target unit
            unit_parent[] weakUnits = GameObject.FindObjectsOfType <unit_parent>();
            foreach (unit_parent unit in weakUnits)
            {
                Debug.Log(this.gameObject.name + " vs " + unit.name);
                if (highLightAttackableNodes(unit.thisNode) && (unit.health <= UnitPower || unit.attackPower == 0))
                {
                    if (prey == null)
                    {
                        prey = unit;
                        Debug.Log(this.gameObject.name + " first prey");
                    }
                    else
                    {
                        if (prey.heldRelic != null)
                        {
                            if ((unit.heldRelic != null) && unit.health < prey.health)
                            {
                                prey = unit;
                                Debug.Log(this.gameObject.name + " new target, weaker, relic");
                            }
                        }
                        else
                        {
                            if (unit.heldRelic != null)
                            {
                                prey = unit;
                                Debug.Log(this.gameObject.name + " new target, relic");
                            }
                            else
                            {
                                if (unit.health < prey.health)
                                {
                                    prey = unit;
                                    Debug.Log(this.gameObject.name + " new target, weaker");
                                }
                                else
                                {
                                    Debug.Log(this.gameObject.name + " no change");
                                }
                            }
                        }
                    }
                }
                else
                {
                    Debug.Log(this.gameObject.name + " out of reach, lets raid hq");
                }
            }


            //step 2: make path to target
            if (prey != null)
            {
                List <Node> attackPath = null;
                attackPath = pathToUnit(prey.thisNode, this.thisNode, 100, true);
                Debug.Log(this.gameObject.name + " path asigned");

                if (attackPath != null && attackPath.Count() > 0)
                {
                    int i = 0;
                    //step 3: move there
                    while ((i < attackPath.Count) && (i < maxWalkDistance + 1))
                    {
                        //Debug.Log(this.gameObject.name + " moving to prey[" + attackPath[i].gridPoint + "]");
                        this.thisNode = attackPath[i];
                        if (!thisNode.nodeOculto)
                        {
                            selector.camScript.focusedObject = this.gameObject;
                        }
                        else
                        {
                            selector.camScript.focusedObject = null;
                        }
                        this.updatePosition();
                        //wait a bit between movements
                        float time = 0.2f;
                        float ix   = 0.0f;
                        float rate = 4.0f / time;
                        while (ix < 4.0f)
                        {
                            ix += Time.deltaTime * rate;
                            yield return(null);
                        }
                        //yield return new WaitForSeconds(1);
                        i++;
                    }
                }
                else
                {
                    if (attackPath == null)
                    {
                        Debug.Log(this.gameObject.name + " attackPath null");
                    }
                    else
                    {
                        Debug.Log(this.gameObject.name + " attackPath count " + attackPath.Count);
                    }
                }

                //step 4: attack
                if (
                    !thisNode.nodeOculto && (
                        (thisNode.upNode != null && thisNode.upNode.Equals(prey.thisNode)) ||
                        (thisNode.leftNode != null && thisNode.leftNode.Equals(prey.thisNode)) ||
                        (thisNode.rightNode != null && thisNode.rightNode.Equals(prey.thisNode)) ||
                        (thisNode.downNode != null && thisNode.downNode.Equals(prey.thisNode))
                        )
                    )
                {
                    prey.health -= UnitPower;
                    animateHead(2);
                    prey.gameObject.GetComponent <Animator>().Play("unitHitAnimation");
                    if (prey.health <= 0)
                    {
                        prey.getRekt();
                    }
                    yield return(new WaitForSeconds(0.5f));
                }
            }
            else
            {
                //Step 2 alternative, attack HQ
                if (!stolenLoot)
                {
                    List <Node> attackPath = null;
                    attackPath = pathToUnit(HQ.thisNode, this.thisNode, 100, true);
                    Debug.Log(this.gameObject.name + " path asigned to hq");

                    if (attackPath != null && attackPath.Count() > 0)
                    {
                        int i = 0;
                        //step 3: move there
                        while ((i < attackPath.Count) && (i < maxWalkDistance + 1))
                        {
                            this.thisNode = attackPath[i];
                            if (!thisNode.nodeOculto)
                            {
                                selector.camScript.focusedObject = this.gameObject;
                            }
                            else
                            {
                                selector.camScript.focusedObject = null;
                            }
                            this.updatePosition();
                            float time = 0.2f;
                            float ix   = 0.0f;
                            float rate = 4.0f / time;
                            while (ix < 4.0f)
                            {
                                ix += Time.deltaTime * rate;
                                yield return(null);
                            }
                            i++;
                        }
                    }
                    else
                    {
                        if (attackPath == null)
                        {
                            Debug.Log(this.gameObject.name + " attackPath null");
                        }
                        else
                        {
                            Debug.Log(this.gameObject.name + " attackPath count " + attackPath.Count);
                        }
                    }


                    //step 4: STEAL
                    if (
                        !thisNode.nodeOculto && (
                            (thisNode.upNode != null && thisNode.upNode.Equals(HQ.thisNode)) ||
                            (thisNode.leftNode != null && thisNode.leftNode.Equals(HQ.thisNode)) ||
                            (thisNode.rightNode != null && thisNode.rightNode.Equals(HQ.thisNode)) ||
                            (thisNode.downNode != null && thisNode.downNode.Equals(HQ.thisNode))
                            )
                        )
                    {
                        if (steal(HQ))
                        {
                            yield return(new WaitForSeconds(0.5f));
                        }
                    }
                }
                else
                {
                    if (originNest != null)
                    {
                        List <Node> attackPath = null;
                        attackPath = pathToUnit(originNest.thisNode, this.thisNode, 100, false);
                        Debug.Log(this.gameObject.name + " path asigned to nest");

                        if (attackPath != null && attackPath.Count() > 0)
                        {
                            int i = 0;
                            //step 3: move there
                            while ((i < attackPath.Count) && (i < maxWalkDistance + 1))
                            {
                                this.thisNode = attackPath[i];
                                if (!thisNode.nodeOculto)
                                {
                                    selector.camScript.focusedObject = this.gameObject;
                                }
                                else
                                {
                                    selector.camScript.focusedObject = null;
                                }
                                this.updatePosition();
                                float time = 0.2f;
                                float ix   = 0.0f;
                                float rate = 4.0f / time;
                                while (ix < 4.0f)
                                {
                                    ix += Time.deltaTime * rate;
                                    yield return(null);
                                }
                                i++;
                            }
                        }
                        else
                        {
                            if (attackPath == null)
                            {
                                Debug.Log(this.gameObject.name + " escape path null");
                            }
                            else
                            {
                                Debug.Log(this.gameObject.name + " escape path count " + attackPath.Count);
                            }
                        }

                        //step 4-alt: escape
                        if (thisNode.Equals(originNest.thisNode))
                        {
                            Debug.Log("enemy escaped");
                            if (heldRelic != null)
                            {
                                heldRelic.transform.position = this.transform.position;
                                heldRelic.onReveal();
                                heldRelic = null;
                                Debug.Log("relic dropped");
                            }
                            yield return(new WaitForSeconds(0.2f));

                            stillVisible = false;
                            yield return(new WaitForSeconds(0.2f));

                            enemyDone = true;
                            yield return(null);

                            Destroy(this.gameObject);
                        }
                    }
                }
            }
        } /*else {
           * Debug.Log(this.gameObject.name + " sleeping");
           * }*/

        animateHead(0);
        yield return(null);

        enemyDone = true;
        selector.camScript.focusedObject = null;
    }
Exemple #15
0
    IEnumerator endTurn()
    {
        if (gamestate == 1)
        {
            playersturn = false;
            guimanager.enemyTurnText.gameObject.SetActive(true);
            selector.actionLocked = true;
            foreach (GameObject unit in units)
            {
                unit_parent unitscript = unit.GetComponent <unit_parent>();
                unitscript.alreadyMoved = false;
                if (unitscript.isActive)
                {
                    //this.addGas(-unitscript.basecost);
                    this.addDinero(-unitscript.basecost);
                }
            }
            if (recursoDinero <= globals.gasCoinCost)
            {
                gamestate = 2;
                Debug.Log("game over");
                yield return(null);
            }

            foreach (GameObject enemy in enemies)
            {
                enemy_parent enemyscript = enemy.GetComponent <enemy_parent>();
                enemyscript.StartCoroutine("enemysturn");

                while (!enemyscript.enemyDone)
                {
                    //wait for enemy to finish his turn
                    yield return(null);
                }
            }

            /*//allNests
             * foreach (GameObject oneNest in allNests) {
             *  enemy_thief_nest nestScript = oneNest.GetComponent<enemy_thief_nest>();
             *  nestScript.StartCoroutine("nestTurn");
             *
             *  while (!nestScript.enemyDone) {
             *      //wait for enemy to finish his turn
             *      yield return null;
             *  }
             * }*/

            selector.actionLocked = false;
            yield return(null);

            playersturn = true;
            guimanager.enemyTurnText.gameObject.SetActive(false);
            turnCount++;
        }

        if (gamestate == 2 || gamestate == 3)
        {
            yield return(null);

            selector.actionLocked = true;
            stageResult.gameObject.SetActive(true);
            stageResult.setValues(gamestate, turnCount, relicsaved, relicounter, recursoDinero, recursoDineroInicial);
        }
    }
Exemple #16
0
    void readFile()
    {
        //leer archivo
        //string[] text = System.IO.File.ReadAllLines (@"Assets\MyFolder\MAP_FILES\map_grid_1.txt");
        string textFile = mapFile[mapIndex].text;

        string[] text = textFile.Split("\n"[0]);

        //leer el tamaño del mapa
        string[] lines = text [0].Split(";"[0]);
        gridSizeX = Mathf.RoundToInt(int.Parse(lines[0]));
        gridSizeZ = Mathf.RoundToInt(int.Parse(lines[1]));
        if (lines.Length >= 4)
        {
            recursoDinero        = Mathf.RoundToInt(int.Parse(lines[2]));
            recursoDineroInicial = recursoDinero;
            recursoGas           = Mathf.RoundToInt(int.Parse(lines[3]));
        }
        if (lines.Length >= 5)
        {
            tutorialIndexForLater = Mathf.RoundToInt(int.Parse(lines[4]));
            Debug.Log(lines[4]);
        }
        else
        {
            tutorialIndexForLater = 0;
        }

        grid          = new Node[gridSizeX, gridSizeZ];
        gridWorldSize = new Vector2(gridSizeX * nodeDiameter, gridSizeZ * nodeDiameter);

        //ajustar tamaño del plano/piso
        this.transform.position    = new Vector3((float.Parse(lines[0]) - 1) / 2, (float.Parse(lines[1]) - 1) / 2, -10);
        plane.transform.localScale = new Vector3(gridSizeX * nodeDiameter, gridSizeZ * nodeDiameter, 1);
        relics      = new List <relic>();
        relicounter = 0;
        relicsaved  = 0;

        //leer cada linea del archivo
        for (int i = 1; i < text.Length; i++)
        {
            //leer linea y transformarla en un nodo segun coordenadas
            lines = text [i].Split(";"[0]);
            Vector2 gridPoint = new Vector2(int.Parse(lines[0]), int.Parse(lines[1]));

            grid[int.Parse(lines[0]), int.Parse(lines[1])] = new Node(gridPoint, lines[2], bool.Parse(lines[3]), this);
            if (lines[2].Contains("relic"))
            {
                relic newrelic = Instantiate(relic_prefab, new Vector3(gridPoint.x, gridPoint.y, 0), Quaternion.identity, groupItems);
                relicounter++;
                newrelic.relicID = relicounter;
                relics.Add(newrelic);
            }

            if (lines[2].Contains("worm"))
            {
                enemy_parent newWorm = Instantiate(enemy_worm_prefab, new Vector3(gridPoint.x, gridPoint.y, 0), Quaternion.identity, groupEnemy);//,this.transform
            }
            if (lines[2].Contains("shark"))
            {
                enemy_shark newshark = Instantiate(enemy_shark_prefab, new Vector3(gridPoint.x, gridPoint.y, 0), Quaternion.identity, groupEnemy);
            }
            if (lines[2].Contains("thief"))
            {
                enemy_thief newthief = Instantiate(enemy_thief_prefab, new Vector3(gridPoint.x, gridPoint.y, 0), Quaternion.identity, groupEnemy);
            }
            if (lines[2].Contains("nest"))
            {
                enemy_thief_nest newNest = Instantiate(enemy_nest_prefab, new Vector3(gridPoint.x, gridPoint.y, 0), Quaternion.identity, groupEnemy);
            }
            if (lines[2].Contains("keymaster"))
            {
                enemy_unlocker newLock = Instantiate(enemy_unlocker_prefab, new Vector3(gridPoint.x, gridPoint.y, 0), Quaternion.identity, groupEnemy);
            }
            if (lines[2].Contains("sphinxawake"))
            {
                enemy_sphinx newboss = Instantiate(enemy_sphinx_prefab, new Vector3(gridPoint.x, gridPoint.y, 0), Quaternion.identity, groupEnemy);
            }

            if (lines[2].Contains("START"))
            {
                unit_HQ newHQ = Instantiate(unit_HQ_prefab, new Vector3(gridPoint.x, gridPoint.y, 0), Quaternion.identity, groupUnit);
                newHQ.name  = "unitHQ";
                unitHQ_code = newHQ;
            }
            if (lines[2].Contains("DRILL"))
            {
                unit_parent startUnit = Instantiate(unit_drill_prefab, new Vector3(gridPoint.x, gridPoint.y, 0), Quaternion.identity, groupUnit);
            }
            if (lines[2].Contains("TANK"))
            {
                unit_parent startUnit = Instantiate(unit_tank_prefab, new Vector3(gridPoint.x, gridPoint.y, 0), Quaternion.identity, groupUnit);
            }
            if (lines[2].Contains("SCOUT"))
            {
                unit_parent startUnit = Instantiate(unit_scout_prefab, new Vector3(gridPoint.x, gridPoint.y, 0), Quaternion.identity, groupUnit);
            }
            if (lines[2].Contains("BOMB"))
            {
                unit_parent startUnit = Instantiate(unit_bomb_prefab, new Vector3(gridPoint.x, gridPoint.y, 0), Quaternion.identity, groupUnit);
            }
        }

        //conectar nodos
        for (int i = 0; i < gridSizeX; i++)
        {
            for (int j = 0; j < gridSizeZ; j++)
            {
                try{ grid [i, j].leftNode = grid [i - 1, j]; }
                catch {}
                try{ grid [i, j].rightNode = grid [i + 1, j]; }
                catch {}
                try{ grid [i, j].upNode = grid [i, j + 1]; }
                catch {}
                try{ grid [i, j].downNode = grid [i, j - 1]; }
                catch {}
                grid [i, j].drawmelikeafrenchgirl();
            }
        }

        checkRelics();//in case of no relics end game
        gamestate = 1;
        //world set
    }