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