30 lines
No EOL
1.1 KiB
C#
30 lines
No EOL
1.1 KiB
C#
using FNAF_Server.Map;
|
|
using GlobalClassLib;
|
|
|
|
namespace FNAF_Server.Enemies;
|
|
|
|
public abstract class RoamingPathfinder : Pathfinder{
|
|
protected RoamingPathfinder(Enemy enemy) : base(enemy) {
|
|
}
|
|
|
|
protected Dictionary<MapTile, int> Crawl(MapTile tile) {
|
|
Dictionary<MapTile, int> distances = new(){ [tile] = 0 };
|
|
CrawlStep(tile, distances);
|
|
return distances;
|
|
}
|
|
|
|
private void CrawlStep(MapTile tile, Dictionary<MapTile, int> distances) {
|
|
List<MapTile> neighbours = GetNeighbours(tile,
|
|
c => (!c.Blocked || c.Type == ConnectorType.DOOR_OFFICE) && tile != Enemy.Location,
|
|
t =>
|
|
(!distances.ContainsKey(t) || distances[t] > distances[tile]) &&
|
|
(!Enemy.BlocksTile || EnemyManager.GetByLocation(t).All(e => !e.BlocksTile || e == Enemy)) &&
|
|
Server.Players.All(p => p.Value.state.officeTileId != t.Id));
|
|
|
|
neighbours.ForEach(t => distances[t] = distances[tile] + tile.GetConnector(t)!.Value);
|
|
|
|
if (neighbours.Count != 0){
|
|
neighbours.ForEach(t => CrawlStep(t, distances));
|
|
}
|
|
}
|
|
} |