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@115
|
25 local LPJ = LibStub("LibPetJournal-2.0")
|
jcallahan@141
|
26 local MapData = LibStub("LibMapData-1.0")
|
jcallahan@48
|
27
|
jcallahan@4
|
28 local DatamineTT = _G.CreateFrame("GameTooltip", "WDPDatamineTT", _G.UIParent, "GameTooltipTemplate")
|
jcallahan@5
|
29 DatamineTT:SetOwner(_G.WorldFrame, "ANCHOR_NONE")
|
jcallahan@5
|
30
|
jcallahan@0
|
31
|
jcallahan@0
|
32 -----------------------------------------------------------------------
|
jcallahan@0
|
33 -- Local constants.
|
jcallahan@0
|
34 -----------------------------------------------------------------------
|
jcallahan@207
|
35 local DB_VERSION = 14
|
jcallahan@151
|
36 local DEBUGGING = false
|
jcallahan@156
|
37 local EVENT_DEBUG = false
|
jcallahan@92
|
38
|
jcallahan@157
|
39
|
jcallahan@0
|
40 local DATABASE_DEFAULTS = {
|
jcallahan@128
|
41 char = {},
|
jcallahan@0
|
42 global = {
|
jcallahan@0
|
43 items = {},
|
jcallahan@0
|
44 npcs = {},
|
jcallahan@0
|
45 objects = {},
|
jcallahan@0
|
46 quests = {},
|
jcallahan@167
|
47 spells = {},
|
jcallahan@17
|
48 zones = {},
|
jcallahan@0
|
49 }
|
jcallahan@0
|
50 }
|
jcallahan@0
|
51
|
jcallahan@0
|
52
|
jcallahan@1
|
53 local EVENT_MAPPING = {
|
jcallahan@90
|
54 AUCTION_HOUSE_SHOW = true,
|
jcallahan@90
|
55 BANKFRAME_OPENED = true,
|
jcallahan@90
|
56 BATTLEFIELDS_SHOW = true,
|
jcallahan@56
|
57 BLACK_MARKET_ITEM_UPDATE = true,
|
jcallahan@48
|
58 CHAT_MSG_LOOT = true,
|
jcallahan@95
|
59 CHAT_MSG_MONSTER_SAY = "RecordQuote",
|
jcallahan@95
|
60 CHAT_MSG_MONSTER_WHISPER = "RecordQuote",
|
jcallahan@95
|
61 CHAT_MSG_MONSTER_YELL = "RecordQuote",
|
jcallahan@40
|
62 CHAT_MSG_SYSTEM = true,
|
jcallahan@23
|
63 COMBAT_LOG_EVENT_UNFILTERED = true,
|
jcallahan@18
|
64 COMBAT_TEXT_UPDATE = true,
|
jcallahan@140
|
65 CURSOR_UPDATE = true,
|
jcallahan@90
|
66 FORGE_MASTER_OPENED = true,
|
jcallahan@90
|
67 GOSSIP_SHOW = true,
|
jcallahan@93
|
68 GUILDBANKFRAME_OPENED = true,
|
jcallahan@42
|
69 ITEM_TEXT_BEGIN = true,
|
jcallahan@189
|
70 ITEM_UPGRADE_MASTER_OPENED = true,
|
jcallahan@124
|
71 LOOT_CLOSED = true,
|
jcallahan@1
|
72 LOOT_OPENED = true,
|
jcallahan@89
|
73 MAIL_SHOW = true,
|
jcallahan@133
|
74 MERCHANT_CLOSED = true,
|
jcallahan@7
|
75 MERCHANT_SHOW = "UpdateMerchantItems",
|
jcallahan@61
|
76 MERCHANT_UPDATE = "UpdateMerchantItems",
|
jcallahan@25
|
77 PET_BAR_UPDATE = true,
|
jcallahan@115
|
78 PET_JOURNAL_LIST_UPDATE = true,
|
jcallahan@156
|
79 PLAYER_REGEN_DISABLED = true,
|
jcallahan@156
|
80 PLAYER_REGEN_ENABLED = true,
|
jcallahan@2
|
81 PLAYER_TARGET_CHANGED = true,
|
jcallahan@9
|
82 QUEST_COMPLETE = true,
|
jcallahan@9
|
83 QUEST_DETAIL = true,
|
jcallahan@9
|
84 QUEST_LOG_UPDATE = true,
|
jcallahan@97
|
85 QUEST_PROGRESS = true,
|
jcallahan@178
|
86 SHOW_LOOT_TOAST = true,
|
jcallahan@88
|
87 TAXIMAP_OPENED = true,
|
jcallahan@92
|
88 TRADE_SKILL_SHOW = true,
|
jcallahan@167
|
89 TRAINER_CLOSED = true,
|
jcallahan@27
|
90 TRAINER_SHOW = true,
|
jcallahan@90
|
91 TRANSMOGRIFY_OPEN = true,
|
jcallahan@4
|
92 UNIT_QUEST_LOG_CHANGED = true,
|
jcallahan@1
|
93 UNIT_SPELLCAST_FAILED = "HandleSpellFailure",
|
jcallahan@1
|
94 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure",
|
jcallahan@1
|
95 UNIT_SPELLCAST_INTERRUPTED = "HandleSpellFailure",
|
jcallahan@1
|
96 UNIT_SPELLCAST_SENT = true,
|
jcallahan@1
|
97 UNIT_SPELLCAST_SUCCEEDED = true,
|
jcallahan@90
|
98 VOID_STORAGE_OPEN = true,
|
jcallahan@129
|
99 ZONE_CHANGED = "SetCurrentAreaID",
|
jcallahan@129
|
100 ZONE_CHANGED_INDOORS = "SetCurrentAreaID",
|
jcallahan@129
|
101 ZONE_CHANGED_NEW_AREA = "SetCurrentAreaID",
|
jcallahan@0
|
102 }
|
jcallahan@0
|
103
|
jcallahan@4
|
104
|
jcallahan@92
|
105 local OBJECT_ID_ANVIL = 192628
|
jcallahan@92
|
106 local OBJECT_ID_FORGE = 1685
|
jcallahan@92
|
107
|
jcallahan@92
|
108
|
jcallahan@1
|
109 local AF = private.ACTION_TYPE_FLAGS
|
jcallahan@0
|
110
|
jcallahan@4
|
111
|
jcallahan@27
|
112 local PLAYER_CLASS = _G.select(2, _G.UnitClass("player"))
|
jcallahan@100
|
113 local PLAYER_FACTION = _G.UnitFactionGroup("player")
|
jcallahan@34
|
114 local PLAYER_GUID = _G.UnitGUID("player")
|
jcallahan@95
|
115 local PLAYER_NAME = _G.UnitName("player")
|
jcallahan@39
|
116 local PLAYER_RACE = _G.select(2, _G.UnitRace("player"))
|
jcallahan@27
|
117
|
jcallahan@95
|
118
|
jcallahan@112
|
119 local CLIENT_LOCALE = _G.GetLocale()
|
jcallahan@112
|
120
|
jcallahan@112
|
121
|
jcallahan@112
|
122 local ALLOWED_LOCALES = {
|
jcallahan@112
|
123 enUS = true,
|
jcallahan@112
|
124 enGB = true,
|
jcallahan@112
|
125 }
|
jcallahan@112
|
126
|
jcallahan@112
|
127
|
jcallahan@0
|
128 -----------------------------------------------------------------------
|
jcallahan@0
|
129 -- Local variables.
|
jcallahan@0
|
130 -----------------------------------------------------------------------
|
jcallahan@92
|
131 local anvil_spell_ids = {}
|
jcallahan@92
|
132 local currently_drunk
|
jcallahan@128
|
133 local char_db
|
jcallahan@128
|
134 local global_db
|
jcallahan@187
|
135 local item_process_timer_handle
|
jcallahan@92
|
136 local faction_standings = {}
|
jcallahan@92
|
137 local forge_spell_ids = {}
|
jcallahan@95
|
138 local languages_known = {}
|
jcallahan@95
|
139 local name_to_id_map = {}
|
jcallahan@177
|
140 local killed_npc_id
|
jcallahan@2
|
141 local target_location_timer_handle
|
jcallahan@86
|
142 local current_target_id
|
jcallahan@126
|
143 local current_area_id
|
jcallahan@131
|
144 local current_loot
|
jcallahan@1
|
145
|
jcallahan@121
|
146 -----------------------------------------------------------------------
|
jcallahan@121
|
147 -- Data for our current action. Including possible values as a reference.
|
jcallahan@121
|
148 -----------------------------------------------------------------------
|
jcallahan@122
|
149 local current_action = {
|
jcallahan@121
|
150 identifier = nil,
|
jcallahan@121
|
151 loot_label = nil,
|
jcallahan@121
|
152 loot_list = nil,
|
jcallahan@121
|
153 loot_sources = nil,
|
jcallahan@121
|
154 map_level = nil,
|
jcallahan@121
|
155 spell_label = nil,
|
jcallahan@123
|
156 target_type = nil,
|
jcallahan@121
|
157 x = nil,
|
jcallahan@121
|
158 y = nil,
|
jcallahan@121
|
159 zone_data = nil,
|
jcallahan@121
|
160 }
|
jcallahan@92
|
161
|
jcallahan@1
|
162 -----------------------------------------------------------------------
|
jcallahan@1
|
163 -- Helper Functions.
|
jcallahan@1
|
164 -----------------------------------------------------------------------
|
jcallahan@151
|
165 local function Debug(...)
|
jcallahan@151
|
166 if not DEBUGGING then
|
jcallahan@151
|
167 return
|
jcallahan@151
|
168 end
|
jcallahan@151
|
169 _G.print(...)
|
jcallahan@151
|
170 end
|
jcallahan@151
|
171
|
jcallahan@151
|
172
|
jcallahan@169
|
173 local TradeSkillExecutePer
|
jcallahan@169
|
174 do
|
jcallahan@169
|
175 local header_list = {}
|
jcallahan@169
|
176
|
jcallahan@169
|
177 -- iter_func returns true to indicate that the loop should be broken
|
jcallahan@169
|
178 function TradeSkillExecutePer(iter_func)
|
jcallahan@169
|
179 if not _G.TradeSkillFrame or not _G.TradeSkillFrame:IsVisible() then
|
jcallahan@169
|
180 return
|
jcallahan@169
|
181 end
|
jcallahan@167
|
182 -- Clear the search box focus so the scan will have correct results.
|
jcallahan@167
|
183 local search_box = _G.TradeSkillFrameSearchBox
|
jcallahan@167
|
184 search_box:SetText("")
|
jcallahan@169
|
185
|
jcallahan@167
|
186 _G.TradeSkillSearch_OnTextChanged(search_box)
|
jcallahan@167
|
187 search_box:ClearFocus()
|
jcallahan@167
|
188 search_box:GetScript("OnEditFocusLost")(search_box)
|
jcallahan@169
|
189
|
jcallahan@169
|
190 table.wipe(header_list)
|
jcallahan@169
|
191
|
jcallahan@169
|
192 -- Save the current state of the TradeSkillFrame so it can be restored after we muck with it.
|
jcallahan@169
|
193 local have_materials = _G.TradeSkillFrame.filterTbl.hasMaterials
|
jcallahan@169
|
194 local have_skillup = _G.TradeSkillFrame.filterTbl.hasSkillUp
|
jcallahan@169
|
195
|
jcallahan@169
|
196 if have_materials then
|
jcallahan@169
|
197 _G.TradeSkillFrame.filterTbl.hasMaterials = false
|
jcallahan@169
|
198 _G.TradeSkillOnlyShowMakeable(false)
|
jcallahan@169
|
199 end
|
jcallahan@169
|
200
|
jcallahan@169
|
201 if have_skillup then
|
jcallahan@169
|
202 _G.TradeSkillFrame.filterTbl.hasSkillUp = false
|
jcallahan@169
|
203 _G.TradeSkillOnlyShowSkillUps(false)
|
jcallahan@169
|
204 end
|
jcallahan@169
|
205 _G.SetTradeSkillInvSlotFilter(0, 1, 1)
|
jcallahan@169
|
206 _G.TradeSkillUpdateFilterBar()
|
jcallahan@169
|
207 _G.TradeSkillFrame_Update()
|
jcallahan@169
|
208
|
jcallahan@169
|
209 -- Expand all headers so we can see all the recipes there are
|
jcallahan@169
|
210 for tradeskill_index = 1, _G.GetNumTradeSkills() do
|
jcallahan@169
|
211 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
|
jcallahan@169
|
212
|
jcallahan@169
|
213 if tradeskill_type == "header" or tradeskill_type == "subheader" then
|
jcallahan@169
|
214 if not is_expanded then
|
jcallahan@169
|
215 header_list[name] = true
|
jcallahan@169
|
216 _G.ExpandTradeSkillSubClass(tradeskill_index)
|
jcallahan@169
|
217 end
|
jcallahan@169
|
218 elseif iter_func(name, tradeskill_index) then
|
jcallahan@169
|
219 break
|
jcallahan@169
|
220 end
|
jcallahan@169
|
221 end
|
jcallahan@169
|
222
|
jcallahan@169
|
223 -- Restore the state of the things we changed.
|
jcallahan@169
|
224 for tradeskill_index = 1, _G.GetNumTradeSkills() do
|
jcallahan@169
|
225 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
|
jcallahan@169
|
226
|
jcallahan@169
|
227 if header_list[name] then
|
jcallahan@169
|
228 _G.CollapseTradeSkillSubClass(tradeskill_index)
|
jcallahan@169
|
229 end
|
jcallahan@169
|
230 end
|
jcallahan@169
|
231 _G.TradeSkillFrame.filterTbl.hasMaterials = have_materials
|
jcallahan@169
|
232 _G.TradeSkillOnlyShowMakeable(have_materials)
|
jcallahan@169
|
233 _G.TradeSkillFrame.filterTbl.hasSkillUp = have_skillup
|
jcallahan@169
|
234 _G.TradeSkillOnlyShowSkillUps(have_skillup)
|
jcallahan@169
|
235
|
jcallahan@169
|
236 _G.TradeSkillUpdateFilterBar()
|
jcallahan@169
|
237 _G.TradeSkillFrame_Update()
|
jcallahan@167
|
238 end
|
jcallahan@169
|
239 end -- do-block
|
jcallahan@167
|
240
|
jcallahan@167
|
241
|
jcallahan@39
|
242 local ActualCopperCost
|
jcallahan@39
|
243 do
|
jcallahan@39
|
244 local BARTERING_SPELL_ID = 83964
|
jcallahan@39
|
245
|
jcallahan@39
|
246 local STANDING_DISCOUNTS = {
|
jcallahan@39
|
247 HATED = 0,
|
jcallahan@39
|
248 HOSTILE = 0,
|
jcallahan@39
|
249 UNFRIENDLY = 0,
|
jcallahan@39
|
250 NEUTRAL = 0,
|
jcallahan@39
|
251 FRIENDLY = 0.05,
|
jcallahan@39
|
252 HONORED = 0.1,
|
jcallahan@39
|
253 REVERED = 0.15,
|
jcallahan@39
|
254 EXALTED = 0.2,
|
jcallahan@39
|
255 }
|
jcallahan@39
|
256
|
jcallahan@39
|
257
|
jcallahan@39
|
258 function ActualCopperCost(copper_cost, rep_standing)
|
jcallahan@39
|
259 if not copper_cost or copper_cost == 0 then
|
jcallahan@39
|
260 return 0
|
jcallahan@39
|
261 end
|
jcallahan@39
|
262 local modifier = 1
|
jcallahan@39
|
263
|
jcallahan@39
|
264 if _G.IsSpellKnown(BARTERING_SPELL_ID) then
|
jcallahan@39
|
265 modifier = modifier - 0.1
|
jcallahan@39
|
266 end
|
jcallahan@39
|
267
|
jcallahan@39
|
268 if rep_standing then
|
jcallahan@39
|
269 if PLAYER_RACE == "Goblin" then
|
jcallahan@39
|
270 modifier = modifier - STANDING_DISCOUNTS["EXALTED"]
|
jcallahan@39
|
271 elseif STANDING_DISCOUNTS[rep_standing] then
|
jcallahan@39
|
272 modifier = modifier - STANDING_DISCOUNTS[rep_standing]
|
jcallahan@39
|
273 end
|
jcallahan@39
|
274 end
|
jcallahan@39
|
275 return math.floor(copper_cost / modifier)
|
jcallahan@39
|
276 end
|
jcallahan@39
|
277 end -- do-block
|
jcallahan@39
|
278
|
jcallahan@39
|
279
|
jcallahan@153
|
280 -- Called on a timer
|
jcallahan@177
|
281 local function ClearKilledNPC()
|
jcallahan@177
|
282 killed_npc_id = nil
|
jcallahan@177
|
283 end
|
jcallahan@177
|
284
|
jcallahan@177
|
285
|
jcallahan@203
|
286 local function ClearKilledBossID()
|
jcallahan@203
|
287 private.raid_finder_boss_id = nil
|
jcallahan@203
|
288 private.world_boss_id = nil
|
jcallahan@203
|
289 end
|
jcallahan@203
|
290
|
jcallahan@203
|
291
|
jcallahan@177
|
292 local function IsRaidFinderInstance(instance_type, instance_difficulty)
|
jcallahan@177
|
293 return instance_type == "raid" and instance_difficulty == 2 and _G.IsPartyLFG() and _G.IsInLFGDungeon()
|
jcallahan@153
|
294 end
|
jcallahan@153
|
295
|
jcallahan@153
|
296
|
jcallahan@29
|
297 local function InstanceDifficultyToken()
|
jcallahan@29
|
298 local _, instance_type, instance_difficulty, difficulty_name, _, _, is_dynamic = _G.GetInstanceInfo()
|
jcallahan@59
|
299 if not difficulty_name or difficulty_name == "" then
|
jcallahan@29
|
300 difficulty_name = "NONE"
|
jcallahan@29
|
301 end
|
jcallahan@59
|
302
|
jcallahan@59
|
303 if not instance_type or instance_type == "" then
|
jcallahan@59
|
304 instance_type = "NONE"
|
jcallahan@59
|
305 end
|
jcallahan@137
|
306
|
jcallahan@137
|
307 -- Raid difficulty of 2 is 25-man
|
jcallahan@177
|
308 if IsRaidFinderInstance(instance_type, instance_difficulty) then
|
jcallahan@137
|
309 difficulty_name = "LOOKING_FOR_RAID"
|
jcallahan@137
|
310 end
|
jcallahan@29
|
311 return ("%s:%s:%s"):format(instance_type:upper(), difficulty_name:upper():gsub(" ", "_"), _G.tostring(is_dynamic))
|
jcallahan@29
|
312 end
|
jcallahan@29
|
313
|
jcallahan@29
|
314
|
jcallahan@19
|
315 local function DBEntry(data_type, unit_id)
|
jcallahan@19
|
316 if not data_type or not unit_id then
|
jcallahan@6
|
317 return
|
jcallahan@6
|
318 end
|
jcallahan@128
|
319 local unit = global_db[data_type][unit_id]
|
jcallahan@6
|
320
|
jcallahan@10
|
321 if not unit then
|
jcallahan@187
|
322 unit = {}
|
jcallahan@187
|
323 global_db[data_type][unit_id] = unit
|
jcallahan@6
|
324 end
|
jcallahan@10
|
325 return unit
|
jcallahan@6
|
326 end
|
jcallahan@6
|
327
|
jcallahan@214
|
328 local NPCEntry
|
jcallahan@214
|
329 do
|
jcallahan@214
|
330 local npc_prototype = {}
|
jcallahan@214
|
331 local npc_meta = {
|
jcallahan@214
|
332 __index = npc_prototype
|
jcallahan@214
|
333 }
|
jcallahan@6
|
334
|
jcallahan@214
|
335 function NPCEntry(identifier)
|
jcallahan@214
|
336 local npc = _G.setmetatable(DBEntry("npcs", identifier), npc_meta)
|
jcallahan@29
|
337
|
jcallahan@214
|
338 if not npc then
|
jcallahan@214
|
339 return
|
jcallahan@214
|
340 end
|
jcallahan@214
|
341 return npc
|
jcallahan@22
|
342 end
|
jcallahan@214
|
343
|
jcallahan@214
|
344 function npc_prototype:EncounterData()
|
jcallahan@214
|
345 local instance_token = InstanceDifficultyToken()
|
jcallahan@214
|
346 self.encounter_data = self.encounter_data or {}
|
jcallahan@214
|
347 self.encounter_data[instance_token] = self.encounter_data[instance_token] or {}
|
jcallahan@214
|
348 self.encounter_data[instance_token].stats = self.encounter_data[instance_token].stats or {}
|
jcallahan@214
|
349
|
jcallahan@214
|
350 return self.encounter_data
|
jcallahan@214
|
351 end
|
jcallahan@214
|
352
|
jcallahan@22
|
353 end
|
jcallahan@22
|
354
|
jcallahan@22
|
355
|
jcallahan@1
|
356 local function CurrentLocationData()
|
jcallahan@161
|
357 if _G.GetCurrentMapAreaID() ~= current_area_id then
|
jcallahan@145
|
358 return _G.GetRealZoneText(), current_area_id, 0, 0, 0, InstanceDifficultyToken()
|
jcallahan@145
|
359 end
|
jcallahan@1
|
360 local map_level = _G.GetCurrentMapDungeonLevel() or 0
|
jcallahan@1
|
361 local x, y = _G.GetPlayerMapPosition("player")
|
jcallahan@1
|
362
|
jcallahan@1
|
363 x = x or 0
|
jcallahan@1
|
364 y = y or 0
|
jcallahan@1
|
365
|
jcallahan@1
|
366 if x == 0 and y == 0 then
|
jcallahan@1
|
367 for level_index = 1, _G.GetNumDungeonMapLevels() do
|
jcallahan@1
|
368 _G.SetDungeonMapLevel(level_index)
|
jcallahan@1
|
369 x, y = _G.GetPlayerMapPosition("player")
|
jcallahan@1
|
370
|
jcallahan@1
|
371 if x and y and (x > 0 or y > 0) then
|
jcallahan@1
|
372 _G.SetDungeonMapLevel(map_level)
|
jcallahan@1
|
373 map_level = level_index
|
jcallahan@1
|
374 break
|
jcallahan@1
|
375 end
|
jcallahan@1
|
376 end
|
jcallahan@1
|
377 end
|
jcallahan@1
|
378
|
jcallahan@1
|
379 if _G.DungeonUsesTerrainMap() then
|
jcallahan@1
|
380 map_level = map_level - 1
|
jcallahan@1
|
381 end
|
jcallahan@31
|
382 local x = _G.floor(x * 1000)
|
jcallahan@31
|
383 local y = _G.floor(y * 1000)
|
jcallahan@28
|
384
|
jcallahan@31
|
385 if x % 2 ~= 0 then
|
jcallahan@31
|
386 x = x + 1
|
jcallahan@28
|
387 end
|
jcallahan@28
|
388
|
jcallahan@31
|
389 if y % 2 ~= 0 then
|
jcallahan@31
|
390 y = y + 1
|
jcallahan@28
|
391 end
|
jcallahan@126
|
392 return _G.GetRealZoneText(), current_area_id, x, y, map_level, InstanceDifficultyToken()
|
jcallahan@1
|
393 end
|
jcallahan@1
|
394
|
jcallahan@1
|
395
|
jcallahan@1
|
396 local function ItemLinkToID(item_link)
|
jcallahan@1
|
397 if not item_link then
|
jcallahan@1
|
398 return
|
jcallahan@1
|
399 end
|
jcallahan@7
|
400 return tonumber(item_link:match("item:(%d+)"))
|
jcallahan@1
|
401 end
|
jcallahan@0
|
402
|
jcallahan@4
|
403
|
jcallahan@171
|
404 local function UnitTypeIsNPC(unit_type)
|
jcallahan@171
|
405 return unit_type == private.UNIT_TYPES.NPC or unit_type == private.UNIT_TYPES.VEHICLE
|
jcallahan@171
|
406 end
|
jcallahan@171
|
407
|
jcallahan@171
|
408
|
jcallahan@34
|
409 local ParseGUID
|
jcallahan@4
|
410 do
|
jcallahan@4
|
411 local UNIT_TYPE_BITMASK = 0x007
|
jcallahan@4
|
412
|
jcallahan@34
|
413 function ParseGUID(guid)
|
jcallahan@5
|
414 if not guid then
|
jcallahan@5
|
415 return
|
jcallahan@5
|
416 end
|
jcallahan@4
|
417 local types = private.UNIT_TYPES
|
jcallahan@4
|
418 local unit_type = _G.bit.band(tonumber(guid:sub(1, 5)), UNIT_TYPE_BITMASK)
|
jcallahan@4
|
419
|
jcallahan@10
|
420 if unit_type ~= types.PLAYER and unit_type ~= types.PET then
|
jcallahan@66
|
421 return unit_type, tonumber(guid:sub(6, 10), 16)
|
jcallahan@4
|
422 end
|
jcallahan@4
|
423 return unit_type
|
jcallahan@4
|
424 end
|
jcallahan@4
|
425 end -- do-block
|
jcallahan@4
|
426
|
jcallahan@4
|
427
|
jcallahan@128
|
428 local function UpdateBlacklistMaps()
|
jcallahan@128
|
429 local empty_count = 0
|
jcallahan@128
|
430
|
jcallahan@128
|
431 for index = 1, _G.MAX_BLACKLIST_BATTLEGROUNDS do
|
jcallahan@128
|
432 local map_id = _G.GetBlacklistMap(index)
|
jcallahan@128
|
433 char_db.bg_blacklist = char_db.bg_blacklist or {}
|
jcallahan@128
|
434 char_db.bg_blacklist[index] = map_id
|
jcallahan@128
|
435
|
jcallahan@128
|
436 if map_id < 0 then
|
jcallahan@128
|
437 empty_count = empty_count + 1
|
jcallahan@143
|
438 empty_count = empty_count + 1
|
jcallahan@128
|
439 end
|
jcallahan@128
|
440 end
|
jcallahan@128
|
441
|
jcallahan@128
|
442 if empty_count == _G.MAX_BLACKLIST_BATTLEGROUNDS then
|
jcallahan@128
|
443 char_db.bg_blacklist = nil
|
jcallahan@128
|
444 end
|
jcallahan@128
|
445 end
|
jcallahan@128
|
446
|
jcallahan@128
|
447
|
jcallahan@141
|
448 local UpdateDBEntryLocation
|
jcallahan@141
|
449 do
|
jcallahan@141
|
450 local pi = math.pi
|
jcallahan@141
|
451
|
jcallahan@141
|
452 -- Fishing node coordinate code based on code in GatherMate2 with permission from Kagaro.
|
jcallahan@141
|
453 local function FishingCoordinates(x, y, yard_width, yard_height)
|
jcallahan@141
|
454 local facing = _G.GetPlayerFacing()
|
jcallahan@141
|
455
|
jcallahan@141
|
456 if not facing then
|
jcallahan@141
|
457 return x, y
|
jcallahan@141
|
458 end
|
jcallahan@141
|
459 local rad = facing + pi
|
jcallahan@141
|
460 return x + math.sin(rad) * 15 / yard_width, y + math.cos(rad) * 15 / yard_height
|
jcallahan@10
|
461 end
|
jcallahan@10
|
462
|
jcallahan@24
|
463
|
jcallahan@141
|
464 function UpdateDBEntryLocation(entry_type, identifier)
|
jcallahan@141
|
465 if not identifier then
|
jcallahan@141
|
466 return
|
jcallahan@141
|
467 end
|
jcallahan@141
|
468 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData()
|
jcallahan@141
|
469 local entry = DBEntry(entry_type, identifier)
|
jcallahan@141
|
470 entry[difficulty_token] = entry[difficulty_token] or {}
|
jcallahan@141
|
471 entry[difficulty_token].locations = entry[difficulty_token].locations or {}
|
jcallahan@141
|
472
|
jcallahan@141
|
473 local zone_token = ("%s:%d"):format(zone_name, area_id)
|
jcallahan@141
|
474 local zone_data = entry[difficulty_token].locations[zone_token]
|
jcallahan@141
|
475
|
jcallahan@141
|
476 if not zone_data then
|
jcallahan@141
|
477 zone_data = {}
|
jcallahan@141
|
478 entry[difficulty_token].locations[zone_token] = zone_data
|
jcallahan@141
|
479 end
|
jcallahan@141
|
480
|
jcallahan@141
|
481 -- Special case for Fishing.
|
jcallahan@141
|
482 if current_action.spell_label == "FISHING" then
|
jcallahan@141
|
483 local yard_width, yard_height = MapData:MapArea(area_id, map_level)
|
jcallahan@141
|
484
|
jcallahan@141
|
485 if yard_width > 0 and yard_height > 0 then
|
jcallahan@141
|
486 x, y = FishingCoordinates(x, y, yard_width, yard_height)
|
jcallahan@141
|
487 current_action.x = x
|
jcallahan@141
|
488 current_action.y = y
|
jcallahan@141
|
489 end
|
jcallahan@141
|
490 end
|
jcallahan@141
|
491 local location_token = ("%d:%d:%d"):format(map_level, x, y)
|
jcallahan@141
|
492
|
jcallahan@141
|
493 zone_data[location_token] = zone_data[location_token] or true
|
jcallahan@141
|
494 return zone_data
|
jcallahan@10
|
495 end
|
jcallahan@141
|
496 end -- do-block
|
jcallahan@10
|
497
|
jcallahan@10
|
498
|
jcallahan@19
|
499 local function HandleItemUse(item_link, bag_index, slot_index)
|
jcallahan@19
|
500 if not item_link then
|
jcallahan@19
|
501 return
|
jcallahan@19
|
502 end
|
jcallahan@19
|
503 local item_id = ItemLinkToID(item_link)
|
jcallahan@19
|
504
|
jcallahan@19
|
505 if not bag_index or not slot_index then
|
jcallahan@19
|
506 for new_bag_index = 0, _G.NUM_BAG_FRAMES do
|
jcallahan@19
|
507 for new_slot_index = 1, _G.GetContainerNumSlots(new_bag_index) do
|
jcallahan@19
|
508 if item_id == ItemLinkToID(_G.GetContainerItemLink(new_bag_index, new_slot_index)) then
|
jcallahan@19
|
509 bag_index = new_bag_index
|
jcallahan@19
|
510 slot_index = new_slot_index
|
jcallahan@19
|
511 break
|
jcallahan@19
|
512 end
|
jcallahan@19
|
513 end
|
jcallahan@19
|
514 end
|
jcallahan@19
|
515 end
|
jcallahan@19
|
516
|
jcallahan@19
|
517 if not bag_index or not slot_index then
|
jcallahan@19
|
518 return
|
jcallahan@19
|
519 end
|
jcallahan@19
|
520 local _, _, _, _, _, is_lootable = _G.GetContainerItemInfo(bag_index, slot_index)
|
jcallahan@19
|
521
|
jcallahan@19
|
522 if not is_lootable then
|
jcallahan@19
|
523 return
|
jcallahan@19
|
524 end
|
jcallahan@19
|
525 DatamineTT:ClearLines()
|
jcallahan@19
|
526 DatamineTT:SetBagItem(bag_index, slot_index)
|
jcallahan@19
|
527
|
jcallahan@19
|
528 for line_index = 1, DatamineTT:NumLines() do
|
jcallahan@19
|
529 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@19
|
530
|
jcallahan@19
|
531 if not current_line then
|
jcallahan@19
|
532 break
|
jcallahan@19
|
533 end
|
jcallahan@19
|
534
|
jcallahan@19
|
535 if current_line:GetText() == _G.ITEM_OPENABLE then
|
jcallahan@122
|
536 table.wipe(current_action)
|
jcallahan@123
|
537 current_action.target_type = AF.ITEM
|
jcallahan@122
|
538 current_action.identifier = item_id
|
jcallahan@122
|
539 current_action.loot_label = "contains"
|
jcallahan@19
|
540 break
|
jcallahan@19
|
541 end
|
jcallahan@19
|
542 end
|
jcallahan@19
|
543 end
|
jcallahan@19
|
544
|
jcallahan@19
|
545
|
jcallahan@39
|
546 local UnitFactionStanding
|
jcallahan@32
|
547 local UpdateFactionData
|
jcallahan@32
|
548 do
|
jcallahan@32
|
549 local MAX_FACTION_INDEX = 1000
|
jcallahan@20
|
550
|
jcallahan@32
|
551 local STANDING_NAMES = {
|
jcallahan@32
|
552 "HATED",
|
jcallahan@32
|
553 "HOSTILE",
|
jcallahan@32
|
554 "UNFRIENDLY",
|
jcallahan@32
|
555 "NEUTRAL",
|
jcallahan@32
|
556 "FRIENDLY",
|
jcallahan@32
|
557 "HONORED",
|
jcallahan@32
|
558 "REVERED",
|
jcallahan@32
|
559 "EXALTED",
|
jcallahan@32
|
560 }
|
jcallahan@32
|
561
|
jcallahan@39
|
562
|
jcallahan@39
|
563 function UnitFactionStanding(unit)
|
jcallahan@135
|
564 local unit_name = _G.UnitName(unit)
|
jcallahan@39
|
565 UpdateFactionData()
|
jcallahan@39
|
566 DatamineTT:ClearLines()
|
jcallahan@39
|
567 DatamineTT:SetUnit(unit)
|
jcallahan@39
|
568
|
jcallahan@39
|
569 for line_index = 1, DatamineTT:NumLines() do
|
jcallahan@64
|
570 local faction_name = _G["WDPDatamineTTTextLeft" .. line_index]:GetText():trim()
|
jcallahan@39
|
571
|
jcallahan@135
|
572 if faction_name and faction_name ~= unit_name and faction_standings[faction_name] then
|
jcallahan@39
|
573 return faction_name, faction_standings[faction_name]
|
jcallahan@39
|
574 end
|
jcallahan@39
|
575 end
|
jcallahan@39
|
576 end
|
jcallahan@39
|
577
|
jcallahan@39
|
578
|
jcallahan@32
|
579 function UpdateFactionData()
|
jcallahan@32
|
580 for faction_index = 1, MAX_FACTION_INDEX do
|
jcallahan@32
|
581 local faction_name, _, current_standing, _, _, _, _, _, is_header = _G.GetFactionInfo(faction_index)
|
jcallahan@32
|
582
|
jcallahan@86
|
583 if faction_name then
|
jcallahan@32
|
584 faction_standings[faction_name] = STANDING_NAMES[current_standing]
|
jcallahan@32
|
585 elseif not faction_name then
|
jcallahan@32
|
586 break
|
jcallahan@32
|
587 end
|
jcallahan@20
|
588 end
|
jcallahan@20
|
589 end
|
jcallahan@32
|
590 end -- do-block
|
jcallahan@20
|
591
|
jcallahan@48
|
592
|
jcallahan@75
|
593 local GenericLootUpdate
|
jcallahan@75
|
594 do
|
jcallahan@77
|
595 local function LootTable(entry, loot_type, top_field)
|
jcallahan@75
|
596 if top_field then
|
jcallahan@75
|
597 entry[top_field] = entry[top_field] or {}
|
jcallahan@75
|
598 entry[top_field][loot_type] = entry[top_field][loot_type] or {}
|
jcallahan@75
|
599 return entry[top_field][loot_type]
|
jcallahan@75
|
600 end
|
jcallahan@48
|
601 entry[loot_type] = entry[loot_type] or {}
|
jcallahan@75
|
602 return entry[loot_type]
|
jcallahan@48
|
603 end
|
jcallahan@48
|
604
|
jcallahan@75
|
605 function GenericLootUpdate(data_type, top_field)
|
jcallahan@132
|
606 local loot_type = current_loot.label
|
jcallahan@75
|
607 local loot_count = ("%s_count"):format(loot_type)
|
jcallahan@77
|
608 local source_list = {}
|
jcallahan@75
|
609
|
jcallahan@131
|
610 if current_loot.sources then
|
jcallahan@131
|
611 for source_guid, loot_data in pairs(current_loot.sources) do
|
jcallahan@119
|
612 local entry, source_id
|
jcallahan@78
|
613
|
jcallahan@131
|
614 if current_loot.target_type == AF.ITEM then
|
jcallahan@182
|
615 -- Debug(("GenericLootUpdate: current_loot.identifier: '%s'"):format(tostring(current_loot.identifier)))
|
jcallahan@119
|
616 -- Items return the player as the source, so we need to use the item's ID (disenchant, milling, etc)
|
jcallahan@131
|
617 source_id = current_loot.identifier
|
jcallahan@119
|
618 entry = DBEntry(data_type, source_id)
|
jcallahan@131
|
619 elseif current_loot.target_type == AF.OBJECT then
|
jcallahan@131
|
620 source_id = ("%s:%s"):format(current_loot.spell_label, select(2, ParseGUID(source_guid)))
|
jcallahan@119
|
621 entry = DBEntry(data_type, source_id)
|
jcallahan@119
|
622 else
|
jcallahan@119
|
623 source_id = select(2, ParseGUID(source_guid))
|
jcallahan@119
|
624 entry = DBEntry(data_type, source_id)
|
jcallahan@119
|
625 end
|
jcallahan@75
|
626
|
jcallahan@119
|
627 if entry then
|
jcallahan@119
|
628 local loot_table = LootTable(entry, loot_type, top_field)
|
jcallahan@77
|
629
|
jcallahan@119
|
630 if not source_list[source_guid] then
|
jcallahan@119
|
631 if top_field then
|
jcallahan@119
|
632 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1
|
jcallahan@119
|
633 else
|
jcallahan@119
|
634 entry[loot_count] = (entry[loot_count] or 0) + 1
|
jcallahan@119
|
635 end
|
jcallahan@119
|
636 source_list[source_guid] = true
|
jcallahan@77
|
637 end
|
jcallahan@119
|
638 UpdateDBEntryLocation(data_type, source_id)
|
jcallahan@75
|
639
|
jcallahan@119
|
640 for item_id, quantity in pairs(loot_data) do
|
jcallahan@119
|
641 table.insert(loot_table, ("%d:%d"):format(item_id, quantity))
|
jcallahan@119
|
642 end
|
jcallahan@75
|
643 end
|
jcallahan@75
|
644 end
|
jcallahan@75
|
645 end
|
jcallahan@121
|
646
|
jcallahan@121
|
647 -- This is used for Gas Extractions.
|
jcallahan@131
|
648 if #current_loot.list <= 0 then
|
jcallahan@78
|
649 return
|
jcallahan@78
|
650 end
|
jcallahan@82
|
651 local entry
|
jcallahan@82
|
652
|
jcallahan@82
|
653 -- At this point we only have a name if it's an object.
|
jcallahan@131
|
654 if current_loot.target_type == AF.OBJECT then
|
jcallahan@131
|
655 entry = DBEntry(data_type, ("%s:%s"):format(current_loot.spell_label, current_loot.object_name))
|
jcallahan@82
|
656 else
|
jcallahan@131
|
657 entry = DBEntry(data_type, current_loot.identifier)
|
jcallahan@82
|
658 end
|
jcallahan@75
|
659
|
jcallahan@75
|
660 if not entry then
|
jcallahan@75
|
661 return
|
jcallahan@75
|
662 end
|
jcallahan@77
|
663 local loot_table = LootTable(entry, loot_type, top_field)
|
jcallahan@77
|
664
|
jcallahan@131
|
665 if not source_list[current_loot.identifier] then
|
jcallahan@77
|
666 if top_field then
|
jcallahan@77
|
667 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1
|
jcallahan@77
|
668 else
|
jcallahan@77
|
669 entry[loot_count] = (entry[loot_count] or 0) + 1
|
jcallahan@77
|
670 end
|
jcallahan@77
|
671 end
|
jcallahan@75
|
672
|
jcallahan@131
|
673 for index = 1, #current_loot.list do
|
jcallahan@131
|
674 table.insert(loot_table, current_loot.list[index])
|
jcallahan@75
|
675 end
|
jcallahan@48
|
676 end
|
jcallahan@75
|
677 end -- do-block
|
jcallahan@48
|
678
|
jcallahan@97
|
679
|
jcallahan@97
|
680 local ReplaceKeywords
|
jcallahan@97
|
681 do
|
jcallahan@97
|
682 local KEYWORD_SUBSTITUTIONS = {
|
jcallahan@97
|
683 class = PLAYER_CLASS,
|
jcallahan@97
|
684 name = PLAYER_NAME,
|
jcallahan@97
|
685 race = PLAYER_RACE,
|
jcallahan@97
|
686 }
|
jcallahan@97
|
687
|
jcallahan@97
|
688
|
jcallahan@97
|
689 function ReplaceKeywords(text)
|
jcallahan@97
|
690 if not text or text == "" then
|
jcallahan@97
|
691 return ""
|
jcallahan@97
|
692 end
|
jcallahan@97
|
693
|
jcallahan@97
|
694 for category, lookup in pairs(KEYWORD_SUBSTITUTIONS) do
|
jcallahan@97
|
695 local category_format = ("<%s>"):format(category)
|
jcallahan@97
|
696 text = text:gsub(lookup, category_format):gsub(lookup:lower(), category_format)
|
jcallahan@97
|
697 end
|
jcallahan@97
|
698 return text
|
jcallahan@97
|
699 end
|
jcallahan@97
|
700 end -- do-block
|
jcallahan@97
|
701
|
jcallahan@97
|
702
|
jcallahan@154
|
703 -- Contains a dirty hack due to Blizzard's strange handling of Micro Dungeons; GetMapInfo() will not return correct information
|
jcallahan@154
|
704 -- unless the WorldMapFrame is shown.
|
jcallahan@143
|
705 do
|
jcallahan@143
|
706 -- MapFileName = MapAreaID
|
jcallahan@143
|
707 local MICRO_DUNGEON_IDS = {
|
jcallahan@143
|
708 ShrineofTwoMoons = 903,
|
jcallahan@143
|
709 ShrineofSevenStars = 905,
|
jcallahan@143
|
710 }
|
jcallahan@126
|
711
|
jcallahan@143
|
712 function WDP:SetCurrentAreaID(event_name)
|
jcallahan@156
|
713 if private.in_combat then
|
jcallahan@156
|
714 private.set_area_id = true
|
jcallahan@156
|
715 return
|
jcallahan@156
|
716 end
|
jcallahan@155
|
717 local map_area_id = _G.GetCurrentMapAreaID()
|
jcallahan@155
|
718
|
jcallahan@155
|
719 if map_area_id == current_area_id then
|
jcallahan@155
|
720 return
|
jcallahan@155
|
721 end
|
jcallahan@143
|
722 local world_map = _G.WorldMapFrame
|
jcallahan@143
|
723 local map_visible = world_map:IsVisible()
|
jcallahan@143
|
724 local sfx_value = _G.tonumber(_G.GetCVar("Sound_EnableSFX"))
|
jcallahan@143
|
725
|
jcallahan@143
|
726 if not map_visible then
|
jcallahan@143
|
727 _G.SetCVar("Sound_EnableSFX", 0)
|
jcallahan@143
|
728 world_map:Show()
|
jcallahan@143
|
729 end
|
jcallahan@143
|
730 local micro_dungeon_id = MICRO_DUNGEON_IDS[select(5, _G.GetMapInfo())]
|
jcallahan@143
|
731
|
jcallahan@154
|
732 _G.SetMapToCurrentZone()
|
jcallahan@154
|
733
|
jcallahan@143
|
734 if micro_dungeon_id then
|
jcallahan@143
|
735 current_area_id = micro_dungeon_id
|
jcallahan@143
|
736 else
|
jcallahan@143
|
737 current_area_id = _G.GetCurrentMapAreaID()
|
jcallahan@143
|
738 end
|
jcallahan@143
|
739
|
jcallahan@154
|
740 if map_visible then
|
jcallahan@154
|
741 _G.SetMapByID(map_area_id)
|
jcallahan@154
|
742 else
|
jcallahan@143
|
743 world_map:Hide()
|
jcallahan@143
|
744 _G.SetCVar("Sound_EnableSFX", sfx_value)
|
jcallahan@143
|
745 end
|
jcallahan@143
|
746 end
|
jcallahan@154
|
747 end
|
jcallahan@126
|
748
|
jcallahan@0
|
749 -----------------------------------------------------------------------
|
jcallahan@0
|
750 -- Methods.
|
jcallahan@0
|
751 -----------------------------------------------------------------------
|
jcallahan@0
|
752 function WDP:OnInitialize()
|
jcallahan@128
|
753 local db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default")
|
jcallahan@128
|
754 global_db = db.global
|
jcallahan@128
|
755 char_db = db.char
|
jcallahan@14
|
756
|
jcallahan@14
|
757 local raw_db = _G["WoWDBProfilerData"]
|
jcallahan@18
|
758 local build_num = tonumber(private.build_num)
|
jcallahan@14
|
759
|
jcallahan@136
|
760 if (raw_db.version and raw_db.version < DB_VERSION) or (raw_db.build_num and raw_db.build_num < build_num) then
|
jcallahan@74
|
761 for entry in pairs(DATABASE_DEFAULTS.global) do
|
jcallahan@128
|
762 global_db[entry] = {}
|
jcallahan@74
|
763 end
|
jcallahan@74
|
764 end
|
jcallahan@35
|
765 raw_db.build_num = build_num
|
jcallahan@63
|
766 raw_db.version = DB_VERSION
|
jcallahan@0
|
767 end
|
jcallahan@0
|
768
|
jcallahan@0
|
769
|
jcallahan@153
|
770 function WDP:EventDispatcher(...)
|
jcallahan@153
|
771 local event_name = ...
|
jcallahan@153
|
772
|
jcallahan@153
|
773 if DEBUGGING then
|
jcallahan@154
|
774 if event_name == "COMBAT_LOG_EVENT_UNFILTERED" then
|
jcallahan@154
|
775 Debug(event_name)
|
jcallahan@154
|
776 else
|
jcallahan@154
|
777 Debug(...)
|
jcallahan@153
|
778 end
|
jcallahan@153
|
779 end
|
jcallahan@153
|
780 local func = EVENT_MAPPING[event_name]
|
jcallahan@153
|
781
|
jcallahan@153
|
782 if _G.type(func) == "boolean" then
|
jcallahan@153
|
783 self[event_name](self, ...)
|
jcallahan@153
|
784 elseif _G.type(func) == "function" then
|
jcallahan@159
|
785 self[func](self, ...)
|
jcallahan@153
|
786 end
|
jcallahan@153
|
787 end
|
jcallahan@153
|
788
|
jcallahan@153
|
789
|
jcallahan@0
|
790 function WDP:OnEnable()
|
jcallahan@0
|
791 for event_name, mapping in pairs(EVENT_MAPPING) do
|
jcallahan@156
|
792 if EVENT_DEBUG then
|
jcallahan@153
|
793 self:RegisterEvent(event_name, "EventDispatcher")
|
jcallahan@153
|
794 else
|
jcallahan@153
|
795 self:RegisterEvent(event_name, (_G.type(mapping) ~= "boolean") and mapping or nil)
|
jcallahan@153
|
796 end
|
jcallahan@0
|
797 end
|
jcallahan@95
|
798
|
jcallahan@95
|
799 for index = 1, _G.GetNumLanguages() do
|
jcallahan@95
|
800 languages_known[_G.GetLanguageByIndex(index)] = true
|
jcallahan@95
|
801 end
|
jcallahan@187
|
802 item_process_timer_handle = self:ScheduleRepeatingTimer("ProcessItems", 30)
|
jcallahan@31
|
803 target_location_timer_handle = self:ScheduleRepeatingTimer("UpdateTargetLocation", 0.5)
|
jcallahan@19
|
804
|
jcallahan@19
|
805 _G.hooksecurefunc("UseContainerItem", function(bag_index, slot_index, target_unit)
|
jcallahan@19
|
806 if target_unit then
|
jcallahan@19
|
807 return
|
jcallahan@19
|
808 end
|
jcallahan@19
|
809 HandleItemUse(_G.GetContainerItemLink(bag_index, slot_index), bag_index, slot_index)
|
jcallahan@19
|
810 end)
|
jcallahan@19
|
811
|
jcallahan@19
|
812 _G.hooksecurefunc("UseItemByName", function(identifier, target_unit)
|
jcallahan@19
|
813 if target_unit then
|
jcallahan@19
|
814 return
|
jcallahan@19
|
815 end
|
jcallahan@19
|
816 local _, item_link = _G.GetItemInfo(identifier)
|
jcallahan@19
|
817 HandleItemUse(item_link)
|
jcallahan@19
|
818 end)
|
jcallahan@129
|
819 self:SetCurrentAreaID("OnEnable")
|
jcallahan@126
|
820
|
jcallahan@128
|
821 _G.hooksecurefunc("SetBlacklistMap", UpdateBlacklistMaps)
|
jcallahan@128
|
822 _G.hooksecurefunc("ClearBlacklistMap", UpdateBlacklistMaps)
|
jcallahan@128
|
823
|
jcallahan@128
|
824 UpdateBlacklistMaps()
|
jcallahan@0
|
825 end
|
jcallahan@0
|
826
|
jcallahan@0
|
827
|
jcallahan@187
|
828 local function RecordItemData(item_id, item_link, durability)
|
jcallahan@187
|
829 local item = DBEntry("items", item_id)
|
jcallahan@191
|
830 local item_string = select(3, item_link:find("^|%x+|H(.+)|h%[.+%]"))
|
jcallahan@0
|
831
|
jcallahan@191
|
832 if item_string then
|
jcallahan@199
|
833 local _, _, _, _, _, _, _, suffix_id, unique_id, _, _, upgrade_id = (":"):split(item_string)
|
jcallahan@201
|
834 suffix_id = tonumber(suffix_id)
|
jcallahan@199
|
835
|
jcallahan@201
|
836 if suffix_id and suffix_id ~= 0 then
|
jcallahan@201
|
837 item.suffix_id = suffix_id
|
jcallahan@201
|
838 item.unique_id = bit.band(unique_id, 0xFFFF)
|
jcallahan@201
|
839 end
|
jcallahan@191
|
840
|
jcallahan@191
|
841 if upgrade_id then
|
jcallahan@191
|
842 item.upgrade_id = upgrade_id
|
jcallahan@191
|
843 end
|
jcallahan@0
|
844 end
|
jcallahan@212
|
845
|
jcallahan@212
|
846 if durability and durability > 0 then
|
jcallahan@212
|
847 item.durability = durability
|
jcallahan@212
|
848 end
|
jcallahan@0
|
849 end
|
jcallahan@0
|
850
|
jcallahan@0
|
851
|
jcallahan@187
|
852 function WDP:ProcessItems()
|
jcallahan@187
|
853 for slot_index = _G.INVSLOT_FIRST_EQUIPPED, _G.INVSLOT_LAST_EQUIPPED do
|
jcallahan@1
|
854 local item_id = _G.GetInventoryItemID("player", slot_index)
|
jcallahan@0
|
855
|
jcallahan@0
|
856 if item_id and item_id > 0 then
|
jcallahan@1
|
857 local _, max_durability = _G.GetInventoryItemDurability(slot_index)
|
jcallahan@187
|
858 RecordItemData(item_id, _G.GetInventoryItemLink("player", slot_index), max_durability)
|
jcallahan@0
|
859 end
|
jcallahan@0
|
860 end
|
jcallahan@0
|
861
|
jcallahan@0
|
862 for bag_index = 0, _G.NUM_BAG_SLOTS do
|
jcallahan@0
|
863 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
|
jcallahan@1
|
864 local item_id = _G.GetContainerItemID(bag_index, slot_index)
|
jcallahan@0
|
865
|
jcallahan@0
|
866 if item_id and item_id > 0 then
|
jcallahan@1
|
867 local _, max_durability = _G.GetContainerItemDurability(bag_index, slot_index)
|
jcallahan@187
|
868 RecordItemData(item_id, _G.GetContainerItemLink(bag_index, slot_index), max_durability)
|
jcallahan@0
|
869 end
|
jcallahan@0
|
870 end
|
jcallahan@0
|
871 end
|
jcallahan@0
|
872 end
|
jcallahan@0
|
873
|
jcallahan@118
|
874
|
jcallahan@215
|
875 local TargetedNPC
|
jcallahan@118
|
876 do
|
jcallahan@118
|
877 local GENDER_NAMES = {
|
jcallahan@118
|
878 "UNKNOWN",
|
jcallahan@118
|
879 "MALE",
|
jcallahan@118
|
880 "FEMALE",
|
jcallahan@118
|
881 }
|
jcallahan@118
|
882
|
jcallahan@118
|
883
|
jcallahan@118
|
884 local REACTION_NAMES = {
|
jcallahan@118
|
885 "HATED",
|
jcallahan@118
|
886 "HOSTILE",
|
jcallahan@118
|
887 "UNFRIENDLY",
|
jcallahan@118
|
888 "NEUTRAL",
|
jcallahan@118
|
889 "FRIENDLY",
|
jcallahan@118
|
890 "HONORED",
|
jcallahan@118
|
891 "REVERED",
|
jcallahan@118
|
892 "EXALTED",
|
jcallahan@118
|
893 }
|
jcallahan@118
|
894
|
jcallahan@118
|
895
|
jcallahan@118
|
896 local POWER_TYPE_NAMES = {
|
jcallahan@118
|
897 ["0"] = "MANA",
|
jcallahan@118
|
898 ["1"] = "RAGE",
|
jcallahan@118
|
899 ["2"] = "FOCUS",
|
jcallahan@118
|
900 ["3"] = "ENERGY",
|
jcallahan@118
|
901 ["6"] = "RUNIC_POWER",
|
jcallahan@118
|
902 }
|
jcallahan@118
|
903
|
jcallahan@118
|
904
|
jcallahan@215
|
905 function TargetedNPC()
|
jcallahan@118
|
906 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or currently_drunk then
|
jcallahan@118
|
907 current_target_id = nil
|
jcallahan@118
|
908 return
|
jcallahan@118
|
909 end
|
jcallahan@118
|
910 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@118
|
911
|
jcallahan@171
|
912 if not unit_idnum or not UnitTypeIsNPC(unit_type) then
|
jcallahan@118
|
913 return
|
jcallahan@118
|
914 end
|
jcallahan@118
|
915 current_target_id = unit_idnum
|
jcallahan@118
|
916
|
jcallahan@118
|
917 local npc = NPCEntry(unit_idnum)
|
jcallahan@118
|
918 local _, class_token = _G.UnitClass("target")
|
jcallahan@118
|
919 npc.class = class_token
|
jcallahan@118
|
920 npc.faction = UnitFactionStanding("target")
|
jcallahan@118
|
921 npc.genders = npc.genders or {}
|
jcallahan@118
|
922 npc.genders[GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"] = true
|
jcallahan@118
|
923 npc.is_pvp = _G.UnitIsPVP("target") and true or nil
|
jcallahan@118
|
924 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")])
|
jcallahan@118
|
925
|
jcallahan@214
|
926 local encounter_data = npc:EncounterData()[InstanceDifficultyToken()].stats
|
jcallahan@118
|
927 local npc_level = ("level_%d"):format(_G.UnitLevel("target"))
|
jcallahan@118
|
928
|
jcallahan@118
|
929 if not encounter_data[npc_level] then
|
jcallahan@118
|
930 encounter_data[npc_level] = {
|
jcallahan@118
|
931 max_health = _G.UnitHealthMax("target"),
|
jcallahan@118
|
932 }
|
jcallahan@118
|
933
|
jcallahan@118
|
934 local max_power = _G.UnitManaMax("target")
|
jcallahan@118
|
935
|
jcallahan@118
|
936 if max_power > 0 then
|
jcallahan@118
|
937 local power_type = _G.UnitPowerType("target")
|
jcallahan@118
|
938 encounter_data[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power)
|
jcallahan@118
|
939 end
|
jcallahan@118
|
940 end
|
jcallahan@118
|
941 name_to_id_map[_G.UnitName("target")] = unit_idnum
|
jcallahan@118
|
942 return npc, unit_idnum
|
jcallahan@118
|
943 end
|
jcallahan@118
|
944 end -- do-block
|
jcallahan@118
|
945
|
jcallahan@118
|
946
|
jcallahan@113
|
947 do
|
jcallahan@113
|
948 local COORD_MAX = 5
|
jcallahan@0
|
949
|
jcallahan@113
|
950 function WDP:UpdateTargetLocation()
|
jcallahan@113
|
951 if currently_drunk or not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or (_G.UnitIsTapped("target") and not _G.UnitIsDead("target")) then
|
jcallahan@2
|
952 return
|
jcallahan@2
|
953 end
|
jcallahan@113
|
954
|
jcallahan@113
|
955 for index = 1, 4 do
|
jcallahan@113
|
956 if not _G.CheckInteractDistance("target", index) then
|
jcallahan@113
|
957 return
|
jcallahan@113
|
958 end
|
jcallahan@113
|
959 end
|
jcallahan@215
|
960 local npc = TargetedNPC()
|
jcallahan@113
|
961
|
jcallahan@113
|
962 if not npc then
|
jcallahan@113
|
963 return
|
jcallahan@113
|
964 end
|
jcallahan@113
|
965 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData()
|
jcallahan@214
|
966 local npc_data = npc:EncounterData()[difficulty_token].stats[("level_%d"):format(_G.UnitLevel("target"))]
|
jcallahan@113
|
967 local zone_token = ("%s:%d"):format(zone_name, area_id)
|
jcallahan@118
|
968 npc_data.locations = npc_data.locations or {} -- TODO: Fix this. It is broken. Possibly something to do with the timed updates.
|
jcallahan@113
|
969
|
jcallahan@113
|
970 local zone_data = npc_data.locations[zone_token]
|
jcallahan@113
|
971
|
jcallahan@113
|
972 if not zone_data then
|
jcallahan@113
|
973 zone_data = {}
|
jcallahan@113
|
974 npc_data.locations[zone_token] = zone_data
|
jcallahan@113
|
975 end
|
jcallahan@113
|
976
|
jcallahan@113
|
977 for location_token in pairs(zone_data) do
|
jcallahan@113
|
978 local loc_level, loc_x, loc_y = (":"):split(location_token)
|
jcallahan@113
|
979 loc_level = tonumber(loc_level)
|
jcallahan@113
|
980
|
jcallahan@113
|
981 if map_level == loc_level and math.abs(x - loc_x) <= COORD_MAX and math.abs(y - loc_y) <= COORD_MAX then
|
jcallahan@113
|
982 return
|
jcallahan@113
|
983 end
|
jcallahan@113
|
984 end
|
jcallahan@141
|
985 zone_data[("%d:%d:%d"):format(map_level, x, y)] = true
|
jcallahan@2
|
986 end
|
jcallahan@113
|
987 end -- do-block
|
jcallahan@2
|
988
|
jcallahan@118
|
989
|
jcallahan@0
|
990 -----------------------------------------------------------------------
|
jcallahan@0
|
991 -- Event handlers.
|
jcallahan@0
|
992 -----------------------------------------------------------------------
|
jcallahan@90
|
993 function WDP:BLACK_MARKET_ITEM_UPDATE(event_name)
|
jcallahan@56
|
994 local num_items = _G.C_BlackMarket.GetNumItems()
|
jcallahan@56
|
995
|
jcallahan@56
|
996 for index = 1, num_items do
|
jcallahan@56
|
997 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
|
998
|
jcallahan@56
|
999 if item_link then
|
jcallahan@56
|
1000 DBEntry("items", ItemLinkToID(item_link)).black_market = seller_name or "UNKNOWN"
|
jcallahan@56
|
1001 end
|
jcallahan@56
|
1002 end
|
jcallahan@56
|
1003 end
|
jcallahan@56
|
1004
|
jcallahan@56
|
1005
|
jcallahan@178
|
1006 function WDP:SHOW_LOOT_TOAST(event_name, loot_type, item_link, quantity)
|
jcallahan@178
|
1007 if loot_type ~= "item" then
|
jcallahan@178
|
1008 return
|
jcallahan@178
|
1009 end
|
jcallahan@203
|
1010 local npc = NPCEntry(private.raid_finder_boss_id or private.world_boss_id)
|
jcallahan@216
|
1011 ClearKilledBossID()
|
jcallahan@178
|
1012
|
jcallahan@178
|
1013 if not npc then
|
jcallahan@182
|
1014 Debug(("%s: NPC is nil."):format(event_name))
|
jcallahan@178
|
1015 return
|
jcallahan@178
|
1016 end
|
jcallahan@178
|
1017 local item_id = ItemLinkToID(item_link)
|
jcallahan@178
|
1018
|
jcallahan@178
|
1019 if not item_id then
|
jcallahan@182
|
1020 Debug(("%s: ItemID is nil, from item link %s"):format(event_name, item_link))
|
jcallahan@178
|
1021 return
|
jcallahan@178
|
1022 end
|
jcallahan@179
|
1023 local loot_type = "drops"
|
jcallahan@214
|
1024 local encounter_data = npc:EncounterData()[InstanceDifficultyToken()]
|
jcallahan@178
|
1025 encounter_data[loot_type] = encounter_data[loot_type] or {}
|
jcallahan@178
|
1026 encounter_data.loot_counts = encounter_data.loot_counts or {}
|
jcallahan@178
|
1027 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1
|
jcallahan@178
|
1028
|
jcallahan@178
|
1029 table.insert(encounter_data[loot_type], ("%d:%d"):format(item_id, quantity))
|
jcallahan@182
|
1030 Debug(("%s: %sX%d (%d)"):format(event_name, item_link, quantity, item_id))
|
jcallahan@178
|
1031 end
|
jcallahan@178
|
1032
|
jcallahan@178
|
1033
|
jcallahan@179
|
1034 do
|
jcallahan@179
|
1035 local CHAT_MSG_LOOT_UPDATE_FUNCS = {
|
jcallahan@179
|
1036 [AF.NPC] = function(item_id, quantity)
|
jcallahan@179
|
1037 Debug(("CHAT_MSG_LOOT: %d (%d)"):format(item_id, quantity))
|
jcallahan@179
|
1038 end,
|
jcallahan@179
|
1039 [AF.ZONE] = function(item_id, quantity)
|
jcallahan@179
|
1040 current_loot = {
|
jcallahan@179
|
1041 list = {
|
jcallahan@179
|
1042 ("%d:%d"):format(item_id, quantity)
|
jcallahan@179
|
1043 },
|
jcallahan@179
|
1044 identifier = current_action.identifier,
|
jcallahan@179
|
1045 label = current_action.loot_label or "drops",
|
jcallahan@179
|
1046 map_level = current_action.map_level,
|
jcallahan@179
|
1047 object_name = current_action.object_name,
|
jcallahan@179
|
1048 spell_label = current_action.spell_label,
|
jcallahan@179
|
1049 target_type = current_action.target_type,
|
jcallahan@179
|
1050 x = current_action.x,
|
jcallahan@179
|
1051 y = current_action.y,
|
jcallahan@179
|
1052 zone_data = current_action.zone_data,
|
jcallahan@179
|
1053 }
|
jcallahan@179
|
1054 table.wipe(current_action)
|
jcallahan@179
|
1055 GenericLootUpdate("zones")
|
jcallahan@179
|
1056 end,
|
jcallahan@179
|
1057 }
|
jcallahan@177
|
1058
|
jcallahan@177
|
1059
|
jcallahan@179
|
1060 function WDP:CHAT_MSG_LOOT(event_name, message)
|
jcallahan@179
|
1061 local category
|
jcallahan@177
|
1062
|
jcallahan@179
|
1063 if current_action.spell_label ~= "EXTRACT_GAS" then
|
jcallahan@179
|
1064 category = AF.ZONE
|
jcallahan@179
|
1065 elseif private.raid_finder_boss_id then
|
jcallahan@179
|
1066 category = AF.NPC
|
jcallahan@179
|
1067 end
|
jcallahan@179
|
1068 local update_func = CHAT_MSG_LOOT_UPDATE_FUNCS[category]
|
jcallahan@177
|
1069
|
jcallahan@179
|
1070 if not category or not update_func then
|
jcallahan@179
|
1071 return
|
jcallahan@179
|
1072 end
|
jcallahan@179
|
1073 local item_link, quantity = deformat(message, _G.LOOT_ITEM_PUSHED_SELF_MULTIPLE)
|
jcallahan@179
|
1074
|
jcallahan@179
|
1075 if not item_link then
|
jcallahan@179
|
1076 quantity, item_link = 1, deformat(message, _G.LOOT_ITEM_PUSHED_SELF)
|
jcallahan@179
|
1077 end
|
jcallahan@179
|
1078 local item_id = ItemLinkToID(item_link)
|
jcallahan@179
|
1079
|
jcallahan@179
|
1080 if not item_id then
|
jcallahan@179
|
1081 return
|
jcallahan@179
|
1082 end
|
jcallahan@179
|
1083 update_func(item_id, quantity)
|
jcallahan@177
|
1084 end
|
jcallahan@48
|
1085 end
|
jcallahan@48
|
1086
|
jcallahan@97
|
1087 function WDP:RecordQuote(event_name, message, source_name, language_name)
|
jcallahan@112
|
1088 if not ALLOWED_LOCALES[CLIENT_LOCALE] or not source_name or not name_to_id_map[source_name] or (language_name ~= "" and not languages_known[language_name]) then
|
jcallahan@97
|
1089 return
|
jcallahan@95
|
1090 end
|
jcallahan@97
|
1091 local npc = NPCEntry(name_to_id_map[source_name])
|
jcallahan@97
|
1092 npc.quotes = npc.quotes or {}
|
jcallahan@97
|
1093 npc.quotes[event_name] = npc.quotes[event_name] or {}
|
jcallahan@97
|
1094 npc.quotes[event_name][ReplaceKeywords(message)] = true
|
jcallahan@97
|
1095 end
|
jcallahan@95
|
1096
|
jcallahan@95
|
1097
|
jcallahan@95
|
1098 do
|
jcallahan@40
|
1099 local SOBER_MATCH = _G.DRUNK_MESSAGE_ITEM_SELF1:gsub("%%s", ".+")
|
jcallahan@40
|
1100
|
jcallahan@40
|
1101 local DRUNK_COMPARES = {
|
jcallahan@40
|
1102 _G.DRUNK_MESSAGE_SELF2,
|
jcallahan@40
|
1103 _G.DRUNK_MESSAGE_SELF3,
|
jcallahan@40
|
1104 _G.DRUNK_MESSAGE_SELF4,
|
jcallahan@40
|
1105 }
|
jcallahan@40
|
1106
|
jcallahan@40
|
1107 local DRUNK_MATCHES = {
|
jcallahan@40
|
1108 _G.DRUNK_MESSAGE_SELF2:gsub("%%s", ".+"),
|
jcallahan@40
|
1109 _G.DRUNK_MESSAGE_SELF3:gsub("%%s", ".+"),
|
jcallahan@40
|
1110 _G.DRUNK_MESSAGE_SELF4:gsub("%%s", ".+"),
|
jcallahan@40
|
1111 }
|
jcallahan@40
|
1112
|
jcallahan@167
|
1113 local RECIPE_MATCH = _G.ERR_LEARN_RECIPE_S:gsub("%%s", "(.*)")
|
jcallahan@167
|
1114
|
jcallahan@167
|
1115
|
jcallahan@167
|
1116 local function RecordDiscovery(tradeskill_name, tradeskill_index)
|
jcallahan@167
|
1117 if tradeskill_name == private.discovered_recipe_name then
|
jcallahan@167
|
1118 DBEntry("spells", tonumber(_G.GetTradeSkillRecipeLink(tradeskill_index):match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)"))).discovery = ("%d:%d"):format(private.previous_spell_id, private.profession_level)
|
jcallahan@167
|
1119
|
jcallahan@167
|
1120 private.discovered_recipe_name = nil
|
jcallahan@167
|
1121 private.profession_level = nil
|
jcallahan@167
|
1122 private.previous_spell_id = nil
|
jcallahan@169
|
1123
|
jcallahan@169
|
1124 return true
|
jcallahan@167
|
1125 end
|
jcallahan@167
|
1126 end
|
jcallahan@167
|
1127
|
jcallahan@167
|
1128
|
jcallahan@167
|
1129 local function IterativeRecordDiscovery()
|
jcallahan@167
|
1130 TradeSkillExecutePer(RecordDiscovery)
|
jcallahan@167
|
1131 end
|
jcallahan@167
|
1132
|
jcallahan@167
|
1133
|
jcallahan@92
|
1134 function WDP:CHAT_MSG_SYSTEM(event_name, message)
|
jcallahan@167
|
1135 if not private.trainer_shown then
|
jcallahan@167
|
1136 local recipe_name = message:match(RECIPE_MATCH)
|
jcallahan@167
|
1137
|
jcallahan@167
|
1138 if recipe_name and private.previous_spell_id then
|
jcallahan@167
|
1139 local profession_name, prof_level = _G.GetTradeSkillLine()
|
jcallahan@167
|
1140
|
jcallahan@167
|
1141 if profession_name == _G.UNKNOWN then
|
jcallahan@167
|
1142 return
|
jcallahan@167
|
1143 end
|
jcallahan@167
|
1144 private.discovered_recipe_name = recipe_name
|
jcallahan@167
|
1145 private.profession_level = prof_level
|
jcallahan@167
|
1146
|
jcallahan@167
|
1147 self:ScheduleTimer(IterativeRecordDiscovery, 0.2)
|
jcallahan@167
|
1148 end
|
jcallahan@167
|
1149 end
|
jcallahan@167
|
1150
|
jcallahan@40
|
1151 if currently_drunk then
|
jcallahan@40
|
1152 if message == _G.DRUNK_MESSAGE_SELF1 or message:match(SOBER_MATCH) then
|
jcallahan@40
|
1153 currently_drunk = nil
|
jcallahan@40
|
1154 end
|
jcallahan@40
|
1155 return
|
jcallahan@40
|
1156 end
|
jcallahan@40
|
1157
|
jcallahan@40
|
1158 for index = 1, #DRUNK_MATCHES do
|
jcallahan@40
|
1159 if message == DRUNK_COMPARES[index] or message:match(DRUNK_MATCHES[index]) then
|
jcallahan@40
|
1160 currently_drunk = true
|
jcallahan@40
|
1161 break
|
jcallahan@40
|
1162 end
|
jcallahan@40
|
1163 end
|
jcallahan@40
|
1164 end
|
jcallahan@40
|
1165 end
|
jcallahan@40
|
1166
|
jcallahan@40
|
1167 -- do-block
|
jcallahan@40
|
1168
|
jcallahan@40
|
1169 do
|
jcallahan@23
|
1170 local FLAGS_NPC = bit.bor(_G.COMBATLOG_OBJECT_TYPE_GUARDIAN, _G.COMBATLOG_OBJECT_CONTROL_NPC)
|
jcallahan@23
|
1171 local FLAGS_NPC_CONTROL = bit.bor(_G.COMBATLOG_OBJECT_AFFILIATION_OUTSIDER, _G.COMBATLOG_OBJECT_CONTROL_NPC)
|
jcallahan@23
|
1172
|
jcallahan@23
|
1173 local function RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
|
jcallahan@23
|
1174 if not spell_id then
|
jcallahan@23
|
1175 return
|
jcallahan@23
|
1176 end
|
jcallahan@34
|
1177 local source_type, source_id = ParseGUID(source_guid)
|
jcallahan@23
|
1178
|
jcallahan@171
|
1179 if not source_id or not UnitTypeIsNPC(source_type) then
|
jcallahan@23
|
1180 return
|
jcallahan@23
|
1181 end
|
jcallahan@23
|
1182
|
jcallahan@23
|
1183 if bit.band(FLAGS_NPC_CONTROL, source_flags) == FLAGS_NPC_CONTROL and bit.band(FLAGS_NPC, source_flags) ~= 0 then
|
jcallahan@214
|
1184 local encounter_data = NPCEntry(source_id):EncounterData()[InstanceDifficultyToken()]
|
jcallahan@28
|
1185 encounter_data.spells = encounter_data.spells or {}
|
jcallahan@28
|
1186 encounter_data.spells[spell_id] = (encounter_data.spells[spell_id] or 0) + 1
|
jcallahan@23
|
1187 end
|
jcallahan@23
|
1188 end
|
jcallahan@23
|
1189
|
jcallahan@115
|
1190 local HEAL_BATTLE_PETS_SPELL_ID = 125801
|
jcallahan@115
|
1191
|
jcallahan@23
|
1192 local COMBAT_LOG_FUNCS = {
|
jcallahan@23
|
1193 SPELL_AURA_APPLIED = RecordNPCSpell,
|
jcallahan@23
|
1194 SPELL_CAST_START = RecordNPCSpell,
|
jcallahan@115
|
1195 SPELL_CAST_SUCCESS = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
|
jcallahan@115
|
1196 if spell_id == HEAL_BATTLE_PETS_SPELL_ID then
|
jcallahan@115
|
1197 local unit_type, unit_idnum = ParseGUID(source_guid)
|
jcallahan@115
|
1198
|
jcallahan@171
|
1199 if unit_idnum and UnitTypeIsNPC(unit_type) then
|
jcallahan@115
|
1200 NPCEntry(unit_idnum).stable_master = true
|
jcallahan@115
|
1201 end
|
jcallahan@115
|
1202 end
|
jcallahan@115
|
1203 RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
|
jcallahan@115
|
1204 end,
|
jcallahan@65
|
1205 UNIT_DIED = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
|
jcallahan@65
|
1206 local unit_type, unit_idnum = ParseGUID(dest_guid)
|
jcallahan@65
|
1207
|
jcallahan@171
|
1208 if not unit_idnum or not UnitTypeIsNPC(unit_type) then
|
jcallahan@182
|
1209 Debug(("%s: %s is not an NPC, or has no ID."):format(sub_event, dest_name))
|
jcallahan@177
|
1210 ClearKilledNPC()
|
jcallahan@216
|
1211 ClearKilledBossID()
|
jcallahan@98
|
1212 private.harvesting = nil
|
jcallahan@65
|
1213 return
|
jcallahan@65
|
1214 end
|
jcallahan@177
|
1215
|
jcallahan@217
|
1216 if dest_guid ~= _G.UnitGUID("target") then
|
jcallahan@217
|
1217 ClearKilledNPC()
|
jcallahan@217
|
1218 ClearKilledBossID()
|
jcallahan@217
|
1219 return
|
jcallahan@217
|
1220 end
|
jcallahan@217
|
1221
|
jcallahan@177
|
1222 if private.RAID_FINDER_BOSS_IDS[unit_idnum] then
|
jcallahan@184
|
1223 Debug(("%s: Matching boss %s."):format(sub_event, dest_name))
|
jcallahan@216
|
1224 ClearKilledBossID()
|
jcallahan@184
|
1225 private.raid_finder_boss_id = unit_idnum
|
jcallahan@203
|
1226 elseif private.WORLD_BOSS_IDS[unit_idnum] then
|
jcallahan@203
|
1227 Debug(("%s: Matching world boss %s."):format(sub_event, dest_name))
|
jcallahan@216
|
1228 ClearKilledBossID()
|
jcallahan@203
|
1229 private.world_boss_id = unit_idnum
|
jcallahan@182
|
1230 else
|
jcallahan@203
|
1231 Debug(("%s: Killed NPC %s (ID: %d) is not in LFG or World boss list."):format(sub_event, dest_name, unit_idnum))
|
jcallahan@177
|
1232 end
|
jcallahan@183
|
1233
|
jcallahan@177
|
1234 killed_npc_id = unit_idnum
|
jcallahan@177
|
1235 WDP:ScheduleTimer(ClearKilledNPC, 0.1)
|
jcallahan@203
|
1236 WDP:ScheduleTimer(ClearKilledBossID, 1)
|
jcallahan@65
|
1237 end,
|
jcallahan@23
|
1238 }
|
jcallahan@23
|
1239
|
jcallahan@23
|
1240
|
jcallahan@92
|
1241 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
|
1242 local combat_log_func = COMBAT_LOG_FUNCS[sub_event]
|
jcallahan@23
|
1243
|
jcallahan@23
|
1244 if not combat_log_func then
|
jcallahan@23
|
1245 return
|
jcallahan@23
|
1246 end
|
jcallahan@23
|
1247 combat_log_func(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, ...)
|
jcallahan@23
|
1248 end
|
jcallahan@23
|
1249
|
jcallahan@44
|
1250 local DIPLOMACY_SPELL_ID = 20599
|
jcallahan@44
|
1251 local MR_POP_RANK1_SPELL_ID = 78634
|
jcallahan@44
|
1252 local MR_POP_RANK2_SPELL_ID = 78635
|
jcallahan@44
|
1253
|
jcallahan@44
|
1254 local REP_BUFFS = {
|
jcallahan@44
|
1255 [_G.GetSpellInfo(30754)] = "CENARION_FAVOR",
|
jcallahan@44
|
1256 [_G.GetSpellInfo(24705)] = "GRIM_VISAGE",
|
jcallahan@44
|
1257 [_G.GetSpellInfo(32098)] = "HONOR_HOLD_FAVOR",
|
jcallahan@44
|
1258 [_G.GetSpellInfo(39913)] = "NAZGRELS_FERVOR",
|
jcallahan@44
|
1259 [_G.GetSpellInfo(39953)] = "SONG_OF_BATTLE",
|
jcallahan@44
|
1260 [_G.GetSpellInfo(61849)] = "SPIRIT_OF_SHARING",
|
jcallahan@44
|
1261 [_G.GetSpellInfo(32096)] = "THRALLMARS_FAVOR",
|
jcallahan@44
|
1262 [_G.GetSpellInfo(39911)] = "TROLLBANES_COMMAND",
|
jcallahan@44
|
1263 [_G.GetSpellInfo(95987)] = "UNBURDENED",
|
jcallahan@44
|
1264 [_G.GetSpellInfo(100951)] = "WOW_ANNIVERSARY",
|
jcallahan@44
|
1265 }
|
jcallahan@44
|
1266
|
jcallahan@44
|
1267
|
jcallahan@44
|
1268 local FACTION_NAMES = {
|
jcallahan@44
|
1269 CENARION_CIRCLE = _G.GetFactionInfoByID(609),
|
jcallahan@44
|
1270 HONOR_HOLD = _G.GetFactionInfoByID(946),
|
jcallahan@44
|
1271 THE_SHATAR = _G.GetFactionInfoByID(935),
|
jcallahan@44
|
1272 THRALLMAR = _G.GetFactionInfoByID(947),
|
jcallahan@44
|
1273 }
|
jcallahan@44
|
1274
|
jcallahan@44
|
1275
|
jcallahan@44
|
1276 local MODIFIERS = {
|
jcallahan@44
|
1277 CENARION_FAVOR = {
|
jcallahan@44
|
1278 faction = FACTION_NAMES.CENARION_CIRCLE,
|
jcallahan@44
|
1279 modifier = 0.25,
|
jcallahan@44
|
1280 },
|
jcallahan@44
|
1281 GRIM_VISAGE = {
|
jcallahan@44
|
1282 modifier = 0.1,
|
jcallahan@44
|
1283 },
|
jcallahan@44
|
1284 HONOR_HOLD_FAVOR = {
|
jcallahan@44
|
1285 faction = FACTION_NAMES.HONOR_HOLD,
|
jcallahan@44
|
1286 modifier = 0.25,
|
jcallahan@44
|
1287 },
|
jcallahan@44
|
1288 NAZGRELS_FERVOR = {
|
jcallahan@44
|
1289 faction = FACTION_NAMES.THRALLMAR,
|
jcallahan@44
|
1290 modifier = 0.1,
|
jcallahan@44
|
1291 },
|
jcallahan@44
|
1292 SONG_OF_BATTLE = {
|
jcallahan@44
|
1293 faction = FACTION_NAMES.THE_SHATAR,
|
jcallahan@44
|
1294 modifier = 0.1,
|
jcallahan@44
|
1295 },
|
jcallahan@44
|
1296 SPIRIT_OF_SHARING = {
|
jcallahan@44
|
1297 modifier = 0.1,
|
jcallahan@44
|
1298 },
|
jcallahan@44
|
1299 THRALLMARS_FAVOR = {
|
jcallahan@44
|
1300 faction = FACTION_NAMES.THRALLMAR,
|
jcallahan@44
|
1301 modifier = 0.25,
|
jcallahan@44
|
1302 },
|
jcallahan@44
|
1303 TROLLBANES_COMMAND = {
|
jcallahan@44
|
1304 faction = FACTION_NAMES.HONOR_HOLD,
|
jcallahan@44
|
1305 modifier = 0.1,
|
jcallahan@44
|
1306 },
|
jcallahan@44
|
1307 UNBURDENED = {
|
jcallahan@44
|
1308 modifier = 0.1,
|
jcallahan@44
|
1309 },
|
jcallahan@44
|
1310 WOW_ANNIVERSARY = {
|
jcallahan@44
|
1311 modifier = 0.08,
|
jcallahan@44
|
1312 }
|
jcallahan@44
|
1313 }
|
jcallahan@44
|
1314
|
jcallahan@44
|
1315
|
jcallahan@92
|
1316 function WDP:COMBAT_TEXT_UPDATE(event_name, message_type, faction_name, amount)
|
jcallahan@177
|
1317 if message_type ~= "FACTION" or not killed_npc_id then
|
jcallahan@44
|
1318 return
|
jcallahan@44
|
1319 end
|
jcallahan@44
|
1320 UpdateFactionData()
|
jcallahan@44
|
1321
|
jcallahan@46
|
1322 if not faction_name or not faction_standings[faction_name] then
|
jcallahan@46
|
1323 return
|
jcallahan@46
|
1324 end
|
jcallahan@177
|
1325 local npc = NPCEntry(killed_npc_id)
|
jcallahan@177
|
1326 ClearKilledNPC()
|
jcallahan@46
|
1327
|
jcallahan@44
|
1328 if not npc then
|
jcallahan@98
|
1329 private.harvesting = nil
|
jcallahan@44
|
1330 return
|
jcallahan@44
|
1331 end
|
jcallahan@98
|
1332 npc.harvested = private.harvesting
|
jcallahan@98
|
1333 private.harvesting = nil
|
jcallahan@98
|
1334
|
jcallahan@44
|
1335 local modifier = 1
|
jcallahan@44
|
1336
|
jcallahan@44
|
1337 if _G.IsSpellKnown(DIPLOMACY_SPELL_ID) then
|
jcallahan@44
|
1338 modifier = modifier + 0.1
|
jcallahan@44
|
1339 end
|
jcallahan@44
|
1340
|
jcallahan@44
|
1341 if _G.IsSpellKnown(MR_POP_RANK2_SPELL_ID) then
|
jcallahan@44
|
1342 modifier = modifier + 0.1
|
jcallahan@44
|
1343 elseif _G.IsSpellKnown(MR_POP_RANK1_SPELL_ID) then
|
jcallahan@44
|
1344 modifier = modifier + 0.05
|
jcallahan@44
|
1345 end
|
jcallahan@44
|
1346
|
jcallahan@44
|
1347 for buff_name, buff_label in pairs(REP_BUFFS) do
|
jcallahan@44
|
1348 if _G.UnitBuff("player", buff_name) then
|
jcallahan@44
|
1349 local modded_faction = MODIFIERS[buff_label].faction
|
jcallahan@44
|
1350
|
jcallahan@44
|
1351 if not modded_faction or faction_name == modded_faction then
|
jcallahan@44
|
1352 modifier = modifier + MODIFIERS[buff_label].modifier
|
jcallahan@44
|
1353 end
|
jcallahan@44
|
1354 end
|
jcallahan@44
|
1355 end
|
jcallahan@65
|
1356 npc.reputations = npc.reputations or {}
|
jcallahan@65
|
1357 npc.reputations[("%s:%s"):format(faction_name, faction_standings[faction_name])] = math.floor(amount / modifier)
|
jcallahan@32
|
1358 end
|
jcallahan@44
|
1359 end -- do-block
|
jcallahan@18
|
1360
|
jcallahan@18
|
1361
|
jcallahan@140
|
1362 function WDP:CURSOR_UPDATE(event_name)
|
jcallahan@141
|
1363 if current_action.fishing_target or _G.Minimap:IsMouseOver() or current_action.spell_label ~= "FISHING" then
|
jcallahan@140
|
1364 return
|
jcallahan@140
|
1365 end
|
jcallahan@140
|
1366 local text = _G["GameTooltipTextLeft1"]:GetText()
|
jcallahan@140
|
1367
|
jcallahan@140
|
1368 if not text or text == "Fishing Bobber" then
|
jcallahan@140
|
1369 text = "NONE"
|
jcallahan@140
|
1370 else
|
jcallahan@140
|
1371 current_action.fishing_target = true
|
jcallahan@140
|
1372 end
|
jcallahan@140
|
1373 current_action.identifier = ("%s:%s"):format(current_action.spell_label, text)
|
jcallahan@140
|
1374 end
|
jcallahan@140
|
1375
|
jcallahan@140
|
1376
|
jcallahan@92
|
1377 function WDP:ITEM_TEXT_BEGIN(event_name)
|
jcallahan@42
|
1378 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
|
jcallahan@42
|
1379
|
jcallahan@42
|
1380 if not unit_idnum or unit_type ~= private.UNIT_TYPES.OBJECT or _G.UnitName("npc") ~= _G.ItemTextGetItem() then
|
jcallahan@42
|
1381 return
|
jcallahan@42
|
1382 end
|
jcallahan@42
|
1383 UpdateDBEntryLocation("objects", unit_idnum)
|
jcallahan@42
|
1384 end
|
jcallahan@42
|
1385
|
jcallahan@42
|
1386
|
jcallahan@13
|
1387 do
|
jcallahan@40
|
1388 local RE_GOLD = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@40
|
1389 local RE_SILVER = _G.SILVER_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@40
|
1390 local RE_COPPER = _G.COPPER_AMOUNT:gsub("%%d", "(%%d+)")
|
jcallahan@13
|
1391
|
jcallahan@13
|
1392
|
jcallahan@13
|
1393 local function _moneyMatch(money, re)
|
jcallahan@13
|
1394 return money:match(re) or 0
|
jcallahan@1
|
1395 end
|
jcallahan@1
|
1396
|
jcallahan@0
|
1397
|
jcallahan@13
|
1398 local function _toCopper(money)
|
jcallahan@13
|
1399 if not money then
|
jcallahan@13
|
1400 return 0
|
jcallahan@13
|
1401 end
|
jcallahan@40
|
1402 return _moneyMatch(money, RE_GOLD) * 10000 + _moneyMatch(money, RE_SILVER) * 100 + _moneyMatch(money, RE_COPPER)
|
jcallahan@1
|
1403 end
|
jcallahan@1
|
1404
|
jcallahan@1
|
1405
|
jcallahan@176
|
1406 local LOOT_OPENED_VERIFY_FUNCS = {
|
jcallahan@16
|
1407 [AF.ITEM] = function()
|
jcallahan@16
|
1408 local locked_item_id
|
jcallahan@16
|
1409
|
jcallahan@16
|
1410 for bag_index = 0, _G.NUM_BAG_FRAMES do
|
jcallahan@16
|
1411 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
|
jcallahan@16
|
1412 local _, _, is_locked = _G.GetContainerItemInfo(bag_index, slot_index)
|
jcallahan@16
|
1413
|
jcallahan@16
|
1414 if is_locked then
|
jcallahan@16
|
1415 locked_item_id = ItemLinkToID(_G.GetContainerItemLink(bag_index, slot_index))
|
jcallahan@165
|
1416 break
|
jcallahan@16
|
1417 end
|
jcallahan@16
|
1418 end
|
jcallahan@165
|
1419
|
jcallahan@165
|
1420 if locked_item_id then
|
jcallahan@165
|
1421 break
|
jcallahan@165
|
1422 end
|
jcallahan@16
|
1423 end
|
jcallahan@16
|
1424
|
jcallahan@122
|
1425 if not locked_item_id or (current_action.identifier and current_action.identifier ~= locked_item_id) then
|
jcallahan@16
|
1426 return false
|
jcallahan@16
|
1427 end
|
jcallahan@122
|
1428 current_action.identifier = locked_item_id
|
jcallahan@16
|
1429 return true
|
jcallahan@16
|
1430 end,
|
jcallahan@13
|
1431 [AF.NPC] = function()
|
jcallahan@17
|
1432 if not _G.UnitExists("target") or _G.UnitIsFriend("player", "target") or _G.UnitIsPlayer("target") or _G.UnitPlayerControlled("target") then
|
jcallahan@15
|
1433 return false
|
jcallahan@13
|
1434 end
|
jcallahan@205
|
1435
|
jcallahan@205
|
1436 if not current_action.identifier then
|
jcallahan@205
|
1437 local unit_type, id_num = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@205
|
1438 current_action.identifier = id_num
|
jcallahan@205
|
1439 end
|
jcallahan@13
|
1440 return true
|
jcallahan@13
|
1441 end,
|
jcallahan@14
|
1442 [AF.OBJECT] = true,
|
jcallahan@17
|
1443 [AF.ZONE] = function()
|
jcallahan@140
|
1444 current_action.zone_data = UpdateDBEntryLocation("zones", current_action.identifier)
|
jcallahan@210
|
1445 return _G.IsFishingLoot()
|
jcallahan@17
|
1446 end,
|
jcallahan@13
|
1447 }
|
jcallahan@13
|
1448
|
jcallahan@13
|
1449
|
jcallahan@176
|
1450 local LOOT_OPENED_UPDATE_FUNCS = {
|
jcallahan@16
|
1451 [AF.ITEM] = function()
|
jcallahan@28
|
1452 GenericLootUpdate("items")
|
jcallahan@28
|
1453 end,
|
jcallahan@28
|
1454 [AF.NPC] = function()
|
jcallahan@75
|
1455 local difficulty_token = InstanceDifficultyToken()
|
jcallahan@132
|
1456 local loot_type = current_loot.label
|
jcallahan@77
|
1457 local source_list = {}
|
jcallahan@75
|
1458
|
jcallahan@131
|
1459 for source_guid, loot_data in pairs(current_loot.sources) do
|
jcallahan@78
|
1460 local source_id = select(2, ParseGUID(source_guid))
|
jcallahan@75
|
1461 local npc = NPCEntry(source_id)
|
jcallahan@75
|
1462
|
jcallahan@75
|
1463 if npc then
|
jcallahan@214
|
1464 local encounter_data = npc:EncounterData()[difficulty_token]
|
jcallahan@75
|
1465 encounter_data[loot_type] = encounter_data[loot_type] or {}
|
jcallahan@75
|
1466
|
jcallahan@78
|
1467 if not source_list[source_guid] then
|
jcallahan@77
|
1468 encounter_data.loot_counts = encounter_data.loot_counts or {}
|
jcallahan@77
|
1469 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1
|
jcallahan@77
|
1470 source_list[source_id] = true
|
jcallahan@77
|
1471 end
|
jcallahan@77
|
1472
|
jcallahan@75
|
1473 for item_id, quantity in pairs(loot_data) do
|
jcallahan@75
|
1474 table.insert(encounter_data[loot_type], ("%d:%d"):format(item_id, quantity))
|
jcallahan@75
|
1475 end
|
jcallahan@75
|
1476 end
|
jcallahan@75
|
1477 end
|
jcallahan@75
|
1478
|
jcallahan@75
|
1479 -- TODO: Remove this when GetLootSourceInfo() has values for money
|
jcallahan@131
|
1480 if #current_loot.list <= 0 then
|
jcallahan@79
|
1481 return
|
jcallahan@79
|
1482 end
|
jcallahan@131
|
1483 local npc = NPCEntry(current_loot.identifier)
|
jcallahan@28
|
1484
|
jcallahan@28
|
1485 if not npc then
|
jcallahan@28
|
1486 return
|
jcallahan@28
|
1487 end
|
jcallahan@214
|
1488 local encounter_data = npc:EncounterData()[difficulty_token]
|
jcallahan@29
|
1489 encounter_data[loot_type] = encounter_data[loot_type] or {}
|
jcallahan@16
|
1490
|
jcallahan@131
|
1491 if not source_list[current_loot.identifier] then
|
jcallahan@77
|
1492 encounter_data.loot_counts = encounter_data.loot_counts or {}
|
jcallahan@77
|
1493 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1
|
jcallahan@77
|
1494 end
|
jcallahan@77
|
1495
|
jcallahan@131
|
1496 for index = 1, #current_loot.list do
|
jcallahan@131
|
1497 table.insert(encounter_data[loot_type], current_loot.list[index])
|
jcallahan@16
|
1498 end
|
jcallahan@16
|
1499 end,
|
jcallahan@13
|
1500 [AF.OBJECT] = function()
|
jcallahan@28
|
1501 GenericLootUpdate("objects", InstanceDifficultyToken())
|
jcallahan@17
|
1502 end,
|
jcallahan@17
|
1503 [AF.ZONE] = function()
|
jcallahan@141
|
1504 local location_token = ("%d:%d:%d"):format(current_loot.map_level, current_loot.x, current_loot.y)
|
jcallahan@41
|
1505
|
jcallahan@41
|
1506 -- This will start life as a boolean true.
|
jcallahan@131
|
1507 if _G.type(current_loot.zone_data[location_token]) ~= "table" then
|
jcallahan@131
|
1508 current_loot.zone_data[location_token] = {
|
jcallahan@41
|
1509 drops = {}
|
jcallahan@41
|
1510 }
|
jcallahan@41
|
1511 end
|
jcallahan@132
|
1512 local loot_count = ("%s_count"):format(current_loot.label)
|
jcallahan@131
|
1513 current_loot.zone_data[location_token][loot_count] = (current_loot.zone_data[location_token][loot_count] or 0) + 1
|
jcallahan@41
|
1514
|
jcallahan@131
|
1515 if current_loot.sources then
|
jcallahan@131
|
1516 for source_guid, loot_data in pairs(current_loot.sources) do
|
jcallahan@131
|
1517 for item_id, quantity in pairs(loot_data) do
|
jcallahan@131
|
1518 table.insert(current_loot.zone_data[location_token].drops, ("%d:%d"):format(item_id, quantity))
|
jcallahan@131
|
1519 end
|
jcallahan@131
|
1520 end
|
jcallahan@131
|
1521 end
|
jcallahan@131
|
1522
|
jcallahan@131
|
1523 if #current_loot.list <= 0 then
|
jcallahan@131
|
1524 return
|
jcallahan@131
|
1525 end
|
jcallahan@131
|
1526
|
jcallahan@131
|
1527 for index = 1, #current_loot.list do
|
jcallahan@131
|
1528 table.insert(current_loot.zone_data[location_token].drops, current_loot.loot_list[index])
|
jcallahan@41
|
1529 end
|
jcallahan@13
|
1530 end,
|
jcallahan@13
|
1531 }
|
jcallahan@13
|
1532
|
jcallahan@79
|
1533 -- Prevent opening the same loot window multiple times from recording data multiple times.
|
jcallahan@79
|
1534 local loot_guid_registry = {}
|
jcallahan@124
|
1535
|
jcallahan@124
|
1536
|
jcallahan@124
|
1537 function WDP:LOOT_CLOSED(event_name)
|
jcallahan@131
|
1538 current_loot = nil
|
jcallahan@131
|
1539 table.wipe(current_action)
|
jcallahan@124
|
1540 end
|
jcallahan@124
|
1541
|
jcallahan@13
|
1542
|
jcallahan@92
|
1543 function WDP:LOOT_OPENED(event_name)
|
jcallahan@132
|
1544 if current_loot then
|
jcallahan@18
|
1545 return
|
jcallahan@18
|
1546 end
|
jcallahan@151
|
1547
|
jcallahan@151
|
1548 if not current_action.target_type then
|
jcallahan@151
|
1549 return
|
jcallahan@151
|
1550 end
|
jcallahan@176
|
1551 local verify_func = LOOT_OPENED_VERIFY_FUNCS[current_action.target_type]
|
jcallahan@176
|
1552 local update_func = LOOT_OPENED_UPDATE_FUNCS[current_action.target_type]
|
jcallahan@13
|
1553
|
jcallahan@14
|
1554 if not verify_func or not update_func then
|
jcallahan@13
|
1555 return
|
jcallahan@13
|
1556 end
|
jcallahan@13
|
1557
|
jcallahan@14
|
1558 if _G.type(verify_func) == "function" and not verify_func() then
|
jcallahan@14
|
1559 return
|
jcallahan@14
|
1560 end
|
jcallahan@80
|
1561 local guids_used = {}
|
jcallahan@132
|
1562
|
jcallahan@131
|
1563 current_loot = {
|
jcallahan@131
|
1564 list = {},
|
jcallahan@131
|
1565 sources = {},
|
jcallahan@131
|
1566 identifier = current_action.identifier,
|
jcallahan@132
|
1567 label = current_action.loot_label or "drops",
|
jcallahan@131
|
1568 map_level = current_action.map_level,
|
jcallahan@131
|
1569 object_name = current_action.object_name,
|
jcallahan@131
|
1570 spell_label = current_action.spell_label,
|
jcallahan@131
|
1571 target_type = current_action.target_type,
|
jcallahan@131
|
1572 x = current_action.x,
|
jcallahan@131
|
1573 y = current_action.y,
|
jcallahan@131
|
1574 zone_data = current_action.zone_data,
|
jcallahan@131
|
1575 }
|
jcallahan@131
|
1576 table.wipe(current_action)
|
jcallahan@13
|
1577
|
jcallahan@217
|
1578 loot_guid_registry[current_loot.label] = loot_guid_registry[current_loot.label] or {}
|
jcallahan@217
|
1579
|
jcallahan@55
|
1580 for loot_slot = 1, _G.GetNumLootItems() do
|
jcallahan@55
|
1581 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
|
jcallahan@55
|
1582 local slot_type = _G.GetLootSlotType(loot_slot)
|
jcallahan@13
|
1583
|
jcallahan@77
|
1584 -- TODO: Move LOOT_SLOT_X checks within loop when money is detectable via GetLootSourceInfo
|
jcallahan@77
|
1585 if slot_type == _G.LOOT_SLOT_ITEM then
|
jcallahan@78
|
1586 local loot_info = {
|
jcallahan@77
|
1587 _G.GetLootSourceInfo(loot_slot)
|
jcallahan@77
|
1588 }
|
jcallahan@75
|
1589
|
jcallahan@77
|
1590 -- Odd index is GUID, even is count.
|
jcallahan@78
|
1591 for loot_index = 1, #loot_info, 2 do
|
jcallahan@78
|
1592 local source_guid = loot_info[loot_index]
|
jcallahan@77
|
1593
|
jcallahan@217
|
1594 if not loot_guid_registry[current_loot.label][source_guid] then
|
jcallahan@79
|
1595 local loot_quantity = loot_info[loot_index + 1]
|
jcallahan@79
|
1596 local source_type, source_id = ParseGUID(source_guid)
|
jcallahan@151
|
1597 local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id)
|
jcallahan@151
|
1598 Debug(("GUID: %s - Type:ID: %s - Amount: %d"):format(loot_info[loot_index], source_key, loot_quantity))
|
jcallahan@79
|
1599
|
jcallahan@79
|
1600 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
|
jcallahan@131
|
1601 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {}
|
jcallahan@131
|
1602 current_loot.sources[source_guid][item_id] = current_loot.sources[source_guid][item_id] or 0 + loot_quantity
|
jcallahan@80
|
1603 guids_used[source_guid] = true
|
jcallahan@79
|
1604 end
|
jcallahan@75
|
1605 end
|
jcallahan@82
|
1606 -- elseif slot_type == _G.LOOT_SLOT_MONEY then
|
jcallahan@122
|
1607 -- table.insert(current_action.loot_list, ("money:%d"):format(_toCopper(item_text)))
|
jcallahan@77
|
1608 elseif slot_type == _G.LOOT_SLOT_CURRENCY then
|
jcallahan@131
|
1609 table.insert(current_loot.list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
|
jcallahan@13
|
1610 end
|
jcallahan@13
|
1611 end
|
jcallahan@80
|
1612
|
jcallahan@81
|
1613 for guid in pairs(guids_used) do
|
jcallahan@217
|
1614 loot_guid_registry[current_loot.label][guid] = true
|
jcallahan@80
|
1615 end
|
jcallahan@13
|
1616 update_func()
|
jcallahan@1
|
1617 end
|
jcallahan@13
|
1618 end -- do-block
|
jcallahan@0
|
1619
|
jcallahan@0
|
1620
|
jcallahan@89
|
1621 function WDP:MAIL_SHOW(event_name)
|
jcallahan@89
|
1622 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
|
jcallahan@89
|
1623
|
jcallahan@89
|
1624 if not unit_idnum or unit_type ~= private.UNIT_TYPES.OBJECT then
|
jcallahan@89
|
1625 return
|
jcallahan@89
|
1626 end
|
jcallahan@89
|
1627 UpdateDBEntryLocation("objects", unit_idnum)
|
jcallahan@89
|
1628 end
|
jcallahan@89
|
1629
|
jcallahan@89
|
1630
|
jcallahan@44
|
1631 do
|
jcallahan@44
|
1632 local POINT_MATCH_PATTERNS = {
|
jcallahan@44
|
1633 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@44
|
1634 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@44
|
1635 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_5V5:gsub("%%d", "(%%d+)")), -- May no longer be necessary
|
jcallahan@44
|
1636 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_BG:gsub("%%d", "(%%d+)")),
|
jcallahan@44
|
1637 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3_BG:gsub("%%d", "(%%d+)")),
|
jcallahan@44
|
1638 }
|
jcallahan@5
|
1639
|
jcallahan@68
|
1640 local ITEM_REQ_REPUTATION_MATCH = "Requires (.-) %- (.*)"
|
jcallahan@87
|
1641 local ITEM_REQ_QUEST_MATCH1 = "Requires: .*"
|
jcallahan@87
|
1642 local ITEM_REQ_QUEST_MATCH2 = "Must have completed: .*"
|
jcallahan@68
|
1643
|
jcallahan@133
|
1644 local current_merchant
|
jcallahan@133
|
1645 local merchant_standing
|
jcallahan@133
|
1646
|
jcallahan@133
|
1647 function WDP:MERCHANT_CLOSED(event_name)
|
jcallahan@133
|
1648 current_merchant = nil
|
jcallahan@133
|
1649 merchant_standing = nil
|
jcallahan@133
|
1650 end
|
jcallahan@133
|
1651
|
jcallahan@133
|
1652
|
jcallahan@89
|
1653 function WDP:UpdateMerchantItems(event_name)
|
jcallahan@144
|
1654 if not current_merchant or event_name == "MERCHANT_SHOW" then
|
jcallahan@195
|
1655 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
|
jcallahan@4
|
1656
|
jcallahan@171
|
1657 if not unit_idnum or not UnitTypeIsNPC(unit_type) then
|
jcallahan@133
|
1658 return
|
jcallahan@133
|
1659 end
|
jcallahan@195
|
1660 merchant_standing = select(2, UnitFactionStanding("npc"))
|
jcallahan@133
|
1661 current_merchant = NPCEntry(unit_idnum)
|
jcallahan@133
|
1662 current_merchant.sells = current_merchant.sells or {}
|
jcallahan@44
|
1663 end
|
jcallahan@55
|
1664 local current_filters = _G.GetMerchantFilter()
|
jcallahan@57
|
1665 _G.SetMerchantFilter(_G.LE_LOOT_FILTER_ALL)
|
jcallahan@57
|
1666 _G.MerchantFrame_Update()
|
jcallahan@57
|
1667
|
jcallahan@150
|
1668 local num_items = _G.GetMerchantNumItems()
|
jcallahan@150
|
1669
|
jcallahan@44
|
1670 for item_index = 1, num_items do
|
jcallahan@44
|
1671 local _, _, copper_price, stack_size, num_available, _, extended_cost = _G.GetMerchantItemInfo(item_index)
|
jcallahan@44
|
1672 local item_id = ItemLinkToID(_G.GetMerchantItemLink(item_index))
|
jcallahan@5
|
1673
|
jcallahan@44
|
1674 if item_id and item_id > 0 then
|
jcallahan@44
|
1675 local price_string = ActualCopperCost(copper_price, merchant_standing)
|
jcallahan@5
|
1676
|
jcallahan@68
|
1677 DatamineTT:ClearLines()
|
jcallahan@68
|
1678 DatamineTT:SetMerchantItem(item_index)
|
jcallahan@68
|
1679
|
jcallahan@68
|
1680 local num_lines = DatamineTT:NumLines()
|
jcallahan@68
|
1681
|
jcallahan@68
|
1682 for line_index = 1, num_lines do
|
jcallahan@68
|
1683 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@68
|
1684
|
jcallahan@68
|
1685 if not current_line then
|
jcallahan@68
|
1686 break
|
jcallahan@68
|
1687 end
|
jcallahan@68
|
1688 local faction, reputation = current_line:GetText():match(ITEM_REQ_REPUTATION_MATCH)
|
jcallahan@68
|
1689
|
jcallahan@68
|
1690 if faction or reputation then
|
jcallahan@68
|
1691 DBEntry("items", item_id).req_reputation = ("%s:%s"):format(faction:gsub("-", ""), reputation:upper())
|
jcallahan@68
|
1692 break
|
jcallahan@68
|
1693 end
|
jcallahan@68
|
1694 end
|
jcallahan@68
|
1695
|
jcallahan@87
|
1696 for line_index = 1, num_lines do
|
jcallahan@87
|
1697 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@87
|
1698
|
jcallahan@87
|
1699 if not current_line then
|
jcallahan@87
|
1700 break
|
jcallahan@87
|
1701 end
|
jcallahan@87
|
1702 local line_text = current_line:GetText()
|
jcallahan@87
|
1703 local quest_name = line_text:match(ITEM_REQ_QUEST_MATCH1) or line_text:match(ITEM_REQ_QUEST_MATCH2)
|
jcallahan@87
|
1704
|
jcallahan@87
|
1705 if quest_name then
|
jcallahan@87
|
1706 DBEntry("items", item_id).req_quest = ("%s"):format(quest_name:gsub("(.+): ", ""), quest_name)
|
jcallahan@87
|
1707 break
|
jcallahan@87
|
1708 end
|
jcallahan@87
|
1709 end
|
jcallahan@87
|
1710
|
jcallahan@44
|
1711 if extended_cost then
|
jcallahan@53
|
1712 local battleground_rating = 0
|
jcallahan@53
|
1713 local personal_rating = 0
|
jcallahan@53
|
1714 local required_season_amount
|
jcallahan@5
|
1715
|
jcallahan@68
|
1716 for line_index = 1, num_lines do
|
jcallahan@44
|
1717 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
|
jcallahan@5
|
1718
|
jcallahan@44
|
1719 if not current_line then
|
jcallahan@44
|
1720 break
|
jcallahan@44
|
1721 end
|
jcallahan@53
|
1722 required_season_amount = current_line:GetText():match("Requires earning a total of (%d+)\n(.-) for the season.")
|
jcallahan@5
|
1723
|
jcallahan@44
|
1724 for match_index = 1, #POINT_MATCH_PATTERNS do
|
jcallahan@44
|
1725 local match1, match2 = current_line:GetText():match(POINT_MATCH_PATTERNS[match_index])
|
jcallahan@53
|
1726 personal_rating = personal_rating + (match1 or 0)
|
jcallahan@53
|
1727 battleground_rating = battleground_rating + (match2 or 0)
|
jcallahan@5
|
1728
|
jcallahan@44
|
1729 if match1 or match2 then
|
jcallahan@44
|
1730 break
|
jcallahan@44
|
1731 end
|
jcallahan@44
|
1732 end
|
jcallahan@5
|
1733 end
|
jcallahan@44
|
1734 local currency_list = {}
|
jcallahan@44
|
1735 local item_count = _G.GetMerchantItemCostInfo(item_index)
|
jcallahan@50
|
1736
|
jcallahan@50
|
1737 -- Keeping this around in case Blizzard makes the two points diverge at some point.
|
jcallahan@53
|
1738 -- price_string = ("%s:%s:%s:%s"):format(price_string, battleground_rating, personal_rating, required_season_amount or 0)
|
jcallahan@53
|
1739 price_string = ("%s:%s:%s"):format(price_string, personal_rating, required_season_amount or 0)
|
jcallahan@5
|
1740
|
jcallahan@44
|
1741 for cost_index = 1, item_count do
|
jcallahan@44
|
1742 local icon_texture, amount_required, currency_link = _G.GetMerchantItemCostItem(item_index, cost_index)
|
jcallahan@44
|
1743 local currency_id = currency_link and ItemLinkToID(currency_link) or nil
|
jcallahan@44
|
1744
|
jcallahan@44
|
1745 if (not currency_id or currency_id < 1) and icon_texture then
|
jcallahan@44
|
1746 currency_id = icon_texture:match("[^\\]+$"):lower()
|
jcallahan@44
|
1747 end
|
jcallahan@44
|
1748
|
jcallahan@44
|
1749 if currency_id then
|
jcallahan@44
|
1750 currency_list[#currency_list + 1] = ("(%s:%s)"):format(amount_required, currency_id)
|
jcallahan@44
|
1751 end
|
jcallahan@44
|
1752 end
|
jcallahan@44
|
1753
|
jcallahan@44
|
1754 for currency_index = 1, #currency_list do
|
jcallahan@44
|
1755 price_string = ("%s:%s"):format(price_string, currency_list[currency_index])
|
jcallahan@5
|
1756 end
|
jcallahan@5
|
1757 end
|
jcallahan@133
|
1758 current_merchant.sells[item_id] = ("%s:%s:[%s]"):format(num_available, stack_size, price_string)
|
jcallahan@44
|
1759 end
|
jcallahan@44
|
1760 end
|
jcallahan@5
|
1761
|
jcallahan@44
|
1762 if _G.CanMerchantRepair() then
|
jcallahan@133
|
1763 current_merchant.can_repair = true
|
jcallahan@5
|
1764 end
|
jcallahan@57
|
1765 _G.SetMerchantFilter(current_filters)
|
jcallahan@57
|
1766 _G.MerchantFrame_Update()
|
jcallahan@4
|
1767 end
|
jcallahan@44
|
1768 end -- do-block
|
jcallahan@4
|
1769
|
jcallahan@89
|
1770
|
jcallahan@92
|
1771 function WDP:PET_BAR_UPDATE(event_name)
|
jcallahan@122
|
1772 if current_action.spell_label ~= "MIND_CONTROL" then
|
jcallahan@25
|
1773 return
|
jcallahan@25
|
1774 end
|
jcallahan@34
|
1775 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("pet"))
|
jcallahan@25
|
1776
|
jcallahan@171
|
1777 if not unit_idnum or not UnitTypeIsNPC(unit_type) then
|
jcallahan@25
|
1778 return
|
jcallahan@25
|
1779 end
|
jcallahan@29
|
1780 NPCEntry(unit_idnum).mind_control = true
|
jcallahan@122
|
1781 table.wipe(current_action)
|
jcallahan@25
|
1782 end
|
jcallahan@25
|
1783
|
jcallahan@25
|
1784
|
jcallahan@115
|
1785 function WDP:PET_JOURNAL_LIST_UPDATE(event_name)
|
jcallahan@115
|
1786 local num_pets = LPJ:NumPets()
|
jcallahan@115
|
1787
|
jcallahan@115
|
1788 for index, pet_id in LPJ:IteratePetIDs() do
|
jcallahan@115
|
1789 local _, _, is_owned, _, level, _, _, name, icon, pet_type, npc_id, _, _, is_wild = _G.C_PetJournal.GetPetInfoByIndex(index)
|
jcallahan@115
|
1790
|
jcallahan@115
|
1791 if is_owned then
|
jcallahan@115
|
1792 local health, max_health, attack, speed, rarity = _G.C_PetJournal.GetPetStats(pet_id)
|
jcallahan@115
|
1793
|
jcallahan@139
|
1794 if rarity then
|
jcallahan@139
|
1795 local rarity_name = _G["BATTLE_PET_BREED_QUALITY" .. rarity]
|
jcallahan@139
|
1796 local npc = NPCEntry(npc_id)
|
jcallahan@139
|
1797 npc.wild_pet = is_wild or nil
|
jcallahan@139
|
1798 npc.battle_pet_data = npc.battle_pet_data or {}
|
jcallahan@139
|
1799 npc.battle_pet_data[rarity_name] = npc.battle_pet_data[rarity_name] or {}
|
jcallahan@139
|
1800 npc.battle_pet_data[rarity_name]["level_" .. level] = npc.battle_pet_data[rarity_name]["level_" .. level] or {}
|
jcallahan@139
|
1801
|
jcallahan@139
|
1802 local data = npc.battle_pet_data[rarity_name]["level_" .. level]
|
jcallahan@139
|
1803 data.max_health = max_health
|
jcallahan@139
|
1804 data.attack = attack
|
jcallahan@139
|
1805 data.speed = speed
|
jcallahan@139
|
1806 end
|
jcallahan@115
|
1807 end
|
jcallahan@115
|
1808 end
|
jcallahan@115
|
1809 end
|
jcallahan@115
|
1810
|
jcallahan@115
|
1811
|
jcallahan@156
|
1812 function WDP:PLAYER_REGEN_DISABLED(event_name)
|
jcallahan@156
|
1813 private.in_combat = true
|
jcallahan@156
|
1814 end
|
jcallahan@156
|
1815
|
jcallahan@156
|
1816
|
jcallahan@156
|
1817 function WDP:PLAYER_REGEN_ENABLED(event_name)
|
jcallahan@156
|
1818 private.in_combat = nil
|
jcallahan@156
|
1819
|
jcallahan@156
|
1820 if private.set_area_id then
|
jcallahan@156
|
1821 self:SetCurrentAreaID(event_name)
|
jcallahan@156
|
1822 private.set_area_id = nil
|
jcallahan@156
|
1823 end
|
jcallahan@156
|
1824 end
|
jcallahan@156
|
1825
|
jcallahan@156
|
1826
|
jcallahan@118
|
1827 function WDP:PLAYER_TARGET_CHANGED(event_name)
|
jcallahan@215
|
1828 if not TargetedNPC() then
|
jcallahan@118
|
1829 return
|
jcallahan@2
|
1830 end
|
jcallahan@151
|
1831 current_action.target_type = AF.NPC
|
jcallahan@118
|
1832 self:UpdateTargetLocation()
|
jcallahan@118
|
1833 end
|
jcallahan@2
|
1834
|
jcallahan@89
|
1835
|
jcallahan@12
|
1836 do
|
jcallahan@12
|
1837 local function UpdateQuestJuncture(point)
|
jcallahan@12
|
1838 local unit_name = _G.UnitName("questnpc")
|
jcallahan@9
|
1839
|
jcallahan@12
|
1840 if not unit_name then
|
jcallahan@12
|
1841 return
|
jcallahan@12
|
1842 end
|
jcallahan@34
|
1843 local unit_type, unit_id = ParseGUID(_G.UnitGUID("questnpc"))
|
jcallahan@9
|
1844
|
jcallahan@12
|
1845 if unit_type == private.UNIT_TYPES.OBJECT then
|
jcallahan@38
|
1846 UpdateDBEntryLocation("objects", unit_id)
|
jcallahan@12
|
1847 end
|
jcallahan@19
|
1848 local quest = DBEntry("quests", _G.GetQuestID())
|
jcallahan@12
|
1849 quest[point] = quest[point] or {}
|
jcallahan@12
|
1850 quest[point][("%s:%d"):format(private.UNIT_TYPE_NAMES[unit_type + 1], unit_id)] = true
|
jcallahan@24
|
1851
|
jcallahan@24
|
1852 return quest
|
jcallahan@12
|
1853 end
|
jcallahan@10
|
1854
|
jcallahan@12
|
1855
|
jcallahan@92
|
1856 function WDP:QUEST_COMPLETE(event_name)
|
jcallahan@97
|
1857 local quest = UpdateQuestJuncture("end")
|
jcallahan@97
|
1858
|
jcallahan@112
|
1859 if ALLOWED_LOCALES[CLIENT_LOCALE] then
|
jcallahan@112
|
1860 quest.reward_text = ReplaceKeywords(_G.GetRewardText())
|
jcallahan@112
|
1861 end
|
jcallahan@67
|
1862 -- Make sure the quest NPC isn't erroneously recorded as giving reputation for quests which award it.
|
jcallahan@177
|
1863 ClearKilledNPC()
|
jcallahan@10
|
1864 end
|
jcallahan@10
|
1865
|
jcallahan@12
|
1866
|
jcallahan@92
|
1867 function WDP:QUEST_DETAIL(event_name)
|
jcallahan@24
|
1868 local quest = UpdateQuestJuncture("begin")
|
jcallahan@24
|
1869
|
jcallahan@46
|
1870 if not quest then
|
jcallahan@46
|
1871 return
|
jcallahan@46
|
1872 end
|
jcallahan@24
|
1873 quest.classes = quest.classes or {}
|
jcallahan@27
|
1874 quest.classes[PLAYER_CLASS] = true
|
jcallahan@24
|
1875
|
jcallahan@24
|
1876 quest.races = quest.races or {}
|
jcallahan@100
|
1877 quest.races[(PLAYER_RACE == "Pandaren") and ("%s_%s"):format(PLAYER_RACE, PLAYER_FACTION or "Neutral") or PLAYER_RACE] = true
|
jcallahan@10
|
1878 end
|
jcallahan@12
|
1879 end -- do-block
|
jcallahan@9
|
1880
|
jcallahan@9
|
1881
|
jcallahan@92
|
1882 function WDP:QUEST_LOG_UPDATE(event_name)
|
jcallahan@38
|
1883 local selected_quest = _G.GetQuestLogSelection() -- Save current selection to be restored when we're done.
|
jcallahan@36
|
1884 local entry_index, processed_quests = 1, 0
|
jcallahan@36
|
1885 local _, num_quests = _G.GetNumQuestLogEntries()
|
jcallahan@36
|
1886
|
jcallahan@36
|
1887 while processed_quests <= num_quests do
|
jcallahan@36
|
1888 local _, _, _, _, is_header, _, _, _, quest_id = _G.GetQuestLogTitle(entry_index)
|
jcallahan@36
|
1889
|
jcallahan@84
|
1890 if quest_id == 0 then
|
jcallahan@84
|
1891 processed_quests = processed_quests + 1
|
jcallahan@84
|
1892 elseif not is_header then
|
jcallahan@36
|
1893 _G.SelectQuestLogEntry(entry_index);
|
jcallahan@36
|
1894
|
jcallahan@36
|
1895 local quest = DBEntry("quests", quest_id)
|
jcallahan@36
|
1896 quest.timer = _G.GetQuestLogTimeLeft()
|
jcallahan@37
|
1897 quest.can_share = _G.GetQuestLogPushable() and true or nil
|
jcallahan@36
|
1898 processed_quests = processed_quests + 1
|
jcallahan@36
|
1899 end
|
jcallahan@36
|
1900 entry_index = entry_index + 1
|
jcallahan@36
|
1901 end
|
jcallahan@36
|
1902 _G.SelectQuestLogEntry(selected_quest)
|
jcallahan@4
|
1903 self:UnregisterEvent("QUEST_LOG_UPDATE")
|
jcallahan@4
|
1904 end
|
jcallahan@4
|
1905
|
jcallahan@4
|
1906
|
jcallahan@97
|
1907 function WDP:QUEST_PROGRESS(event_name)
|
jcallahan@112
|
1908 if not ALLOWED_LOCALES[CLIENT_LOCALE] then
|
jcallahan@112
|
1909 return
|
jcallahan@112
|
1910 end
|
jcallahan@97
|
1911 DBEntry("quests", _G.GetQuestID()).progress_text = ReplaceKeywords(_G.GetProgressText())
|
jcallahan@97
|
1912 end
|
jcallahan@97
|
1913
|
jcallahan@97
|
1914
|
jcallahan@92
|
1915 function WDP:UNIT_QUEST_LOG_CHANGED(event_name, unit_id)
|
jcallahan@4
|
1916 if unit_id ~= "player" then
|
jcallahan@4
|
1917 return
|
jcallahan@4
|
1918 end
|
jcallahan@4
|
1919 self:RegisterEvent("QUEST_LOG_UPDATE")
|
jcallahan@4
|
1920 end
|
jcallahan@4
|
1921
|
jcallahan@4
|
1922
|
jcallahan@92
|
1923 do
|
jcallahan@92
|
1924 local TRADESKILL_TOOLS = {
|
jcallahan@92
|
1925 Anvil = anvil_spell_ids,
|
jcallahan@92
|
1926 Forge = forge_spell_ids,
|
jcallahan@92
|
1927 }
|
jcallahan@92
|
1928
|
jcallahan@92
|
1929
|
jcallahan@167
|
1930 local function RegisterTools(tradeskill_name, tradeskill_index)
|
jcallahan@167
|
1931 local spell_id = tonumber(_G.GetTradeSkillRecipeLink(tradeskill_index):match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)"))
|
jcallahan@167
|
1932 local required_tool = _G.GetTradeSkillTools(tradeskill_index)
|
jcallahan@167
|
1933
|
jcallahan@167
|
1934 if required_tool then
|
jcallahan@167
|
1935 for tool_name, registry in pairs(TRADESKILL_TOOLS) do
|
jcallahan@167
|
1936 if required_tool:find(tool_name) then
|
jcallahan@167
|
1937 registry[spell_id] = true
|
jcallahan@167
|
1938 end
|
jcallahan@167
|
1939 end
|
jcallahan@167
|
1940 end
|
jcallahan@167
|
1941 end
|
jcallahan@167
|
1942
|
jcallahan@167
|
1943
|
jcallahan@92
|
1944 function WDP:TRADE_SKILL_SHOW(event_name)
|
jcallahan@92
|
1945 local profession_name, prof_level = _G.GetTradeSkillLine()
|
jcallahan@92
|
1946
|
jcallahan@92
|
1947 if profession_name == _G.UNKNOWN then
|
jcallahan@92
|
1948 return
|
jcallahan@92
|
1949 end
|
jcallahan@167
|
1950 TradeSkillExecutePer(RegisterTools)
|
jcallahan@92
|
1951 end
|
jcallahan@92
|
1952 end -- do-block
|
jcallahan@92
|
1953
|
jcallahan@92
|
1954
|
jcallahan@167
|
1955 function WDP:TRAINER_CLOSED(event_name)
|
jcallahan@167
|
1956 private.trainer_shown = nil
|
jcallahan@167
|
1957 end
|
jcallahan@167
|
1958
|
jcallahan@167
|
1959
|
jcallahan@92
|
1960 function WDP:TRAINER_SHOW(event_name)
|
jcallahan@34
|
1961 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
|
jcallahan@164
|
1962 local trainer = NPCEntry(unit_idnum)
|
jcallahan@58
|
1963
|
jcallahan@164
|
1964 if not trainer then
|
jcallahan@58
|
1965 return
|
jcallahan@58
|
1966 end
|
jcallahan@164
|
1967 local trainer_standing = select(2, UnitFactionStanding("target"))
|
jcallahan@164
|
1968 trainer.teaches = trainer.teaches or {}
|
jcallahan@27
|
1969
|
jcallahan@167
|
1970 private.trainer_shown = true
|
jcallahan@167
|
1971
|
jcallahan@27
|
1972 -- Get the initial trainer filters
|
jcallahan@27
|
1973 local available = _G.GetTrainerServiceTypeFilter("available")
|
jcallahan@27
|
1974 local unavailable = _G.GetTrainerServiceTypeFilter("unavailable")
|
jcallahan@27
|
1975 local used = _G.GetTrainerServiceTypeFilter("used")
|
jcallahan@27
|
1976
|
jcallahan@27
|
1977 -- Clear the trainer filters
|
jcallahan@27
|
1978 _G.SetTrainerServiceTypeFilter("available", 1)
|
jcallahan@27
|
1979 _G.SetTrainerServiceTypeFilter("unavailable", 1)
|
jcallahan@27
|
1980 _G.SetTrainerServiceTypeFilter("used", 1)
|
jcallahan@27
|
1981
|
jcallahan@27
|
1982 for index = 1, _G.GetNumTrainerServices(), 1 do
|
jcallahan@27
|
1983 local spell_name, rank_name, _, _, required_level = _G.GetTrainerServiceInfo(index)
|
jcallahan@27
|
1984
|
jcallahan@27
|
1985 if spell_name then
|
jcallahan@27
|
1986 DatamineTT:ClearLines()
|
jcallahan@27
|
1987 DatamineTT:SetTrainerService(index)
|
jcallahan@27
|
1988
|
jcallahan@27
|
1989 local _, _, spell_id = DatamineTT:GetSpell()
|
jcallahan@27
|
1990
|
jcallahan@43
|
1991 if spell_id then
|
jcallahan@164
|
1992 local class_professions = trainer.teaches[PLAYER_CLASS]
|
jcallahan@164
|
1993
|
jcallahan@164
|
1994 if not class_professions then
|
jcallahan@164
|
1995 trainer.teaches[PLAYER_CLASS] = {}
|
jcallahan@164
|
1996 class_professions = trainer.teaches[PLAYER_CLASS]
|
jcallahan@164
|
1997 end
|
jcallahan@43
|
1998 local profession, min_skill = _G.GetTrainerServiceSkillReq(index)
|
jcallahan@43
|
1999 profession = profession or "General"
|
jcallahan@43
|
2000
|
jcallahan@164
|
2001 local profession_skills = class_professions[profession]
|
jcallahan@43
|
2002
|
jcallahan@43
|
2003 if not profession_skills then
|
jcallahan@43
|
2004 class_professions[profession] = {}
|
jcallahan@43
|
2005 profession_skills = class_professions[profession]
|
jcallahan@43
|
2006 end
|
jcallahan@173
|
2007 profession_skills[spell_id] = ("%d:%d:%d"):format(required_level, min_skill, _G.GetTrainerServiceCost(index))
|
jcallahan@27
|
2008 end
|
jcallahan@27
|
2009 end
|
jcallahan@27
|
2010 end
|
jcallahan@27
|
2011 -- Reset the filters to what they were before
|
jcallahan@27
|
2012 _G.SetTrainerServiceTypeFilter("available", available or 0)
|
jcallahan@27
|
2013 _G.SetTrainerServiceTypeFilter("unavailable", unavailable or 0)
|
jcallahan@27
|
2014 _G.SetTrainerServiceTypeFilter("used", used or 0)
|
jcallahan@27
|
2015 end
|
jcallahan@27
|
2016
|
jcallahan@27
|
2017
|
jcallahan@1
|
2018 function WDP:UNIT_SPELLCAST_SENT(event_name, unit_id, spell_name, spell_rank, target_name, spell_line)
|
jcallahan@1
|
2019 if private.tracked_line or unit_id ~= "player" then
|
jcallahan@1
|
2020 return
|
jcallahan@1
|
2021 end
|
jcallahan@1
|
2022 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name]
|
jcallahan@1
|
2023
|
jcallahan@1
|
2024 if not spell_label then
|
jcallahan@1
|
2025 return
|
jcallahan@1
|
2026 end
|
jcallahan@150
|
2027 local item_name, item_link = _G.GameTooltip:GetItem()
|
jcallahan@150
|
2028 local unit_name, unit_id = _G.GameTooltip:GetUnit()
|
jcallahan@1
|
2029
|
jcallahan@150
|
2030 if not unit_name and _G.UnitName("target") == target_name then
|
jcallahan@150
|
2031 unit_name = target_name
|
jcallahan@150
|
2032 unit_id = "target"
|
jcallahan@1
|
2033 end
|
jcallahan@1
|
2034 local spell_flags = private.SPELL_FLAGS_BY_LABEL[spell_label]
|
jcallahan@28
|
2035 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData()
|
jcallahan@28
|
2036
|
jcallahan@205
|
2037 table.wipe(current_action)
|
jcallahan@122
|
2038 current_action.instance_token = instance_token
|
jcallahan@122
|
2039 current_action.map_level = map_level
|
jcallahan@122
|
2040 current_action.x = x
|
jcallahan@122
|
2041 current_action.y = y
|
jcallahan@122
|
2042 current_action.zone_data = ("%s:%d"):format(zone_name, area_id)
|
jcallahan@122
|
2043 current_action.spell_label = spell_label
|
jcallahan@105
|
2044
|
jcallahan@105
|
2045 if not private.NON_LOOT_SPELL_LABELS[spell_label] then
|
jcallahan@122
|
2046 current_action.loot_label = spell_label:lower()
|
jcallahan@105
|
2047 end
|
jcallahan@1
|
2048
|
jcallahan@151
|
2049 if unit_name and unit_name == target_name and not item_name then
|
jcallahan@16
|
2050 if bit.band(spell_flags, AF.NPC) == AF.NPC then
|
jcallahan@150
|
2051 if not unit_id or unit_name ~= target_name then
|
jcallahan@16
|
2052 return
|
jcallahan@16
|
2053 end
|
jcallahan@123
|
2054 current_action.target_type = AF.NPC
|
jcallahan@16
|
2055 end
|
jcallahan@16
|
2056 elseif bit.band(spell_flags, AF.ITEM) == AF.ITEM then
|
jcallahan@123
|
2057 current_action.target_type = AF.ITEM
|
jcallahan@16
|
2058
|
jcallahan@150
|
2059 if item_name and item_name == target_name then
|
jcallahan@150
|
2060 current_action.identifier = ItemLinkToID(item_link)
|
jcallahan@16
|
2061 elseif target_name and target_name ~= "" then
|
jcallahan@150
|
2062 current_action.identifier = ItemLinkToID(select(2, _G.GetItemInfo(target_name)))
|
jcallahan@16
|
2063 end
|
jcallahan@150
|
2064 elseif not item_name and not unit_name then
|
jcallahan@1
|
2065 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then
|
jcallahan@17
|
2066 if target_name == "" then
|
jcallahan@17
|
2067 return
|
jcallahan@17
|
2068 end
|
jcallahan@122
|
2069 current_action.object_name = target_name
|
jcallahan@123
|
2070 current_action.target_type = AF.OBJECT
|
jcallahan@1
|
2071 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then
|
jcallahan@123
|
2072 current_action.target_type = AF.ZONE
|
jcallahan@1
|
2073 end
|
jcallahan@1
|
2074 end
|
jcallahan@1
|
2075 private.tracked_line = spell_line
|
jcallahan@0
|
2076 end
|
jcallahan@0
|
2077
|
jcallahan@94
|
2078
|
jcallahan@1
|
2079 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
|
jcallahan@1
|
2080 if unit_id ~= "player" then
|
jcallahan@1
|
2081 return
|
jcallahan@1
|
2082 end
|
jcallahan@1
|
2083 private.tracked_line = nil
|
jcallahan@167
|
2084 private.previous_spell_id = spell_id
|
jcallahan@85
|
2085
|
jcallahan@86
|
2086 if spell_name:match("^Harvest.+") then
|
jcallahan@177
|
2087 killed_npc_id = current_target_id
|
jcallahan@98
|
2088 private.harvesting = true
|
jcallahan@85
|
2089 end
|
jcallahan@92
|
2090
|
jcallahan@92
|
2091 if anvil_spell_ids[spell_id] then
|
jcallahan@92
|
2092 UpdateDBEntryLocation("objects", OBJECT_ID_ANVIL)
|
jcallahan@92
|
2093 elseif forge_spell_ids[spell_id] then
|
jcallahan@92
|
2094 UpdateDBEntryLocation("objects", OBJECT_ID_FORGE)
|
jcallahan@92
|
2095 end
|
jcallahan@0
|
2096 end
|
jcallahan@0
|
2097
|
jcallahan@90
|
2098
|
jcallahan@1
|
2099 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
|
jcallahan@1
|
2100 if unit_id ~= "player" then
|
jcallahan@1
|
2101 return
|
jcallahan@1
|
2102 end
|
jcallahan@0
|
2103
|
jcallahan@1
|
2104 if private.tracked_line == spell_line then
|
jcallahan@1
|
2105 private.tracked_line = nil
|
jcallahan@1
|
2106 end
|
jcallahan@147
|
2107 table.wipe(current_action)
|
jcallahan@0
|
2108 end
|
jcallahan@90
|
2109
|
jcallahan@90
|
2110
|
jcallahan@90
|
2111 do
|
jcallahan@90
|
2112 local function SetUnitField(field, required_type)
|
jcallahan@90
|
2113 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
|
jcallahan@90
|
2114
|
jcallahan@90
|
2115 if not unit_idnum or (required_type and unit_type ~= required_type) then
|
jcallahan@90
|
2116 return
|
jcallahan@90
|
2117 end
|
jcallahan@90
|
2118
|
jcallahan@171
|
2119 if UnitTypeIsNPC(unit_type) then
|
jcallahan@90
|
2120 NPCEntry(unit_idnum)[field] = true
|
jcallahan@90
|
2121 elseif unit_type == private.UNIT_TYPES.OBJECT then
|
jcallahan@90
|
2122 DBEntry("objects", unit_idnum)[field] = true
|
jcallahan@93
|
2123 UpdateDBEntryLocation("objects", unit_idnum)
|
jcallahan@90
|
2124 end
|
jcallahan@90
|
2125 end
|
jcallahan@90
|
2126
|
jcallahan@90
|
2127
|
jcallahan@90
|
2128 function WDP:AUCTION_HOUSE_SHOW(event_name)
|
jcallahan@90
|
2129 SetUnitField("auctioneer", private.UNIT_TYPES.NPC)
|
jcallahan@90
|
2130 end
|
jcallahan@90
|
2131
|
jcallahan@90
|
2132
|
jcallahan@90
|
2133 function WDP:BANKFRAME_OPENED(event_name)
|
jcallahan@90
|
2134 SetUnitField("banker", private.UNIT_TYPES.NPC)
|
jcallahan@90
|
2135 end
|
jcallahan@90
|
2136
|
jcallahan@90
|
2137
|
jcallahan@90
|
2138 function WDP:BATTLEFIELDS_SHOW(event_name)
|
jcallahan@90
|
2139 SetUnitField("battlemaster", private.UNIT_TYPES.NPC)
|
jcallahan@90
|
2140 end
|
jcallahan@90
|
2141
|
jcallahan@90
|
2142
|
jcallahan@92
|
2143 function WDP:FORGE_MASTER_OPENED(event_name)
|
jcallahan@90
|
2144 SetUnitField("arcane_reforger", private.UNIT_TYPES.NPC)
|
jcallahan@90
|
2145 end
|
jcallahan@90
|
2146
|
jcallahan@90
|
2147
|
jcallahan@92
|
2148 function WDP:GOSSIP_SHOW(event_name)
|
jcallahan@90
|
2149 local gossip_options = { _G.GetGossipOptions() }
|
jcallahan@90
|
2150
|
jcallahan@90
|
2151 for index = 2, #gossip_options, 2 do
|
jcallahan@90
|
2152 if gossip_options[index] == "binder" then
|
jcallahan@90
|
2153 SetUnitField("innkeeper", private.UNIT_TYPES.NPC)
|
jcallahan@90
|
2154 return
|
jcallahan@90
|
2155 end
|
jcallahan@90
|
2156 end
|
jcallahan@90
|
2157 end
|
jcallahan@90
|
2158
|
jcallahan@90
|
2159
|
jcallahan@93
|
2160 function WDP:GUILDBANKFRAME_OPENED(event_name)
|
jcallahan@93
|
2161 SetUnitField("guild_bank", private.UNIT_TYPES.OBJECT)
|
jcallahan@93
|
2162 end
|
jcallahan@93
|
2163
|
jcallahan@93
|
2164
|
jcallahan@189
|
2165 function WDP:ITEM_UPGRADE_MASTER_OPENED(event_name)
|
jcallahan@189
|
2166 SetUnitField("item_upgrade_master", private.UNIT_TYPES.NPC)
|
jcallahan@189
|
2167 end
|
jcallahan@189
|
2168
|
jcallahan@189
|
2169
|
jcallahan@90
|
2170 function WDP:TAXIMAP_OPENED(event_name)
|
jcallahan@90
|
2171 SetUnitField("flight_master", private.UNIT_TYPES.NPC)
|
jcallahan@90
|
2172 end
|
jcallahan@90
|
2173
|
jcallahan@90
|
2174
|
jcallahan@90
|
2175 function WDP:TRANSMOGRIFY_OPEN(event_name)
|
jcallahan@90
|
2176 SetUnitField("transmogrifier", private.UNIT_TYPES.NPC)
|
jcallahan@90
|
2177 end
|
jcallahan@90
|
2178
|
jcallahan@90
|
2179
|
jcallahan@90
|
2180 function WDP:VOID_STORAGE_OPEN(event_name)
|
jcallahan@90
|
2181 SetUnitField("void_storage", private.UNIT_TYPES.NPC)
|
jcallahan@90
|
2182 end
|
jcallahan@90
|
2183 end -- do-block
|