První 3 monstra z plánovaných pěti. Kompletní pathfinding i zrcadlení do clienta. Útoky implementované nejsou. Lurk a Neko jsou hardcoded aby útočili na P1.

This commit is contained in:
Perry 2026-03-08 16:55:49 +01:00
parent 4484b127c5
commit 9bfe63a166
27 changed files with 772 additions and 47 deletions

View file

@ -0,0 +1,60 @@
using System.Diagnostics;
namespace FNAF_Server.Enemies;
public class MovementOpportunity {
public int Interval{ get; set; }
// public double ChanceDenominator;
public double MovementChance{ get; set; }
public bool Running => stopwatch.IsRunning;
public bool ConstantChance{ get; private set; }
private Stopwatch stopwatch = new();
private int stopwatchOffset = 0;
private Random random = new();
public MovementOpportunity(int intervalMs, double movementChance) {
Interval = intervalMs;
MovementChance = movementChance;
GuaranteeSuccess(false);
ConstantChance = true; // unused
}
public MovementOpportunity(int intervalMs) {
Interval = intervalMs;
GuaranteeSuccess(true);
MovementChance = 1;
}
public void Start() {
stopwatch.Start();
}
public void Stop() {
stopwatch.Stop();
}
public bool Check() {
if (stopwatch.ElapsedMilliseconds + stopwatchOffset >= Interval){
stopwatchOffset = (int)(stopwatch.ElapsedMilliseconds - Interval);
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;
}
}