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