Oprava spawnování monster, optimalizace v CommandProcessor a EventProcessor. Přesunutí některých tříd do vlastních namespaců, pročištění kódu, úpravy formátování, odstranění nepoužívaných souborů a zakomentovaného kódu
This commit is contained in:
parent
e5d746d597
commit
243f071a43
62 changed files with 873 additions and 1217 deletions
|
|
@ -1,25 +1,19 @@
|
|||
using GlobalClassLib;
|
||||
using ONDServer.Map;
|
||||
using ONDServer.Net;
|
||||
|
||||
namespace ONDServer.Enemies;
|
||||
|
||||
public class RoamingPathfinder : Pathfinder {
|
||||
public class RoamingPathfinder(Enemy enemy, int tolerance) : Pathfinder(enemy) {
|
||||
|
||||
public Predicate<MapTile> AdditionalTileFilter{ get; set; } = _ => true;
|
||||
public Predicate<TileConnector> AdditionalConnectorFilter{ get; set; } = _ => true;
|
||||
|
||||
protected int tolerance;
|
||||
protected int Tolerance = tolerance;
|
||||
public List<MapTile> TakenPath { get; } = new();
|
||||
|
||||
private Random random = new();
|
||||
|
||||
// private Queue<MapTile> tilesToCrawl = new();
|
||||
// private Dictionary<MapTile, int> distances = new();
|
||||
// private Func<TileConnector, MapTile, bool> defaultConnectorFilter;
|
||||
public RoamingPathfinder(Enemy enemy, int tolerance) : base(enemy) {
|
||||
this.tolerance = tolerance;
|
||||
}
|
||||
|
||||
|
||||
protected Dictionary<MapTile, int> Search(MapTile startingTile) {
|
||||
Dictionary<MapTile, int> distances = new(){ [startingTile] = 0 };
|
||||
Queue<MapTile> tilesToSearch = new();
|
||||
|
|
@ -36,7 +30,7 @@ public class RoamingPathfinder : Pathfinder {
|
|||
t =>
|
||||
AdditionalTileFilter(t) &&
|
||||
(!Enemy.BlocksTile || EnemyManager.GetByLocation(t).All(e => !e.BlocksTile || e == Enemy)) &&
|
||||
Server.Players.All(p => p.Value.state.officeTileId != t.Id));
|
||||
Server.Players.All(p => p.Value.State.OfficeTileId != t.Id));
|
||||
|
||||
neighbours.ForEach(t => {
|
||||
distances[t] = distances[currentTile] + currentTile.GetConnector(t)!.Value;
|
||||
|
|
@ -47,37 +41,20 @@ public class RoamingPathfinder : Pathfinder {
|
|||
return distances;
|
||||
}
|
||||
|
||||
// private void CrawlStep(MapTile tile) {
|
||||
// List<MapTile> neighbours = GetNeighbours(tile,
|
||||
// c =>
|
||||
// AdditionalConnectorFilter(c) &&
|
||||
// (!c.Blocked || c.Type == ConnectorType.DOOR_OFFICE) &&
|
||||
// tile != Enemy.Location &&
|
||||
// (!distances.ContainsKey(c.OtherTile(tile)) || distances[c.OtherTile(tile)] > distances[tile] + c.Value),
|
||||
// t =>
|
||||
// AdditionalTileFilter(t) &&
|
||||
// (!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));
|
||||
// }
|
||||
// }
|
||||
|
||||
public override Decision DecideNext(MapTile goal) {
|
||||
if (Enemy.Location == null) return Decision.Wait();
|
||||
|
||||
Dictionary<MapTile, int> distances = Search(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);
|
||||
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);
|
||||
IEnumerable<ServerPlayer> players = Server.Players.Values.Where(p => p.State.OfficeTileId == goal.Id);
|
||||
if (players.Count() == 1){
|
||||
return Decision.Attack(players.First());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue