public void TravelTo(LocationComponent location) { if (!location) { return; } this.Log(Entity.Location ? $"Travel travelling from {Entity.Location} to {location}" : $"Travel spawning entity at {location}"); if (Entity.Location) { Entity.Location.EntityRegistry.Unregister(Entity); } CurrentDestination = location; Pathfinder.SetDestination(location.EntryCell); DestinationChanged?.Invoke(this, new MapComponent.LocationEventArgs(location)); }
public void SetDestination(Vector2Int destinationCell) { var map = Entity ? Entity.Map ? Entity.Map : Locator.City ? Locator.City.Map : null : null; if (!map) { this.Log($"Pathfinding can not find path without being registered in a map.", LogType.Warning); return; } Waypoints.Clear(); DestinationChanged?.Invoke(this, new CellEventArgs(destinationCell)); this.Log($"Pathfinding sending entity from {Entity.CellPosition} to {destinationCell}"); if (CellPosition == destinationCell) { this.Log($"Pathfinding entity was already at {destinationCell}"); DestinationReached?.Invoke(this, new CellEventArgs(destinationCell)); return; } var newWaypoints = Path.FindPath(CellPosition, destinationCell, map); Waypoints = newWaypoints ?? new Queue <Vector2Int>(); if (Waypoints.Count == 0) { this.Log($"Pathfinding couldn't find a path!", LogType.Warning); DestinationReached?.Invoke(this, new CellEventArgs(destinationCell)); } else { TotalWaypoints = Waypoints.Count; } }