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
|
|
@ -32,13 +32,13 @@ public class LurkEnemy : Enemy {
|
|||
base.Spawn(location);
|
||||
// stopwatch.Start();
|
||||
movementOpportunity.Start();
|
||||
pathfinder.takenPath.Add(Location);
|
||||
pathfinder.TakenPath.Add(Location);
|
||||
Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(TypeId, Id, Difficulty, Location.Id)]);
|
||||
}
|
||||
|
||||
public override void Reset() {
|
||||
pathfinder.takenPath.Clear();
|
||||
pathfinder.takenPath.Add(Location);
|
||||
pathfinder.TakenPath.Clear();
|
||||
pathfinder.TakenPath.Add(Location);
|
||||
|
||||
Target.state.power -= 30;
|
||||
|
||||
|
|
@ -69,6 +69,9 @@ public class LurkEnemy : Enemy {
|
|||
Pathfinder.Decision decision = pathfinder.DecideNext(MapManager.Get(Target.state.officeTileId));
|
||||
switch (decision.type){
|
||||
case Pathfinder.Decision.MoveType:
|
||||
if (Location.GetConnector(decision.nextTile!)!.Type == ConnectorType.VENT){
|
||||
Server.SendUpdateToAll([GameEvent.VENT_USED()]);
|
||||
}
|
||||
Location = decision.nextTile!;
|
||||
Server.SendUpdateToAll([GameEvent.ENEMY_MOVEMENT(Id, Location.Id)]);
|
||||
Console.WriteLine($"Enemy {TypeId} ({Name}) moving to {Location.PositionAsString})");
|
||||
|
|
@ -86,46 +89,43 @@ public class LurkEnemy : Enemy {
|
|||
}
|
||||
|
||||
private class LurkPathfinder : RoamingPathfinder {
|
||||
private Random random = new();
|
||||
// private Random random = new();
|
||||
|
||||
private int tolerance;
|
||||
public List<MapTile> takenPath = new();
|
||||
|
||||
public LurkPathfinder(Enemy enemy, int tolerance) : base(enemy) {
|
||||
public LurkPathfinder(Enemy enemy, int tolerance) : base(enemy, tolerance) {
|
||||
this.tolerance = tolerance;
|
||||
}
|
||||
|
||||
public override Decision DecideNext(MapTile goal) {
|
||||
Dictionary<MapTile, int> distances = Crawl(goal);
|
||||
|
||||
List<MapTile> closerTiles = GetNeighbours(Enemy.Location,
|
||||
c => !c.Blocked || c.Type == ConnectorType.DOOR_OFFICE,
|
||||
t => distances.ContainsKey(t) && distances[t] <= distances[Enemy.Location] + tolerance);
|
||||
if (closerTiles.Contains(goal)){
|
||||
if (Enemy.Location.GetConnector(goal)!.Blocked){
|
||||
return Decision.Reset();
|
||||
}
|
||||
|
||||
return Decision.Attack(((LurkEnemy)Enemy).Target);
|
||||
}
|
||||
|
||||
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){
|
||||
if (roll <= 1.0 / distances[tile]){
|
||||
takenPath.Add(tile);
|
||||
return Decision.Move(tile);
|
||||
}
|
||||
roll -= 1.0 / distances[tile];
|
||||
}
|
||||
|
||||
return Decision.Wait();
|
||||
}
|
||||
// public override Decision DecideNext(MapTile goal) {
|
||||
// Dictionary<MapTile, int> distances = Crawl(goal);
|
||||
//
|
||||
// List<MapTile> closerTiles = GetNeighbours(Enemy.Location,
|
||||
// c => !c.Blocked || c.Type == ConnectorType.DOOR_OFFICE,
|
||||
// t => distances.ContainsKey(t) && distances[t] <= distances[Enemy.Location] + tolerance);
|
||||
// if (closerTiles.Contains(goal)){
|
||||
// if (Enemy.Location.GetConnector(goal)!.Blocked){
|
||||
// return Decision.Reset();
|
||||
// }
|
||||
//
|
||||
// return Decision.Attack(((LurkEnemy)Enemy).Target);
|
||||
// }
|
||||
//
|
||||
// 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){
|
||||
// if (roll <= 1.0 / distances[tile]){
|
||||
// takenPath.Add(tile);
|
||||
// return Decision.Move(tile);
|
||||
// }
|
||||
// roll -= 1.0 / distances[tile];
|
||||
// }
|
||||
//
|
||||
// return Decision.Wait();
|
||||
// }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue