LADXHD/InGame/GameObjects/Base/Components/AI/AiTriggerRandomTime.cs

51 lines
1.1 KiB
C#
Raw Normal View History

2023-12-14 22:21:22 +00:00

namespace ProjectZ.InGame.GameObjects.Base.Components.AI
{
class AiTriggerRandomTime : AiTrigger
{
public delegate void TriggerFunction();
public TriggerFunction Triggered;
public double CurrentTime;
public int MinTime;
public int MaxTime;
public bool IsRunning = true;
public bool ResetAfterEnd = true;
public AiTriggerRandomTime(TriggerFunction triggered, int minTime, int maxTime)
{
Triggered = triggered;
MinTime = minTime;
MaxTime = maxTime;
}
public override void OnInit()
{
IsRunning = true;
CurrentTime = Game1.RandomNumber.Next(MinTime, MaxTime);
}
public override void Update()
{
if (!IsRunning)
return;
CurrentTime -= Game1.DeltaTime;
if (CurrentTime > 0)
return;
Triggered();
if (ResetAfterEnd)
OnInit();
else
IsRunning = false;
}
}
}