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

XFEWarframe

【WinUI】基于Warframe游戏本体的公开服务器以及安装器

公开
关注 0 Fork 0 Star 0
UTF-8
using Newtonsoft.Json.Linq;

namespace XFEWarframe.Core.Data;

public static class LegacyMods
{
    private static readonly Lazy<JObject> Data = new(() => (JObject)Assets.Json("editor/legacy-mods.json"));
    public static JObject All => Data.Value;
    public static JObject? Find(string type) => All[type] as JObject;
    public static (double Min, double Max, bool Percent) Range(JObject meta, string fit, string attribute, string rarity)
    {
        var attenuation = meta["fits"]!.FirstOrDefault(x => x.Value<string>("type") == fit)?.Value<double?>("statAtten") ?? 1;
        var stat = meta["upgrades"]!.FirstOrDefault(x => x.Value<string>("type") == attribute) ?? throw new ApiException(400, "未知旧版 MOD 属性。");
        // U5 clients use the uncommon numeric range for rare rolls too.
        var range = stat["valueRarity"]?[rarity == "RARE" ? "UNCOMMON" : rarity] as JArray ?? throw new ApiException(400, "未知旧版 MOD 稀有度。");
        var multiply = stat.Value<string>("operation") == "MULTIPLY"; var percent = multiply || stat.Value<bool>("displayAsPercent");
        double Convert(double x) => (percent ? x * 100 - (multiply ? 100 : 0) : x) * attenuation;
        return (Convert(range[0]!.Value<double>()), Convert(range[1]!.Value<double>()), percent);
    }
}