public void initialize() { //gridMaster = (Grid)GameObject.Find("GameMaster").GetComponent(typeof(Grid)); cursorParent = gridMaster.selector; unitHQ_code = gridMaster.selector.unitHQ_code; menubuygas = gridMaster.selector.menuBuyGas; //menubuygas.gameObject.SetActive(false); }
public bool steal(unit_HQ HQ) { 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)) ) ) { int rng = Random.Range(stealPotential / 2, stealPotential); selector.gridMaster.addDinero(-rng); this.stolenCoin = rng; this.stolenLoot = true; animateTail(stolenLoot); animateBody(stolenLoot); return(true); } else { return(false); } }
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; }
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 }