using Newtonsoft.Json.Linq; using XFEWarframe.Core.Data; namespace XFEWarframe.Core.Services; public sealed partial class AccountEditor { // Every choice is a dependency of an owned frame or one of its saved ability banks. // Reading this view does not grant equipment. Preparation is a versioned, authorized write. private IEnumerable RelatedWeaponTypes(JObject suit) { var types = new HashSet(StringComparer.Ordinal); void Add(string? frame, bool whipOnly = false) { foreach (var type in (GameData.Find("Warframes", frame)?["exalted"] as JArray ?? []).Values().OfType()) if (GameData.Find("Weapons", type)?.Value("productCategory") == "SpecialItems" && (!whipOnly || type.EndsWith("/KhoraWhipclawWeapon", StringComparison.Ordinal))) types.Add(type); } Add(suit.Value("ItemType")); foreach (var config in (suit["Configs"] as JArray ?? []).OfType()) { var abilities = ExperimentalAbilities.ReadBanks(config).Properties() .SelectMany(x => ((JObject)x.Value).Properties().Select(y => y.Value.ToString())) .Append(config["AbilityOverride"]?.Value("Ability") ?? ""); foreach (var ability in abilities) { var name = ability.Split('/').Last(); if (WorldData.Get("abilityWeaponDonors").Value(name) is string donor) Add(donor, name == "KhoraCrackAbility"); } } return types.Order(StringComparer.Ordinal); } private JArray RelatedWeapons(JObject suit, JObject inv) => new(RelatedWeaponTypes(suit).Select(type => { var owned = inv.Array("SpecialItems").OfType().FirstOrDefault(x => x.Value("ItemType") == type); return new JObject { ["type"] = type, ["name"] = Name(owned ?? new JObject { ["ItemType"] = type }), ["category"] = "SpecialItems", ["key"] = owned is null ? "" : Key(owned), ["owned"] = owned is not null, ["canEdit"] = true, ["editActions"] = owned is null ? new JArray("exalted.prepare") : new JArray(Actions("SpecialItems", owned, inv).Select(x => x.Value("key"))), ["description"] = "按武器类型共享库存配装;使用战甲当前的 A–F 配置。保存后需重新登录游戏加载。" }; })); private void PrepareExalted(JObject account, JObject suit, string type) { if (!RelatedWeaponTypes(suit).Contains(type, StringComparer.Ordinal)) throw new ApiException(400, "此武器不是该战甲或已保存移植技能的显赫武器。"); var inv = account.Obj("Inventory"); new ItemAcquisition(catalog, clock, account).Add(inv, type, premium: true, withSlots: false); var weapon = inv.Array("SpecialItems").OfType().Single(x => x.Value("ItemType") == type); // A transplanted weapon may follow a host's purchased D–F configuration. weapon["ModSlotPurchases"] = Math.Max(weapon.Value("ModSlotPurchases"), Math.Clamp(suit.Value("ModSlotPurchases"), 0, 3)); } private static string? ExaltedModFamily(string type) { var meta = GameData.Find("Weapons", type); if (meta?.Value("productCategory") != "SpecialItems") return null; if (meta.ContainsKey("heavyAttackDamage")) return "MELEE"; if (type.Contains("/BlastWeapon", StringComparison.Ordinal)) return "SHOTGUN"; if (type.Contains("/ChoirEruptWeapon", StringComparison.Ordinal) || type.Contains("/SlingerPistols", StringComparison.Ordinal) || type.Contains("/FlightPistols", StringComparison.Ordinal)) return "SECONDARY"; if (type.Contains("/ExaltedBow", StringComparison.Ordinal) || type.Contains("/ExaltedBook", StringComparison.Ordinal) || type.Contains("/ExaltedGuitar", StringComparison.Ordinal) || type.Contains("/ExaltedSniper", StringComparison.Ordinal)) return "PRIMARY"; return null; } private static bool ExaltedModCompatible(string type, JObject mod) { var meta = ModMetadata(mod.RequiredString("ItemType")); if (meta is null || meta.Value("type") is "STANCE" or "AURA" || meta.Value("isUtility")) return false; var compatibility = meta.Value("compat"); var family = ExaltedModFamily(type); var general = family switch { "SECONDARY" => "/Lotus/Weapons/Tenno/Pistol/LotusPistol", "PRIMARY" => "/Lotus/Weapons/Tenno/Rifle/LotusRifle", "SHOTGUN" => "/Lotus/Weapons/Tenno/Shotgun/LotusShotgun", "MELEE" => "/Lotus/Weapons/Tenno/Melee/PlayerMeleeWeapon", _ => null }; if (general is not null && compatibility == general) return true; // Exact weapon augments are allowed; another weapon's or frame's MOD is not. for (var parent = type; !string.IsNullOrEmpty(parent);) { if (parent == compatibility) return true; var next = GameData.Find("Weapons", parent)?.Value("parentName"); if (next == parent) break; parent = next; } return false; } private void AddExaltedModActions(JArray actions, JObject weapon, JObject inv) { var type = weapon.RequiredString("ItemType"); if (ExaltedModFamily(type) is null) return; var options = new List<(string, string)> { ("", "空槽") }; foreach (var mod in inv.Array("Upgrades").OfType().Where(x => ExaltedModCompatible(type, x))) { var id = Wire.Id(mod["ItemId"]); if (id.Length != 24) continue; int rank; try { rank = JObject.Parse(mod.Value("UpgradeFingerprint") ?? "{}").Value("lvl"); } catch { rank = 0; } options.Add((id, Name(mod) + " · 等级 " + rank + " · " + id[^6..])); } foreach (var mod in inv.Array("RawUpgrades").OfType().Where(x => x.Value("ItemCount") > 0 && ExaltedModCompatible(type, x))) options.Add(("raw:" + mod.RequiredString("ItemType"), Name(mod) + " · 未升级 · 持有 " + mod.Value("ItemCount"))); for (var index = 0; index < 3 + Math.Clamp(weapon.Value("ModSlotPurchases"), 0, 3); index++) { var config = (weapon["Configs"] as JArray)?.ElementAtOrDefault(index) as JObject; var fields = Enumerable.Range(0, 8).Select(slot => Choice("mod" + slot, "MOD 槽 " + (slot + 1), config?["Upgrades"]?.ElementAtOrDefault(slot)?.ToString() ?? "", options.ToArray())).ToArray(); var action = Action("exalted.mods." + index, "配置 " + (char)('A' + index) + " · MOD 配装", [Text("name", "配装名称", config?.Value("Name") ?? ""), .. fields]); action["description"] = "旧版客户端兼容接口,使用与拖动配装页相同的库存、槽位和容量校验。"; actions.Add(action); } } private void SaveExaltedMods(JObject inv, JObject weapon, int index, JObject values) { SaveModding("SpecialItems", weapon, inv, index, values); } }