using System.Globalization; using System.Text.RegularExpressions; using Newtonsoft.Json.Linq; using XFEWarframe.Core.Data; namespace XFEWarframe.Core.Services; public static partial class RivenCalculator { public static string DisplayName(ItemCatalog catalog, string type, JObject fingerprint) => DisplayName(catalog, Parse(type, fingerprint, 1)); private static string DisplayName(ItemCatalog catalog, JObject parsed) { if (parsed.Value("veiled")) return parsed.Value("name")!; var weapon = parsed["fingerprint"]!.Value("compat") ?? ""; var name = weapon.Length == 0 ? "" : catalog.Name(GameData.Find("Weapons", weapon) ?? new JObject(), weapon); return (name + " " + parsed.Value("name")).Trim(); } // Desktop presentation is kept separate from the saved fingerprint and reference math. public static JObject Calculate(JObject request, ItemCatalog catalog) { var parsed = Calculate(request); parsed["displayName"] = DisplayName(catalog, parsed); if (parsed.Value("veiled")) return parsed; var type = request.RequiredString("type"); var fp = (JObject)parsed["fingerprint"]!; var buffs = fp["buffs"]!.Count(); var curses = fp["curses"]?.Count() ?? 0; foreach (var stat in parsed["stats"]!.OfType()) { var tag = stat.RequiredString("tag"); stat.Merge(StatPresentation(catalog, type, tag, stat.Value("displayValue"))); if (!request.Value("includeOptions")) continue; // Alternatives use this row's quality and the same rank, disposition and stat counts. stat["options"] = new JArray(Entries(type).OfType().Select(entry => { var key = entry.RequiredString("tag"); var actual = Factor(type, key, request.Value("disposition") ?? 1, fp.Value("lvl"), buffs, curses, stat.Value("negative")) * stat.Value("roll") / 10000; return StatPresentation(catalog, type, key, key == tag ? stat.Value("displayValue") : Display(key, actual)); })); } return parsed; } private static JObject StatPresentation(ItemCatalog catalog, string type, string tag, double? value = null) { var meta = RivenApi.Metadata(Prefix + Family(type)); var loc = (meta["upgradeEntries"] as JArray ?? []).FirstOrDefault(x => x.Value("tag") == tag)?["upgradeValues"]?.FirstOrDefault()?.Value("locTag"); var template = loc is null ? tag : catalog.Localize(loc, tag); var color = Regex.Match(template, @"<(DT_[A-Z_]+_COLOR)>").Groups[1].Value; template = Regex.Replace(template, "<[^>]*>|\\|(?:OPEN_COLOR|CLOSE_COLOR)\\|", ""); var label = Regex.Replace(template, @"\|[^|]+\|\s*%?", "").Trim(); var text = label; if (value is double number) { var formatted = Faction(tag) ? "×" + (1 + number).ToString("0.##", CultureInfo.InvariantCulture) : number.ToString("+0.##;-0.##;0", CultureInfo.InvariantCulture); text = template.Contains('|') ? Regex.Replace(template, @"\|[^|]+\|", _ => formatted) : formatted + " " + template; } return new JObject { ["key"] = tag, ["label"] = label, ["text"] = text.Trim(), ["color"] = color, ["displayValue"] = value }; } }