annotate Main.lua @ 350:37c27a7509c4 WoD

Expanded the Debug function to no longer -require- arguments other than the message.
author MMOSimca <MMOSimca@gmail.com>
date Sat, 04 Oct 2014 07:10:44 -0400
parents 146072e39150
children e7cbe43d8418
rev   line source
jcallahan@246 1 -- LUA API ------------------------------------------------------------
jcallahan@246 2
jcallahan@0 3 local _G = getfenv(0)
jcallahan@0 4
jcallahan@0 5 local pairs = _G.pairs
jcallahan@312 6 local tostring = _G.tostring
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@334 13 local next = _G.next
jcallahan@78 14 local select = _G.select
jcallahan@306 15 local unpack = _G.unpack
jcallahan@78 16
jcallahan@0 17
jcallahan@246 18 -- ADDON NAMESPACE ----------------------------------------------------
jcallahan@246 19
jcallahan@0 20 local ADDON_NAME, private = ...
jcallahan@0 21
jcallahan@0 22 local LibStub = _G.LibStub
jcallahan@249 23 local WDP = LibStub("AceAddon-3.0"):NewAddon(ADDON_NAME, "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0")
jcallahan@0 24
jcallahan@48 25 local deformat = LibStub("LibDeformat-3.0")
jcallahan@115 26 local LPJ = LibStub("LibPetJournal-2.0")
jcallahan@141 27 local MapData = LibStub("LibMapData-1.0")
jcallahan@48 28
jcallahan@4 29 local DatamineTT = _G.CreateFrame("GameTooltip", "WDPDatamineTT", _G.UIParent, "GameTooltipTemplate")
jcallahan@5 30 DatamineTT:SetOwner(_G.WorldFrame, "ANCHOR_NONE")
jcallahan@5 31
jcallahan@0 32
jcallahan@246 33 -- CONSTANTS ----------------------------------------------------------
jcallahan@246 34
jcallahan@246 35 local AF = private.ACTION_TYPE_FLAGS
jcallahan@246 36 local CLIENT_LOCALE = _G.GetLocale()
jcallahan@313 37 local DB_VERSION = 18
MMOSimca@346 38 local DEBUGGING = false
jcallahan@156 39 local EVENT_DEBUG = false
jcallahan@322 40
jcallahan@246 41 local OBJECT_ID_ANVIL = 192628
jcallahan@322 42 local OBJECT_ID_FISHING_BOBBER = 35591
jcallahan@246 43 local OBJECT_ID_FORGE = 1685
jcallahan@322 44
jcallahan@246 45 local PLAYER_CLASS = _G.select(2, _G.UnitClass("player"))
jcallahan@246 46 local PLAYER_FACTION = _G.UnitFactionGroup("player")
jcallahan@300 47 local PLAYER_GUID
jcallahan@246 48 local PLAYER_NAME = _G.UnitName("player")
jcallahan@246 49 local PLAYER_RACE = _G.select(2, _G.UnitRace("player"))
jcallahan@246 50
MMOSimca@337 51 -- Ignoring NPC casts of the following spells
MMOSimca@336 52 local CHI_WAVE_SPELL_ID = 132464
MMOSimca@336 53 local DISGUISE_SPELL_ID = 121308
MMOSimca@336 54
MMOSimca@347 55 -- For timer-based loot gathering of abnormal containers (that don't use SHOW_LOOT_TOAST, sadly)
MMOSimca@349 56 local BAG_OF_SALVAGE_ITEM_ID = private.SALVAGE_SPELL_ID_TO_ITEM_ID_MAP[168178]
MMOSimca@347 57 local CRATE_OF_SALVAGE_ITEM_ID = private.SALVAGE_SPELL_ID_TO_ITEM_ID_MAP[168179]
MMOSimca@347 58 local BIG_CRATE_OF_SALVAGE_ITEM_ID = private.SALVAGE_SPELL_ID_TO_ITEM_ID_MAP[168180]
MMOSimca@347 59
MMOSimca@336 60 -- Constant for duplicate boss data; a dirty hack to get around world bosses that cannot be identified individually and cannot be linked on wowdb because they are not in a raid
MMOSimca@336 61 local DUPLICATE_WORLD_BOSS_IDS = {
MMOSimca@336 62 [71952] = { 71953, 71954, 71955, },
MMOSimca@336 63 }
jcallahan@326 64
jcallahan@246 65 local ALLOWED_LOCALES = {
jcallahan@246 66 enUS = true,
jcallahan@246 67 enGB = true,
MMOSimca@336 68 enTW = true,
MMOSimca@336 69 enCN = true,
jcallahan@246 70 }
jcallahan@157 71
jcallahan@0 72 local DATABASE_DEFAULTS = {
jcallahan@128 73 char = {},
jcallahan@0 74 global = {
jcallahan@270 75 config = {
jcallahan@270 76 minimap_icon = {
jcallahan@270 77 hide = true,
jcallahan@270 78 },
jcallahan@270 79 },
jcallahan@0 80 items = {},
jcallahan@0 81 npcs = {},
jcallahan@0 82 objects = {},
jcallahan@0 83 quests = {},
jcallahan@167 84 spells = {},
jcallahan@17 85 zones = {},
jcallahan@0 86 }
jcallahan@0 87 }
jcallahan@0 88
jcallahan@1 89 local EVENT_MAPPING = {
jcallahan@90 90 AUCTION_HOUSE_SHOW = true,
jcallahan@90 91 BANKFRAME_OPENED = true,
jcallahan@90 92 BATTLEFIELDS_SHOW = true,
jcallahan@56 93 BLACK_MARKET_ITEM_UPDATE = true,
jcallahan@48 94 CHAT_MSG_LOOT = true,
jcallahan@95 95 CHAT_MSG_MONSTER_SAY = "RecordQuote",
jcallahan@95 96 CHAT_MSG_MONSTER_WHISPER = "RecordQuote",
jcallahan@95 97 CHAT_MSG_MONSTER_YELL = "RecordQuote",
jcallahan@40 98 CHAT_MSG_SYSTEM = true,
jcallahan@23 99 COMBAT_LOG_EVENT_UNFILTERED = true,
jcallahan@18 100 COMBAT_TEXT_UPDATE = true,
jcallahan@140 101 CURSOR_UPDATE = true,
jcallahan@90 102 FORGE_MASTER_OPENED = true,
jcallahan@90 103 GOSSIP_SHOW = true,
jcallahan@290 104 GROUP_ROSTER_UPDATE = true,
jcallahan@93 105 GUILDBANKFRAME_OPENED = true,
jcallahan@42 106 ITEM_TEXT_BEGIN = true,
jcallahan@189 107 ITEM_UPGRADE_MASTER_OPENED = true,
jcallahan@124 108 LOOT_CLOSED = true,
MMOSimca@343 109 LOOT_OPENED = true,
jcallahan@89 110 MAIL_SHOW = true,
jcallahan@133 111 MERCHANT_CLOSED = true,
jcallahan@7 112 MERCHANT_SHOW = "UpdateMerchantItems",
jcallahan@61 113 MERCHANT_UPDATE = "UpdateMerchantItems",
jcallahan@25 114 PET_BAR_UPDATE = true,
jcallahan@115 115 PET_JOURNAL_LIST_UPDATE = true,
jcallahan@156 116 PLAYER_REGEN_DISABLED = true,
jcallahan@156 117 PLAYER_REGEN_ENABLED = true,
jcallahan@2 118 PLAYER_TARGET_CHANGED = true,
jcallahan@9 119 QUEST_COMPLETE = true,
jcallahan@9 120 QUEST_DETAIL = true,
jcallahan@9 121 QUEST_LOG_UPDATE = true,
jcallahan@97 122 QUEST_PROGRESS = true,
jcallahan@178 123 SHOW_LOOT_TOAST = true,
jcallahan@306 124 SPELL_CONFIRMATION_PROMPT = true,
jcallahan@88 125 TAXIMAP_OPENED = true,
jcallahan@92 126 TRADE_SKILL_SHOW = true,
jcallahan@167 127 TRAINER_CLOSED = true,
jcallahan@27 128 TRAINER_SHOW = true,
jcallahan@90 129 TRANSMOGRIFY_OPEN = true,
jcallahan@246 130 UNIT_PET = true,
jcallahan@4 131 UNIT_QUEST_LOG_CHANGED = true,
jcallahan@1 132 UNIT_SPELLCAST_FAILED = "HandleSpellFailure",
jcallahan@1 133 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure",
jcallahan@1 134 UNIT_SPELLCAST_INTERRUPTED = "HandleSpellFailure",
jcallahan@1 135 UNIT_SPELLCAST_SENT = true,
jcallahan@1 136 UNIT_SPELLCAST_SUCCEEDED = true,
jcallahan@90 137 VOID_STORAGE_OPEN = true,
jcallahan@299 138 ZONE_CHANGED = "HandleZoneChange",
jcallahan@299 139 ZONE_CHANGED_INDOORS = "HandleZoneChange",
jcallahan@299 140 ZONE_CHANGED_NEW_AREA = "HandleZoneChange",
jcallahan@0 141 }
jcallahan@0 142
jcallahan@4 143
jcallahan@246 144 -- VARIABLES ----------------------------------------------------------
jcallahan@246 145
jcallahan@92 146 local anvil_spell_ids = {}
jcallahan@92 147 local currently_drunk
jcallahan@128 148 local char_db
jcallahan@128 149 local global_db
jcallahan@299 150 local group_member_guids = {}
jcallahan@246 151 local group_owner_guids_to_pet_guids = {}
jcallahan@246 152 local group_pet_guids = {}
jcallahan@299 153 local in_instance
jcallahan@187 154 local item_process_timer_handle
jcallahan@92 155 local faction_standings = {}
jcallahan@92 156 local forge_spell_ids = {}
jcallahan@95 157 local languages_known = {}
jcallahan@317 158 local boss_loot_toasting = {}
jcallahan@306 159 local loot_toast_container_timer_handle
jcallahan@307 160 local loot_toast_data
jcallahan@307 161 local loot_toast_data_timer_handle
jcallahan@95 162 local name_to_id_map = {}
jcallahan@306 163 local killed_boss_id_timer_handle
jcallahan@177 164 local killed_npc_id
jcallahan@2 165 local target_location_timer_handle
MMOSimca@345 166 local last_timber_spell_id
MMOSimca@347 167 local chat_loot_timer_handle
jcallahan@86 168 local current_target_id
jcallahan@126 169 local current_area_id
jcallahan@131 170 local current_loot
jcallahan@1 171
jcallahan@312 172
jcallahan@121 173 -- Data for our current action. Including possible values as a reference.
jcallahan@122 174 local current_action = {
jcallahan@121 175 identifier = nil,
jcallahan@121 176 loot_label = nil,
jcallahan@121 177 loot_list = nil,
jcallahan@121 178 loot_sources = nil,
jcallahan@121 179 map_level = nil,
jcallahan@121 180 spell_label = nil,
jcallahan@123 181 target_type = nil,
jcallahan@121 182 x = nil,
jcallahan@121 183 y = nil,
jcallahan@121 184 zone_data = nil,
jcallahan@121 185 }
jcallahan@92 186
jcallahan@246 187
jcallahan@246 188 -- HELPERS ------------------------------------------------------------
jcallahan@246 189
jcallahan@245 190 local function Debug(message, ...)
MMOSimca@350 191 if not DEBUGGING or not message then
jcallahan@151 192 return
jcallahan@151 193 end
MMOSimca@350 194
MMOSimca@350 195 if ... then
MMOSimca@350 196 local args = { ... }
MMOSimca@350 197
MMOSimca@350 198 for index = 1, #args do
MMOSimca@350 199 if args[index] == nil then
MMOSimca@350 200 args[index] = "nil"
MMOSimca@350 201 end
jcallahan@306 202 end
MMOSimca@350 203 _G.print(message:format(unpack(args)))
MMOSimca@350 204 else
MMOSimca@350 205 _G.print(message)
jcallahan@306 206 end
jcallahan@151 207 end
jcallahan@151 208
jcallahan@151 209
jcallahan@169 210 local TradeSkillExecutePer
jcallahan@169 211 do
jcallahan@169 212 local header_list = {}
jcallahan@169 213
jcallahan@169 214 function TradeSkillExecutePer(iter_func)
jcallahan@169 215 if not _G.TradeSkillFrame or not _G.TradeSkillFrame:IsVisible() then
jcallahan@169 216 return
jcallahan@169 217 end
jcallahan@167 218 -- Clear the search box focus so the scan will have correct results.
jcallahan@167 219 local search_box = _G.TradeSkillFrameSearchBox
jcallahan@167 220 search_box:SetText("")
jcallahan@169 221
jcallahan@167 222 _G.TradeSkillSearch_OnTextChanged(search_box)
jcallahan@167 223 search_box:ClearFocus()
jcallahan@167 224 search_box:GetScript("OnEditFocusLost")(search_box)
jcallahan@169 225
jcallahan@169 226 table.wipe(header_list)
jcallahan@169 227
jcallahan@169 228 -- Save the current state of the TradeSkillFrame so it can be restored after we muck with it.
jcallahan@169 229 local have_materials = _G.TradeSkillFrame.filterTbl.hasMaterials
jcallahan@169 230 local have_skillup = _G.TradeSkillFrame.filterTbl.hasSkillUp
jcallahan@169 231
jcallahan@169 232 if have_materials then
jcallahan@169 233 _G.TradeSkillFrame.filterTbl.hasMaterials = false
jcallahan@169 234 _G.TradeSkillOnlyShowMakeable(false)
jcallahan@169 235 end
jcallahan@169 236
jcallahan@169 237 if have_skillup then
jcallahan@169 238 _G.TradeSkillFrame.filterTbl.hasSkillUp = false
jcallahan@169 239 _G.TradeSkillOnlyShowSkillUps(false)
jcallahan@169 240 end
MMOSimca@330 241 _G.SetTradeSkillInvSlotFilter(0, true, true)
jcallahan@169 242 _G.TradeSkillUpdateFilterBar()
jcallahan@169 243 _G.TradeSkillFrame_Update()
jcallahan@169 244
jcallahan@169 245 -- Expand all headers so we can see all the recipes there are
jcallahan@169 246 for tradeskill_index = 1, _G.GetNumTradeSkills() do
jcallahan@169 247 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
jcallahan@169 248
jcallahan@169 249 if tradeskill_type == "header" or tradeskill_type == "subheader" then
jcallahan@169 250 if not is_expanded then
jcallahan@169 251 header_list[name] = true
jcallahan@169 252 _G.ExpandTradeSkillSubClass(tradeskill_index)
jcallahan@169 253 end
jcallahan@169 254 elseif iter_func(name, tradeskill_index) then
jcallahan@169 255 break
jcallahan@169 256 end
jcallahan@169 257 end
jcallahan@169 258
jcallahan@169 259 -- Restore the state of the things we changed.
jcallahan@169 260 for tradeskill_index = 1, _G.GetNumTradeSkills() do
jcallahan@169 261 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
jcallahan@169 262
jcallahan@169 263 if header_list[name] then
jcallahan@169 264 _G.CollapseTradeSkillSubClass(tradeskill_index)
jcallahan@169 265 end
jcallahan@169 266 end
jcallahan@169 267 _G.TradeSkillFrame.filterTbl.hasMaterials = have_materials
jcallahan@169 268 _G.TradeSkillOnlyShowMakeable(have_materials)
jcallahan@169 269 _G.TradeSkillFrame.filterTbl.hasSkillUp = have_skillup
jcallahan@169 270 _G.TradeSkillOnlyShowSkillUps(have_skillup)
jcallahan@169 271
jcallahan@169 272 _G.TradeSkillUpdateFilterBar()
jcallahan@169 273 _G.TradeSkillFrame_Update()
jcallahan@167 274 end
jcallahan@169 275 end -- do-block
jcallahan@167 276
jcallahan@167 277
jcallahan@39 278 local ActualCopperCost
jcallahan@39 279 do
jcallahan@39 280 local BARTERING_SPELL_ID = 83964
jcallahan@39 281
jcallahan@39 282 local STANDING_DISCOUNTS = {
jcallahan@39 283 HATED = 0,
jcallahan@39 284 HOSTILE = 0,
jcallahan@39 285 UNFRIENDLY = 0,
jcallahan@39 286 NEUTRAL = 0,
jcallahan@39 287 FRIENDLY = 0.05,
jcallahan@39 288 HONORED = 0.1,
jcallahan@39 289 REVERED = 0.15,
jcallahan@39 290 EXALTED = 0.2,
jcallahan@39 291 }
jcallahan@39 292
jcallahan@39 293
jcallahan@39 294 function ActualCopperCost(copper_cost, rep_standing)
jcallahan@39 295 if not copper_cost or copper_cost == 0 then
jcallahan@39 296 return 0
jcallahan@39 297 end
jcallahan@39 298 local modifier = 1
jcallahan@39 299
jcallahan@39 300 if _G.IsSpellKnown(BARTERING_SPELL_ID) then
jcallahan@39 301 modifier = modifier - 0.1
jcallahan@39 302 end
jcallahan@39 303
jcallahan@39 304 if rep_standing then
jcallahan@39 305 if PLAYER_RACE == "Goblin" then
jcallahan@39 306 modifier = modifier - STANDING_DISCOUNTS["EXALTED"]
jcallahan@39 307 elseif STANDING_DISCOUNTS[rep_standing] then
jcallahan@39 308 modifier = modifier - STANDING_DISCOUNTS[rep_standing]
jcallahan@39 309 end
jcallahan@39 310 end
jcallahan@39 311 return math.floor(copper_cost / modifier)
jcallahan@39 312 end
jcallahan@39 313 end -- do-block
jcallahan@39 314
jcallahan@39 315
jcallahan@29 316 local function InstanceDifficultyToken()
jcallahan@233 317 local _, instance_type, instance_difficulty, _, _, _, is_dynamic = _G.GetInstanceInfo()
jcallahan@59 318
jcallahan@59 319 if not instance_type or instance_type == "" then
jcallahan@59 320 instance_type = "NONE"
jcallahan@59 321 end
jcallahan@312 322 return ("%s:%d:%s"):format(instance_type:upper(), instance_difficulty, tostring(is_dynamic))
jcallahan@29 323 end
jcallahan@29 324
jcallahan@29 325
jcallahan@19 326 local function DBEntry(data_type, unit_id)
jcallahan@19 327 if not data_type or not unit_id then
jcallahan@6 328 return
jcallahan@6 329 end
jcallahan@289 330 local category = global_db[data_type]
jcallahan@289 331
jcallahan@289 332 if not category then
jcallahan@289 333 category = {}
jcallahan@289 334 global_db[data_type] = category
jcallahan@289 335 end
jcallahan@289 336 local unit = category[unit_id]
jcallahan@6 337
jcallahan@10 338 if not unit then
jcallahan@187 339 unit = {}
jcallahan@289 340 category[unit_id] = unit
jcallahan@6 341 end
jcallahan@10 342 return unit
jcallahan@6 343 end
jcallahan@270 344
jcallahan@263 345 private.DBEntry = DBEntry
jcallahan@6 346
jcallahan@214 347 local NPCEntry
jcallahan@214 348 do
jcallahan@214 349 local npc_prototype = {}
jcallahan@214 350 local npc_meta = {
jcallahan@214 351 __index = npc_prototype
jcallahan@214 352 }
jcallahan@6 353
jcallahan@214 354 function NPCEntry(identifier)
jcallahan@227 355 local npc = DBEntry("npcs", identifier)
jcallahan@331 356 return npc and _G.setmetatable(npc, npc_meta) or nil
jcallahan@22 357 end
jcallahan@214 358
jcallahan@248 359 function npc_prototype:EncounterData(difficulty_token)
jcallahan@214 360 self.encounter_data = self.encounter_data or {}
jcallahan@248 361 self.encounter_data[difficulty_token] = self.encounter_data[difficulty_token] or {}
jcallahan@248 362 self.encounter_data[difficulty_token].stats = self.encounter_data[difficulty_token].stats or {}
jcallahan@248 363
jcallahan@248 364 return self.encounter_data[difficulty_token]
jcallahan@214 365 end
jcallahan@22 366 end
jcallahan@22 367
jcallahan@22 368
jcallahan@1 369 local function CurrentLocationData()
jcallahan@161 370 if _G.GetCurrentMapAreaID() ~= current_area_id then
jcallahan@145 371 return _G.GetRealZoneText(), current_area_id, 0, 0, 0, InstanceDifficultyToken()
jcallahan@145 372 end
jcallahan@1 373 local map_level = _G.GetCurrentMapDungeonLevel() or 0
jcallahan@1 374 local x, y = _G.GetPlayerMapPosition("player")
jcallahan@1 375
jcallahan@1 376 x = x or 0
jcallahan@1 377 y = y or 0
jcallahan@1 378
jcallahan@1 379 if x == 0 and y == 0 then
jcallahan@1 380 for level_index = 1, _G.GetNumDungeonMapLevels() do
jcallahan@1 381 _G.SetDungeonMapLevel(level_index)
jcallahan@1 382 x, y = _G.GetPlayerMapPosition("player")
jcallahan@1 383
jcallahan@1 384 if x and y and (x > 0 or y > 0) then
jcallahan@1 385 _G.SetDungeonMapLevel(map_level)
jcallahan@1 386 map_level = level_index
jcallahan@1 387 break
jcallahan@1 388 end
jcallahan@1 389 end
jcallahan@1 390 end
jcallahan@1 391
jcallahan@1 392 if _G.DungeonUsesTerrainMap() then
jcallahan@1 393 map_level = map_level - 1
jcallahan@1 394 end
jcallahan@31 395 local x = _G.floor(x * 1000)
jcallahan@31 396 local y = _G.floor(y * 1000)
jcallahan@28 397
jcallahan@31 398 if x % 2 ~= 0 then
jcallahan@31 399 x = x + 1
jcallahan@28 400 end
jcallahan@28 401
jcallahan@31 402 if y % 2 ~= 0 then
jcallahan@31 403 y = y + 1
jcallahan@28 404 end
jcallahan@126 405 return _G.GetRealZoneText(), current_area_id, x, y, map_level, InstanceDifficultyToken()
jcallahan@1 406 end
jcallahan@1 407
jcallahan@1 408
jcallahan@312 409 local function CurrencyLinkToTexture(currency_link)
jcallahan@312 410 if not currency_link then
jcallahan@312 411 return
jcallahan@312 412 end
jcallahan@312 413 local _, _, texture_path = _G.GetCurrencyInfo(tonumber(currency_link:match("currency:(%d+)")))
jcallahan@312 414 return texture_path:match("[^\\]+$"):lower()
jcallahan@312 415 end
jcallahan@312 416
jcallahan@312 417
jcallahan@1 418 local function ItemLinkToID(item_link)
jcallahan@1 419 if not item_link then
jcallahan@1 420 return
jcallahan@1 421 end
jcallahan@7 422 return tonumber(item_link:match("item:(%d+)"))
jcallahan@1 423 end
jcallahan@270 424
jcallahan@260 425 private.ItemLinkToID = ItemLinkToID
jcallahan@4 426
jcallahan@171 427 local function UnitTypeIsNPC(unit_type)
jcallahan@171 428 return unit_type == private.UNIT_TYPES.NPC or unit_type == private.UNIT_TYPES.VEHICLE
jcallahan@171 429 end
jcallahan@171 430
jcallahan@171 431
jcallahan@34 432 local ParseGUID
jcallahan@4 433 do
jcallahan@229 434 local UNIT_TYPES = private.UNIT_TYPES
jcallahan@4 435
jcallahan@281 436 local NPC_ID_MAPPING = {
jcallahan@281 437 [62164] = 63191, -- Garalon
jcallahan@281 438 }
jcallahan@281 439
jcallahan@281 440
jcallahan@334 441 local function MatchUnitTypes(unit_type_name)
MMOSimca@329 442 if not unit_type_name then
MMOSimca@329 443 return UNIT_TYPES.UNKNOWN
MMOSimca@329 444 end
MMOSimca@329 445
MMOSimca@329 446 for def, text in next, UNIT_TYPES do
MMOSimca@329 447 if unit_type_name == text then
MMOSimca@329 448 return UNIT_TYPES[def]
MMOSimca@329 449 end
MMOSimca@329 450 end
MMOSimca@329 451 return UNIT_TYPES.UNKNOWN
MMOSimca@329 452 end
MMOSimca@329 453
MMOSimca@329 454
jcallahan@34 455 function ParseGUID(guid)
jcallahan@5 456 if not guid then
jcallahan@5 457 return
jcallahan@5 458 end
MMOSimca@329 459
MMOSimca@329 460 -- We might want to use some of this new information later, but leaving the returns alone for now
MMOSimca@339 461 local unit_type_name, unk_id1, server_id, instance_id, unk_id2, unit_idnum, spawn_id = ("-"):split(guid)
MMOSimca@329 462
jcallahan@334 463 local unit_type = MatchUnitTypes(unit_type_name)
MMOSimca@329 464 if unit_type ~= UNIT_TYPES.PLAYER and unit_type ~= UNIT_TYPES.PET and unit_type ~= UNIT_TYPES.ITEM then
MMOSimca@329 465
jcallahan@281 466 local id_mapping = NPC_ID_MAPPING[unit_idnum]
jcallahan@281 467
jcallahan@281 468 if id_mapping and UnitTypeIsNPC(unit_type) then
jcallahan@281 469 unit_idnum = id_mapping
jcallahan@281 470 end
jcallahan@281 471 return unit_type, unit_idnum
jcallahan@4 472 end
jcallahan@4 473 return unit_type
jcallahan@4 474 end
jcallahan@249 475
jcallahan@249 476 private.ParseGUID = ParseGUID
jcallahan@4 477 end -- do-block
jcallahan@4 478
jcallahan@4 479
jcallahan@141 480 local UpdateDBEntryLocation
jcallahan@141 481 do
jcallahan@141 482 -- Fishing node coordinate code based on code in GatherMate2 with permission from Kagaro.
jcallahan@141 483 local function FishingCoordinates(x, y, yard_width, yard_height)
jcallahan@141 484 local facing = _G.GetPlayerFacing()
jcallahan@141 485
jcallahan@141 486 if not facing then
jcallahan@141 487 return x, y
jcallahan@141 488 end
jcallahan@246 489 local rad = facing + math.pi
jcallahan@141 490 return x + math.sin(rad) * 15 / yard_width, y + math.cos(rad) * 15 / yard_height
jcallahan@10 491 end
jcallahan@10 492
jcallahan@24 493
jcallahan@141 494 function UpdateDBEntryLocation(entry_type, identifier)
jcallahan@141 495 if not identifier then
jcallahan@141 496 return
jcallahan@141 497 end
jcallahan@141 498 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData()
MMOSimca@328 499 if not (zone_name and area_id and x and y and map_level) then
MMOSimca@328 500 Debug("UpdateDBEntryLocation: Missing current location data - %s, %d, %d, %d, %d.", zone_name, area_id, x, y, map_level)
MMOSimca@328 501 return
MMOSimca@328 502 end
jcallahan@141 503 local entry = DBEntry(entry_type, identifier)
jcallahan@141 504 entry[difficulty_token] = entry[difficulty_token] or {}
jcallahan@141 505 entry[difficulty_token].locations = entry[difficulty_token].locations or {}
jcallahan@141 506
jcallahan@141 507 local zone_token = ("%s:%d"):format(zone_name, area_id)
jcallahan@141 508 local zone_data = entry[difficulty_token].locations[zone_token]
jcallahan@141 509
jcallahan@141 510 if not zone_data then
jcallahan@141 511 zone_data = {}
jcallahan@141 512 entry[difficulty_token].locations[zone_token] = zone_data
jcallahan@141 513 end
jcallahan@141 514
jcallahan@141 515 -- Special case for Fishing.
jcallahan@141 516 if current_action.spell_label == "FISHING" then
jcallahan@141 517 local yard_width, yard_height = MapData:MapArea(area_id, map_level)
jcallahan@141 518
jcallahan@141 519 if yard_width > 0 and yard_height > 0 then
jcallahan@141 520 x, y = FishingCoordinates(x, y, yard_width, yard_height)
jcallahan@141 521 current_action.x = x
jcallahan@141 522 current_action.y = y
jcallahan@141 523 end
jcallahan@141 524 end
jcallahan@141 525 local location_token = ("%d:%d:%d"):format(map_level, x, y)
jcallahan@141 526
jcallahan@141 527 zone_data[location_token] = zone_data[location_token] or true
jcallahan@141 528 return zone_data
jcallahan@10 529 end
jcallahan@141 530 end -- do-block
jcallahan@10 531
jcallahan@10 532
jcallahan@19 533 local function HandleItemUse(item_link, bag_index, slot_index)
jcallahan@19 534 if not item_link then
jcallahan@19 535 return
jcallahan@19 536 end
jcallahan@19 537 local item_id = ItemLinkToID(item_link)
jcallahan@19 538
jcallahan@19 539 if not bag_index or not slot_index then
jcallahan@19 540 for new_bag_index = 0, _G.NUM_BAG_FRAMES do
jcallahan@19 541 for new_slot_index = 1, _G.GetContainerNumSlots(new_bag_index) do
jcallahan@19 542 if item_id == ItemLinkToID(_G.GetContainerItemLink(new_bag_index, new_slot_index)) then
jcallahan@19 543 bag_index = new_bag_index
jcallahan@19 544 slot_index = new_slot_index
jcallahan@19 545 break
jcallahan@19 546 end
jcallahan@19 547 end
jcallahan@19 548 end
jcallahan@19 549 end
jcallahan@19 550
jcallahan@19 551 if not bag_index or not slot_index then
jcallahan@19 552 return
jcallahan@19 553 end
jcallahan@19 554 local _, _, _, _, _, is_lootable = _G.GetContainerItemInfo(bag_index, slot_index)
jcallahan@19 555
jcallahan@19 556 if not is_lootable then
jcallahan@19 557 return
jcallahan@19 558 end
jcallahan@19 559 DatamineTT:ClearLines()
jcallahan@19 560 DatamineTT:SetBagItem(bag_index, slot_index)
jcallahan@19 561
jcallahan@19 562 for line_index = 1, DatamineTT:NumLines() do
jcallahan@19 563 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
jcallahan@19 564
jcallahan@19 565 if not current_line then
MMOSimca@336 566 Debug("HandleItemUse: Item with ID %d and link %s had an invalid tooltip.", item_id, item_link)
jcallahan@324 567 return
jcallahan@19 568 end
jcallahan@306 569
jcallahan@306 570 if current_line:GetText() == _G.ITEM_OPENABLE then
jcallahan@122 571 table.wipe(current_action)
jcallahan@312 572 current_loot = nil
jcallahan@312 573
jcallahan@123 574 current_action.target_type = AF.ITEM
jcallahan@122 575 current_action.identifier = item_id
jcallahan@122 576 current_action.loot_label = "contains"
jcallahan@324 577 return
jcallahan@19 578 end
jcallahan@19 579 end
jcallahan@324 580 Debug("HandleItemUse: Item with ID %d and link %s did not have a tooltip that contained the string %s.", item_id, item_link, _G.ITEM_OPENABLE)
jcallahan@19 581 end
jcallahan@19 582
jcallahan@19 583
jcallahan@39 584 local UnitFactionStanding
jcallahan@32 585 local UpdateFactionData
jcallahan@32 586 do
jcallahan@32 587 local MAX_FACTION_INDEX = 1000
jcallahan@20 588
jcallahan@32 589 local STANDING_NAMES = {
jcallahan@32 590 "HATED",
jcallahan@32 591 "HOSTILE",
jcallahan@32 592 "UNFRIENDLY",
jcallahan@32 593 "NEUTRAL",
jcallahan@32 594 "FRIENDLY",
jcallahan@32 595 "HONORED",
jcallahan@32 596 "REVERED",
jcallahan@32 597 "EXALTED",
jcallahan@32 598 }
jcallahan@32 599
jcallahan@39 600
jcallahan@39 601 function UnitFactionStanding(unit)
jcallahan@135 602 local unit_name = _G.UnitName(unit)
jcallahan@39 603 UpdateFactionData()
jcallahan@39 604 DatamineTT:ClearLines()
jcallahan@39 605 DatamineTT:SetUnit(unit)
jcallahan@39 606
jcallahan@39 607 for line_index = 1, DatamineTT:NumLines() do
jcallahan@64 608 local faction_name = _G["WDPDatamineTTTextLeft" .. line_index]:GetText():trim()
jcallahan@39 609
jcallahan@135 610 if faction_name and faction_name ~= unit_name and faction_standings[faction_name] then
jcallahan@39 611 return faction_name, faction_standings[faction_name]
jcallahan@39 612 end
jcallahan@39 613 end
jcallahan@39 614 end
jcallahan@39 615
jcallahan@39 616
jcallahan@32 617 function UpdateFactionData()
jcallahan@32 618 for faction_index = 1, MAX_FACTION_INDEX do
jcallahan@32 619 local faction_name, _, current_standing, _, _, _, _, _, is_header = _G.GetFactionInfo(faction_index)
jcallahan@32 620
jcallahan@86 621 if faction_name then
jcallahan@32 622 faction_standings[faction_name] = STANDING_NAMES[current_standing]
jcallahan@32 623 elseif not faction_name then
jcallahan@32 624 break
jcallahan@32 625 end
jcallahan@20 626 end
jcallahan@20 627 end
jcallahan@32 628 end -- do-block
jcallahan@20 629
jcallahan@48 630
jcallahan@75 631 local GenericLootUpdate
jcallahan@75 632 do
jcallahan@77 633 local function LootTable(entry, loot_type, top_field)
jcallahan@75 634 if top_field then
jcallahan@75 635 entry[top_field] = entry[top_field] or {}
jcallahan@75 636 entry[top_field][loot_type] = entry[top_field][loot_type] or {}
jcallahan@75 637 return entry[top_field][loot_type]
jcallahan@75 638 end
jcallahan@48 639 entry[loot_type] = entry[loot_type] or {}
jcallahan@75 640 return entry[loot_type]
jcallahan@48 641 end
jcallahan@48 642
jcallahan@75 643 function GenericLootUpdate(data_type, top_field)
jcallahan@132 644 local loot_type = current_loot.label
jcallahan@75 645 local loot_count = ("%s_count"):format(loot_type)
jcallahan@77 646 local source_list = {}
jcallahan@75 647
jcallahan@131 648 if current_loot.sources then
jcallahan@131 649 for source_guid, loot_data in pairs(current_loot.sources) do
jcallahan@304 650 local source_id
jcallahan@78 651
jcallahan@131 652 if current_loot.target_type == AF.ITEM then
jcallahan@119 653 -- Items return the player as the source, so we need to use the item's ID (disenchant, milling, etc)
jcallahan@131 654 source_id = current_loot.identifier
jcallahan@119 655 else
jcallahan@331 656 local _, unit_ID = ParseGUID(source_guid)
MMOSimca@328 657 if unit_ID then
MMOSimca@328 658 if current_loot.target_type == AF.OBJECT then
MMOSimca@328 659 source_id = ("%s:%s"):format(current_loot.spell_label, unit_ID)
MMOSimca@328 660 else
MMOSimca@328 661 source_id = unit_ID
MMOSimca@328 662 end
MMOSimca@328 663 end
jcallahan@119 664 end
jcallahan@304 665 local entry = DBEntry(data_type, source_id)
jcallahan@75 666
jcallahan@119 667 if entry then
jcallahan@119 668 local loot_table = LootTable(entry, loot_type, top_field)
jcallahan@77 669
jcallahan@304 670 if not source_list[source_id] then
jcallahan@119 671 if top_field then
jcallahan@119 672 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1
jcallahan@306 673 elseif not private.container_loot_toasting then
jcallahan@119 674 entry[loot_count] = (entry[loot_count] or 0) + 1
jcallahan@119 675 end
jcallahan@304 676 source_list[source_id] = true
jcallahan@77 677 end
jcallahan@119 678 UpdateDBEntryLocation(data_type, source_id)
jcallahan@75 679
jcallahan@309 680 if current_loot.target_type == AF.ZONE then
jcallahan@309 681 for item_id, quantity in pairs(loot_data) do
jcallahan@309 682 table.insert(loot_table, ("%d:%d"):format(item_id, quantity))
jcallahan@309 683 end
jcallahan@309 684 else
jcallahan@308 685 for loot_token, quantity in pairs(loot_data) do
jcallahan@308 686 local label, currency_texture = (":"):split(loot_token)
jcallahan@308 687
jcallahan@308 688 if label == "currency" and currency_texture then
jcallahan@308 689 table.insert(loot_table, ("currency:%d:%s"):format(quantity, currency_texture))
jcallahan@308 690 elseif loot_token == "money" then
jcallahan@308 691 table.insert(loot_table, ("money:%d"):format(quantity))
jcallahan@308 692 else
jcallahan@308 693 table.insert(loot_table, ("%d:%d"):format(loot_token, quantity))
jcallahan@308 694 end
jcallahan@308 695 end
jcallahan@119 696 end
jcallahan@75 697 end
jcallahan@75 698 end
jcallahan@75 699 end
jcallahan@121 700
jcallahan@121 701 -- This is used for Gas Extractions.
jcallahan@131 702 if #current_loot.list <= 0 then
jcallahan@78 703 return
jcallahan@78 704 end
jcallahan@82 705 local entry
jcallahan@82 706
jcallahan@82 707 -- At this point we only have a name if it's an object.
jcallahan@131 708 if current_loot.target_type == AF.OBJECT then
jcallahan@131 709 entry = DBEntry(data_type, ("%s:%s"):format(current_loot.spell_label, current_loot.object_name))
jcallahan@82 710 else
jcallahan@131 711 entry = DBEntry(data_type, current_loot.identifier)
jcallahan@82 712 end
jcallahan@75 713
jcallahan@75 714 if not entry then
jcallahan@75 715 return
jcallahan@75 716 end
jcallahan@77 717 local loot_table = LootTable(entry, loot_type, top_field)
jcallahan@77 718
jcallahan@307 719 if current_loot.identifier then
jcallahan@307 720 if not source_list[current_loot.identifier] then
jcallahan@307 721 if top_field then
jcallahan@307 722 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1
jcallahan@307 723 else
jcallahan@307 724 entry[loot_count] = (entry[loot_count] or 0) + 1
jcallahan@307 725 end
jcallahan@307 726 source_list[current_loot.identifier] = true
jcallahan@77 727 end
jcallahan@77 728 end
jcallahan@75 729
jcallahan@131 730 for index = 1, #current_loot.list do
jcallahan@131 731 table.insert(loot_table, current_loot.list[index])
jcallahan@75 732 end
jcallahan@48 733 end
jcallahan@75 734 end -- do-block
jcallahan@48 735
jcallahan@97 736
jcallahan@97 737 local ReplaceKeywords
jcallahan@97 738 do
jcallahan@97 739 local KEYWORD_SUBSTITUTIONS = {
jcallahan@97 740 class = PLAYER_CLASS,
jcallahan@97 741 name = PLAYER_NAME,
jcallahan@97 742 race = PLAYER_RACE,
jcallahan@97 743 }
jcallahan@97 744
jcallahan@97 745
jcallahan@97 746 function ReplaceKeywords(text)
jcallahan@97 747 if not text or text == "" then
jcallahan@97 748 return ""
jcallahan@97 749 end
jcallahan@97 750
jcallahan@97 751 for category, lookup in pairs(KEYWORD_SUBSTITUTIONS) do
jcallahan@97 752 local category_format = ("<%s>"):format(category)
jcallahan@97 753 text = text:gsub(lookup, category_format):gsub(lookup:lower(), category_format)
jcallahan@97 754 end
jcallahan@97 755 return text
jcallahan@97 756 end
jcallahan@97 757 end -- do-block
jcallahan@97 758
jcallahan@97 759
jcallahan@154 760 -- Contains a dirty hack due to Blizzard's strange handling of Micro Dungeons; GetMapInfo() will not return correct information
jcallahan@154 761 -- unless the WorldMapFrame is shown.
jcallahan@143 762 do
jcallahan@143 763 -- MapFileName = MapAreaID
jcallahan@143 764 local MICRO_DUNGEON_IDS = {
jcallahan@143 765 ShrineofTwoMoons = 903,
jcallahan@143 766 ShrineofSevenStars = 905,
jcallahan@143 767 }
jcallahan@126 768
jcallahan@299 769 local function SetCurrentAreaID()
jcallahan@156 770 if private.in_combat then
jcallahan@156 771 private.set_area_id = true
jcallahan@156 772 return
jcallahan@156 773 end
jcallahan@155 774 local map_area_id = _G.GetCurrentMapAreaID()
jcallahan@155 775
jcallahan@155 776 if map_area_id == current_area_id then
jcallahan@155 777 return
jcallahan@155 778 end
jcallahan@143 779 local world_map = _G.WorldMapFrame
jcallahan@143 780 local map_visible = world_map:IsVisible()
jcallahan@312 781 local sfx_value = tonumber(_G.GetCVar("Sound_EnableSFX"))
jcallahan@143 782
jcallahan@143 783 if not map_visible then
jcallahan@143 784 _G.SetCVar("Sound_EnableSFX", 0)
jcallahan@143 785 world_map:Show()
jcallahan@143 786 end
jcallahan@331 787 local _, _, _, _, micro_dungeon_map_name = _G.GetMapInfo()
jcallahan@331 788 local micro_dungeon_id = MICRO_DUNGEON_IDS[micro_dungeon_map_name]
jcallahan@143 789
jcallahan@154 790 _G.SetMapToCurrentZone()
jcallahan@154 791
jcallahan@143 792 if micro_dungeon_id then
jcallahan@143 793 current_area_id = micro_dungeon_id
jcallahan@143 794 else
jcallahan@143 795 current_area_id = _G.GetCurrentMapAreaID()
jcallahan@143 796 end
jcallahan@143 797
jcallahan@154 798 if map_visible then
jcallahan@154 799 _G.SetMapByID(map_area_id)
jcallahan@154 800 else
jcallahan@143 801 world_map:Hide()
jcallahan@143 802 _G.SetCVar("Sound_EnableSFX", sfx_value)
jcallahan@143 803 end
jcallahan@143 804 end
jcallahan@299 805
jcallahan@299 806 function WDP:HandleZoneChange(event_name)
jcallahan@299 807 in_instance = _G.IsInInstance()
jcallahan@299 808 SetCurrentAreaID()
jcallahan@299 809 end
jcallahan@154 810 end
jcallahan@126 811
jcallahan@301 812 local function InitializeCurrentLoot()
jcallahan@301 813 current_loot = {
jcallahan@301 814 list = {},
jcallahan@301 815 sources = {},
jcallahan@301 816 identifier = current_action.identifier,
jcallahan@301 817 label = current_action.loot_label or "drops",
jcallahan@301 818 map_level = current_action.map_level,
jcallahan@301 819 object_name = current_action.object_name,
jcallahan@301 820 spell_label = current_action.spell_label,
jcallahan@301 821 target_type = current_action.target_type,
jcallahan@301 822 x = current_action.x,
jcallahan@301 823 y = current_action.y,
jcallahan@301 824 zone_data = current_action.zone_data,
jcallahan@301 825 }
jcallahan@301 826
jcallahan@301 827 table.wipe(current_action)
jcallahan@301 828 end
jcallahan@246 829
MMOSimca@347 830
MMOSimca@347 831 -- TIMERS -------------------------------------------------------------
MMOSimca@347 832
MMOSimca@347 833 local function ClearKilledNPC()
MMOSimca@347 834 killed_npc_id = nil
MMOSimca@347 835 end
MMOSimca@347 836
MMOSimca@347 837
MMOSimca@347 838 local function ClearKilledBossID()
MMOSimca@347 839 if killed_boss_id_timer_handle then
MMOSimca@347 840 WDP:CancelTimer(killed_boss_id_timer_handle)
MMOSimca@347 841 killed_boss_id_timer_handle = nil
MMOSimca@347 842 end
MMOSimca@347 843
MMOSimca@347 844 table.wipe(boss_loot_toasting)
MMOSimca@347 845 private.raid_boss_id = nil
MMOSimca@347 846 end
MMOSimca@347 847
MMOSimca@347 848
MMOSimca@347 849 local function ClearLootToastContainerID()
MMOSimca@347 850 if loot_toast_container_timer_handle then
MMOSimca@347 851 WDP:CancelTimer(loot_toast_container_timer_handle)
MMOSimca@347 852 loot_toast_container_timer_handle = nil
MMOSimca@347 853 end
MMOSimca@347 854
MMOSimca@347 855 private.container_loot_toasting = false
MMOSimca@347 856 private.loot_toast_container_id = nil
MMOSimca@347 857 end
MMOSimca@347 858
MMOSimca@347 859
MMOSimca@347 860 local function ClearLootToastData()
MMOSimca@347 861 -- cancel existing timer if found
MMOSimca@347 862 if loot_toast_data_timer_handle then
MMOSimca@347 863 WDP:CancelTimer(loot_toast_data_timer_handle)
MMOSimca@347 864 loot_toast_data_timer_handle = nil
MMOSimca@347 865 end
MMOSimca@347 866
MMOSimca@347 867 if loot_toast_data then
MMOSimca@347 868 table.wipe(loot_toast_data)
MMOSimca@347 869 end
MMOSimca@347 870 end
MMOSimca@347 871
MMOSimca@347 872
MMOSimca@347 873 local function ClearTimeBasedLootData()
MMOSimca@349 874 Debug("ClearTimeBasedLootData: Ending salvage loot timer.")
MMOSimca@347 875 if chat_loot_timer_handle then
MMOSimca@347 876 WDP:CancelTimer(chat_loot_timer_handle)
MMOSimca@347 877 chat_loot_timer_handle = nil
MMOSimca@347 878 end
MMOSimca@347 879
MMOSimca@349 880 if current_loot and current_loot.identifier and (current_loot.identifier == BAG_OF_SALVAGE_ITEM_ID or current_loot.identifier == CRATE_OF_SALVAGE_ITEM_ID or current_loot.identifier == BIG_CRATE_OF_SALVAGE_ITEM_ID) then
MMOSimca@347 881 GenericLootUpdate("items")
MMOSimca@347 882 end
MMOSimca@347 883 current_loot = nil
MMOSimca@347 884 end
MMOSimca@347 885
MMOSimca@347 886
jcallahan@246 887 -- METHODS ------------------------------------------------------------
jcallahan@246 888
jcallahan@0 889 function WDP:OnInitialize()
jcallahan@128 890 local db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default")
jcallahan@270 891 private.db = db
jcallahan@128 892 global_db = db.global
jcallahan@128 893 char_db = db.char
jcallahan@14 894
jcallahan@270 895 local raw_db = _G.WoWDBProfilerData
jcallahan@18 896 local build_num = tonumber(private.build_num)
jcallahan@14 897
jcallahan@136 898 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 899 for entry in pairs(DATABASE_DEFAULTS.global) do
jcallahan@128 900 global_db[entry] = {}
jcallahan@74 901 end
jcallahan@74 902 end
jcallahan@35 903 raw_db.build_num = build_num
MMOSimca@330 904 raw_db.region = private.region
jcallahan@63 905 raw_db.version = DB_VERSION
jcallahan@249 906
jcallahan@312 907 private.InitializeCommentSystem()
jcallahan@312 908 self:RegisterChatCommand("comment", private.ProcessCommentCommand)
jcallahan@0 909 end
jcallahan@0 910
jcallahan@0 911
jcallahan@153 912 function WDP:EventDispatcher(...)
jcallahan@153 913 local event_name = ...
jcallahan@153 914
MMOSimca@346 915 if DEBUGGING then
jcallahan@154 916 if event_name == "COMBAT_LOG_EVENT_UNFILTERED" then
jcallahan@154 917 Debug(event_name)
jcallahan@154 918 else
jcallahan@154 919 Debug(...)
jcallahan@153 920 end
jcallahan@153 921 end
jcallahan@153 922 local func = EVENT_MAPPING[event_name]
jcallahan@153 923
jcallahan@153 924 if _G.type(func) == "boolean" then
jcallahan@153 925 self[event_name](self, ...)
jcallahan@153 926 elseif _G.type(func) == "function" then
jcallahan@159 927 self[func](self, ...)
jcallahan@153 928 end
jcallahan@153 929 end
jcallahan@153 930
jcallahan@153 931
jcallahan@0 932 function WDP:OnEnable()
jcallahan@300 933 PLAYER_GUID = _G.UnitGUID("player")
jcallahan@300 934
jcallahan@0 935 for event_name, mapping in pairs(EVENT_MAPPING) do
jcallahan@156 936 if EVENT_DEBUG then
jcallahan@153 937 self:RegisterEvent(event_name, "EventDispatcher")
jcallahan@153 938 else
jcallahan@153 939 self:RegisterEvent(event_name, (_G.type(mapping) ~= "boolean") and mapping or nil)
jcallahan@153 940 end
jcallahan@0 941 end
jcallahan@95 942
jcallahan@95 943 for index = 1, _G.GetNumLanguages() do
jcallahan@95 944 languages_known[_G.GetLanguageByIndex(index)] = true
jcallahan@95 945 end
jcallahan@187 946 item_process_timer_handle = self:ScheduleRepeatingTimer("ProcessItems", 30)
jcallahan@31 947 target_location_timer_handle = self:ScheduleRepeatingTimer("UpdateTargetLocation", 0.5)
jcallahan@19 948
jcallahan@19 949 _G.hooksecurefunc("UseContainerItem", function(bag_index, slot_index, target_unit)
jcallahan@19 950 if target_unit then
jcallahan@19 951 return
jcallahan@19 952 end
jcallahan@19 953 HandleItemUse(_G.GetContainerItemLink(bag_index, slot_index), bag_index, slot_index)
jcallahan@19 954 end)
jcallahan@19 955
jcallahan@19 956 _G.hooksecurefunc("UseItemByName", function(identifier, target_unit)
jcallahan@19 957 if target_unit then
jcallahan@19 958 return
jcallahan@19 959 end
jcallahan@19 960 local _, item_link = _G.GetItemInfo(identifier)
jcallahan@19 961 HandleItemUse(item_link)
jcallahan@19 962 end)
jcallahan@263 963
jcallahan@299 964 self:HandleZoneChange("OnEnable")
jcallahan@290 965 self:GROUP_ROSTER_UPDATE()
jcallahan@0 966 end
jcallahan@0 967
jcallahan@0 968
jcallahan@219 969 local ScrapeItemUpgradeStats
jcallahan@219 970 do
jcallahan@219 971 local intermediary = {}
jcallahan@219 972
jcallahan@220 973 function ScrapeItemUpgradeStats(item_id, upgrade_id, reforge_id)
jcallahan@220 974 if not ALLOWED_LOCALES[CLIENT_LOCALE] then
jcallahan@220 975 return
jcallahan@220 976 end
jcallahan@219 977 local create_entry
jcallahan@219 978
jcallahan@219 979 table.wipe(intermediary)
jcallahan@219 980
jcallahan@219 981 for line_index = 1, DatamineTT:NumLines() do
jcallahan@293 982 local left_text = _G["WDPDatamineTTTextLeft" .. line_index]:GetText():trim()
jcallahan@293 983
jcallahan@293 984 if not left_text or left_text == "" or left_text:find("Socket") or left_text:find("Set:") then
jcallahan@293 985 break
jcallahan@219 986 end
jcallahan@219 987 local amount, stat = left_text:match("+(.-) (.*)")
jcallahan@219 988
jcallahan@219 989 if amount and stat then
jcallahan@219 990 create_entry = true
jcallahan@295 991 intermediary[stat:lower():gsub(" ", "_"):gsub("|r", "")] = tonumber((amount:gsub(",", "")))
jcallahan@219 992 end
jcallahan@219 993 end
jcallahan@219 994
jcallahan@219 995 if not create_entry then
jcallahan@219 996 return
jcallahan@219 997 end
jcallahan@219 998 local item = DBEntry("items", item_id)
jcallahan@225 999 item.upgrade_id = upgrade_id
jcallahan@219 1000 item.upgrades = item.upgrades or {}
jcallahan@219 1001 item.upgrades[upgrade_id] = item.upgrades[upgrade_id] or {}
jcallahan@219 1002
jcallahan@219 1003 for stat, amount in pairs(intermediary) do
jcallahan@219 1004 item.upgrades[upgrade_id][stat] = amount
jcallahan@219 1005 end
jcallahan@219 1006 end
MMOSimca@336 1007 end -- do-block
jcallahan@219 1008
jcallahan@219 1009
MMOSimca@340 1010 local function RecordItemData(item_id, item_link, process_bonus_ids, durability)
jcallahan@331 1011 local _, _, item_string = item_link:find("^|%x+|H(.+)|h%[.+%]")
jcallahan@219 1012 local item
jcallahan@0 1013
jcallahan@191 1014 if item_string then
MMOSimca@338 1015 local item_results = { (":"):split(item_string) }
MMOSimca@338 1016
MMOSimca@338 1017 local suffix_id = tonumber(item_results[8])
MMOSimca@338 1018 local unique_id = item_results[9]
MMOSimca@338 1019 local upgrade_id = tonumber(item_results[11])
MMOSimca@338 1020 local instance_difficulty_id = tonumber(item_results[12])
MMOSimca@338 1021 local num_bonus_ids = tonumber(item_results[13])
jcallahan@333 1022
MMOSimca@340 1023 if not num_bonus_ids or num_bonus_ids == 0 or not process_bonus_ids then
MMOSimca@329 1024 if (suffix_id and suffix_id ~= 0) or (instance_difficulty_id and instance_difficulty_id ~= 0) then
MMOSimca@329 1025 item = DBEntry("items", item_id)
MMOSimca@329 1026 item.unique_id = bit.band(unique_id, 0xFFFF)
jcallahan@331 1027
jcallahan@331 1028 if suffix_id and suffix_id ~= 0 then
MMOSimca@329 1029 item.suffix_id = suffix_id
MMOSimca@329 1030 end
jcallahan@331 1031
jcallahan@331 1032 if instance_difficulty_id and instance_difficulty_id ~= 0 then
MMOSimca@329 1033 item.instance_difficulty_id = instance_difficulty_id
MMOSimca@329 1034 end
MMOSimca@329 1035 end
MMOSimca@329 1036 elseif num_bonus_ids > 0 then
jcallahan@219 1037 item = DBEntry("items", item_id)
MMOSimca@329 1038
jcallahan@201 1039 item.unique_id = bit.band(unique_id, 0xFFFF)
MMOSimca@329 1040 item.instance_difficulty_id = instance_difficulty_id
jcallahan@331 1041
MMOSimca@329 1042 if not item.bonus_ids then
MMOSimca@329 1043 item.bonus_ids = {}
MMOSimca@329 1044 end
MMOSimca@338 1045
MMOSimca@329 1046 for bonus_index = 1, num_bonus_ids do
MMOSimca@338 1047 item.bonus_ids[tonumber(item_results[13 + bonus_index])] = true
MMOSimca@329 1048 end
MMOSimca@329 1049 else
MMOSimca@329 1050 Debug("RecordItemData: Item_system is supposed to be 0 or positive, instead it was %s.", item_system)
jcallahan@201 1051 end
jcallahan@219 1052 if upgrade_id and upgrade_id ~= 0 then
jcallahan@220 1053 DatamineTT:SetHyperlink(item_link)
MMOSimca@329 1054 ScrapeItemUpgradeStats(item_id, upgrade_id)
jcallahan@191 1055 end
jcallahan@0 1056 end
jcallahan@212 1057
jcallahan@212 1058 if durability and durability > 0 then
jcallahan@219 1059 item = item or DBEntry("items", item_id)
jcallahan@212 1060 item.durability = durability
jcallahan@212 1061 end
jcallahan@0 1062 end
jcallahan@0 1063
jcallahan@0 1064
jcallahan@187 1065 function WDP:ProcessItems()
jcallahan@187 1066 for slot_index = _G.INVSLOT_FIRST_EQUIPPED, _G.INVSLOT_LAST_EQUIPPED do
jcallahan@1 1067 local item_id = _G.GetInventoryItemID("player", slot_index)
jcallahan@0 1068
jcallahan@0 1069 if item_id and item_id > 0 then
jcallahan@1 1070 local _, max_durability = _G.GetInventoryItemDurability(slot_index)
MMOSimca@340 1071 RecordItemData(item_id, _G.GetInventoryItemLink("player", slot_index), false, max_durability)
jcallahan@0 1072 end
jcallahan@0 1073 end
jcallahan@0 1074
jcallahan@0 1075 for bag_index = 0, _G.NUM_BAG_SLOTS do
jcallahan@0 1076 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
jcallahan@1 1077 local item_id = _G.GetContainerItemID(bag_index, slot_index)
jcallahan@0 1078
jcallahan@0 1079 if item_id and item_id > 0 then
jcallahan@1 1080 local _, max_durability = _G.GetContainerItemDurability(bag_index, slot_index)
MMOSimca@340 1081 RecordItemData(item_id, _G.GetContainerItemLink(bag_index, slot_index), false, max_durability)
jcallahan@0 1082 end
jcallahan@0 1083 end
jcallahan@0 1084 end
jcallahan@0 1085 end
jcallahan@0 1086
jcallahan@118 1087
jcallahan@215 1088 local TargetedNPC
jcallahan@118 1089 do
jcallahan@118 1090 local GENDER_NAMES = {
jcallahan@118 1091 "UNKNOWN",
jcallahan@118 1092 "MALE",
jcallahan@118 1093 "FEMALE",
jcallahan@118 1094 }
jcallahan@118 1095
jcallahan@118 1096
jcallahan@118 1097 local REACTION_NAMES = {
jcallahan@118 1098 "HATED",
jcallahan@118 1099 "HOSTILE",
jcallahan@118 1100 "UNFRIENDLY",
jcallahan@118 1101 "NEUTRAL",
jcallahan@118 1102 "FRIENDLY",
jcallahan@118 1103 "HONORED",
jcallahan@118 1104 "REVERED",
jcallahan@118 1105 "EXALTED",
jcallahan@118 1106 }
jcallahan@118 1107
jcallahan@118 1108
jcallahan@118 1109 local POWER_TYPE_NAMES = {
jcallahan@118 1110 ["0"] = "MANA",
jcallahan@118 1111 ["1"] = "RAGE",
jcallahan@118 1112 ["2"] = "FOCUS",
jcallahan@118 1113 ["3"] = "ENERGY",
jcallahan@118 1114 ["6"] = "RUNIC_POWER",
jcallahan@118 1115 }
jcallahan@118 1116
jcallahan@118 1117
jcallahan@215 1118 function TargetedNPC()
jcallahan@118 1119 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or currently_drunk then
jcallahan@118 1120 current_target_id = nil
jcallahan@118 1121 return
jcallahan@118 1122 end
jcallahan@118 1123 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
jcallahan@118 1124
jcallahan@171 1125 if not unit_idnum or not UnitTypeIsNPC(unit_type) then
jcallahan@118 1126 return
jcallahan@118 1127 end
jcallahan@118 1128 current_target_id = unit_idnum
jcallahan@118 1129
jcallahan@118 1130 local npc = NPCEntry(unit_idnum)
jcallahan@118 1131 local _, class_token = _G.UnitClass("target")
jcallahan@118 1132 npc.class = class_token
jcallahan@118 1133 npc.faction = UnitFactionStanding("target")
jcallahan@118 1134 npc.genders = npc.genders or {}
jcallahan@118 1135 npc.genders[GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"] = true
jcallahan@118 1136 npc.is_pvp = _G.UnitIsPVP("target") and true or nil
jcallahan@118 1137 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")])
jcallahan@118 1138
jcallahan@248 1139 local encounter_data = npc:EncounterData(InstanceDifficultyToken()).stats
jcallahan@118 1140 local npc_level = ("level_%d"):format(_G.UnitLevel("target"))
jcallahan@250 1141 local level_data = encounter_data[npc_level]
jcallahan@250 1142
jcallahan@250 1143 if not level_data then
jcallahan@250 1144 level_data = {}
jcallahan@250 1145 encounter_data[npc_level] = level_data
jcallahan@250 1146 end
jcallahan@257 1147 level_data.max_health = level_data.max_health or _G.UnitHealthMax("target")
jcallahan@257 1148
jcallahan@257 1149 if not level_data.power then
MMOSimca@337 1150 local max_power = _G.UnitPowerMax("target")
jcallahan@257 1151
jcallahan@257 1152 if max_power > 0 then
jcallahan@257 1153 local power_type = _G.UnitPowerType("target")
jcallahan@312 1154 level_data.power = ("%s:%d"):format(POWER_TYPE_NAMES[tostring(power_type)] or power_type, max_power)
jcallahan@257 1155 end
jcallahan@118 1156 end
jcallahan@118 1157 name_to_id_map[_G.UnitName("target")] = unit_idnum
jcallahan@118 1158 return npc, unit_idnum
jcallahan@118 1159 end
jcallahan@118 1160 end -- do-block
jcallahan@118 1161
jcallahan@118 1162
jcallahan@113 1163 do
jcallahan@113 1164 local COORD_MAX = 5
jcallahan@0 1165
jcallahan@113 1166 function WDP:UpdateTargetLocation()
jcallahan@113 1167 if currently_drunk or not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or (_G.UnitIsTapped("target") and not _G.UnitIsDead("target")) then
jcallahan@2 1168 return
jcallahan@2 1169 end
jcallahan@113 1170
jcallahan@113 1171 for index = 1, 4 do
jcallahan@113 1172 if not _G.CheckInteractDistance("target", index) then
jcallahan@113 1173 return
jcallahan@113 1174 end
jcallahan@113 1175 end
jcallahan@215 1176 local npc = TargetedNPC()
jcallahan@113 1177
jcallahan@113 1178 if not npc then
jcallahan@113 1179 return
jcallahan@113 1180 end
jcallahan@113 1181 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData()
MMOSimca@328 1182 if not (zone_name and area_id and x and y and map_level) then
MMOSimca@328 1183 Debug("UpdateTargetLocation: Missing current location data - %s, %d, %d, %d, %d.", zone_name, area_id, x, y, map_level)
MMOSimca@328 1184 return
MMOSimca@328 1185 end
jcallahan@248 1186 local npc_data = npc:EncounterData(difficulty_token).stats[("level_%d"):format(_G.UnitLevel("target"))]
jcallahan@113 1187 local zone_token = ("%s:%d"):format(zone_name, area_id)
jcallahan@118 1188 npc_data.locations = npc_data.locations or {} -- TODO: Fix this. It is broken. Possibly something to do with the timed updates.
jcallahan@113 1189
jcallahan@113 1190 local zone_data = npc_data.locations[zone_token]
jcallahan@113 1191
jcallahan@113 1192 if not zone_data then
jcallahan@113 1193 zone_data = {}
jcallahan@113 1194 npc_data.locations[zone_token] = zone_data
jcallahan@113 1195 end
jcallahan@113 1196
jcallahan@113 1197 for location_token in pairs(zone_data) do
jcallahan@113 1198 local loc_level, loc_x, loc_y = (":"):split(location_token)
jcallahan@113 1199 loc_level = tonumber(loc_level)
jcallahan@113 1200
jcallahan@113 1201 if map_level == loc_level and math.abs(x - loc_x) <= COORD_MAX and math.abs(y - loc_y) <= COORD_MAX then
jcallahan@113 1202 return
jcallahan@113 1203 end
jcallahan@113 1204 end
jcallahan@141 1205 zone_data[("%d:%d:%d"):format(map_level, x, y)] = true
jcallahan@2 1206 end
jcallahan@113 1207 end -- do-block
jcallahan@2 1208
jcallahan@118 1209
jcallahan@246 1210 -- EVENT HANDLERS -----------------------------------------------------
jcallahan@246 1211
jcallahan@90 1212 function WDP:BLACK_MARKET_ITEM_UPDATE(event_name)
jcallahan@243 1213 if not ALLOWED_LOCALES[CLIENT_LOCALE] then
jcallahan@243 1214 return
jcallahan@243 1215 end
jcallahan@282 1216 local num_items = _G.C_BlackMarket.GetNumItems() or 0
jcallahan@56 1217
jcallahan@56 1218 for index = 1, num_items do
jcallahan@56 1219 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 1220
jcallahan@56 1221 if item_link then
jcallahan@56 1222 DBEntry("items", ItemLinkToID(item_link)).black_market = seller_name or "UNKNOWN"
jcallahan@56 1223 end
jcallahan@56 1224 end
jcallahan@56 1225 end
jcallahan@56 1226
jcallahan@56 1227
jcallahan@298 1228 local function UpdateUnitPet(unit_guid, unit_id)
jcallahan@246 1229 local current_pet_guid = group_owner_guids_to_pet_guids[unit_guid]
jcallahan@246 1230
jcallahan@246 1231 if current_pet_guid then
jcallahan@246 1232 group_owner_guids_to_pet_guids[unit_guid] = nil
jcallahan@246 1233 group_pet_guids[current_pet_guid] = nil
jcallahan@246 1234 end
jcallahan@246 1235 local pet_guid = _G.UnitGUID(unit_id .. "pet")
jcallahan@246 1236
jcallahan@246 1237 if pet_guid then
jcallahan@296 1238 group_owner_guids_to_pet_guids[unit_guid] = pet_guid
jcallahan@246 1239 group_pet_guids[pet_guid] = true
jcallahan@246 1240 end
jcallahan@246 1241 end
jcallahan@246 1242
jcallahan@246 1243
jcallahan@298 1244 function WDP:GROUP_ROSTER_UPDATE(event_name)
jcallahan@298 1245 local is_raid = _G.IsInRaid()
jcallahan@298 1246 local unit_type = is_raid and "raid" or "party"
jcallahan@298 1247 local group_size = is_raid and _G.GetNumGroupMembers() or _G.GetNumSubgroupMembers()
jcallahan@298 1248
jcallahan@299 1249 table.wipe(group_member_guids)
jcallahan@298 1250
jcallahan@298 1251 for index = 1, group_size do
jcallahan@298 1252 local unit_id = unit_type .. index
jcallahan@298 1253 local unit_guid = _G.UnitGUID(unit_id)
jcallahan@298 1254
jcallahan@299 1255 group_member_guids[unit_guid] = true
jcallahan@298 1256 UpdateUnitPet(unit_guid, unit_id)
jcallahan@298 1257 end
jcallahan@299 1258 group_member_guids[PLAYER_GUID] = true
jcallahan@298 1259 end
jcallahan@298 1260
jcallahan@298 1261
jcallahan@298 1262 function WDP:UNIT_PET(event_name, unit_id)
jcallahan@298 1263 UpdateUnitPet(_G.UnitGUID(unit_id), unit_id)
jcallahan@298 1264 end
jcallahan@298 1265
jcallahan@298 1266
jcallahan@178 1267 function WDP:SHOW_LOOT_TOAST(event_name, loot_type, item_link, quantity)
jcallahan@312 1268 if not loot_type or (loot_type ~= "item" and loot_type ~= "money" and loot_type ~= "currency") then
jcallahan@306 1269 Debug("%s: loot_type is %s. Item link is %s, and quantity is %d.", event_name, loot_type, item_link, quantity)
jcallahan@306 1270 return
jcallahan@306 1271 end
jcallahan@301 1272 local container_id = private.loot_toast_container_id
MMOSimca@336 1273 local npc_id = private.raid_boss_id
jcallahan@317 1274
jcallahan@317 1275 if npc_id then
MMOSimca@336 1276 -- Slightly messy hack to workaround duplicate world bosses
jcallahan@317 1277 local upper_limit = 0
jcallahan@317 1278 if DUPLICATE_WORLD_BOSS_IDS[npc_id] then
jcallahan@317 1279 upper_limit = #DUPLICATE_WORLD_BOSS_IDS[npc_id]
jcallahan@317 1280 end
jcallahan@317 1281 for i = 0, upper_limit do
jcallahan@317 1282 local temp_npc_id = npc_id
jcallahan@317 1283
jcallahan@317 1284 if i > 0 then
jcallahan@317 1285 temp_npc_id = DUPLICATE_WORLD_BOSS_IDS[npc_id][i]
jcallahan@312 1286 end
jcallahan@317 1287
jcallahan@317 1288 local npc = NPCEntry(temp_npc_id)
jcallahan@317 1289 if npc then
jcallahan@317 1290 local loot_label = "drops"
jcallahan@317 1291 local encounter_data = npc:EncounterData(InstanceDifficultyToken())
jcallahan@317 1292 encounter_data[loot_label] = encounter_data[loot_label] or {}
jcallahan@317 1293 encounter_data.loot_counts = encounter_data.loot_counts or {}
jcallahan@317 1294
jcallahan@317 1295 if loot_type == "item" then
jcallahan@317 1296 local item_id = ItemLinkToID(item_link)
jcallahan@317 1297 if item_id then
jcallahan@317 1298 Debug("%s: %s X %d (%d)", event_name, item_link, quantity, item_id)
MMOSimca@340 1299 RecordItemData(item_id, item_link, true)
jcallahan@317 1300 table.insert(encounter_data[loot_label], ("%d:%d"):format(item_id, quantity))
jcallahan@317 1301 else
jcallahan@317 1302 Debug("%s: ItemID is nil, from item link %s", event_name, item_link)
jcallahan@317 1303 return
jcallahan@317 1304 end
jcallahan@317 1305 elseif loot_type == "money" then
jcallahan@317 1306 Debug("%s: money X %d", event_name, quantity)
jcallahan@317 1307 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity))
jcallahan@317 1308 elseif loot_type == "currency" then
jcallahan@317 1309 local currency_texture = CurrencyLinkToTexture(item_link)
jcallahan@317 1310 if currency_texture and currency_texture ~= "" then
jcallahan@317 1311 Debug("%s: %s X %d", event_name, currency_texture, quantity)
MMOSimca@337 1312 -- Workaround for Patch 5.4.0 bug with Flexible raid Siege of Orgrimmar bosses and Valor Points
jcallahan@317 1313 if quantity > 1000 and currency_texture == "pvecurrency-valor" then
jcallahan@317 1314 quantity = math.floor(quantity / 100)
jcallahan@317 1315 end
jcallahan@317 1316 table.insert(encounter_data[loot_label], ("currency:%d:%s"):format(quantity, currency_texture))
jcallahan@317 1317 else
jcallahan@317 1318 Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link)
jcallahan@317 1319 return
jcallahan@317 1320 end
jcallahan@317 1321 end
jcallahan@317 1322
jcallahan@317 1323 if not boss_loot_toasting[temp_npc_id] then
jcallahan@317 1324 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1
jcallahan@317 1325 boss_loot_toasting[temp_npc_id] = true -- Do not count further loots until timer expires or another boss is killed
jcallahan@317 1326 end
jcallahan@312 1327 end
jcallahan@312 1328 end
jcallahan@301 1329 elseif container_id then
jcallahan@305 1330 InitializeCurrentLoot()
jcallahan@305 1331
jcallahan@306 1332 -- Fake the loot characteristics to match that of an actual container item
jcallahan@306 1333 current_loot.identifier = container_id
jcallahan@306 1334 current_loot.label = "contains"
jcallahan@306 1335 current_loot.target_type = AF.ITEM
jcallahan@306 1336
jcallahan@312 1337 current_loot.sources[container_id] = current_loot.sources[container_id] or {}
jcallahan@312 1338
jcallahan@301 1339 if loot_type == "item" then
jcallahan@312 1340 local item_id = ItemLinkToID(item_link)
jcallahan@312 1341 if item_id then
jcallahan@312 1342 Debug("%s: %s X %d (%d)", event_name, item_link, quantity, item_id)
MMOSimca@340 1343 RecordItemData(item_id, item_link, true)
jcallahan@312 1344 current_loot.sources[container_id][item_id] = current_loot.sources[container_id][item_id] or 0 + quantity
jcallahan@312 1345 else
jcallahan@301 1346 Debug("%s: ItemID is nil, from item link %s", event_name, item_link)
jcallahan@312 1347 current_loot = nil
jcallahan@301 1348 return
jcallahan@301 1349 end
jcallahan@301 1350 elseif loot_type == "money" then
jcallahan@312 1351 Debug("%s: money X %d", event_name, quantity)
jcallahan@312 1352 current_loot.sources[container_id]["money"] = current_loot.sources[container_id]["money"] or 0 + quantity
jcallahan@312 1353 elseif loot_type == "currency" then
jcallahan@312 1354 local currency_texture = CurrencyLinkToTexture(item_link)
jcallahan@312 1355 if currency_texture and currency_texture ~= "" then
jcallahan@312 1356 Debug("%s: %s X %d", event_name, currency_texture, quantity)
jcallahan@312 1357 local currency_token = ("currency:%s"):format(currency_texture)
jcallahan@312 1358 current_loot.sources[container_id][currency_token] = current_loot.sources[container_id][currency_token] or 0 + quantity
jcallahan@312 1359 else
jcallahan@312 1360 Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link)
jcallahan@312 1361 current_loot = nil
jcallahan@312 1362 return
jcallahan@312 1363 end
jcallahan@301 1364 end
jcallahan@312 1365
jcallahan@301 1366 GenericLootUpdate("items")
jcallahan@301 1367 current_loot = nil
jcallahan@307 1368 private.container_loot_toasting = true -- Do not count further loots until timer expires or another container is opened
jcallahan@301 1369 else
jcallahan@307 1370 Debug("%s: NPC and Container are nil, storing loot toast data for 5 seconds.", event_name)
jcallahan@307 1371
jcallahan@307 1372 loot_toast_data = loot_toast_data or {}
jcallahan@312 1373 loot_toast_data[#loot_toast_data + 1] = { loot_type, item_link, quantity }
jcallahan@307 1374
MMOSimca@340 1375 local item_id = ItemLinkToID(item_link)
MMOSimca@340 1376 if item_id then
MMOSimca@340 1377 RecordItemData(item_id, item_link, true)
MMOSimca@340 1378 end
MMOSimca@340 1379
jcallahan@307 1380 loot_toast_data_timer_handle = WDP:ScheduleTimer(ClearLootToastData, 5)
jcallahan@178 1381 end
jcallahan@178 1382 end
jcallahan@178 1383
jcallahan@178 1384
jcallahan@179 1385 do
jcallahan@179 1386 local CHAT_MSG_LOOT_UPDATE_FUNCS = {
MMOSimca@347 1387 [AF.ITEM] = function(item_id, quantity)
MMOSimca@349 1388 local container_id = current_loot.identifier -- For faster access, since this is going to be called 9 times in the next 3 lines
MMOSimca@347 1389 -- Verify that we're still assigning data to the right items
MMOSimca@349 1390 if container_id and (container_id == BAG_OF_SALVAGE_ITEM_ID or container_id == CRATE_OF_SALVAGE_ITEM_ID or container_id == BIG_CRATE_OF_SALVAGE_ITEM_ID) then
MMOSimca@347 1391 Debug("CHAT_MSG_LOOT: AF.ITEM %d (%d)", item_id, quantity)
MMOSimca@347 1392 current_loot.sources[container_id] = current_loot.sources[container_id] or {}
MMOSimca@347 1393 current_loot.sources[container_id][item_id] = current_loot.sources[container_id][item_id] or 0 + quantity
MMOSimca@347 1394 else -- If not, cancel the timer and wipe the loot table early
MMOSimca@347 1395 Debug("CHAT_MSG_LOOT: We would have assigned the wrong loot to salvage crates!")
MMOSimca@349 1396 ClearTimeBasedLootData()
MMOSimca@347 1397 end
MMOSimca@347 1398 end,
jcallahan@179 1399 [AF.NPC] = function(item_id, quantity)
MMOSimca@345 1400 Debug("CHAT_MSG_LOOT: AF.NPC %d (%d)", item_id, quantity)
MMOSimca@345 1401 end,
MMOSimca@345 1402 [AF.OBJECT] = function(item_id, quantity)
MMOSimca@345 1403 Debug("CHAT_MSG_LOOT: AF.OBJECT %d (%d)", item_id, quantity)
MMOSimca@345 1404 for timber_variant = 1, #private.LOGGING_SPELL_ID_TO_OBJECT_ID_MAP[last_timber_spell_id] do
MMOSimca@345 1405 -- Check for top level object data
MMOSimca@345 1406 local object_entry = DBEntry("objects", ("OPENING:%s"):format(private.LOGGING_SPELL_ID_TO_OBJECT_ID_MAP[last_timber_spell_id][timber_variant]))
MMOSimca@345 1407 local difficulty_token = InstanceDifficultyToken()
MMOSimca@345 1408 if object_entry[difficulty_token] then
MMOSimca@345 1409 -- Increment loot count
MMOSimca@345 1410 object_entry[difficulty_token]["opening_count"] = object_entry[difficulty_token]["opening_count"] or 0 + 1
MMOSimca@348 1411
MMOSimca@345 1412 -- Add drop data
MMOSimca@348 1413 object_entry[difficulty_token]["opening"] = entry[difficulty_token]["opening"] or {}
MMOSimca@348 1414 table.insert(object_entry[difficulty_token]["opening"], ("%d:%d"):format(item_id, quantity))
MMOSimca@345 1415 else
MMOSimca@345 1416 Debug("CHAT_MSG_LOOT: When handling timber, the top level loot data was missing for objectID %s.", private.LOGGING_SPELL_ID_TO_OBJECT_ID_MAP[last_timber_spell_id][timber_variant])
MMOSimca@345 1417 end
MMOSimca@345 1418 end
jcallahan@179 1419 end,
jcallahan@179 1420 [AF.ZONE] = function(item_id, quantity)
MMOSimca@345 1421 Debug("CHAT_MSG_LOOT: AF.ZONE %d (%d)", item_id, quantity)
jcallahan@312 1422 InitializeCurrentLoot()
jcallahan@312 1423 current_loot.list[1] = ("%d:%d"):format(item_id, quantity)
jcallahan@179 1424 GenericLootUpdate("zones")
jcallahan@312 1425 current_loot = nil
jcallahan@179 1426 end,
jcallahan@179 1427 }
jcallahan@177 1428
jcallahan@177 1429
jcallahan@179 1430 function WDP:CHAT_MSG_LOOT(event_name, message)
jcallahan@179 1431 local category
jcallahan@177 1432
MMOSimca@345 1433 local item_link, quantity = deformat(message, _G.LOOT_ITEM_PUSHED_SELF_MULTIPLE)
MMOSimca@345 1434 if not item_link then
MMOSimca@345 1435 quantity, item_link = 1, deformat(message, _G.LOOT_ITEM_PUSHED_SELF)
MMOSimca@345 1436 end
MMOSimca@345 1437 local item_id = ItemLinkToID(item_link)
MMOSimca@345 1438
MMOSimca@345 1439 if not item_id then
MMOSimca@345 1440 return
MMOSimca@345 1441 end
MMOSimca@345 1442
MMOSimca@345 1443 -- Set update category
MMOSimca@345 1444 if last_timber_spell_id and item_id == TIMBER_ITEM_ID then
MMOSimca@345 1445 category = AF.OBJECT
MMOSimca@345 1446 -- Recently changed from ~= "EXTRACT_GAS" because of some occassional bad data, and, as far as I know, no benefit.
MMOSimca@345 1447 elseif current_action.spell_label == "FISHING" then
jcallahan@179 1448 category = AF.ZONE
MMOSimca@336 1449 elseif private.raid_boss_id then
jcallahan@179 1450 category = AF.NPC
MMOSimca@347 1451 elseif chat_loot_timer_handle then
MMOSimca@347 1452 category = AF.ITEM
jcallahan@179 1453 end
MMOSimca@345 1454
MMOSimca@345 1455 -- Take action based on update category
jcallahan@179 1456 local update_func = CHAT_MSG_LOOT_UPDATE_FUNCS[category]
MMOSimca@340 1457 if not category or not update_func then
MMOSimca@340 1458 -- We still want to record the item's data, even if it doesn't need its drop location recorded
MMOSimca@340 1459 RecordItemData(item_id, item_link, true)
MMOSimca@340 1460 return
MMOSimca@340 1461 end
jcallahan@179 1462 update_func(item_id, quantity)
jcallahan@177 1463 end
jcallahan@48 1464 end
jcallahan@48 1465
jcallahan@312 1466
jcallahan@97 1467 function WDP:RecordQuote(event_name, message, source_name, language_name)
jcallahan@112 1468 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 1469 return
jcallahan@95 1470 end
jcallahan@97 1471 local npc = NPCEntry(name_to_id_map[source_name])
jcallahan@97 1472 npc.quotes = npc.quotes or {}
jcallahan@97 1473 npc.quotes[event_name] = npc.quotes[event_name] or {}
jcallahan@97 1474 npc.quotes[event_name][ReplaceKeywords(message)] = true
jcallahan@97 1475 end
jcallahan@95 1476
jcallahan@95 1477
jcallahan@95 1478 do
jcallahan@40 1479 local SOBER_MATCH = _G.DRUNK_MESSAGE_ITEM_SELF1:gsub("%%s", ".+")
jcallahan@40 1480
jcallahan@40 1481 local DRUNK_COMPARES = {
jcallahan@40 1482 _G.DRUNK_MESSAGE_SELF2,
jcallahan@40 1483 _G.DRUNK_MESSAGE_SELF3,
jcallahan@40 1484 _G.DRUNK_MESSAGE_SELF4,
jcallahan@40 1485 }
jcallahan@40 1486
jcallahan@40 1487 local DRUNK_MATCHES = {
jcallahan@254 1488 (_G.DRUNK_MESSAGE_SELF2:gsub("%%s", ".+")),
jcallahan@254 1489 (_G.DRUNK_MESSAGE_SELF3:gsub("%%s", ".+")),
jcallahan@254 1490 (_G.DRUNK_MESSAGE_SELF4:gsub("%%s", ".+")),
jcallahan@40 1491 }
jcallahan@40 1492
jcallahan@167 1493 local RECIPE_MATCH = _G.ERR_LEARN_RECIPE_S:gsub("%%s", "(.*)")
jcallahan@167 1494
jcallahan@167 1495
jcallahan@167 1496 local function RecordDiscovery(tradeskill_name, tradeskill_index)
jcallahan@167 1497 if tradeskill_name == private.discovered_recipe_name then
jcallahan@167 1498 DBEntry("spells", tonumber(_G.GetTradeSkillRecipeLink(tradeskill_index):match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)"))).discovery = ("%d:%d"):format(private.previous_spell_id, private.profession_level)
jcallahan@167 1499
jcallahan@167 1500 private.discovered_recipe_name = nil
jcallahan@167 1501 private.profession_level = nil
jcallahan@167 1502 private.previous_spell_id = nil
jcallahan@169 1503
jcallahan@169 1504 return true
jcallahan@167 1505 end
jcallahan@167 1506 end
jcallahan@167 1507
jcallahan@167 1508
jcallahan@167 1509 local function IterativeRecordDiscovery()
jcallahan@167 1510 TradeSkillExecutePer(RecordDiscovery)
jcallahan@167 1511 end
jcallahan@167 1512
jcallahan@167 1513
jcallahan@92 1514 function WDP:CHAT_MSG_SYSTEM(event_name, message)
jcallahan@167 1515 if not private.trainer_shown then
jcallahan@167 1516 local recipe_name = message:match(RECIPE_MATCH)
jcallahan@167 1517
jcallahan@167 1518 if recipe_name and private.previous_spell_id then
jcallahan@167 1519 local profession_name, prof_level = _G.GetTradeSkillLine()
jcallahan@167 1520
jcallahan@167 1521 if profession_name == _G.UNKNOWN then
jcallahan@167 1522 return
jcallahan@167 1523 end
jcallahan@167 1524 private.discovered_recipe_name = recipe_name
jcallahan@167 1525 private.profession_level = prof_level
jcallahan@167 1526
jcallahan@167 1527 self:ScheduleTimer(IterativeRecordDiscovery, 0.2)
jcallahan@167 1528 end
jcallahan@167 1529 end
jcallahan@167 1530
jcallahan@40 1531 if currently_drunk then
jcallahan@40 1532 if message == _G.DRUNK_MESSAGE_SELF1 or message:match(SOBER_MATCH) then
jcallahan@40 1533 currently_drunk = nil
jcallahan@40 1534 end
jcallahan@40 1535 return
jcallahan@40 1536 end
jcallahan@40 1537
jcallahan@40 1538 for index = 1, #DRUNK_MATCHES do
jcallahan@40 1539 if message == DRUNK_COMPARES[index] or message:match(DRUNK_MATCHES[index]) then
jcallahan@40 1540 currently_drunk = true
jcallahan@40 1541 break
jcallahan@40 1542 end
jcallahan@40 1543 end
jcallahan@40 1544 end
jcallahan@40 1545 end
jcallahan@40 1546
jcallahan@307 1547
jcallahan@331 1548 do
jcallahan@23 1549 local FLAGS_NPC = bit.bor(_G.COMBATLOG_OBJECT_TYPE_GUARDIAN, _G.COMBATLOG_OBJECT_CONTROL_NPC)
jcallahan@23 1550 local FLAGS_NPC_CONTROL = bit.bor(_G.COMBATLOG_OBJECT_AFFILIATION_OUTSIDER, _G.COMBATLOG_OBJECT_CONTROL_NPC)
jcallahan@23 1551
jcallahan@23 1552 local function RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
MMOSimca@336 1553 if not spell_id or spell_id == CHI_WAVE_SPELL_ID or spell_id == DISGUISE_SPELL_ID then
jcallahan@23 1554 return
jcallahan@23 1555 end
jcallahan@34 1556 local source_type, source_id = ParseGUID(source_guid)
jcallahan@23 1557
jcallahan@171 1558 if not source_id or not UnitTypeIsNPC(source_type) then
jcallahan@23 1559 return
jcallahan@23 1560 end
jcallahan@23 1561
jcallahan@23 1562 if bit.band(FLAGS_NPC_CONTROL, source_flags) == FLAGS_NPC_CONTROL and bit.band(FLAGS_NPC, source_flags) ~= 0 then
jcallahan@248 1563 local encounter_data = NPCEntry(source_id):EncounterData(InstanceDifficultyToken())
jcallahan@28 1564 encounter_data.spells = encounter_data.spells or {}
jcallahan@28 1565 encounter_data.spells[spell_id] = (encounter_data.spells[spell_id] or 0) + 1
jcallahan@23 1566 end
jcallahan@23 1567 end
jcallahan@23 1568
jcallahan@115 1569 local HEAL_BATTLE_PETS_SPELL_ID = 125801
jcallahan@115 1570
jcallahan@246 1571 local previous_combat_event = {}
jcallahan@246 1572
jcallahan@23 1573 local COMBAT_LOG_FUNCS = {
jcallahan@23 1574 SPELL_AURA_APPLIED = RecordNPCSpell,
jcallahan@23 1575 SPELL_CAST_START = RecordNPCSpell,
jcallahan@115 1576 SPELL_CAST_SUCCESS = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
jcallahan@115 1577 if spell_id == HEAL_BATTLE_PETS_SPELL_ID then
jcallahan@115 1578 local unit_type, unit_idnum = ParseGUID(source_guid)
jcallahan@115 1579
jcallahan@171 1580 if unit_idnum and UnitTypeIsNPC(unit_type) then
jcallahan@115 1581 NPCEntry(unit_idnum).stable_master = true
jcallahan@115 1582 end
jcallahan@115 1583 end
jcallahan@115 1584 RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
jcallahan@115 1585 end,
jcallahan@65 1586 UNIT_DIED = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
jcallahan@65 1587 local unit_type, unit_idnum = ParseGUID(dest_guid)
jcallahan@65 1588
jcallahan@171 1589 if not unit_idnum or not UnitTypeIsNPC(unit_type) then
jcallahan@245 1590 Debug("%s: %s is not an NPC, or has no ID.", sub_event, dest_name or _G.UNKNOWN)
jcallahan@177 1591 ClearKilledNPC()
jcallahan@98 1592 private.harvesting = nil
jcallahan@65 1593 return
jcallahan@65 1594 end
jcallahan@177 1595
jcallahan@246 1596 if source_guid == "" then
jcallahan@246 1597 source_guid = nil
jcallahan@246 1598 end
jcallahan@246 1599 local killer_guid = source_guid or previous_combat_event.source_guid
jcallahan@246 1600 local killer_name = source_name or previous_combat_event.source_name
jcallahan@246 1601
jcallahan@299 1602 if not previous_combat_event.party_damage then
jcallahan@312 1603 --Debug("%s: %s was killed by %s (not group member or pet).", sub_event, dest_name or _G.UNKNOWN, killer_name or _G.UNKNOWN) -- broken in Patch 5.4
jcallahan@299 1604 table.wipe(previous_combat_event)
jcallahan@217 1605 ClearKilledNPC()
jcallahan@306 1606 else
jcallahan@317 1607 --Debug("%s: %s was killed by %s.", sub_event, dest_name or _G.UNKNOWN, killer_name or _G.UNKNOWN) -- broken in Patch 5.4
jcallahan@177 1608 end
jcallahan@177 1609 killed_npc_id = unit_idnum
jcallahan@177 1610 WDP:ScheduleTimer(ClearKilledNPC, 0.1)
jcallahan@65 1611 end,
jcallahan@23 1612 }
jcallahan@23 1613
jcallahan@23 1614
jcallahan@246 1615 local NON_DAMAGE_EVENTS = {
jcallahan@246 1616 SPELL_AURA_APPLIED = true,
jcallahan@246 1617 SPELL_AURA_REMOVED = true,
jcallahan@246 1618 SPELL_AURA_REMOVED_DOSE = true,
jcallahan@246 1619 SPELL_CAST_FAILED = true,
jcallahan@246 1620 SWING_MISSED = true,
jcallahan@246 1621 }
jcallahan@246 1622
jcallahan@299 1623 local DAMAGE_EVENTS = {
jcallahan@299 1624 RANGE_DAMAGE = true,
jcallahan@299 1625 SPELL_BUILDING_DAMAGE = true,
jcallahan@299 1626 SPELL_DAMAGE = true,
jcallahan@299 1627 SPELL_PERIODIC_DAMAGE = true,
jcallahan@299 1628 SWING_DAMAGE = true,
jcallahan@299 1629 }
jcallahan@299 1630
jcallahan@246 1631
jcallahan@92 1632 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 1633 local combat_log_func = COMBAT_LOG_FUNCS[sub_event]
jcallahan@23 1634
jcallahan@23 1635 if not combat_log_func then
jcallahan@299 1636 if DAMAGE_EVENTS[sub_event] then
jcallahan@299 1637 table.wipe(previous_combat_event)
jcallahan@246 1638 previous_combat_event.source_name = source_name
jcallahan@299 1639
jcallahan@299 1640 if source_guid ~= dest_guid and (in_instance or group_member_guids[source_guid] or group_pet_guids[source_guid]) then
jcallahan@299 1641 previous_combat_event.party_damage = true
jcallahan@299 1642 end
jcallahan@246 1643 end
jcallahan@23 1644 return
jcallahan@23 1645 end
jcallahan@23 1646 combat_log_func(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, ...)
jcallahan@297 1647
jcallahan@297 1648 if NON_DAMAGE_EVENTS[sub_event] then
jcallahan@297 1649 table.wipe(previous_combat_event)
jcallahan@297 1650 end
jcallahan@23 1651 end
jcallahan@23 1652
MMOSimca@337 1653
jcallahan@44 1654 local DIPLOMACY_SPELL_ID = 20599
jcallahan@44 1655 local MR_POP_RANK1_SPELL_ID = 78634
jcallahan@44 1656 local MR_POP_RANK2_SPELL_ID = 78635
MMOSimca@340 1657 local FACTION_DATA = private.FACTION_DATA
MMOSimca@337 1658 local REP_BUFFS = private.REP_BUFFS
jcallahan@44 1659
jcallahan@44 1660
jcallahan@92 1661 function WDP:COMBAT_TEXT_UPDATE(event_name, message_type, faction_name, amount)
jcallahan@177 1662 if message_type ~= "FACTION" or not killed_npc_id then
jcallahan@44 1663 return
jcallahan@44 1664 end
jcallahan@44 1665 UpdateFactionData()
jcallahan@44 1666
jcallahan@46 1667 if not faction_name or not faction_standings[faction_name] then
jcallahan@46 1668 return
jcallahan@46 1669 end
jcallahan@177 1670 local npc = NPCEntry(killed_npc_id)
jcallahan@177 1671 ClearKilledNPC()
jcallahan@46 1672
jcallahan@44 1673 if not npc then
jcallahan@98 1674 private.harvesting = nil
jcallahan@44 1675 return
jcallahan@44 1676 end
jcallahan@98 1677 npc.harvested = private.harvesting
jcallahan@98 1678 private.harvesting = nil
jcallahan@98 1679
jcallahan@44 1680 local modifier = 1
jcallahan@44 1681
MMOSimca@340 1682 -- Check for modifiers from known spells
jcallahan@44 1683 if _G.IsSpellKnown(DIPLOMACY_SPELL_ID) then
jcallahan@44 1684 modifier = modifier + 0.1
jcallahan@44 1685 end
jcallahan@44 1686 if _G.IsSpellKnown(MR_POP_RANK2_SPELL_ID) then
jcallahan@44 1687 modifier = modifier + 0.1
jcallahan@44 1688 elseif _G.IsSpellKnown(MR_POP_RANK1_SPELL_ID) then
jcallahan@44 1689 modifier = modifier + 0.05
jcallahan@44 1690 end
jcallahan@44 1691
MMOSimca@340 1692 -- Determine faction ID
MMOSimca@340 1693 local faction_ID
MMOSimca@340 1694 for pseudo_faction_name, faction_data_table in pairs(FACTION_DATA) do
MMOSimca@340 1695 if faction_name == faction_data_table[2] then
MMOSimca@340 1696 faction_ID = faction_data_table[1]
MMOSimca@340 1697 end
MMOSimca@340 1698 end
MMOSimca@340 1699 if faction_ID and faction_ID > 0 then
MMOSimca@340 1700 -- Check for modifiers from Commendations (applied directly to the faction, account-wide)
MMOSimca@340 1701 local _, _, _, _, _, _, _, _, _, _, _, _, _, _, has_bonus_rep_gain = GetFactionInfoByID(faction_ID)
MMOSimca@340 1702 if has_bonus_rep_gain then
MMOSimca@340 1703 modifier = modifier + 1
MMOSimca@340 1704 end
MMOSimca@340 1705 end
MMOSimca@340 1706
MMOSimca@340 1707 -- Check for modifiers from buffs
MMOSimca@340 1708 for buff_name, buff_data_table in pairs(REP_BUFFS) do
jcallahan@44 1709 if _G.UnitBuff("player", buff_name) then
MMOSimca@340 1710 local modded_faction = buff_data_table.faction
jcallahan@44 1711
jcallahan@44 1712 if not modded_faction or faction_name == modded_faction then
MMOSimca@340 1713 if buff_data_table.ignore then
MMOSimca@340 1714 -- Some buffs from tabards convert all rep of other factions into rep for a specific faction.
MMOSimca@340 1715 -- We can't know what faction the rep was orginally from, so we must ignore the data entirely in these cases.
MMOSimca@340 1716 return
MMOSimca@340 1717 else
MMOSimca@340 1718 modifier = modifier + buff_data_table.modifier
MMOSimca@340 1719 end
jcallahan@44 1720 end
jcallahan@44 1721 end
jcallahan@44 1722 end
MMOSimca@340 1723
jcallahan@65 1724 npc.reputations = npc.reputations or {}
jcallahan@65 1725 npc.reputations[("%s:%s"):format(faction_name, faction_standings[faction_name])] = math.floor(amount / modifier)
jcallahan@32 1726 end
jcallahan@44 1727 end -- do-block
jcallahan@18 1728
jcallahan@18 1729
jcallahan@140 1730 function WDP:CURSOR_UPDATE(event_name)
jcallahan@141 1731 if current_action.fishing_target or _G.Minimap:IsMouseOver() or current_action.spell_label ~= "FISHING" then
jcallahan@140 1732 return
jcallahan@140 1733 end
jcallahan@140 1734 local text = _G["GameTooltipTextLeft1"]:GetText()
jcallahan@140 1735
jcallahan@140 1736 if not text or text == "Fishing Bobber" then
jcallahan@140 1737 text = "NONE"
jcallahan@140 1738 else
jcallahan@140 1739 current_action.fishing_target = true
jcallahan@140 1740 end
jcallahan@140 1741 current_action.identifier = ("%s:%s"):format(current_action.spell_label, text)
jcallahan@140 1742 end
jcallahan@140 1743
jcallahan@140 1744
jcallahan@92 1745 function WDP:ITEM_TEXT_BEGIN(event_name)
jcallahan@42 1746 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
jcallahan@42 1747
jcallahan@42 1748 if not unit_idnum or unit_type ~= private.UNIT_TYPES.OBJECT or _G.UnitName("npc") ~= _G.ItemTextGetItem() then
jcallahan@42 1749 return
jcallahan@42 1750 end
jcallahan@42 1751 UpdateDBEntryLocation("objects", unit_idnum)
jcallahan@42 1752 end
jcallahan@42 1753
jcallahan@42 1754
jcallahan@13 1755 do
MMOSimca@343 1756 local LOOT_OPENED_VERIFY_FUNCS = {
jcallahan@324 1757 -- Item containers can be AOE-looted in Patch 5.4.2 if the user clicks fast enough, but this verification still works as long as they both have loot.
jcallahan@16 1758 [AF.ITEM] = function()
jcallahan@16 1759 local locked_item_id
jcallahan@16 1760
jcallahan@16 1761 for bag_index = 0, _G.NUM_BAG_FRAMES do
jcallahan@16 1762 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
jcallahan@324 1763 local _, _, is_locked, _, _, is_lootable = _G.GetContainerItemInfo(bag_index, slot_index)
jcallahan@324 1764
jcallahan@324 1765 if is_locked and is_lootable then
jcallahan@16 1766 locked_item_id = ItemLinkToID(_G.GetContainerItemLink(bag_index, slot_index))
jcallahan@165 1767 break
jcallahan@16 1768 end
jcallahan@16 1769 end
jcallahan@165 1770
jcallahan@165 1771 if locked_item_id then
jcallahan@165 1772 break
jcallahan@165 1773 end
jcallahan@16 1774 end
jcallahan@16 1775
jcallahan@122 1776 if not locked_item_id or (current_action.identifier and current_action.identifier ~= locked_item_id) then
jcallahan@16 1777 return false
jcallahan@16 1778 end
jcallahan@122 1779 current_action.identifier = locked_item_id
jcallahan@16 1780 return true
jcallahan@16 1781 end,
jcallahan@322 1782 [AF.NPC] = true,
jcallahan@14 1783 [AF.OBJECT] = true,
jcallahan@17 1784 [AF.ZONE] = function()
jcallahan@140 1785 current_action.zone_data = UpdateDBEntryLocation("zones", current_action.identifier)
jcallahan@210 1786 return _G.IsFishingLoot()
jcallahan@17 1787 end,
jcallahan@13 1788 }
jcallahan@13 1789
jcallahan@13 1790
MMOSimca@343 1791 local LOOT_OPENED_UPDATE_FUNCS = {
jcallahan@16 1792 [AF.ITEM] = function()
jcallahan@28 1793 GenericLootUpdate("items")
jcallahan@28 1794 end,
jcallahan@28 1795 [AF.NPC] = function()
jcallahan@75 1796 local difficulty_token = InstanceDifficultyToken()
jcallahan@312 1797 local loot_label = current_loot.label
jcallahan@77 1798 local source_list = {}
jcallahan@75 1799
jcallahan@131 1800 for source_guid, loot_data in pairs(current_loot.sources) do
jcallahan@331 1801 local _, source_id = ParseGUID(source_guid)
jcallahan@75 1802 local npc = NPCEntry(source_id)
jcallahan@75 1803
jcallahan@75 1804 if npc then
jcallahan@248 1805 local encounter_data = npc:EncounterData(difficulty_token)
jcallahan@312 1806 encounter_data[loot_label] = encounter_data[loot_label] or {}
jcallahan@75 1807
jcallahan@78 1808 if not source_list[source_guid] then
jcallahan@77 1809 encounter_data.loot_counts = encounter_data.loot_counts or {}
jcallahan@312 1810 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1
jcallahan@312 1811 source_list[source_guid] = true
jcallahan@77 1812 end
jcallahan@77 1813
jcallahan@309 1814 for loot_token, quantity in pairs(loot_data) do
jcallahan@312 1815 local loot_type, currency_texture = (":"):split(loot_token)
jcallahan@312 1816
jcallahan@312 1817 if loot_type == "currency" and currency_texture then
jcallahan@312 1818 table.insert(encounter_data[loot_label], ("currency:%d:%s"):format(quantity, currency_texture))
jcallahan@309 1819 elseif loot_token == "money" then
jcallahan@312 1820 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity))
jcallahan@309 1821 else
jcallahan@312 1822 table.insert(encounter_data[loot_label], ("%d:%d"):format(loot_token, quantity))
jcallahan@309 1823 end
jcallahan@75 1824 end
jcallahan@75 1825 end
jcallahan@75 1826 end
jcallahan@16 1827 end,
jcallahan@13 1828 [AF.OBJECT] = function()
jcallahan@28 1829 GenericLootUpdate("objects", InstanceDifficultyToken())
jcallahan@17 1830 end,
jcallahan@17 1831 [AF.ZONE] = function()
MMOSimca@328 1832 if not (current_loot.map_level and current_loot.x and current_loot.y and current_loot.zone_data) then
MMOSimca@328 1833 return
MMOSimca@328 1834 end
jcallahan@141 1835 local location_token = ("%d:%d:%d"):format(current_loot.map_level, current_loot.x, current_loot.y)
jcallahan@41 1836
jcallahan@41 1837 -- This will start life as a boolean true.
jcallahan@131 1838 if _G.type(current_loot.zone_data[location_token]) ~= "table" then
jcallahan@131 1839 current_loot.zone_data[location_token] = {
jcallahan@41 1840 drops = {}
jcallahan@41 1841 }
jcallahan@41 1842 end
jcallahan@132 1843 local loot_count = ("%s_count"):format(current_loot.label)
jcallahan@131 1844 current_loot.zone_data[location_token][loot_count] = (current_loot.zone_data[location_token][loot_count] or 0) + 1
jcallahan@41 1845
jcallahan@131 1846 if current_loot.sources then
jcallahan@131 1847 for source_guid, loot_data in pairs(current_loot.sources) do
jcallahan@131 1848 for item_id, quantity in pairs(loot_data) do
jcallahan@131 1849 table.insert(current_loot.zone_data[location_token].drops, ("%d:%d"):format(item_id, quantity))
jcallahan@131 1850 end
jcallahan@131 1851 end
jcallahan@131 1852 end
jcallahan@131 1853
jcallahan@131 1854 if #current_loot.list <= 0 then
jcallahan@131 1855 return
jcallahan@131 1856 end
jcallahan@131 1857
jcallahan@131 1858 for index = 1, #current_loot.list do
jcallahan@131 1859 table.insert(current_loot.zone_data[location_token].drops, current_loot.loot_list[index])
jcallahan@41 1860 end
jcallahan@13 1861 end,
jcallahan@13 1862 }
jcallahan@13 1863
jcallahan@79 1864 -- Prevent opening the same loot window multiple times from recording data multiple times.
jcallahan@79 1865 local loot_guid_registry = {}
jcallahan@124 1866
jcallahan@124 1867
jcallahan@124 1868 function WDP:LOOT_CLOSED(event_name)
jcallahan@131 1869 current_loot = nil
jcallahan@131 1870 table.wipe(current_action)
jcallahan@124 1871 end
jcallahan@124 1872
jcallahan@13 1873
jcallahan@322 1874 local function ExtrapolatedCurrentActionFromLootData(event_name)
jcallahan@322 1875 local extrapolated_guid_registry = {}
jcallahan@322 1876 local num_guids = 0
jcallahan@322 1877
MMOSimca@344 1878 -- Loot extrapolation cannot handle objects that need special spell labels (like HERBALISM or MINING) (MIND_CONTROL is okay)
MMOSimca@348 1879 if private.SPELL_FLAGS_BY_LABEL[current_action.spell_label] and not private.NON_LOOT_SPELL_LABELS[current_action.spell_label] then
MMOSimca@344 1880 Debug("%s: Problematic spell label %s found. Loot extrapolation for this set of loot would have run an increased risk of introducing bad data into the system.", log_source, private.previous_spell_id)
MMOSimca@344 1881 table.wipe(current_action)
MMOSimca@344 1882 return false
MMOSimca@344 1883 end
MMOSimca@344 1884
jcallahan@322 1885 table.wipe(current_action)
jcallahan@322 1886
jcallahan@322 1887 for loot_slot = 1, _G.GetNumLootItems() do
jcallahan@322 1888 local loot_info = {
jcallahan@322 1889 _G.GetLootSourceInfo(loot_slot)
jcallahan@322 1890 }
jcallahan@322 1891
jcallahan@322 1892 for loot_index = 1, #loot_info, 2 do
jcallahan@322 1893 local source_guid = loot_info[loot_index]
jcallahan@322 1894
jcallahan@322 1895 if not extrapolated_guid_registry[source_guid] then
jcallahan@322 1896 local unit_type, unit_idnum = ParseGUID(source_guid)
jcallahan@322 1897
jcallahan@322 1898 if unit_type and unit_idnum then
jcallahan@322 1899 extrapolated_guid_registry[source_guid] = {
jcallahan@322 1900 unit_type,
jcallahan@322 1901 unit_idnum
jcallahan@322 1902 }
jcallahan@322 1903
jcallahan@322 1904 num_guids = num_guids + 1
jcallahan@322 1905 end
jcallahan@322 1906 end
jcallahan@322 1907 end
jcallahan@322 1908 end
jcallahan@322 1909 local log_source = event_name .. "- ExtrapolatedCurrentActionFromLootData"
jcallahan@322 1910
jcallahan@322 1911 if num_guids == 0 then
jcallahan@322 1912 Debug("%s: No GUIDs found in loot. Blank loot window?", log_source)
jcallahan@322 1913 return false
jcallahan@322 1914 end
jcallahan@326 1915
jcallahan@322 1916 local num_npcs = 0
jcallahan@322 1917 local num_objects = 0
jcallahan@324 1918 local num_itemcontainers = 0
jcallahan@322 1919
jcallahan@322 1920 for source_guid, guid_data in pairs(extrapolated_guid_registry) do
jcallahan@322 1921 local unit_type = guid_data[1]
jcallahan@324 1922 local loot_label = (unit_type == private.UNIT_TYPES.OBJECT) and "opening" or (UnitTypeIsNPC(unit_type) and "drops") or ((unit_type == private.UNIT_TYPES.PLAYER) and "contains")
jcallahan@322 1923
jcallahan@322 1924 if loot_label then
jcallahan@322 1925 local unit_idnum = guid_data[2]
jcallahan@322 1926
jcallahan@322 1927 if loot_guid_registry[loot_label] and loot_guid_registry[loot_label][source_guid] then
jcallahan@322 1928 Debug("%s: Previously scanned loot for unit with GUID %s and identifier %s.", log_source, source_guid, unit_idnum)
jcallahan@322 1929 elseif unit_type == private.UNIT_TYPES.OBJECT and unit_idnum ~= OBJECT_ID_FISHING_BOBBER then
jcallahan@322 1930 current_action.loot_label = loot_label
jcallahan@322 1931 current_action.spell_label = "OPENING"
jcallahan@322 1932 current_action.target_type = AF.OBJECT
jcallahan@322 1933 current_action.identifier = unit_idnum
jcallahan@322 1934 num_objects = num_objects + 1
jcallahan@322 1935 elseif UnitTypeIsNPC(unit_type) then
jcallahan@322 1936 current_action.loot_label = loot_label
jcallahan@322 1937 current_action.target_type = AF.NPC
jcallahan@322 1938 current_action.identifier = unit_idnum
jcallahan@322 1939 num_npcs = num_npcs + 1
jcallahan@324 1940 elseif unit_type == private.UNIT_TYPES.PLAYER then
jcallahan@331 1941 -- Item container GUIDs are currently of the 'PLAYER' type; this may be unintended and could change in the future.
jcallahan@324 1942 current_action.loot_label = loot_label
jcallahan@324 1943 current_action.target_type = AF.ITEM
jcallahan@324 1944 -- current_action.identifier assigned during loot verification.
jcallahan@324 1945 num_itemcontainers = num_itemcontainers + 1
jcallahan@322 1946 end
jcallahan@322 1947 else
jcallahan@322 1948 -- Bail here; not only do we not know what this unit is, but we don't want to attribute loot to something that doesn't actually drop it.
jcallahan@322 1949 Debug("%s: Unit with GUID %s has unsupported type for looting.", log_source, source_guid)
jcallahan@322 1950 return false
jcallahan@322 1951 end
jcallahan@322 1952 end
jcallahan@322 1953
jcallahan@322 1954 if not current_action.target_type then
jcallahan@322 1955 Debug("%s: Failure to obtain target_type.", log_source)
jcallahan@322 1956 return false
jcallahan@322 1957 end
jcallahan@322 1958
jcallahan@322 1959 -- We can't figure out what dropped the loot. This shouldn't ever happen, but hey - Blizzard does some awesome stuff on occasion.
jcallahan@324 1960 if (num_npcs > 0 and num_objects + num_itemcontainers > 0) or (num_objects > 0 and num_npcs + num_itemcontainers > 0) or (num_itemcontainers > 0 and num_npcs + num_objects > 0) then
jcallahan@324 1961 Debug("%s: Mixed target types are not supported. NPCs - %d, Objects - %d, Item Containers - %d.", log_source, num_npcs, num_objects, num_itemcontainers)
jcallahan@322 1962 return false
jcallahan@322 1963 end
jcallahan@322 1964
jcallahan@322 1965 Debug("%s: Successfully extrapolated information for current_action.", log_source)
jcallahan@322 1966 return true
jcallahan@322 1967 end
jcallahan@322 1968
jcallahan@322 1969
MMOSimca@343 1970 function WDP:LOOT_OPENED(event_name)
jcallahan@132 1971 if current_loot then
jcallahan@322 1972 current_loot = nil
jcallahan@322 1973 Debug("%s: Previous loot did not process in time for this event. Attempting to extrapolate current_action from loot data.", event_name)
jcallahan@322 1974
jcallahan@322 1975 if not ExtrapolatedCurrentActionFromLootData(event_name) then
jcallahan@322 1976 Debug("%s: Unable to extrapolate current_action. Aborting attempts to handle loot for now.", event_name)
jcallahan@322 1977 return
jcallahan@322 1978 end
jcallahan@18 1979 end
jcallahan@151 1980
jcallahan@151 1981 if not current_action.target_type then
jcallahan@322 1982 Debug("%s: No target type found. Attempting to extrapolate current_action from loot data.", event_name)
jcallahan@322 1983
jcallahan@322 1984 if not ExtrapolatedCurrentActionFromLootData(event_name) then
jcallahan@322 1985 Debug("%s: Unable to extrapolate current_action. Aborting attempts to handle loot for now.", event_name)
jcallahan@322 1986 return
jcallahan@322 1987 end
jcallahan@151 1988 end
MMOSimca@343 1989 local verify_func = LOOT_OPENED_VERIFY_FUNCS[current_action.target_type]
MMOSimca@343 1990 local update_func = LOOT_OPENED_UPDATE_FUNCS[current_action.target_type]
jcallahan@13 1991
jcallahan@14 1992 if not verify_func or not update_func then
jcallahan@322 1993 Debug("%s: The current action's target type is unsupported or nil.", event_name)
jcallahan@13 1994 return
jcallahan@13 1995 end
jcallahan@13 1996
jcallahan@14 1997 if _G.type(verify_func) == "function" and not verify_func() then
jcallahan@324 1998 Debug("%s: The current action type, %s, is supported but has failed loot verification.", event_name, private.ACTION_TYPE_NAMES[current_action.target_type])
jcallahan@14 1999 return
jcallahan@14 2000 end
jcallahan@80 2001 local guids_used = {}
jcallahan@132 2002
jcallahan@301 2003 InitializeCurrentLoot()
jcallahan@217 2004 loot_guid_registry[current_loot.label] = loot_guid_registry[current_loot.label] or {}
jcallahan@217 2005
jcallahan@55 2006 for loot_slot = 1, _G.GetNumLootItems() do
jcallahan@302 2007 local icon_texture, item_text, slot_quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
jcallahan@55 2008 local slot_type = _G.GetLootSlotType(loot_slot)
jcallahan@237 2009 local loot_info = {
jcallahan@237 2010 _G.GetLootSourceInfo(loot_slot)
jcallahan@237 2011 }
jcallahan@13 2012
jcallahan@237 2013 -- Odd index is GUID, even is count.
jcallahan@237 2014 for loot_index = 1, #loot_info, 2 do
jcallahan@237 2015 local source_guid = loot_info[loot_index]
jcallahan@75 2016
jcallahan@237 2017 if not loot_guid_registry[current_loot.label][source_guid] then
jcallahan@237 2018 local loot_quantity = loot_info[loot_index + 1]
jcallahan@324 2019 -- There is a new bug in 5.4.0 that causes GetLootSlotInfo() to (rarely) return nil values for slot_quantity.
jcallahan@324 2020 if slot_quantity then
jcallahan@324 2021 -- We need slot_quantity to account for an old bug where loot_quantity is sometimes '1' for stacks of items, such as cloth.
jcallahan@324 2022 if slot_quantity > loot_quantity then
jcallahan@324 2023 loot_quantity = slot_quantity
jcallahan@324 2024 end
jcallahan@324 2025 local source_type, source_id = ParseGUID(source_guid)
MMOSimca@329 2026 local source_key = ("%s:%d"):format(source_type, source_id)
jcallahan@324 2027
jcallahan@324 2028 if slot_type == _G.LOOT_SLOT_ITEM then
jcallahan@324 2029 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
jcallahan@324 2030 Debug("GUID: %s - Type:ID: %s - ItemID: %d - Amount: %d (%d)", loot_info[loot_index], source_key, item_id, loot_info[loot_index + 1], slot_quantity)
jcallahan@308 2031 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {}
jcallahan@324 2032 current_loot.sources[source_guid][item_id] = current_loot.sources[source_guid][item_id] or 0 + loot_quantity
jcallahan@309 2033 guids_used[source_guid] = true
jcallahan@324 2034 elseif slot_type == _G.LOOT_SLOT_MONEY then
jcallahan@324 2035 Debug("GUID: %s - Type:ID: %s - Money - Amount: %d (%d)", loot_info[loot_index], source_key, loot_info[loot_index + 1], slot_quantity)
jcallahan@324 2036 if current_loot.target_type == AF.ZONE then
jcallahan@324 2037 table.insert(current_loot.list, ("money:%d"):format(loot_quantity))
jcallahan@324 2038 else
jcallahan@324 2039 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {}
jcallahan@324 2040 current_loot.sources[source_guid]["money"] = current_loot.sources[source_guid]["money"] or 0 + loot_quantity
jcallahan@324 2041 guids_used[source_guid] = true
jcallahan@324 2042 end
jcallahan@324 2043 elseif slot_type == _G.LOOT_SLOT_CURRENCY then
jcallahan@324 2044 -- Same bug with GetLootSlotInfo() will screw up currency when it happens, so we won't process this slot's loot.
jcallahan@324 2045 if icon_texture then
jcallahan@324 2046 Debug("GUID: %s - Type:ID: %s - Currency: %s - Amount: %d (%d)", loot_info[loot_index], source_key, icon_texture, loot_info[loot_index + 1], slot_quantity)
jcallahan@324 2047 if current_loot.target_type == AF.ZONE then
jcallahan@324 2048 table.insert(current_loot.list, ("currency:%d:%s"):format(loot_quantity, icon_texture:match("[^\\]+$"):lower()))
jcallahan@324 2049 else
jcallahan@324 2050 local currency_token = ("currency:%s"):format(icon_texture:match("[^\\]+$"):lower())
jcallahan@324 2051
jcallahan@324 2052 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {}
jcallahan@324 2053 current_loot.sources[source_guid][currency_token] = current_loot.sources[source_guid][currency_token] or 0 + loot_quantity
jcallahan@324 2054 guids_used[source_guid] = true
jcallahan@324 2055 end
jcallahan@324 2056 else
jcallahan@324 2057 Debug("%s: Slot quantity is nil for loot slot %d of the entity with GUID %s and Type:ID: %s.", event_name, loot_slot, loot_info[loot_index], source_key)
jcallahan@324 2058 end
jcallahan@308 2059 end
jcallahan@324 2060 else
jcallahan@324 2061 -- If this is nil, then the item's quantity could be wrong if loot_quantity is wrong, so we won't process this slot's loot.
jcallahan@324 2062 Debug("%s: Slot quantity is nil for loot slot %d of the entity with GUID %s and Type:ID: %s.", event_name, loot_slot, loot_info[loot_index], source_key)
jcallahan@79 2063 end
jcallahan@75 2064 end
jcallahan@13 2065 end
jcallahan@13 2066 end
jcallahan@80 2067
jcallahan@81 2068 for guid in pairs(guids_used) do
jcallahan@217 2069 loot_guid_registry[current_loot.label][guid] = true
jcallahan@80 2070 end
jcallahan@13 2071 update_func()
jcallahan@1 2072 end
jcallahan@13 2073 end -- do-block
jcallahan@0 2074
jcallahan@0 2075
jcallahan@89 2076 function WDP:MAIL_SHOW(event_name)
jcallahan@89 2077 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
jcallahan@89 2078
jcallahan@89 2079 if not unit_idnum or unit_type ~= private.UNIT_TYPES.OBJECT then
jcallahan@89 2080 return
jcallahan@89 2081 end
jcallahan@89 2082 UpdateDBEntryLocation("objects", unit_idnum)
jcallahan@89 2083 end
jcallahan@89 2084
jcallahan@89 2085
jcallahan@44 2086 do
jcallahan@44 2087 local POINT_MATCH_PATTERNS = {
jcallahan@44 2088 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING:gsub("%%d", "(%%d+)")), -- May no longer be necessary
jcallahan@44 2089 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3:gsub("%%d", "(%%d+)")), -- May no longer be necessary
jcallahan@44 2090 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_5V5:gsub("%%d", "(%%d+)")), -- May no longer be necessary
jcallahan@44 2091 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_BG:gsub("%%d", "(%%d+)")),
jcallahan@44 2092 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3_BG:gsub("%%d", "(%%d+)")),
jcallahan@44 2093 }
jcallahan@5 2094
jcallahan@68 2095 local ITEM_REQ_REPUTATION_MATCH = "Requires (.-) %- (.*)"
jcallahan@87 2096 local ITEM_REQ_QUEST_MATCH1 = "Requires: .*"
jcallahan@87 2097 local ITEM_REQ_QUEST_MATCH2 = "Must have completed: .*"
jcallahan@68 2098
jcallahan@133 2099 local current_merchant
jcallahan@133 2100 local merchant_standing
jcallahan@133 2101
jcallahan@133 2102 function WDP:MERCHANT_CLOSED(event_name)
jcallahan@133 2103 current_merchant = nil
jcallahan@133 2104 merchant_standing = nil
jcallahan@133 2105 end
jcallahan@133 2106
jcallahan@133 2107
jcallahan@89 2108 function WDP:UpdateMerchantItems(event_name)
jcallahan@144 2109 if not current_merchant or event_name == "MERCHANT_SHOW" then
jcallahan@195 2110 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
jcallahan@4 2111
jcallahan@171 2112 if not unit_idnum or not UnitTypeIsNPC(unit_type) then
jcallahan@133 2113 return
jcallahan@133 2114 end
jcallahan@331 2115 local _, faction_standing = UnitFactionStanding("npc")
jcallahan@331 2116 merchant_standing = faction_standing
jcallahan@133 2117 current_merchant = NPCEntry(unit_idnum)
jcallahan@133 2118 current_merchant.sells = current_merchant.sells or {}
jcallahan@44 2119 end
jcallahan@55 2120 local current_filters = _G.GetMerchantFilter()
jcallahan@57 2121 _G.SetMerchantFilter(_G.LE_LOOT_FILTER_ALL)
jcallahan@57 2122 _G.MerchantFrame_Update()
jcallahan@57 2123
jcallahan@150 2124 local num_items = _G.GetMerchantNumItems()
jcallahan@150 2125
jcallahan@44 2126 for item_index = 1, num_items do
jcallahan@44 2127 local _, _, copper_price, stack_size, num_available, _, extended_cost = _G.GetMerchantItemInfo(item_index)
jcallahan@44 2128 local item_id = ItemLinkToID(_G.GetMerchantItemLink(item_index))
jcallahan@5 2129
jcallahan@324 2130 DatamineTT:ClearLines()
jcallahan@324 2131 DatamineTT:SetMerchantItem(item_index)
jcallahan@324 2132
jcallahan@324 2133 if not item_id then
jcallahan@324 2134 local item_name, item_link = DatamineTT:GetItem()
jcallahan@324 2135 item_id = ItemLinkToID(item_link)
MMOSimca@328 2136 if item_id then
MMOSimca@328 2137 Debug("%s: GetMerchantItemLink() still ocassionally fails, apparently. Failed item's ID - %s", event_name, item_id)
MMOSimca@328 2138 else
MMOSimca@328 2139 Debug("%s: GetMerchantItemLink() still ocassionally fails, apparently. Failed item's ID - nil", event_name)
MMOSimca@328 2140 end
jcallahan@324 2141 end
jcallahan@324 2142
jcallahan@44 2143 if item_id and item_id > 0 then
jcallahan@44 2144 local price_string = ActualCopperCost(copper_price, merchant_standing)
jcallahan@5 2145
jcallahan@68 2146 local num_lines = DatamineTT:NumLines()
jcallahan@68 2147
jcallahan@68 2148 for line_index = 1, num_lines do
jcallahan@68 2149 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
jcallahan@68 2150
jcallahan@68 2151 if not current_line then
jcallahan@68 2152 break
jcallahan@68 2153 end
jcallahan@68 2154 local faction, reputation = current_line:GetText():match(ITEM_REQ_REPUTATION_MATCH)
jcallahan@68 2155
jcallahan@68 2156 if faction or reputation then
jcallahan@68 2157 DBEntry("items", item_id).req_reputation = ("%s:%s"):format(faction:gsub("-", ""), reputation:upper())
jcallahan@68 2158 break
jcallahan@68 2159 end
jcallahan@68 2160 end
jcallahan@68 2161
jcallahan@87 2162 for line_index = 1, num_lines do
jcallahan@87 2163 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
jcallahan@87 2164
jcallahan@87 2165 if not current_line then
jcallahan@87 2166 break
jcallahan@87 2167 end
jcallahan@87 2168 local line_text = current_line:GetText()
jcallahan@87 2169 local quest_name = line_text:match(ITEM_REQ_QUEST_MATCH1) or line_text:match(ITEM_REQ_QUEST_MATCH2)
jcallahan@87 2170
jcallahan@87 2171 if quest_name then
jcallahan@87 2172 DBEntry("items", item_id).req_quest = ("%s"):format(quest_name:gsub("(.+): ", ""), quest_name)
jcallahan@87 2173 break
jcallahan@87 2174 end
jcallahan@87 2175 end
jcallahan@87 2176
jcallahan@44 2177 if extended_cost then
jcallahan@53 2178 local battleground_rating = 0
jcallahan@53 2179 local personal_rating = 0
jcallahan@53 2180 local required_season_amount
jcallahan@5 2181
jcallahan@68 2182 for line_index = 1, num_lines do
jcallahan@44 2183 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
jcallahan@5 2184
jcallahan@44 2185 if not current_line then
jcallahan@44 2186 break
jcallahan@44 2187 end
jcallahan@53 2188 required_season_amount = current_line:GetText():match("Requires earning a total of (%d+)\n(.-) for the season.")
jcallahan@5 2189
jcallahan@44 2190 for match_index = 1, #POINT_MATCH_PATTERNS do
jcallahan@44 2191 local match1, match2 = current_line:GetText():match(POINT_MATCH_PATTERNS[match_index])
jcallahan@53 2192 personal_rating = personal_rating + (match1 or 0)
jcallahan@53 2193 battleground_rating = battleground_rating + (match2 or 0)
jcallahan@5 2194
jcallahan@44 2195 if match1 or match2 then
jcallahan@44 2196 break
jcallahan@44 2197 end
jcallahan@44 2198 end
jcallahan@5 2199 end
jcallahan@44 2200 local currency_list = {}
jcallahan@44 2201 local item_count = _G.GetMerchantItemCostInfo(item_index)
jcallahan@50 2202
jcallahan@50 2203 -- Keeping this around in case Blizzard makes the two points diverge at some point.
jcallahan@53 2204 -- price_string = ("%s:%s:%s:%s"):format(price_string, battleground_rating, personal_rating, required_season_amount or 0)
jcallahan@53 2205 price_string = ("%s:%s:%s"):format(price_string, personal_rating, required_season_amount or 0)
jcallahan@5 2206
jcallahan@44 2207 for cost_index = 1, item_count do
jcallahan@324 2208 -- The third return (Blizz calls "currency_link") of GetMerchantItemCostItem only returns item links as of Patch 5.3.0.
jcallahan@317 2209 local icon_texture, amount_required, item_link = _G.GetMerchantItemCostItem(item_index, cost_index)
jcallahan@317 2210 local currency_identifier = item_link and ItemLinkToID(item_link) or nil
jcallahan@317 2211
jcallahan@317 2212 if (not currency_identifier or currency_identifier < 1) and icon_texture then
jcallahan@317 2213 currency_identifier = icon_texture:match("[^\\]+$"):lower()
jcallahan@317 2214 end
jcallahan@317 2215
jcallahan@317 2216 if currency_identifier then
jcallahan@317 2217 currency_list[#currency_list + 1] = ("(%s:%s)"):format(amount_required, currency_identifier)
jcallahan@44 2218 end
jcallahan@44 2219 end
jcallahan@44 2220
jcallahan@44 2221 for currency_index = 1, #currency_list do
jcallahan@44 2222 price_string = ("%s:%s"):format(price_string, currency_list[currency_index])
jcallahan@5 2223 end
jcallahan@5 2224 end
jcallahan@133 2225 current_merchant.sells[item_id] = ("%s:%s:[%s]"):format(num_available, stack_size, price_string)
jcallahan@44 2226 end
jcallahan@44 2227 end
jcallahan@5 2228
jcallahan@44 2229 if _G.CanMerchantRepair() then
jcallahan@133 2230 current_merchant.can_repair = true
jcallahan@5 2231 end
jcallahan@57 2232 _G.SetMerchantFilter(current_filters)
jcallahan@57 2233 _G.MerchantFrame_Update()
jcallahan@4 2234 end
jcallahan@44 2235 end -- do-block
jcallahan@4 2236
jcallahan@89 2237
jcallahan@92 2238 function WDP:PET_BAR_UPDATE(event_name)
MMOSimca@336 2239 if not private.NON_LOOT_SPELL_LABELS[current_action.spell_label] then
jcallahan@25 2240 return
jcallahan@25 2241 end
jcallahan@34 2242 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("pet"))
jcallahan@25 2243
jcallahan@171 2244 if not unit_idnum or not UnitTypeIsNPC(unit_type) then
jcallahan@25 2245 return
jcallahan@25 2246 end
jcallahan@29 2247 NPCEntry(unit_idnum).mind_control = true
jcallahan@122 2248 table.wipe(current_action)
jcallahan@25 2249 end
jcallahan@25 2250
jcallahan@25 2251
jcallahan@115 2252 function WDP:PET_JOURNAL_LIST_UPDATE(event_name)
jcallahan@324 2253 -- This function produces data currently unused by wowdb.com and it makes debugging errors in the .lua output nearly impossible due to the massive bloat.
MMOSimca@346 2254 if DEBUGGING then
jcallahan@309 2255 return
jcallahan@309 2256 end
jcallahan@309 2257
jcallahan@115 2258 local num_pets = LPJ:NumPets()
jcallahan@115 2259
jcallahan@115 2260 for index, pet_id in LPJ:IteratePetIDs() do
jcallahan@115 2261 local _, _, is_owned, _, level, _, _, name, icon, pet_type, npc_id, _, _, is_wild = _G.C_PetJournal.GetPetInfoByIndex(index)
jcallahan@115 2262
jcallahan@115 2263 if is_owned then
jcallahan@115 2264 local health, max_health, attack, speed, rarity = _G.C_PetJournal.GetPetStats(pet_id)
jcallahan@115 2265
jcallahan@139 2266 if rarity then
jcallahan@139 2267 local rarity_name = _G["BATTLE_PET_BREED_QUALITY" .. rarity]
jcallahan@139 2268 local npc = NPCEntry(npc_id)
jcallahan@139 2269 npc.wild_pet = is_wild or nil
jcallahan@139 2270 npc.battle_pet_data = npc.battle_pet_data or {}
jcallahan@139 2271 npc.battle_pet_data[rarity_name] = npc.battle_pet_data[rarity_name] or {}
jcallahan@139 2272 npc.battle_pet_data[rarity_name]["level_" .. level] = npc.battle_pet_data[rarity_name]["level_" .. level] or {}
jcallahan@139 2273
jcallahan@139 2274 local data = npc.battle_pet_data[rarity_name]["level_" .. level]
jcallahan@139 2275 data.max_health = max_health
jcallahan@139 2276 data.attack = attack
jcallahan@139 2277 data.speed = speed
jcallahan@139 2278 end
jcallahan@115 2279 end
jcallahan@115 2280 end
jcallahan@115 2281 end
jcallahan@115 2282
jcallahan@115 2283
jcallahan@156 2284 function WDP:PLAYER_REGEN_DISABLED(event_name)
jcallahan@156 2285 private.in_combat = true
jcallahan@156 2286 end
jcallahan@156 2287
jcallahan@156 2288
jcallahan@156 2289 function WDP:PLAYER_REGEN_ENABLED(event_name)
jcallahan@156 2290 private.in_combat = nil
jcallahan@156 2291
jcallahan@156 2292 if private.set_area_id then
jcallahan@299 2293 self:HandleZoneChange(event_name)
jcallahan@156 2294 private.set_area_id = nil
jcallahan@156 2295 end
jcallahan@156 2296 end
jcallahan@156 2297
jcallahan@156 2298
jcallahan@118 2299 function WDP:PLAYER_TARGET_CHANGED(event_name)
jcallahan@215 2300 if not TargetedNPC() then
jcallahan@118 2301 return
jcallahan@2 2302 end
jcallahan@151 2303 current_action.target_type = AF.NPC
jcallahan@118 2304 self:UpdateTargetLocation()
jcallahan@118 2305 end
jcallahan@2 2306
jcallahan@89 2307
jcallahan@12 2308 do
jcallahan@12 2309 local function UpdateQuestJuncture(point)
jcallahan@12 2310 local unit_name = _G.UnitName("questnpc")
jcallahan@9 2311
jcallahan@12 2312 if not unit_name then
jcallahan@12 2313 return
jcallahan@12 2314 end
jcallahan@34 2315 local unit_type, unit_id = ParseGUID(_G.UnitGUID("questnpc"))
jcallahan@9 2316
jcallahan@12 2317 if unit_type == private.UNIT_TYPES.OBJECT then
jcallahan@38 2318 UpdateDBEntryLocation("objects", unit_id)
jcallahan@12 2319 end
jcallahan@19 2320 local quest = DBEntry("quests", _G.GetQuestID())
jcallahan@12 2321 quest[point] = quest[point] or {}
MMOSimca@329 2322 quest[point][("%s:%d"):format(private.UNIT_TYPE_NAMES[unit_type], unit_id)] = true
jcallahan@24 2323
jcallahan@24 2324 return quest
jcallahan@12 2325 end
jcallahan@10 2326
jcallahan@12 2327
jcallahan@92 2328 function WDP:QUEST_COMPLETE(event_name)
jcallahan@97 2329 local quest = UpdateQuestJuncture("end")
jcallahan@97 2330
jcallahan@112 2331 if ALLOWED_LOCALES[CLIENT_LOCALE] then
jcallahan@112 2332 quest.reward_text = ReplaceKeywords(_G.GetRewardText())
jcallahan@112 2333 end
jcallahan@67 2334 -- Make sure the quest NPC isn't erroneously recorded as giving reputation for quests which award it.
jcallahan@177 2335 ClearKilledNPC()
jcallahan@10 2336 end
jcallahan@10 2337
jcallahan@12 2338
jcallahan@92 2339 function WDP:QUEST_DETAIL(event_name)
jcallahan@24 2340 local quest = UpdateQuestJuncture("begin")
jcallahan@24 2341
jcallahan@46 2342 if not quest then
jcallahan@46 2343 return
jcallahan@46 2344 end
jcallahan@24 2345 quest.classes = quest.classes or {}
jcallahan@27 2346 quest.classes[PLAYER_CLASS] = true
jcallahan@24 2347
jcallahan@24 2348 quest.races = quest.races or {}
jcallahan@100 2349 quest.races[(PLAYER_RACE == "Pandaren") and ("%s_%s"):format(PLAYER_RACE, PLAYER_FACTION or "Neutral") or PLAYER_RACE] = true
jcallahan@10 2350 end
jcallahan@12 2351 end -- do-block
jcallahan@9 2352
jcallahan@9 2353
jcallahan@92 2354 function WDP:QUEST_LOG_UPDATE(event_name)
jcallahan@38 2355 local selected_quest = _G.GetQuestLogSelection() -- Save current selection to be restored when we're done.
jcallahan@36 2356 local entry_index, processed_quests = 1, 0
jcallahan@36 2357 local _, num_quests = _G.GetNumQuestLogEntries()
jcallahan@36 2358
jcallahan@36 2359 while processed_quests <= num_quests do
MMOSimca@329 2360 local _, _, _, is_header, _, _, _, quest_id = _G.GetQuestLogTitle(entry_index)
jcallahan@36 2361
jcallahan@84 2362 if quest_id == 0 then
jcallahan@84 2363 processed_quests = processed_quests + 1
jcallahan@84 2364 elseif not is_header then
jcallahan@36 2365 _G.SelectQuestLogEntry(entry_index);
jcallahan@36 2366
jcallahan@36 2367 local quest = DBEntry("quests", quest_id)
jcallahan@36 2368 quest.timer = _G.GetQuestLogTimeLeft()
jcallahan@37 2369 quest.can_share = _G.GetQuestLogPushable() and true or nil
jcallahan@36 2370 processed_quests = processed_quests + 1
jcallahan@36 2371 end
jcallahan@36 2372 entry_index = entry_index + 1
jcallahan@36 2373 end
jcallahan@36 2374 _G.SelectQuestLogEntry(selected_quest)
jcallahan@4 2375 self:UnregisterEvent("QUEST_LOG_UPDATE")
jcallahan@4 2376 end
jcallahan@4 2377
jcallahan@4 2378
jcallahan@97 2379 function WDP:QUEST_PROGRESS(event_name)
jcallahan@112 2380 if not ALLOWED_LOCALES[CLIENT_LOCALE] then
jcallahan@112 2381 return
jcallahan@112 2382 end
jcallahan@97 2383 DBEntry("quests", _G.GetQuestID()).progress_text = ReplaceKeywords(_G.GetProgressText())
jcallahan@97 2384 end
jcallahan@97 2385
jcallahan@97 2386
jcallahan@92 2387 function WDP:UNIT_QUEST_LOG_CHANGED(event_name, unit_id)
jcallahan@4 2388 if unit_id ~= "player" then
jcallahan@4 2389 return
jcallahan@4 2390 end
jcallahan@4 2391 self:RegisterEvent("QUEST_LOG_UPDATE")
jcallahan@4 2392 end
jcallahan@4 2393
jcallahan@4 2394
jcallahan@92 2395 do
jcallahan@92 2396 local TRADESKILL_TOOLS = {
jcallahan@92 2397 Anvil = anvil_spell_ids,
jcallahan@92 2398 Forge = forge_spell_ids,
jcallahan@92 2399 }
jcallahan@92 2400
jcallahan@92 2401
jcallahan@167 2402 local function RegisterTools(tradeskill_name, tradeskill_index)
jcallahan@167 2403 local spell_id = tonumber(_G.GetTradeSkillRecipeLink(tradeskill_index):match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)"))
jcallahan@167 2404 local required_tool = _G.GetTradeSkillTools(tradeskill_index)
jcallahan@167 2405
jcallahan@167 2406 if required_tool then
jcallahan@167 2407 for tool_name, registry in pairs(TRADESKILL_TOOLS) do
jcallahan@167 2408 if required_tool:find(tool_name) then
jcallahan@167 2409 registry[spell_id] = true
jcallahan@167 2410 end
jcallahan@167 2411 end
jcallahan@167 2412 end
jcallahan@167 2413 end
jcallahan@167 2414
jcallahan@167 2415
jcallahan@92 2416 function WDP:TRADE_SKILL_SHOW(event_name)
jcallahan@92 2417 local profession_name, prof_level = _G.GetTradeSkillLine()
jcallahan@92 2418
jcallahan@92 2419 if profession_name == _G.UNKNOWN then
jcallahan@92 2420 return
jcallahan@92 2421 end
jcallahan@167 2422 TradeSkillExecutePer(RegisterTools)
jcallahan@92 2423 end
jcallahan@92 2424 end -- do-block
jcallahan@92 2425
jcallahan@92 2426
jcallahan@167 2427 function WDP:TRAINER_CLOSED(event_name)
jcallahan@167 2428 private.trainer_shown = nil
jcallahan@167 2429 end
jcallahan@167 2430
jcallahan@167 2431
jcallahan@92 2432 function WDP:TRAINER_SHOW(event_name)
jcallahan@232 2433 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
jcallahan@164 2434 local trainer = NPCEntry(unit_idnum)
jcallahan@58 2435
jcallahan@164 2436 if not trainer then
jcallahan@58 2437 return
jcallahan@58 2438 end
jcallahan@331 2439 local _, trainer_standing = UnitFactionStanding("npc")
jcallahan@164 2440 trainer.teaches = trainer.teaches or {}
jcallahan@27 2441
jcallahan@167 2442 private.trainer_shown = true
jcallahan@167 2443
jcallahan@27 2444 -- Get the initial trainer filters
MMOSimca@344 2445 local available = _G.GetTrainerServiceTypeFilter("available") and 1 or 0
MMOSimca@344 2446 local unavailable = _G.GetTrainerServiceTypeFilter("unavailable") and 1 or 0
MMOSimca@344 2447 local used = _G.GetTrainerServiceTypeFilter("used") and 1 or 0
jcallahan@27 2448
jcallahan@27 2449 -- Clear the trainer filters
MMOSimca@344 2450 _G.SetTrainerServiceTypeFilter("available", 1)
MMOSimca@344 2451 _G.SetTrainerServiceTypeFilter("unavailable", 1)
MMOSimca@344 2452 _G.SetTrainerServiceTypeFilter("used", 1)
jcallahan@27 2453
jcallahan@27 2454 for index = 1, _G.GetNumTrainerServices(), 1 do
jcallahan@27 2455 local spell_name, rank_name, _, _, required_level = _G.GetTrainerServiceInfo(index)
jcallahan@27 2456
jcallahan@27 2457 if spell_name then
jcallahan@27 2458 DatamineTT:ClearLines()
jcallahan@27 2459 DatamineTT:SetTrainerService(index)
jcallahan@27 2460
jcallahan@27 2461 local _, _, spell_id = DatamineTT:GetSpell()
jcallahan@27 2462
jcallahan@43 2463 if spell_id then
jcallahan@164 2464 local class_professions = trainer.teaches[PLAYER_CLASS]
jcallahan@164 2465
jcallahan@164 2466 if not class_professions then
jcallahan@164 2467 trainer.teaches[PLAYER_CLASS] = {}
jcallahan@164 2468 class_professions = trainer.teaches[PLAYER_CLASS]
jcallahan@164 2469 end
jcallahan@43 2470 local profession, min_skill = _G.GetTrainerServiceSkillReq(index)
jcallahan@43 2471 profession = profession or "General"
jcallahan@43 2472
jcallahan@164 2473 local profession_skills = class_professions[profession]
jcallahan@43 2474
jcallahan@43 2475 if not profession_skills then
jcallahan@43 2476 class_professions[profession] = {}
jcallahan@43 2477 profession_skills = class_professions[profession]
jcallahan@43 2478 end
jcallahan@173 2479 profession_skills[spell_id] = ("%d:%d:%d"):format(required_level, min_skill, _G.GetTrainerServiceCost(index))
jcallahan@27 2480 end
jcallahan@27 2481 end
jcallahan@27 2482 end
jcallahan@27 2483 -- Reset the filters to what they were before
MMOSimca@344 2484 _G.SetTrainerServiceTypeFilter("available", available or 0)
MMOSimca@344 2485 _G.SetTrainerServiceTypeFilter("unavailable", unavailable or 0)
MMOSimca@344 2486 _G.SetTrainerServiceTypeFilter("used", used or 0)
jcallahan@27 2487 end
jcallahan@27 2488
jcallahan@27 2489
jcallahan@1 2490 function WDP:UNIT_SPELLCAST_SENT(event_name, unit_id, spell_name, spell_rank, target_name, spell_line)
jcallahan@1 2491 if private.tracked_line or unit_id ~= "player" then
jcallahan@1 2492 return
jcallahan@1 2493 end
jcallahan@1 2494 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name]
jcallahan@1 2495
jcallahan@1 2496 if not spell_label then
jcallahan@1 2497 return
jcallahan@1 2498 end
jcallahan@306 2499
MMOSimca@343 2500 Debug("UNIT_SPELLCAST_SENT: %s was cast.", spell_name)
jcallahan@150 2501 local item_name, item_link = _G.GameTooltip:GetItem()
jcallahan@150 2502 local unit_name, unit_id = _G.GameTooltip:GetUnit()
jcallahan@1 2503
jcallahan@150 2504 if not unit_name and _G.UnitName("target") == target_name then
jcallahan@150 2505 unit_name = target_name
jcallahan@150 2506 unit_id = "target"
jcallahan@1 2507 end
jcallahan@1 2508 local spell_flags = private.SPELL_FLAGS_BY_LABEL[spell_label]
jcallahan@28 2509 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData()
MMOSimca@328 2510 if not (zone_name and area_id and x and y and map_level) then
MMOSimca@328 2511 Debug("%s: Missing current location data - %s, %d, %d, %d, %d.", event_name, zone_name, area_id, x, y, map_level)
MMOSimca@328 2512 return
MMOSimca@328 2513 end
jcallahan@28 2514
jcallahan@205 2515 table.wipe(current_action)
jcallahan@122 2516 current_action.instance_token = instance_token
jcallahan@122 2517 current_action.map_level = map_level
jcallahan@122 2518 current_action.x = x
jcallahan@122 2519 current_action.y = y
jcallahan@122 2520 current_action.zone_data = ("%s:%d"):format(zone_name, area_id)
jcallahan@122 2521 current_action.spell_label = spell_label
jcallahan@105 2522
jcallahan@105 2523 if not private.NON_LOOT_SPELL_LABELS[spell_label] then
jcallahan@122 2524 current_action.loot_label = spell_label:lower()
jcallahan@105 2525 end
jcallahan@1 2526
jcallahan@151 2527 if unit_name and unit_name == target_name and not item_name then
jcallahan@16 2528 if bit.band(spell_flags, AF.NPC) == AF.NPC then
jcallahan@150 2529 if not unit_id or unit_name ~= target_name then
jcallahan@16 2530 return
jcallahan@16 2531 end
jcallahan@123 2532 current_action.target_type = AF.NPC
jcallahan@16 2533 end
jcallahan@16 2534 elseif bit.band(spell_flags, AF.ITEM) == AF.ITEM then
jcallahan@123 2535 current_action.target_type = AF.ITEM
jcallahan@16 2536
jcallahan@150 2537 if item_name and item_name == target_name then
jcallahan@150 2538 current_action.identifier = ItemLinkToID(item_link)
jcallahan@16 2539 elseif target_name and target_name ~= "" then
jcallahan@331 2540 local _, item_link = _G.GetItemInfo(target_name)
jcallahan@331 2541 current_action.identifier = ItemLinkToID(item_link)
jcallahan@16 2542 end
jcallahan@150 2543 elseif not item_name and not unit_name then
jcallahan@1 2544 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then
jcallahan@17 2545 if target_name == "" then
jcallahan@17 2546 return
jcallahan@17 2547 end
jcallahan@122 2548 current_action.object_name = target_name
jcallahan@123 2549 current_action.target_type = AF.OBJECT
jcallahan@1 2550 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then
jcallahan@123 2551 current_action.target_type = AF.ZONE
jcallahan@1 2552 end
jcallahan@1 2553 end
jcallahan@1 2554 private.tracked_line = spell_line
jcallahan@0 2555 end
jcallahan@0 2556
jcallahan@94 2557
jcallahan@312 2558 function WDP:SPELL_CONFIRMATION_PROMPT(event_name, spell_id, confirm_type, text, duration, currency_id_cost)
jcallahan@306 2559 if private.RAID_BOSS_BONUS_SPELL_ID_TO_NPC_ID_MAP[spell_id] then
jcallahan@306 2560 ClearKilledBossID()
jcallahan@306 2561 ClearLootToastContainerID()
MMOSimca@336 2562 private.raid_boss_id = private.RAID_BOSS_BONUS_SPELL_ID_TO_NPC_ID_MAP[spell_id]
jcallahan@306 2563 else
MMOSimca@336 2564 Debug("%s: Spell ID %d is not a known raid boss 'Bonus' spell.", event_name, spell_id)
jcallahan@306 2565 return
jcallahan@1 2566 end
jcallahan@306 2567
jcallahan@324 2568 -- Assign existing loot data to boss if it exists
jcallahan@307 2569 if loot_toast_data then
MMOSimca@336 2570 local npc_id = private.raid_boss_id
jcallahan@317 2571
jcallahan@324 2572 -- Slightly messy hack to workaround duplicate world bosses
jcallahan@317 2573 local upper_limit = 0
jcallahan@317 2574 if DUPLICATE_WORLD_BOSS_IDS[npc_id] then
jcallahan@317 2575 upper_limit = #DUPLICATE_WORLD_BOSS_IDS[npc_id]
jcallahan@317 2576 end
jcallahan@317 2577
jcallahan@317 2578 for i = 0, upper_limit do
jcallahan@317 2579 local temp_npc_id = npc_id
jcallahan@317 2580
jcallahan@317 2581 if i > 0 then
jcallahan@317 2582 temp_npc_id = DUPLICATE_WORLD_BOSS_IDS[npc_id][i]
jcallahan@317 2583 end
jcallahan@317 2584
jcallahan@317 2585 local npc = NPCEntry(temp_npc_id)
jcallahan@317 2586 if npc then
jcallahan@324 2587 -- Create needed npc fields if required
jcallahan@317 2588 local loot_label = "drops"
jcallahan@317 2589 local encounter_data = npc:EncounterData(InstanceDifficultyToken())
jcallahan@317 2590 encounter_data[loot_label] = encounter_data[loot_label] or {}
jcallahan@317 2591 encounter_data.loot_counts = encounter_data.loot_counts or {}
jcallahan@317 2592
jcallahan@317 2593 for index = 1, #loot_toast_data do
jcallahan@317 2594 local data = loot_toast_data[index]
jcallahan@317 2595 local loot_type = data[1]
jcallahan@317 2596 local hyperlink = data[2]
jcallahan@317 2597 local quantity = data[3]
jcallahan@317 2598
jcallahan@317 2599 if loot_type == "item" then
jcallahan@317 2600 local item_id = ItemLinkToID(hyperlink)
jcallahan@317 2601 Debug("%s: Assigned stored item loot data - %s - %d:%d", event_name, hyperlink, item_id, quantity)
jcallahan@317 2602 table.insert(encounter_data[loot_label], ("%d:%d"):format(item_id, quantity))
jcallahan@317 2603 elseif loot_type == "money" then
jcallahan@317 2604 Debug("%s: Assigned stored money loot data - money:%d", event_name, quantity)
jcallahan@317 2605 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity))
jcallahan@317 2606 elseif loot_type == "currency" then
jcallahan@317 2607 local currency_texture = CurrencyLinkToTexture(hyperlink)
jcallahan@317 2608 Debug("%s: Assigned stored currency loot data - %s - currency:%d:%s", event_name, hyperlink, currency_texture, quantity)
jcallahan@324 2609 -- Workaround for Patch 5.4.0 bug with Flexible raid Siege of Orgrimmar bosses and Valor Points
jcallahan@317 2610 if quantity > 1000 and currency_texture == "pvecurrency-valor" then
jcallahan@317 2611 quantity = math.floor(quantity / 100)
jcallahan@317 2612 end
jcallahan@317 2613 table.insert(encounter_data[loot_label], ("currency:%d:%s"):format(quantity, currency_texture))
jcallahan@317 2614 end
jcallahan@307 2615 end
jcallahan@317 2616
jcallahan@317 2617 if not boss_loot_toasting[temp_npc_id] then
jcallahan@317 2618 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1
jcallahan@317 2619 boss_loot_toasting[temp_npc_id] = true -- Do not count further loots until timer expires or another boss is killed
jcallahan@317 2620 end
jcallahan@317 2621 else
jcallahan@317 2622 Debug("%s: NPC is nil, but we have stored loot data...", event_name)
jcallahan@307 2623 end
jcallahan@307 2624 end
jcallahan@307 2625 end
jcallahan@307 2626
jcallahan@307 2627 ClearLootToastData()
jcallahan@307 2628
jcallahan@307 2629 killed_boss_id_timer_handle = WDP:ScheduleTimer(ClearKilledBossID, 5) -- we need to assign a handle here to cancel it later
jcallahan@306 2630 end
jcallahan@306 2631
jcallahan@306 2632
jcallahan@306 2633 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
jcallahan@306 2634 if unit_id ~= "player" then
jcallahan@306 2635 return
jcallahan@306 2636 end
jcallahan@306 2637 private.tracked_line = nil
jcallahan@306 2638 private.previous_spell_id = spell_id
jcallahan@306 2639
MMOSimca@345 2640 -- Handle Logging spell casts
MMOSimca@345 2641 if private.LOGGING_SPELL_ID_TO_OBJECT_ID_MAP[spell_id] then
MMOSimca@345 2642 last_timber_spell_id = spell_id
MMOSimca@345 2643 for timber_variant = 1, #private.LOGGING_SPELL_ID_TO_OBJECT_ID_MAP[spell_id] do
MMOSimca@345 2644 UpdateDBEntryLocation("objects", ("OPENING:%s"):format(private.LOGGING_SPELL_ID_TO_OBJECT_ID_MAP[spell_id][timber_variant]))
MMOSimca@345 2645 end
MMOSimca@345 2646 return
MMOSimca@345 2647 end
MMOSimca@345 2648
MMOSimca@345 2649 -- Handle Loot Toast spell casts
jcallahan@306 2650 if private.LOOT_SPELL_ID_TO_ITEM_ID_MAP[spell_id] then
jcallahan@306 2651 ClearKilledBossID()
jcallahan@306 2652 ClearLootToastContainerID()
jcallahan@307 2653 ClearLootToastData()
jcallahan@306 2654
jcallahan@306 2655 private.loot_toast_container_id = private.LOOT_SPELL_ID_TO_ITEM_ID_MAP[spell_id]
jcallahan@306 2656 loot_toast_container_timer_handle = WDP:ScheduleTimer(ClearLootToastContainerID, 1) -- we need to assign a handle here to cancel it later
MMOSimca@345 2657 return
jcallahan@306 2658 end
jcallahan@306 2659
MMOSimca@347 2660 -- For Crates of Salvage (and potentially other items based on spell casts in the future which need manual handling)
MMOSimca@347 2661 if private.SALVAGE_SPELL_ID_TO_ITEM_ID_MAP[spell_id] then
MMOSimca@347 2662 -- Set up timer
MMOSimca@349 2663 Debug("%s: Beginning Salvage loot timer for spellID %d", event_name, spell_id)
MMOSimca@349 2664 chat_loot_timer_handle = WDP:ScheduleTimer(ClearTimeBasedLootData, 1)
MMOSimca@347 2665
MMOSimca@347 2666 -- Standard item handling setup
MMOSimca@347 2667 table.wipe(current_action)
MMOSimca@347 2668 current_loot = nil
MMOSimca@347 2669 current_action.target_type = AF.ITEM
MMOSimca@349 2670 current_action.identifier = private.SALVAGE_SPELL_ID_TO_ITEM_ID_MAP[spell_id]
MMOSimca@347 2671 current_action.loot_label = "contains"
MMOSimca@349 2672 InitializeCurrentLoot()
MMOSimca@347 2673 return
MMOSimca@347 2674 end
MMOSimca@347 2675
jcallahan@306 2676 if anvil_spell_ids[spell_id] then
jcallahan@306 2677 UpdateDBEntryLocation("objects", OBJECT_ID_ANVIL)
jcallahan@306 2678 elseif forge_spell_ids[spell_id] then
jcallahan@306 2679 UpdateDBEntryLocation("objects", OBJECT_ID_FORGE)
jcallahan@306 2680 elseif spell_name:match("^Harvest.+") then
jcallahan@306 2681 killed_npc_id = current_target_id
MMOSimca@343 2682 private.harvesting = true -- Used to track which NPCs can be harvested (can we get this from CreatureCache instead?)
jcallahan@306 2683 end
jcallahan@306 2684 end
jcallahan@0 2685
jcallahan@90 2686
jcallahan@1 2687 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
jcallahan@1 2688 if unit_id ~= "player" then
jcallahan@1 2689 return
jcallahan@1 2690 end
jcallahan@0 2691
jcallahan@1 2692 if private.tracked_line == spell_line then
jcallahan@1 2693 private.tracked_line = nil
jcallahan@1 2694 end
jcallahan@147 2695 table.wipe(current_action)
jcallahan@0 2696 end
jcallahan@90 2697
jcallahan@90 2698
jcallahan@90 2699 do
jcallahan@90 2700 local function SetUnitField(field, required_type)
jcallahan@90 2701 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
jcallahan@90 2702
jcallahan@90 2703 if not unit_idnum or (required_type and unit_type ~= required_type) then
jcallahan@90 2704 return
jcallahan@90 2705 end
jcallahan@90 2706
jcallahan@171 2707 if UnitTypeIsNPC(unit_type) then
jcallahan@90 2708 NPCEntry(unit_idnum)[field] = true
jcallahan@90 2709 elseif unit_type == private.UNIT_TYPES.OBJECT then
jcallahan@90 2710 DBEntry("objects", unit_idnum)[field] = true
jcallahan@93 2711 UpdateDBEntryLocation("objects", unit_idnum)
jcallahan@90 2712 end
jcallahan@90 2713 end
jcallahan@90 2714
jcallahan@90 2715
jcallahan@90 2716 function WDP:AUCTION_HOUSE_SHOW(event_name)
jcallahan@90 2717 SetUnitField("auctioneer", private.UNIT_TYPES.NPC)
jcallahan@90 2718 end
jcallahan@90 2719
jcallahan@90 2720
jcallahan@90 2721 function WDP:BANKFRAME_OPENED(event_name)
jcallahan@90 2722 SetUnitField("banker", private.UNIT_TYPES.NPC)
jcallahan@90 2723 end
jcallahan@90 2724
jcallahan@90 2725
jcallahan@90 2726 function WDP:BATTLEFIELDS_SHOW(event_name)
jcallahan@90 2727 SetUnitField("battlemaster", private.UNIT_TYPES.NPC)
jcallahan@90 2728 end
jcallahan@90 2729
jcallahan@90 2730
jcallahan@92 2731 function WDP:FORGE_MASTER_OPENED(event_name)
jcallahan@90 2732 SetUnitField("arcane_reforger", private.UNIT_TYPES.NPC)
jcallahan@90 2733 end
jcallahan@90 2734
jcallahan@90 2735
jcallahan@323 2736 local GOSSIP_SHOW_FUNCS = {
jcallahan@323 2737 [private.UNIT_TYPES.NPC] = function(unit_idnum)
jcallahan@323 2738 local gossip_options = { _G.GetGossipOptions() }
jcallahan@323 2739
jcallahan@323 2740 for index = 2, #gossip_options, 2 do
jcallahan@323 2741 if gossip_options[index] == "binder" then
jcallahan@323 2742 SetUnitField("innkeeper", private.UNIT_TYPES.NPC)
jcallahan@323 2743 return
jcallahan@323 2744 end
jcallahan@323 2745 end
jcallahan@323 2746 end,
jcallahan@323 2747 [private.UNIT_TYPES.OBJECT] = function(unit_idnum)
jcallahan@323 2748 UpdateDBEntryLocation("objects", unit_idnum)
jcallahan@323 2749 end,
jcallahan@323 2750 }
jcallahan@323 2751
jcallahan@323 2752
jcallahan@92 2753 function WDP:GOSSIP_SHOW(event_name)
jcallahan@323 2754 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
jcallahan@323 2755 if not unit_idnum then
jcallahan@323 2756 return
jcallahan@323 2757 end
jcallahan@323 2758
jcallahan@323 2759 if GOSSIP_SHOW_FUNCS[unit_type] then
jcallahan@323 2760 GOSSIP_SHOW_FUNCS[unit_type](unit_idnum)
jcallahan@90 2761 end
jcallahan@90 2762 end
jcallahan@90 2763
jcallahan@90 2764
jcallahan@93 2765 function WDP:GUILDBANKFRAME_OPENED(event_name)
jcallahan@93 2766 SetUnitField("guild_bank", private.UNIT_TYPES.OBJECT)
jcallahan@93 2767 end
jcallahan@93 2768
jcallahan@93 2769
jcallahan@189 2770 function WDP:ITEM_UPGRADE_MASTER_OPENED(event_name)
jcallahan@189 2771 SetUnitField("item_upgrade_master", private.UNIT_TYPES.NPC)
jcallahan@189 2772 end
jcallahan@189 2773
jcallahan@189 2774
jcallahan@90 2775 function WDP:TAXIMAP_OPENED(event_name)
jcallahan@90 2776 SetUnitField("flight_master", private.UNIT_TYPES.NPC)
jcallahan@90 2777 end
jcallahan@90 2778
jcallahan@90 2779
jcallahan@90 2780 function WDP:TRANSMOGRIFY_OPEN(event_name)
jcallahan@90 2781 SetUnitField("transmogrifier", private.UNIT_TYPES.NPC)
jcallahan@90 2782 end
jcallahan@90 2783
jcallahan@90 2784
jcallahan@90 2785 function WDP:VOID_STORAGE_OPEN(event_name)
jcallahan@90 2786 SetUnitField("void_storage", private.UNIT_TYPES.NPC)
jcallahan@90 2787 end
jcallahan@90 2788 end -- do-block