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