OneNightDuel/ONDServer/Enemies/LurkEnemy.cs

77 lines
No EOL
2.8 KiB
C#

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 EnemyType Type{ get; } = EnemyType.LURK;
public override bool BlocksTile{ get; set; } = true;
public ServerPlayer? Target{ get; set; }
private readonly RoamingPathfinder pathfinder;
public LurkEnemy(int difficulty) : base(difficulty, 5000) {
pathfinder = new RoamingPathfinder(this, 1);
Target = null;
}
public override void Spawn(MapTile location) {
base.Spawn(location);
MovementOpportunity.Start();
pathfinder.TakenPath.Add(Location!);
Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(Type, Id, Difficulty, Location!.Id)]);
}
public override void Reset() {
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();
pathfinder.TakenPath.Add(Location);
Server.SendUpdateToAll([GameEvent.ENEMY_RESET(Id, Location.Id)]);
}
public override void Update() {
base.Update();
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){
Target = Server.P2;
}
else{
return;
}
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 {Type} ({Name}) moving to {Location.IdAsString})");
break;
case Pathfinder.Decision.AttackType:
Attack(decision.attackTarget!);
break;
case Pathfinder.Decision.ResetType:
Reset();
break;
case Pathfinder.Decision.WaitType:
break;
}
}
}
}