public void DealDamageTo(int X, int Y, UnitIn TypeOfUnit) { // Debug.Log("Dealing Damage"); In here I might wanna implement the weapon system or sum if (TypeOfUnit == UnitIn.AI) { //Find the AI creature GameObject[] AllUnits = GameObject.FindGameObjectsWithTag("Enemy_AI"); Unit Enemy = null; foreach (GameObject T in AllUnits) { if (T.GetComponent <Unit>() != null && T.GetComponent <Unit>().GridPos.x == X && T.GetComponent <Unit>().GridPos.y == Y) { Enemy = T.GetComponent <Unit>(); break; } } if (Enemy == null) { Debug.LogError("Enemy not found"); return; } Enemy.TakeDamage(unitStats.AttackPoints); } }
public MapTile(int newX, int newY, int newRoughness, TileType NewType) //Simple constructor to give it values quick { Neighbours = new MapTile[4]; FarNeighbours = new MapTile[4]; X = newX; Y = newY; Roughness = newRoughness; Type = NewType; OcupedByMat = MaterialTile.None; OcupiedByUnit = UnitIn.None; OcupingUnitScript = null; Visible = false; Discovered = false; // Debug.Log("me llaman"); }
public List <MapTile> Pathfinding(Vector2Int Origin, Vector2Int Target) { MapTile OriginT = FindTile(Origin.x, Origin.y); MapTile TargetT = FindTile(Target.x, Target.y); //Temporarily unocupy the start (Cheap way to fix it) Might not even be necessary but I cant be bothered to change it UnitIn TempU = OriginT.OcupiedByUnit; OriginT.OcupiedByUnit = UnitIn.None; Heap <MapTile> OpenTiles = new Heap <MapTile>(AllMapTiles.Count); //not sure how it wooorks HashSet <MapTile> ClosedTiles = new HashSet <MapTile>(); OpenTiles.Add(OriginT); for (int b = 0; b < 3; b++) { while (OpenTiles.Count > 0) { MapTile current = OpenTiles.RemoveFirst(); ClosedTiles.Add(current); if (current == TargetT) { List <MapTile> Path = new List <MapTile>(); MapTile cur = TargetT; while (cur != OriginT) { Path.Add(cur); cur = cur.parent; } Path.Reverse(); OriginT.OcupiedByUnit = TempU; //cheap way return(Path); } foreach (MapTile Neighbour in current.Neighbours) { if (Neighbour == null || !current.Walkable || ClosedTiles.Contains(Neighbour)) { continue; } int MoveCostToN = current.GCost + GetDistance(current.GetPos, Neighbour.GetPos); //This probably does not work if (MoveCostToN < Neighbour.GCost || !OpenTiles.Contains(Neighbour)) { Neighbour.GCost = MoveCostToN; Neighbour.HCost = GetDistance(Neighbour.GetPos, TargetT.GetPos); //Same thing with this Neighbour.parent = current; if (!OpenTiles.Contains(Neighbour)) { OpenTiles.Add(Neighbour); } } } } } OriginT.OcupiedByUnit = TempU; return(null); }