-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRumorMap.lua
More file actions
386 lines (343 loc) · 13.7 KB
/
RumorMap.lua
File metadata and controls
386 lines (343 loc) · 13.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
local addonName = ...;
--- @class RumorMapNS
local ns = select(2, ...);
local RumorMap = LibStub('AceAddon-3.0'):NewAddon(addonName);
local HandyNotes = LibStub('AceAddon-3.0'):GetAddon('HandyNotes', true);
if not HandyNotes then return; end
local HBD = LibStub('HereBeDragons-2.0');
RumorMap.debug = false;
--@debug@
RumorMap.debug = false;
_G.RumorMap = RumorMap;
--@end-debug@
local function debugPrint(...)
if not RumorMap.debug then return; end
print(...);
end
local mapID = 2255; -- Azj-Kahet
local cityMapID = 2213; -- City of Threads
local alternateMapIDs = {
[2255] = true, -- Azj-Kahet
[2256] = true, -- Azj-Kahet Lower
[2213] = true, -- City of Threads
[2216] = true, -- City of Threads Lower
}
local atlas = 'notoriety-32x32';
local atlasInfo = C_Texture.GetAtlasInfo(atlas);
local iconDefault = {
icon = atlasInfo.file,
tCoordLeft = atlasInfo.leftTexCoord,
tCoordRight = atlasInfo.rightTexCoord,
tCoordTop = atlasInfo.topTexCoord,
tCoordBottom = atlasInfo.bottomTexCoord,
};
RumorMap.Pacts = {};
RumorMap.Pacts.QuestIDs = {
General = 80671,
Vizier = 80672,
Weaver = 80670,
};
RumorMap.Pacts.TreasureNames = {
['Forgotten Memorial'] = 'General',
['Kaheti Excavation'] = 'Vizier',
['Weave-Rat Cache'] = 'Weaver',
};
RumorMap.Pacts.TreasureSpellIDs = {
General = 463375,
Vizier = 463387,
Weaver = 463346,
};
local locations = ns.locations;
local questObjectives = ns.questObjectives;
local modifierTrees = ns.modifierTrees;
local modifierEnum = ns.modifierEnum;
--- @class RumorMap_Node
--- @field x number
--- @field y number
--- @field name string
--- @field description string|nil
--- @field areaPoiID number
--- @field questID number|nil
--- @field prevQuestID number|nil
--- @field modifierTreeID number
--- @type table<number, RumorMap_Node[]> # [uiMapID] = list of locations
RumorMap.nodes = {
[2255] = {},
[2213] = {},
};
RumorMap.nodes[2256] = RumorMap.nodes[2255];
RumorMap.nodes[2216] = RumorMap.nodes[2213];
function RumorMap:OnInitialize()
for _, pin in ipairs(locations) do
local x, y = HBD:GetZoneCoordinatesFromWorld(pin.pos1, pin.pos0, mapID);
if x and y then
local coord = HandyNotes:getCoord(x, y);
--- @type RumorMap_Node
self.nodes[mapID][coord] = {
name = pin.name,
description = pin.description,
areaPoiID = pin.areaPoiID,
questID = pin.questID,
prevQuestID = pin.prevQuestID,
modifierTreeID = pin.modifierTreeID,
x = x,
y = y,
};
end
local x, y = HBD:GetZoneCoordinatesFromWorld(pin.pos1, pin.pos0, cityMapID);
if x and y then
local coord = HandyNotes:getCoord(x, y);
--- @type RumorMap_Node
self.nodes[cityMapID][coord] = {
name = pin.name,
description = pin.description,
areaPoiID = pin.areaPoiID,
questID = pin.questID,
prevQuestID = pin.prevQuestID,
modifierTreeID = pin.modifierTreeID,
x = x,
y = y,
};
end
end
local defaults = {
profile = {
iconScale = 1.0,
iconAlpha = 1.0,
showTreasures = true,
showRumors = true,
},
};
self.db = LibStub('AceDB-3.0'):New('HandyNotes_RumorMapDB', defaults, true).profile;
if (C_AddOns.IsAddOnLoaded('TomTom')) then
self.isTomTomLoaded = true;
end
local increment = CreateCounter(1);
local options = {
type = 'group',
name = 'Rumor Map',
desc = 'Locations of Rumors and Pact treasures in Azj-Kahet',
get = function(info) return self.db[info[#info]]; end,
set = function(info, v) self.db[info[#info]] = v; self:Refresh(); end,
args = {
desc = {
name = 'These settings control the look and feel of the icon.',
type = 'description',
order = increment(),
},
iconScale = {
type = 'range',
name = 'Icon Scale',
desc = 'The scale of the icons',
min = 0.25, max = 3, step = 0.01,
order = increment(),
},
iconAlpha = {
type = 'range',
name = 'Icon Alpha',
desc = 'The alpha transparency of the icons',
min = 0, max = 1, step = 0.01,
order = increment(),
},
showTreasures = {
type = 'toggle',
name = 'Show Pact treasures',
desc = 'Show Pact treasures (requires Crony reputation with your current pact)',
order = increment(),
},
showRumors = {
type = 'toggle',
name = 'Show Rumors',
desc = 'Show Rumors',
order = increment(),
},
},
};
HandyNotes:RegisterPluginDB(addonName, self, options);
C_Timer.NewTicker(2, function()
self:Refresh();
end);
end
function RumorMap:GetActivePact()
for pact, questID in pairs(self.Pacts.QuestIDs) do
if self:ResolvePlayerOnQuest(questID) or self:ResolvePlayerHasCompletedQuest(questID) then
return pact;
end
end
return nil;
end
function RumorMap:ResolvePlayerOnQuest(questID, debug)
if debug then debugPrint('PlayerOnQuest', questID, C_QuestLog.IsOnQuest(questID)); end
return C_QuestLog.IsOnQuest(questID);
end
function RumorMap:ResolvePlayerHasCompletedQuest(questID, debug)
if debug then debugPrint('PlayerHasCompletedQuest', questID, C_QuestLog.IsQuestFlaggedCompletedOnAccount(questID)); end
return C_QuestLog.IsQuestFlaggedCompleted(questID);
end
function RumorMap:ResolvePlayerHasCompletedQuestObjective(objectiveID, debug)
local objectiveInfo = questObjectives[objectiveID];
if not objectiveInfo then error('Unknown quest objective ' .. objectiveID); end
local questID = objectiveInfo.questID;
local objectiveIndex = objectiveInfo.objectiveIndex;
-- assumption that completing the quest, is acceptable for completing the quest objective
if self:ResolvePlayerHasCompletedQuest(questID) then
if debug then debugPrint('PlayerHasCompletedQuestObjective', questID, objectiveIndex, 'quest true'); end
return true;
end
local displayComplete = false;
local finished = select(3, GetQuestObjectiveInfo(questID, objectiveIndex, displayComplete));
if debug then debugPrint('PlayerHasCompletedQuestObjective', questID, objectiveIndex, finished); end
return finished;
end
function RumorMap:ResolveModifierTree(modifierTreeID, debug)
local tree = modifierTrees[modifierTreeID];
if not tree then error('Unknown modifier tree ' .. modifierTreeID); end
local resolver;
local type = tree.type;
if type == modifierEnum.Type.ModifierTree or type == modifierEnum.Type.None then
resolver = self.ResolveModifierTree;
elseif type == modifierEnum.Type.PlayerOnQuest then
resolver = self.ResolvePlayerOnQuest;
elseif type == modifierEnum.Type.PlayerHasCompletedQuest then
resolver = self.ResolvePlayerHasCompletedQuest;
elseif type == modifierEnum.Type.PlayerHasCompletedQuestObjective then
resolver = self.ResolvePlayerHasCompletedQuestObjective;
end
local operator = tree.operator;
if operator == modifierEnum.Operator.SingleTrue then
if type == modifierEnum.Type.PlayerHasCompletedQuest then
if debug then debugPrint('SingleTrue', tree.asset, 'hardcoded true'); end
-- this is likely to be the quest for treasure/rumor map
return true;
end
if debug then debugPrint('SingleTrue', tree.asset, resolver(self, tree.asset, true)); end
return resolver(self, tree.asset);
elseif operator == modifierEnum.Operator.SingleFalse then
if debug then debugPrint('SingleFalse', tree.asset, not resolver(self, tree.asset, true)); end
return not resolver(self, tree.asset);
elseif operator == modifierEnum.Operator.All then
for _, childID in pairs(tree.children) do
if debug then debugPrint('All', childID, resolver(self, childID, true)); end
if not resolver(self, childID) then return false; end
end
if debug then debugPrint('All', 'done', true); end
return true;
elseif operator == modifierEnum.Operator.Some then
for _, childID in pairs(tree.children) do
if debug then debugPrint('Some', childID, resolver(self, childID, true)); end
if resolver(self, childID) then return true; end
end
if debug then debugPrint('Some', 'done', false); end
return false;
end
error('Unknown operator ' .. operator);
end
function RumorMap:ResolvePactTreasure(apoiName, debug)
local pact = self.Pacts.TreasureNames[apoiName];
if debug then debugPrint('ResolvePactTreasure', pact, apoiName); end
if not pact then
return self.db.showRumors;
elseif not self.db.showTreasures then
return false;
end
local activePact = self:GetActivePact();
if pact ~= activePact then
if debug then debugPrint('ResolvePactTreasure', pact, activePact, false); end
return false;
end
local knowsPactTreasureTrait = IsPlayerSpell(self.Pacts.TreasureSpellIDs[pact]);
if debug then debugPrint('ResolvePactTreasure', pact, activePact, knowsPactTreasureTrait); end
return knowsPactTreasureTrait;
end
function RumorMap:CheckAreaPOIIsOnMap(areaPoiID)
local info = C_AreaPoiInfo.GetAreaPOIInfo(mapID, areaPoiID);
return not not info;
end
local superTrackedAreaPoiID;
local function iter(t, previousIndex)
if not t then return nil; end
local index, value = next(t, previousIndex);
while index and value do
--- @type RumorMap_Node
local node = value;
local shouldShow = not RumorMap:CheckAreaPOIIsOnMap(node.areaPoiID);
shouldShow = shouldShow and RumorMap:ResolveModifierTree(node.modifierTreeID);
shouldShow = shouldShow and (not node.prevQuestID or not RumorMap:ResolvePlayerHasCompletedQuest(node.prevQuestID));
shouldShow = shouldShow and (not node.questID or not RumorMap:ResolvePlayerHasCompletedQuest(node.questID));
shouldShow = shouldShow and (RumorMap:ResolvePactTreasure(node.name));
if (shouldShow or RumorMap.debug) then
local scaleModifier = superTrackedAreaPoiID == node.areaPoiID and 1.5 or 1.2;
return index, nil, iconDefault, RumorMap.db.iconScale * scaleModifier, RumorMap.db.iconAlpha * 2;
end
index, value = next(t, index);
end
end
function RumorMap:GetNodes2(uiMapId, isMinimapUpdate)
if not alternateMapIDs[uiMapId] or isMinimapUpdate then return function() end end
superTrackedAreaPoiID = nil;
local type, id = C_SuperTrack.GetSuperTrackedMapPin();
if type == Enum.SuperTrackingMapPinType.AreaPOI then
superTrackedAreaPoiID = id;
end
return iter, self.nodes[uiMapId], nil
end
function RumorMap.OnClick(mapPin, button, down, mapFile, coord)
if not down then return; end
local node = RumorMap.nodes[mapFile][coord];
if not node then return; end
if IsAltKeyDown() and RumorMap.isTomTomLoaded then
TomTom:AddWaypoint(mapFile, node.x, node.y, {
title = node.name,
from = addonName,
persistent = nil,
minimap = true,
world = true,
});
elseif node.areaPoiID then
local type, id = C_SuperTrack.GetSuperTrackedMapPin();
if type == Enum.SuperTrackingMapPinType.AreaPOI and id == node.areaPoiID then
C_SuperTrack.ClearSuperTrackedMapPin();
else
C_SuperTrack.SetSuperTrackedMapPin(Enum.SuperTrackingMapPinType.AreaPOI, node.areaPoiID);
end
RumorMap:Refresh();
end
end
function RumorMap.OnEnter(mapPin, mapFile, coord)
local node = RumorMap.nodes[mapFile][coord];
if not node then return; end
if ( mapPin:GetCenter() > UIParent:GetCenter() ) then
GameTooltip:SetOwner(mapPin, 'ANCHOR_LEFT');
else
GameTooltip:SetOwner(mapPin, 'ANCHOR_RIGHT');
end
local text = node.name;
GameTooltip:SetText(text);
if node.description then
GameTooltip:AddLine(node.description, 1, 1, 1, true);
end
GameTooltip:AddDoubleLine('AreaPoiID', node.areaPoiID, 1, 1, 1);
if RumorMap.debug then
debugPrint('---start---');
local modifier = RumorMap:ResolveModifierTree(node.modifierTreeID, true);
debugPrint('---end---');
local prevquestID = (not node.prevQuestID or not RumorMap:ResolvePlayerHasCompletedQuest(node.prevQuestID));
local questID = (not node.questID or not RumorMap:ResolvePlayerHasCompletedQuest(node.questID));
local pactTreasure = RumorMap:ResolvePactTreasure(node.name, true);
GameTooltip:AddDoubleLine('Modifier', modifier and 'true' or 'false', 1, 1, 1, 1, 1, 1);
GameTooltip:AddDoubleLine('PrevQuestID', prevquestID and 'true' or 'false', 1, 1, 1, 1, 1, 1);
GameTooltip:AddDoubleLine('QuestID', questID and 'true' or 'false', 1, 1, 1, 1, 1, 1);
GameTooltip:AddDoubleLine('PactTreasure', pactTreasure and 'true' or 'false', 1, 1, 1, 1, 1, 1);
end
GameTooltip_AddInstructionLine(GameTooltip, 'Click to toggle SuperTrack');
if RumorMap.isTomTomLoaded then
GameTooltip_AddInstructionLine(GameTooltip, 'Alt-click to set TomTom waypoint');
end
GameTooltip:Show();
end
function RumorMap:OnLeave()
GameTooltip:Hide()
end
function RumorMap:Refresh()
HandyNotes:SendMessage('HandyNotes_NotifyUpdate', addonName);
end