public void getRekt() { Debug.Log("desu troyed"); GameObject explotion_inst = Instantiate((GameObject)Resources.Load("unit_explotion"), this.transform.position, Quaternion.identity, gridMaster.groupUnit); Destroy(explotion_inst, 1.0f); if (heldRelic != null) { /*relic newrelic = Instantiate(gridMaster.relic_prefab, this.transform.position, Quaternion.identity); * newrelic.relicID = relicID; * newrelic.onReveal(); * gridMaster.relics.Add(newrelic);*/ heldRelic.transform.position = this.transform.position; heldRelic.onReveal(); heldRelic = null; Debug.Log("relic dropped"); } Destroy(this.gameObject); }
public void detonate() { Debug.Log("XPLOTIOOOOON"); GameObject explotion_inst = Instantiate((GameObject)Resources.Load("unit_explotion"), this.transform.position, Quaternion.identity, gridMaster.groupUnit); Destroy(explotion_inst, 1.0f); if (heldRelic != null) { heldRelic.transform.position = this.transform.position; heldRelic.onReveal(); heldRelic = null; Debug.Log("relic dropped"); } Destroy(this.gameObject); }
public virtual void getRekt() { Debug.Log("enemy destroyed"); GameObject explotion_inst = Instantiate((GameObject)Resources.Load("enemy_explotion"), this.transform.position, Quaternion.identity, gridMaster.groupEnemy); Destroy(explotion_inst, 1.0f); if (heldRelic != null) { heldRelic.transform.position = this.transform.position; heldRelic.onReveal(); heldRelic = null; Debug.Log("relic dropped"); } //gridMaster.addGas(globals.wormGasloot); gridMaster.addDinero(globals.wormGasloot); Destroy(this.gameObject); }
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------- public override IEnumerator enemysturn() { enemyDone = false; 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 Debug.Log(this.gameObject.name + " is just a brick"); yield return(null); enemyDone = true; animateBody(false); }
// Start is called before the first frame update void Start() { gridMaster = (Grid)GameObject.Find("GameMaster").GetComponent(typeof(Grid)); selector = (selector)GameObject.Find("Selector").GetComponent(typeof(selector)); headAnimator = this.transform.Find("worm_head").gameObject.GetComponent <Animator>(); bodyAnimator = this.transform.Find("worm_body").gameObject.GetComponent <Animator>(); childSprites = GetComponentsInChildren <SpriteRenderer>(); foreach (SpriteRenderer csprite in childSprites) { csprite.enabled = false; } enemyDone = true; thisNode = gridMaster.nodeFromWorldPoint(this.transform.position); lastNode = thisNode; heldRelic = null; enemyClass = globals.wormname; maxHealth = globals.wormhealth; health = globals.wormhealth; UnitPower = globals.wormPower; }
// Start is called before the first frame update void Start() { gridMaster = (Grid)GameObject.Find("GameMaster").GetComponent(typeof(Grid)); selector = (selector)GameObject.Find("Selector").GetComponent(typeof(selector)); //spriteAnimator = this.gameObject.GetComponentsInChildren<Animator>(); //0=drill 1=threads attackAnimator = this.transform.Find("sprite_drill").gameObject.GetComponent <Animator>(); movementAnimator = this.transform.Find("sprite_threads").gameObject.GetComponent <Animator>(); childSprites = GetComponentsInChildren <SpriteRenderer>(); thisNode = gridMaster.nodeFromWorldPoint(this.transform.position); lastNode = thisNode; heldRelic = null; maxWalkDistance = 3; unitClass = globals.drillname; health = globals.drillhealth; maxHealth = globals.drillhealth; attackPower = globals.drillattackstat; basecost = globals.action_cost_base_drill; attackRange = 1; scanRange = globals.scout_scan_range; }
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; }
// 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(); }
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); }
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 }