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<long>("alertInterval"); var length = meta.Value<long>("alertLength");
var current = (now - Epoch) / interval; var systems = meta["allowedSystemIndexes"]!.Values<int>().ToHashSet(); var alerts = world.Array("Alerts");
for (var index = current; index >= current - length / interval; index--)
{
var used = alerts.Select(x => x["MissionInfo"]?.Value<string>("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<int>("systemIndex")) && x.Value.Value<int>("nodeType") is not (3 or 7)
&& !ExcludedMissions.Contains(x.Value.Value<string>("missionType")) && x.Value.Value<string>("missionType") != "MT_RACE"
&& !new[] { "1999NodeI", "1999NodeJ", "SolarMapEntratiNode", "Archwing" }.Any(s => (x.Value.Value<string>("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<string>("tileset") is null || selected.Value.Value<string>("faction") is null);
var missions = ((JObject)GameData.Table("Tilesets")[selected.Value.Value<string>("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<int>("maxRotations");
info.Remove("maxRotations"); alerts.Add(alert);
}
}
}
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<long>("alertInterval"); var length = meta.Value<long>("alertLength");
var current = (now - Epoch) / interval; var systems = meta["allowedSystemIndexes"]!.Values<int>().ToHashSet(); var alerts = world.Array("Alerts");
for (var index = current; index >= current - length / interval; index--)
{
var used = alerts.Select(x => x["MissionInfo"]?.Value<string>("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<int>("systemIndex")) && x.Value.Value<int>("nodeType") is not (3 or 7)
&& !ExcludedMissions.Contains(x.Value.Value<string>("missionType")) && x.Value.Value<string>("missionType") != "MT_RACE"
&& !new[] { "1999NodeI", "1999NodeJ", "SolarMapEntratiNode", "Archwing" }.Any(s => (x.Value.Value<string>("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<string>("tileset") is null || selected.Value.Value<string>("faction") is null);
var missions = ((JObject)GameData.Table("Tilesets")[selected.Value.Value<string>("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<int>("maxRotations");
info.Remove("maxRotations"); alerts.Add(alert);
}
}
}