mirror of
https://github.com/D1GQ/BetterAmongUs.git
synced 2026-10-20 01:46:19 +00:00
55 lines
1.3 KiB
C#
55 lines
1.3 KiB
C#
// Code from: https://github.com/0xDrMoe/TownofHost-Enhanced
|
|
|
|
using System.Linq;
|
|
|
|
namespace BetterAmongUs;
|
|
|
|
class LateTask
|
|
{
|
|
public string name;
|
|
public float timer;
|
|
public bool shouldLog;
|
|
public Action action;
|
|
public static List<LateTask> Tasks = [];
|
|
public bool Run(float deltaTime)
|
|
{
|
|
timer -= deltaTime;
|
|
if (timer <= 0)
|
|
{
|
|
action();
|
|
|
|
if (shouldLog == true)
|
|
Logger.Log($"{name} has finished", "LateTask");
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
public LateTask(Action action, float time, string name = "No Name Task", bool shoudLog = true)
|
|
{
|
|
this.action = action;
|
|
this.timer = time;
|
|
this.name = name;
|
|
this.shouldLog = shoudLog;
|
|
Tasks.Add(this);
|
|
}
|
|
public static void Update(float deltaTime)
|
|
{
|
|
var TasksToRemove = new List<LateTask>();
|
|
foreach (var task in Tasks.ToArray())
|
|
{
|
|
try
|
|
{
|
|
if (task.Run(deltaTime))
|
|
{
|
|
TasksToRemove.Add(task);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TasksToRemove.Add(task);
|
|
Logger.Error(ex.ToString());
|
|
}
|
|
}
|
|
TasksToRemove.ForEach(task => Tasks.Remove(task));
|
|
}
|
|
} |