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
|
|
@ -2,41 +2,33 @@ using System.Diagnostics;
|
|||
using System.Reflection;
|
||||
using GlobalClassLib;
|
||||
using ONDServer.Map;
|
||||
using ONDServer.Net;
|
||||
using PacketLib;
|
||||
|
||||
namespace ONDServer.Enemies;
|
||||
|
||||
public class LurkEnemy : Enemy {
|
||||
public override string Name{ get; } = "Lurk";
|
||||
public override int TypeId{ get; } = (int)EnemyType.LURK;
|
||||
|
||||
public override EnemyType Type{ get; } = EnemyType.LURK;
|
||||
public override bool BlocksTile{ get; set; } = true;
|
||||
|
||||
private LurkPathfinder pathfinder;
|
||||
|
||||
// private int movementRollInterval = 5000;
|
||||
// private static readonly double CHANCE_DENOMINATOR = 2 + Math.Pow(1.5f, 10); // d10 Lurk will have a 100% chance to move
|
||||
// private double movementChance => (2 + Math.Pow(1.5f, Difficulty)) / CHANCE_DENOMINATOR; // chance scales exponentially using a constant multiplier
|
||||
|
||||
public ServerPlayer? Target{ get; set; }
|
||||
|
||||
private readonly RoamingPathfinder pathfinder;
|
||||
|
||||
public LurkEnemy(int difficulty) : base(difficulty, 5000) {
|
||||
pathfinder = new LurkPathfinder(this, 1);
|
||||
// movementOpportunity = new MovementOpportunity(5000);
|
||||
Target = null;
|
||||
// SetDifficulty(difficulty);
|
||||
pathfinder = new RoamingPathfinder(this, 1);
|
||||
Target = null;
|
||||
}
|
||||
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() {
|
||||
Target.state.power -= 80;
|
||||
|
||||
if (Target != null) Target.State.Power -= 80;
|
||||
|
||||
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)];
|
||||
pathfinder.TakenPath.Clear();
|
||||
|
|
@ -45,26 +37,23 @@ public class LurkEnemy : Enemy {
|
|||
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 (movementOpportunity.CheckAndRoll()){
|
||||
if (Server.P1.state.power > Server.P2.state.power){
|
||||
if(Location == null) return;
|
||||
|
||||
if (MovementOpportunity.CheckAndRoll()){
|
||||
if (Server.P1.State.Power > Server.P2.State.Power){
|
||||
Target = Server.P1;
|
||||
}
|
||||
else if (Server.P1.state.power < Server.P2.state.power){
|
||||
else if (Server.P1.State.Power < Server.P2.State.Power){
|
||||
Target = Server.P2;
|
||||
}
|
||||
else{
|
||||
return;
|
||||
}
|
||||
|
||||
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){
|
||||
|
|
@ -72,7 +61,7 @@ public class LurkEnemy : 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!);
|
||||
|
|
@ -85,45 +74,4 @@ public class LurkEnemy : Enemy {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class LurkPathfinder : RoamingPathfinder {
|
||||
// private Random random = new();
|
||||
|
||||
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();
|
||||
// }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue