Všechna monstra, dynamický targeting. Bugfixy u monster.

This commit is contained in:
Perry 2026-03-17 20:14:29 +01:00
parent 55fd052072
commit 4fdff0a0cc
18 changed files with 345 additions and 43 deletions

View file

@ -10,17 +10,23 @@ public class NekoEnemy : Enemy {
public NekoEnemy(int difficulty) : base(difficulty) {
pathfinder = new NekoPathfinder(this, 1);
movementOpportunity = new MovementOpportunity(5000);
SetDifficulty(difficulty);
}
public override string Name{ get; } = "Neko";
public override int TypeId{ get; } = 1;
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 = new MovementOpportunity(5000, ((2 + Math.Pow(1.5f, Difficulty)) * Math.Sign(Difficulty)) / (2 + Math.Pow(1.5f, 10)));
movementOpportunity.Start();
pathfinder.takenPath.Add(Location);
Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(TypeId, Id, Difficulty, Location.Id)]);
@ -30,14 +36,38 @@ public class NekoEnemy : Enemy {
pathfinder.takenPath.Clear();
MapTile[] resetLocations = new[]{MapManager.Get(7), MapManager.Get(12), MapManager.Get(17)}.Where(t => EnemyManager.GetByLocation(t).Length == 0).ToArray();
Location = resetLocations[new Random().Next(resetLocations.Length)];
Aggressive = false;
Server.SendUpdateToAll([GameEvent.ENEMY_RESET(Id, Location.Id)]);
}
public override void SetDifficulty(int difficulty) {
Difficulty = difficulty;
movementOpportunity.MovementChance =
((2 + Math.Pow(1.5f, Difficulty)) * Math.Sign(Difficulty)) / (2 + Math.Pow(1.5f, 10));
}
public override void Update() {
base.Update();
if (movementOpportunity.CheckAndRoll()){
Pathfinder.Decision decision = pathfinder.DecideNext(MapManager.Get(10));
if (Location.Owner != null && Location.Lit){
Aggressive = true;
Server.SendUpdateToAll([GameEvent.NEKO_ANGERED(Location.Owner.state.pid, Id)]);
}
if (movementOpportunity.CheckAndRoll() || (Aggressive && GameLogic.NSecondUpdate)){
if (Target == null){
if (Server.P1.state.power > Server.P2.state.power){
Target = Server.P2;
}
else if (Server.P1.state.power < Server.P2.state.power){
Target = Server.P1;
}
else{
return;
}
}
Pathfinder.Decision decision = pathfinder.DecideNext(MapManager.Get(Target.state.officeTileId));
switch (decision.type){
case Pathfinder.Decision.MoveType:
Location = decision.nextTile!;
@ -51,6 +81,7 @@ public class NekoEnemy : Enemy {
Reset();
break;
case Pathfinder.Decision.WaitType:
Aggressive = false;
break;
}
}
@ -64,6 +95,7 @@ public class NekoEnemy : Enemy {
public NekoPathfinder(Enemy enemy, int tolerance) : base(enemy) {
this.tolerance = tolerance;
AdditionalTileFilter = t => ((NekoEnemy)Enemy).Aggressive || t.Owner == null || !t.Lit;
}
public override Decision DecideNext(MapTile goal) {
@ -71,13 +103,15 @@ public class NekoEnemy : Enemy {
List<MapTile> closerTiles = GetNeighbours(Enemy.Location,
c => !c.Blocked || c.Type == ConnectorType.DOOR_OFFICE,
t => distances.ContainsKey(t) && distances[t] <= distances[Enemy.Location] + tolerance);
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(Server.P1); // TODO: un-hardcode this
return Decision.Attack(((NekoEnemy)Enemy).Target);
}
if (closerTiles.Count != 0 && closerTiles.All(t => takenPath.Contains(t))){