public List <Vector3> EstablecerNodoFinal(PersonajeNPC npc) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); List <Nodo> nodos; nodoActual = grid.NodeFromWorldPoint(npc.posicion); if (Physics.Raycast(ray, out hit, 1000.0f)) { if (hit.transform != null && hit.transform.tag != "Muro" && hit.transform.tag != "Agua") { if (nodoEnd != null) { Destroy(nodoEnd); } nodoEnd = GameObject.CreatePrimitive(PrimitiveType.Sphere); nodoEnd.transform.localScale = new Vector3(10, 10, 10); nodoEnd.transform.position = new Vector3(hit.transform.position.x, hit.transform.position.y + 1, hit.transform.position.z); nodoEnd.GetComponent <Renderer>().material.color = new Color(255, 0, 0); nodoFinal = grid.NodeFromWorldPoint(nodoEnd.transform.position); nodos = lrtaStar.FindPath(nodoActual, nodoFinal, npc.distancePathfinding, grid, mapaCostes); List <Vector3> aux = new List <Vector3>(nodos.Count); for (int i = 0; i < nodos.Count; i++) { aux.Add(nodos[i].vPosition); } return(aux); } } return(null); }
protected void checkRespawnUnits() { if (respawnTimer <= 0) { if (!playerIA.getBaseUnderAttack() && muertosAllys.Count > 0) { PersonajePlayer person = muertosAllys.First.Value; muertosAllys.RemoveFirst(); person.revive(allySpawnPoints[0].position); if (muertosAllys.Count > 0) { PersonajePlayer person2 = muertosAllys.First.Value; muertosAllys.RemoveFirst(); person2.revive(allySpawnPoints[1].position); } } if (!enemyIA.getBaseUnderAttack() && muertosEnemys.Count > 0) { PersonajeNPC person = muertosEnemys.First.Value; muertosEnemys.RemoveFirst(); person.revive(enemySpawnPoints[0].position); if (muertosEnemys.Count > 0) { PersonajeNPC person2 = muertosEnemys.First.Value; muertosEnemys.RemoveFirst(); person2.revive(enemySpawnPoints[1].position); } } respawnTimer = 10f; } else { respawnTimer -= Time.fixedDeltaTime; } }
public bool isBeingAttacked(PersonajeNPC npc) { PersonajeBase aggresor = null; foreach (AccionAttack att in combatlist) { aggresor = (att.receptor == npc) ? att.sujeto : null; if (aggresor) { break; } } return(aggresor); }
protected new void Update() { if (!iaControlled) { if (!mouseOverUI) { if (mouseBehav == MOUSE_ACTION_FINAL.SELECT) { if (Input.GetMouseButton(0)) { if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8)) { PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>(); if (!selectedUnits.Contains(character)) { character.selected = true; characterWithFocus = character; selectedUnits.Add(character); ui.showDebugInfo(true); (ui as UIManagerFinal).actualizeAgentDebugInfo(characterWithFocus); } else { character.selected = false; if (character == characterWithFocus) { characterWithFocus = null; ui.showDebugInfo(false); } selectedUnits.Remove(character); } } else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 13)) { PersonajeNPC character = hit.collider.gameObject.GetComponent <PersonajeNPC>(); if (character != characterWithFocus) { characterWithFocus = character; ui.showDebugInfo(true); ui.actualizeAgentDebugInfo(character); } } } else { foreach (PersonajePlayer person in selectedUnits) { person.selected = false; } selectedUnits.Clear(); RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8)) { PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>(); character.selected = true; characterWithFocus = character; selectedUnits.Add(character); ui.showDebugInfo(true); (ui as UIManagerFinal).actualizeAgentDebugInfo(characterWithFocus); } else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 13)) { PersonajeNPC character = hit.collider.gameObject.GetComponent <PersonajeNPC>(); if (character != characterWithFocus) { characterWithFocus = character; ui.showDebugInfo(true); ui.actualizeAgentDebugInfo(character); } } else { if (characterWithFocus != null) { characterWithFocus = null; ui.showDebugInfo(false); } } } ui.actualizeUserButtons(allPossibleActions()); } } else if (mouseBehav == MOUSE_ACTION_FINAL.MOVE) { if (selectedUnits.Count > 0) { if (Input.GetMouseButton(0)) { RaycastHit hit; /*if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 9)) * { * return; * } * else */ if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 13)) { PersonajeBase enemigo = hit.collider.GetComponent <PersonajeBase>(); foreach (PersonajeBase person in selectedUnits) { AccionCompuesta ac = TacticalModule.createAttackingAction(person, enemigo); if (person.currentFormacion != null) { Formacion formation = person.currentFormacion; if (person.currentFormacion.lider == person) { formation.disbandGrid(); for (int i = 0; i < formation.getMiembros.Length; i++) { if (formation.getMiembros[i] != null) { AccionCompuesta attackMachaka = TacticalModule.createAttackingAction(formation.getMiembros[i], enemigo); formation.getMiembros[i].accion = attackMachaka; formation.getMiembros[i].accion.doit(); } } formaciones.Remove(formation); } else { formation.removeMiembro(person); person.currentFormacion = null; person.accion = ac; person.accion.doit(); } } else { person.accion = ac; person.accion.doit(); } } } else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 14)) { Vector2 baseToGo = positionToGrid(hit.collider.transform.parent.position); foreach (PersonajeBase person in selectedUnits) { ActionGo gotobase = new ActionGo(person, TacticalModule.getUnitPointOnBaseStatic(person, baseToGo, gm.getAllies()), null); if (person.currentFormacion != null) { Formacion formation = person.currentFormacion; if (person.currentFormacion.lider == person) { formation.disbandGrid(); for (int i = 0; i < formation.getMiembros.Length; i++) { if (formation.getMiembros[i] != null) { ActionGo gotobaseMachakas = new ActionGo(formation.getMiembros[i], TacticalModule.getUnitPointOnBaseStatic(formation.getMiembros[i], baseToGo, gm.getAllies()), null); formation.getMiembros[i].accion = gotobaseMachakas; formation.getMiembros[i].accion.doit(); } } formaciones.Remove(formation); } else { formation.removeMiembro(person); person.currentFormacion = null; person.accion = gotobase; person.accion.doit(); } } else { person.accion = gotobase; person.accion.doit(); } } } else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 10)) { foreach (PersonajeBase person in selectedUnits) { Vector2 posicionDestino = positionToGrid(hit.point); Vector2 posicionOrigen = positionToGrid(person.posicion); ActionGo moverse = new ActionGo(person, posicionDestino, null); if (person.currentFormacion != null) { Formacion formation = person.currentFormacion; if (person.currentFormacion.lider != person) { formation.removeMiembro(person); person.currentFormacion = null; } person.accion = moverse; person.accion.doit(); } else { person.accion = moverse; person.accion.doit(); } } } } } } else if (mouseBehav == MOUSE_ACTION_FINAL.FORM_T || mouseBehav == MOUSE_ACTION_FINAL.FORM_S || mouseBehav == MOUSE_ACTION_FINAL.FORM_R) { if (selectedUnits.Count > 0) { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8)) { // PARA FORMACIONES foreach (PersonajeBase person in selectedUnits) { if (person.currentFormacion != null) { formaciones.Remove(person.currentFormacion); person.currentFormacion.disbandGrid(); } } //Asignamos el lider que clicamos PersonajeBase lider = hit.collider.gameObject.GetComponent <PersonajeBase>(); Formacion formacion = null; switch (mouseBehav) { case MOUSE_ACTION_FINAL.FORM_T: formacion = new FormacionTriangulo(lider); break; case MOUSE_ACTION_FINAL.FORM_S: formacion = new FormacionCuadrado(lider); break; case MOUSE_ACTION_FINAL.FORM_R: formacion = new FormacionPorRoles(lider); break; } foreach (PersonajeBase person in selectedUnits) { person.currentFormacion = formacion; formacion.addMiembro(person); } lider.currentFormacion = formacion; formacion.formacionASusPuestosAccion(); //formacion.formacionASusPuestos(); formaciones.Add(formacion); } } } } else if (mouseBehav == MOUSE_ACTION_FINAL.ROUTE_SET) { if (selectedUnits.Count > 0) { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 11)) { foreach (PersonajeBase person in selectedUnits) { if (person.currentFormacion != null) { formaciones.Remove(person.currentFormacion); person.currentFormacion.disbandGrid(); } } setRouteOnUnits(); pathToSet.Clear(); setMouseBehaviour(0); ui.selectMouseOption(0); } else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 10)) { if (pathToSet.Count == 0) { foreach (PersonajeBase unit in selectedUnits) { foreach (Transform routeElem in unit.routeMarks) { Destroy(routeElem.gameObject); } } } pathToSet.Add(hit.point); foreach (PersonajeBase unit in selectedUnits) { GameObject routeMark = Instantiate(routeMarkPrefab, unit.routeMarks); routeMark.transform.position = new Vector3(hit.point.x, 0.05f, hit.point.z); if (pathToSet.Count > 1) { GameObject routeLine = Instantiate(routeLinePrefab, unit.routeMarks); routeLine.GetComponent <FlechaDeRutaDelegate>().setRouteDirection(pathToSet[pathToSet.Count - 2], pathToSet[pathToSet.Count - 1]); } } } } } } } } else { if (Input.GetMouseButton(0)) { if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8)) { PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>(); if (!selectedUnits.Contains(character)) { character.selected = true; characterWithFocus = character; selectedUnits.Add(character); ui.showDebugInfo(true); ui.actualizeAgentDebugInfo(character); } else { character.selected = false; if (character == characterWithFocus) { characterWithFocus = null; ui.showDebugInfo(false); } selectedUnits.Remove(character); } } else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 13)) { PersonajeNPC character = hit.collider.gameObject.GetComponent <PersonajeNPC>(); if (character != characterWithFocus) { characterWithFocus = character; ui.showDebugInfo(true); ui.actualizeAgentDebugInfo(character); } } } else { foreach (PersonajePlayer person in selectedUnits) { person.selected = false; } selectedUnits.Clear(); RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8)) { PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>(); character.selected = true; characterWithFocus = character; selectedUnits.Add(character); ui.showDebugInfo(true); ui.actualizeAgentDebugInfo(character); } else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 13)) { PersonajeNPC character = hit.collider.gameObject.GetComponent <PersonajeNPC>(); if (character != characterWithFocus) { characterWithFocus = character; ui.showDebugInfo(true); ui.actualizeAgentDebugInfo(character); } } else { if (characterWithFocus != null) { characterWithFocus = null; ui.showDebugInfo(false); } } } } } }