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:
parent
4484b127c5
commit
9bfe63a166
27 changed files with 772 additions and 47 deletions
60
FNAF_Server/Enemies/MovementOpportunity.cs
Normal file
60
FNAF_Server/Enemies/MovementOpportunity.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue