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