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