using Newtonsoft.Json.Linq; using XFEWarframe.Core.Data; using static XFEWarframe.Core.Services.WorldData; namespace XFEWarframe.Core.Services; public static partial class WorldEventSettings { private static readonly string[] ExcludedMissions = ["MT_ASSASSINATION", "MT_LANDSCAPE", "MT_RAILJACK", "MT_PVPVE", "MT_PVP", "MT_ARENA"]; private static void GoalAlerts(JObject world, string tag, long now, long build) { var meta = (JObject)Data.Value["alertGeneratorConfig"]![tag]!; var interval = meta.Value("alertInterval"); var length = meta.Value("alertLength"); var current = (now - Epoch) / interval; var systems = meta["allowedSystemIndexes"]!.Values().ToHashSet(); var alerts = world.Array("Alerts"); for (var index = current; index >= current - length / interval; index--) { var used = alerts.Select(x => x["MissionInfo"]?.Value("location")).ToHashSet(); var hash = VendorApi.Hash(tag); var rng = new SeededRng(unchecked((int)index ^ (int)hash)); var nodes = GameData.Table("Regions").Properties().Where(x => systems.Contains(x.Value.Value("systemIndex")) && x.Value.Value("nodeType") is not (3 or 7) && !ExcludedMissions.Contains(x.Value.Value("missionType")) && x.Value.Value("missionType") != "MT_RACE" && !new[] { "1999NodeI", "1999NodeJ", "SolarMapEntratiNode", "Archwing" }.Any(s => (x.Value.Value("name") ?? "").Contains(s, StringComparison.Ordinal)) && !used.Contains(x.Name)).ToArray(); JProperty? selected = null; var attempts = 0; do { if (++attempts > 10000 || nodes.Length == 0) throw new InvalidDataException("No nodes for event alert " + tag); selected = rng.Element(nodes); } while (selected.Value.Value("tileset") is null || selected.Value.Value("faction") is null); var missions = ((JObject)GameData.Table("Tilesets")[selected.Value.Value("tileset")!]!["missions"]!).Properties().ToArray(); JProperty mission; attempts = 0; do { if (++attempts > 10000) throw new InvalidDataException("No missions for event alert " + tag); mission = rng.Element(missions); } while (ExcludedMissions.Contains(mission.Name)); var start = Epoch + index * interval; var alert = Window(start, start + length, Id(start, hash.ToString("x").PadRight(8, '0') + unchecked((uint)index).ToString("x8")), build); alert.Merge(meta["baseAlert"]!); var info = new JObject { ["location"] = selected.Name, ["missionType"] = mission.Name, ["faction"] = selected.Value["faction"]!.DeepClone(), ["difficulty"] = 1, ["seed"] = index, ["levelOverride"] = mission.Value["procLevel"]?.DeepClone() }; info.Merge(meta["baseMissionInfo"]!); alert["MissionInfo"] = info; foreach (var (field, output) in new[] { ("enemySpecs", "enemySpec"), ("extraEnemySpecs", "extraEnemySpec") }) if (mission.Value[field] is JArray { Count: > 0 } choices) info[output] = rng.Element(choices.ToArray()).DeepClone(); foreach (var (field, output) in new[] { ("vipAgent", "vipAgent"), ("advancedSpawners", "customAdvancedSpawners") }) if (mission.Value[field] is JToken value) info[output] = value.DeepClone(); if (mission.Name is "MT_INTEL" or "MT_TERRITORY" or "MT_EXCAVATE") info["maxWaveNum"] = 2; else if (mission.Name is "MT_SURVIVAL" or "MT_DEFENSE") info["maxWaveNum"] = (mission.Name == "MT_SURVIVAL" || build < GameVersion.Of("38.5.0") ? 5 : 3) * info.Value("maxRotations"); info.Remove("maxRotations"); alerts.Add(alert); } } }