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@78
|
13 local select = _G.select
|
jcallahan@78
|
14
|
jcallahan@0
|
15
|
jcallahan@0
|
16 -----------------------------------------------------------------------
|
jcallahan@0
|
17 -- AddOn namespace.
|
jcallahan@0
|
18 -----------------------------------------------------------------------
|
jcallahan@0
|
19 local ADDON_NAME, private = ...
|
jcallahan@0
|
20
|
jcallahan@0
|
21 local LibStub = _G.LibStub
|
jcallahan@0
|
22 local WDP = LibStub("AceAddon-3.0"):NewAddon(ADDON_NAME, "AceEvent-3.0", "AceTimer-3.0")
|
jcallahan@0
|
23
|
jcallahan@48
|
24 local deformat = LibStub("LibDeformat-3.0")
|
jcallahan@48
|
25
|
jcallahan@4
|
26 local DatamineTT = _G.CreateFrame("GameTooltip", "WDPDatamineTT", _G.UIParent, "GameTooltipTemplate")
|
jcallahan@5
|
27 DatamineTT:SetOwner(_G.WorldFrame, "ANCHOR_NONE")
|
jcallahan@5
|
28
|
jcallahan@0
|
29
|
jcallahan@0
|
30 -----------------------------------------------------------------------
|
jcallahan@0
|
31 -- Local constants.
|
jcallahan@0
|
32 -----------------------------------------------------------------------
|
jcallahan@74
|
33 local DB_VERSION = 4
|
jcallahan@63
|
34
|
jcallahan@92
|
35
|
jcallahan@0
|
36 local DATABASE_DEFAULTS = {
|
jcallahan@0
|
37 global = {
|
jcallahan@0
|
38 items = {},
|
jcallahan@0
|
39 npcs = {},
|
jcallahan@0
|
40 objects = {},
|
jcallahan@0
|
41 quests = {},
|
jcallahan@17
|
42 zones = {},
|
jcallahan@0
|
43 }
|
jcallahan@0
|
44 }
|
jcallahan@0
|
45
|
jcallahan@0
|
46
|
jcallahan@1
|
47 local EVENT_MAPPING = {
|
jcallahan@90
|
48 AUCTION_HOUSE_SHOW = true,
|
jcallahan@90
|
49 BANKFRAME_OPENED = true,
|
jcallahan@90
|
50 BATTLEFIELDS_SHOW = true,
|
jcallahan@56
|
51 BLACK_MARKET_ITEM_UPDATE = true,
|
jcallahan@48
|
52 CHAT_MSG_LOOT = true,
|
jcallahan@95
|
53 CHAT_MSG_MONSTER_SAY = "RecordQuote",
|
jcallahan@95
|
54 CHAT_MSG_MONSTER_WHISPER = "RecordQuote",
|
jcallahan@95
|
55 CHAT_MSG_MONSTER_YELL = "RecordQuote",
|
jcallahan@40
|
56 CHAT_MSG_SYSTEM = true,
|
jcallahan@23
|
57 COMBAT_LOG_EVENT_UNFILTERED = true,
|
jcallahan@18
|
58 COMBAT_TEXT_UPDATE = true,
|
jcallahan@90
|
59 FORGE_MASTER_OPENED = true,
|
jcallahan@90
|
60 GOSSIP_SHOW = true,
|
jcallahan@93
|
61 GUILDBANKFRAME_OPENED = true,
|
jcallahan@42
|
62 ITEM_TEXT_BEGIN = true,
|
jcallahan@1
|
63 LOOT_OPENED = true,
|
jcallahan@89
|
64 MAIL_SHOW = true,
|
jcallahan@7
|
65 MERCHANT_SHOW = "UpdateMerchantItems",
|
jcallahan@61
|
66 MERCHANT_UPDATE = "UpdateMerchantItems",
|
jcallahan@25
|
67 PET_BAR_UPDATE = true,
|
jcallahan@2
|
68 PLAYER_TARGET_CHANGED = true,
|
jcallahan@9
|
69 QUEST_COMPLETE = true,
|
jcallahan@9
|
70 QUEST_DETAIL = true,
|
jcallahan@9
|
71 QUEST_LOG_UPDATE = true,
|
jcallahan@97
|
72 QUEST_PROGRESS = true,
|
jcallahan@88
|
73 TAXIMAP_OPENED = true,
|
jcallahan@92
|
74 TRADE_SKILL_SHOW = true,
|
jcallahan@27
|
75 TRAINER_SHOW = true,
|
jcallahan@90
|
76 TRANSMOGRIFY_OPEN = true,
|
jcallahan@4
|
77 UNIT_QUEST_LOG_CHANGED = true,
|
jcallahan@1
|
78 UNIT_SPELLCAST_FAILED = "HandleSpellFailure",
|
jcallahan@1
|
79 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure",
|
jcallahan@1
|
80 UNIT_SPELLCAST_INTERRUPTED = "HandleSpellFailure",
|
jcallahan@1
|
81 UNIT_SPELLCAST_SENT = true,
|
jcallahan@1
|
82 UNIT_SPELLCAST_SUCCEEDED = true,
|
jcallahan@90
|
83 VOID_STORAGE_OPEN = true,
|
jcallahan@0
|
84 }
|
jcallahan@0
|
85
|
jcallahan@4
|
86
|
jcallahan@92
|
87 local OBJECT_ID_ANVIL = 192628
|
jcallahan@92
|
88 local OBJECT_ID_FORGE = 1685
|
jcallahan@92
|
89
|
jcallahan@92
|
90
|
jcallahan@1
|
91 local AF = private.ACTION_TYPE_FLAGS
|
jcallahan@0
|
92
|
jcallahan@4
|
93
|
jcallahan@27
|
94 local PLAYER_CLASS = _G.select(2, _G.UnitClass("player"))
|
jcallahan@100
|
95 local PLAYER_FACTION = _G.UnitFactionGroup("player")
|
jcallahan@34
|
96 local PLAYER_GUID = _G.UnitGUID("player")
|
jcallahan@95
|
97 local PLAYER_NAME = _G.UnitName("player")
|
jcallahan@39
|
98 local PLAYER_RACE = _G.select(2, _G.UnitRace("player"))
|
jcallahan@27
|
99
|
jcallahan@95
|
100
|
jcallahan@0
|
101 -----------------------------------------------------------------------
|
jcallahan@0
|
102 -- Local variables.
|
jcallahan@0
|
103 -----------------------------------------------------------------------
|
jcallahan@92
|
104 local anvil_spell_ids = {}
|
jcallahan@92
|
105 local action_data = {}
|
jcallahan@92
|
106 local currently_drunk
|
jcallahan@0
|
107 local db
|
jcallahan@0
|
108 local durability_timer_handle
|
jcallahan@92
|
109 local faction_standings = {}
|
jcallahan@92
|
110 local forge_spell_ids = {}
|
jcallahan@95
|
111 local languages_known = {}
|
jcallahan@95
|
112 local name_to_id_map = {}
|
jcallahan@92
|
113 local reputation_npc_id
|
jcallahan@2
|
114 local target_location_timer_handle
|
jcallahan@86
|
115 local current_target_id
|
jcallahan@1
|
116
|
jcallahan@92
|
117
|
jcallahan@1
|
118 -----------------------------------------------------------------------
|
jcallahan@1
|
119 -- Helper Functions.
|
jcallahan@1
|
120 -----------------------------------------------------------------------
|
jcallahan@39
|
121 local ActualCopperCost
|
jcallahan@39
|
122 do
|
jcallahan@39
|
123 local BARTERING_SPELL_ID = 83964
|
jcallahan@39
|
124
|
jcallahan@39
|
125 local STANDING_DISCOUNTS = {
|
jcallahan@39
|
126 HATED = 0,
|
jcallahan@39
|
127 HOSTILE = 0,
|
jcallahan@39
|
128 UNFRIENDLY = 0,
|
jcallahan@39
|
129 NEUTRAL = 0,
|
jcallahan@39
|
130 FRIENDLY = 0.05,
|
jcallahan@39
|
131 HONORED = 0.1,
|
jcallahan@39
|
132 REVERED = 0.15,
|
jcallahan@39
|
133 EXALTED = 0.2,
|
jcallahan@39
|
134 }
|
jcallahan@39
|
135
|
jcallahan@39
|
136
|
jcallahan@39
|
137 function ActualCopperCost(copper_cost, rep_standing)
|
jcallahan@39
|
138 if not copper_cost or copper_cost == 0 then
|
jcallahan@39
|
139 return 0
|
jcallahan@39
|
140 end
|
jcallahan@39
|
141 local modifier = 1
|
jcallahan@39
|
142
|
jcallahan@39
|
143 if _G.IsSpellKnown(BARTERING_SPELL_ID) then
|
jcallahan@39
|
144 modifier = modifier - 0.1
|
jcallahan@39
|
145 end
|
jcallahan@39
|
146
|
jcallahan@39
|
147 if rep_standing then
|
jcallahan@39
|
148 if PLAYER_RACE == "Goblin" then
|
jcallahan@39
|
149 modifier = modifier - STANDING_DISCOUNTS["EXALTED"]
|
jcallahan@39
|
150 elseif STANDING_DISCOUNTS[rep_standing] then
|
jcallahan@39
|
151 modifier = modifier - STANDING_DISCOUNTS[rep_standing]
|
jcallahan@39
|
152 end
|
jcallahan@39
|
153 end
|
jcallahan@39
|
154 return math.floor(copper_cost / modifier)
|
jcallahan@39
|
155 end
|
jcallahan@39
|
156 end -- do-block
|
jcallahan@39
|
157
|
jcallahan@39
|
158
|
jcallahan@29
|
159 local function InstanceDifficultyToken()
|
jcallahan@29
|
160 local _, instance_type, instance_difficulty, difficulty_name, _, _, is_dynamic = _G.GetInstanceInfo()
|
jcallahan@59
|
161 if not difficulty_name or difficulty_name == "" then
|
jcallahan@29
|
162 difficulty_name = "NONE"
|
jcallahan@29
|
163 end
|
jcallahan@59
|
164
|
jcallahan@59
|
165 if not instance_type or instance_type == "" then
|
jcallahan@59
|
166 instance_type = "NONE"
|
jcallahan@59
|
167 end
|
jcallahan@29
|
168 return ("%s:%s:%s"):format(instance_type:upper(), difficulty_name:upper():gsub(" ", "_"), _G.tostring(is_dynamic))
|
jcallahan@29
|
169 end
|
jcallahan@29
|
170
|
jcallahan@29
|
171
|
jcallahan@19
|
172 local function DBEntry(data_type, unit_id)
|
jcallahan@19
|
173 if not data_type or not unit_id then
|
jcallahan@6
|
174 return
|
jcallahan@6
|
175 end
|
jcallahan@19
|
176 local unit = db[data_type][unit_id]
|
jcallahan@6
|
177
|
jcallahan@10
|
178 if not unit then
|
jcallahan@19
|
179 db[data_type][unit_id] = {}
|
jcallahan@19
|
180 unit = db[data_type][unit_id]
|
jcallahan@6
|
181 end
|
jcallahan@10
|
182 return unit
|
jcallahan@6
|
183 end
|
jcallahan@6
|
184
|
jcallahan@6
|
185
|
jcallahan@29
|
186 local function NPCEntry(identifier)
|
jcallahan@29
|
187 local npc = DBEntry("npcs", identifier)
|
jcallahan@29
|
188
|
jcallahan@29
|
189 if not npc then
|
jcallahan@29
|
190 return
|
jcallahan@22
|
191 end
|
jcallahan@29
|
192 local instance_token = InstanceDifficultyToken()
|
jcallahan@29
|
193 npc.encounter_data = npc.encounter_data or {}
|
jcallahan@29
|
194 npc.encounter_data[instance_token] = npc.encounter_data[instance_token] or {}
|
jcallahan@30
|
195 npc.encounter_data[instance_token].stats = npc.encounter_data[instance_token].stats or {}
|
jcallahan@29
|
196 return npc
|
jcallahan@22
|
197 end
|
jcallahan@22
|
198
|
jcallahan@22
|
199
|
jcallahan@1
|
200 local function CurrentLocationData()
|
jcallahan@1
|
201 local map_level = _G.GetCurrentMapDungeonLevel() or 0
|
jcallahan@1
|
202 local x, y = _G.GetPlayerMapPosition("player")
|
jcallahan@1
|
203
|
jcallahan@1
|
204 x = x or 0
|
jcallahan@1
|
205 y = y or 0
|
jcallahan@1
|
206
|
jcallahan@1
|
207 if x == 0 and y == 0 then
|
jcallahan@1
|
208 for level_index = 1, _G.GetNumDungeonMapLevels() do
|
jcallahan@1
|
209 _G.SetDungeonMapLevel(level_index)
|
jcallahan@1
|
210 x, y = _G.GetPlayerMapPosition("player")
|
jcallahan@1
|
211
|
jcallahan@1
|
212 if x and y and (x > 0 or y > 0) then
|
jcallahan@1
|
213 _G.SetDungeonMapLevel(map_level)
|
jcallahan@1
|
214 map_level = level_index
|
jcallahan@1
|
215 break
|
jcallahan@1
|
216 end
|
jcallahan@1
|
217 end
|
jcallahan@1
|
218 end
|
jcallahan@1
|
219
|
jcallahan@1
|
220 if _G.DungeonUsesTerrainMap() then
|
jcallahan@1
|
221 map_level = map_level - 1
|
jcallahan@1
|
222 end
|
jcallahan@31
|
223 local x = _G.floor(x * 1000)
|
jcallahan@31
|
224 local y = _G.floor(y * 1000)
|
jcallahan@28
|
225
|
jcallahan@31
|
226 if x % 2 ~= 0 then
|
jcallahan@31
|
227 x = x + 1
|
jcallahan@28
|
228 end
|
jcallahan@28
|
229
|
jcallahan@31
|
230 if y % 2 ~= 0 then
|
jcallahan@31
|
231 y = y + 1
|
jcallahan@28
|
232 end
|
jcallahan@31
|
233 return _G.GetRealZoneText(), _G.GetCurrentMapAreaID(), x, y, map_level, InstanceDifficultyToken()
|
jcallahan@1
|
234 end
|
jcallahan@1
|
235
|
jcallahan@1
|
236
|
jcallahan@1
|
237 local function ItemLinkToID(item_link)
|
jcallahan@1
|
238 if not item_link then
|
jcallahan@1
|
239 return
|
jcallahan@1
|
240 end
|
jcallahan@7
|
241 return tonumber(item_link:match("item:(%d+)"))
|
jcallahan@1
|
242 end
|
jcallahan@0
|
243
|
jcallahan@4
|
244
|
jcallahan@34
|
245 local ParseGUID
|
jcallahan@4
|
246 do
|
jcallahan@4
|
247 local UNIT_TYPE_BITMASK = 0x007
|
jcallahan@4
|
248
|
jcallahan@34
|
249 function ParseGUID(guid)
|
jcallahan@5
|
250 if not guid then
|
jcallahan@5
|
251 return
|
jcallahan@5
|
252 end
|
jcallahan@4
|
253 local types = private.UNIT_TYPES
|
jcallahan@4
|
254 local unit_type = _G.bit.band(tonumber(guid:sub(1, 5)), UNIT_TYPE_BITMASK)
|
jcallahan@4
|
255
|
jcallahan@10
|
256 if unit_type ~= types.PLAYER and unit_type ~= types.PET then
|
jcallahan@66
|
257 return unit_type, tonumber(guid:sub(6, 10), 16)
|
jcallahan@4
|
258 end
|
jcallahan@4
|
259 return unit_type
|
jcallahan@4
|
260 end
|
jcallahan@4
|
261 end -- do-block
|
jcallahan@4
|
262
|
jcallahan@4
|
263
|
jcallahan@34
|
264 local UpdateNPCLocation
|
jcallahan@34
|
265 do
|
jcallahan@34
|
266 local COORD_MAX = 5
|
jcallahan@34
|
267
|
jcallahan@34
|
268 function UpdateNPCLocation(unit_idnum)
|
jcallahan@34
|
269 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData()
|
jcallahan@34
|
270 local npc_data = NPCEntry(unit_idnum).encounter_data[difficulty_token].stats[("level_%d"):format(_G.UnitLevel("target"))]
|
jcallahan@34
|
271 local zone_token = ("%s:%d"):format(zone_name, area_id)
|
jcallahan@34
|
272 npc_data.locations = npc_data.locations or {}
|
jcallahan@34
|
273
|
jcallahan@34
|
274 local zone_data = npc_data.locations[zone_token]
|
jcallahan@34
|
275
|
jcallahan@34
|
276 if not zone_data then
|
jcallahan@34
|
277 zone_data = {}
|
jcallahan@34
|
278 npc_data.locations[zone_token] = zone_data
|
jcallahan@34
|
279 end
|
jcallahan@34
|
280
|
jcallahan@34
|
281 for location_token in pairs(zone_data) do
|
jcallahan@34
|
282 local loc_level, loc_x, loc_y = (":"):split(location_token)
|
jcallahan@34
|
283 loc_level = tonumber(loc_level)
|
jcallahan@34
|
284
|
jcallahan@34
|
285 if map_level == loc_level and math.abs(x - loc_x) <= COORD_MAX and math.abs(y - loc_y) <= COORD_MAX then
|
jcallahan@34
|
286 return
|
jcallahan@34
|
287 end
|
jcallahan@34
|
288 end
|
jcallahan@34
|
289 zone_data[("%s:%s:%s"):format(map_level, x, y)] = true
|
jcallahan@34
|
290 end
|
jcallahan@34
|
291 end -- do-block
|
jcallahan@34
|
292
|
jcallahan@34
|
293
|
jcallahan@52
|
294 local function UpdateDBEntryLocation(entry_type, identifier)
|
jcallahan@10
|
295 if not identifier then
|
jcallahan@10
|
296 return
|
jcallahan@10
|
297 end
|
jcallahan@31
|
298 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData()
|
jcallahan@41
|
299 local entry = DBEntry(entry_type, identifier)
|
jcallahan@41
|
300 entry[difficulty_token] = entry[difficulty_token] or {}
|
jcallahan@52
|
301 entry[difficulty_token].locations = entry[difficulty_token].locations or {}
|
jcallahan@10
|
302
|
jcallahan@31
|
303 local zone_token = ("%s:%d"):format(zone_name, area_id)
|
jcallahan@52
|
304 local zone_data = entry[difficulty_token].locations[zone_token]
|
jcallahan@24
|
305
|
jcallahan@31
|
306 if not zone_data then
|
jcallahan@31
|
307 zone_data = {}
|
jcallahan@52
|
308 entry[difficulty_token].locations[zone_token] = zone_data
|
jcallahan@10
|
309 end
|
jcallahan@41
|
310 local location_token = ("%s:%s:%s"):format(map_level, x, y)
|
jcallahan@41
|
311 zone_data[location_token] = zone_data[location_token] or true
|
jcallahan@41
|
312 return zone_data
|
jcallahan@10
|
313 end
|
jcallahan@10
|
314
|
jcallahan@10
|
315
|
jcallahan@19
|
316 local function HandleItemUse(item_link, bag_index, slot_index)
|
jcallahan@19
|
317 if not item_link then
|
jcallahan@19
|
318 return
|
jcallahan@19
|
319 end
|
jcallahan@19
|
320 local item_id = ItemLinkToID(item_link)
|
jcallahan@19
|
321
|
jcallahan@19
|
322 if not bag_index or not slot_index then
|
jcallahan@19
|
323 for new_bag_index = 0, _G.NUM_BAG_FRAMES do
|
jcallahan@19
|
324 for new_slot_index = 1, _G.GetContainerNumSlots(new_bag_index) do
|
jcallahan@19
|
325 if item_id == ItemLinkToID(_G.GetContainerItemLink(new_bag_index, new_slot_index)) then
|
jcallahan@19
|
326 bag_index = new_bag_index
|
jcallahan@19
|
327 slot_index = new_slot_index
|
jcallahan@19
|
328 break
|
jcallahan@19
|
329 end
|
jcallahan@19
|
330 end
|
jcallahan@19
|
331 end
|
jcallahan@19
|
332 end
|
jcallahan@19
|
333
|
jcallahan@19
|
334 if not bag_index or not slot_index then
|
jcallahan@19
|
335 return
|
jcallahan@19
|
336 end
|
jcallahan@19
|
337 local _, _, _, _, _, is_lootable = _G.GetContainerItemInfo(bag_index, slot_index)
|
jcallahan@19
|
338
|
jcallahan@19
|
339 if not is_lootable then
|
jcallahan@19
|
340 return
|
jcallahan@19
|
341 end
|
jcallahan@19
|
342 DatamineTT:ClearLines()
|
jcallahan@19
|
343 DatamineTT:SetBagItem(bag_index, slot_index)
|
jcallahan@19
|
344
|
jcallahan@19
|
345 for line_index = 1, DatamineTT:NumLines() do
|
jcallahan@19
|
346 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@19
|
347
|
jcallahan@19
|
348 if not current_line then
|
jcallahan@19
|
349 break
|
jcallahan@19
|
350 end
|
jcallahan@19
|
351
|
jcallahan@19
|
352 if current_line:GetText() == _G.ITEM_OPENABLE then
|
jcallahan@19
|
353 table.wipe(action_data)
|
jcallahan@19
|
354 action_data.type = AF.ITEM
|
jcallahan@28
|
355 action_data.identifier = item_id
|
jcallahan@25
|
356 action_data.label = "contains"
|
jcallahan@19
|
357 break
|
jcallahan@19
|
358 end
|
jcallahan@19
|
359 end
|
jcallahan@19
|
360 end
|
jcallahan@19
|
361
|
jcallahan@19
|
362
|
jcallahan@39
|
363 local UnitFactionStanding
|
jcallahan@32
|
364 local UpdateFactionData
|
jcallahan@32
|
365 do
|
jcallahan@32
|
366 local MAX_FACTION_INDEX = 1000
|
jcallahan@20
|
367
|
jcallahan@32
|
368 local STANDING_NAMES = {
|
jcallahan@32
|
369 "HATED",
|
jcallahan@32
|
370 "HOSTILE",
|
jcallahan@32
|
371 "UNFRIENDLY",
|
jcallahan@32
|
372 "NEUTRAL",
|
jcallahan@32
|
373 "FRIENDLY",
|
jcallahan@32
|
374 "HONORED",
|
jcallahan@32
|
375 "REVERED",
|
jcallahan@32
|
376 "EXALTED",
|
jcallahan@32
|
377 }
|
jcallahan@32
|
378
|
jcallahan@39
|
379
|
jcallahan@39
|
380 function UnitFactionStanding(unit)
|
jcallahan@39
|
381 UpdateFactionData()
|
jcallahan@39
|
382 DatamineTT:ClearLines()
|
jcallahan@39
|
383 DatamineTT:SetUnit(unit)
|
jcallahan@39
|
384
|
jcallahan@39
|
385 for line_index = 1, DatamineTT:NumLines() do
|
jcallahan@64
|
386 local faction_name = _G["WDPDatamineTTTextLeft" .. line_index]:GetText():trim()
|
jcallahan@39
|
387
|
jcallahan@39
|
388 if faction_name and faction_standings[faction_name] then
|
jcallahan@39
|
389 return faction_name, faction_standings[faction_name]
|
jcallahan@39
|
390 end
|
jcallahan@39
|
391 end
|
jcallahan@39
|
392 end
|
jcallahan@39
|
393
|
jcallahan@39
|
394
|
jcallahan@32
|
395 function UpdateFactionData()
|
jcallahan@32
|
396 for faction_index = 1, MAX_FACTION_INDEX do
|
jcallahan@32
|
397 local faction_name, _, current_standing, _, _, _, _, _, is_header = _G.GetFactionInfo(faction_index)
|
jcallahan@32
|
398
|
jcallahan@86
|
399 if faction_name then
|
jcallahan@32
|
400 faction_standings[faction_name] = STANDING_NAMES[current_standing]
|
jcallahan@32
|
401 elseif not faction_name then
|
jcallahan@32
|
402 break
|
jcallahan@32
|
403 end
|
jcallahan@20
|
404 end
|
jcallahan@20
|
405 end
|
jcallahan@32
|
406 end -- do-block
|
jcallahan@20
|
407
|
jcallahan@48
|
408
|
jcallahan@75
|
409 local GenericLootUpdate
|
jcallahan@75
|
410 do
|
jcallahan@77
|
411 local function LootTable(entry, loot_type, top_field)
|
jcallahan@75
|
412 if top_field then
|
jcallahan@75
|
413 entry[top_field] = entry[top_field] or {}
|
jcallahan@75
|
414 entry[top_field][loot_type] = entry[top_field][loot_type] or {}
|
jcallahan@75
|
415 return entry[top_field][loot_type]
|
jcallahan@75
|
416 end
|
jcallahan@48
|
417 entry[loot_type] = entry[loot_type] or {}
|
jcallahan@75
|
418 return entry[loot_type]
|
jcallahan@48
|
419 end
|
jcallahan@48
|
420
|
jcallahan@75
|
421 function GenericLootUpdate(data_type, top_field)
|
jcallahan@75
|
422 local loot_type = action_data.label or "drops"
|
jcallahan@75
|
423 local loot_count = ("%s_count"):format(loot_type)
|
jcallahan@77
|
424 local source_list = {}
|
jcallahan@75
|
425
|
jcallahan@78
|
426 for source_guid, loot_data in pairs(action_data.loot_sources) do
|
jcallahan@78
|
427 local entry, source_id
|
jcallahan@78
|
428
|
jcallahan@78
|
429 if action_data.type == AF.ITEM then
|
jcallahan@78
|
430 -- Items return the player as the source, so we need to use the item's ID (disenchant, milling, etc)
|
jcallahan@78
|
431 source_id = action_data.identifier
|
jcallahan@78
|
432 entry = DBEntry(data_type, source_id)
|
jcallahan@78
|
433 elseif action_data.type == AF.OBJECT then
|
jcallahan@78
|
434 source_id = ("%s:%s"):format(action_data.spell_label, select(2, ParseGUID(source_guid)))
|
jcallahan@78
|
435 entry = DBEntry(data_type, source_id)
|
jcallahan@78
|
436 else
|
jcallahan@78
|
437 source_id = select(2, ParseGUID(source_guid))
|
jcallahan@78
|
438 entry = DBEntry(data_type, source_id)
|
jcallahan@78
|
439 end
|
jcallahan@75
|
440
|
jcallahan@75
|
441 if entry then
|
jcallahan@77
|
442 local loot_table = LootTable(entry, loot_type, top_field)
|
jcallahan@77
|
443
|
jcallahan@78
|
444 if not source_list[source_guid] then
|
jcallahan@77
|
445 if top_field then
|
jcallahan@77
|
446 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1
|
jcallahan@77
|
447 else
|
jcallahan@77
|
448 entry[loot_count] = (entry[loot_count] or 0) + 1
|
jcallahan@77
|
449 end
|
jcallahan@78
|
450 source_list[source_guid] = true
|
jcallahan@77
|
451 end
|
jcallahan@75
|
452 UpdateDBEntryLocation(data_type, source_id)
|
jcallahan@75
|
453
|
jcallahan@75
|
454 for item_id, quantity in pairs(loot_data) do
|
jcallahan@75
|
455 table.insert(loot_table, ("%d:%d"):format(item_id, quantity))
|
jcallahan@75
|
456 end
|
jcallahan@75
|
457 end
|
jcallahan@75
|
458 end
|
jcallahan@75
|
459 -- TODO: Remove this when GetLootSourceInfo() has values for money
|
jcallahan@82
|
460 if #action_data.loot_list <= 0 then
|
jcallahan@78
|
461 return
|
jcallahan@78
|
462 end
|
jcallahan@82
|
463 local entry
|
jcallahan@82
|
464
|
jcallahan@82
|
465 -- At this point we only have a name if it's an object.
|
jcallahan@82
|
466 if action_data.type == AF.OBJECT then
|
jcallahan@82
|
467 entry = DBEntry(data_type, ("%s:%s"):format(action_data.spell_label, action_data.target_name))
|
jcallahan@82
|
468 else
|
jcallahan@82
|
469 entry = DBEntry(data_type, action_data.identifier)
|
jcallahan@82
|
470 end
|
jcallahan@75
|
471
|
jcallahan@75
|
472 if not entry then
|
jcallahan@75
|
473 return
|
jcallahan@75
|
474 end
|
jcallahan@77
|
475 local loot_table = LootTable(entry, loot_type, top_field)
|
jcallahan@77
|
476
|
jcallahan@77
|
477 if not source_list[action_data.identifier] then
|
jcallahan@77
|
478 if top_field then
|
jcallahan@77
|
479 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1
|
jcallahan@77
|
480 else
|
jcallahan@77
|
481 entry[loot_count] = (entry[loot_count] or 0) + 1
|
jcallahan@77
|
482 end
|
jcallahan@77
|
483 end
|
jcallahan@75
|
484
|
jcallahan@75
|
485 for index = 1, #action_data.loot_list do
|
jcallahan@75
|
486 table.insert(loot_table, action_data.loot_list[index])
|
jcallahan@75
|
487 end
|
jcallahan@48
|
488 end
|
jcallahan@75
|
489 end -- do-block
|
jcallahan@48
|
490
|
jcallahan@97
|
491
|
jcallahan@97
|
492 local ReplaceKeywords
|
jcallahan@97
|
493 do
|
jcallahan@97
|
494 local KEYWORD_SUBSTITUTIONS = {
|
jcallahan@97
|
495 class = PLAYER_CLASS,
|
jcallahan@97
|
496 name = PLAYER_NAME,
|
jcallahan@97
|
497 race = PLAYER_RACE,
|
jcallahan@97
|
498 }
|
jcallahan@97
|
499
|
jcallahan@97
|
500
|
jcallahan@97
|
501 function ReplaceKeywords(text)
|
jcallahan@97
|
502 if not text or text == "" then
|
jcallahan@97
|
503 return ""
|
jcallahan@97
|
504 end
|
jcallahan@97
|
505
|
jcallahan@97
|
506 for category, lookup in pairs(KEYWORD_SUBSTITUTIONS) do
|
jcallahan@97
|
507 local category_format = ("<%s>"):format(category)
|
jcallahan@97
|
508 text = text:gsub(lookup, category_format):gsub(lookup:lower(), category_format)
|
jcallahan@97
|
509 end
|
jcallahan@97
|
510 return text
|
jcallahan@97
|
511 end
|
jcallahan@97
|
512 end -- do-block
|
jcallahan@97
|
513
|
jcallahan@97
|
514
|
jcallahan@0
|
515 -----------------------------------------------------------------------
|
jcallahan@0
|
516 -- Methods.
|
jcallahan@0
|
517 -----------------------------------------------------------------------
|
jcallahan@0
|
518 function WDP:OnInitialize()
|
jcallahan@0
|
519 db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default").global
|
jcallahan@14
|
520
|
jcallahan@14
|
521 local raw_db = _G["WoWDBProfilerData"]
|
jcallahan@18
|
522 local build_num = tonumber(private.build_num)
|
jcallahan@14
|
523
|
jcallahan@74
|
524 -- TODO: Merge this with the DB version check when MoP goes live.
|
jcallahan@35
|
525 -- if raw_db.build_num and raw_db.build_num < build_num then
|
jcallahan@74
|
526 if raw_db.version and raw_db.version < DB_VERSION then
|
jcallahan@74
|
527 for entry in pairs(DATABASE_DEFAULTS.global) do
|
jcallahan@74
|
528 db[entry] = {}
|
jcallahan@74
|
529 end
|
jcallahan@74
|
530 end
|
jcallahan@35
|
531 raw_db.build_num = build_num
|
jcallahan@63
|
532 raw_db.version = DB_VERSION
|
jcallahan@0
|
533 end
|
jcallahan@0
|
534
|
jcallahan@0
|
535
|
jcallahan@0
|
536 function WDP:OnEnable()
|
jcallahan@0
|
537 for event_name, mapping in pairs(EVENT_MAPPING) do
|
jcallahan@1
|
538 self:RegisterEvent(event_name, (_G.type(mapping) ~= "boolean") and mapping or nil)
|
jcallahan@0
|
539 end
|
jcallahan@95
|
540
|
jcallahan@95
|
541 for index = 1, _G.GetNumLanguages() do
|
jcallahan@95
|
542 languages_known[_G.GetLanguageByIndex(index)] = true
|
jcallahan@95
|
543 end
|
jcallahan@0
|
544 durability_timer_handle = self:ScheduleRepeatingTimer("ProcessDurability", 30)
|
jcallahan@31
|
545 target_location_timer_handle = self:ScheduleRepeatingTimer("UpdateTargetLocation", 0.5)
|
jcallahan@19
|
546
|
jcallahan@19
|
547 _G.hooksecurefunc("UseContainerItem", function(bag_index, slot_index, target_unit)
|
jcallahan@19
|
548 if target_unit then
|
jcallahan@19
|
549 return
|
jcallahan@19
|
550 end
|
jcallahan@19
|
551 HandleItemUse(_G.GetContainerItemLink(bag_index, slot_index), bag_index, slot_index)
|
jcallahan@19
|
552 end)
|
jcallahan@19
|
553
|
jcallahan@19
|
554 _G.hooksecurefunc("UseItemByName", function(identifier, target_unit)
|
jcallahan@19
|
555 if target_unit then
|
jcallahan@19
|
556 return
|
jcallahan@19
|
557 end
|
jcallahan@19
|
558 local _, item_link = _G.GetItemInfo(identifier)
|
jcallahan@19
|
559 HandleItemUse(item_link)
|
jcallahan@19
|
560 end)
|
jcallahan@0
|
561 end
|
jcallahan@0
|
562
|
jcallahan@0
|
563
|
jcallahan@0
|
564 local function RecordDurability(item_id, durability)
|
jcallahan@0
|
565 if not durability or durability <= 0 then
|
jcallahan@0
|
566 return
|
jcallahan@0
|
567 end
|
jcallahan@0
|
568
|
jcallahan@0
|
569 if not db.items[item_id] then
|
jcallahan@0
|
570 db.items[item_id] = {}
|
jcallahan@0
|
571 end
|
jcallahan@0
|
572 db.items[item_id].durability = durability
|
jcallahan@0
|
573 end
|
jcallahan@0
|
574
|
jcallahan@0
|
575
|
jcallahan@0
|
576 function WDP:ProcessDurability()
|
jcallahan@0
|
577 for slot_index = 0, _G.INVSLOT_LAST_EQUIPPED do
|
jcallahan@1
|
578 local item_id = _G.GetInventoryItemID("player", slot_index)
|
jcallahan@0
|
579
|
jcallahan@0
|
580 if item_id and item_id > 0 then
|
jcallahan@1
|
581 local _, max_durability = _G.GetInventoryItemDurability(slot_index)
|
jcallahan@0
|
582 RecordDurability(item_id, max_durability)
|
jcallahan@0
|
583 end
|
jcallahan@0
|
584 end
|
jcallahan@0
|
585
|
jcallahan@0
|
586 for bag_index = 0, _G.NUM_BAG_SLOTS do
|
jcallahan@0
|
587 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
|
jcallahan@1
|
588 local item_id = _G.GetContainerItemID(bag_index, slot_index)
|
jcallahan@0
|
589
|
jcallahan@0
|
590 if item_id and item_id > 0 then
|
jcallahan@1
|
591 local _, max_durability = _G.GetContainerItemDurability(bag_index, slot_index)
|
jcallahan@0
|
592 RecordDurability(item_id, max_durability)
|
jcallahan@0
|
593 end
|
jcallahan@0
|
594 end
|
jcallahan@0
|
595 end
|
jcallahan@0
|
596 end
|
jcallahan@0
|
597
|
jcallahan@0
|
598
|
jcallahan@2
|
599 function WDP:UpdateTargetLocation()
|
jcallahan@40
|
600 if currently_drunk or not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or (_G.UnitIsTapped("target") and not _G.UnitIsDead("target")) then
|
jcallahan@2
|
601 return
|
jcallahan@2
|
602 end
|
jcallahan@2
|
603
|
jcallahan@2
|
604 for index = 1, 4 do
|
jcallahan@2
|
605 if not _G.CheckInteractDistance("target", index) then
|
jcallahan@2
|
606 return
|
jcallahan@2
|
607 end
|
jcallahan@2
|
608 end
|
jcallahan@40
|
609 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@2
|
610
|
jcallahan@40
|
611 if not unit_idnum or unit_type ~= private.UNIT_TYPES.NPC then
|
jcallahan@2
|
612 return
|
jcallahan@2
|
613 end
|
jcallahan@34
|
614 UpdateNPCLocation(unit_idnum)
|
jcallahan@2
|
615 end
|
jcallahan@2
|
616
|
jcallahan@2
|
617
|
jcallahan@0
|
618 -----------------------------------------------------------------------
|
jcallahan@0
|
619 -- Event handlers.
|
jcallahan@0
|
620 -----------------------------------------------------------------------
|
jcallahan@90
|
621 function WDP:BLACK_MARKET_ITEM_UPDATE(event_name)
|
jcallahan@56
|
622 local num_items = _G.C_BlackMarket.GetNumItems()
|
jcallahan@56
|
623
|
jcallahan@56
|
624 for index = 1, num_items do
|
jcallahan@56
|
625 local name, texture, quantity, item_type, is_usable, level, level_type, seller_name, min_bid, min_increment, current_bid, has_high_bid, num_bids, time_left, item_link, market_id = _G.C_BlackMarket.GetItemInfoByIndex(index);
|
jcallahan@56
|
626
|
jcallahan@56
|
627 if item_link then
|
jcallahan@56
|
628 DBEntry("items", ItemLinkToID(item_link)).black_market = seller_name or "UNKNOWN"
|
jcallahan@56
|
629 end
|
jcallahan@56
|
630 end
|
jcallahan@56
|
631 end
|
jcallahan@56
|
632
|
jcallahan@56
|
633
|
jcallahan@75
|
634 function WDP:CHAT_MSG_LOOT(event_name, message)
|
jcallahan@48
|
635 if action_data.spell_label ~= "EXTRACT_GAS" then
|
jcallahan@48
|
636 return
|
jcallahan@48
|
637 end
|
jcallahan@48
|
638 local item_link, quantity = deformat(message, _G.LOOT_ITEM_PUSHED_SELF_MULTIPLE)
|
jcallahan@48
|
639
|
jcallahan@48
|
640 if not item_link then
|
jcallahan@48
|
641 quantity, item_link = 1, deformat(message, _G.LOOT_ITEM_PUSHED_SELF)
|
jcallahan@48
|
642 end
|
jcallahan@48
|
643
|
jcallahan@48
|
644 if not item_link then
|
jcallahan@48
|
645 return
|
jcallahan@48
|
646 end
|
jcallahan@48
|
647 local item_id = ItemLinkToID(item_link)
|
jcallahan@48
|
648
|
jcallahan@48
|
649 if not item_id then
|
jcallahan@48
|
650 return
|
jcallahan@48
|
651 end
|
jcallahan@48
|
652 action_data.loot_list = {
|
jcallahan@48
|
653 ("%d:%d"):format(item_id, quantity)
|
jcallahan@48
|
654 }
|
jcallahan@48
|
655 GenericLootUpdate("zones")
|
jcallahan@48
|
656 table.wipe(action_data)
|
jcallahan@48
|
657 end
|
jcallahan@48
|
658
|
jcallahan@48
|
659
|
jcallahan@97
|
660 function WDP:RecordQuote(event_name, message, source_name, language_name)
|
jcallahan@97
|
661 if not source_name or not name_to_id_map[source_name] or (language_name ~= "" and not languages_known[language_name]) then
|
jcallahan@97
|
662 return
|
jcallahan@95
|
663 end
|
jcallahan@97
|
664 local npc = NPCEntry(name_to_id_map[source_name])
|
jcallahan@97
|
665 npc.quotes = npc.quotes or {}
|
jcallahan@97
|
666 npc.quotes[event_name] = npc.quotes[event_name] or {}
|
jcallahan@97
|
667 npc.quotes[event_name][ReplaceKeywords(message)] = true
|
jcallahan@97
|
668 end
|
jcallahan@95
|
669
|
jcallahan@95
|
670
|
jcallahan@95
|
671 do
|
jcallahan@40
|
672 local SOBER_MATCH = _G.DRUNK_MESSAGE_ITEM_SELF1:gsub("%%s", ".+")
|
jcallahan@40
|
673
|
jcallahan@40
|
674 local DRUNK_COMPARES = {
|
jcallahan@40
|
675 _G.DRUNK_MESSAGE_SELF2,
|
jcallahan@40
|
676 _G.DRUNK_MESSAGE_SELF3,
|
jcallahan@40
|
677 _G.DRUNK_MESSAGE_SELF4,
|
jcallahan@40
|
678 }
|
jcallahan@40
|
679
|
jcallahan@40
|
680 local DRUNK_MATCHES = {
|
jcallahan@40
|
681 _G.DRUNK_MESSAGE_SELF2:gsub("%%s", ".+"),
|
jcallahan@40
|
682 _G.DRUNK_MESSAGE_SELF3:gsub("%%s", ".+"),
|
jcallahan@40
|
683 _G.DRUNK_MESSAGE_SELF4:gsub("%%s", ".+"),
|
jcallahan@40
|
684 }
|
jcallahan@40
|
685
|
jcallahan@92
|
686 function WDP:CHAT_MSG_SYSTEM(event_name, message)
|
jcallahan@40
|
687 if currently_drunk then
|
jcallahan@40
|
688 if message == _G.DRUNK_MESSAGE_SELF1 or message:match(SOBER_MATCH) then
|
jcallahan@40
|
689 currently_drunk = nil
|
jcallahan@40
|
690 end
|
jcallahan@40
|
691 return
|
jcallahan@40
|
692 end
|
jcallahan@40
|
693
|
jcallahan@40
|
694 for index = 1, #DRUNK_MATCHES do
|
jcallahan@40
|
695 if message == DRUNK_COMPARES[index] or message:match(DRUNK_MATCHES[index]) then
|
jcallahan@40
|
696 currently_drunk = true
|
jcallahan@40
|
697 break
|
jcallahan@40
|
698 end
|
jcallahan@40
|
699 end
|
jcallahan@40
|
700 end
|
jcallahan@40
|
701 end
|
jcallahan@40
|
702
|
jcallahan@40
|
703 -- do-block
|
jcallahan@40
|
704
|
jcallahan@40
|
705 do
|
jcallahan@23
|
706 local FLAGS_NPC = bit.bor(_G.COMBATLOG_OBJECT_TYPE_GUARDIAN, _G.COMBATLOG_OBJECT_CONTROL_NPC)
|
jcallahan@23
|
707 local FLAGS_NPC_CONTROL = bit.bor(_G.COMBATLOG_OBJECT_AFFILIATION_OUTSIDER, _G.COMBATLOG_OBJECT_CONTROL_NPC)
|
jcallahan@23
|
708
|
jcallahan@23
|
709 local function RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
|
jcallahan@23
|
710 if not spell_id then
|
jcallahan@23
|
711 return
|
jcallahan@23
|
712 end
|
jcallahan@34
|
713 local source_type, source_id = ParseGUID(source_guid)
|
jcallahan@23
|
714
|
jcallahan@23
|
715 if not source_id or source_type ~= private.UNIT_TYPES.NPC then
|
jcallahan@23
|
716 return
|
jcallahan@23
|
717 end
|
jcallahan@23
|
718
|
jcallahan@23
|
719 if bit.band(FLAGS_NPC_CONTROL, source_flags) == FLAGS_NPC_CONTROL and bit.band(FLAGS_NPC, source_flags) ~= 0 then
|
jcallahan@29
|
720 local encounter_data = NPCEntry(source_id).encounter_data[InstanceDifficultyToken()]
|
jcallahan@28
|
721 encounter_data.spells = encounter_data.spells or {}
|
jcallahan@28
|
722 encounter_data.spells[spell_id] = (encounter_data.spells[spell_id] or 0) + 1
|
jcallahan@23
|
723 end
|
jcallahan@23
|
724 end
|
jcallahan@23
|
725
|
jcallahan@23
|
726 local COMBAT_LOG_FUNCS = {
|
jcallahan@23
|
727 SPELL_AURA_APPLIED = RecordNPCSpell,
|
jcallahan@23
|
728 SPELL_CAST_START = RecordNPCSpell,
|
jcallahan@48
|
729 SPELL_CAST_SUCCESS = RecordNPCSpell,
|
jcallahan@65
|
730 UNIT_DIED = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
|
jcallahan@65
|
731 local unit_type, unit_idnum = ParseGUID(dest_guid)
|
jcallahan@65
|
732
|
jcallahan@65
|
733 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@67
|
734 reputation_npc_id = nil
|
jcallahan@98
|
735 private.harvesting = nil
|
jcallahan@65
|
736 return
|
jcallahan@65
|
737 end
|
jcallahan@67
|
738 reputation_npc_id = unit_idnum
|
jcallahan@65
|
739 end,
|
jcallahan@23
|
740 }
|
jcallahan@23
|
741
|
jcallahan@23
|
742
|
jcallahan@92
|
743 function WDP:COMBAT_LOG_EVENT_UNFILTERED(event_name, 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
|
744 local combat_log_func = COMBAT_LOG_FUNCS[sub_event]
|
jcallahan@23
|
745
|
jcallahan@23
|
746 if not combat_log_func then
|
jcallahan@23
|
747 return
|
jcallahan@23
|
748 end
|
jcallahan@23
|
749 combat_log_func(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, ...)
|
jcallahan@23
|
750 end
|
jcallahan@23
|
751
|
jcallahan@44
|
752 local DIPLOMACY_SPELL_ID = 20599
|
jcallahan@44
|
753 local MR_POP_RANK1_SPELL_ID = 78634
|
jcallahan@44
|
754 local MR_POP_RANK2_SPELL_ID = 78635
|
jcallahan@44
|
755
|
jcallahan@44
|
756 local REP_BUFFS = {
|
jcallahan@44
|
757 [_G.GetSpellInfo(30754)] = "CENARION_FAVOR",
|
jcallahan@44
|
758 [_G.GetSpellInfo(24705)] = "GRIM_VISAGE",
|
jcallahan@44
|
759 [_G.GetSpellInfo(32098)] = "HONOR_HOLD_FAVOR",
|
jcallahan@44
|
760 [_G.GetSpellInfo(39913)] = "NAZGRELS_FERVOR",
|
jcallahan@44
|
761 [_G.GetSpellInfo(39953)] = "SONG_OF_BATTLE",
|
jcallahan@44
|
762 [_G.GetSpellInfo(61849)] = "SPIRIT_OF_SHARING",
|
jcallahan@44
|
763 [_G.GetSpellInfo(32096)] = "THRALLMARS_FAVOR",
|
jcallahan@44
|
764 [_G.GetSpellInfo(39911)] = "TROLLBANES_COMMAND",
|
jcallahan@44
|
765 [_G.GetSpellInfo(95987)] = "UNBURDENED",
|
jcallahan@44
|
766 [_G.GetSpellInfo(100951)] = "WOW_ANNIVERSARY",
|
jcallahan@44
|
767 }
|
jcallahan@44
|
768
|
jcallahan@44
|
769
|
jcallahan@44
|
770 local FACTION_NAMES = {
|
jcallahan@44
|
771 CENARION_CIRCLE = _G.GetFactionInfoByID(609),
|
jcallahan@44
|
772 HONOR_HOLD = _G.GetFactionInfoByID(946),
|
jcallahan@44
|
773 THE_SHATAR = _G.GetFactionInfoByID(935),
|
jcallahan@44
|
774 THRALLMAR = _G.GetFactionInfoByID(947),
|
jcallahan@44
|
775 }
|
jcallahan@44
|
776
|
jcallahan@44
|
777
|
jcallahan@44
|
778 local MODIFIERS = {
|
jcallahan@44
|
779 CENARION_FAVOR = {
|
jcallahan@44
|
780 faction = FACTION_NAMES.CENARION_CIRCLE,
|
jcallahan@44
|
781 modifier = 0.25,
|
jcallahan@44
|
782 },
|
jcallahan@44
|
783 GRIM_VISAGE = {
|
jcallahan@44
|
784 modifier = 0.1,
|
jcallahan@44
|
785 },
|
jcallahan@44
|
786 HONOR_HOLD_FAVOR = {
|
jcallahan@44
|
787 faction = FACTION_NAMES.HONOR_HOLD,
|
jcallahan@44
|
788 modifier = 0.25,
|
jcallahan@44
|
789 },
|
jcallahan@44
|
790 NAZGRELS_FERVOR = {
|
jcallahan@44
|
791 faction = FACTION_NAMES.THRALLMAR,
|
jcallahan@44
|
792 modifier = 0.1,
|
jcallahan@44
|
793 },
|
jcallahan@44
|
794 SONG_OF_BATTLE = {
|
jcallahan@44
|
795 faction = FACTION_NAMES.THE_SHATAR,
|
jcallahan@44
|
796 modifier = 0.1,
|
jcallahan@44
|
797 },
|
jcallahan@44
|
798 SPIRIT_OF_SHARING = {
|
jcallahan@44
|
799 modifier = 0.1,
|
jcallahan@44
|
800 },
|
jcallahan@44
|
801 THRALLMARS_FAVOR = {
|
jcallahan@44
|
802 faction = FACTION_NAMES.THRALLMAR,
|
jcallahan@44
|
803 modifier = 0.25,
|
jcallahan@44
|
804 },
|
jcallahan@44
|
805 TROLLBANES_COMMAND = {
|
jcallahan@44
|
806 faction = FACTION_NAMES.HONOR_HOLD,
|
jcallahan@44
|
807 modifier = 0.1,
|
jcallahan@44
|
808 },
|
jcallahan@44
|
809 UNBURDENED = {
|
jcallahan@44
|
810 modifier = 0.1,
|
jcallahan@44
|
811 },
|
jcallahan@44
|
812 WOW_ANNIVERSARY = {
|
jcallahan@44
|
813 modifier = 0.08,
|
jcallahan@44
|
814 }
|
jcallahan@44
|
815 }
|
jcallahan@44
|
816
|
jcallahan@44
|
817
|
jcallahan@92
|
818 function WDP:COMBAT_TEXT_UPDATE(event_name, message_type, faction_name, amount)
|
jcallahan@67
|
819 if message_type ~= "FACTION" or not reputation_npc_id then
|
jcallahan@44
|
820 return
|
jcallahan@44
|
821 end
|
jcallahan@44
|
822 UpdateFactionData()
|
jcallahan@44
|
823
|
jcallahan@46
|
824 if not faction_name or not faction_standings[faction_name] then
|
jcallahan@46
|
825 return
|
jcallahan@46
|
826 end
|
jcallahan@67
|
827 local npc = NPCEntry(reputation_npc_id)
|
jcallahan@98
|
828 reputation_npc_id = nil
|
jcallahan@46
|
829
|
jcallahan@44
|
830 if not npc then
|
jcallahan@98
|
831 private.harvesting = nil
|
jcallahan@44
|
832 return
|
jcallahan@44
|
833 end
|
jcallahan@98
|
834 npc.harvested = private.harvesting
|
jcallahan@98
|
835 private.harvesting = nil
|
jcallahan@98
|
836
|
jcallahan@44
|
837 local modifier = 1
|
jcallahan@44
|
838
|
jcallahan@44
|
839 if _G.IsSpellKnown(DIPLOMACY_SPELL_ID) then
|
jcallahan@44
|
840 modifier = modifier + 0.1
|
jcallahan@44
|
841 end
|
jcallahan@44
|
842
|
jcallahan@44
|
843 if _G.IsSpellKnown(MR_POP_RANK2_SPELL_ID) then
|
jcallahan@44
|
844 modifier = modifier + 0.1
|
jcallahan@44
|
845 elseif _G.IsSpellKnown(MR_POP_RANK1_SPELL_ID) then
|
jcallahan@44
|
846 modifier = modifier + 0.05
|
jcallahan@44
|
847 end
|
jcallahan@44
|
848
|
jcallahan@44
|
849 for buff_name, buff_label in pairs(REP_BUFFS) do
|
jcallahan@44
|
850 if _G.UnitBuff("player", buff_name) then
|
jcallahan@44
|
851 local modded_faction = MODIFIERS[buff_label].faction
|
jcallahan@44
|
852
|
jcallahan@44
|
853 if not modded_faction or faction_name == modded_faction then
|
jcallahan@44
|
854 modifier = modifier + MODIFIERS[buff_label].modifier
|
jcallahan@44
|
855 end
|
jcallahan@44
|
856 end
|
jcallahan@44
|
857 end
|
jcallahan@65
|
858 npc.reputations = npc.reputations or {}
|
jcallahan@65
|
859 npc.reputations[("%s:%s"):format(faction_name, faction_standings[faction_name])] = math.floor(amount / modifier)
|
jcallahan@32
|
860 end
|
jcallahan@44
|
861 end -- do-block
|
jcallahan@18
|
862
|
jcallahan@18
|
863
|
jcallahan@92
|
864 function WDP:ITEM_TEXT_BEGIN(event_name)
|
jcallahan@42
|
865 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
|
jcallahan@42
|
866
|
jcallahan@42
|
867 if not unit_idnum or unit_type ~= private.UNIT_TYPES.OBJECT or _G.UnitName("npc") ~= _G.ItemTextGetItem() then
|
jcallahan@42
|
868 return
|
jcallahan@42
|
869 end
|
jcallahan@42
|
870 UpdateDBEntryLocation("objects", unit_idnum)
|
jcallahan@42
|
871 end
|
jcallahan@42
|
872
|
jcallahan@42
|
873
|
jcallahan@13
|
874 do
|
jcallahan@40
|
875 local RE_GOLD = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@40
|
876 local RE_SILVER = _G.SILVER_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@40
|
877 local RE_COPPER = _G.COPPER_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@13
|
878
|
jcallahan@13
|
879
|
jcallahan@13
|
880 local function _moneyMatch(money, re)
|
jcallahan@13
|
881 return money:match(re) or 0
|
jcallahan@1
|
882 end
|
jcallahan@1
|
883
|
jcallahan@0
|
884
|
jcallahan@13
|
885 local function _toCopper(money)
|
jcallahan@13
|
886 if not money then
|
jcallahan@13
|
887 return 0
|
jcallahan@13
|
888 end
|
jcallahan@40
|
889 return _moneyMatch(money, RE_GOLD) * 10000 + _moneyMatch(money, RE_SILVER) * 100 + _moneyMatch(money, RE_COPPER)
|
jcallahan@1
|
890 end
|
jcallahan@1
|
891
|
jcallahan@1
|
892
|
jcallahan@13
|
893 local LOOT_VERIFY_FUNCS = {
|
jcallahan@16
|
894 [AF.ITEM] = function()
|
jcallahan@16
|
895 local locked_item_id
|
jcallahan@16
|
896
|
jcallahan@16
|
897 for bag_index = 0, _G.NUM_BAG_FRAMES do
|
jcallahan@16
|
898 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
|
jcallahan@16
|
899 local _, _, is_locked = _G.GetContainerItemInfo(bag_index, slot_index)
|
jcallahan@16
|
900
|
jcallahan@16
|
901 if is_locked then
|
jcallahan@16
|
902 locked_item_id = ItemLinkToID(_G.GetContainerItemLink(bag_index, slot_index))
|
jcallahan@16
|
903 end
|
jcallahan@16
|
904 end
|
jcallahan@16
|
905 end
|
jcallahan@16
|
906
|
jcallahan@28
|
907 if not locked_item_id or (action_data.identifier and action_data.identifier ~= locked_item_id) then
|
jcallahan@16
|
908 return false
|
jcallahan@16
|
909 end
|
jcallahan@28
|
910 action_data.identifier = locked_item_id
|
jcallahan@16
|
911 return true
|
jcallahan@16
|
912 end,
|
jcallahan@13
|
913 [AF.NPC] = function()
|
jcallahan@17
|
914 if not _G.UnitExists("target") or _G.UnitIsFriend("player", "target") or _G.UnitIsPlayer("target") or _G.UnitPlayerControlled("target") then
|
jcallahan@15
|
915 return false
|
jcallahan@13
|
916 end
|
jcallahan@34
|
917 local unit_type, id_num = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@27
|
918 action_data.identifier = id_num
|
jcallahan@13
|
919 return true
|
jcallahan@13
|
920 end,
|
jcallahan@14
|
921 [AF.OBJECT] = true,
|
jcallahan@17
|
922 [AF.ZONE] = function()
|
jcallahan@38
|
923 return _G.IsFishingLoot()
|
jcallahan@17
|
924 end,
|
jcallahan@13
|
925 }
|
jcallahan@13
|
926
|
jcallahan@13
|
927
|
jcallahan@13
|
928 local LOOT_UPDATE_FUNCS = {
|
jcallahan@16
|
929 [AF.ITEM] = function()
|
jcallahan@28
|
930 GenericLootUpdate("items")
|
jcallahan@28
|
931 end,
|
jcallahan@28
|
932 [AF.NPC] = function()
|
jcallahan@75
|
933 local difficulty_token = InstanceDifficultyToken()
|
jcallahan@75
|
934 local loot_type = action_data.label or "drops"
|
jcallahan@77
|
935 local source_list = {}
|
jcallahan@75
|
936
|
jcallahan@78
|
937 for source_guid, loot_data in pairs(action_data.loot_sources) do
|
jcallahan@78
|
938 local source_id = select(2, ParseGUID(source_guid))
|
jcallahan@75
|
939 local npc = NPCEntry(source_id)
|
jcallahan@75
|
940
|
jcallahan@75
|
941 if npc then
|
jcallahan@75
|
942 local encounter_data = npc.encounter_data[difficulty_token]
|
jcallahan@75
|
943 encounter_data[loot_type] = encounter_data[loot_type] or {}
|
jcallahan@75
|
944
|
jcallahan@78
|
945 if not source_list[source_guid] then
|
jcallahan@77
|
946 encounter_data.loot_counts = encounter_data.loot_counts or {}
|
jcallahan@77
|
947 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1
|
jcallahan@77
|
948 source_list[source_id] = true
|
jcallahan@77
|
949 end
|
jcallahan@77
|
950
|
jcallahan@75
|
951 for item_id, quantity in pairs(loot_data) do
|
jcallahan@75
|
952 table.insert(encounter_data[loot_type], ("%d:%d"):format(item_id, quantity))
|
jcallahan@75
|
953 end
|
jcallahan@75
|
954 end
|
jcallahan@75
|
955 end
|
jcallahan@75
|
956
|
jcallahan@75
|
957 -- TODO: Remove this when GetLootSourceInfo() has values for money
|
jcallahan@79
|
958 if #action_data.loot_list <= 0 then
|
jcallahan@79
|
959 return
|
jcallahan@79
|
960 end
|
jcallahan@29
|
961 local npc = NPCEntry(action_data.identifier)
|
jcallahan@28
|
962
|
jcallahan@28
|
963 if not npc then
|
jcallahan@28
|
964 return
|
jcallahan@28
|
965 end
|
jcallahan@75
|
966 local encounter_data = npc.encounter_data[difficulty_token]
|
jcallahan@29
|
967 encounter_data[loot_type] = encounter_data[loot_type] or {}
|
jcallahan@16
|
968
|
jcallahan@77
|
969 if not source_list[action_data.identifier] then
|
jcallahan@77
|
970 encounter_data.loot_counts = encounter_data.loot_counts or {}
|
jcallahan@77
|
971 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1
|
jcallahan@77
|
972 end
|
jcallahan@77
|
973
|
jcallahan@17
|
974 for index = 1, #action_data.loot_list do
|
jcallahan@29
|
975 table.insert(encounter_data[loot_type], action_data.loot_list[index])
|
jcallahan@16
|
976 end
|
jcallahan@16
|
977 end,
|
jcallahan@13
|
978 [AF.OBJECT] = function()
|
jcallahan@28
|
979 GenericLootUpdate("objects", InstanceDifficultyToken())
|
jcallahan@17
|
980 end,
|
jcallahan@17
|
981 [AF.ZONE] = function()
|
jcallahan@41
|
982 local location_token = ("%s:%s:%s"):format(action_data.map_level, action_data.x, action_data.y)
|
jcallahan@41
|
983
|
jcallahan@41
|
984 -- This will start life as a boolean true.
|
jcallahan@41
|
985 if _G.type(action_data.zone_data[location_token]) ~= "table" then
|
jcallahan@41
|
986 action_data.zone_data[location_token] = {
|
jcallahan@41
|
987 drops = {}
|
jcallahan@41
|
988 }
|
jcallahan@41
|
989 end
|
jcallahan@41
|
990 local loot_count = ("%s_count"):format(action_data.label or "drops")
|
jcallahan@41
|
991 action_data.zone_data[location_token][loot_count] = (action_data.zone_data[location_token][loot_count] or 0) + 1
|
jcallahan@41
|
992
|
jcallahan@41
|
993 for index = 1, #action_data.loot_list do
|
jcallahan@41
|
994 table.insert(action_data.zone_data[location_token].drops, action_data.loot_list[index])
|
jcallahan@41
|
995 end
|
jcallahan@13
|
996 end,
|
jcallahan@13
|
997 }
|
jcallahan@13
|
998
|
jcallahan@79
|
999 -- Prevent opening the same loot window multiple times from recording data multiple times.
|
jcallahan@79
|
1000 local loot_guid_registry = {}
|
jcallahan@13
|
1001
|
jcallahan@92
|
1002 function WDP:LOOT_OPENED(event_name)
|
jcallahan@18
|
1003 if action_data.looting then
|
jcallahan@18
|
1004 return
|
jcallahan@18
|
1005 end
|
jcallahan@18
|
1006
|
jcallahan@13
|
1007 if not action_data.type then
|
jcallahan@13
|
1008 action_data.type = AF.NPC
|
jcallahan@1
|
1009 end
|
jcallahan@13
|
1010 local verify_func = LOOT_VERIFY_FUNCS[action_data.type]
|
jcallahan@13
|
1011 local update_func = LOOT_UPDATE_FUNCS[action_data.type]
|
jcallahan@13
|
1012
|
jcallahan@14
|
1013 if not verify_func or not update_func then
|
jcallahan@13
|
1014 return
|
jcallahan@13
|
1015 end
|
jcallahan@13
|
1016
|
jcallahan@14
|
1017 if _G.type(verify_func) == "function" and not verify_func() then
|
jcallahan@14
|
1018 return
|
jcallahan@14
|
1019 end
|
jcallahan@80
|
1020 local guids_used = {}
|
jcallahan@17
|
1021 action_data.loot_list = {}
|
jcallahan@75
|
1022 action_data.loot_sources = {}
|
jcallahan@18
|
1023 action_data.looting = true
|
jcallahan@13
|
1024
|
jcallahan@55
|
1025 for loot_slot = 1, _G.GetNumLootItems() do
|
jcallahan@55
|
1026 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
|
jcallahan@55
|
1027 local slot_type = _G.GetLootSlotType(loot_slot)
|
jcallahan@13
|
1028
|
jcallahan@77
|
1029 -- TODO: Move LOOT_SLOT_X checks within loop when money is detectable via GetLootSourceInfo
|
jcallahan@77
|
1030 if slot_type == _G.LOOT_SLOT_ITEM then
|
jcallahan@78
|
1031 local loot_info = {
|
jcallahan@77
|
1032 _G.GetLootSourceInfo(loot_slot)
|
jcallahan@77
|
1033 }
|
jcallahan@75
|
1034
|
jcallahan@75
|
1035 -- TODO: Remove debugging
|
jcallahan@77
|
1036 -- print(("Loot slot %d: Source count: %d"):format(loot_slot, floor((#sources / 2) + 0.5)))
|
jcallahan@75
|
1037
|
jcallahan@77
|
1038 -- Odd index is GUID, even is count.
|
jcallahan@78
|
1039 for loot_index = 1, #loot_info, 2 do
|
jcallahan@78
|
1040 local source_guid = loot_info[loot_index]
|
jcallahan@77
|
1041
|
jcallahan@79
|
1042 if not loot_guid_registry[source_guid] then
|
jcallahan@79
|
1043 local loot_quantity = loot_info[loot_index + 1]
|
jcallahan@79
|
1044 local source_type, source_id = ParseGUID(source_guid)
|
jcallahan@79
|
1045 -- TODO: Remove debugging
|
jcallahan@79
|
1046 -- local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id)
|
jcallahan@79
|
1047 -- print(("GUID: %s - Type:ID: %s - Amount: %d"):format(loot_info[loot_index], source_key, loot_quantity))
|
jcallahan@79
|
1048
|
jcallahan@79
|
1049 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
|
jcallahan@79
|
1050 action_data.loot_sources[source_guid] = action_data.loot_sources[source_guid] or {}
|
jcallahan@79
|
1051 action_data.loot_sources[source_guid][item_id] = action_data.loot_sources[source_guid][item_id] or 0 + loot_quantity
|
jcallahan@80
|
1052 guids_used[source_guid] = true
|
jcallahan@79
|
1053 end
|
jcallahan@75
|
1054 end
|
jcallahan@82
|
1055 -- elseif slot_type == _G.LOOT_SLOT_MONEY then
|
jcallahan@82
|
1056 -- table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
|
jcallahan@77
|
1057 elseif slot_type == _G.LOOT_SLOT_CURRENCY then
|
jcallahan@77
|
1058 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
|
jcallahan@13
|
1059 end
|
jcallahan@13
|
1060 end
|
jcallahan@80
|
1061
|
jcallahan@81
|
1062 for guid in pairs(guids_used) do
|
jcallahan@80
|
1063 loot_guid_registry[guid] = true
|
jcallahan@80
|
1064 end
|
jcallahan@13
|
1065 update_func()
|
jcallahan@1
|
1066 end
|
jcallahan@13
|
1067 end -- do-block
|
jcallahan@0
|
1068
|
jcallahan@0
|
1069
|
jcallahan@89
|
1070 function WDP:MAIL_SHOW(event_name)
|
jcallahan@89
|
1071 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
|
jcallahan@89
|
1072
|
jcallahan@89
|
1073 if not unit_idnum or unit_type ~= private.UNIT_TYPES.OBJECT then
|
jcallahan@89
|
1074 return
|
jcallahan@89
|
1075 end
|
jcallahan@89
|
1076 UpdateDBEntryLocation("objects", unit_idnum)
|
jcallahan@89
|
1077 end
|
jcallahan@89
|
1078
|
jcallahan@89
|
1079
|
jcallahan@44
|
1080 do
|
jcallahan@44
|
1081 local POINT_MATCH_PATTERNS = {
|
jcallahan@44
|
1082 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@44
|
1083 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@44
|
1084 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_5V5:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@44
|
1085 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_BG:gsub("%%d", "(%%d+)")),
|
jcallahan@44
|
1086 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3_BG:gsub("%%d", "(%%d+)")),
|
jcallahan@44
|
1087 }
|
jcallahan@5
|
1088
|
jcallahan@68
|
1089 local ITEM_REQ_REPUTATION_MATCH = "Requires (.-) %- (.*)"
|
jcallahan@87
|
1090 local ITEM_REQ_QUEST_MATCH1 = "Requires: .*"
|
jcallahan@87
|
1091 local ITEM_REQ_QUEST_MATCH2 = "Must have completed: .*"
|
jcallahan@68
|
1092
|
jcallahan@89
|
1093 function WDP:UpdateMerchantItems(event_name)
|
jcallahan@44
|
1094 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@4
|
1095
|
jcallahan@44
|
1096 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@44
|
1097 return
|
jcallahan@44
|
1098 end
|
jcallahan@55
|
1099 local current_filters = _G.GetMerchantFilter()
|
jcallahan@44
|
1100 local _, merchant_standing = UnitFactionStanding("target")
|
jcallahan@44
|
1101 local merchant = NPCEntry(unit_idnum)
|
jcallahan@44
|
1102 merchant.sells = merchant.sells or {}
|
jcallahan@5
|
1103
|
jcallahan@57
|
1104 _G.SetMerchantFilter(_G.LE_LOOT_FILTER_ALL)
|
jcallahan@57
|
1105 _G.MerchantFrame_Update()
|
jcallahan@57
|
1106
|
jcallahan@57
|
1107 local num_items = _G.GetMerchantNumItems()
|
jcallahan@35
|
1108
|
jcallahan@44
|
1109 for item_index = 1, num_items do
|
jcallahan@44
|
1110 local _, _, copper_price, stack_size, num_available, _, extended_cost = _G.GetMerchantItemInfo(item_index)
|
jcallahan@44
|
1111 local item_id = ItemLinkToID(_G.GetMerchantItemLink(item_index))
|
jcallahan@5
|
1112
|
jcallahan@44
|
1113 if item_id and item_id > 0 then
|
jcallahan@44
|
1114 local price_string = ActualCopperCost(copper_price, merchant_standing)
|
jcallahan@5
|
1115
|
jcallahan@68
|
1116 DatamineTT:ClearLines()
|
jcallahan@68
|
1117 DatamineTT:SetMerchantItem(item_index)
|
jcallahan@68
|
1118
|
jcallahan@68
|
1119 local num_lines = DatamineTT:NumLines()
|
jcallahan@68
|
1120
|
jcallahan@68
|
1121 for line_index = 1, num_lines do
|
jcallahan@68
|
1122 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@68
|
1123
|
jcallahan@68
|
1124 if not current_line then
|
jcallahan@68
|
1125 break
|
jcallahan@68
|
1126 end
|
jcallahan@68
|
1127 local faction, reputation = current_line:GetText():match(ITEM_REQ_REPUTATION_MATCH)
|
jcallahan@68
|
1128
|
jcallahan@68
|
1129 if faction or reputation then
|
jcallahan@68
|
1130 DBEntry("items", item_id).req_reputation = ("%s:%s"):format(faction:gsub("-", ""), reputation:upper())
|
jcallahan@68
|
1131 break
|
jcallahan@68
|
1132 end
|
jcallahan@68
|
1133 end
|
jcallahan@68
|
1134
|
jcallahan@87
|
1135 for line_index = 1, num_lines do
|
jcallahan@87
|
1136 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@87
|
1137
|
jcallahan@87
|
1138 if not current_line then
|
jcallahan@87
|
1139 break
|
jcallahan@87
|
1140 end
|
jcallahan@87
|
1141 local line_text = current_line:GetText()
|
jcallahan@87
|
1142 local quest_name = line_text:match(ITEM_REQ_QUEST_MATCH1) or line_text:match(ITEM_REQ_QUEST_MATCH2)
|
jcallahan@87
|
1143
|
jcallahan@87
|
1144 if quest_name then
|
jcallahan@87
|
1145 DBEntry("items", item_id).req_quest = ("%s"):format(quest_name:gsub("(.+): ", ""), quest_name)
|
jcallahan@87
|
1146 break
|
jcallahan@87
|
1147 end
|
jcallahan@87
|
1148 end
|
jcallahan@87
|
1149
|
jcallahan@44
|
1150 if extended_cost then
|
jcallahan@53
|
1151 local battleground_rating = 0
|
jcallahan@53
|
1152 local personal_rating = 0
|
jcallahan@53
|
1153 local required_season_amount
|
jcallahan@5
|
1154
|
jcallahan@68
|
1155 for line_index = 1, num_lines do
|
jcallahan@44
|
1156 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@5
|
1157
|
jcallahan@44
|
1158 if not current_line then
|
jcallahan@44
|
1159 break
|
jcallahan@44
|
1160 end
|
jcallahan@53
|
1161 required_season_amount = current_line:GetText():match("Requires earning a total of (%d+)\n(.-) for the season.")
|
jcallahan@5
|
1162
|
jcallahan@44
|
1163 for match_index = 1, #POINT_MATCH_PATTERNS do
|
jcallahan@44
|
1164 local match1, match2 = current_line:GetText():match(POINT_MATCH_PATTERNS[match_index])
|
jcallahan@53
|
1165 personal_rating = personal_rating + (match1 or 0)
|
jcallahan@53
|
1166 battleground_rating = battleground_rating + (match2 or 0)
|
jcallahan@5
|
1167
|
jcallahan@44
|
1168 if match1 or match2 then
|
jcallahan@44
|
1169 break
|
jcallahan@44
|
1170 end
|
jcallahan@44
|
1171 end
|
jcallahan@5
|
1172 end
|
jcallahan@44
|
1173 local currency_list = {}
|
jcallahan@44
|
1174 local item_count = _G.GetMerchantItemCostInfo(item_index)
|
jcallahan@50
|
1175
|
jcallahan@50
|
1176 -- Keeping this around in case Blizzard makes the two points diverge at some point.
|
jcallahan@53
|
1177 -- price_string = ("%s:%s:%s:%s"):format(price_string, battleground_rating, personal_rating, required_season_amount or 0)
|
jcallahan@53
|
1178 price_string = ("%s:%s:%s"):format(price_string, personal_rating, required_season_amount or 0)
|
jcallahan@5
|
1179
|
jcallahan@44
|
1180 for cost_index = 1, item_count do
|
jcallahan@44
|
1181 local icon_texture, amount_required, currency_link = _G.GetMerchantItemCostItem(item_index, cost_index)
|
jcallahan@44
|
1182 local currency_id = currency_link and ItemLinkToID(currency_link) or nil
|
jcallahan@44
|
1183
|
jcallahan@44
|
1184 if (not currency_id or currency_id < 1) and icon_texture then
|
jcallahan@44
|
1185 currency_id = icon_texture:match("[^\\]+$"):lower()
|
jcallahan@44
|
1186 end
|
jcallahan@44
|
1187
|
jcallahan@44
|
1188 if currency_id then
|
jcallahan@44
|
1189 currency_list[#currency_list + 1] = ("(%s:%s)"):format(amount_required, currency_id)
|
jcallahan@44
|
1190 end
|
jcallahan@44
|
1191 end
|
jcallahan@44
|
1192
|
jcallahan@44
|
1193 for currency_index = 1, #currency_list do
|
jcallahan@44
|
1194 price_string = ("%s:%s"):format(price_string, currency_list[currency_index])
|
jcallahan@5
|
1195 end
|
jcallahan@5
|
1196 end
|
jcallahan@61
|
1197 merchant.sells[item_id] = ("%s:%s:[%s]"):format(num_available, stack_size, price_string)
|
jcallahan@44
|
1198 end
|
jcallahan@44
|
1199 end
|
jcallahan@5
|
1200
|
jcallahan@44
|
1201 if _G.CanMerchantRepair() then
|
jcallahan@44
|
1202 merchant.can_repair = true
|
jcallahan@5
|
1203 end
|
jcallahan@57
|
1204 _G.SetMerchantFilter(current_filters)
|
jcallahan@57
|
1205 _G.MerchantFrame_Update()
|
jcallahan@4
|
1206 end
|
jcallahan@44
|
1207 end -- do-block
|
jcallahan@4
|
1208
|
jcallahan@89
|
1209
|
jcallahan@92
|
1210 function WDP:PET_BAR_UPDATE(event_name)
|
jcallahan@25
|
1211 if not action_data.label or not action_data.label == "mind_control" then
|
jcallahan@25
|
1212 return
|
jcallahan@25
|
1213 end
|
jcallahan@34
|
1214 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("pet"))
|
jcallahan@25
|
1215
|
jcallahan@25
|
1216 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@25
|
1217 return
|
jcallahan@25
|
1218 end
|
jcallahan@29
|
1219 NPCEntry(unit_idnum).mind_control = true
|
jcallahan@25
|
1220 table.wipe(action_data)
|
jcallahan@25
|
1221 end
|
jcallahan@25
|
1222
|
jcallahan@25
|
1223
|
jcallahan@18
|
1224 do
|
jcallahan@18
|
1225 local GENDER_NAMES = {
|
jcallahan@18
|
1226 "UNKNOWN",
|
jcallahan@18
|
1227 "MALE",
|
jcallahan@18
|
1228 "FEMALE",
|
jcallahan@18
|
1229 }
|
jcallahan@2
|
1230
|
jcallahan@2
|
1231
|
jcallahan@18
|
1232 local REACTION_NAMES = {
|
jcallahan@18
|
1233 "HATED",
|
jcallahan@18
|
1234 "HOSTILE",
|
jcallahan@18
|
1235 "UNFRIENDLY",
|
jcallahan@18
|
1236 "NEUTRAL",
|
jcallahan@18
|
1237 "FRIENDLY",
|
jcallahan@18
|
1238 "HONORED",
|
jcallahan@18
|
1239 "REVERED",
|
jcallahan@18
|
1240 "EXALTED",
|
jcallahan@18
|
1241 }
|
jcallahan@2
|
1242
|
jcallahan@2
|
1243
|
jcallahan@18
|
1244 local POWER_TYPE_NAMES = {
|
jcallahan@18
|
1245 ["0"] = "MANA",
|
jcallahan@18
|
1246 ["1"] = "RAGE",
|
jcallahan@18
|
1247 ["2"] = "FOCUS",
|
jcallahan@18
|
1248 ["3"] = "ENERGY",
|
jcallahan@18
|
1249 ["6"] = "RUNIC_POWER",
|
jcallahan@18
|
1250 }
|
jcallahan@2
|
1251
|
jcallahan@2
|
1252
|
jcallahan@92
|
1253 function WDP:PLAYER_TARGET_CHANGED(event_name)
|
jcallahan@40
|
1254 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or currently_drunk then
|
jcallahan@86
|
1255 current_target_id = nil
|
jcallahan@18
|
1256 return
|
jcallahan@18
|
1257 end
|
jcallahan@34
|
1258 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@2
|
1259
|
jcallahan@18
|
1260 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
|
jcallahan@18
|
1261 return
|
jcallahan@18
|
1262 end
|
jcallahan@86
|
1263 current_target_id = unit_idnum
|
jcallahan@86
|
1264
|
jcallahan@29
|
1265 local npc = NPCEntry(unit_idnum)
|
jcallahan@18
|
1266 local _, class_token = _G.UnitClass("target")
|
jcallahan@18
|
1267 npc.class = class_token
|
jcallahan@39
|
1268 npc.faction = UnitFactionStanding("target")
|
jcallahan@26
|
1269 npc.genders = npc.genders or {}
|
jcallahan@26
|
1270 npc.genders[GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"] = true
|
jcallahan@18
|
1271 npc.is_pvp = _G.UnitIsPVP("target") and true or nil
|
jcallahan@18
|
1272 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")])
|
jcallahan@2
|
1273
|
jcallahan@30
|
1274 local encounter_data = npc.encounter_data[InstanceDifficultyToken()].stats
|
jcallahan@18
|
1275 local npc_level = ("level_%d"):format(_G.UnitLevel("target"))
|
jcallahan@3
|
1276
|
jcallahan@28
|
1277 if not encounter_data[npc_level] then
|
jcallahan@28
|
1278 encounter_data[npc_level] = {
|
jcallahan@18
|
1279 max_health = _G.UnitHealthMax("target"),
|
jcallahan@18
|
1280 }
|
jcallahan@3
|
1281
|
jcallahan@18
|
1282 local max_power = _G.UnitManaMax("target")
|
jcallahan@18
|
1283
|
jcallahan@18
|
1284 if max_power > 0 then
|
jcallahan@18
|
1285 local power_type = _G.UnitPowerType("target")
|
jcallahan@28
|
1286 encounter_data[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power)
|
jcallahan@18
|
1287 end
|
jcallahan@3
|
1288 end
|
jcallahan@95
|
1289 name_to_id_map[_G.UnitName("target")] = unit_idnum
|
jcallahan@95
|
1290
|
jcallahan@21
|
1291 table.wipe(action_data)
|
jcallahan@21
|
1292 action_data.type = AF.NPC
|
jcallahan@27
|
1293 action_data.identifier = unit_idnum
|
jcallahan@21
|
1294 action_data.npc_level = npc_level
|
jcallahan@31
|
1295 self:UpdateTargetLocation()
|
jcallahan@2
|
1296 end
|
jcallahan@18
|
1297 end -- do-block
|
jcallahan@2
|
1298
|
jcallahan@89
|
1299
|
jcallahan@12
|
1300 do
|
jcallahan@12
|
1301 local function UpdateQuestJuncture(point)
|
jcallahan@12
|
1302 local unit_name = _G.UnitName("questnpc")
|
jcallahan@9
|
1303
|
jcallahan@12
|
1304 if not unit_name then
|
jcallahan@12
|
1305 return
|
jcallahan@12
|
1306 end
|
jcallahan@34
|
1307 local unit_type, unit_id = ParseGUID(_G.UnitGUID("questnpc"))
|
jcallahan@9
|
1308
|
jcallahan@12
|
1309 if unit_type == private.UNIT_TYPES.OBJECT then
|
jcallahan@38
|
1310 UpdateDBEntryLocation("objects", unit_id)
|
jcallahan@12
|
1311 end
|
jcallahan@19
|
1312 local quest = DBEntry("quests", _G.GetQuestID())
|
jcallahan@12
|
1313 quest[point] = quest[point] or {}
|
jcallahan@12
|
1314 quest[point][("%s:%d"):format(private.UNIT_TYPE_NAMES[unit_type + 1], unit_id)] = true
|
jcallahan@24
|
1315
|
jcallahan@24
|
1316 return quest
|
jcallahan@12
|
1317 end
|
jcallahan@10
|
1318
|
jcallahan@12
|
1319
|
jcallahan@92
|
1320 function WDP:QUEST_COMPLETE(event_name)
|
jcallahan@97
|
1321 local quest = UpdateQuestJuncture("end")
|
jcallahan@97
|
1322 quest.reward_text = ReplaceKeywords(_G.GetRewardText())
|
jcallahan@97
|
1323
|
jcallahan@67
|
1324 -- Make sure the quest NPC isn't erroneously recorded as giving reputation for quests which award it.
|
jcallahan@67
|
1325 reputation_npc_id = nil
|
jcallahan@10
|
1326 end
|
jcallahan@10
|
1327
|
jcallahan@12
|
1328
|
jcallahan@92
|
1329 function WDP:QUEST_DETAIL(event_name)
|
jcallahan@24
|
1330 local quest = UpdateQuestJuncture("begin")
|
jcallahan@24
|
1331
|
jcallahan@46
|
1332 if not quest then
|
jcallahan@46
|
1333 return
|
jcallahan@46
|
1334 end
|
jcallahan@24
|
1335 quest.classes = quest.classes or {}
|
jcallahan@27
|
1336 quest.classes[PLAYER_CLASS] = true
|
jcallahan@24
|
1337
|
jcallahan@24
|
1338 quest.races = quest.races or {}
|
jcallahan@100
|
1339 quest.races[(PLAYER_RACE == "Pandaren") and ("%s_%s"):format(PLAYER_RACE, PLAYER_FACTION or "Neutral") or PLAYER_RACE] = true
|
jcallahan@10
|
1340 end
|
jcallahan@12
|
1341 end -- do-block
|
jcallahan@9
|
1342
|
jcallahan@9
|
1343
|
jcallahan@92
|
1344 function WDP:QUEST_LOG_UPDATE(event_name)
|
jcallahan@38
|
1345 local selected_quest = _G.GetQuestLogSelection() -- Save current selection to be restored when we're done.
|
jcallahan@36
|
1346 local entry_index, processed_quests = 1, 0
|
jcallahan@36
|
1347 local _, num_quests = _G.GetNumQuestLogEntries()
|
jcallahan@36
|
1348
|
jcallahan@36
|
1349 while processed_quests <= num_quests do
|
jcallahan@36
|
1350 local _, _, _, _, is_header, _, _, _, quest_id = _G.GetQuestLogTitle(entry_index)
|
jcallahan@36
|
1351
|
jcallahan@84
|
1352 if quest_id == 0 then
|
jcallahan@84
|
1353 processed_quests = processed_quests + 1
|
jcallahan@84
|
1354 elseif not is_header then
|
jcallahan@36
|
1355 _G.SelectQuestLogEntry(entry_index);
|
jcallahan@36
|
1356
|
jcallahan@36
|
1357 local quest = DBEntry("quests", quest_id)
|
jcallahan@36
|
1358 quest.timer = _G.GetQuestLogTimeLeft()
|
jcallahan@37
|
1359 quest.can_share = _G.GetQuestLogPushable() and true or nil
|
jcallahan@36
|
1360 processed_quests = processed_quests + 1
|
jcallahan@36
|
1361 end
|
jcallahan@36
|
1362 entry_index = entry_index + 1
|
jcallahan@36
|
1363 end
|
jcallahan@36
|
1364 _G.SelectQuestLogEntry(selected_quest)
|
jcallahan@4
|
1365 self:UnregisterEvent("QUEST_LOG_UPDATE")
|
jcallahan@4
|
1366 end
|
jcallahan@4
|
1367
|
jcallahan@4
|
1368
|
jcallahan@97
|
1369 function WDP:QUEST_PROGRESS(event_name)
|
jcallahan@97
|
1370 DBEntry("quests", _G.GetQuestID()).progress_text = ReplaceKeywords(_G.GetProgressText())
|
jcallahan@97
|
1371 end
|
jcallahan@97
|
1372
|
jcallahan@97
|
1373
|
jcallahan@92
|
1374 function WDP:UNIT_QUEST_LOG_CHANGED(event_name, unit_id)
|
jcallahan@4
|
1375 if unit_id ~= "player" then
|
jcallahan@4
|
1376 return
|
jcallahan@4
|
1377 end
|
jcallahan@4
|
1378 self:RegisterEvent("QUEST_LOG_UPDATE")
|
jcallahan@4
|
1379 end
|
jcallahan@4
|
1380
|
jcallahan@4
|
1381
|
jcallahan@92
|
1382 do
|
jcallahan@92
|
1383 local TRADESKILL_TOOLS = {
|
jcallahan@92
|
1384 Anvil = anvil_spell_ids,
|
jcallahan@92
|
1385 Forge = forge_spell_ids,
|
jcallahan@92
|
1386 }
|
jcallahan@92
|
1387
|
jcallahan@92
|
1388
|
jcallahan@92
|
1389 function WDP:TRADE_SKILL_SHOW(event_name)
|
jcallahan@92
|
1390 local profession_name, prof_level = _G.GetTradeSkillLine()
|
jcallahan@92
|
1391
|
jcallahan@92
|
1392 if profession_name == _G.UNKNOWN then
|
jcallahan@92
|
1393 return
|
jcallahan@92
|
1394 end
|
jcallahan@92
|
1395
|
jcallahan@92
|
1396 if _G.TradeSkillFrame and _G.TradeSkillFrame:IsVisible() then
|
jcallahan@92
|
1397 -- Clear the search box focus so the scan will have correct results.
|
jcallahan@92
|
1398 local search_box = _G.TradeSkillFrameSearchBox
|
jcallahan@92
|
1399 search_box:SetText("")
|
jcallahan@92
|
1400 _G.TradeSkillSearch_OnTextChanged(search_box)
|
jcallahan@92
|
1401 search_box:ClearFocus()
|
jcallahan@92
|
1402 search_box:GetScript("OnEditFocusLost")(search_box)
|
jcallahan@92
|
1403 end
|
jcallahan@92
|
1404 local header_list = {}
|
jcallahan@92
|
1405
|
jcallahan@92
|
1406 -- Save the current state of the TradeSkillFrame so it can be restored after we muck with it.
|
jcallahan@92
|
1407 local have_materials = _G.TradeSkillFrame.filterTbl.hasMaterials
|
jcallahan@92
|
1408 local have_skillup = _G.TradeSkillFrame.filterTbl.hasSkillUp
|
jcallahan@92
|
1409
|
jcallahan@92
|
1410 if have_materials then
|
jcallahan@92
|
1411 _G.TradeSkillFrame.filterTbl.hasMaterials = false
|
jcallahan@92
|
1412 _G.TradeSkillOnlyShowMakeable(false)
|
jcallahan@92
|
1413 end
|
jcallahan@92
|
1414
|
jcallahan@92
|
1415 if have_skillup then
|
jcallahan@92
|
1416 _G.TradeSkillFrame.filterTbl.hasSkillUp = false
|
jcallahan@92
|
1417 _G.TradeSkillOnlyShowSkillUps(false)
|
jcallahan@92
|
1418 end
|
jcallahan@92
|
1419 _G.SetTradeSkillInvSlotFilter(0, 1, 1)
|
jcallahan@92
|
1420 _G.TradeSkillUpdateFilterBar()
|
jcallahan@92
|
1421 _G.TradeSkillFrame_Update()
|
jcallahan@92
|
1422
|
jcallahan@92
|
1423 -- Expand all headers so we can see all the recipes there are
|
jcallahan@92
|
1424 for tradeskill_index = 1, _G.GetNumTradeSkills() do
|
jcallahan@92
|
1425 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
|
jcallahan@92
|
1426
|
jcallahan@94
|
1427 if tradeskill_type == "header" or tradeskill_type == "subheader" then
|
jcallahan@92
|
1428 if not is_expanded then
|
jcallahan@92
|
1429 header_list[name] = true
|
jcallahan@92
|
1430 _G.ExpandTradeSkillSubClass(tradeskill_index)
|
jcallahan@92
|
1431 end
|
jcallahan@92
|
1432 else
|
jcallahan@92
|
1433 local spell_id = tonumber(_G.GetTradeSkillRecipeLink(tradeskill_index):match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)"))
|
jcallahan@92
|
1434 local required_tool = _G.GetTradeSkillTools(tradeskill_index)
|
jcallahan@92
|
1435
|
jcallahan@92
|
1436 if required_tool then
|
jcallahan@92
|
1437 for tool_name, registry in pairs(TRADESKILL_TOOLS) do
|
jcallahan@92
|
1438 if required_tool:find(tool_name) then
|
jcallahan@92
|
1439 registry[spell_id] = true
|
jcallahan@92
|
1440 end
|
jcallahan@92
|
1441 end
|
jcallahan@92
|
1442 end
|
jcallahan@92
|
1443 end
|
jcallahan@92
|
1444 end
|
jcallahan@92
|
1445
|
jcallahan@92
|
1446 -- Restore the state of the things we changed.
|
jcallahan@92
|
1447 for tradeskill_index = 1, _G.GetNumTradeSkills() do
|
jcallahan@92
|
1448 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
|
jcallahan@92
|
1449
|
jcallahan@92
|
1450 if header_list[name] then
|
jcallahan@92
|
1451 _G.CollapseTradeSkillSubClass(tradeskill_index)
|
jcallahan@92
|
1452 end
|
jcallahan@92
|
1453 end
|
jcallahan@92
|
1454 _G.TradeSkillFrame.filterTbl.hasMaterials = have_materials
|
jcallahan@92
|
1455 _G.TradeSkillOnlyShowMakeable(have_materials)
|
jcallahan@92
|
1456 _G.TradeSkillFrame.filterTbl.hasSkillUp = have_skillup
|
jcallahan@92
|
1457 _G.TradeSkillOnlyShowSkillUps(have_skillup)
|
jcallahan@92
|
1458
|
jcallahan@92
|
1459 _G.TradeSkillUpdateFilterBar()
|
jcallahan@92
|
1460 _G.TradeSkillFrame_Update()
|
jcallahan@92
|
1461 end
|
jcallahan@92
|
1462 end -- do-block
|
jcallahan@92
|
1463
|
jcallahan@92
|
1464
|
jcallahan@92
|
1465 function WDP:TRAINER_SHOW(event_name)
|
jcallahan@34
|
1466 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@29
|
1467 local npc = NPCEntry(unit_idnum)
|
jcallahan@58
|
1468
|
jcallahan@58
|
1469 if not npc then
|
jcallahan@58
|
1470 return
|
jcallahan@58
|
1471 end
|
jcallahan@27
|
1472 npc.teaches = npc.teaches or {}
|
jcallahan@27
|
1473
|
jcallahan@27
|
1474 -- Get the initial trainer filters
|
jcallahan@27
|
1475 local available = _G.GetTrainerServiceTypeFilter("available")
|
jcallahan@27
|
1476 local unavailable = _G.GetTrainerServiceTypeFilter("unavailable")
|
jcallahan@27
|
1477 local used = _G.GetTrainerServiceTypeFilter("used")
|
jcallahan@27
|
1478
|
jcallahan@27
|
1479 -- Clear the trainer filters
|
jcallahan@27
|
1480 _G.SetTrainerServiceTypeFilter("available", 1)
|
jcallahan@27
|
1481 _G.SetTrainerServiceTypeFilter("unavailable", 1)
|
jcallahan@27
|
1482 _G.SetTrainerServiceTypeFilter("used", 1)
|
jcallahan@27
|
1483
|
jcallahan@27
|
1484 for index = 1, _G.GetNumTrainerServices(), 1 do
|
jcallahan@27
|
1485 local spell_name, rank_name, _, _, required_level = _G.GetTrainerServiceInfo(index)
|
jcallahan@27
|
1486
|
jcallahan@27
|
1487 if spell_name then
|
jcallahan@27
|
1488 DatamineTT:ClearLines()
|
jcallahan@27
|
1489 DatamineTT:SetTrainerService(index)
|
jcallahan@27
|
1490
|
jcallahan@27
|
1491 local _, _, spell_id = DatamineTT:GetSpell()
|
jcallahan@27
|
1492
|
jcallahan@43
|
1493 if spell_id then
|
jcallahan@43
|
1494 local profession, min_skill = _G.GetTrainerServiceSkillReq(index)
|
jcallahan@43
|
1495 profession = profession or "General"
|
jcallahan@43
|
1496
|
jcallahan@43
|
1497 local class_professions = npc.teaches[PLAYER_CLASS]
|
jcallahan@43
|
1498 if not class_professions then
|
jcallahan@43
|
1499 npc.teaches[PLAYER_CLASS] = {}
|
jcallahan@43
|
1500 class_professions = npc.teaches[PLAYER_CLASS]
|
jcallahan@43
|
1501 end
|
jcallahan@43
|
1502
|
jcallahan@43
|
1503 local profession_skills = class_professions[profession]
|
jcallahan@43
|
1504 if not profession_skills then
|
jcallahan@43
|
1505 class_professions[profession] = {}
|
jcallahan@43
|
1506 profession_skills = class_professions[profession]
|
jcallahan@43
|
1507 end
|
jcallahan@43
|
1508 profession_skills[spell_id] = ("%d:%d"):format(required_level, min_skill)
|
jcallahan@27
|
1509 end
|
jcallahan@27
|
1510 end
|
jcallahan@27
|
1511 end
|
jcallahan@27
|
1512
|
jcallahan@27
|
1513 -- Reset the filters to what they were before
|
jcallahan@27
|
1514 _G.SetTrainerServiceTypeFilter("available", available or 0)
|
jcallahan@27
|
1515 _G.SetTrainerServiceTypeFilter("unavailable", unavailable or 0)
|
jcallahan@27
|
1516 _G.SetTrainerServiceTypeFilter("used", used or 0)
|
jcallahan@27
|
1517 end
|
jcallahan@27
|
1518
|
jcallahan@27
|
1519
|
jcallahan@1
|
1520 function WDP:UNIT_SPELLCAST_SENT(event_name, unit_id, spell_name, spell_rank, target_name, spell_line)
|
jcallahan@1
|
1521 if private.tracked_line or unit_id ~= "player" then
|
jcallahan@1
|
1522 return
|
jcallahan@1
|
1523 end
|
jcallahan@1
|
1524 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name]
|
jcallahan@1
|
1525
|
jcallahan@1
|
1526 if not spell_label then
|
jcallahan@1
|
1527 return
|
jcallahan@1
|
1528 end
|
jcallahan@18
|
1529 table.wipe(action_data)
|
jcallahan@1
|
1530
|
jcallahan@1
|
1531 local tt_item_name, tt_item_link = _G.GameTooltip:GetItem()
|
jcallahan@1
|
1532 local tt_unit_name, tt_unit_id = _G.GameTooltip:GetUnit()
|
jcallahan@1
|
1533
|
jcallahan@1
|
1534 if not tt_unit_name and _G.UnitName("target") == target_name then
|
jcallahan@1
|
1535 tt_unit_name = target_name
|
jcallahan@1
|
1536 tt_unit_id = "target"
|
jcallahan@1
|
1537 end
|
jcallahan@1
|
1538 local spell_flags = private.SPELL_FLAGS_BY_LABEL[spell_label]
|
jcallahan@28
|
1539 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData()
|
jcallahan@28
|
1540
|
jcallahan@28
|
1541 action_data.instance_token = instance_token
|
jcallahan@28
|
1542 action_data.map_level = map_level
|
jcallahan@28
|
1543 action_data.x = x
|
jcallahan@28
|
1544 action_data.y = y
|
jcallahan@28
|
1545 action_data.zone = ("%s:%d"):format(zone_name, area_id)
|
jcallahan@76
|
1546 action_data.spell_label = spell_label
|
jcallahan@76
|
1547 action_data.label = spell_label:lower()
|
jcallahan@1
|
1548
|
jcallahan@16
|
1549 if tt_unit_name and not tt_item_name then
|
jcallahan@16
|
1550 if bit.band(spell_flags, AF.NPC) == AF.NPC then
|
jcallahan@16
|
1551 if not tt_unit_id or tt_unit_name ~= target_name then
|
jcallahan@16
|
1552 return
|
jcallahan@16
|
1553 end
|
jcallahan@16
|
1554 action_data.type = AF.NPC
|
jcallahan@25
|
1555 action_data.unit_name = tt_unit_name
|
jcallahan@16
|
1556 end
|
jcallahan@16
|
1557 elseif bit.band(spell_flags, AF.ITEM) == AF.ITEM then
|
jcallahan@16
|
1558 action_data.type = AF.ITEM
|
jcallahan@16
|
1559
|
jcallahan@16
|
1560 if tt_item_name and tt_item_name == target_name then
|
jcallahan@28
|
1561 action_data.identifier = ItemLinkToID(tt_item_link)
|
jcallahan@16
|
1562 elseif target_name and target_name ~= "" then
|
jcallahan@16
|
1563 local _, target_item_link = _G.GetItemInfo(target_name)
|
jcallahan@28
|
1564 action_data.identifier = ItemLinkToID(target_item_link)
|
jcallahan@16
|
1565 end
|
jcallahan@16
|
1566 elseif not tt_item_name and not tt_unit_name then
|
jcallahan@17
|
1567 action_data.name = target_name
|
jcallahan@17
|
1568
|
jcallahan@1
|
1569 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then
|
jcallahan@17
|
1570 if target_name == "" then
|
jcallahan@17
|
1571 return
|
jcallahan@17
|
1572 end
|
jcallahan@82
|
1573 action_data.target_name = target_name
|
jcallahan@1
|
1574 action_data.type = AF.OBJECT
|
jcallahan@1
|
1575 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then
|
jcallahan@38
|
1576 local identifier = ("%s:%s"):format(spell_label, _G["GameTooltipTextLeft1"]:GetText() or "NONE") -- Possible fishing pool name.
|
jcallahan@52
|
1577 action_data.zone_data = UpdateDBEntryLocation("zones", identifier)
|
jcallahan@17
|
1578 action_data.type = AF.ZONE
|
jcallahan@38
|
1579 action_data.identifier = identifier
|
jcallahan@1
|
1580 end
|
jcallahan@1
|
1581 end
|
jcallahan@1
|
1582 private.tracked_line = spell_line
|
jcallahan@0
|
1583 end
|
jcallahan@0
|
1584
|
jcallahan@94
|
1585
|
jcallahan@1
|
1586 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
|
jcallahan@1
|
1587 if unit_id ~= "player" then
|
jcallahan@1
|
1588 return
|
jcallahan@1
|
1589 end
|
jcallahan@1
|
1590 private.tracked_line = nil
|
jcallahan@85
|
1591
|
jcallahan@86
|
1592 if spell_name:match("^Harvest.+") then
|
jcallahan@86
|
1593 reputation_npc_id = current_target_id
|
jcallahan@98
|
1594 private.harvesting = true
|
jcallahan@85
|
1595 end
|
jcallahan@92
|
1596
|
jcallahan@92
|
1597 if anvil_spell_ids[spell_id] then
|
jcallahan@92
|
1598 UpdateDBEntryLocation("objects", OBJECT_ID_ANVIL)
|
jcallahan@92
|
1599 elseif forge_spell_ids[spell_id] then
|
jcallahan@92
|
1600 UpdateDBEntryLocation("objects", OBJECT_ID_FORGE)
|
jcallahan@92
|
1601 end
|
jcallahan@0
|
1602 end
|
jcallahan@0
|
1603
|
jcallahan@90
|
1604
|
jcallahan@1
|
1605 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
|
jcallahan@1
|
1606 if unit_id ~= "player" then
|
jcallahan@1
|
1607 return
|
jcallahan@1
|
1608 end
|
jcallahan@0
|
1609
|
jcallahan@1
|
1610 if private.tracked_line == spell_line then
|
jcallahan@1
|
1611 private.tracked_line = nil
|
jcallahan@103
|
1612 table.wipe(action_data)
|
jcallahan@1
|
1613 end
|
jcallahan@0
|
1614 end
|
jcallahan@90
|
1615
|
jcallahan@90
|
1616
|
jcallahan@90
|
1617 do
|
jcallahan@90
|
1618 local function SetUnitField(field, required_type)
|
jcallahan@90
|
1619 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
|
jcallahan@90
|
1620
|
jcallahan@90
|
1621 if not unit_idnum or (required_type and unit_type ~= required_type) then
|
jcallahan@90
|
1622 return
|
jcallahan@90
|
1623 end
|
jcallahan@90
|
1624
|
jcallahan@90
|
1625 if unit_type == private.UNIT_TYPES.NPC then
|
jcallahan@90
|
1626 NPCEntry(unit_idnum)[field] = true
|
jcallahan@90
|
1627 elseif unit_type == private.UNIT_TYPES.OBJECT then
|
jcallahan@90
|
1628 DBEntry("objects", unit_idnum)[field] = true
|
jcallahan@93
|
1629 UpdateDBEntryLocation("objects", unit_idnum)
|
jcallahan@90
|
1630 end
|
jcallahan@90
|
1631 end
|
jcallahan@90
|
1632
|
jcallahan@90
|
1633
|
jcallahan@90
|
1634 function WDP:AUCTION_HOUSE_SHOW(event_name)
|
jcallahan@90
|
1635 SetUnitField("auctioneer", private.UNIT_TYPES.NPC)
|
jcallahan@90
|
1636 end
|
jcallahan@90
|
1637
|
jcallahan@90
|
1638
|
jcallahan@90
|
1639 function WDP:BANKFRAME_OPENED(event_name)
|
jcallahan@90
|
1640 SetUnitField("banker", private.UNIT_TYPES.NPC)
|
jcallahan@90
|
1641 end
|
jcallahan@90
|
1642
|
jcallahan@90
|
1643
|
jcallahan@90
|
1644 function WDP:BATTLEFIELDS_SHOW(event_name)
|
jcallahan@90
|
1645 SetUnitField("battlemaster", private.UNIT_TYPES.NPC)
|
jcallahan@90
|
1646 end
|
jcallahan@90
|
1647
|
jcallahan@90
|
1648
|
jcallahan@92
|
1649 function WDP:FORGE_MASTER_OPENED(event_name)
|
jcallahan@90
|
1650 SetUnitField("arcane_reforger", private.UNIT_TYPES.NPC)
|
jcallahan@90
|
1651 end
|
jcallahan@90
|
1652
|
jcallahan@90
|
1653
|
jcallahan@92
|
1654 function WDP:GOSSIP_SHOW(event_name)
|
jcallahan@90
|
1655 local gossip_options = { _G.GetGossipOptions() }
|
jcallahan@90
|
1656
|
jcallahan@90
|
1657 for index = 2, #gossip_options, 2 do
|
jcallahan@90
|
1658 if gossip_options[index] == "binder" then
|
jcallahan@90
|
1659 SetUnitField("innkeeper", private.UNIT_TYPES.NPC)
|
jcallahan@90
|
1660 return
|
jcallahan@90
|
1661 end
|
jcallahan@90
|
1662 end
|
jcallahan@90
|
1663 end
|
jcallahan@90
|
1664
|
jcallahan@90
|
1665
|
jcallahan@93
|
1666 function WDP:GUILDBANKFRAME_OPENED(event_name)
|
jcallahan@93
|
1667 SetUnitField("guild_bank", private.UNIT_TYPES.OBJECT)
|
jcallahan@93
|
1668 end
|
jcallahan@93
|
1669
|
jcallahan@93
|
1670
|
jcallahan@90
|
1671 function WDP:TAXIMAP_OPENED(event_name)
|
jcallahan@90
|
1672 SetUnitField("flight_master", private.UNIT_TYPES.NPC)
|
jcallahan@90
|
1673 end
|
jcallahan@90
|
1674
|
jcallahan@90
|
1675
|
jcallahan@90
|
1676 function WDP:TRANSMOGRIFY_OPEN(event_name)
|
jcallahan@90
|
1677 SetUnitField("transmogrifier", private.UNIT_TYPES.NPC)
|
jcallahan@90
|
1678 end
|
jcallahan@90
|
1679
|
jcallahan@90
|
1680
|
jcallahan@90
|
1681 function WDP:VOID_STORAGE_OPEN(event_name)
|
jcallahan@90
|
1682 SetUnitField("void_storage", private.UNIT_TYPES.NPC)
|
jcallahan@90
|
1683 end
|
jcallahan@90
|
1684 end -- do-block
|