using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace XFEWarframe.Core.Services; /// A separate owned MOD; the native card is only a game resource carrier. public static class InfestationKing { public const string Type = "/Lotus/Upgrades/XFEWarframe/InfestationKing"; public const string Carrier = "/Lotus/Powersuits/Infestation/InfestPassiveAugmentCard"; public const string EquippedField = "XFEInfestationKing"; public static bool Compatible(string? suit) => suit is "/Lotus/Powersuits/Infestation/Infestation" or "/Lotus/Powersuits/Infestation/InfestationPrime"; public static JObject Add(JObject inventory, int count) { if (count is < 1 or > 100) throw new ApiException(400, "每次最多添加 100 张感染之王。"); var cards = new JArray(); for (var i = 0; i < count; i++) { var card = new JObject { ["ItemId"] = Wire.Oid(Wire.NewId()), ["ItemType"] = Type, ["UpgradeFingerprint"] = "{\"lvl\":0}" }; inventory.Array("Upgrades").Add(card); cards.Add(card.DeepClone()); } return new JObject { ["Upgrades"] = cards }; } public static void Project(JObject inventory) { var ids = inventory.Array("Upgrades").OfType().Where(x => x.Value("ItemType") == Type) .Select(x => Wire.Id(x["ItemId"])).ToHashSet(StringComparer.Ordinal); // Ignore imported/client-supplied flags: only an owned, installed card enables it. foreach (var category in Inventory.EquipmentKeys) foreach (var item in inventory.Array(category).OfType()) foreach (var config in (item["Configs"] as JArray ?? []).OfType()) { config.Remove(EquippedField); if (category == "Suits" && Compatible(item.Value("ItemType")) && (config["Upgrades"] as JArray ?? []).Any(x => ids.Contains(Wire.Id(x)))) config[EquippedField] = true; } foreach (var card in inventory.Array("Upgrades").OfType().Where(x => x.Value("ItemType") == Type)) { card["ItemType"] = Carrier; var fingerprint = JObject.Parse(card.Value("UpgradeFingerprint") ?? "{}"); fingerprint["xfe"] = "InfestationKing"; card["UpgradeFingerprint"] = fingerprint.ToString(Formatting.None); } } // Requests use the resource carrier but identity is always resolved by owned ID. public static void ResolveRequest(JObject inventory, JObject request) { var ids = inventory.Array("Upgrades").OfType().Where(x => x.Value("ItemType") == Type) .Select(x => Wire.Id(x["ItemId"])).ToHashSet(StringComparer.Ordinal); foreach (var item in request.DescendantsAndSelf().OfType()) if (item.Value("ItemType") == Carrier && ids.Contains(Wire.Id(item["ItemId"]))) item["ItemType"] = Type; } }