Skip to content

Commit

Permalink
support hard coded instances for siren
Browse files Browse the repository at this point in the history
  • Loading branch information
dit-zy committed Feb 12, 2024
1 parent 711c87f commit 784033b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
8 changes: 6 additions & 2 deletions ScoutHelper/Data/Siren.json
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,12 @@
"mob order": [
"storsie",
"hulder",
"yilan",
"sugriva",
"yilan 1",
"sugriva 1",
"yilan 2",
"sugriva 2",
"yilan 3",
"sugriva 3",
"minerva",
"aegeiros",
"mousse princess",
Expand Down
5 changes: 3 additions & 2 deletions ScoutHelper/Managers/SirenManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ MobManager mobManager
patchData.MobOrder
.Select(
mobId => mobList.FindMob(mobId)
mobOrderInfo => mobList.FindMob(mobOrderInfo.mobId, mobOrderInfo.instance)
.SelectMany(
mob => patchData
.Maps
Expand Down Expand Up @@ -110,7 +110,7 @@ MobManager mobManager

var mobToPatch = patchesData
.Value
.SelectMany(entry => entry.Value.MobOrder.Select(mobId => (mobId, entry.Key)))
.SelectMany(entry => entry.Value.MobOrder.Select(mob => (mob.mobId, entry.Key)))
.ToDict();

_log.Debug("Siren data loaded.");
Expand All @@ -134,6 +134,7 @@ KeyValuePair<string, JObject> patchData
mobName => mobManager
.GetMobId(mobName.UnInstanced())
.ToResult($"No mobId found for mobName: {mobName.UnInstanced()}")
.Map(mobId => (mobId, mobName.Instance()))
);

var mapResults = patchDataElements["maps"]
Expand Down
4 changes: 2 additions & 2 deletions ScoutHelper/Models/SirenPatchData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
namespace ScoutHelper.Models;

public record SirenPatchData(
IList<uint> MobOrder,
IList<(uint mobId, uint? instance)> MobOrder,
IDictionary<uint, IList<SirenSpawnPoint>> Maps
) {
public static SirenPatchData From(IEnumerable<uint> mobOrder, IDictionary<uint, IList<SirenSpawnPoint>> maps) =>
public static SirenPatchData From(IEnumerable<(uint, uint?)> mobOrder, IDictionary<uint, IList<SirenSpawnPoint>> maps) =>
new(mobOrder.ToImmutableList(), maps);
}
17 changes: 12 additions & 5 deletions ScoutHelper/Utils/XivExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace ScoutHelper.Utils;

public static partial class XivExtensions {
[GeneratedRegex(@" \d{1,2}$")] private static partial Regex UnInstanceRegex();
[GeneratedRegex(@" \d{1,2}$")] private static partial Regex InstanceRegex();

public static string WorldName(this IClientState clientState) =>
clientState.LocalPlayer?.CurrentWorld.GameData?.Name.ToString() ?? "Not Found";
Expand All @@ -28,8 +28,15 @@ public static void TaggedPrintError(this IChatGui chatGui, string message) {
chatGui.PrintError(message, Plugin.Name);
}

public static Maybe<TrainMob> FindMob(this IEnumerable<TrainMob> mobList, uint mobId) =>
Maybe.From(mobList.FirstOrDefault(mob => mob.MobId == mobId));

public static string UnInstanced(this string mobName) => UnInstanceRegex().Replace(mobName, "");
public static Maybe<TrainMob> FindMob(this IEnumerable<TrainMob> mobList, uint mobId, uint? instance = null) =>
Maybe.From(mobList.FirstOrDefault(mob => mob.MobId == mobId && mob.Instance == instance));

public static string UnInstanced(this string mobName) => InstanceRegex().Replace(mobName, "");

public static uint? Instance(this string mobName) => InstanceRegex()
.Match(mobName)
.AsMaybe()
.Where(match => match.Success)
.Map(match => uint.Parse(match.Value))
.GetValueOrDefault();
}

0 comments on commit 784033b

Please sign in to comment.