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