Projekt přejmenován. Neko nastaven na výchozí pozici

This commit is contained in:
Perry 2026-03-22 18:31:05 +01:00
parent 1a27dd6fab
commit ceac37920b
104 changed files with 873 additions and 208 deletions

View file

@ -0,0 +1,70 @@
using System.Net.Mime;
using GlobalClassLib;
using ONDServer.Map;
using PacketLib;
namespace ONDServer.Enemies;
public class DashEnemy : Enemy {
public DashEnemy(int difficulty) : base(difficulty) {
movementOpportunity = new(5000);
SetDifficulty(difficulty);
}
public override string Name{ get; } = "Dash";
public override int TypeId{ get; } = (int)EnemyType.DASH;
public override bool BlocksTile{ get; set; } = false;
private MovementOpportunity movementOpportunity;
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 SetDifficulty(int difficulty) {
Difficulty = difficulty;
movementOpportunity.MovementChance = (2 * Math.Sign(difficulty) + difficulty) / 12.0;
}
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(TypeId, 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();
}
}
}

View file

@ -0,0 +1,35 @@
using GlobalClassLib;
using ONDServer.Map;
using PacketLib;
namespace ONDServer.Enemies;
public abstract class Enemy : GlobalEnemy<MapTile, TileConnector> {
public int Difficulty { get; protected set; }
protected Enemy(int difficulty) {
Difficulty = difficulty;
}
public abstract bool BlocksTile { get; set; }
public bool Spawned { get; set; }
public virtual void SpawnSilent(MapTile location) {
Console.WriteLine($"!!! Silent spawn not implemented for enemy {TypeId} ({Name}), reverting to regular spawn");
Spawn(location);
}
public override void Spawn(MapTile location) {
base.Spawn(location);
Spawned = true;
}
public abstract void Reset();
public virtual void Attack(ServerPlayer player) {
Server.SendUpdateToAll([GameEvent.ENEMY_ATTACK(Id, player.state.pid)]);
GameLogic.DeclareWinner(Server.OtherPlayer(player));
}
public abstract void SetDifficulty(int difficulty);
}

View file

@ -0,0 +1,32 @@
using ONDServer.Map;
namespace ONDServer.Enemies;
public class EnemyManager {
private static Dictionary<int, Enemy> enemies = new();
public static void Update() {
foreach (var pair in enemies){
if (pair.Value.Spawned) pair.Value.Update();
}
}
public static Enemy AddEnemy(Enemy enemy) {
enemies.Add(enemy.Id, enemy);
return enemy;
}
public static Enemy[] GetByLocation(MapTile tile) {
List<Enemy> output = new();
foreach (var e in enemies.Values){
if (e.Location == tile){
output.Add(e);
}
}
return output.ToArray();
}
public static Enemy Get(int id) => enemies[id];
public static Enemy[] GetAll() => enemies.Values.ToArray();
}

View file

@ -0,0 +1,5 @@
namespace ONDServer.Enemies;
public interface ITargetingEnemy {
ServerPlayer Target { get; set; }
}

View file

@ -0,0 +1,131 @@
using System.Diagnostics;
using System.Reflection;
using GlobalClassLib;
using ONDServer.Map;
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 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
private MovementOpportunity movementOpportunity;
public ServerPlayer? Target{ get; set; }
public LurkEnemy(int difficulty) : base(difficulty) {
pathfinder = new LurkPathfinder(this, 1);
movementOpportunity = new MovementOpportunity(5000);
Target = null;
SetDifficulty(difficulty);
}
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)]);
}
public override void Reset() {
pathfinder.TakenPath.Clear();
pathfinder.TakenPath.Add(Location);
Target.state.power -= 30;
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)];
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){
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 {TypeId} ({Name}) moving to {Location.PositionAsString})");
break;
case Pathfinder.Decision.AttackType:
Attack(decision.attackTarget!);
break;
case Pathfinder.Decision.ResetType:
Reset();
break;
case Pathfinder.Decision.WaitType:
break;
}
}
}
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();
// }
}
}

View file

