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