From 9aab08af39e4a6ba698e7b3ca5618a729af71880 Mon Sep 17 00:00:00 2001 From: Anna Date: Sat, 1 Aug 2020 20:39:45 -0400 Subject: [PATCH] feat: compile list of map associations at runtime This is very fragile. I would like to find a better way to associate unopened to opened. A clear-cut association of unopened to opened maps would make this no longer fragile. --- Globetrotter/TreasureMaps.cs | 51 ++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/Globetrotter/TreasureMaps.cs b/Globetrotter/TreasureMaps.cs index 100be40..45ff1c1 100644 --- a/Globetrotter/TreasureMaps.cs +++ b/Globetrotter/TreasureMaps.cs @@ -7,27 +7,40 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; namespace Globetrotter { class TreasureMaps { - private static readonly Dictionary MAP_TO_ROW = new Dictionary { - [2_001_087] = 1, - [2_001_088] = 2, - [2_001_089] = 3, - [2_001_090] = 4, - [2_001_091] = 5, - // missing 6, 7, 8 - [2_001_762] = 9, - [2_001_763] = 10, - [2_001_764] = 11, - [2_002_209] = 12, - [2_002_210] = 13, - // missing 14, 15, 16 - [2_002_663] = 17, - [2_002_664] = 18, - }; + private static Dictionary _mapToRow; + private Dictionary MapToRow { + get { + if (_mapToRow != null) { + return _mapToRow; + } + + Item[] unopenedMaps = this.pi.Data.GetExcelSheet() + .Where(item => item.FilterGroup == 18) // this is the filter group for maps + .Where(item => item.RowId != 24_794) // exclude the seemingly special maps + .ToArray(); + EventItem[] openedMaps = this.pi.Data.GetExcelSheet() + .Where(item => item.Unknown13 == 2) // apparently only opened maps have this field + .Where(item => item.Unknown5 == 1) // this removes some weird maps and dupes + .Where(item => item.RowId != 2_002_503 && item.RowId != 2_002_504) // exclude the seemingly special maps + .ToArray(); + + Dictionary mapToRow = new Dictionary(); + for (int i = 0; i < unopenedMaps.Length; i++) { + Item unopened = unopenedMaps[i]; + EventItem opened = openedMaps[i]; + + // associate the eventitem's id with the additional data of the unopened map, which is the row for the treasure spot table + mapToRow[opened.RowId] = unopened.AdditionalData; + } + + _mapToRow = mapToRow; + + return _mapToRow; + } + } private readonly DalamudPluginInterface pi; private readonly Configuration config; @@ -71,7 +84,7 @@ namespace Globetrotter { return; } - if (!MAP_TO_ROW.TryGetValue(packet.EventItemId, out uint rowId)) { + if (!this.MapToRow.TryGetValue(packet.EventItemId, out uint rowId)) { return; }