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