mirror of
https://github.com/Phantop/LADXHD.git
synced 2024-11-01 12:24:16 +00:00
51 lines
1.1 KiB
C#
51 lines
1.1 KiB
C#
|
|
|||
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|