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.
This commit is contained in:
Anna 2020-08-01 20:39:45 -04:00
parent 7653eb72e4
commit 9aab08af39
1 changed files with 32 additions and 19 deletions

View File

@ -7,27 +7,40 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Globetrotter { namespace Globetrotter {
class TreasureMaps { class TreasureMaps {
private static readonly Dictionary<uint, uint> MAP_TO_ROW = new Dictionary<uint, uint> { private static Dictionary<uint, uint> _mapToRow;
[2_001_087] = 1, private Dictionary<uint, uint> MapToRow {
[2_001_088] = 2, get {
[2_001_089] = 3, if (_mapToRow != null) {
[2_001_090] = 4, return _mapToRow;
[2_001_091] = 5, }
// missing 6, 7, 8
[2_001_762] = 9, Item[] unopenedMaps = this.pi.Data.GetExcelSheet<Item>()
[2_001_763] = 10, .Where(item => item.FilterGroup == 18) // this is the filter group for maps
[2_001_764] = 11, .Where(item => item.RowId != 24_794) // exclude the seemingly special maps
[2_002_209] = 12, .ToArray();
[2_002_210] = 13, EventItem[] openedMaps = this.pi.Data.GetExcelSheet<EventItem>()
// missing 14, 15, 16 .Where(item => item.Unknown13 == 2) // apparently only opened maps have this field
[2_002_663] = 17, .Where(item => item.Unknown5 == 1) // this removes some weird maps and dupes
[2_002_664] = 18, .Where(item => item.RowId != 2_002_503 && item.RowId != 2_002_504) // exclude the seemingly special maps
}; .ToArray();
Dictionary<uint, uint> mapToRow = new Dictionary<uint, uint>();
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 DalamudPluginInterface pi;
private readonly Configuration config; private readonly Configuration config;
@ -71,7 +84,7 @@ namespace Globetrotter {
return; return;
} }
if (!MAP_TO_ROW.TryGetValue(packet.EventItemId, out uint rowId)) { if (!this.MapToRow.TryGetValue(packet.EventItemId, out uint rowId)) {
return; return;
} }