jcallahan@0
|
1 -----------------------------------------------------------------------
|
jcallahan@0
|
2 -- Upvalued Lua API.
|
jcallahan@0
|
3 -----------------------------------------------------------------------
|
jcallahan@0
|
4 local _G = getfenv(0)
|
jcallahan@0
|
5
|
jcallahan@0
|
6 local pairs = _G.pairs
|
jcallahan@1
|
7 local tonumber = _G.tonumber
|
jcallahan@1
|
8
|
jcallahan@1
|
9 local bit = _G.bit
|
jcallahan@1
|
10 local math = _G.math
|
jcallahan@1
|
11 local table = _G.table
|
jcallahan@1
|
12
|
jcallahan@0
|
13
|
jcallahan@0
|
14 -----------------------------------------------------------------------
|
jcallahan@0
|
15 -- AddOn namespace.
|
jcallahan@0
|
16 -----------------------------------------------------------------------
|
jcallahan@0
|
17 local ADDON_NAME, private = ...
|
jcallahan@0
|
18
|
jcallahan@0
|
19 local LibStub = _G.LibStub
|
jcallahan@0
|
20 local WDP = LibStub("AceAddon-3.0"):NewAddon(ADDON_NAME, "AceEvent-3.0", "AceTimer-3.0")
|
jcallahan@0
|
21
|
jcallahan@48
|
22 local deformat = LibStub("LibDeformat-3.0")
|
jcallahan@48
|
23
|
jcallahan@4
|
24 local DatamineTT = _G.CreateFrame("GameTooltip", "WDPDatamineTT", _G.UIParent, "GameTooltipTemplate")
|
jcallahan@5
|
25 DatamineTT:SetOwner(_G.WorldFrame, "ANCHOR_NONE")
|
jcallahan@5
|
26
|
jcallahan@0
|
27
|
jcallahan@0
|
28 -----------------------------------------------------------------------
|
jcallahan@0
|
29 -- Local constants.
|
jcallahan@0
|
30 -----------------------------------------------------------------------
|
jcallahan@63
|
31 local DB_VERSION = 1
|
jcallahan@63
|
32
|
jcallahan@0
|
33 local DATABASE_DEFAULTS = {
|
jcallahan@0
|
34 global = {
|
jcallahan@0
|
35 items = {},
|
jcallahan@0
|
36 npcs = {},
|
jcallahan@0
|
37 objects = {},
|
jcallahan@0
|
38 quests = {},
|
jcallahan@17
|
39 zones = {},
|
jcallahan@0
|
40 }
|
jcallahan@0
|
41 }
|
jcallahan@0
|
42
|
jcallahan@0
|
43
|
jcallahan@1
|
44 local EVENT_MAPPING = {
|
jcallahan@56
|
45 BLACK_MARKET_ITEM_UPDATE = true,
|
jcallahan@48
|
46 CHAT_MSG_LOOT = true,
|
jcallahan@40
|
47 CHAT_MSG_SYSTEM = true,
|
jcallahan@23
|
48 COMBAT_LOG_EVENT_UNFILTERED = true,
|
jcallahan@18
|
49 COMBAT_TEXT_UPDATE = true,
|
jcallahan@42
|
50 ITEM_TEXT_BEGIN = true,
|
jcallahan@1
|
51 LOOT_OPENED = true,
|
jcallahan@7
|
52 MERCHANT_SHOW = "UpdateMerchantItems",
|
jcallahan@61
|
53 MERCHANT_UPDATE = "UpdateMerchantItems",
|
jcallahan@25
|
54 PET_BAR_UPDATE = true,
|
jcallahan@2
|
55 PLAYER_TARGET_CHANGED = true,
|
jcallahan@9
|
56 QUEST_COMPLETE = true,
|
jcallahan@9
|
57 QUEST_DETAIL = true,
|
jcallahan@9
|
58 QUEST_LOG_UPDATE = true,
|
jcallahan@27
|
59 TRAINER_SHOW = true,
|
jcallahan@4
|
60 UNIT_QUEST_LOG_CHANGED = true,
|
jcallahan@1
|
61 UNIT_SPELLCAST_FAILED = "HandleSpellFailure",
|
jcallahan@1
|
62 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure",
|
jcallahan@1
|
63 UNIT_SPELLCAST_INTERRUPTED = "HandleSpellFailure",
|
jcallahan@1
|
64 UNIT_SPELLCAST_SENT = true,
|
jcallahan@1
|
65 UNIT_SPELLCAST_SUCCEEDED = true,
|
jcallahan@0
|
66 }
|
jcallahan@0
|
67
|
jcallahan@4
|
68
|
jcallahan@1
|
69 local AF = private.ACTION_TYPE_FLAGS
|
jcallahan@0
|
70
|
jcallahan@4
|
71
|
jcallahan@27
|
72 local PLAYER_CLASS = _G.select(2, _G.UnitClass("player"))
|
jcallahan@34
|
73 local PLAYER_GUID = _G.UnitGUID("player")
|
jcallahan@39
|
74 local PLAYER_RACE = _G.select(2, _G.UnitRace("player"))
|
jcallahan@27
|
75
|
jcallahan@0
|
76 -----------------------------------------------------------------------
|
jcallahan@0
|
77 -- Local variables.
|
jcallahan@0
|
78 -----------------------------------------------------------------------
|
jcallahan@0
|
79 local db
|
jcallahan@0
|
80 local durability_timer_handle
|
jcallahan@2
|
81 local target_location_timer_handle
|
jcallahan@1
|
82 local action_data = {}
|
jcallahan@40
|
83 local currently_drunk
|
jcallahan@32
|
84 local faction_standings = {}
|
jcallahan@0
|
85
|
jcallahan@1
|
86
|
jcallahan@1
|
87 -----------------------------------------------------------------------
|
jcallahan@1
|
88 -- Helper Functions.
|
jcallahan@1
|
89 -----------------------------------------------------------------------
|
jcallahan@39
|
90 local ActualCopperCost
|
jcallahan@39
|
91 do
|
jcallahan@39
|
92 local BARTERING_SPELL_ID = 83964
|
jcallahan@39
|
93
|
jcallahan@39
|
94 local STANDING_DISCOUNTS = {
|
jcallahan@39
|
95 HATED = 0,
|
jcallahan@39
|
96 HOSTILE = 0,
|
jcallahan@39
|
97 UNFRIENDLY = 0,
|
jcallahan@39
|
98 NEUTRAL = 0,
|
jcallahan@39
|
99 FRIENDLY = 0.05,
|
jcallahan@39
|
100 HONORED = 0.1,
|
jcallahan@39
|
101 REVERED = 0.15,
|
jcallahan@39
|
102 EXALTED = 0.2,
|
jcallahan@39
|
103 }
|
jcallahan@39
|
104
|
jcallahan@39
|
105
|
jcallahan@39
|
106 function ActualCopperCost(copper_cost, rep_standing)
|
jcallahan@39
|
107 if not copper_cost or copper_cost == 0 then
|
jcallahan@39
|
108 return 0
|
jcallahan@39
|
109 end
|
jcallahan@39
|
110 local modifier = 1
|
jcallahan@39
|
111
|
jcallahan@39
|
112 if _G.IsSpellKnown(BARTERING_SPELL_ID) then
|
jcallahan@39
|
113 modifier = modifier - 0.1
|
jcallahan@39
|
114 end
|
jcallahan@39
|
115
|
jcallahan@39
|
116 if rep_standing then
|
jcallahan@39
|
117 if PLAYER_RACE == "Goblin" then
|
jcallahan@39
|
118 modifier = modifier - STANDING_DISCOUNTS["EXALTED"]
|
jcallahan@39
|
119 elseif STANDING_DISCOUNTS[rep_standing] then
|
jcallahan@39
|
120 modifier = modifier - STANDING_DISCOUNTS[rep_standing]
|
jcallahan@39
|
121 end
|
jcallahan@39
|
122 end
|
jcallahan@39
|
123 return math.floor(copper_cost / modifier)
|
jcallahan@39
|
124 end
|
jcallahan@39
|
125 end -- do-block
|
jcallahan@39
|
126
|
jcallahan@39
|
127
|
jcallahan@29
|
128 local function InstanceDifficultyToken()
|
jcallahan@29
|
129 local _, instance_type, instance_difficulty, difficulty_name, _, _, is_dynamic = _G.GetInstanceInfo()
|
jcallahan@59
|
130 if not difficulty_name or difficulty_name == "" then
|
jcallahan@29
|
131 difficulty_name = "NONE"
|
jcallahan@29
|
132 end
|
jcallahan@59
|
133
|
jcallahan@59
|
134 if not instance_type or instance_type == "" then
|
jcallahan@59
|
135 instance_type = "NONE"
|
jcallahan@59
|
136 end
|
jcallahan@29
|
137 return ("%s:%s:%s"):format(instance_type:upper(), difficulty_name:upper():gsub(" ", "_"), _G.tostring(is_dynamic))
|
jcallahan@29
|
138 end
|
jcallahan@29
|
139
|
jcallahan@29
|
140
|
jcallahan@19
|
141 local function DBEntry(data_type, unit_id)
|
jcallahan@19
|
142 if not data_type or not unit_id then
|
jcallahan@6
|
143 return
|
jcallahan@6
|
144 end
|
jcallahan@19
|
145 local unit = db[data_type][unit_id]
|
jcallahan@6
|
146
|
jcallahan@10
|
147 if not unit then
|
jcallahan@19
|
148 db[data_type][unit_id] = {}
|
jcallahan@19
|
149 unit = db[data_type][unit_id]
|
jcallahan@6
|
150 end
|
jcallahan@10
|
151 return unit
|
jcallahan@6
|
152 end
|
jcallahan@6
|
153
|
jcallahan@6
|
154
|
jcallahan@29
|
155 local function NPCEntry(identifier)
|
jcallahan@29
|
156 local npc = DBEntry("npcs", identifier)
|
jcallahan@29
|
157
|
jcallahan@29
|
158 if not npc then
|
jcallahan@29
|
159 return
|
jcallahan@22
|
160 end
|
jcallahan@29
|
161 local instance_token = InstanceDifficultyToken()
|
jcallahan@29
|
162 npc.encounter_data = npc.encounter_data or {}
|
jcallahan@29
|
163 npc.encounter_data[instance_token] = npc.encounter_data[instance_token] or {}
|
jcallahan@30
|
164 npc.encounter_data[instance_token].stats = npc.encounter_data[instance_token].stats or {}
|
jcallahan@29
|
165 return npc
|
jcallahan@22
|
166 end
|
jcallahan@22
|
167
|
jcallahan@22
|
168
|
jcallahan@1
|
169 local function CurrentLocationData()
|
jcallahan@1
|
170 local map_level = _G.GetCurrentMapDungeonLevel() or 0
|
jcallahan@1
|
171 local x, y = _G.GetPlayerMapPosition("player")
|
jcallahan@1
|
172
|
jcallahan@1
|
173 x = x or 0
|
jcallahan@1
|
174 y = y or 0
|
jcallahan@1
|
175
|
jcallahan@1
|
176 if x == 0 and y == 0 then
|
jcallahan@1
|
177 for level_index = 1, _G.GetNumDungeonMapLevels() do
|
jcallahan@1
|
178 _G.SetDungeonMapLevel(level_index)
|
jcallahan@1
|
179 x, y = _G.GetPlayerMapPosition("player")
|
jcallahan@1
|
180
|
jcallahan@1
|
181 if x and y and (x > 0 or y > 0) then
|
jcallahan@1
|
182 _G.SetDungeonMapLevel(map_level)
|
jcallahan@1
|
183 map_level = level_index
|
jcallahan@1
|
184 break
|
jcallahan@1
|
185 end
|
jcallahan@1
|
186 end
|
jcallahan@1
|
187 end
|
jcallahan@1
|
188
|
jcallahan@1
|
189 if _G.DungeonUsesTerrainMap() then
|
jcallahan@1
|
190 map_level = map_level - 1
|
jcallahan@1
|
191 end
|
jcallahan@31
|
192 local x = _G.floor(x * 1000)
|
jcallahan@31
|
193 local y = _G.floor(y * 1000)
|
jcallahan@28
|
194
|
jcallahan@31
|
195 if x % 2 ~= 0 then
|
jcallahan@31
|
196 x = x + 1
|
jcallahan@28
|
197 end
|
jcallahan@28
|
198
|
jcallahan@31
|
199 if y % 2 ~= 0 then
|
jcallahan@31
|
200 y = y + 1
|
jcallahan@28
|
201 end
|
jcallahan@31
|
202 return _G.GetRealZoneText(), _G.GetCurrentMapAreaID(), x, y, map_level, InstanceDifficultyToken()
|
jcallahan@1
|
203 end
|
jcallahan@1
|
204
|
jcallahan@1
|
205
|
jcallahan@1
|
206 local function ItemLinkToID(item_link)
|
jcallahan@1
|
207 if not item_link then
|
jcallahan@1
|
208 return
|
jcallahan@1
|
209 end
|
jcallahan@7
|
210 return tonumber(item_link:match("item:(%d+)"))
|
jcallahan@1
|
211 end
|
jcallahan@0
|
212
|
jcallahan@4
|
213
|
jcallahan@34
|
214 local ParseGUID
|
jcallahan@4
|
215 do
|
jcallahan@4
|
216 local UNIT_TYPE_BITMASK = 0x007
|
jcallahan@4
|
217
|
jcallahan@34
|
218 function ParseGUID(guid)
|
jcallahan@5
|
219 if not guid then
|
jcallahan@5
|
220 return
|
jcallahan@5
|
221 end
|
jcallahan@4
|
222 local types = private.UNIT_TYPES
|
jcallahan@4
|
223 local unit_type = _G.bit.band(tonumber(guid:sub(1, 5)), UNIT_TYPE_BITMASK)
|
jcallahan@4
|
224
|
jcallahan@10
|
225 if unit_type ~= types.PLAYER and unit_type ~= types.PET then
|
jcallahan@66
|
226 return unit_type, tonumber(guid:sub(6, 10), 16)
|
jcallahan@4
|
227 end
|
jcallahan@4
|
228 return unit_type
|
jcallahan@4
|
229 end
|
jcallahan@4
|
230 end -- do-block
|
jcallahan@4
|
231
|
jcallahan@4
|
232
|
jcallahan@34
|
233 local UpdateNPCLocation
|
jcallahan@34
|
234 do
|
jcallahan@34
|
235 local COORD_MAX = 5
|
jcallahan@34
|
236
|
jcallahan@34
|
237 function UpdateNPCLocation(unit_idnum)
|
jcallahan@34
|
238 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData()
|
jcallahan@34
|
239 local npc_data = NPCEntry(unit_idnum).encounter_data[difficulty_token].stats[("level_%d"):format(_G.UnitLevel("target"))]
|
jcallahan@34
|
240 local zone_token = ("%s:%d"):format(zone_name, area_id)
|
jcallahan@34
|
241 npc_data.locations = npc_data.locations or {}
|
jcallahan@34
|
242
|
jcallahan@34
|
243 local zone_data = npc_data.locations[zone_token]
|
jcallahan@34
|
244
|
jcallahan@34
|
245 if not zone_data then
|
jcallahan@34
|
246 zone_data = {}
|
jcallahan@34
|
247 npc_data.locations[zone_token] = zone_data
|
jcallahan@34
|
248 end
|
jcallahan@34
|
249
|
jcallahan@34
|
250 for location_token in pairs(zone_data) do
|
jcallahan@34
|
251 local loc_level, loc_x, loc_y = (":"):split(location_token)
|
jcallahan@34
|
252 loc_level = tonumber(loc_level)
|
jcallahan@34
|
253
|
jcallahan@34
|
254 if map_level == loc_level and math.abs(x - loc_x) <= COORD_MAX and math.abs(y - loc_y) <= COORD_MAX then
|
jcallahan@34
|
255 return
|
jcallahan@34
|
256 end
|
jcallahan@34
|
257 end
|
jcallahan@34
|
258 zone_data[("%s:%s:%s"):format(map_level, x, y)] = true
|
jcallahan@34
|
259 end
|
jcallahan@34
|
260 end -- do-block
|
jcallahan@34
|
261
|
jcallahan@34
|
262
|
jcallahan@52
|
263 local function UpdateDBEntryLocation(entry_type, identifier)
|
jcallahan@10
|
264 if not identifier then
|
jcallahan@10
|
265 return
|
jcallahan@10
|
266 end
|
jcallahan@31
|
267 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData()
|
jcallahan@41
|
268 local entry = DBEntry(entry_type, identifier)
|
jcallahan@41
|
269 entry[difficulty_token] = entry[difficulty_token] or {}
|
jcallahan@52
|
270 entry[difficulty_token].locations = entry[difficulty_token].locations or {}
|
jcallahan@10
|
271
|
jcallahan@31
|
272 local zone_token = ("%s:%d"):format(zone_name, area_id)
|
jcallahan@52
|
273 local zone_data = entry[difficulty_token].locations[zone_token]
|
jcallahan@24
|
274
|
jcallahan@31
|
275 if not zone_data then
|
jcallahan@31
|
276 zone_data = {}
|
jcallahan@52
|
277 entry[difficulty_token].locations[zone_token] = zone_data
|
jcallahan@10
|
278 end
|
jcallahan@41
|
279 local location_token = ("%s:%s:%s"):format(map_level, x, y)
|
jcallahan@41
|
280 zone_data[location_token] = zone_data[location_token] or true
|
jcallahan@41
|
281 return zone_data
|
jcallahan@10
|
282 end
|
jcallahan@10
|
283
|
jcallahan@10
|
284
|
jcallahan@19
|
285 local function HandleItemUse(item_link, bag_index, slot_index)
|
jcallahan@19
|
286 if not item_link then
|
jcallahan@19
|
287 return
|
jcallahan@19
|
288 end
|
jcallahan@19
|
289 local item_id = ItemLinkToID(item_link)
|
jcallahan@19
|
290
|
jcallahan@19
|
291 if not bag_index or not slot_index then
|
jcallahan@19
|
292 for new_bag_index = 0, _G.NUM_BAG_FRAMES do
|
jcallahan@19
|
293 for new_slot_index = 1, _G.GetContainerNumSlots(new_bag_index) do
|
jcallahan@19
|
294 if item_id == ItemLinkToID(_G.GetContainerItemLink(new_bag_index, new_slot_index)) then
|
jcallahan@19
|
295 bag_index = new_bag_index
|
jcallahan@19
|
296 slot_index = new_slot_index
|
jcallahan@19
|
297 break
|
jcallahan@19
|
298 end
|
jcallahan@19
|
299 end
|
jcallahan@19
|
300 end
|
jcallahan@19
|
301 end
|
jcallahan@19
|
302
|
jcallahan@19
|
303 if not bag_index or not slot_index then
|
jcallahan@19
|
304 return
|
jcallahan@19
|
305 end
|
jcallahan@19
|
306 local _, _, _, _, _, is_lootable = _G.GetContainerItemInfo(bag_index, slot_index)
|
jcallahan@19
|
307
|
jcallahan@19
|
308 if not is_lootable then
|
jcallahan@19
|
309 return
|
jcallahan@19
|
310 end
|
jcallahan@19
|
311 DatamineTT:ClearLines()
|
jcallahan@19
|
312 DatamineTT:SetBagItem(bag_index, slot_index)
|
jcallahan@19
|
313
|
jcallahan@19
|
314 for line_index = 1, DatamineTT:NumLines() do
|
jcallahan@19
|
315 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@19
|
316
|
jcallahan@19
|
317 if not current_line then
|
jcallahan@19
|
318 break
|
jcallahan@19
|
319 end
|
jcallahan@19
|
320
|
jcallahan@19
|
321 if current_line:GetText() == _G.ITEM_OPENABLE then
|
jcallahan@19
|
322 table.wipe(action_data)
|
jcallahan@19
|
323 action_data.type = AF.ITEM
|
jcallahan@28
|
324 action_data.identifier = item_id
|
jcallahan@25
|
325 action_data.label = "contains"
|
jcallahan@19
|
326 break
|
jcallahan@19
|
327 end
|
jcallahan@19
|
328 end
|
jcallahan@19
|
329 end
|
jcallahan@19
|
330
|
jcallahan@19
|
331
|
jcallahan@39
|
332 local UnitFactionStanding
|
jcallahan@32
|
333 local UpdateFactionData
|
jcallahan@32
|
334 do
|
jcallahan@32
|
335 local MAX_FACTION_INDEX = 1000
|
jcallahan@20
|
336
|
jcallahan@32
|
337 local STANDING_NAMES = {
|
jcallahan@32
|
338 "HATED",
|
jcallahan@32
|
339 "HOSTILE",
|
jcallahan@32
|
340 "UNFRIENDLY",
|
jcallahan@32
|
341 "NEUTRAL",
|
jcallahan@32
|
342 "FRIENDLY",
|
jcallahan@32
|
343 "HONORED",
|
jcallahan@32
|
344 "REVERED",
|
jcallahan@32
|
345 "EXALTED",
|
jcallahan@32
|
346 }
|
jcallahan@32
|
347
|
jcallahan@39
|
348
|
jcallahan@39
|
349 function UnitFactionStanding(unit)
|
jcallahan@39
|
350 UpdateFactionData()
|
jcallahan@39
|
351 DatamineTT:ClearLines()
|
jcallahan@39
|
352 DatamineTT:SetUnit(unit)
|
jcallahan@39
|
353
|
jcallahan@39
|
354 for line_index = 1, DatamineTT:NumLines() do
|
jcallahan@64
|
355 local faction_name = _G["WDPDatamineTTTextLeft" .. line_index]:GetText():trim()
|
jcallahan@39
|
356
|
jcallahan@39
|
357 if faction_name and faction_standings[faction_name] then
|
jcallahan@39
|
358 return faction_name, faction_standings[faction_name]
|
jcallahan@39
|
359 end
|
jcallahan@39
|
360 end
|
jcallahan@39
|
361 end
|
jcallahan@39
|
362
|
jcallahan@39
|
363
|
jcallahan@32
|
364 function UpdateFactionData()
|
jcallahan@32
|
365 for faction_index = 1, MAX_FACTION_INDEX do
|
jcallahan@32
|
366 local faction_name, _, current_standing, _, _, _, _, _, is_header = _G.GetFactionInfo(faction_index)
|
jcallahan@32
|
367
|
jcallahan@32
|
368 if faction_name and not is_header then
|
jcallahan@32
|
369 faction_standings[faction_name] = STANDING_NAMES[current_standing]
|
jcallahan@32
|
370 elseif not faction_name then
|
jcallahan@32
|
371 break
|
jcallahan@32
|
372 end
|
jcallahan@20
|
373 end
|
jcallahan@20
|
374 end
|
jcallahan@32
|
375 end -- do-block
|
jcallahan@20
|
376
|
jcallahan@48
|
377
|
jcallahan@62
|
378 local function GenericLootUpdate(data_type, top_field)
|
jcallahan@48
|
379 local entry = DBEntry(data_type, action_data.identifier)
|
jcallahan@48
|
380
|
jcallahan@48
|
381 if not entry then
|
jcallahan@48
|
382 return
|
jcallahan@48
|
383 end
|
jcallahan@48
|
384 local loot_type = action_data.label or "drops"
|
jcallahan@48
|
385 local loot_count = ("%s_count"):format(loot_type)
|
jcallahan@48
|
386 local loot_data
|
jcallahan@48
|
387
|
jcallahan@48
|
388 if top_field then
|
jcallahan@48
|
389 entry[top_field] = entry[top_field] or {}
|
jcallahan@48
|
390 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1
|
jcallahan@48
|
391 entry[top_field][loot_type] = entry[top_field][loot_type] or {}
|
jcallahan@48
|
392 loot_data = entry[top_field][loot_type]
|
jcallahan@48
|
393 else
|
jcallahan@48
|
394 entry[loot_count] = (entry[loot_count] or 0) + 1
|
jcallahan@48
|
395 entry[loot_type] = entry[loot_type] or {}
|
jcallahan@48
|
396 loot_data = entry[loot_type]
|
jcallahan@48
|
397 end
|
jcallahan@48
|
398
|
jcallahan@48
|
399 for index = 1, #action_data.loot_list do
|
jcallahan@48
|
400 table.insert(loot_data, action_data.loot_list[index])
|
jcallahan@48
|
401 end
|
jcallahan@48
|
402 end
|
jcallahan@48
|
403
|
jcallahan@48
|
404
|
jcallahan@0
|
405 -----------------------------------------------------------------------
|
jcallahan@0
|
406 -- Methods.
|
jcallahan@0
|
407 -----------------------------------------------------------------------
|
jcallahan@0
|
408 function WDP:OnInitialize()
|
jcallahan@0
|
409 db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default").global
|
jcallahan@14
|
410
|
jcallahan@14
|
411 local raw_db = _G["WoWDBProfilerData"]
|
jcallahan@14
|
412
|
jcallahan@18
|
413 local build_num = tonumber(private.build_num)
|
jcallahan@14
|
414
|
jcallahan@35
|
415 -- TODO: Un-comment this when MoP goes live.
|
jcallahan@35
|
416 -- if raw_db.build_num and raw_db.build_num < build_num then
|
jcallahan@35
|
417 -- for entry in pairs(DATABASE_DEFAULTS.global) do
|
jcallahan@35
|
418 -- db[entry] = {}
|
jcallahan@35
|
419 -- end
|
jcallahan@35
|
420 -- end
|
jcallahan@35
|
421 raw_db.build_num = build_num
|
jcallahan@63
|
422 raw_db.version = DB_VERSION
|
jcallahan@0
|
423 end
|
jcallahan@0
|
424
|
jcallahan@0
|
425
|
jcallahan@0
|
426 function WDP:OnEnable()
|
jcallahan@0
|
427 for event_name, mapping in pairs(EVENT_MAPPING) do
|
jcallahan@1
|
428 self:RegisterEvent(event_name, (_G.type(mapping) ~= "boolean") and mapping or nil)
|
jcallahan@0
|
429 end
|
jcallahan@0
|
430 durability_timer_handle = self:ScheduleRepeatingTimer("ProcessDurability", 30)
|
jcallahan@31
|
431 target_location_timer_handle = self:ScheduleRepeatingTimer("UpdateTargetLocation", 0.5)
|
jcallahan@19
|
432
|
jcallahan@19
|
433 _G.hooksecurefunc("UseContainerItem", function(bag_index, slot_index, target_unit)
|
jcallahan@19
|
434 if target_unit then
|
jcallahan@19
|
435 return
|
jcallahan@19
|
436 end
|
jcallahan@19
|
437 HandleItemUse(_G.GetContainerItemLink(bag_index, slot_index), bag_index, slot_index)
|
jcallahan@19
|
438 end)
|
jcallahan@19
|
439
|
jcallahan@19
|
440 _G.hooksecurefunc("UseItemByName", function(identifier, target_unit)
|
jcallahan@19
|
441 if target_unit then
|
jcallahan@19
|
442 return
|
jcallahan@19
|
443 end
|
jcallahan@19
|
444 local _, item_link = _G.GetItemInfo(identifier)
|
jcallahan@19
|
445 HandleItemUse(item_link)
|
jcallahan@19
|
446 end)
|
jcallahan@0
|
447 end
|
jcallahan@0
|
448
|
jcallahan@0
|
449
|
jcallahan@0
|
450 local function RecordDurability(item_id, durability)
|
jcallahan@0
|
451 if not durability or durability <= 0 then
|
jcallahan@0
|
452 return
|
jcallahan@0
|
453 end
|
jcallahan@0
|
454
|
jcallahan@0
|
455 if not db.items[item_id] then
|
jcallahan@0
|
456 db.items[item_id] = {}
|
jcallahan@0
|
457 end
|
jcallahan@0
|
458 db.items[item_id].durability = durability
|
jcallahan@0
|
459 end
|
jcallahan@0
|
460
|
jcallahan@0
|
461
|
jcallahan@0
|
462 function WDP:ProcessDurability()
|
jcallahan@0
|
463 for slot_index = 0, _G.INVSLOT_LAST_EQUIPPED do
|
jcallahan@1
|
464 local item_id = _G.GetInventoryItemID("player", slot_index)
|
jcallahan@0
|
465
|
jcallahan@0
|
466 if item_id and item_id > 0 then
|
jcallahan@1
|
467 local _, max_durability = _G.GetInventoryItemDurability(slot_index)
|
jcallahan@0
|
468 RecordDurability(item_id, max_durability)
|
jcallahan@0
|
469 end
|
jcallahan@0
|
470 end
|
jcallahan@0
|
471
|
jcallahan@0
|
472 for bag_index = 0, _G.NUM_BAG_SLOTS do
|
jcallahan@0
|
473 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
|
jcallahan@1
|
474 local item_id = _G.GetContainerItemID(bag_index, slot_index)
|
jcallahan@0
|
475
|
jcallahan@0
|
476 if item_id and item_id > 0 then
|
jcallahan@1
|
477 local _, max_durability = _G.GetContainerItemDurability(bag_index, slot_index)
|
jcallahan@0
|
478 RecordDurability(item_id, max_durability)
|
jcallahan@0
|
479 end
|
jcallahan@0
|
480 end
|
jcallahan@0
|
481 end
|
jcallahan@0
|
482 end
|
jcallahan@0
|
483
|
jcallahan@0
|
484
|
jcallahan@2
|
485 function WDP:UpdateTargetLocation()
|
jcallahan@40
|
486 if currently_drunk or not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or (_G.UnitIsTapped("target") and not _G.UnitIsDead("target")) then
|
jcallahan@2
|
487 return
|
jcallahan@2
|
488 end
|
jcallahan@2
|
489
|
jcallahan@2
|
490 for index = 1, 4 do
|
jcallahan@2
|
491 if not _G.CheckInteractDistance("target", index) then
|
jcallahan@2
|
492 return
|
jcallahan@2
|
493 end
|
jcallahan@2
|
494 end
|
jcallahan@40
|
495 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@2
|
496
|
jcallahan@40
|
497 if not unit_idnum or unit_type ~= private.UNIT_TYPES.NPC then
|
jcallahan@2
|
498 return
|
jcallahan@2
|
499 end
|
jcallahan@34
|
500 UpdateNPCLocation(unit_idnum)
|
jcallahan@2
|
501 end
|
jcallahan@2
|
502
|
jcallahan@2
|
503
|
jcallahan@0
|
504 -----------------------------------------------------------------------
|
jcallahan@0
|
505 -- Event handlers.
|
jcallahan@0
|
506 -----------------------------------------------------------------------
|
jcallahan@56
|
507 function WDP:BLACK_MARKET_ITEM_UPDATE(event)
|
jcallahan@56
|
508 local num_items = _G.C_BlackMarket.GetNumItems()
|
jcallahan@56
|
509
|
jcallahan@56
|
510 for index = 1, num_items do
|
jcallahan@56
|
511 local name, texture, quantity, item_type, is_usable, level, level_type, seller_name, min_bid, min_increment, current_bid, has_high_bid, num_bids, time_left, item_link, market_id = _G.C_BlackMarket.GetItemInfoByIndex(index);
|
jcallahan@56
|
512
|
jcallahan@56
|
513 if item_link then
|
jcallahan@56
|
514 DBEntry("items", ItemLinkToID(item_link)).black_market = seller_name or "UNKNOWN"
|
jcallahan@56
|
515 end
|
jcallahan@56
|
516 end
|
jcallahan@56
|
517 end
|
jcallahan@56
|
518
|
jcallahan@56
|
519
|
jcallahan@48
|
520 function WDP:CHAT_MSG_LOOT(event, message)
|
jcallahan@48
|
521 if action_data.spell_label ~= "EXTRACT_GAS" then
|
jcallahan@48
|
522 return
|
jcallahan@48
|
523 end
|
jcallahan@48
|
524 local item_link, quantity = deformat(message, _G.LOOT_ITEM_PUSHED_SELF_MULTIPLE)
|
jcallahan@48
|
525
|
jcallahan@48
|
526 if not item_link then
|
jcallahan@48
|
527 quantity, item_link = 1, deformat(message, _G.LOOT_ITEM_PUSHED_SELF)
|
jcallahan@48
|
528 end
|
jcallahan@48
|
529
|
jcallahan@48
|
530 if not item_link then
|
jcallahan@48
|
531 return
|
jcallahan@48
|
532 end
|
jcallahan@48
|
533 local item_id = ItemLinkToID(item_link)
|
jcallahan@48
|
534
|
jcallahan@48
|
535 if not item_id then
|
jcallahan@48
|
536 return
|
jcallahan@48
|
537 end
|
jcallahan@48
|
538 action_data.loot_list = {
|
jcallahan@48
|
539 ("%d:%d"):format(item_id, quantity)
|
jcallahan@48
|
540 }
|
jcallahan@48
|
541 GenericLootUpdate("zones")
|
jcallahan@48
|
542 table.wipe(action_data)
|
jcallahan@48
|
543 end
|
jcallahan@48
|
544
|
jcallahan@48
|
545
|
jcallahan@23
|
546 do
|
jcallahan@40
|
547 local SOBER_MATCH = _G.DRUNK_MESSAGE_ITEM_SELF1:gsub("%%s", ".+")
|
jcallahan@40
|
548
|
jcallahan@40
|
549 local DRUNK_COMPARES = {
|
jcallahan@40
|
550 _G.DRUNK_MESSAGE_SELF2,
|
jcallahan@40
|
551 _G.DRUNK_MESSAGE_SELF3,
|
jcallahan@40
|
552 _G.DRUNK_MESSAGE_SELF4,
|
jcallahan@40
|
553 }
|
jcallahan@40
|
554
|
jcallahan@40
|
555 local DRUNK_MATCHES = {
|
jcallahan@40
|
556 _G.DRUNK_MESSAGE_SELF2:gsub("%%s", ".+"),
|
jcallahan@40
|
557 _G.DRUNK_MESSAGE_SELF3:gsub("%%s", ".+"),
|
jcallahan@40
|
558 _G.DRUNK_MESSAGE_SELF4:gsub("%%s", ".+"),
|
jcallahan@40
|
559 }
|
jcallahan@40
|
560
|
jcallahan@40
|
561 function WDP:CHAT_MSG_SYSTEM(event, message)
|
jcallahan@40
|
562 if currently_drunk then
|
jcallahan@40
|
563 if message == _G.DRUNK_MESSAGE_SELF1 or message:match(SOBER_MATCH) then
|
jcallahan@40
|
564 currently_drunk = nil
|
jcallahan@40
|
565 end
|
jcallahan@40
|
566 return
|
jcallahan@40
|
567 end
|
jcallahan@40
|
568
|
jcallahan@40
|
569 for index = 1, #DRUNK_MATCHES do
|
jcallahan@40
|
570 if message == DRUNK_COMPARES[index] or message:match(DRUNK_MATCHES[index]) then
|
jcallahan@40
|
571 currently_drunk = true
|
jcallahan@40
|
572 break
|
jcallahan@40
|
573 end
|
jcallahan@40
|
574 end
|
jcallahan@40
|
575 end
|
jcallahan@40
|
576 end
|
jcallahan@40
|
577
|
jcallahan@40
|
578 -- do-block
|
jcallahan@40
|
579
|
jcallahan@40
|
580 do
|
jcallahan@23
|
581 local FLAGS_NPC = bit.bor(_G.COMBATLOG_OBJECT_TYPE_GUARDIAN, _G.COMBATLOG_OBJECT_CONTROL_NPC)
|
jcallahan@23
|
582 local FLAGS_NPC_CONTROL = bit.bor(_G.COMBATLOG_OBJECT_AFFILIATION_OUTSIDER, _G.COMBATLOG_OBJECT_CONTROL_NPC)
|
jcallahan@23
|
583
|
jcallahan@65
|
584 -- This is used to record faction gains
|
jcallahan@65
|
585 local dead_npc_id
|
jcallahan@23
|
586
|
jcallahan@23
|
587 local function RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
|
jcallahan@23
|
588 if not spell_id then
|
jcallahan@23
|
589 return
|
jcallahan@23
|
590 end
|
jcallahan@34
|
591 local source_type, source_id = ParseGUID(source_guid)
|
jcallahan@23
|
592
|
jcallahan@23
|
593 if not source_id or source_type ~= private.UNIT_TYPES.NPC then
|
jcallahan@23
|
594 return
|
jcallahan@23
|
595 end
|
jcallahan@23
|
596
|
jcallahan@23
|
597 if bit.band(FLAGS_NPC_CONTROL, source_flags) == FLAGS_NPC_CONTROL and bit.band(FLAGS_NPC, source_flags) ~= 0 then
|
jcallahan@29
|
598 local encounter_data = NPCEntry(source_id).encounter_data[InstanceDifficultyToken()]
|
jcallahan@28
|
599 encounter_data.spells = encounter_data.spells or {}
|
jcallahan@28
|
600 encounter_data.spells[spell_id] = (encounter_data.spells[spell_id] or 0) + 1
|
jcallahan@23
|
601 end
|
jcallahan@23
|
602 end
|
jcallahan@23
|
603
|
jcallahan@23
|
604 local COMBAT_LOG_FUNCS = {
|
jcallahan@23
|
605 SPELL_AURA_APPLIED = RecordNPCSpell,
|
jcallahan@23
|
606 SPELL_CAST_START = RecordNPCSpell,
|
jcallahan@48
|
607 SPELL_CAST_SUCCESS = RecordNPCSpell,
|
jcallahan@65
|
608 UNIT_DIED = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
|
jcallahan@65
|
609 local unit_type, unit_idnum = ParseGUID(dest_guid)
|
jcallahan@65
|
610
|
jcallahan@65
|
611 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@65
|
612 dead_npc_id = nil
|
jcallahan@65
|
613 return
|
jcallahan@65
|
614 end
|
jcallahan@65
|
615 dead_npc_id = unit_idnum
|
jcallahan@65
|
616 end,
|
jcallahan@23
|
617 }
|
jcallahan@23
|
618
|
jcallahan@23
|
619
|
jcallahan@23
|
620 function WDP:COMBAT_LOG_EVENT_UNFILTERED(event, time_stamp, sub_event, hide_caster, source_guid, source_name, source_flags, source_raid_flags, dest_guid, dest_name, dest_flags, dest_raid_flags, ...)
|
jcallahan@23
|
621 local combat_log_func = COMBAT_LOG_FUNCS[sub_event]
|
jcallahan@23
|
622
|
jcallahan@23
|
623 if not combat_log_func then
|
jcallahan@23
|
624 return
|
jcallahan@23
|
625 end
|
jcallahan@23
|
626 combat_log_func(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, ...)
|
jcallahan@23
|
627 end
|
jcallahan@23
|
628
|
jcallahan@44
|
629 local DIPLOMACY_SPELL_ID = 20599
|
jcallahan@44
|
630 local MR_POP_RANK1_SPELL_ID = 78634
|
jcallahan@44
|
631 local MR_POP_RANK2_SPELL_ID = 78635
|
jcallahan@44
|
632
|
jcallahan@44
|
633 local REP_BUFFS = {
|
jcallahan@44
|
634 [_G.GetSpellInfo(30754)] = "CENARION_FAVOR",
|
jcallahan@44
|
635 [_G.GetSpellInfo(24705)] = "GRIM_VISAGE",
|
jcallahan@44
|
636 [_G.GetSpellInfo(32098)] = "HONOR_HOLD_FAVOR",
|
jcallahan@44
|
637 [_G.GetSpellInfo(39913)] = "NAZGRELS_FERVOR",
|
jcallahan@44
|
638 [_G.GetSpellInfo(39953)] = "SONG_OF_BATTLE",
|
jcallahan@44
|
639 [_G.GetSpellInfo(61849)] = "SPIRIT_OF_SHARING",
|
jcallahan@44
|
640 [_G.GetSpellInfo(32096)] = "THRALLMARS_FAVOR",
|
jcallahan@44
|
641 [_G.GetSpellInfo(39911)] = "TROLLBANES_COMMAND",
|
jcallahan@44
|
642 [_G.GetSpellInfo(95987)] = "UNBURDENED",
|
jcallahan@44
|
643 [_G.GetSpellInfo(100951)] = "WOW_ANNIVERSARY",
|
jcallahan@44
|
644 }
|
jcallahan@44
|
645
|
jcallahan@44
|
646
|
jcallahan@44
|
647 local FACTION_NAMES = {
|
jcallahan@44
|
648 CENARION_CIRCLE = _G.GetFactionInfoByID(609),
|
jcallahan@44
|
649 HONOR_HOLD = _G.GetFactionInfoByID(946),
|
jcallahan@44
|
650 THE_SHATAR = _G.GetFactionInfoByID(935),
|
jcallahan@44
|
651 THRALLMAR = _G.GetFactionInfoByID(947),
|
jcallahan@44
|
652 }
|
jcallahan@44
|
653
|
jcallahan@44
|
654
|
jcallahan@44
|
655 local MODIFIERS = {
|
jcallahan@44
|
656 CENARION_FAVOR = {
|
jcallahan@44
|
657 faction = FACTION_NAMES.CENARION_CIRCLE,
|
jcallahan@44
|
658 modifier = 0.25,
|
jcallahan@44
|
659 },
|
jcallahan@44
|
660 GRIM_VISAGE = {
|
jcallahan@44
|
661 modifier = 0.1,
|
jcallahan@44
|
662 },
|
jcallahan@44
|
663 HONOR_HOLD_FAVOR = {
|
jcallahan@44
|
664 faction = FACTION_NAMES.HONOR_HOLD,
|
jcallahan@44
|
665 modifier = 0.25,
|
jcallahan@44
|
666 },
|
jcallahan@44
|
667 NAZGRELS_FERVOR = {
|
jcallahan@44
|
668 faction = FACTION_NAMES.THRALLMAR,
|
jcallahan@44
|
669 modifier = 0.1,
|
jcallahan@44
|
670 },
|
jcallahan@44
|
671 SONG_OF_BATTLE = {
|
jcallahan@44
|
672 faction = FACTION_NAMES.THE_SHATAR,
|
jcallahan@44
|
673 modifier = 0.1,
|
jcallahan@44
|
674 },
|
jcallahan@44
|
675 SPIRIT_OF_SHARING = {
|
jcallahan@44
|
676 modifier = 0.1,
|
jcallahan@44
|
677 },
|
jcallahan@44
|
678 THRALLMARS_FAVOR = {
|
jcallahan@44
|
679 faction = FACTION_NAMES.THRALLMAR,
|
jcallahan@44
|
680 modifier = 0.25,
|
jcallahan@44
|
681 },
|
jcallahan@44
|
682 TROLLBANES_COMMAND = {
|
jcallahan@44
|
683 faction = FACTION_NAMES.HONOR_HOLD,
|
jcallahan@44
|
684 modifier = 0.1,
|
jcallahan@44
|
685 },
|
jcallahan@44
|
686 UNBURDENED = {
|
jcallahan@44
|
687 modifier = 0.1,
|
jcallahan@44
|
688 },
|
jcallahan@44
|
689 WOW_ANNIVERSARY = {
|
jcallahan@44
|
690 modifier = 0.08,
|
jcallahan@44
|
691 }
|
jcallahan@44
|
692 }
|
jcallahan@44
|
693
|
jcallahan@44
|
694
|
jcallahan@44
|
695 function WDP:COMBAT_TEXT_UPDATE(event, message_type, faction_name, amount)
|
jcallahan@65
|
696 if message_type ~= "FACTION" or not dead_npc_id then
|
jcallahan@44
|
697 return
|
jcallahan@44
|
698 end
|
jcallahan@44
|
699 UpdateFactionData()
|
jcallahan@44
|
700
|
jcallahan@46
|
701 if not faction_name or not faction_standings[faction_name] then
|
jcallahan@46
|
702 return
|
jcallahan@46
|
703 end
|
jcallahan@65
|
704 local npc = NPCEntry(dead_npc_id)
|
jcallahan@46
|
705
|
jcallahan@44
|
706 if not npc then
|
jcallahan@44
|
707 return
|
jcallahan@44
|
708 end
|
jcallahan@44
|
709 local modifier = 1
|
jcallahan@44
|
710
|
jcallahan@44
|
711 if _G.IsSpellKnown(DIPLOMACY_SPELL_ID) then
|
jcallahan@44
|
712 modifier = modifier + 0.1
|
jcallahan@44
|
713 end
|
jcallahan@44
|
714
|
jcallahan@44
|
715 if _G.IsSpellKnown(MR_POP_RANK2_SPELL_ID) then
|
jcallahan@44
|
716 modifier = modifier + 0.1
|
jcallahan@44
|
717 elseif _G.IsSpellKnown(MR_POP_RANK1_SPELL_ID) then
|
jcallahan@44
|
718 modifier = modifier + 0.05
|
jcallahan@44
|
719 end
|
jcallahan@44
|
720
|
jcallahan@44
|
721 for buff_name, buff_label in pairs(REP_BUFFS) do
|
jcallahan@44
|
722 if _G.UnitBuff("player", buff_name) then
|
jcallahan@44
|
723 local modded_faction = MODIFIERS[buff_label].faction
|
jcallahan@44
|
724
|
jcallahan@44
|
725 if not modded_faction or faction_name == modded_faction then
|
jcallahan@44
|
726 modifier = modifier + MODIFIERS[buff_label].modifier
|
jcallahan@44
|
727 end
|
jcallahan@44
|
728 end
|
jcallahan@44
|
729 end
|
jcallahan@65
|
730 npc.reputations = npc.reputations or {}
|
jcallahan@65
|
731 npc.reputations[("%s:%s"):format(faction_name, faction_standings[faction_name])] = math.floor(amount / modifier)
|
jcallahan@32
|
732 end
|
jcallahan@44
|
733 end -- do-block
|
jcallahan@18
|
734
|
jcallahan@18
|
735
|
jcallahan@42
|
736 function WDP:ITEM_TEXT_BEGIN()
|
jcallahan@42
|
737 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
|
jcallahan@42
|
738
|
jcallahan@42
|
739 if not unit_idnum or unit_type ~= private.UNIT_TYPES.OBJECT or _G.UnitName("npc") ~= _G.ItemTextGetItem() then
|
jcallahan@42
|
740 return
|
jcallahan@42
|
741 end
|
jcallahan@42
|
742 UpdateDBEntryLocation("objects", unit_idnum)
|
jcallahan@42
|
743 end
|
jcallahan@42
|
744
|
jcallahan@42
|
745
|
jcallahan@13
|
746 do
|
jcallahan@40
|
747 local RE_GOLD = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@40
|
748 local RE_SILVER = _G.SILVER_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@40
|
749 local RE_COPPER = _G.COPPER_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@13
|
750
|
jcallahan@13
|
751
|
jcallahan@13
|
752 local function _moneyMatch(money, re)
|
jcallahan@13
|
753 return money:match(re) or 0
|
jcallahan@1
|
754 end
|
jcallahan@1
|
755
|
jcallahan@0
|
756
|
jcallahan@13
|
757 local function _toCopper(money)
|
jcallahan@13
|
758 if not money then
|
jcallahan@13
|
759 return 0
|
jcallahan@13
|
760 end
|
jcallahan@40
|
761 return _moneyMatch(money, RE_GOLD) * 10000 + _moneyMatch(money, RE_SILVER) * 100 + _moneyMatch(money, RE_COPPER)
|
jcallahan@1
|
762 end
|
jcallahan@1
|
763
|
jcallahan@1
|
764
|
jcallahan@13
|
765 local LOOT_VERIFY_FUNCS = {
|
jcallahan@16
|
766 [AF.ITEM] = function()
|
jcallahan@16
|
767 local locked_item_id
|
jcallahan@16
|
768
|
jcallahan@16
|
769 for bag_index = 0, _G.NUM_BAG_FRAMES do
|
jcallahan@16
|
770 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
|
jcallahan@16
|
771 local _, _, is_locked = _G.GetContainerItemInfo(bag_index, slot_index)
|
jcallahan@16
|
772
|
jcallahan@16
|
773 if is_locked then
|
jcallahan@16
|
774 locked_item_id = ItemLinkToID(_G.GetContainerItemLink(bag_index, slot_index))
|
jcallahan@16
|
775 end
|
jcallahan@16
|
776 end
|
jcallahan@16
|
777 end
|
jcallahan@16
|
778
|
jcallahan@28
|
779 if not locked_item_id or (action_data.identifier and action_data.identifier ~= locked_item_id) then
|
jcallahan@16
|
780 return false
|
jcallahan@16
|
781 end
|
jcallahan@28
|
782 action_data.identifier = locked_item_id
|
jcallahan@16
|
783 return true
|
jcallahan@16
|
784 end,
|
jcallahan@13
|
785 [AF.NPC] = function()
|
jcallahan@17
|
786 if not _G.UnitExists("target") or _G.UnitIsFriend("player", "target") or _G.UnitIsPlayer("target") or _G.UnitPlayerControlled("target") then
|
jcallahan@15
|
787 return false
|
jcallahan@13
|
788 end
|
jcallahan@34
|
789 local unit_type, id_num = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@27
|
790 action_data.identifier = id_num
|
jcallahan@13
|
791 return true
|
jcallahan@13
|
792 end,
|
jcallahan@14
|
793 [AF.OBJECT] = true,
|
jcallahan@17
|
794 [AF.ZONE] = function()
|
jcallahan@38
|
795 return _G.IsFishingLoot()
|
jcallahan@17
|
796 end,
|
jcallahan@13
|
797 }
|
jcallahan@13
|
798
|
jcallahan@13
|
799
|
jcallahan@13
|
800 local LOOT_UPDATE_FUNCS = {
|
jcallahan@16
|
801 [AF.ITEM] = function()
|
jcallahan@28
|
802 GenericLootUpdate("items")
|
jcallahan@28
|
803 end,
|
jcallahan@28
|
804 [AF.NPC] = function()
|
jcallahan@29
|
805 local npc = NPCEntry(action_data.identifier)
|
jcallahan@28
|
806
|
jcallahan@28
|
807 if not npc then
|
jcallahan@28
|
808 return
|
jcallahan@28
|
809 end
|
jcallahan@29
|
810 local encounter_data = npc.encounter_data[InstanceDifficultyToken()]
|
jcallahan@25
|
811 local loot_type = action_data.label or "drops"
|
jcallahan@62
|
812 encounter_data.loot_counts = encounter_data.loot_counts or {}
|
jcallahan@62
|
813 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1
|
jcallahan@29
|
814 encounter_data[loot_type] = encounter_data[loot_type] or {}
|
jcallahan@16
|
815
|
jcallahan@17
|
816 for index = 1, #action_data.loot_list do
|
jcallahan@29
|
817 table.insert(encounter_data[loot_type], action_data.loot_list[index])
|
jcallahan@16
|
818 end
|
jcallahan@16
|
819 end,
|
jcallahan@13
|
820 [AF.OBJECT] = function()
|
jcallahan@28
|
821 GenericLootUpdate("objects", InstanceDifficultyToken())
|
jcallahan@17
|
822 end,
|
jcallahan@17
|
823 [AF.ZONE] = function()
|
jcallahan@41
|
824 local location_token = ("%s:%s:%s"):format(action_data.map_level, action_data.x, action_data.y)
|
jcallahan@41
|
825
|
jcallahan@41
|
826 -- This will start life as a boolean true.
|
jcallahan@41
|
827 if _G.type(action_data.zone_data[location_token]) ~= "table" then
|
jcallahan@41
|
828 action_data.zone_data[location_token] = {
|
jcallahan@41
|
829 drops = {}
|
jcallahan@41
|
830 }
|
jcallahan@41
|
831 end
|
jcallahan@41
|
832 local loot_count = ("%s_count"):format(action_data.label or "drops")
|
jcallahan@41
|
833 action_data.zone_data[location_token][loot_count] = (action_data.zone_data[location_token][loot_count] or 0) + 1
|
jcallahan@41
|
834
|
jcallahan@41
|
835 for index = 1, #action_data.loot_list do
|
jcallahan@41
|
836 table.insert(action_data.zone_data[location_token].drops, action_data.loot_list[index])
|
jcallahan@41
|
837 end
|
jcallahan@13
|
838 end,
|
jcallahan@13
|
839 }
|
jcallahan@13
|
840
|
jcallahan@13
|
841
|
jcallahan@13
|
842 function WDP:LOOT_OPENED()
|
jcallahan@18
|
843 if action_data.looting then
|
jcallahan@18
|
844 return
|
jcallahan@18
|
845 end
|
jcallahan@18
|
846
|
jcallahan@13
|
847 if not action_data.type then
|
jcallahan@13
|
848 action_data.type = AF.NPC
|
jcallahan@1
|
849 end
|
jcallahan@13
|
850 local verify_func = LOOT_VERIFY_FUNCS[action_data.type]
|
jcallahan@13
|
851 local update_func = LOOT_UPDATE_FUNCS[action_data.type]
|
jcallahan@13
|
852
|
jcallahan@14
|
853 if not verify_func or not update_func then
|
jcallahan@13
|
854 return
|
jcallahan@13
|
855 end
|
jcallahan@13
|
856
|
jcallahan@14
|
857 if _G.type(verify_func) == "function" and not verify_func() then
|
jcallahan@14
|
858 return
|
jcallahan@14
|
859 end
|
jcallahan@13
|
860 local loot_registry = {}
|
jcallahan@17
|
861 action_data.loot_list = {}
|
jcallahan@18
|
862 action_data.looting = true
|
jcallahan@13
|
863
|
jcallahan@55
|
864 for loot_slot = 1, _G.GetNumLootItems() do
|
jcallahan@55
|
865 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
|
jcallahan@55
|
866 local slot_type = _G.GetLootSlotType(loot_slot)
|
jcallahan@13
|
867
|
jcallahan@55
|
868 if slot_type == _G.LOOT_SLOT_ITEM then
|
jcallahan@55
|
869 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
|
jcallahan@55
|
870 loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity
|
jcallahan@55
|
871 elseif slot_type == _G.LOOT_SLOT_MONEY then
|
jcallahan@55
|
872 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
|
jcallahan@55
|
873 elseif slot_type == _G.LOOT_SLOT_CURRENCY then
|
jcallahan@55
|
874 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
|
jcallahan@13
|
875 end
|
jcallahan@13
|
876 end
|
jcallahan@13
|
877
|
jcallahan@13
|
878 for item_id, quantity in pairs(loot_registry) do
|
jcallahan@17
|
879 table.insert(action_data.loot_list, ("%d:%d"):format(item_id, quantity))
|
jcallahan@13
|
880 end
|
jcallahan@13
|
881 update_func()
|
jcallahan@1
|
882 end
|
jcallahan@13
|
883 end -- do-block
|
jcallahan@0
|
884
|
jcallahan@0
|
885
|
jcallahan@44
|
886 do
|
jcallahan@44
|
887 local POINT_MATCH_PATTERNS = {
|
jcallahan@44
|
888 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@44
|
889 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@44
|
890 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_5V5:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@44
|
891 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_BG:gsub("%%d", "(%%d+)")),
|
jcallahan@44
|
892 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3_BG:gsub("%%d", "(%%d+)")),
|
jcallahan@44
|
893 }
|
jcallahan@5
|
894
|
jcallahan@44
|
895 function WDP:UpdateMerchantItems(event)
|
jcallahan@44
|
896 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@4
|
897
|
jcallahan@44
|
898 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@44
|
899 return
|
jcallahan@44
|
900 end
|
jcallahan@55
|
901 local current_filters = _G.GetMerchantFilter()
|
jcallahan@44
|
902 local _, merchant_standing = UnitFactionStanding("target")
|
jcallahan@44
|
903 local merchant = NPCEntry(unit_idnum)
|
jcallahan@44
|
904 merchant.sells = merchant.sells or {}
|
jcallahan@5
|
905
|
jcallahan@57
|
906 _G.SetMerchantFilter(_G.LE_LOOT_FILTER_ALL)
|
jcallahan@57
|
907 _G.MerchantFrame_Update()
|
jcallahan@57
|
908
|
jcallahan@57
|
909 local num_items = _G.GetMerchantNumItems()
|
jcallahan@35
|
910
|
jcallahan@44
|
911 for item_index = 1, num_items do
|
jcallahan@44
|
912 local _, _, copper_price, stack_size, num_available, _, extended_cost = _G.GetMerchantItemInfo(item_index)
|
jcallahan@44
|
913 local item_id = ItemLinkToID(_G.GetMerchantItemLink(item_index))
|
jcallahan@5
|
914
|
jcallahan@44
|
915 if item_id and item_id > 0 then
|
jcallahan@44
|
916 local price_string = ActualCopperCost(copper_price, merchant_standing)
|
jcallahan@5
|
917
|
jcallahan@44
|
918 if extended_cost then
|
jcallahan@53
|
919 local battleground_rating = 0
|
jcallahan@53
|
920 local personal_rating = 0
|
jcallahan@53
|
921 local required_season_amount
|
jcallahan@5
|
922
|
jcallahan@44
|
923 DatamineTT:ClearLines()
|
jcallahan@44
|
924 DatamineTT:SetMerchantItem(item_index)
|
jcallahan@5
|
925
|
jcallahan@44
|
926 for line_index = 1, DatamineTT:NumLines() do
|
jcallahan@44
|
927 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@5
|
928
|
jcallahan@44
|
929 if not current_line then
|
jcallahan@44
|
930 break
|
jcallahan@44
|
931 end
|
jcallahan@53
|
932 local breakout
|
jcallahan@53
|
933 required_season_amount = current_line:GetText():match("Requires earning a total of (%d+)\n(.-) for the season.")
|
jcallahan@5
|
934
|
jcallahan@44
|
935 for match_index = 1, #POINT_MATCH_PATTERNS do
|
jcallahan@44
|
936 local match1, match2 = current_line:GetText():match(POINT_MATCH_PATTERNS[match_index])
|
jcallahan@53
|
937 personal_rating = personal_rating + (match1 or 0)
|
jcallahan@53
|
938 battleground_rating = battleground_rating + (match2 or 0)
|
jcallahan@5
|
939
|
jcallahan@44
|
940 if match1 or match2 then
|
jcallahan@44
|
941 break
|
jcallahan@44
|
942 end
|
jcallahan@44
|
943 end
|
jcallahan@5
|
944 end
|
jcallahan@44
|
945 local currency_list = {}
|
jcallahan@44
|
946 local item_count = _G.GetMerchantItemCostInfo(item_index)
|
jcallahan@50
|
947
|
jcallahan@50
|
948 -- Keeping this around in case Blizzard makes the two points diverge at some point.
|
jcallahan@53
|
949 -- price_string = ("%s:%s:%s:%s"):format(price_string, battleground_rating, personal_rating, required_season_amount or 0)
|
jcallahan@53
|
950 price_string = ("%s:%s:%s"):format(price_string, personal_rating, required_season_amount or 0)
|
jcallahan@5
|
951
|
jcallahan@44
|
952 for cost_index = 1, item_count do
|
jcallahan@44
|
953 local icon_texture, amount_required, currency_link = _G.GetMerchantItemCostItem(item_index, cost_index)
|
jcallahan@44
|
954 local currency_id = currency_link and ItemLinkToID(currency_link) or nil
|
jcallahan@44
|
955
|
jcallahan@44
|
956 if (not currency_id or currency_id < 1) and icon_texture then
|
jcallahan@44
|
957 currency_id = icon_texture:match("[^\\]+$"):lower()
|
jcallahan@44
|
958 end
|
jcallahan@44
|
959
|
jcallahan@44
|
960 if currency_id then
|
jcallahan@44
|
961 currency_list[#currency_list + 1] = ("(%s:%s)"):format(amount_required, currency_id)
|
jcallahan@44
|
962 end
|
jcallahan@44
|
963 end
|
jcallahan@44
|
964
|
jcallahan@44
|
965 for currency_index = 1, #currency_list do
|
jcallahan@44
|
966 price_string = ("%s:%s"):format(price_string, currency_list[currency_index])
|
jcallahan@5
|
967 end
|
jcallahan@5
|
968 end
|
jcallahan@61
|
969 merchant.sells[item_id] = ("%s:%s:[%s]"):format(num_available, stack_size, price_string)
|
jcallahan@44
|
970 end
|
jcallahan@44
|
971 end
|
jcallahan@5
|
972
|
jcallahan@44
|
973 if _G.CanMerchantRepair() then
|
jcallahan@44
|
974 merchant.can_repair = true
|
jcallahan@5
|
975 end
|
jcallahan@57
|
976 _G.SetMerchantFilter(current_filters)
|
jcallahan@57
|
977 _G.MerchantFrame_Update()
|
jcallahan@4
|
978 end
|
jcallahan@44
|
979 end -- do-block
|
jcallahan@4
|
980
|
jcallahan@25
|
981 function WDP:PET_BAR_UPDATE()
|
jcallahan@25
|
982 if not action_data.label or not action_data.label == "mind_control" then
|
jcallahan@25
|
983 return
|
jcallahan@25
|
984 end
|
jcallahan@34
|
985 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("pet"))
|
jcallahan@25
|
986
|
jcallahan@25
|
987 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@25
|
988 return
|
jcallahan@25
|
989 end
|
jcallahan@29
|
990 NPCEntry(unit_idnum).mind_control = true
|
jcallahan@25
|
991 table.wipe(action_data)
|
jcallahan@25
|
992 end
|
jcallahan@25
|
993
|
jcallahan@25
|
994
|
jcallahan@18
|
995 do
|
jcallahan@18
|
996 local GENDER_NAMES = {
|
jcallahan@18
|
997 "UNKNOWN",
|
jcallahan@18
|
998 "MALE",
|
jcallahan@18
|
999 "FEMALE",
|
jcallahan@18
|
1000 }
|
jcallahan@2
|
1001
|
jcallahan@2
|
1002
|
jcallahan@18
|
1003 local REACTION_NAMES = {
|
jcallahan@18
|
1004 "HATED",
|
jcallahan@18
|
1005 "HOSTILE",
|
jcallahan@18
|
1006 "UNFRIENDLY",
|
jcallahan@18
|
1007 "NEUTRAL",
|
jcallahan@18
|
1008 "FRIENDLY",
|
jcallahan@18
|
1009 "HONORED",
|
jcallahan@18
|
1010 "REVERED",
|
jcallahan@18
|
1011 "EXALTED",
|
jcallahan@18
|
1012 }
|
jcallahan@2
|
1013
|
jcallahan@2
|
1014
|
jcallahan@18
|
1015 local POWER_TYPE_NAMES = {
|
jcallahan@18
|
1016 ["0"] = "MANA",
|
jcallahan@18
|
1017 ["1"] = "RAGE",
|
jcallahan@18
|
1018 ["2"] = "FOCUS",
|
jcallahan@18
|
1019 ["3"] = "ENERGY",
|
jcallahan@18
|
1020 ["6"] = "RUNIC_POWER",
|
jcallahan@18
|
1021 }
|
jcallahan@2
|
1022
|
jcallahan@2
|
1023
|
jcallahan@18
|
1024 function WDP:PLAYER_TARGET_CHANGED()
|
jcallahan@40
|
1025 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or currently_drunk then
|
jcallahan@18
|
1026 return
|
jcallahan@18
|
1027 end
|
jcallahan@34
|
1028 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@2
|
1029
|
jcallahan@18
|
1030 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@18
|
1031 return
|
jcallahan@18
|
1032 end
|
jcallahan@29
|
1033 local npc = NPCEntry(unit_idnum)
|
jcallahan@18
|
1034 local _, class_token = _G.UnitClass("target")
|
jcallahan@18
|
1035 npc.class = class_token
|
jcallahan@39
|
1036 npc.faction = UnitFactionStanding("target")
|
jcallahan@26
|
1037 npc.genders = npc.genders or {}
|
jcallahan@26
|
1038 npc.genders[GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"] = true
|
jcallahan@18
|
1039 npc.is_pvp = _G.UnitIsPVP("target") and true or nil
|
jcallahan@18
|
1040 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")])
|
jcallahan@2
|
1041
|
jcallahan@30
|
1042 local encounter_data = npc.encounter_data[InstanceDifficultyToken()].stats
|
jcallahan@18
|
1043 local npc_level = ("level_%d"):format(_G.UnitLevel("target"))
|
jcallahan@3
|
1044
|
jcallahan@28
|
1045 if not encounter_data[npc_level] then
|
jcallahan@28
|
1046 encounter_data[npc_level] = {
|
jcallahan@18
|
1047 max_health = _G.UnitHealthMax("target"),
|
jcallahan@18
|
1048 }
|
jcallahan@3
|
1049
|
jcallahan@18
|
1050 local max_power = _G.UnitManaMax("target")
|
jcallahan@18
|
1051
|
jcallahan@18
|
1052 if max_power > 0 then
|
jcallahan@18
|
1053 local power_type = _G.UnitPowerType("target")
|
jcallahan@28
|
1054 encounter_data[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power)
|
jcallahan@18
|
1055 end
|
jcallahan@3
|
1056 end
|
jcallahan@21
|
1057 table.wipe(action_data)
|
jcallahan@21
|
1058 action_data.type = AF.NPC
|
jcallahan@27
|
1059 action_data.identifier = unit_idnum
|
jcallahan@21
|
1060 action_data.npc_level = npc_level
|
jcallahan@31
|
1061
|
jcallahan@31
|
1062 self:UpdateTargetLocation()
|
jcallahan@2
|
1063 end
|
jcallahan@18
|
1064 end -- do-block
|
jcallahan@2
|
1065
|
jcallahan@12
|
1066 do
|
jcallahan@12
|
1067 local function UpdateQuestJuncture(point)
|
jcallahan@12
|
1068 local unit_name = _G.UnitName("questnpc")
|
jcallahan@9
|
1069
|
jcallahan@12
|
1070 if not unit_name then
|
jcallahan@12
|
1071 return
|
jcallahan@12
|
1072 end
|
jcallahan@34
|
1073 local unit_type, unit_id = ParseGUID(_G.UnitGUID("questnpc"))
|
jcallahan@9
|
1074
|
jcallahan@12
|
1075 if unit_type == private.UNIT_TYPES.OBJECT then
|
jcallahan@38
|
1076 UpdateDBEntryLocation("objects", unit_id)
|
jcallahan@12
|
1077 end
|
jcallahan@19
|
1078 local quest = DBEntry("quests", _G.GetQuestID())
|
jcallahan@12
|
1079 quest[point] = quest[point] or {}
|
jcallahan@12
|
1080 quest[point][("%s:%d"):format(private.UNIT_TYPE_NAMES[unit_type + 1], unit_id)] = true
|
jcallahan@24
|
1081
|
jcallahan@24
|
1082 return quest
|
jcallahan@12
|
1083 end
|
jcallahan@10
|
1084
|
jcallahan@12
|
1085
|
jcallahan@12
|
1086 function WDP:QUEST_COMPLETE()
|
jcallahan@12
|
1087 UpdateQuestJuncture("end")
|
jcallahan@10
|
1088 end
|
jcallahan@10
|
1089
|
jcallahan@12
|
1090
|
jcallahan@12
|
1091 function WDP:QUEST_DETAIL()
|
jcallahan@24
|
1092 local quest = UpdateQuestJuncture("begin")
|
jcallahan@24
|
1093
|
jcallahan@46
|
1094 if not quest then
|
jcallahan@46
|
1095 return
|
jcallahan@46
|
1096 end
|
jcallahan@24
|
1097 quest.classes = quest.classes or {}
|
jcallahan@27
|
1098 quest.classes[PLAYER_CLASS] = true
|
jcallahan@24
|
1099
|
jcallahan@24
|
1100 local _, race = _G.UnitRace("player")
|
jcallahan@24
|
1101 quest.races = quest.races or {}
|
jcallahan@24
|
1102 quest.races[race] = true
|
jcallahan@10
|
1103 end
|
jcallahan@12
|
1104 end -- do-block
|
jcallahan@9
|
1105
|
jcallahan@9
|
1106
|
jcallahan@4
|
1107 function WDP:QUEST_LOG_UPDATE()
|
jcallahan@38
|
1108 local selected_quest = _G.GetQuestLogSelection() -- Save current selection to be restored when we're done.
|
jcallahan@36
|
1109 local entry_index, processed_quests = 1, 0
|
jcallahan@36
|
1110 local _, num_quests = _G.GetNumQuestLogEntries()
|
jcallahan@36
|
1111
|
jcallahan@36
|
1112 while processed_quests <= num_quests do
|
jcallahan@36
|
1113 local _, _, _, _, is_header, _, _, _, quest_id = _G.GetQuestLogTitle(entry_index)
|
jcallahan@36
|
1114
|
jcallahan@36
|
1115 if not is_header then
|
jcallahan@36
|
1116 _G.SelectQuestLogEntry(entry_index);
|
jcallahan@36
|
1117
|
jcallahan@36
|
1118 local quest = DBEntry("quests", quest_id)
|
jcallahan@36
|
1119 quest.timer = _G.GetQuestLogTimeLeft()
|
jcallahan@37
|
1120 quest.can_share = _G.GetQuestLogPushable() and true or nil
|
jcallahan@36
|
1121 processed_quests = processed_quests + 1
|
jcallahan@36
|
1122 end
|
jcallahan@36
|
1123 entry_index = entry_index + 1
|
jcallahan@36
|
1124 end
|
jcallahan@36
|
1125 _G.SelectQuestLogEntry(selected_quest)
|
jcallahan@4
|
1126 self:UnregisterEvent("QUEST_LOG_UPDATE")
|
jcallahan@4
|
1127 end
|
jcallahan@4
|
1128
|
jcallahan@4
|
1129
|
jcallahan@4
|
1130 function WDP:UNIT_QUEST_LOG_CHANGED(event, unit_id)
|
jcallahan@4
|
1131 if unit_id ~= "player" then
|
jcallahan@4
|
1132 return
|
jcallahan@4
|
1133 end
|
jcallahan@4
|
1134 self:RegisterEvent("QUEST_LOG_UPDATE")
|
jcallahan@4
|
1135 end
|
jcallahan@4
|
1136
|
jcallahan@4
|
1137
|
jcallahan@27
|
1138 function WDP:TRAINER_SHOW()
|
jcallahan@27
|
1139 if not _G.IsTradeskillTrainer() then
|
jcallahan@27
|
1140 return
|
jcallahan@27
|
1141 end
|
jcallahan@34
|
1142 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@29
|
1143 local npc = NPCEntry(unit_idnum)
|
jcallahan@58
|
1144
|
jcallahan@58
|
1145 if not npc then
|
jcallahan@58
|
1146 return
|
jcallahan@58
|
1147 end
|
jcallahan@27
|
1148 npc.teaches = npc.teaches or {}
|
jcallahan@27
|
1149
|
jcallahan@27
|
1150 -- Get the initial trainer filters
|
jcallahan@27
|
1151 local available = _G.GetTrainerServiceTypeFilter("available")
|
jcallahan@27
|
1152 local unavailable = _G.GetTrainerServiceTypeFilter("unavailable")
|
jcallahan@27
|
1153 local used = _G.GetTrainerServiceTypeFilter("used")
|
jcallahan@27
|
1154
|
jcallahan@27
|
1155 -- Clear the trainer filters
|
jcallahan@27
|
1156 _G.SetTrainerServiceTypeFilter("available", 1)
|
jcallahan@27
|
1157 _G.SetTrainerServiceTypeFilter("unavailable", 1)
|
jcallahan@27
|
1158 _G.SetTrainerServiceTypeFilter("used", 1)
|
jcallahan@27
|
1159
|
jcallahan@27
|
1160 for index = 1, _G.GetNumTrainerServices(), 1 do
|
jcallahan@27
|
1161 local spell_name, rank_name, _, _, required_level = _G.GetTrainerServiceInfo(index)
|
jcallahan@27
|
1162
|
jcallahan@27
|
1163 if spell_name then
|
jcallahan@27
|
1164 DatamineTT:ClearLines()
|
jcallahan@27
|
1165 DatamineTT:SetTrainerService(index)
|
jcallahan@27
|
1166
|
jcallahan@27
|
1167 local _, _, spell_id = DatamineTT:GetSpell()
|
jcallahan@27
|
1168
|
jcallahan@43
|
1169 if spell_id then
|
jcallahan@43
|
1170 local profession, min_skill = _G.GetTrainerServiceSkillReq(index)
|
jcallahan@43
|
1171 profession = profession or "General"
|
jcallahan@43
|
1172
|
jcallahan@43
|
1173 local class_professions = npc.teaches[PLAYER_CLASS]
|
jcallahan@43
|
1174 if not class_professions then
|
jcallahan@43
|
1175 npc.teaches[PLAYER_CLASS] = {}
|
jcallahan@43
|
1176 class_professions = npc.teaches[PLAYER_CLASS]
|
jcallahan@43
|
1177 end
|
jcallahan@43
|
1178
|
jcallahan@43
|
1179 local profession_skills = class_professions[profession]
|
jcallahan@43
|
1180 if not profession_skills then
|
jcallahan@43
|
1181 class_professions[profession] = {}
|
jcallahan@43
|
1182 profession_skills = class_professions[profession]
|
jcallahan@43
|
1183 end
|
jcallahan@43
|
1184 profession_skills[spell_id] = ("%d:%d"):format(required_level, min_skill)
|
jcallahan@27
|
1185 end
|
jcallahan@27
|
1186 end
|
jcallahan@27
|
1187 end
|
jcallahan@27
|
1188
|
jcallahan@27
|
1189 -- Reset the filters to what they were before
|
jcallahan@27
|
1190 _G.SetTrainerServiceTypeFilter("available", available or 0)
|
jcallahan@27
|
1191 _G.SetTrainerServiceTypeFilter("unavailable", unavailable or 0)
|
jcallahan@27
|
1192 _G.SetTrainerServiceTypeFilter("used", used or 0)
|
jcallahan@27
|
1193 end
|
jcallahan@27
|
1194
|
jcallahan@27
|
1195
|
jcallahan@1
|
1196 function WDP:UNIT_SPELLCAST_SENT(event_name, unit_id, spell_name, spell_rank, target_name, spell_line)
|
jcallahan@1
|
1197 if private.tracked_line or unit_id ~= "player" then
|
jcallahan@1
|
1198 return
|
jcallahan@1
|
1199 end
|
jcallahan@1
|
1200 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name]
|
jcallahan@1
|
1201
|
jcallahan@1
|
1202 if not spell_label then
|
jcallahan@1
|
1203 return
|
jcallahan@1
|
1204 end
|
jcallahan@18
|
1205 table.wipe(action_data)
|
jcallahan@1
|
1206
|
jcallahan@1
|
1207 local tt_item_name, tt_item_link = _G.GameTooltip:GetItem()
|
jcallahan@1
|
1208 local tt_unit_name, tt_unit_id = _G.GameTooltip:GetUnit()
|
jcallahan@1
|
1209
|
jcallahan@1
|
1210 if not tt_unit_name and _G.UnitName("target") == target_name then
|
jcallahan@1
|
1211 tt_unit_name = target_name
|
jcallahan@1
|
1212 tt_unit_id = "target"
|
jcallahan@1
|
1213 end
|
jcallahan@1
|
1214 local spell_flags = private.SPELL_FLAGS_BY_LABEL[spell_label]
|
jcallahan@28
|
1215 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData()
|
jcallahan@28
|
1216
|
jcallahan@28
|
1217 action_data.instance_token = instance_token
|
jcallahan@28
|
1218 action_data.map_level = map_level
|
jcallahan@28
|
1219 action_data.x = x
|
jcallahan@28
|
1220 action_data.y = y
|
jcallahan@28
|
1221 action_data.zone = ("%s:%d"):format(zone_name, area_id)
|
jcallahan@1
|
1222
|
jcallahan@16
|
1223 if tt_unit_name and not tt_item_name then
|
jcallahan@16
|
1224 if bit.band(spell_flags, AF.NPC) == AF.NPC then
|
jcallahan@16
|
1225 if not tt_unit_id or tt_unit_name ~= target_name then
|
jcallahan@16
|
1226 return
|
jcallahan@16
|
1227 end
|
jcallahan@16
|
1228 action_data.type = AF.NPC
|
jcallahan@25
|
1229 action_data.label = spell_label:lower()
|
jcallahan@25
|
1230 action_data.unit_name = tt_unit_name
|
jcallahan@16
|
1231 end
|
jcallahan@16
|
1232 elseif bit.band(spell_flags, AF.ITEM) == AF.ITEM then
|
jcallahan@16
|
1233 action_data.type = AF.ITEM
|
jcallahan@25
|
1234 action_data.label = spell_label:lower()
|
jcallahan@16
|
1235
|
jcallahan@16
|
1236 if tt_item_name and tt_item_name == target_name then
|
jcallahan@28
|
1237 action_data.identifier = ItemLinkToID(tt_item_link)
|
jcallahan@16
|
1238 elseif target_name and target_name ~= "" then
|
jcallahan@16
|
1239 local _, target_item_link = _G.GetItemInfo(target_name)
|
jcallahan@28
|
1240 action_data.identifier = ItemLinkToID(target_item_link)
|
jcallahan@16
|
1241 end
|
jcallahan@16
|
1242 elseif not tt_item_name and not tt_unit_name then
|
jcallahan@17
|
1243 action_data.name = target_name
|
jcallahan@17
|
1244
|
jcallahan@1
|
1245 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then
|
jcallahan@17
|
1246 if target_name == "" then
|
jcallahan@17
|
1247 return
|
jcallahan@17
|
1248 end
|
jcallahan@11
|
1249 local identifier = ("%s:%s"):format(spell_label, target_name)
|
jcallahan@38
|
1250 UpdateDBEntryLocation("objects", identifier)
|
jcallahan@11
|
1251
|
jcallahan@1
|
1252 action_data.type = AF.OBJECT
|
jcallahan@11
|
1253 action_data.identifier = identifier
|
jcallahan@1
|
1254 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then
|
jcallahan@38
|
1255 local identifier = ("%s:%s"):format(spell_label, _G["GameTooltipTextLeft1"]:GetText() or "NONE") -- Possible fishing pool name.
|
jcallahan@52
|
1256 action_data.zone_data = UpdateDBEntryLocation("zones", identifier)
|
jcallahan@17
|
1257 action_data.type = AF.ZONE
|
jcallahan@38
|
1258 action_data.identifier = identifier
|
jcallahan@48
|
1259 action_data.spell_label = spell_label
|
jcallahan@1
|
1260 end
|
jcallahan@1
|
1261 end
|
jcallahan@1
|
1262 private.tracked_line = spell_line
|
jcallahan@0
|
1263 end
|
jcallahan@0
|
1264
|
jcallahan@0
|
1265
|
jcallahan@1
|
1266 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
|
jcallahan@1
|
1267 if unit_id ~= "player" then
|
jcallahan@1
|
1268 return
|
jcallahan@1
|
1269 end
|
jcallahan@1
|
1270 private.tracked_line = nil
|
jcallahan@0
|
1271 end
|
jcallahan@0
|
1272
|
jcallahan@1
|
1273 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
|
jcallahan@1
|
1274 if unit_id ~= "player" then
|
jcallahan@1
|
1275 return
|
jcallahan@1
|
1276 end
|
jcallahan@0
|
1277
|
jcallahan@1
|
1278 if private.tracked_line == spell_line then
|
jcallahan@1
|
1279 private.tracked_line = nil
|
jcallahan@1
|
1280 end
|
jcallahan@0
|
1281 end
|