Unmount: Make sure to call twice if you've been in flight initially

This commit is contained in:
Liza 2024-06-15 22:22:00 +02:00
parent 83de113c08
commit 63b3f4cd3a
Signed by: liza
GPG Key ID: 7199F8D727D55F67

View File

@ -9,7 +9,7 @@ internal sealed class UnmountTask(ICondition condition, ILogger<UnmountTask> log
: ITask
{
private bool _unmountTriggered;
private DateTime _unmountedAt = DateTime.MinValue;
private DateTime _continueAt = DateTime.MinValue;
public bool Start()
{
@ -17,26 +17,34 @@ internal sealed class UnmountTask(ICondition condition, ILogger<UnmountTask> log
return false;
logger.LogInformation("Step explicitly wants no mount, trying to unmount...");
if (condition[ConditionFlag.InFlight])
{
gameFunctions.Unmount();
return true;
}
_unmountTriggered = gameFunctions.Unmount();
if (_unmountTriggered)
_unmountedAt = DateTime.Now;
_continueAt = DateTime.Now.AddSeconds(1);
return true;
}
public ETaskResult Update()
{
if (_continueAt >= DateTime.Now)
return ETaskResult.StillRunning;
if (!_unmountTriggered)
{
// if still flying, we still need to land
if (condition[ConditionFlag.InFlight])
gameFunctions.Unmount();
else
_unmountTriggered = gameFunctions.Unmount();
if (_unmountTriggered)
_unmountedAt = DateTime.Now;
_continueAt = DateTime.Now.AddSeconds(0.5);
return ETaskResult.StillRunning;
}
if (DateTime.Now < _unmountedAt.AddSeconds(1))
return ETaskResult.StillRunning;
return condition[ConditionFlag.Mounted]
? ETaskResult.StillRunning
: ETaskResult.TaskComplete;