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

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Globalization;
using XFEEDToolBox.Core.Outfitting;

namespace XFEEDToolBox.Core.Presentation;

public sealed record ShipDetailValue(string Key,string Name,string OriginalName,string Value);
public sealed record ShipDetailSection(string Key,string Name,string Caption,IReadOnlyList<ShipDetailValue> Values,bool InitiallyExpanded=true);
public sealed class ShipDetailValueLiveRow(ShipDetailValue value):LiveRow<ShipDetailValue>(value)
{
    public string Name=>Record.Name;
    public string OriginalName=>Record.OriginalName;
    public bool HasOriginalName=>Record.OriginalName.Length>0;
    public string Value=>Record.Value;
}
public sealed class ShipDetailSectionLiveRow:LiveRow<ShipDetailSection>
{
    public string Name=>Record.Name;
    public string Caption=>Record.Caption;
    public bool HasCaption=>Record.Caption.Length>0;
    public bool InitiallyExpanded=>Record.InitiallyExpanded;
    public LiveCollection<ShipDetailValueLiveRow,ShipDetailValue,string> Values{get;}=new(v=>v.Key,v=>new(v));
    public ShipDetailSectionLiveRow(ShipDetailSection section):base(section)=>Values.Apply(section.Values);
}

/// <summary>All available values from the same edited build as the compact overview.</summary>
public static class ShipDetailValues
{
    public static IReadOnlyList<ShipDetailSection> Create(ShipOverviewValues overview,EquipmentStatistics? stats,ShipRefitDocument? document)
    {
        static ShipDetailSection Summary(string key,string name,IEnumerable<ShipOverviewMetric> rows)=>new(key,name,"",rows.Select((r,i)=>new ShipDetailValue(i.ToString(),r.Label,"",r.Value)).ToArray());
        var sections=new List<ShipDetailSection>
        {
            Summary("flight","飞行与跃迁",[new("极速 / 加力速度",overview.SpeedText),new("俯仰 / 滚转 / 偏航",overview.RotationText),new("跃迁距离 最小 / 当前 / 最大",overview.JumpText)]),
            Summary("defence","船体与护盾",overview.DefenceHull.Select(r=>r.Label=="动能 / 热能 / 爆炸抗性"?r with{Label="船体 · "+r.Label}:r).Concat(overview.DefenceShield.Select(r=>r.Label=="动能 / 热能 / 爆炸抗性"?r with{Label="护盾 · "+r.Label}:r))),
            Summary("weapons","武器与伤害",overview.WeaponOutput.Concat(overview.WeaponDamage)),
            Summary("capacity","容量、温控与造价",overview.Capacities.Concat(overview.ThermalAndCost)),
            Summary("power","供电与配电",[new("总功率",overview.CapacityText),new("收起时功耗",overview.RetractedText),new("部署时功耗",overview.DeployedText),new("部署后剩余功率",overview.MarginText),new("武器配电",overview.WeaponPipsText)])
        };
        if(stats is not null)
            sections.Add(new("ship","整舰计算参数","完整装配计算结果",stats.Ship.OrderBy(p=>p.Key,StringComparer.Ordinal).Select(p=>Attribute(p.Key,p.Value)).ToArray(),false));
        foreach(var slot in document?.Slots??[])
        {
            if(slot.Module is not {} module)continue;
            var rows=new List<ShipDetailValue>
            {
                new("@state","运行状态","Power state",module.State),
                new("@health","模块完整度","Module integrity",module.HealthText),
                new("@engineering","工程改装","Engineering",module.EngineeringText),
                new("@origin","模块来源","Source",slot.Origin)
            };
            if(module.Value is {} value)rows.Add(new("@cost","记录价值","Recorded value",value.ToString("N0",CultureInfo.InvariantCulture)+" Cr"));
            if(module.AmmoInClip is not null||module.AmmoInHopper is not null)rows.Add(new("@ammo","弹匣 / 储备","Clip / reserve",module.AmmoText));
            if(stats?.Modules.TryGetValue(slot.Slot,out var attributes)==true)
                rows.AddRange(attributes.OrderBy(p=>p.Key,StringComparer.Ordinal).Select(p=>Attribute(p.Key,p.Value,true)));
            foreach(var modifier in module.Engineering?.Modifiers??[])
                rows.Add(new("@modifier:"+modifier.Label,modifier.Display,modifier.EnglishDisplay,""));
            sections.Add(new("module:"+slot.Slot,slot.Caption,slot.OriginalName,rows,false));
        }
        return sections;
    }

