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