Zvuky, změny v pathfindingu, přidány ventilace
This commit is contained in:
parent
4fdff0a0cc
commit
c5adebb2db
36 changed files with 527 additions and 143 deletions
|
|
@ -3,13 +3,18 @@ using GlobalClassLib;
|
|||
|
||||
namespace FNAF_Server.Enemies;
|
||||
|
||||
public abstract class RoamingPathfinder : Pathfinder {
|
||||
public class RoamingPathfinder : Pathfinder {
|
||||
|
||||
protected Predicate<MapTile> AdditionalTileFilter = _ => true;
|
||||
protected Predicate<TileConnector> AdditionalConnectorFilter = _ => true;
|
||||
public Predicate<MapTile> AdditionalTileFilter{ get; set; } = _ => true;
|
||||
public Predicate<TileConnector> AdditionalConnectorFilter{ get; set; } = _ => true;
|
||||
|
||||
protected int tolerance;
|
||||
public List<MapTile> TakenPath { get; } = new();
|
||||
|
||||
private Random random = new();
|
||||
// private Func<TileConnector, MapTile, bool> defaultConnectorFilter;
|
||||
protected RoamingPathfinder(Enemy enemy) : base(enemy) {
|
||||
public RoamingPathfinder(Enemy enemy, int tolerance) : base(enemy) {
|
||||
this.tolerance = tolerance;
|
||||
}
|
||||
|
||||
protected Dictionary<MapTile, int> Crawl(MapTile tile) {
|
||||
|
|
@ -23,10 +28,10 @@ public abstract class RoamingPathfinder : Pathfinder {
|
|||
c =>
|
||||
AdditionalConnectorFilter(c) &&
|
||||
(!c.Blocked || c.Type == ConnectorType.DOOR_OFFICE) &&
|
||||
tile != Enemy.Location,
|
||||
tile != Enemy.Location &&
|
||||
(!distances.ContainsKey(c.OtherTile(tile)) || distances[c.OtherTile(tile)] > distances[tile] + c.Value),
|
||||
t =>
|
||||
AdditionalTileFilter(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));
|
||||
|
||||
|
|
@ -36,4 +41,42 @@ public abstract class RoamingPathfinder : Pathfinder {
|
|||
neighbours.ForEach(t => CrawlStep(t, distances));
|
||||
}
|
||||
}
|
||||
|
||||
public override Decision DecideNext(MapTile goal) {
|
||||
Dictionary<MapTile, int> distances = Crawl(goal);
|
||||
|
||||
List<MapTile> closerTiles = GetNeighbours(Enemy.Location,
|
||||
c => AdditionalConnectorFilter(c) && !c.Blocked || c.Type == ConnectorType.DOOR_OFFICE,
|
||||
t => AdditionalTileFilter(t) && distances.ContainsKey(t) && distances[t] + t.GetConnector(Enemy.Location).Value <= distances[Enemy.Location] + tolerance);
|
||||
if (closerTiles.Contains(goal)){
|
||||
if (Enemy.Location.GetConnector(goal)!.Blocked){
|
||||
return Decision.Reset();
|
||||
}
|
||||
|
||||
IEnumerable<ServerPlayer> players = Server.Players.Values.Where(p => p.state.officeTileId == goal.Id);
|
||||
if (players.Count() == 1){
|
||||
return Decision.Attack(players.First());
|
||||
}
|
||||
return Decision.Move(goal);
|
||||
}
|
||||
|
||||
if (closerTiles.Count != 0 && closerTiles.All(t => TakenPath.Contains(t))){
|
||||
TakenPath.Clear();
|
||||
return DecideNext(goal);
|
||||
}
|
||||
closerTiles.RemoveAll(t => TakenPath.Contains(t));
|
||||
|
||||
closerTiles.ForEach(t => distances[t] += Enemy.Location.GetConnector(t)!.Value);
|
||||
double roll = random.NextDouble() * closerTiles.Sum(t => 1.0 / distances[t]);
|
||||
foreach (var tile in closerTiles){
|
||||
double value = 1.0 / distances[tile];
|
||||
if (roll <= value){
|
||||
TakenPath.Add(tile);
|
||||
return Decision.Move(tile);
|
||||
}
|
||||
roll -= value;
|
||||
}
|
||||
|
||||
return Decision.Wait();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue