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