@ -0,0 +1,130 @@
using GlobalClassLib;
using ONDServer.Map;
using PacketLib;
namespace ONDServer.Enemies;
public class MareEnemy : Enemy {
public override string Name{ get; } = "Mare";
public override int TypeId{ get; } = (int)EnemyType.MARE;
public override bool BlocksTile{ get; set; } = true;
private MarePathfinder pathfinder;
private MovementOpportunity movementOpportunity;
public ServerPlayer Target{ get; set; }
public MareEnemy(int difficulty) : base(difficulty) {
pathfinder = new MarePathfinder(this, 1);
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 = new MovementOpportunity(5000);
SetDifficulty(difficulty);
}
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 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 Spawn(MapTile location) {
base.Spawn(location);
// stopwatch.Start();
movementOpportunity.Start();
pathfinder.TakenPath.Add(Location);
Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(TypeId, Id, Difficulty, Location.Id)]);
}
public override void Update() {
base.Update();
if (movementOpportunity.CheckAndRoll()){
if (Location.Owner != null && Location.Lit){
Attack(Location.Owner);
}
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 {TypeId} ({Name}) moving to {Location.PositionAsString})");
break;
case Pathfinder.Decision.AttackType:
Attack(decision.attackTarget!);
break;
case Pathfinder.Decision.ResetType:
Reset();
break;
case Pathfinder.Decision.WaitType:
break;
}
}
}
private class MarePathfinder : RoamingPathfinder {
// private Random random = new();
public MarePathfinder(Enemy enemy, int tolerance) : base(enemy, tolerance) {
this.tolerance = tolerance;
AdditionalConnectorFilter = c => c.Type != ConnectorType.VENT;
}
// 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(((MareEnemy)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();
// }
}
}

View file

@ -0,0 +1,62 @@
using System.Diagnostics;
namespace ONDServer.Enemies;
public class MovementOpportunity {
public int Interval{ get; set; }
// public double ChanceDenominator;
public double MovementChance{
get;
set{
field = value;
GuaranteeSuccess(value >= 1);
}
}
public bool Running => stopwatch.IsRunning;
private Stopwatch stopwatch = new();
private long stopwatchOffset = 0;
private Random random = new();
public MovementOpportunity(int intervalMs, double movementChance) {
Interval = intervalMs;
MovementChance = movementChance;
}
public MovementOpportunity(int intervalMs) {
Interval = intervalMs;
MovementChance = 1;
}
public void Start() {
stopwatch.Start();
}
public void Stop() {
stopwatch.Stop();
}
public bool Check() {
if (stopwatch.ElapsedMilliseconds - stopwatchOffset >= Interval){
int overshoot = (int)(stopwatch.ElapsedMilliseconds - stopwatchOffset - Interval);
stopwatchOffset = stopwatch.ElapsedMilliseconds - overshoot;
// stopwatch.Restart();
return true;
}
return false;
}
public bool Roll() => roll();
private Func<bool> roll = () => true;
public bool CheckAndRoll() {
if (Check()) return Roll();
return false;
}
public void GuaranteeSuccess(bool value) {
roll = value ? () => true : () => random.NextDouble() <= MovementChance;
}
}

View file

@ -0,0 +1,140 @@
using GlobalClassLib;
using ONDServer.Map;
using PacketLib;
namespace ONDServer.Enemies;
public class NekoEnemy : Enemy {
private MovementOpportunity movementOpportunity;
private RoamingPathfinder pathfinder;
public NekoEnemy(int difficulty) : base(difficulty) {
pathfinder = new RoamingPathfinder(this, 1){AdditionalTileFilter = t => Aggressive || t.Owner == null || !t.Lit};
movementOpportunity = new MovementOpportunity(5000);
SetDifficulty(difficulty);
}
public override string Name{ get; } = "Neko";
public override int TypeId{ get; } = (int)EnemyType.NEKO;
public override bool BlocksTile{ get; set; } = true;
public bool Aggressive = false;
public ServerPlayer? Target{ get; set; }
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)]);
}
public override void Reset() {
pathfinder.TakenPath.Clear();
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)];
Aggressive = false;
Target = Server.OtherPlayer(Target);
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 (Location.Owner != null && Location.Lit && !Aggressive){
Aggressive = true;
Server.SendUpdateToAll([GameEvent.NEKO_ANGERED(Location.Owner.state.pid, Id)]);
}
if (Target == null){
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{
if (GameLogic.PhaseCounter > 1){
Target = Server.Players[new Random().Next(2)];
SetDifficulty(8);
}
}
}
if (Target != null && (movementOpportunity.CheckAndRoll() || (Aggressive && GameLogic.NSecondUpdate))){
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 {TypeId} ({Name}) moving to {Location.PositionAsString})");
break;
case Pathfinder.Decision.AttackType:
Attack(decision.attackTarget!);
break;
case Pathfinder.Decision.ResetType:
Reset();
break;
case Pathfinder.Decision.WaitType:
Aggressive = false;
break;
}
}
}
private class NekoPathfinder : RoamingPathfinder {
// private Random random = new();
public NekoPathfinder(Enemy enemy, int tolerance) : base(enemy, tolerance) {
this.tolerance = tolerance;
AdditionalTileFilter = t => ((NekoEnemy)Enemy).Aggressive || t.Owner == null || !t.Lit;
}
// 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(((NekoEnemy)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();
// }
}
}

View file

