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