OneNightDuel/FNAF_Server/Enemies/SpotEnemy.cs

95 lines
No EOL
3.3 KiB
C#

using FNAF_Server.Map;
using GlobalClassLib;
using PacketLib;
namespace FNAF_Server.Enemies;
public class SpotEnemy : Enemy {
public SpotEnemy(int difficulty) : base(difficulty) {
path = [MapManager.Get(10), MapManager.Get(11), MapManager.Get(12), MapManager.Get(13), MapManager.Get(14)];
pathId = 2;
movementOpportunity = new(6000, (2 * Math.Sign(difficulty) + difficulty) / 12.0);
}
public override string Name{ get; } = "Spot";
public override int TypeId{ get; } = (int)EnemyType.SPOT;
public override bool BlocksTile{ get; set; } = false;
public bool Active{ get; set; } = false;
private MovementOpportunity movementOpportunity;
private MapTile[] path;
private int pathId;
private int p1WatchCounter = 0;
private int p2WatchCounter = 0;
public override void Reset() {
pathId = 2;
Location = path[pathId];
Server.SendUpdateToAll([GameEvent.ENEMY_RESET(Id, Location.Id)]);
}
public override void Attack(ServerPlayer player) {
throw new NotImplementedException();
}
public override void Update() {
if (GameLogic.NSecondUpdate){
if(!movementOpportunity.Running)
movementOpportunity.Start();
if (Active){
if (Server.P1.state.monitorUp && Server.P1.state.camera == Location.Id) p1WatchCounter++;
if (Server.P2.state.monitorUp && Server.P2.state.camera == Location.Id) p2WatchCounter++;
Console.WriteLine($"P1: {p1WatchCounter} | P2: {p2WatchCounter}");
}
}
if (movementOpportunity.CheckAndRoll()){
if(!Active) {
Active = true;
movementOpportunity.Interval = 12_000;
movementOpportunity.GuaranteeSuccess(true);
Server.SendUpdateToAll([GameEvent.SPOT_SET_ACTIVE(Id, true)]);
}
else{
movementOpportunity.Interval = 6000;
movementOpportunity.GuaranteeSuccess(false);
movementOpportunity.Stop();
if (p1WatchCounter > p2WatchCounter){
pathId++;
if (Location.GetConnector(path[pathId])!.Blocked){
Reset();
}
else if (pathId == path.Length - 1){
Attack(Server.P1);
}
}
else if (p2WatchCounter > p1WatchCounter){
pathId--;
if (Location.GetConnector(path[pathId])!.Blocked){
Reset();
}
else if (pathId == 0){
Attack(Server.P2);
}
}
Location = path[pathId];
Active = false;
p1WatchCounter = 0;
p2WatchCounter = 0;
Server.SendUpdateToAll([GameEvent.ENEMY_MOVEMENT(Id, Location.Id), GameEvent.SPOT_SET_ACTIVE(Id, false)]);
}
}
}
public override void Spawn(MapTile location) {
base.Spawn(location);
Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(TypeId, Id, Difficulty, Location.Id)]);
}
}