XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using XFEEDToolBox.Core.Models;

namespace XFEEDToolBox.Core.Navigation;

public enum StationDepartureAction { WaitForNative,Completed,CancelNativeForTakeover,RecoverSession,ManualTakeover,ContinueVerifiedDeparture }

/// <summary>Continue a verified original exit outside the station envelope; complete only when the original FSD is ready.</summary>
public static class StationDepartureTakeoverPolicy
{
    public static readonly TimeSpan TakeoverAfter=TimeSpan.FromMinutes(2);
    public static readonly TimeSpan CancellationObservationLimit=TimeSpan.FromSeconds(2);

    public static StationDepartureAction Decide(SystemFlightFrame frame,SystemNavigationTarget origin,PlayerState player,
        DateTimeOffset launchRequestedJournalAt,TimeSpan elapsed,DateTimeOffset now,bool nativeStateVerified,bool launchActive,bool launchRequested,bool nativeDutyActive,bool cancellationTargetVerified=true,
        StationDeparturePathEvidence? departurePath=null)
    {
        if(frame.PlayerOverride)return StationDepartureAction.ManualTakeover;
        var departed=CurrentDepartureFrame(frame,origin,player,launchRequestedJournalAt,now)&&nativeStateVerified;
        var ready=departed&&frame.FsdReady;
        if(ready&&!launchActive&&!launchRequested&&!nativeDutyActive)return StationDepartureAction.Completed;
        if(elapsed>=StationDepartureWatchdog.RecoveryAfter)return StationDepartureAction.RecoverSession;
        if(departed&&!launchActive&&!launchRequested&&!nativeDutyActive&&departurePath?.CanContinue(frame,now)==true)
            return StationDepartureAction.ContinueVerifiedDeparture;
        // A landing/other original duty is not an owned launch to cancel.
        // The eventual handoff still requires all three flags to be inactive.
        if(ready&&(launchActive||launchRequested)&&cancellationTargetVerified&&elapsed>=TakeoverAfter)return StationDepartureAction.CancelNativeForTakeover;
        return StationDepartureAction.WaitForNative;
    }
    internal static bool CurrentDepartureFrame(SystemFlightFrame frame,SystemNavigationTarget origin,PlayerState player,DateTimeOffset launchRequestedJournalAt,DateTimeOffset now)
    {
        var journalNow=GameJournalClock.Now(player,now);
        var departed=player.InGame&&!player.Docked&&player.Navigation.UndockedAt is {} at&&at>=launchRequestedJournalAt.AddSeconds(-1)&&at<=journalNow.AddSeconds(5);
        return departed&&frame.InGame&&!frame.PlayerOverride&&!frame.ExternalThreat&&frame.Mode==LocalFlightMode.Normal
            &&frame.GeometryVerified&&frame.ShipEntity!=0&&frame.ReferenceWorld!=0&&frame.Sequence>0
            &&frame.ObservedAt<=now&&now-frame.ObservedAt<=TimeSpan.FromMilliseconds(300)
            &&frame.SystemAddress==origin.SystemAddress&&frame.SelectedTarget is {} selected&&origin.SameIdentity(selected)
            &&frame.Position.Finite&&frame.Velocity.Finite&&frame.TargetPosition.Finite&&frame.TargetVelocity.Finite&&frame.Forward.Finite&&frame.Forward.Length>.9;
    }
}