@ -0,0 +1,36 @@
using ONDServer.Map;
namespace ONDServer.Enemies;
public abstract class Pathfinder {
public Enemy Enemy;
public Pathfinder(Enemy enemy) {
Enemy = enemy;
}
public abstract Decision DecideNext(MapTile goal);
// protected abstract Dictionary<MapTile, int> Crawl(MapTile tile); // fill Distances with all reachable tiles
protected virtual List<MapTile> GetNeighbours(MapTile tile, Predicate<TileConnector> connectorFilter, Predicate<MapTile> tileFilter) {
return tile.GetAllConnectors().Where(c => connectorFilter(c)).Select(c => c.OtherTile(tile)).Where(t => tileFilter(t)).ToList();
}
public class Decision {
public int type;
public MapTile? nextTile;
public ServerPlayer? attackTarget;
private Decision() { }
public static Decision Move(MapTile tile) => new() { type = MoveType, nextTile = tile };
public static Decision Attack(ServerPlayer player) => new(){ type = AttackType, attackTarget = player };
public static Decision Reset() => new(){ type = ResetType };
public static Decision Wait() => new(){ type = WaitType };
public const int MoveType = 0;
public const int AttackType = 1;
public const int ResetType = 2;
public const int WaitType = 3;
}
}

View file

@ -0,0 +1,82 @@
using GlobalClassLib;
using ONDServer.Map;
namespace ONDServer.Enemies;
public class RoamingPathfinder : Pathfinder {
public Predicate<MapTile> AdditionalTileFilter{ get; set; } = _ => true;
public Predicate<TileConnector> AdditionalConnectorFilter{ get; set; } = _ => true;
protected int tolerance;
public List<MapTile> TakenPath { get; } = new();
private Random random = new();
// private Func<TileConnector, MapTile, bool> defaultConnectorFilter;
public RoamingPathfinder(Enemy enemy, int tolerance) : base(enemy) {
this.tolerance = tolerance;
}
protected Dictionary<MapTile, int> Crawl(MapTile tile) {
Dictionary<MapTile, int> distances = new(){ [tile] = 0 };
CrawlStep(tile, distances);
return distances;
}
private void CrawlStep(MapTile tile, Dictionary<MapTile, int> distances) {
List<MapTile> neighbours = GetNeighbours(tile,
c =>
AdditionalConnectorFilter(c) &&
(!c.Blocked || c.Type == ConnectorType.DOOR_OFFICE) &&
tile != Enemy.Location &&
(!distances.ContainsKey(c.OtherTile(tile)) || distances[c.OtherTile(tile)] > distances[tile] + c.Value),
t =>
AdditionalTileFilter(t) &&
(!Enemy.BlocksTile || EnemyManager.GetByLocation(t).All(e => !e.BlocksTile || e == Enemy)) &&
Server.Players.All(p => p.Value.state.officeTileId != t.Id));
neighbours.ForEach(t => distances[t] = distances[tile] + tile.GetConnector(t)!.Value);
if (neighbours.Count != 0){
neighbours.ForEach(t => CrawlStep(t, distances));
}
}
public override Decision DecideNext(MapTile goal) {
Dictionary<MapTile, int> distances = Crawl(goal);
List<MapTile> closerTiles = GetNeighbours(Enemy.Location,
c => AdditionalConnectorFilter(c) && !c.Blocked || c.Type == ConnectorType.DOOR_OFFICE,
t => AdditionalTileFilter(t) && distances.ContainsKey(t) && distances[t] + t.GetConnector(Enemy.Location).Value <= distances[Enemy.Location] + tolerance);
if (closerTiles.Contains(goal)){
if (Enemy.Location.GetConnector(goal)!.Blocked){
return Decision.Reset();
}
IEnumerable<ServerPlayer> players = Server.Players.Values.Where(p => p.state.officeTileId == goal.Id);
if (players.Count() == 1){
return Decision.Attack(players.First());
}
return Decision.Move(goal);
}
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){
double value = 1.0 / distances[tile];
if (roll <= value){
TakenPath.Add(tile);
return Decision.Move(tile);
}
roll -= value;
}
return Decision.Wait();
}
}

View file

@ -0,0 +1,97 @@
using GlobalClassLib;
using ONDServer.Map;
using PacketLib;
namespace ONDServer.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);
SetDifficulty(difficulty);
}
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 SetDifficulty(int difficulty) {
Difficulty = difficulty;
movementOpportunity.MovementChance = (2 * Math.Sign(difficulty) + difficulty) / 12.0;
}
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.P2);
}
}
else if (p2WatchCounter > p1WatchCounter){
pathId--;
if (Location.GetConnector(path[pathId])!.Blocked){
Reset();
}
else if (pathId == 0){
Attack(Server.P1);
}
}
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)]);
}
}