    private static ShipDetailValue Attribute(string key,double value,bool module=false)
    {
        var (name,english,unit)=key switch
        {
            "mass"=>("空载质量","Unladen mass"," t"),
            "integ"=>("耐久度","Structural integrity"," HP"),
            "pwrcap"=>("总功率","Power capacity"," MW"),
            "pwrdraw"=>("电量消耗","Power draw"," MW"),
            "pwrdraw_ret"=>("收起时功耗","Retracted power draw"," MW"),
            "pwrdraw_dep"=>("部署时功耗","Deployed power draw"," MW"),
            "heateff"=>("电厂热效率","Power plant heat efficiency",""),
            "_speed"=>("满燃料极速","Full-fuel speed"," m/s"),
            "_boost"=>("满燃料加力速度","Full-fuel boost speed"," m/s"),
            "_jump_laden"=>("满载跃迁距离","Laden jump range"," ly"),
            "_jump_unladen"=>("空载跃迁距离","Unladen jump range"," ly"),
            "_jump_max"=>("最大跃迁距离","Maximum jump range"," ly"),
            "jumpbst"=>("跃迁距离加成","Jump range boost"," ly"),
            "_shields"=>("护盾强度","Shield strength"," MJ"),
            "_armour"=>("船体完整度","Hull strength"," HP"),
            "_skinres"=>("护盾动能抗性","Shield kinetic resistance"," %"),
            "_sthmres"=>("护盾热能抗性","Shield thermal resistance"," %"),
            "_sexpres"=>("护盾爆炸抗性","Shield explosive resistance"," %"),
            "_akinres"=>("船体动能抗性","Hull kinetic resistance"," %"),
            "_athmres"=>("船体热能抗性","Hull thermal resistance"," %"),
            "_aexpres"=>("船体爆炸抗性","Hull explosive resistance"," %"),
            "integ_imrp"=>("模块保护耐久度","Module reinforcement integrity"," HP"),
            "dmgprot"=>("穿透模块伤害比例","Module damage multiplier",""),
            "shieldrnfps_ammomax"=>("护盾电池总回复","Total shield cell reinforcement"," MJ"),
            "dps"=>("总爆发 DPS","Burst damage per second"," DPS"),
            "_sustained_dps_cur"=>("持续 DPS(当前配电)","Sustained DPS at current WEP"," DPS"),
            "_sustained_dps_max"=>("持续 DPS(4 格武器配电)","Sustained DPS at full WEP"," DPS"),
            "dps_kin"=>("动能伤害","Kinetic damage per second"," DPS"),
            "dps_thm"=>("热能伤害","Thermal damage per second"," DPS"),
            "dps_exp"=>("爆炸伤害","Explosive damage per second"," DPS"),
            "dps_abs"=>("绝对伤害","Absolute damage per second"," DPS"),
            "dps_axe"=>("反异种伤害","Anti-xeno damage per second"," DPS"),
            "dps_cau"=>("腐蚀伤害","Caustic damage per second"," DPS"),
            "dps_nodistdraw"=>("不消耗武器电容的 DPS","DPS independent of WEP capacitor"," DPS"),
            "dps_distdraw"=>("消耗武器电容的 DPS","DPS dependent on WEP capacitor"," DPS"),
            "wepchg_sustain_cur"=>("当前配电持续输出比例","Current WEP sustained output ratio",""),
            "wepchg_sustain_max"=>("全武器配电持续输出比例","Full WEP sustained output ratio",""),
            "wepcap_burst_cur"=>("当前配电武器电容续航","Current WEP burst duration"," s"),
            "_wepcap_unlimited"=>("武器电容可持续开火","Unlimited WEP burst duration",""),
            "_engine_pips"=>("引擎配电","ENG pips"," 格"),
            "_weapon_pips"=>("武器配电","WEP pips"," 格"),
            "fuelcap"=>("燃料容量","Fuel capacity"," t"),
            "cargocap"=>("货物容量","Cargo capacity"," t"),
            "cabincap"=>("乘客容量","Passenger capacity"," 人"),
            "cost"=>("装配造价","Loadout cost"," Cr"),
            "cost_rearm"=>("弹药补给费用","Rearm cost"," Cr"),
            "_hull_topspd"=>("船体基础极速","Base hull speed"," m/s"),
            "_hull_bstspd"=>("船体基础加力速度","Base hull boost speed"," m/s"),
            "_hull_minthrust"=>("最低引擎配电推力比例","Minimum ENG thrust"," %"),
            "_hull_pitch"=>("船体基础俯仰","Base hull pitch"," °/s"),
            "_hull_roll"=>("船体基础滚转","Base hull roll"," °/s"),
            "_hull_yaw"=>("船体基础偏航","Base hull yaw"," °/s"),
            "_hull_minpitch"=>("最低配电俯仰","Minimum ENG pitch"," °/s"),
            "_hull_minroll"=>("最低配电滚转","Minimum ENG roll"," °/s"),
            "_hull_minyaw"=>("最低配电偏航","Minimum ENG yaw"," °/s"),
            "_hull_boostcost"=>("加力所需电容","Boost capacitor cost"," MJ"),
            "_hull_hardness"=>("装甲硬度","Hull hardness",""),
            "_hull_heatcap"=>("船体热容量","Hull heat capacity",""),
            "distdraw"=>("能量分配器消耗","Distributor draw"," MW"),
            "pierce"=>("穿甲能力","Armour penetration",""),
            "maximumrng"=>("最大射程","Maximum range"," m"),
            "shotspd"=>("膛速","Projectile speed"," m/s"),
            "rof"=>("射速","Rate of fire"," /s"),
            "ammoclip"=>("弹匣容量","Ammo clip size",""),
            "ammomax"=>("最大储备弹药","Maximum reserve ammunition",""),
            "dmgfall"=>("伤害衰减起始距离","Damage falloff start"," m"),
            "kinwgt"=>("动能伤害占比","Kinetic damage fraction"," %"),
            "thmwgt"=>("热能伤害占比","Thermal damage fraction"," %"),
            "expwgt"=>("爆炸伤害占比","Explosive damage fraction"," %"),
            "abswgt"=>("绝对伤害占比","Absolute damage fraction"," %"),
            "cauwgt"=>("腐蚀伤害占比","Caustic damage fraction"," %"),
            "axewgt"=>("反异种伤害占比","Anti-xeno damage fraction"," %"),
            "fsdoptmass"=>("跃迁引擎最佳质量","FSD optimal mass"," t"),
            "maxfuel"=>("每跳最大燃料","Maximum fuel per jump"," t"),
            "fuelmul"=>("跃迁燃耗系数","FSD fuel multiplier",""),
            "fuelpower"=>("跃迁燃耗指数","FSD fuel exponent",""),
            "scooprate"=>("最大燃料采集速率","Maximum scoop rate"," t/s"),
            "engminmass"=>("推进器最小质量","Thruster minimum mass"," t"),
            "engoptmass"=>("推进器最佳质量","Thruster optimal mass"," t"),
            "engmaxmass"=>("推进器最大质量","Thruster maximum mass"," t"),
            "minmulspd"=>("最小质量速度倍率","Minimum-mass speed multiplier"," %"),
            "optmulspd"=>("最佳质量速度倍率","Optimal-mass speed multiplier"," %"),
            "maxmulspd"=>("最大质量速度倍率","Maximum-mass speed multiplier"," %"),
            "minmulrot"=>("最小质量转向倍率","Minimum-mass rotation multiplier"," %"),
            "optmulrot"=>("最佳质量转向倍率","Optimal-mass rotation multiplier"," %"),
            "maxmulrot"=>("最大质量转向倍率","Maximum-mass rotation multiplier"," %"),
            "syscap"=>("系统电容容量","SYS capacitor"," MJ"),
            "engcap"=>("引擎电容容量","ENG capacitor"," MJ"),
            "wepcap"=>("武器电容容量","WEP capacitor"," MJ"),
            "syschg"=>("系统电容充能速率","SYS recharge"," MW"),
            "engchg"=>("引擎电容充能速率","ENG recharge"," MW"),
            "wepchg"=>("武器电容充能速率","WEP recharge"," MW"),
            _=>(key,key,"")
        };
        if(module&&key=="mass"){name="质量";english="Mass";}
        var text=!double.IsFinite(value)?"—":key=="_wepcap_unlimited"?(value==1?"是":"否")
            :(key is "_engine_pips" or "_weapon_pips"?value/2:value).ToString(unit==" Cr"?"N0":"0.######",CultureInfo.InvariantCulture)+unit;
        return new(key,name,english,text);
    }
}