using GlobalClassLib; using ONDServer.Map; using ONDServer.Net; using PacketLib; namespace ONDServer.Enemies; public class DashEnemy : Enemy { public DashEnemy(int difficulty) : base(difficulty, 5000) { MovementOpportunity = new(5000); SetDifficulty(difficulty); } public override string Name{ get; } = "Dash"; public override EnemyType Type{ get; } = EnemyType.DASH; public override bool BlocksTile{ get; set; } = false; private readonly (MapTile tile, Direction p1AttackDir, Direction p2AttackDir)[] positions =[ (MapManager.Get(7), Direction.EAST, Direction.WEST), (MapManager.Get(12), Direction.NORTH, Direction.NORTH), (MapManager.Get(17), Direction.WEST, Direction.EAST) ]; private int currentPosIndex = 0; private Random random = new(); public override void Reset() { int roll = random.Next(0, positions.Length - 1); if (roll >= currentPosIndex) roll++; currentPosIndex = roll; Location = positions[roll].tile; Server.SendUpdateToAll([GameEvent.ENEMY_RESET(Id, Location.Id)]); } public override void Spawn(MapTile location) { currentPosIndex = positions.ToList().FindIndex(p => p.tile == location); if (currentPosIndex == -1){ Console.WriteLine("Dash failed to spawn on " + location.Id); return; } base.Spawn(location); MovementOpportunity.Start(); Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(Type, Id, Difficulty, Location!.Id)]); } public override void Update() { base.Update(); if (MovementOpportunity.CheckAndRoll()){ bool attackP1 = !Server.P1.State.DoorStates[(int)positions[currentPosIndex].p1AttackDir]; bool attackP2 = !Server.P2.State.DoorStates[(int)positions[currentPosIndex].p2AttackDir]; if (attackP1 != attackP2){ if(attackP1) Attack(Server.P1); else if(attackP2) Attack(Server.P2); return; } Reset(); } } }