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

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
namespace XFEEDToolBox.Plugin;

internal static unsafe partial class Navigation
{
    // The server quote belongs to this exact docked ship, independently of
    // the shared request/receipt slot used by subsequent trade operations.
    private struct ServiceQuoteSnapshot
    {
        internal CommerceReadRequest source;
        internal string? body;
        internal uint consumed;
    }
    private static ServiceQuoteSnapshot serviceQuoteSnapshot;
    private static bool ServiceQuoteMatches(in ServiceQuoteSnapshot quote,in Snapshot frame,nuint backend,uint market,ulong generation,uint kind,ulong now,ulong epoch)
        =>kind is >=4 and <=7&&quote.body is {Length:>0}&&quote.source.kind==3&&quote.source.state==3
        &&quote.source.generation==generation&&generation!=0&&quote.source.market==market&&quote.source.maintenance==backend
        &&quote.source.entity==frame.entity&&quote.source.life==frame.life&&quote.source.epoch==epoch
        &&now>=quote.source.observed&&now-quote.source.observed<=30000&&(quote.consumed&(1u<<(int)kind))==0;
    private static void CaptureServiceQuote(in CommerceReadRequest work,string body)
    {
        if(work.kind==3&&work.state==3&&body.Length!=0)serviceQuoteSnapshot=new(){source=work,body=body};
    }
    private static uint ServiceQuotesSelfTest()
    {
        var frame=new Snapshot{entity=12,life=34};
        var quote=new ServiceQuoteSnapshot{source=new(){generation=5,entity=12,life=34,epoch=7,kind=3,state=3,market=42,maintenance=56,observed=100},body="original"};
        bool Matches(ServiceQuoteSnapshot value,Snapshot actual,nuint backend=56,uint market=42,ulong generation=5,uint kind=4,ulong now=101,ulong epoch=7)
            =>ServiceQuoteMatches(value,actual,backend,market,generation,kind,now,epoch);
        uint passed=0;
        if(Matches(quote,frame)&&Matches(quote,frame,kind:7))passed|=1;
        if(!Matches(quote,frame,generation:4)&&!Matches(quote,frame,generation:0))passed|=2;
        if(!Matches(quote,frame,market:43)&&!Matches(quote,frame,backend:57))passed|=4;
        if(!Matches(quote,new Snapshot{entity=13,life=34})&&!Matches(quote,new Snapshot{entity=12,life=35}))passed|=8;
        if(!Matches(quote,frame,epoch:8)&&!Matches(quote,frame,now:99)&&!Matches(quote,frame,now:30101))passed|=16;
        quote.consumed=1u<<4;if(!Matches(quote,frame)&&Matches(quote,frame,kind:5))passed|=32;quote.consumed=0;
        quote.source.kind=1;if(!Matches(quote,frame))passed|=64;quote.source.kind=3;
        quote.source.state=4;if(!Matches(quote,frame)&&!Matches(quote,frame,kind:3)&&!Matches(quote,frame,kind:8))passed|=128;
        return passed;
    }
#if PLUGIN_NAVIGATION
    [UnmanagedCallersOnly(EntryPoint="XFENavigationServiceQuotesSelfTest")]
    internal static uint ExportServiceQuotesSelfTest()=>RunTest(ServiceQuotesSelfTest);
#endif
}