using Newtonsoft.Json.Linq; using XFEWarframe.Core.Data; namespace XFEWarframe.Core.Services; public static class MissionDrops { public static void Relics(JObject inv, long build, JArray rewards, SeededRng rng) { var all = inv.Value("missionsCanGiveAllRelics"); var relics = GameData.Table("Relics"); var baro = ((JArray)WorldData.Get("baro")["rest"]!).Select(x => GameData.ItemType(x.Value("ItemType") ?? "")).ToHashSet(StringComparer.Ordinal); static long Date(JToken? value) => value?.Value() is > 0 and var seconds ? GameVersion.Parse(DateTimeOffset.FromUnixTimeSeconds(seconds).ToString("yyyy.MM.dd.HH.mm", System.Globalization.CultureInfo.InvariantCulture)) : 0; foreach (var drop in rewards.OfType().ToArray()) { if (relics[GameData.ItemType(drop.RequiredString("StoreItem"))] is not JObject source) continue; var introduced = Date(source["introducedAt"]); var vaulted = Date(source["vaultedAt"]); if (!all && introduced != 0 && !(introduced > build && (vaulted == 0 || vaulted > build))) continue; var pool = relics.Properties().Where(p => { var relic = p.Value; if (relic.Value("era") != source.Value("era") || relic.Value("quality") != source.Value("quality")) return false; var release = Date(relic["introducedAt"]); if (release == 0 || release > build) return false; var retirement = Date(relic["vaultedAt"]); return all || retirement == 0 || retirement > build || baro.Contains(p.Name) || p.Name.Contains("Railjack", StringComparison.Ordinal) || p.Name.Contains("Baro", StringComparison.Ordinal); }).Select(p => p.Name).ToArray(); if (pool.Length == 0) drop.Remove(); else drop["StoreItem"] = GameData.StoreType(rng.Element(pool)); } } public static void Stripped(JObject inv, JObject body, JArray rewards, long now) { if (!body.Value("EndOfMatchUpload")) return; foreach (var item in (body["StrippedItems"] as JArray ?? []).OfType()) { var name = item.RequiredString("DropTable"); name = WorldData.Get("droptableAliases").Value(name) ?? name; if (GameData.Table("Enemies")["droptables"]?[name] is not JArray tables) throw new ApiException(400, "Unknown stripped drop table"); foreach (var (field, type) in new[] { ("DROP_MOD", "mod"), ("DROP_BLUEPRINT", "blueprint"), ("DROP_MISC_ITEM", "resource") }) { var identifiers = item[field] as JArray; if (name == "/Lotus/Types/DropTables/Tau/TwelveMinuteWar/TMWPrimeMinibossSteelPathDropTable" && item["DROP_MOD"] is null) { if (field == "DROP_MISC_ITEM") continue; if (field == "DROP_MOD") identifiers = item["DROP_MISC_ITEM"] as JArray; } if (identifiers is null || identifiers.Count == 0) continue; if (identifiers.Count > 1000) throw new ApiException(400, "Too many stripped drops"); var table = tables.FirstOrDefault(x => x.Value("type") == type)?["items"] as JArray ?? throw new ApiException(400, "Drop table does not support the reported reward kind"); for (var i = 0; i < identifiers.Count; i++) { var reward = SeededRng.RewardAt(table, Random.Shared.NextDouble()) ?? throw new ApiException(400, "Empty drop table"); rewards.Add(new JObject { ["StoreItem"] = GameData.StoreType(reward.Value("type")!), ["ItemCount"] = 1, ["FromEnemyCache"] = true }); } if (field == "DROP_MOD") { var bonusKey = name switch { "/Lotus/Types/DropTables/EidolonDropTables/TeralystCapturedDropTable" => "teralystCapturePlatinumBonus", "/Lotus/Types/DropTables/EidolonDropTables/TeralystBigCapturedDropTable" => "gantulystCapturePlatinumBonus", "/Lotus/Types/DropTables/EidolonDropTables/TeralystRainCapturedDropTable" => "hydrolystCapturePlatinumBonus", _ => null }; if (bonusKey is not null && inv.Value(bonusKey) > 0) inv["pendingPremiumCredits"] = checked(inv.Value("pendingPremiumCredits") + inv.Value(bonusKey) * identifiers.Count); } } if (name == "/Lotus/Types/DropTables/ContainerDropTables/VoidVaultMissionRewardsDropTable") { WeeklyApi.ResetVault(inv, now); if (inv.Value("EntratiVaultCountLastPeriod") >= 5) throw new ApiException(409, "No weekly search pulses remain"); inv["EntratiVaultCountLastPeriod"] = inv.Value("EntratiVaultCountLastPeriod") + 1; } } } }