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:
Perry 2026-03-28 09:59:31 +01:00
parent e5d746d597
commit 243f071a43
62 changed files with 873 additions and 1217 deletions

View file

@ -1,35 +1,29 @@
using GlobalClassLib;
using ONDServer.Map;
using ONDServer.Net;
using PacketLib;
namespace ONDServer.Enemies;
public class NekoEnemy : Enemy {
// private MovementOpportunity movementOpportunity;
private RoamingPathfinder pathfinder;
public override string Name{ get; } = "Neko";
public override EnemyType Type{ get; } = EnemyType.NEKO;
public override bool BlocksTile{ get; set; } = true;
public bool Aggressive = false;
public ServerPlayer? Target{ get; set; }
private readonly RoamingPathfinder pathfinder;
public NekoEnemy(int difficulty) : base(difficulty, 4000) {
pathfinder = new RoamingPathfinder(this, 1){AdditionalTileFilter = t => Aggressive || t.Owner == null || !t.Lit};
// movementOpportunity = new MovementOpportunity(5000);
// SetDifficulty(difficulty);
}
public override string Name{ get; } = "Neko";
public override int TypeId{ get; } = (int)EnemyType.NEKO;
public override bool BlocksTile{ get; set; } = true;
public bool Aggressive = false;
public ServerPlayer? Target{ get; set; }
public override void Spawn(MapTile location) {
base.Spawn(location);
// stopwatch.Start();
movementOpportunity.Start();
pathfinder.TakenPath.Add(Location);
Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(TypeId, Id, Difficulty, Location.Id)]);
MovementOpportunity.Start();
pathfinder.TakenPath.Add(Location!);
Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(Type, Id, Difficulty, Location!.Id)]);
}
public override void Reset() {
@ -38,29 +32,25 @@ public class NekoEnemy : Enemy {
pathfinder.TakenPath.Clear();
pathfinder.TakenPath.Add(Location);
Aggressive = false;
Target = Server.OtherPlayer(Target);
Target = Server.OtherPlayer(Target!);
Server.SendUpdateToAll([GameEvent.ENEMY_RESET(Id, Location.Id)]);
}
// public override void SetDifficulty(int difficulty) {
// Difficulty = difficulty;
// movementOpportunity.MovementChance =
// ((5 + Math.Pow(1.5f, Difficulty)) * Math.Sign(Difficulty)) / (5 + Math.Pow(1.5f, 10));
// }
public override void Update() {
base.Update();
if(Location == null) return;
if (Location.Owner != null && Location.Lit && !Aggressive){
Aggressive = true;
Server.SendUpdateToAll([GameEvent.NEKO_ANGERED(Location.Owner.state.pid, Id)]);
Server.SendUpdateToAll([GameEvent.NEKO_ANGERED(Location.Owner.State.Pid, Id)]);
}
if (Target == null){
if (Server.P1.state.power > Server.P2.state.power){
if (Server.P1.State.Power > Server.P2.State.Power){
Target = Server.P2;
}
else if (Server.P1.state.power < Server.P2.state.power){
else if (Server.P1.State.Power < Server.P2.State.Power){
Target = Server.P1;
}
else{
@ -71,9 +61,9 @@ public class NekoEnemy : Enemy {
}
}
bool succeed = movementOpportunity.CheckAndRoll();
bool succeed = MovementOpportunity.CheckAndRoll();
if (Target != null && (succeed || (Aggressive && GameLogic.NSecondUpdate))){
Pathfinder.Decision decision = pathfinder.DecideNext(MapManager.Get(Target.state.officeTileId));
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){
@ -81,7 +71,7 @@ public class NekoEnemy : Enemy {
}
Location = decision.nextTile!;
Server.SendUpdateToAll([GameEvent.ENEMY_MOVEMENT(Id, Location.Id)]);
Console.WriteLine($"Enemy {TypeId} ({Name}) moving to {Location.PositionAsString})");
Console.WriteLine($"Enemy {Type} ({Name}) moving to {Location.IdAsString})");
break;
case Pathfinder.Decision.AttackType:
Attack(decision.attackTarget!);
@ -95,48 +85,4 @@ public class NekoEnemy : Enemy {
}
}
}
private class NekoPathfinder : RoamingPathfinder {
// private Random random = new();
public NekoPathfinder(Enemy enemy, int tolerance) : base(enemy, tolerance) {
this.tolerance = tolerance;
AdditionalTileFilter = t => ((NekoEnemy)Enemy).Aggressive || t.Owner == null || !t.Lit;
}
// 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(((NekoEnemy)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();
// }
}
}