using Newtonsoft.Json.Linq; using XFEWarframe.Core.Data; using static XFEWarframe.Core.Services.WorldData; namespace XFEWarframe.Core.Services; public static class WorldBounties { public const double CycleSeconds = 24 / 0.0026670000515878; public const double BountyEpoch = 1391990400 + 5 * CycleSeconds / 24; public static int CycleAt(long now) => (int)((now / 1000d - BountyEpoch) / CycleSeconds); public static int CycleFromId(string id) => id.Length == 24 && uint.TryParse(id[..8], System.Globalization.NumberStyles.HexNumber, null, out var seconds) ? (int)Math.Floor((seconds - BountyEpoch) / CycleSeconds + .5) : throw new ApiException(400, "Invalid bounty mission identifier"); public static JArray Xp(SeededRng rng, int stages, int min, int max) { var step = min < 1000 ? 1 : 10; var total = rng.Int(min / step, max / step); if (stages < 4) return new JArray(Enumerable.Repeat((int)Math.Ceiling(total / (double)stages) * step, stages)); var perStage = (int)Math.Ceiling(Math.Floor(total * .667 + .5) / (stages - 1)) * step; return new JArray(Enumerable.Repeat(perStage, stages - 1).Append((int)Math.Ceiling(total * .332) * step)); } private static JObject Job(string? type, string rewards, int mastery, int min, int max, JArray xp) => new() { ["jobType"] = type, ["rewards"] = rewards, ["masteryReq"] = mastery, ["minEnemyLevel"] = min, ["maxEnemyLevel"] = max, ["xpAmounts"] = xp }; public static void Generate(JArray destination, int cycle, long build) { var table = (char)('A' + cycle % 3); var vault = (char)('A' + (cycle + 1) % 3); var deimos = (char)('A' + cycle % 2); var seed = new SeededRng(cycle).Int(0, 100_000); var start = (long)((BountyEpoch + cycle * CycleSeconds) * 1000); var end = (long)(start + CycleSeconds * 1000); void Append(string tag, string suffix, int missionSeed, JArray? jobs = null) { var entry = Window(start, end, Id(start, suffix), build); entry["Tag"] = tag; entry["Seed"] = missionSeed; entry["Nodes"] = new JArray(); if (jobs is not null) entry["Jobs"] = jobs; destination.Add(entry); } if (build >= GameVersion.Of("29.0.0")) Append("EntratiLabSyndicate", "0000000000000004", cycle); if (build >= GameVersion.Of("31.5.0")) Append("ZarimanSyndicate", "0000000000000029", cycle); if (build >= GameVersion.Of("38.0.0")) Append("HexSyndicate", "0000000000000006", cycle); foreach (var venus in new[] { false, true }) { if (build < GameVersion.Of(venus ? "24.0.0" : "22.0.0")) continue; var rng = new SeededRng(seed); var pool = Strings(Get(venus ? "venusJobs" : "eidolonJobs")).ToList(); var jobs = new JArray(); var prefix = "/Lotus/Types/Game/MissionDecks/" + (venus ? "VenusJobMissionRewards/Venus" : "EidolonJobMissionRewards/"); for (var i = 0; i < 5; i++) { var job = Job(rng.Pop(pool), prefix + $"Tier{(char)('A' + i)}Table{table}Rewards", venus && i == 4 ? 5 : i, new[] { 5, 10, 20, 30, 40 }[i], new[] { 15, 30, 40, 50, 60 }[i], Xp(rng, new[] { 3, 3, 4, 5, 5 }[i], 1000 + i * 750, 1500 + i * 750)); if (!venus && build < GameVersion.Of("22.13.4")) job.Remove("masteryReq"); jobs.Add(job); } if (build >= GameVersion.Of("28.3.0")) jobs.Add(Job(rng.Pop(pool), prefix + $"TierETable{table}Rewards", 10, 100, 100, new JArray(840, 840, 840, 840, 1660))); if (build >= GameVersion.Of("31.0.0")) jobs.Add(Job(rng.Element(Strings(Get(venus ? "venusNarmerJobs" : "eidolonNarmerJobs"))), $"/Lotus/Types/Game/MissionDecks/EidolonJobMissionRewards/NarmerTable{(venus ? 'B' : table)}Rewards", 0, 50, 70, Xp(rng, 5, 4500, 5000))); Append(venus ? "SolarisSyndicate" : "CetusSyndicate", venus ? "0000000000000025" : "0000000000000008", seed, jobs); } if (build >= GameVersion.Of("29.0.0")) { var rng = new SeededRng(seed); var pool = Strings(Get("microplanetJobs")).ToList(); var prefix = "/Lotus/Types/Game/MissionDecks/DeimosMissionRewards/"; var jobs = new JArray(Job(rng.Pop(pool), prefix + $"TierATable{table}Rewards", 0, 5, 15, Xp(rng, 3, 12, 18)), Job(rng.Pop(pool), prefix + $"TierCTable{table}Rewards", 1, 15, 25, Xp(rng, 3, 24, 36))); var endless = Job(rng.Element(Strings(Get("microplanetEndlessJobs"))), prefix + $"TierBTable{table}Rewards", 5, 25, 30, new JArray(14, 14, 14)); endless["endless"] = true; jobs.Add(endless); jobs.Add(Job(rng.Pop(pool), prefix + $"TierDTable{deimos}Rewards", 2, 30, 40, Xp(rng, 4, 72, 88))); jobs.Add(Job(rng.Pop(pool), prefix + "TierETableARewards", 3, 40, 60, Xp(rng, 5, 115, 135))); jobs.Add(Job(rng.Pop(pool), prefix + "TierETableARewards", 10, 100, 100, new JArray(25, 25, 25, 25, 50))); int[][] xps = [[2, 2, 2, 4], [4, 4, 4, 5], [5, 5, 5, 7]]; for (var i = 0; i < 3; i++) { var job = Job(null, prefix + $"VaultBountyTier{(char)('A' + i)}Table{vault}Rewards", 5, 30 + 10 * i, 40 + 10 * i, new JArray(xps[i])); job.Remove("jobType"); job["locationTag"] = new[] { "ChamberB", "ChamberA", "ChamberC" }[i]; job["isVault"] = true; jobs.Add(job); } Append("EntratiSyndicate", "0000000000000002", seed, jobs); } } public static (JObject Job, string Syndicate) Resolve(JObject info, long build, JObject? world = null) { var id = info.RequiredString("jobId"); var parts = id.Split('_'); var type = parts[0]; var missionId = parts.FirstOrDefault(x => x.Length == 24); var entries = new JArray(); var isGoal = type.StartsWith("/Lotus/Types/Gameplay/Eidolon/Jobs/Events/", StringComparison.Ordinal); if (isGoal) { var goal = (world?["Goals"] as JArray ?? []).OfType().FirstOrDefault(x => Wire.Id(x["_id"]) == missionId) ?? throw new ApiException(400, "Activity bounty is not active"); var found = (goal["Jobs"] as JArray ?? []).Concat(goal["PreviousJobs"] as JArray ?? []).OfType().FirstOrDefault(x => x.Value("jobType") == type) ?? throw new ApiException(400, "Unknown activity bounty"); return ((JObject)found.DeepClone(), goal.RequiredString("JobAffiliationTag")); } if (missionId is not null) Generate(entries, CycleFromId(missionId), build); var entry = entries.FirstOrDefault(x => Wire.Id(x["_id"]) == missionId); var tag = entry?.Value("Tag") ?? parts.FirstOrDefault(x => x.EndsWith("Syndicate", StringComparison.Ordinal)); if (type.EndsWith("Hunts/TeralystHunt", StringComparison.Ordinal) || type.EndsWith("Hunts/AllTeralystsHunt", StringComparison.Ordinal) && info.Value("JobStage") == 2) return (Job(type, "", 0, 20, 40, new JArray(type.EndsWith("AllTeralystsHunt", StringComparison.Ordinal) ? 5000 : 1000)), "CetusSyndicate"); if (type.EndsWith("Jobs/NewbieJob", StringComparison.Ordinal)) return (Job(type, "/Lotus/Types/Game/MissionDecks/EidolonJobMissionRewards/TierATableARewards", 0, 3, 5, new JArray(200)), "CetusSyndicate"); if (type.Contains("/Venus/Jobs/Heists/", StringComparison.Ordinal)) tag = "SolarisSyndicate"; if (tag == "SolarisSyndicate") { if (type.StartsWith("/Lotus/Types/Gameplay/NokkoColony/Jobs/NokkoJob", StringComparison.Ordinal)) return (Job(type, type.Replace("SteelPath", "Steel", StringComparison.Ordinal).Replace("/Lotus/Types/Gameplay/NokkoColony/Jobs/NokkoJob", "/Lotus/Types/Game/MissionDecks/NokkoColonyRewards/NokkoColonyRewards", StringComparison.Ordinal), 0, 30, 40, new JArray(0, 0, 0, 0, 0)), tag); if (type.EndsWith("Heists/ExploiterHunt", StringComparison.Ordinal)) return (Job(type, "", 0, 40, 60, new JArray(1000)), tag); var stages = new[] { "One", "Two", "Three", "Four" }; var index = Array.FindIndex(stages, x => type.EndsWith("Heists/HeistProfitTakerBounty" + x, StringComparison.Ordinal)); if (index >= 0) return (Job(type, index == 0 && info.Value("JobStage") != 2 ? "" : $"/Lotus/Types/Game/MissionDecks/HeistJobMissionRewards/HeistTier{(char)('A' + index)}TableARewards", 0, 40, 60, new JArray(index == 0 && info.Value("JobStage") != 2 ? 0 : 1000)), tag); } var jobs = entry?["Jobs"] as JArray; var job = info["JobTier"] is not null && info.Value("JobTier") >= 0 && info.Value("JobTier") < (jobs?.Count ?? 0) ? jobs![info.Value("JobTier")] as JObject : jobs?.OfType().FirstOrDefault(x => x.Value("jobType") == type); if (tag == "EntratiSyndicate" && jobs is not null) { if (type.Contains("DeimosEndless", StringComparison.Ordinal)) { job = (JObject?)jobs.FirstOrDefault(x => x.Value("endless"))?.DeepClone(); if (job is not null) job["rewards"] = $"/Lotus/Types/Game/MissionDecks/DeimosMissionRewards/TierBTable{(char)('A' + new[] { 0, 0, 1, 2 }[(info.Value("JobStage") / 2) % 4])}Rewards"; } else if (type.EndsWith("VaultBounty", StringComparison.Ordinal)) { job = (JObject?)jobs.FirstOrDefault(x => x.Value("locationTag") == parts.LastOrDefault(p => p.StartsWith("Chamber", StringComparison.Ordinal)))?.DeepClone(); if (job is not null) { job["jobType"] = type; job["rewards"] = job.Value("rewards")!.Replace("/Lotus/Types/Game/MissionDecks/", "/Supplementals/", StringComparison.Ordinal); job["xpAmounts"] = new JArray(((JArray)job["xpAmounts"]!).Sum(x => x.Value())); } } } if (job is not null) return ((JObject)job.DeepClone(), tag!); if (type.EndsWith("Hunts/AllTeralystsHunt", StringComparison.Ordinal)) return (Job(type, "", 0, 20, 40, new JArray(0)), "CetusSyndicate"); throw new ApiException(400, "Unknown bounty reward definition"); } }