public bool PathFind(Vector2 target, Vector2 goal) { List <o_node> openlist = new List <o_node>(); HashSet <o_node> closelist = new HashSet <o_node>(); o_node startnode = Grid.NodeFromWorld(target); o_node goalnode = Grid.NodeFromWorld(goal); if (goalnode == null || //!startnode.walkable || !goalnode.walkable) { //print("You're not a bloody ghost!"); return(false); } startnode.h = HerusticVal(startnode.position, goal); openlist.Add(startnode); while (openlist.Count > 0) { o_node currentnode = openlist[0]; //print(currentnode.h); for (int i = 1; i < openlist.Count; i++) { if (openlist[i].f <= currentnode.f && openlist[i].h < currentnode.h) { currentnode = openlist[i]; } } openlist.Remove(currentnode); closelist.Add(currentnode); //closednodes.Add(currentnode); //For visual if (currentnode == goalnode) { Grid.ResetNodes(); return(true); } foreach (o_node neighbour in Grid.CheckAroundNode(currentnode, this)) { float newcost = currentnode.g + HerusticVal(currentnode.position, neighbour.position); if (!neighbour.walkable || closelist.Contains(neighbour)) { continue; } if (newcost < neighbour.g || !openlist.Contains(neighbour)) { neighbour.g = newcost; neighbour.h = HerusticVal(neighbour.position, goal); neighbour.parent = currentnode; if (!openlist.Contains(neighbour)) { //opennodes.Add(neighbour); openlist.Add(neighbour); } } } } return(false); }
public void CheckCharacterSurroundings(bool is_enemy) { //If an enemy or two appears enable the confirm attack button targets.Clear(); HashSet <o_node> enemynodes = Grid.CheckAroundNode(Grid.NodeFromWorld(player.transform.position)); foreach (o_node e in enemynodes) { s_object enemyObject = Grid.ObjectFromWorld(e); if (enemyObject == null) { continue; } if (enemyObject.GetType() == typeof(o_character)) { o_character enemy = enemyObject.GetComponent <o_character>(); if (PlayerPrefs.GetInt("MonsterMode") == 0) { if (!is_enemy) { if (!Heroes.Contains(enemy.name)) { targets.Add(enemy); } } else { if (!Adversaries.Contains(enemy.name)) { targets.Add(enemy); } } } else if (PlayerPrefs.GetInt("MonsterMode") == 1) { if (!is_enemy) { if (!Adversaries.Contains(enemy.name)) { targets.Add(enemy); } } else { if (!Heroes.Contains(enemy.name)) { targets.Add(enemy); } } } } else { continue; } } }