using GlobalClassLib; using ONDServer.Map; using ONDServer.Net; using PacketLib; namespace ONDServer.Enemies; public class MareEnemy : Enemy { public override string Name{ get; } = "Mare"; public override EnemyType Type{ get; } = EnemyType.MARE; public override bool BlocksTile{ get; set; } = true; private readonly RoamingPathfinder pathfinder; public ServerPlayer? Target{ get; set; } public MareEnemy(int difficulty) : base(difficulty, 6000) { pathfinder = new RoamingPathfinder(this, 1){ AdditionalConnectorFilter = c => c.Type != ConnectorType.VENT }; } public override void Reset() { pathfinder.TakenPath.Clear(); Target = Server.OtherPlayer(Target); Pathfinder.Decision decision = pathfinder.DecideNext(MapManager.Get(Target.State.OfficeTileId)); if (decision.type == Pathfinder.Decision.MoveType){ Location = decision.nextTile!; } Server.SendUpdateToAll([GameEvent.ENEMY_RESET(Id, Location.Id)]); } public override void Spawn(MapTile location) { base.Spawn(location); 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{ Target = new Random().Next(2) == 0 ? Server.P1 : Server.P2; } MovementOpportunity.Start(); pathfinder.TakenPath.Add(Location); Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(Type, Id, Difficulty, Location.Id)]); } public override void Update() { base.Update(); if (MovementOpportunity.CheckAndRoll()){ if (Location.Owner != null && Location.Lit){ Attack(Location.Owner); } if (Target == null) return; Pathfinder.Decision decision = pathfinder.DecideNext(MapManager.Get(Target.State.OfficeTileId)); switch (decision.type){ case Pathfinder.Decision.MoveType: 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; } } } }