annotate Main.lua @ 82:fc3e8a55d7ea 1.0.1

Ignore money completely (for now). Revert to using names for certain objects since Archaeology doesn't produce a GUID.
author James D. Callahan III <jcallahan@curse.com>
date Wed, 22 Aug 2012 15:15:30 -0500
parents 3db9f681d2e5
children 1f09f3590baa
rev   line source
jcallahan@0 1 -----------------------------------------------------------------------
jcallahan@0 2 -- Upvalued Lua API.
jcallahan@0 3 -----------------------------------------------------------------------
jcallahan@0 4 local _G = getfenv(0)
jcallahan@0 5
jcallahan@0 6 local pairs = _G.pairs
jcallahan@1 7 local tonumber = _G.tonumber
jcallahan@1 8
jcallahan@1 9 local bit = _G.bit
jcallahan@1 10 local math = _G.math
jcallahan@1 11 local table = _G.table
jcallahan@1 12
jcallahan@78 13 local select = _G.select
jcallahan@78 14
jcallahan@0 15
jcallahan@0 16 -----------------------------------------------------------------------
jcallahan@0 17 -- AddOn namespace.
jcallahan@0 18 -----------------------------------------------------------------------
jcallahan@0 19 local ADDON_NAME, private = ...
jcallahan@0 20
jcallahan@74 21 -- TODO: Remove this once 5.0.4 hits Live.
jcallahan@74 22 if private.wow_version == "4.3.4" then
jcallahan@74 23 return
jcallahan@74 24 end
jcallahan@74 25
jcallahan@0 26 local LibStub = _G.LibStub
jcallahan@0 27 local WDP = LibStub("AceAddon-3.0"):NewAddon(ADDON_NAME, "AceEvent-3.0", "AceTimer-3.0")
jcallahan@0 28
jcallahan@48 29 local deformat = LibStub("LibDeformat-3.0")
jcallahan@48 30
jcallahan@4 31 local DatamineTT = _G.CreateFrame("GameTooltip", "WDPDatamineTT", _G.UIParent, "GameTooltipTemplate")
jcallahan@5 32 DatamineTT:SetOwner(_G.WorldFrame, "ANCHOR_NONE")
jcallahan@5 33
jcallahan@0 34
jcallahan@0 35 -----------------------------------------------------------------------
jcallahan@0 36 -- Local constants.
jcallahan@0 37 -----------------------------------------------------------------------
jcallahan@74 38 local DB_VERSION = 4
jcallahan@63 39
jcallahan@0 40 local DATABASE_DEFAULTS = {
jcallahan@0 41 global = {
jcallahan@0 42 items = {},
jcallahan@0 43 npcs = {},
jcallahan@0 44 objects = {},
jcallahan@0 45 quests = {},
jcallahan@17 46 zones = {},
jcallahan@0 47 }
jcallahan@0 48 }
jcallahan@0 49
jcallahan@0 50
jcallahan@1 51 local EVENT_MAPPING = {
jcallahan@56 52 BLACK_MARKET_ITEM_UPDATE = true,
jcallahan@48 53 CHAT_MSG_LOOT = true,
jcallahan@40 54 CHAT_MSG_SYSTEM = true,
jcallahan@23 55 COMBAT_LOG_EVENT_UNFILTERED = true,
jcallahan@18 56 COMBAT_TEXT_UPDATE = true,
jcallahan@42 57 ITEM_TEXT_BEGIN = true,
jcallahan@1 58 LOOT_OPENED = true,
jcallahan@7 59 MERCHANT_SHOW = "UpdateMerchantItems",
jcallahan@61 60 MERCHANT_UPDATE = "UpdateMerchantItems",
jcallahan@25 61 PET_BAR_UPDATE = true,
jcallahan@2 62 PLAYER_TARGET_CHANGED = true,
jcallahan@9 63 QUEST_COMPLETE = true,
jcallahan@9 64 QUEST_DETAIL = true,
jcallahan@9 65 QUEST_LOG_UPDATE = true,
jcallahan@27 66 TRAINER_SHOW = true,
jcallahan@4 67 UNIT_QUEST_LOG_CHANGED = true,
jcallahan@1 68 UNIT_SPELLCAST_FAILED = "HandleSpellFailure",
jcallahan@1 69 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure",
jcallahan@1 70 UNIT_SPELLCAST_INTERRUPTED = "HandleSpellFailure",
jcallahan@1 71 UNIT_SPELLCAST_SENT = true,
jcallahan@1 72 UNIT_SPELLCAST_SUCCEEDED = true,
jcallahan@0 73 }
jcallahan@0 74
jcallahan@4 75
jcallahan@1 76 local AF = private.ACTION_TYPE_FLAGS
jcallahan@0 77
jcallahan@4 78
jcallahan@27 79 local PLAYER_CLASS = _G.select(2, _G.UnitClass("player"))
jcallahan@34 80 local PLAYER_GUID = _G.UnitGUID("player")
jcallahan@39 81 local PLAYER_RACE = _G.select(2, _G.UnitRace("player"))
jcallahan@27 82
jcallahan@0 83 -----------------------------------------------------------------------
jcallahan@0 84 -- Local variables.
jcallahan@0 85 -----------------------------------------------------------------------
jcallahan@0 86 local db
jcallahan@0 87 local durability_timer_handle
jcallahan@2 88 local target_location_timer_handle
jcallahan@1 89 local action_data = {}
jcallahan@40 90 local currently_drunk
jcallahan@32 91 local faction_standings = {}
jcallahan@67 92 local reputation_npc_id
jcallahan@0 93
jcallahan@1 94
jcallahan@1 95 -----------------------------------------------------------------------
jcallahan@1 96 -- Helper Functions.
jcallahan@1 97 -----------------------------------------------------------------------
jcallahan@39 98 local ActualCopperCost
jcallahan@39 99 do
jcallahan@39 100 local BARTERING_SPELL_ID = 83964
jcallahan@39 101
jcallahan@39 102 local STANDING_DISCOUNTS = {
jcallahan@39 103 HATED = 0,
jcallahan@39 104 HOSTILE = 0,
jcallahan@39 105 UNFRIENDLY = 0,
jcallahan@39 106 NEUTRAL = 0,
jcallahan@39 107 FRIENDLY = 0.05,
jcallahan@39 108 HONORED = 0.1,
jcallahan@39 109 REVERED = 0.15,
jcallahan@39 110 EXALTED = 0.2,
jcallahan@39 111 }
jcallahan@39 112
jcallahan@39 113
jcallahan@39 114 function ActualCopperCost(copper_cost, rep_standing)
jcallahan@39 115 if not copper_cost or copper_cost == 0 then
jcallahan@39 116 return 0
jcallahan@39 117 end
jcallahan@39 118 local modifier = 1
jcallahan@39 119
jcallahan@39 120 if _G.IsSpellKnown(BARTERING_SPELL_ID) then
jcallahan@39 121 modifier = modifier - 0.1
jcallahan@39 122 end
jcallahan@39 123
jcallahan@39 124 if rep_standing then
jcallahan@39 125 if PLAYER_RACE == "Goblin" then
jcallahan@39 126 modifier = modifier - STANDING_DISCOUNTS["EXALTED"]
jcallahan@39 127 elseif STANDING_DISCOUNTS[rep_standing] then
jcallahan@39 128 modifier = modifier - STANDING_DISCOUNTS[rep_standing]
jcallahan@39 129 end
jcallahan@39 130 end
jcallahan@39 131 return math.floor(copper_cost / modifier)
jcallahan@39 132 end
jcallahan@39 133 end -- do-block
jcallahan@39 134
jcallahan@39 135
jcallahan@29 136 local function InstanceDifficultyToken()
jcallahan@29 137 local _, instance_type, instance_difficulty, difficulty_name, _, _, is_dynamic = _G.GetInstanceInfo()
jcallahan@59 138 if not difficulty_name or difficulty_name == "" then
jcallahan@29 139 difficulty_name = "NONE"
jcallahan@29 140 end
jcallahan@59 141
jcallahan@59 142 if not instance_type or instance_type == "" then
jcallahan@59 143 instance_type = "NONE"
jcallahan@59 144 end
jcallahan@29 145 return ("%s:%s:%s"):format(instance_type:upper(), difficulty_name:upper():gsub(" ", "_"), _G.tostring(is_dynamic))
jcallahan@29 146 end
jcallahan@29 147
jcallahan@29 148
jcallahan@19 149 local function DBEntry(data_type, unit_id)
jcallahan@19 150 if not data_type or not unit_id then
jcallahan@6 151 return
jcallahan@6 152 end
jcallahan@19 153 local unit = db[data_type][unit_id]
jcallahan@6 154
jcallahan@10 155 if not unit then
jcallahan@19 156 db[data_type][unit_id] = {}
jcallahan@19 157 unit = db[data_type][unit_id]
jcallahan@6 158 end
jcallahan@10 159 return unit
jcallahan@6 160 end
jcallahan@6 161
jcallahan@6 162
jcallahan@29 163 local function NPCEntry(identifier)
jcallahan@29 164 local npc = DBEntry("npcs", identifier)
jcallahan@29 165
jcallahan@29 166 if not npc then
jcallahan@29 167 return
jcallahan@22 168 end
jcallahan@29 169 local instance_token = InstanceDifficultyToken()
jcallahan@29 170 npc.encounter_data = npc.encounter_data or {}
jcallahan@29 171 npc.encounter_data[instance_token] = npc.encounter_data[instance_token] or {}
jcallahan@30 172 npc.encounter_data[instance_token].stats = npc.encounter_data[instance_token].stats or {}
jcallahan@29 173 return npc
jcallahan@22 174 end
jcallahan@22 175
jcallahan@22 176
jcallahan@1 177 local function CurrentLocationData()
jcallahan@1 178 local map_level = _G.GetCurrentMapDungeonLevel() or 0
jcallahan@1 179 local x, y = _G.GetPlayerMapPosition("player")
jcallahan@1 180
jcallahan@1 181 x = x or 0
jcallahan@1 182 y = y or 0
jcallahan@1 183
jcallahan@1 184 if x == 0 and y == 0 then
jcallahan@1 185 for level_index = 1, _G.GetNumDungeonMapLevels() do
jcallahan@1 186 _G.SetDungeonMapLevel(level_index)
jcallahan@1 187 x, y = _G.GetPlayerMapPosition("player")
jcallahan@1 188
jcallahan@1 189 if x and y and (x > 0 or y > 0) then
jcallahan@1 190 _G.SetDungeonMapLevel(map_level)
jcallahan@1 191 map_level = level_index
jcallahan@1 192 break
jcallahan@1 193 end
jcallahan@1 194 end
jcallahan@1 195 end
jcallahan@1 196
jcallahan@1 197 if _G.DungeonUsesTerrainMap() then
jcallahan@1 198 map_level = map_level - 1
jcallahan@1 199 end
jcallahan@31 200 local x = _G.floor(x * 1000)
jcallahan@31 201 local y = _G.floor(y * 1000)
jcallahan@28 202
jcallahan@31 203 if x % 2 ~= 0 then
jcallahan@31 204 x = x + 1
jcallahan@28 205 end
jcallahan@28 206
jcallahan@31 207 if y % 2 ~= 0 then
jcallahan@31 208 y = y + 1
jcallahan@28 209 end
jcallahan@31 210 return _G.GetRealZoneText(), _G.GetCurrentMapAreaID(), x, y, map_level, InstanceDifficultyToken()
jcallahan@1 211 end
jcallahan@1 212
jcallahan@1 213
jcallahan@1 214 local function ItemLinkToID(item_link)
jcallahan@1 215 if not item_link then
jcallahan@1 216 return
jcallahan@1 217 end
jcallahan@7 218 return tonumber(item_link:match("item:(%d+)"))
jcallahan@1 219 end
jcallahan@0 220
jcallahan@4 221
jcallahan@34 222 local ParseGUID
jcallahan@4 223 do
jcallahan@4 224 local UNIT_TYPE_BITMASK = 0x007
jcallahan@4 225
jcallahan@34 226 function ParseGUID(guid)
jcallahan@5 227 if not guid then
jcallahan@5 228 return
jcallahan@5 229 end
jcallahan@4 230 local types = private.UNIT_TYPES
jcallahan@4 231 local unit_type = _G.bit.band(tonumber(guid:sub(1, 5)), UNIT_TYPE_BITMASK)
jcallahan@4 232
jcallahan@10 233 if unit_type ~= types.PLAYER and unit_type ~= types.PET then
jcallahan@66 234 return unit_type, tonumber(guid:sub(6, 10), 16)
jcallahan@4 235 end
jcallahan@4 236 return unit_type
jcallahan@4 237 end
jcallahan@4 238 end -- do-block
jcallahan@4 239
jcallahan@4 240
jcallahan@34 241 local UpdateNPCLocation
jcallahan@34 242 do
jcallahan@34 243 local COORD_MAX = 5
jcallahan@34 244
jcallahan@34 245 function UpdateNPCLocation(unit_idnum)
jcallahan@34 246 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData()
jcallahan@34 247 local npc_data = NPCEntry(unit_idnum).encounter_data[difficulty_token].stats[("level_%d"):format(_G.UnitLevel("target"))]
jcallahan@34 248 local zone_token = ("%s:%d"):format(zone_name, area_id)
jcallahan@34 249 npc_data.locations = npc_data.locations or {}
jcallahan@34 250
jcallahan@34 251 local zone_data = npc_data.locations[zone_token]
jcallahan@34 252
jcallahan@34 253 if not zone_data then
jcallahan@34 254 zone_data = {}
jcallahan@34 255 npc_data.locations[zone_token] = zone_data
jcallahan@34 256 end
jcallahan@34 257
jcallahan@34 258 for location_token in pairs(zone_data) do
jcallahan@34 259 local loc_level, loc_x, loc_y = (":"):split(location_token)
jcallahan@34 260 loc_level = tonumber(loc_level)
jcallahan@34 261
jcallahan@34 262 if map_level == loc_level and math.abs(x - loc_x) <= COORD_MAX and math.abs(y - loc_y) <= COORD_MAX then
jcallahan@34 263 return
jcallahan@34 264 end
jcallahan@34 265 end
jcallahan@34 266 zone_data[("%s:%s:%s"):format(map_level, x, y)] = true
jcallahan@34 267 end
jcallahan@34 268 end -- do-block
jcallahan@34 269
jcallahan@34 270
jcallahan@52 271 local function UpdateDBEntryLocation(entry_type, identifier)
jcallahan@10 272 if not identifier then
jcallahan@10 273 return
jcallahan@10 274 end
jcallahan@31 275 local zone_name, area_id, x, y, map_level, difficulty_token = CurrentLocationData()
jcallahan@41 276 local entry = DBEntry(entry_type, identifier)
jcallahan@41 277 entry[difficulty_token] = entry[difficulty_token] or {}
jcallahan@52 278 entry[difficulty_token].locations = entry[difficulty_token].locations or {}
jcallahan@10 279
jcallahan@31 280 local zone_token = ("%s:%d"):format(zone_name, area_id)
jcallahan@52 281 local zone_data = entry[difficulty_token].locations[zone_token]
jcallahan@24 282
jcallahan@31 283 if not zone_data then
jcallahan@31 284 zone_data = {}
jcallahan@52 285 entry[difficulty_token].locations[zone_token] = zone_data
jcallahan@10 286 end
jcallahan@41 287 local location_token = ("%s:%s:%s"):format(map_level, x, y)
jcallahan@41 288 zone_data[location_token] = zone_data[location_token] or true
jcallahan@41 289 return zone_data
jcallahan@10 290 end
jcallahan@10 291
jcallahan@10 292
jcallahan@19 293 local function HandleItemUse(item_link, bag_index, slot_index)
jcallahan@19 294 if not item_link then
jcallahan@19 295 return
jcallahan@19 296 end
jcallahan@19 297 local item_id = ItemLinkToID(item_link)
jcallahan@19 298
jcallahan@19 299 if not bag_index or not slot_index then
jcallahan@19 300 for new_bag_index = 0, _G.NUM_BAG_FRAMES do
jcallahan@19 301 for new_slot_index = 1, _G.GetContainerNumSlots(new_bag_index) do
jcallahan@19 302 if item_id == ItemLinkToID(_G.GetContainerItemLink(new_bag_index, new_slot_index)) then
jcallahan@19 303 bag_index = new_bag_index
jcallahan@19 304 slot_index = new_slot_index
jcallahan@19 305 break
jcallahan@19 306 end
jcallahan@19 307 end
jcallahan@19 308 end
jcallahan@19 309 end
jcallahan@19 310
jcallahan@19 311 if not bag_index or not slot_index then
jcallahan@19 312 return
jcallahan@19 313 end
jcallahan@19 314 local _, _, _, _, _, is_lootable = _G.GetContainerItemInfo(bag_index, slot_index)
jcallahan@19 315
jcallahan@19 316 if not is_lootable then
jcallahan@19 317 return
jcallahan@19 318 end
jcallahan@19 319 DatamineTT:ClearLines()
jcallahan@19 320 DatamineTT:SetBagItem(bag_index, slot_index)
jcallahan@19 321
jcallahan@19 322 for line_index = 1, DatamineTT:NumLines() do
jcallahan@19 323 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
jcallahan@19 324
jcallahan@19 325 if not current_line then
jcallahan@19 326 break
jcallahan@19 327 end
jcallahan@19 328
jcallahan@19 329 if current_line:GetText() == _G.ITEM_OPENABLE then
jcallahan@19 330 table.wipe(action_data)
jcallahan@19 331 action_data.type = AF.ITEM
jcallahan@28 332 action_data.identifier = item_id
jcallahan@25 333 action_data.label = "contains"
jcallahan@19 334 break
jcallahan@19 335 end
jcallahan@19 336 end
jcallahan@19 337 end
jcallahan@19 338
jcallahan@19 339
jcallahan@39 340 local UnitFactionStanding
jcallahan@32 341 local UpdateFactionData
jcallahan@32 342 do
jcallahan@32 343 local MAX_FACTION_INDEX = 1000
jcallahan@20 344
jcallahan@32 345 local STANDING_NAMES = {
jcallahan@32 346 "HATED",
jcallahan@32 347 "HOSTILE",
jcallahan@32 348 "UNFRIENDLY",
jcallahan@32 349 "NEUTRAL",
jcallahan@32 350 "FRIENDLY",
jcallahan@32 351 "HONORED",
jcallahan@32 352 "REVERED",
jcallahan@32 353 "EXALTED",
jcallahan@32 354 }
jcallahan@32 355
jcallahan@39 356
jcallahan@39 357 function UnitFactionStanding(unit)
jcallahan@39 358 UpdateFactionData()
jcallahan@39 359 DatamineTT:ClearLines()
jcallahan@39 360 DatamineTT:SetUnit(unit)
jcallahan@39 361
jcallahan@39 362 for line_index = 1, DatamineTT:NumLines() do
jcallahan@64 363 local faction_name = _G["WDPDatamineTTTextLeft" .. line_index]:GetText():trim()
jcallahan@39 364
jcallahan@39 365 if faction_name and faction_standings[faction_name] then
jcallahan@39 366 return faction_name, faction_standings[faction_name]
jcallahan@39 367 end
jcallahan@39 368 end
jcallahan@39 369 end
jcallahan@39 370
jcallahan@39 371
jcallahan@32 372 function UpdateFactionData()
jcallahan@32 373 for faction_index = 1, MAX_FACTION_INDEX do
jcallahan@32 374 local faction_name, _, current_standing, _, _, _, _, _, is_header = _G.GetFactionInfo(faction_index)
jcallahan@32 375
jcallahan@32 376 if faction_name and not is_header then
jcallahan@32 377 faction_standings[faction_name] = STANDING_NAMES[current_standing]
jcallahan@32 378 elseif not faction_name then
jcallahan@32 379 break
jcallahan@32 380 end
jcallahan@20 381 end
jcallahan@20 382 end
jcallahan@32 383 end -- do-block
jcallahan@20 384
jcallahan@48 385
jcallahan@75 386 local GenericLootUpdate
jcallahan@75 387 do
jcallahan@77 388 local function LootTable(entry, loot_type, top_field)
jcallahan@75 389 if top_field then
jcallahan@75 390 entry[top_field] = entry[top_field] or {}
jcallahan@75 391 entry[top_field][loot_type] = entry[top_field][loot_type] or {}
jcallahan@75 392 return entry[top_field][loot_type]
jcallahan@75 393 end
jcallahan@48 394 entry[loot_type] = entry[loot_type] or {}
jcallahan@75 395 return entry[loot_type]
jcallahan@48 396 end
jcallahan@48 397
jcallahan@75 398 function GenericLootUpdate(data_type, top_field)
jcallahan@75 399 local loot_type = action_data.label or "drops"
jcallahan@75 400 local loot_count = ("%s_count"):format(loot_type)
jcallahan@77 401 local source_list = {}
jcallahan@75 402
jcallahan@78 403 for source_guid, loot_data in pairs(action_data.loot_sources) do
jcallahan@78 404 local entry, source_id
jcallahan@78 405
jcallahan@78 406 if action_data.type == AF.ITEM then
jcallahan@78 407 -- Items return the player as the source, so we need to use the item's ID (disenchant, milling, etc)
jcallahan@78 408 source_id = action_data.identifier
jcallahan@78 409 entry = DBEntry(data_type, source_id)
jcallahan@78 410 elseif action_data.type == AF.OBJECT then
jcallahan@78 411 source_id = ("%s:%s"):format(action_data.spell_label, select(2, ParseGUID(source_guid)))
jcallahan@78 412 entry = DBEntry(data_type, source_id)
jcallahan@78 413 else
jcallahan@78 414 source_id = select(2, ParseGUID(source_guid))
jcallahan@78 415 entry = DBEntry(data_type, source_id)
jcallahan@78 416 end
jcallahan@75 417
jcallahan@75 418 if entry then
jcallahan@77 419 local loot_table = LootTable(entry, loot_type, top_field)
jcallahan@77 420
jcallahan@78 421 if not source_list[source_guid] then
jcallahan@77 422 if top_field then
jcallahan@77 423 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1
jcallahan@77 424 else
jcallahan@77 425 entry[loot_count] = (entry[loot_count] or 0) + 1
jcallahan@77 426 end
jcallahan@78 427 source_list[source_guid] = true
jcallahan@77 428 end
jcallahan@75 429 UpdateDBEntryLocation(data_type, source_id)
jcallahan@75 430
jcallahan@75 431 for item_id, quantity in pairs(loot_data) do
jcallahan@75 432 table.insert(loot_table, ("%d:%d"):format(item_id, quantity))
jcallahan@75 433 end
jcallahan@75 434 end
jcallahan@75 435 end
jcallahan@75 436 -- TODO: Remove this when GetLootSourceInfo() has values for money
jcallahan@82 437 if #action_data.loot_list <= 0 then
jcallahan@78 438 return
jcallahan@78 439 end
jcallahan@82 440 local entry
jcallahan@82 441
jcallahan@82 442 -- At this point we only have a name if it's an object.
jcallahan@82 443 if action_data.type == AF.OBJECT then
jcallahan@82 444 entry = DBEntry(data_type, ("%s:%s"):format(action_data.spell_label, action_data.target_name))
jcallahan@82 445 else
jcallahan@82 446 entry = DBEntry(data_type, action_data.identifier)
jcallahan@82 447 end
jcallahan@75 448
jcallahan@75 449 if not entry then
jcallahan@75 450 return
jcallahan@75 451 end
jcallahan@77 452 local loot_table = LootTable(entry, loot_type, top_field)
jcallahan@77 453
jcallahan@77 454 if not source_list[action_data.identifier] then
jcallahan@77 455 if top_field then
jcallahan@77 456 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1
jcallahan@77 457 else
jcallahan@77 458 entry[loot_count] = (entry[loot_count] or 0) + 1
jcallahan@77 459 end
jcallahan@77 460 end
jcallahan@75 461
jcallahan@75 462 for index = 1, #action_data.loot_list do
jcallahan@75 463 table.insert(loot_table, action_data.loot_list[index])
jcallahan@75 464 end
jcallahan@48 465 end
jcallahan@75 466 end -- do-block
jcallahan@48 467
jcallahan@0 468 -----------------------------------------------------------------------
jcallahan@0 469 -- Methods.
jcallahan@0 470 -----------------------------------------------------------------------
jcallahan@0 471 function WDP:OnInitialize()
jcallahan@0 472 db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default").global
jcallahan@14 473
jcallahan@14 474 local raw_db = _G["WoWDBProfilerData"]
jcallahan@18 475 local build_num = tonumber(private.build_num)
jcallahan@14 476
jcallahan@74 477 -- TODO: Merge this with the DB version check when MoP goes live.
jcallahan@35 478 -- if raw_db.build_num and raw_db.build_num < build_num then
jcallahan@74 479 if raw_db.version and raw_db.version < DB_VERSION then
jcallahan@74 480 for entry in pairs(DATABASE_DEFAULTS.global) do
jcallahan@74 481 db[entry] = {}
jcallahan@74 482 end
jcallahan@74 483 end
jcallahan@35 484 raw_db.build_num = build_num
jcallahan@63 485 raw_db.version = DB_VERSION
jcallahan@0 486 end
jcallahan@0 487
jcallahan@0 488
jcallahan@0 489 function WDP:OnEnable()
jcallahan@0 490 for event_name, mapping in pairs(EVENT_MAPPING) do
jcallahan@1 491 self:RegisterEvent(event_name, (_G.type(mapping) ~= "boolean") and mapping or nil)
jcallahan@0 492 end
jcallahan@0 493 durability_timer_handle = self:ScheduleRepeatingTimer("ProcessDurability", 30)
jcallahan@31 494 target_location_timer_handle = self:ScheduleRepeatingTimer("UpdateTargetLocation", 0.5)
jcallahan@19 495
jcallahan@19 496 _G.hooksecurefunc("UseContainerItem", function(bag_index, slot_index, target_unit)
jcallahan@19 497 if target_unit then
jcallahan@19 498 return
jcallahan@19 499 end
jcallahan@19 500 HandleItemUse(_G.GetContainerItemLink(bag_index, slot_index), bag_index, slot_index)
jcallahan@19 501 end)
jcallahan@19 502
jcallahan@19 503 _G.hooksecurefunc("UseItemByName", function(identifier, target_unit)
jcallahan@19 504 if target_unit then
jcallahan@19 505 return
jcallahan@19 506 end
jcallahan@19 507 local _, item_link = _G.GetItemInfo(identifier)
jcallahan@19 508 HandleItemUse(item_link)
jcallahan@19 509 end)
jcallahan@0 510 end
jcallahan@0 511
jcallahan@0 512
jcallahan@0 513 local function RecordDurability(item_id, durability)
jcallahan@0 514 if not durability or durability <= 0 then
jcallahan@0 515 return
jcallahan@0 516 end
jcallahan@0 517
jcallahan@0 518 if not db.items[item_id] then
jcallahan@0 519 db.items[item_id] = {}
jcallahan@0 520 end
jcallahan@0 521 db.items[item_id].durability = durability
jcallahan@0 522 end
jcallahan@0 523
jcallahan@0 524
jcallahan@0 525 function WDP:ProcessDurability()
jcallahan@0 526 for slot_index = 0, _G.INVSLOT_LAST_EQUIPPED do
jcallahan@1 527 local item_id = _G.GetInventoryItemID("player", slot_index)
jcallahan@0 528
jcallahan@0 529 if item_id and item_id > 0 then
jcallahan@1 530 local _, max_durability = _G.GetInventoryItemDurability(slot_index)
jcallahan@0 531 RecordDurability(item_id, max_durability)
jcallahan@0 532 end
jcallahan@0 533 end
jcallahan@0 534
jcallahan@0 535 for bag_index = 0, _G.NUM_BAG_SLOTS do
jcallahan@0 536 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
jcallahan@1 537 local item_id = _G.GetContainerItemID(bag_index, slot_index)
jcallahan@0 538
jcallahan@0 539 if item_id and item_id > 0 then
jcallahan@1 540 local _, max_durability = _G.GetContainerItemDurability(bag_index, slot_index)
jcallahan@0 541 RecordDurability(item_id, max_durability)
jcallahan@0 542 end
jcallahan@0 543 end
jcallahan@0 544 end
jcallahan@0 545 end
jcallahan@0 546
jcallahan@0 547
jcallahan@2 548 function WDP:UpdateTargetLocation()
jcallahan@40 549 if currently_drunk or not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or (_G.UnitIsTapped("target") and not _G.UnitIsDead("target")) then
jcallahan@2 550 return
jcallahan@2 551 end
jcallahan@2 552
jcallahan@2 553 for index = 1, 4 do
jcallahan@2 554 if not _G.CheckInteractDistance("target", index) then
jcallahan@2 555 return
jcallahan@2 556 end
jcallahan@2 557 end
jcallahan@40 558 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
jcallahan@2 559
jcallahan@40 560 if not unit_idnum or unit_type ~= private.UNIT_TYPES.NPC then
jcallahan@2 561 return
jcallahan@2 562 end
jcallahan@34 563 UpdateNPCLocation(unit_idnum)
jcallahan@2 564 end
jcallahan@2 565
jcallahan@2 566
jcallahan@0 567 -----------------------------------------------------------------------
jcallahan@0 568 -- Event handlers.
jcallahan@0 569 -----------------------------------------------------------------------
jcallahan@56 570 function WDP:BLACK_MARKET_ITEM_UPDATE(event)
jcallahan@56 571 local num_items = _G.C_BlackMarket.GetNumItems()
jcallahan@56 572
jcallahan@56 573 for index = 1, num_items do
jcallahan@56 574 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 575
jcallahan@56 576 if item_link then
jcallahan@56 577 DBEntry("items", ItemLinkToID(item_link)).black_market = seller_name or "UNKNOWN"
jcallahan@56 578 end
jcallahan@56 579 end
jcallahan@56 580 end
jcallahan@56 581
jcallahan@56 582
jcallahan@75 583 function WDP:CHAT_MSG_LOOT(event_name, message)
jcallahan@48 584 if action_data.spell_label ~= "EXTRACT_GAS" then
jcallahan@48 585 return
jcallahan@48 586 end
jcallahan@48 587 local item_link, quantity = deformat(message, _G.LOOT_ITEM_PUSHED_SELF_MULTIPLE)
jcallahan@48 588
jcallahan@48 589 if not item_link then
jcallahan@48 590 quantity, item_link = 1, deformat(message, _G.LOOT_ITEM_PUSHED_SELF)
jcallahan@48 591 end
jcallahan@48 592
jcallahan@48 593 if not item_link then
jcallahan@48 594 return
jcallahan@48 595 end
jcallahan@48 596 local item_id = ItemLinkToID(item_link)
jcallahan@48 597
jcallahan@48 598 if not item_id then
jcallahan@48 599 return
jcallahan@48 600 end
jcallahan@48 601 action_data.loot_list = {
jcallahan@48 602 ("%d:%d"):format(item_id, quantity)
jcallahan@48 603 }
jcallahan@48 604 GenericLootUpdate("zones")
jcallahan@48 605 table.wipe(action_data)
jcallahan@48 606 end
jcallahan@48 607
jcallahan@48 608
jcallahan@23 609 do
jcallahan@40 610 local SOBER_MATCH = _G.DRUNK_MESSAGE_ITEM_SELF1:gsub("%%s", ".+")
jcallahan@40 611
jcallahan@40 612 local DRUNK_COMPARES = {
jcallahan@40 613 _G.DRUNK_MESSAGE_SELF2,
jcallahan@40 614 _G.DRUNK_MESSAGE_SELF3,
jcallahan@40 615 _G.DRUNK_MESSAGE_SELF4,
jcallahan@40 616 }
jcallahan@40 617
jcallahan@40 618 local DRUNK_MATCHES = {
jcallahan@40 619 _G.DRUNK_MESSAGE_SELF2:gsub("%%s", ".+"),
jcallahan@40 620 _G.DRUNK_MESSAGE_SELF3:gsub("%%s", ".+"),
jcallahan@40 621 _G.DRUNK_MESSAGE_SELF4:gsub("%%s", ".+"),
jcallahan@40 622 }
jcallahan@40 623
jcallahan@40 624 function WDP:CHAT_MSG_SYSTEM(event, message)
jcallahan@40 625 if currently_drunk then
jcallahan@40 626 if message == _G.DRUNK_MESSAGE_SELF1 or message:match(SOBER_MATCH) then
jcallahan@40 627 currently_drunk = nil
jcallahan@40 628 end
jcallahan@40 629 return
jcallahan@40 630 end
jcallahan@40 631
jcallahan@40 632 for index = 1, #DRUNK_MATCHES do
jcallahan@40 633 if message == DRUNK_COMPARES[index] or message:match(DRUNK_MATCHES[index]) then
jcallahan@40 634 currently_drunk = true
jcallahan@40 635 break
jcallahan@40 636 end
jcallahan@40 637 end
jcallahan@40 638 end
jcallahan@40 639 end
jcallahan@40 640
jcallahan@40 641 -- do-block
jcallahan@40 642
jcallahan@40 643 do
jcallahan@23 644 local FLAGS_NPC = bit.bor(_G.COMBATLOG_OBJECT_TYPE_GUARDIAN, _G.COMBATLOG_OBJECT_CONTROL_NPC)
jcallahan@23 645 local FLAGS_NPC_CONTROL = bit.bor(_G.COMBATLOG_OBJECT_AFFILIATION_OUTSIDER, _G.COMBATLOG_OBJECT_CONTROL_NPC)
jcallahan@23 646
jcallahan@23 647 local function RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
jcallahan@23 648 if not spell_id then
jcallahan@23 649 return
jcallahan@23 650 end
jcallahan@34 651 local source_type, source_id = ParseGUID(source_guid)
jcallahan@23 652
jcallahan@23 653 if not source_id or source_type ~= private.UNIT_TYPES.NPC then
jcallahan@23 654 return
jcallahan@23 655 end
jcallahan@23 656
jcallahan@23 657 if bit.band(FLAGS_NPC_CONTROL, source_flags) == FLAGS_NPC_CONTROL and bit.band(FLAGS_NPC, source_flags) ~= 0 then
jcallahan@29 658 local encounter_data = NPCEntry(source_id).encounter_data[InstanceDifficultyToken()]
jcallahan@28 659 encounter_data.spells = encounter_data.spells or {}
jcallahan@28 660 encounter_data.spells[spell_id] = (encounter_data.spells[spell_id] or 0) + 1
jcallahan@23 661 end
jcallahan@23 662 end
jcallahan@23 663
jcallahan@23 664 local COMBAT_LOG_FUNCS = {
jcallahan@23 665 SPELL_AURA_APPLIED = RecordNPCSpell,
jcallahan@23 666 SPELL_CAST_START = RecordNPCSpell,
jcallahan@48 667 SPELL_CAST_SUCCESS = RecordNPCSpell,
jcallahan@65 668 UNIT_DIED = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
jcallahan@65 669 local unit_type, unit_idnum = ParseGUID(dest_guid)
jcallahan@65 670
jcallahan@65 671 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
jcallahan@67 672 reputation_npc_id = nil
jcallahan@65 673 return
jcallahan@65 674 end
jcallahan@67 675 reputation_npc_id = unit_idnum
jcallahan@65 676 end,
jcallahan@23 677 }
jcallahan@23 678
jcallahan@23 679
jcallahan@23 680 function WDP:COMBAT_LOG_EVENT_UNFILTERED(event, 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 681 local combat_log_func = COMBAT_LOG_FUNCS[sub_event]
jcallahan@23 682
jcallahan@23 683 if not combat_log_func then
jcallahan@23 684 return
jcallahan@23 685 end
jcallahan@23 686 combat_log_func(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, ...)
jcallahan@23 687 end
jcallahan@23 688
jcallahan@44 689 local DIPLOMACY_SPELL_ID = 20599
jcallahan@44 690 local MR_POP_RANK1_SPELL_ID = 78634
jcallahan@44 691 local MR_POP_RANK2_SPELL_ID = 78635
jcallahan@44 692
jcallahan@44 693 local REP_BUFFS = {
jcallahan@44 694 [_G.GetSpellInfo(30754)] = "CENARION_FAVOR",
jcallahan@44 695 [_G.GetSpellInfo(24705)] = "GRIM_VISAGE",
jcallahan@44 696 [_G.GetSpellInfo(32098)] = "HONOR_HOLD_FAVOR",
jcallahan@44 697 [_G.GetSpellInfo(39913)] = "NAZGRELS_FERVOR",
jcallahan@44 698 [_G.GetSpellInfo(39953)] = "SONG_OF_BATTLE",
jcallahan@44 699 [_G.GetSpellInfo(61849)] = "SPIRIT_OF_SHARING",
jcallahan@44 700 [_G.GetSpellInfo(32096)] = "THRALLMARS_FAVOR",
jcallahan@44 701 [_G.GetSpellInfo(39911)] = "TROLLBANES_COMMAND",
jcallahan@44 702 [_G.GetSpellInfo(95987)] = "UNBURDENED",
jcallahan@44 703 [_G.GetSpellInfo(100951)] = "WOW_ANNIVERSARY",
jcallahan@44 704 }
jcallahan@44 705
jcallahan@44 706
jcallahan@44 707 local FACTION_NAMES = {
jcallahan@44 708 CENARION_CIRCLE = _G.GetFactionInfoByID(609),
jcallahan@44 709 HONOR_HOLD = _G.GetFactionInfoByID(946),
jcallahan@44 710 THE_SHATAR = _G.GetFactionInfoByID(935),
jcallahan@44 711 THRALLMAR = _G.GetFactionInfoByID(947),
jcallahan@44 712 }
jcallahan@44 713
jcallahan@44 714
jcallahan@44 715 local MODIFIERS = {
jcallahan@44 716 CENARION_FAVOR = {
jcallahan@44 717 faction = FACTION_NAMES.CENARION_CIRCLE,
jcallahan@44 718 modifier = 0.25,
jcallahan@44 719 },
jcallahan@44 720 GRIM_VISAGE = {
jcallahan@44 721 modifier = 0.1,
jcallahan@44 722 },
jcallahan@44 723 HONOR_HOLD_FAVOR = {
jcallahan@44 724 faction = FACTION_NAMES.HONOR_HOLD,
jcallahan@44 725 modifier = 0.25,
jcallahan@44 726 },
jcallahan@44 727 NAZGRELS_FERVOR = {
jcallahan@44 728 faction = FACTION_NAMES.THRALLMAR,
jcallahan@44 729 modifier = 0.1,
jcallahan@44 730 },
jcallahan@44 731 SONG_OF_BATTLE = {
jcallahan@44 732 faction = FACTION_NAMES.THE_SHATAR,
jcallahan@44 733 modifier = 0.1,
jcallahan@44 734 },
jcallahan@44 735 SPIRIT_OF_SHARING = {
jcallahan@44 736 modifier = 0.1,
jcallahan@44 737 },
jcallahan@44 738 THRALLMARS_FAVOR = {
jcallahan@44 739 faction = FACTION_NAMES.THRALLMAR,
jcallahan@44 740 modifier = 0.25,
jcallahan@44 741 },
jcallahan@44 742 TROLLBANES_COMMAND = {
jcallahan@44 743 faction = FACTION_NAMES.HONOR_HOLD,
jcallahan@44 744 modifier = 0.1,
jcallahan@44 745 },
jcallahan@44 746 UNBURDENED = {
jcallahan@44 747 modifier = 0.1,
jcallahan@44 748 },
jcallahan@44 749 WOW_ANNIVERSARY = {
jcallahan@44 750 modifier = 0.08,
jcallahan@44 751 }
jcallahan@44 752 }
jcallahan@44 753
jcallahan@44 754
jcallahan@44 755 function WDP:COMBAT_TEXT_UPDATE(event, message_type, faction_name, amount)
jcallahan@67 756 if message_type ~= "FACTION" or not reputation_npc_id then
jcallahan@44 757 return
jcallahan@44 758 end
jcallahan@44 759 UpdateFactionData()
jcallahan@44 760
jcallahan@46 761 if not faction_name or not faction_standings[faction_name] then
jcallahan@46 762 return
jcallahan@46 763 end
jcallahan@67 764 local npc = NPCEntry(reputation_npc_id)
jcallahan@46 765
jcallahan@44 766 if not npc then
jcallahan@44 767 return
jcallahan@44 768 end
jcallahan@44 769 local modifier = 1
jcallahan@44 770
jcallahan@44 771 if _G.IsSpellKnown(DIPLOMACY_SPELL_ID) then
jcallahan@44 772 modifier = modifier + 0.1
jcallahan@44 773 end
jcallahan@44 774
jcallahan@44 775 if _G.IsSpellKnown(MR_POP_RANK2_SPELL_ID) then
jcallahan@44 776 modifier = modifier + 0.1
jcallahan@44 777 elseif _G.IsSpellKnown(MR_POP_RANK1_SPELL_ID) then
jcallahan@44 778 modifier = modifier + 0.05
jcallahan@44 779 end
jcallahan@44 780
jcallahan@44 781 for buff_name, buff_label in pairs(REP_BUFFS) do
jcallahan@44 782 if _G.UnitBuff("player", buff_name) then
jcallahan@44 783 local modded_faction = MODIFIERS[buff_label].faction
jcallahan@44 784
jcallahan@44 785 if not modded_faction or faction_name == modded_faction then
jcallahan@44 786 modifier = modifier + MODIFIERS[buff_label].modifier
jcallahan@44 787 end
jcallahan@44 788 end
jcallahan@44 789 end
jcallahan@65 790 npc.reputations = npc.reputations or {}
jcallahan@65 791 npc.reputations[("%s:%s"):format(faction_name, faction_standings[faction_name])] = math.floor(amount / modifier)
jcallahan@67 792 reputation_npc_id = nil
jcallahan@32 793 end
jcallahan@44 794 end -- do-block
jcallahan@18 795
jcallahan@18 796
jcallahan@42 797 function WDP:ITEM_TEXT_BEGIN()
jcallahan@42 798 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
jcallahan@42 799
jcallahan@42 800 if not unit_idnum or unit_type ~= private.UNIT_TYPES.OBJECT or _G.UnitName("npc") ~= _G.ItemTextGetItem() then
jcallahan@42 801 return
jcallahan@42 802 end
jcallahan@42 803 UpdateDBEntryLocation("objects", unit_idnum)
jcallahan@42 804 end
jcallahan@42 805
jcallahan@42 806
jcallahan@13 807 do
jcallahan@40 808 local RE_GOLD = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)")
jcallahan@40 809 local RE_SILVER = _G.SILVER_AMOUNT:gsub("%%d", "(%%d+)")
jcallahan@40 810 local RE_COPPER = _G.COPPER_AMOUNT:gsub("%%d", "(%%d+)")
jcallahan@13 811
jcallahan@13 812
jcallahan@13 813 local function _moneyMatch(money, re)
jcallahan@13 814 return money:match(re) or 0
jcallahan@1 815 end
jcallahan@1 816
jcallahan@0 817
jcallahan@13 818 local function _toCopper(money)
jcallahan@13 819 if not money then
jcallahan@13 820 return 0
jcallahan@13 821 end
jcallahan@40 822 return _moneyMatch(money, RE_GOLD) * 10000 + _moneyMatch(money, RE_SILVER) * 100 + _moneyMatch(money, RE_COPPER)
jcallahan@1 823 end
jcallahan@1 824
jcallahan@1 825
jcallahan@13 826 local LOOT_VERIFY_FUNCS = {
jcallahan@16 827 [AF.ITEM] = function()
jcallahan@16 828 local locked_item_id
jcallahan@16 829
jcallahan@16 830 for bag_index = 0, _G.NUM_BAG_FRAMES do
jcallahan@16 831 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
jcallahan@16 832 local _, _, is_locked = _G.GetContainerItemInfo(bag_index, slot_index)
jcallahan@16 833
jcallahan@16 834 if is_locked then
jcallahan@16 835 locked_item_id = ItemLinkToID(_G.GetContainerItemLink(bag_index, slot_index))
jcallahan@16 836 end
jcallahan@16 837 end
jcallahan@16 838 end
jcallahan@16 839
jcallahan@28 840 if not locked_item_id or (action_data.identifier and action_data.identifier ~= locked_item_id) then
jcallahan@16 841 return false
jcallahan@16 842 end
jcallahan@28 843 action_data.identifier = locked_item_id
jcallahan@16 844 return true
jcallahan@16 845 end,
jcallahan@13 846 [AF.NPC] = function()
jcallahan@17 847 if not _G.UnitExists("target") or _G.UnitIsFriend("player", "target") or _G.UnitIsPlayer("target") or _G.UnitPlayerControlled("target") then
jcallahan@15 848 return false
jcallahan@13 849 end
jcallahan@34 850 local unit_type, id_num = ParseGUID(_G.UnitGUID("target"))
jcallahan@27 851 action_data.identifier = id_num
jcallahan@13 852 return true
jcallahan@13 853 end,
jcallahan@14 854 [AF.OBJECT] = true,
jcallahan@17 855 [AF.ZONE] = function()
jcallahan@38 856 return _G.IsFishingLoot()
jcallahan@17 857 end,
jcallahan@13 858 }
jcallahan@13 859
jcallahan@13 860
jcallahan@13 861 local LOOT_UPDATE_FUNCS = {
jcallahan@16 862 [AF.ITEM] = function()
jcallahan@28 863 GenericLootUpdate("items")
jcallahan@28 864 end,
jcallahan@28 865 [AF.NPC] = function()
jcallahan@75 866 local difficulty_token = InstanceDifficultyToken()
jcallahan@75 867 local loot_type = action_data.label or "drops"
jcallahan@77 868 local source_list = {}
jcallahan@75 869
jcallahan@78 870 for source_guid, loot_data in pairs(action_data.loot_sources) do
jcallahan@78 871 local source_id = select(2, ParseGUID(source_guid))
jcallahan@75 872 local npc = NPCEntry(source_id)
jcallahan@75 873
jcallahan@75 874 if npc then
jcallahan@75 875 local encounter_data = npc.encounter_data[difficulty_token]
jcallahan@75 876 encounter_data[loot_type] = encounter_data[loot_type] or {}
jcallahan@75 877
jcallahan@78 878 if not source_list[source_guid] then
jcallahan@77 879 encounter_data.loot_counts = encounter_data.loot_counts or {}
jcallahan@77 880 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1
jcallahan@77 881 source_list[source_id] = true
jcallahan@77 882 end
jcallahan@77 883
jcallahan@75 884 for item_id, quantity in pairs(loot_data) do
jcallahan@75 885 table.insert(encounter_data[loot_type], ("%d:%d"):format(item_id, quantity))
jcallahan@75 886 end
jcallahan@75 887 end
jcallahan@75 888 end
jcallahan@75 889
jcallahan@75 890 -- TODO: Remove this when GetLootSourceInfo() has values for money
jcallahan@79 891 if #action_data.loot_list <= 0 then
jcallahan@79 892 return
jcallahan@79 893 end
jcallahan@29 894 local npc = NPCEntry(action_data.identifier)
jcallahan@28 895
jcallahan@28 896 if not npc then
jcallahan@28 897 return
jcallahan@28 898 end
jcallahan@75 899 local encounter_data = npc.encounter_data[difficulty_token]
jcallahan@29 900 encounter_data[loot_type] = encounter_data[loot_type] or {}
jcallahan@16 901
jcallahan@77 902 if not source_list[action_data.identifier] then
jcallahan@77 903 encounter_data.loot_counts = encounter_data.loot_counts or {}
jcallahan@77 904 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1
jcallahan@77 905 end
jcallahan@77 906
jcallahan@17 907 for index = 1, #action_data.loot_list do
jcallahan@29 908 table.insert(encounter_data[loot_type], action_data.loot_list[index])
jcallahan@16 909 end
jcallahan@16 910 end,
jcallahan@13 911 [AF.OBJECT] = function()
jcallahan@28 912 GenericLootUpdate("objects", InstanceDifficultyToken())
jcallahan@17 913 end,
jcallahan@17 914 [AF.ZONE] = function()
jcallahan@41 915 local location_token = ("%s:%s:%s"):format(action_data.map_level, action_data.x, action_data.y)
jcallahan@41 916
jcallahan@41 917 -- This will start life as a boolean true.
jcallahan@41 918 if _G.type(action_data.zone_data[location_token]) ~= "table" then
jcallahan@41 919 action_data.zone_data[location_token] = {
jcallahan@41 920 drops = {}
jcallahan@41 921 }
jcallahan@41 922 end
jcallahan@41 923 local loot_count = ("%s_count"):format(action_data.label or "drops")
jcallahan@41 924 action_data.zone_data[location_token][loot_count] = (action_data.zone_data[location_token][loot_count] or 0) + 1
jcallahan@41 925
jcallahan@41 926 for index = 1, #action_data.loot_list do
jcallahan@41 927 table.insert(action_data.zone_data[location_token].drops, action_data.loot_list[index])
jcallahan@41 928 end
jcallahan@13 929 end,
jcallahan@13 930 }
jcallahan@13 931
jcallahan@79 932 -- Prevent opening the same loot window multiple times from recording data multiple times.
jcallahan@79 933 local loot_guid_registry = {}
jcallahan@13 934
jcallahan@13 935 function WDP:LOOT_OPENED()
jcallahan@18 936 if action_data.looting then
jcallahan@18 937 return
jcallahan@18 938 end
jcallahan@18 939
jcallahan@13 940 if not action_data.type then
jcallahan@13 941 action_data.type = AF.NPC
jcallahan@1 942 end
jcallahan@13 943 local verify_func = LOOT_VERIFY_FUNCS[action_data.type]
jcallahan@13 944 local update_func = LOOT_UPDATE_FUNCS[action_data.type]
jcallahan@13 945
jcallahan@14 946 if not verify_func or not update_func then
jcallahan@13 947 return
jcallahan@13 948 end
jcallahan@13 949
jcallahan@14 950 if _G.type(verify_func) == "function" and not verify_func() then
jcallahan@14 951 return
jcallahan@14 952 end
jcallahan@80 953 local guids_used = {}
jcallahan@17 954 action_data.loot_list = {}
jcallahan@75 955 action_data.loot_sources = {}
jcallahan@18 956 action_data.looting = true
jcallahan@13 957
jcallahan@55 958 for loot_slot = 1, _G.GetNumLootItems() do
jcallahan@55 959 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
jcallahan@55 960 local slot_type = _G.GetLootSlotType(loot_slot)
jcallahan@13 961
jcallahan@77 962 -- TODO: Move LOOT_SLOT_X checks within loop when money is detectable via GetLootSourceInfo
jcallahan@77 963 if slot_type == _G.LOOT_SLOT_ITEM then
jcallahan@78 964 local loot_info = {
jcallahan@77 965 _G.GetLootSourceInfo(loot_slot)
jcallahan@77 966 }
jcallahan@75 967
jcallahan@75 968 -- TODO: Remove debugging
jcallahan@77 969 -- print(("Loot slot %d: Source count: %d"):format(loot_slot, floor((#sources / 2) + 0.5)))
jcallahan@75 970
jcallahan@77 971 -- Odd index is GUID, even is count.
jcallahan@78 972 for loot_index = 1, #loot_info, 2 do
jcallahan@78 973 local source_guid = loot_info[loot_index]
jcallahan@77 974
jcallahan@79 975 if not loot_guid_registry[source_guid] then
jcallahan@79 976 local loot_quantity = loot_info[loot_index + 1]
jcallahan@79 977 local source_type, source_id = ParseGUID(source_guid)
jcallahan@79 978 -- TODO: Remove debugging
jcallahan@79 979 -- local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id)
jcallahan@79 980 -- print(("GUID: %s - Type:ID: %s - Amount: %d"):format(loot_info[loot_index], source_key, loot_quantity))
jcallahan@79 981
jcallahan@79 982 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
jcallahan@79 983 action_data.loot_sources[source_guid] = action_data.loot_sources[source_guid] or {}
jcallahan@79 984 action_data.loot_sources[source_guid][item_id] = action_data.loot_sources[source_guid][item_id] or 0 + loot_quantity
jcallahan@80 985 guids_used[source_guid] = true
jcallahan@79 986 end
jcallahan@75 987 end
jcallahan@82 988 -- elseif slot_type == _G.LOOT_SLOT_MONEY then
jcallahan@82 989 -- table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
jcallahan@77 990 elseif slot_type == _G.LOOT_SLOT_CURRENCY then
jcallahan@77 991 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
jcallahan@13 992 end
jcallahan@13 993 end
jcallahan@80 994
jcallahan@81 995 for guid in pairs(guids_used) do
jcallahan@80 996 loot_guid_registry[guid] = true
jcallahan@80 997 end
jcallahan@13 998 update_func()
jcallahan@1 999 end
jcallahan@13 1000 end -- do-block
jcallahan@0 1001
jcallahan@0 1002
jcallahan@44 1003 do
jcallahan@44 1004 local POINT_MATCH_PATTERNS = {
jcallahan@44 1005 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING:gsub("%%d", "(%%d+)")), -- May no longer be necessary
jcallahan@44 1006 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3:gsub("%%d", "(%%d+)")), -- May no longer be necessary
jcallahan@44 1007 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_5V5:gsub("%%d", "(%%d+)")), -- May no longer be necessary
jcallahan@44 1008 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_BG:gsub("%%d", "(%%d+)")),
jcallahan@44 1009 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3_BG:gsub("%%d", "(%%d+)")),
jcallahan@44 1010 }
jcallahan@5 1011
jcallahan@68 1012 local ITEM_REQ_REPUTATION_MATCH = "Requires (.-) %- (.*)"
jcallahan@68 1013
jcallahan@44 1014 function WDP:UpdateMerchantItems(event)
jcallahan@44 1015 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
jcallahan@4 1016
jcallahan@44 1017 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
jcallahan@44 1018 return
jcallahan@44 1019 end
jcallahan@55 1020 local current_filters = _G.GetMerchantFilter()
jcallahan@44 1021 local _, merchant_standing = UnitFactionStanding("target")
jcallahan@44 1022 local merchant = NPCEntry(unit_idnum)
jcallahan@44 1023 merchant.sells = merchant.sells or {}
jcallahan@5 1024
jcallahan@57 1025 _G.SetMerchantFilter(_G.LE_LOOT_FILTER_ALL)
jcallahan@57 1026 _G.MerchantFrame_Update()
jcallahan@57 1027
jcallahan@57 1028 local num_items = _G.GetMerchantNumItems()
jcallahan@35 1029
jcallahan@44 1030 for item_index = 1, num_items do
jcallahan@44 1031 local _, _, copper_price, stack_size, num_available, _, extended_cost = _G.GetMerchantItemInfo(item_index)
jcallahan@44 1032 local item_id = ItemLinkToID(_G.GetMerchantItemLink(item_index))
jcallahan@5 1033
jcallahan@44 1034 if item_id and item_id > 0 then
jcallahan@44 1035 local price_string = ActualCopperCost(copper_price, merchant_standing)
jcallahan@5 1036
jcallahan@68 1037 DatamineTT:ClearLines()
jcallahan@68 1038 DatamineTT:SetMerchantItem(item_index)
jcallahan@68 1039
jcallahan@68 1040 local num_lines = DatamineTT:NumLines()
jcallahan@68 1041
jcallahan@68 1042 for line_index = 1, num_lines do
jcallahan@68 1043 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
jcallahan@68 1044
jcallahan@68 1045 if not current_line then
jcallahan@68 1046 break
jcallahan@68 1047 end
jcallahan@68 1048 local faction, reputation = current_line:GetText():match(ITEM_REQ_REPUTATION_MATCH)
jcallahan@68 1049
jcallahan@68 1050 if faction or reputation then
jcallahan@68 1051 DBEntry("items", item_id).req_reputation = ("%s:%s"):format(faction:gsub("-", ""), reputation:upper())
jcallahan@68 1052 break
jcallahan@68 1053 end
jcallahan@68 1054 end
jcallahan@68 1055
jcallahan@44 1056 if extended_cost then
jcallahan@53 1057 local battleground_rating = 0
jcallahan@53 1058 local personal_rating = 0
jcallahan@53 1059 local required_season_amount
jcallahan@5 1060
jcallahan@68 1061 for line_index = 1, num_lines do
jcallahan@44 1062 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
jcallahan@5 1063
jcallahan@44 1064 if not current_line then
jcallahan@44 1065 break
jcallahan@44 1066 end
jcallahan@53 1067 required_season_amount = current_line:GetText():match("Requires earning a total of (%d+)\n(.-) for the season.")
jcallahan@5 1068
jcallahan@44 1069 for match_index = 1, #POINT_MATCH_PATTERNS do
jcallahan@44 1070 local match1, match2 = current_line:GetText():match(POINT_MATCH_PATTERNS[match_index])
jcallahan@53 1071 personal_rating = personal_rating + (match1 or 0)
jcallahan@53 1072 battleground_rating = battleground_rating + (match2 or 0)
jcallahan@5 1073
jcallahan@44 1074 if match1 or match2 then
jcallahan@44 1075 break
jcallahan@44 1076 end
jcallahan@44 1077 end
jcallahan@5 1078 end
jcallahan@44 1079 local currency_list = {}
jcallahan@44 1080 local item_count = _G.GetMerchantItemCostInfo(item_index)
jcallahan@50 1081
jcallahan@50 1082 -- Keeping this around in case Blizzard makes the two points diverge at some point.
jcallahan@53 1083 -- price_string = ("%s:%s:%s:%s"):format(price_string, battleground_rating, personal_rating, required_season_amount or 0)
jcallahan@53 1084 price_string = ("%s:%s:%s"):format(price_string, personal_rating, required_season_amount or 0)
jcallahan@5 1085
jcallahan@44 1086 for cost_index = 1, item_count do
jcallahan@44 1087 local icon_texture, amount_required, currency_link = _G.GetMerchantItemCostItem(item_index, cost_index)
jcallahan@44 1088 local currency_id = currency_link and ItemLinkToID(currency_link) or nil
jcallahan@44 1089
jcallahan@44 1090 if (not currency_id or currency_id < 1) and icon_texture then
jcallahan@44 1091 currency_id = icon_texture:match("[^\\]+$"):lower()
jcallahan@44 1092 end
jcallahan@44 1093
jcallahan@44 1094 if currency_id then
jcallahan@44 1095 currency_list[#currency_list + 1] = ("(%s:%s)"):format(amount_required, currency_id)
jcallahan@44 1096 end
jcallahan@44 1097 end
jcallahan@44 1098
jcallahan@44 1099 for currency_index = 1, #currency_list do
jcallahan@44 1100 price_string = ("%s:%s"):format(price_string, currency_list[currency_index])
jcallahan@5 1101 end
jcallahan@5 1102 end
jcallahan@61 1103 merchant.sells[item_id] = ("%s:%s:[%s]"):format(num_available, stack_size, price_string)
jcallahan@44 1104 end
jcallahan@44 1105 end
jcallahan@5 1106
jcallahan@44 1107 if _G.CanMerchantRepair() then
jcallahan@44 1108 merchant.can_repair = true
jcallahan@5 1109 end
jcallahan@57 1110 _G.SetMerchantFilter(current_filters)
jcallahan@57 1111 _G.MerchantFrame_Update()
jcallahan@4 1112 end
jcallahan@44 1113 end -- do-block
jcallahan@4 1114
jcallahan@25 1115 function WDP:PET_BAR_UPDATE()
jcallahan@25 1116 if not action_data.label or not action_data.label == "mind_control" then
jcallahan@25 1117 return
jcallahan@25 1118 end
jcallahan@34 1119 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("pet"))
jcallahan@25 1120
jcallahan@25 1121 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
jcallahan@25 1122 return
jcallahan@25 1123 end
jcallahan@29 1124 NPCEntry(unit_idnum).mind_control = true
jcallahan@25 1125 table.wipe(action_data)
jcallahan@25 1126 end
jcallahan@25 1127
jcallahan@25 1128
jcallahan@18 1129 do
jcallahan@18 1130 local GENDER_NAMES = {
jcallahan@18 1131 "UNKNOWN",
jcallahan@18 1132 "MALE",
jcallahan@18 1133 "FEMALE",
jcallahan@18 1134 }
jcallahan@2 1135
jcallahan@2 1136
jcallahan@18 1137 local REACTION_NAMES = {
jcallahan@18 1138 "HATED",
jcallahan@18 1139 "HOSTILE",
jcallahan@18 1140 "UNFRIENDLY",
jcallahan@18 1141 "NEUTRAL",
jcallahan@18 1142 "FRIENDLY",
jcallahan@18 1143 "HONORED",
jcallahan@18 1144 "REVERED",
jcallahan@18 1145 "EXALTED",
jcallahan@18 1146 }
jcallahan@2 1147
jcallahan@2 1148
jcallahan@18 1149 local POWER_TYPE_NAMES = {
jcallahan@18 1150 ["0"] = "MANA",
jcallahan@18 1151 ["1"] = "RAGE",
jcallahan@18 1152 ["2"] = "FOCUS",
jcallahan@18 1153 ["3"] = "ENERGY",
jcallahan@18 1154 ["6"] = "RUNIC_POWER",
jcallahan@18 1155 }
jcallahan@2 1156
jcallahan@2 1157
jcallahan@18 1158 function WDP:PLAYER_TARGET_CHANGED()
jcallahan@40 1159 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or currently_drunk then
jcallahan@18 1160 return
jcallahan@18 1161 end
jcallahan@34 1162 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
jcallahan@2 1163
jcallahan@18 1164 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
jcallahan@18 1165 return
jcallahan@18 1166 end
jcallahan@29 1167 local npc = NPCEntry(unit_idnum)
jcallahan@18 1168 local _, class_token = _G.UnitClass("target")
jcallahan@18 1169 npc.class = class_token
jcallahan@39 1170 npc.faction = UnitFactionStanding("target")
jcallahan@26 1171 npc.genders = npc.genders or {}
jcallahan@26 1172 npc.genders[GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"] = true
jcallahan@18 1173 npc.is_pvp = _G.UnitIsPVP("target") and true or nil
jcallahan@18 1174 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")])
jcallahan@2 1175
jcallahan@30 1176 local encounter_data = npc.encounter_data[InstanceDifficultyToken()].stats
jcallahan@18 1177 local npc_level = ("level_%d"):format(_G.UnitLevel("target"))
jcallahan@3 1178
jcallahan@28 1179 if not encounter_data[npc_level] then
jcallahan@28 1180 encounter_data[npc_level] = {
jcallahan@18 1181 max_health = _G.UnitHealthMax("target"),
jcallahan@18 1182 }
jcallahan@3 1183
jcallahan@18 1184 local max_power = _G.UnitManaMax("target")
jcallahan@18 1185
jcallahan@18 1186 if max_power > 0 then
jcallahan@18 1187 local power_type = _G.UnitPowerType("target")
jcallahan@28 1188 encounter_data[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power)
jcallahan@18 1189 end
jcallahan@3 1190 end
jcallahan@21 1191 table.wipe(action_data)
jcallahan@21 1192 action_data.type = AF.NPC
jcallahan@27 1193 action_data.identifier = unit_idnum
jcallahan@21 1194 action_data.npc_level = npc_level
jcallahan@31 1195
jcallahan@31 1196 self:UpdateTargetLocation()
jcallahan@2 1197 end
jcallahan@18 1198 end -- do-block
jcallahan@2 1199
jcallahan@12 1200 do
jcallahan@12 1201 local function UpdateQuestJuncture(point)
jcallahan@12 1202 local unit_name = _G.UnitName("questnpc")
jcallahan@9 1203
jcallahan@12 1204 if not unit_name then
jcallahan@12 1205 return
jcallahan@12 1206 end
jcallahan@34 1207 local unit_type, unit_id = ParseGUID(_G.UnitGUID("questnpc"))
jcallahan@9 1208
jcallahan@12 1209 if unit_type == private.UNIT_TYPES.OBJECT then
jcallahan@38 1210 UpdateDBEntryLocation("objects", unit_id)
jcallahan@12 1211 end
jcallahan@19 1212 local quest = DBEntry("quests", _G.GetQuestID())
jcallahan@12 1213 quest[point] = quest[point] or {}
jcallahan@12 1214 quest[point][("%s:%d"):format(private.UNIT_TYPE_NAMES[unit_type + 1], unit_id)] = true
jcallahan@24 1215
jcallahan@24 1216 return quest
jcallahan@12 1217 end
jcallahan@10 1218
jcallahan@12 1219
jcallahan@12 1220 function WDP:QUEST_COMPLETE()
jcallahan@67 1221 -- Make sure the quest NPC isn't erroneously recorded as giving reputation for quests which award it.
jcallahan@67 1222 reputation_npc_id = nil
jcallahan@12 1223 UpdateQuestJuncture("end")
jcallahan@10 1224 end
jcallahan@10 1225
jcallahan@12 1226
jcallahan@12 1227 function WDP:QUEST_DETAIL()
jcallahan@24 1228 local quest = UpdateQuestJuncture("begin")
jcallahan@24 1229
jcallahan@46 1230 if not quest then
jcallahan@46 1231 return
jcallahan@46 1232 end
jcallahan@24 1233 quest.classes = quest.classes or {}
jcallahan@27 1234 quest.classes[PLAYER_CLASS] = true
jcallahan@24 1235
jcallahan@24 1236 local _, race = _G.UnitRace("player")
jcallahan@24 1237 quest.races = quest.races or {}
jcallahan@24 1238 quest.races[race] = true
jcallahan@10 1239 end
jcallahan@12 1240 end -- do-block
jcallahan@9 1241
jcallahan@9 1242
jcallahan@4 1243 function WDP:QUEST_LOG_UPDATE()
jcallahan@38 1244 local selected_quest = _G.GetQuestLogSelection() -- Save current selection to be restored when we're done.
jcallahan@36 1245 local entry_index, processed_quests = 1, 0
jcallahan@36 1246 local _, num_quests = _G.GetNumQuestLogEntries()
jcallahan@36 1247
jcallahan@36 1248 while processed_quests <= num_quests do
jcallahan@36 1249 local _, _, _, _, is_header, _, _, _, quest_id = _G.GetQuestLogTitle(entry_index)
jcallahan@36 1250
jcallahan@36 1251 if not is_header then
jcallahan@36 1252 _G.SelectQuestLogEntry(entry_index);
jcallahan@36 1253
jcallahan@36 1254 local quest = DBEntry("quests", quest_id)
jcallahan@36 1255 quest.timer = _G.GetQuestLogTimeLeft()
jcallahan@37 1256 quest.can_share = _G.GetQuestLogPushable() and true or nil
jcallahan@36 1257 processed_quests = processed_quests + 1
jcallahan@36 1258 end
jcallahan@36 1259 entry_index = entry_index + 1
jcallahan@36 1260 end
jcallahan@36 1261 _G.SelectQuestLogEntry(selected_quest)
jcallahan@4 1262 self:UnregisterEvent("QUEST_LOG_UPDATE")
jcallahan@4 1263 end
jcallahan@4 1264
jcallahan@4 1265
jcallahan@4 1266 function WDP:UNIT_QUEST_LOG_CHANGED(event, unit_id)
jcallahan@4 1267 if unit_id ~= "player" then
jcallahan@4 1268 return
jcallahan@4 1269 end
jcallahan@4 1270 self:RegisterEvent("QUEST_LOG_UPDATE")
jcallahan@4 1271 end
jcallahan@4 1272
jcallahan@4 1273
jcallahan@27 1274 function WDP:TRAINER_SHOW()
jcallahan@34 1275 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
jcallahan@29 1276 local npc = NPCEntry(unit_idnum)
jcallahan@58 1277
jcallahan@58 1278 if not npc then
jcallahan@58 1279 return
jcallahan@58 1280 end
jcallahan@27 1281 npc.teaches = npc.teaches or {}
jcallahan@27 1282
jcallahan@27 1283 -- Get the initial trainer filters
jcallahan@27 1284 local available = _G.GetTrainerServiceTypeFilter("available")
jcallahan@27 1285 local unavailable = _G.GetTrainerServiceTypeFilter("unavailable")
jcallahan@27 1286 local used = _G.GetTrainerServiceTypeFilter("used")
jcallahan@27 1287
jcallahan@27 1288 -- Clear the trainer filters
jcallahan@27 1289 _G.SetTrainerServiceTypeFilter("available", 1)
jcallahan@27 1290 _G.SetTrainerServiceTypeFilter("unavailable", 1)
jcallahan@27 1291 _G.SetTrainerServiceTypeFilter("used", 1)
jcallahan@27 1292
jcallahan@27 1293 for index = 1, _G.GetNumTrainerServices(), 1 do
jcallahan@27 1294 local spell_name, rank_name, _, _, required_level = _G.GetTrainerServiceInfo(index)
jcallahan@27 1295
jcallahan@27 1296 if spell_name then
jcallahan@27 1297 DatamineTT:ClearLines()
jcallahan@27 1298 DatamineTT:SetTrainerService(index)
jcallahan@27 1299
jcallahan@27 1300 local _, _, spell_id = DatamineTT:GetSpell()
jcallahan@27 1301
jcallahan@43 1302 if spell_id then
jcallahan@43 1303 local profession, min_skill = _G.GetTrainerServiceSkillReq(index)
jcallahan@43 1304 profession = profession or "General"
jcallahan@43 1305
jcallahan@43 1306 local class_professions = npc.teaches[PLAYER_CLASS]
jcallahan@43 1307 if not class_professions then
jcallahan@43 1308 npc.teaches[PLAYER_CLASS] = {}
jcallahan@43 1309 class_professions = npc.teaches[PLAYER_CLASS]
jcallahan@43 1310 end
jcallahan@43 1311
jcallahan@43 1312 local profession_skills = class_professions[profession]
jcallahan@43 1313 if not profession_skills then
jcallahan@43 1314 class_professions[profession] = {}
jcallahan@43 1315 profession_skills = class_professions[profession]
jcallahan@43 1316 end
jcallahan@43 1317 profession_skills[spell_id] = ("%d:%d"):format(required_level, min_skill)
jcallahan@27 1318 end
jcallahan@27 1319 end
jcallahan@27 1320 end
jcallahan@27 1321
jcallahan@27 1322 -- Reset the filters to what they were before
jcallahan@27 1323 _G.SetTrainerServiceTypeFilter("available", available or 0)
jcallahan@27 1324 _G.SetTrainerServiceTypeFilter("unavailable", unavailable or 0)
jcallahan@27 1325 _G.SetTrainerServiceTypeFilter("used", used or 0)
jcallahan@27 1326 end
jcallahan@27 1327
jcallahan@27 1328
jcallahan@1 1329 function WDP:UNIT_SPELLCAST_SENT(event_name, unit_id, spell_name, spell_rank, target_name, spell_line)
jcallahan@1 1330 if private.tracked_line or unit_id ~= "player" then
jcallahan@1 1331 return
jcallahan@1 1332 end
jcallahan@1 1333 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name]
jcallahan@1 1334
jcallahan@1 1335 if not spell_label then
jcallahan@1 1336 return
jcallahan@1 1337 end
jcallahan@18 1338 table.wipe(action_data)
jcallahan@1 1339
jcallahan@1 1340 local tt_item_name, tt_item_link = _G.GameTooltip:GetItem()
jcallahan@1 1341 local tt_unit_name, tt_unit_id = _G.GameTooltip:GetUnit()
jcallahan@1 1342
jcallahan@1 1343 if not tt_unit_name and _G.UnitName("target") == target_name then
jcallahan@1 1344 tt_unit_name = target_name
jcallahan@1 1345 tt_unit_id = "target"
jcallahan@1 1346 end
jcallahan@1 1347 local spell_flags = private.SPELL_FLAGS_BY_LABEL[spell_label]
jcallahan@28 1348 local zone_name, area_id, x, y, map_level, instance_token = CurrentLocationData()
jcallahan@28 1349
jcallahan@28 1350 action_data.instance_token = instance_token
jcallahan@28 1351 action_data.map_level = map_level
jcallahan@28 1352 action_data.x = x
jcallahan@28 1353 action_data.y = y
jcallahan@28 1354 action_data.zone = ("%s:%d"):format(zone_name, area_id)
jcallahan@76 1355 action_data.spell_label = spell_label
jcallahan@76 1356 action_data.label = spell_label:lower()
jcallahan@1 1357
jcallahan@16 1358 if tt_unit_name and not tt_item_name then
jcallahan@16 1359 if bit.band(spell_flags, AF.NPC) == AF.NPC then
jcallahan@16 1360 if not tt_unit_id or tt_unit_name ~= target_name then
jcallahan@16 1361 return
jcallahan@16 1362 end
jcallahan@16 1363 action_data.type = AF.NPC
jcallahan@25 1364 action_data.unit_name = tt_unit_name
jcallahan@16 1365 end
jcallahan@16 1366 elseif bit.band(spell_flags, AF.ITEM) == AF.ITEM then
jcallahan@16 1367 action_data.type = AF.ITEM
jcallahan@16 1368
jcallahan@16 1369 if tt_item_name and tt_item_name == target_name then
jcallahan@28 1370 action_data.identifier = ItemLinkToID(tt_item_link)
jcallahan@16 1371 elseif target_name and target_name ~= "" then
jcallahan@16 1372 local _, target_item_link = _G.GetItemInfo(target_name)
jcallahan@28 1373 action_data.identifier = ItemLinkToID(target_item_link)
jcallahan@16 1374 end
jcallahan@16 1375 elseif not tt_item_name and not tt_unit_name then
jcallahan@17 1376 action_data.name = target_name
jcallahan@17 1377
jcallahan@1 1378 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then
jcallahan@17 1379 if target_name == "" then
jcallahan@17 1380 return
jcallahan@17 1381 end
jcallahan@82 1382 action_data.target_name = target_name
jcallahan@1 1383 action_data.type = AF.OBJECT
jcallahan@1 1384 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then
jcallahan@38 1385 local identifier = ("%s:%s"):format(spell_label, _G["GameTooltipTextLeft1"]:GetText() or "NONE") -- Possible fishing pool name.
jcallahan@52 1386 action_data.zone_data = UpdateDBEntryLocation("zones", identifier)
jcallahan@17 1387 action_data.type = AF.ZONE
jcallahan@38 1388 action_data.identifier = identifier
jcallahan@1 1389 end
jcallahan@1 1390 end
jcallahan@1 1391 private.tracked_line = spell_line
jcallahan@0 1392 end
jcallahan@0 1393
jcallahan@0 1394
jcallahan@1 1395 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
jcallahan@1 1396 if unit_id ~= "player" then
jcallahan@1 1397 return
jcallahan@1 1398 end
jcallahan@1 1399 private.tracked_line = nil
jcallahan@0 1400 end
jcallahan@0 1401
jcallahan@1 1402 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
jcallahan@1 1403 if unit_id ~= "player" then
jcallahan@1 1404 return
jcallahan@1 1405 end
jcallahan@0 1406
jcallahan@1 1407 if private.tracked_line == spell_line then
jcallahan@1 1408 private.tracked_line = nil
jcallahan@1 1409 end
jcallahan@0 1410 end