annotate Main.lua @ 13:39972835bdc9

Added proper support for Herbalism and Mining from NPC corpses. Wipe action_data when LOOT_CLOSED fires.
author James D. Callahan III <jcallahan@curse.com>
date Tue, 01 May 2012 16:07:13 -0500
parents be3d67c28a27
children 27c153c3a1ed
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@0 13
jcallahan@0 14 -----------------------------------------------------------------------
jcallahan@0 15 -- AddOn namespace.
jcallahan@0 16 -----------------------------------------------------------------------
jcallahan@0 17 local ADDON_NAME, private = ...
jcallahan@0 18
jcallahan@0 19 local LibStub = _G.LibStub
jcallahan@0 20 local WDP = LibStub("AceAddon-3.0"):NewAddon(ADDON_NAME, "AceEvent-3.0", "AceTimer-3.0")
jcallahan@0 21
jcallahan@4 22 local DatamineTT = _G.CreateFrame("GameTooltip", "WDPDatamineTT", _G.UIParent, "GameTooltipTemplate")
jcallahan@5 23 DatamineTT:SetOwner(_G.WorldFrame, "ANCHOR_NONE")
jcallahan@5 24
jcallahan@0 25
jcallahan@0 26 -----------------------------------------------------------------------
jcallahan@0 27 -- Local constants.
jcallahan@0 28 -----------------------------------------------------------------------
jcallahan@0 29 local DATABASE_DEFAULTS = {
jcallahan@0 30 global = {
jcallahan@0 31 items = {},
jcallahan@0 32 npcs = {},
jcallahan@0 33 objects = {},
jcallahan@0 34 quests = {},
jcallahan@0 35 }
jcallahan@0 36 }
jcallahan@0 37
jcallahan@0 38
jcallahan@1 39 local EVENT_MAPPING = {
jcallahan@13 40 LOOT_CLOSED = true,
jcallahan@1 41 LOOT_OPENED = true,
jcallahan@7 42 MERCHANT_SHOW = "UpdateMerchantItems",
jcallahan@7 43 MERCHANT_UPDATE = "UpdateMerchantItems",
jcallahan@2 44 PLAYER_TARGET_CHANGED = true,
jcallahan@9 45 QUEST_COMPLETE = true,
jcallahan@9 46 QUEST_DETAIL = true,
jcallahan@9 47 QUEST_LOG_UPDATE = true,
jcallahan@9 48 QUEST_PROGRESS = true,
jcallahan@4 49 UNIT_QUEST_LOG_CHANGED = true,
jcallahan@1 50 UNIT_SPELLCAST_FAILED = "HandleSpellFailure",
jcallahan@1 51 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure",
jcallahan@1 52 UNIT_SPELLCAST_INTERRUPTED = "HandleSpellFailure",
jcallahan@1 53 UNIT_SPELLCAST_SENT = true,
jcallahan@1 54 UNIT_SPELLCAST_SUCCEEDED = true,
jcallahan@0 55 }
jcallahan@0 56
jcallahan@4 57
jcallahan@1 58 local AF = private.ACTION_TYPE_FLAGS
jcallahan@0 59
jcallahan@4 60
jcallahan@0 61 -----------------------------------------------------------------------
jcallahan@0 62 -- Local variables.
jcallahan@0 63 -----------------------------------------------------------------------
jcallahan@0 64 local db
jcallahan@0 65 local durability_timer_handle
jcallahan@2 66 local target_location_timer_handle
jcallahan@1 67 local action_data = {}
jcallahan@0 68
jcallahan@1 69
jcallahan@1 70 -----------------------------------------------------------------------
jcallahan@1 71 -- Helper Functions.
jcallahan@1 72 -----------------------------------------------------------------------
jcallahan@10 73 local function UnitEntry(unit_type, unit_id)
jcallahan@10 74 if not unit_type or not unit_id then
jcallahan@6 75 return
jcallahan@6 76 end
jcallahan@10 77 local unit = db[unit_type][unit_id]
jcallahan@6 78
jcallahan@10 79 if not unit then
jcallahan@10 80 db[unit_type][unit_id] = {}
jcallahan@10 81 unit = db[unit_type][unit_id]
jcallahan@6 82 end
jcallahan@10 83 return unit
jcallahan@6 84 end
jcallahan@6 85
jcallahan@6 86
jcallahan@1 87 local function CurrentLocationData()
jcallahan@1 88 local map_level = _G.GetCurrentMapDungeonLevel() or 0
jcallahan@1 89 local x, y = _G.GetPlayerMapPosition("player")
jcallahan@1 90
jcallahan@1 91 x = x or 0
jcallahan@1 92 y = y or 0
jcallahan@1 93
jcallahan@1 94 if x == 0 and y == 0 then
jcallahan@1 95 for level_index = 1, _G.GetNumDungeonMapLevels() do
jcallahan@1 96 _G.SetDungeonMapLevel(level_index)
jcallahan@1 97 x, y = _G.GetPlayerMapPosition("player")
jcallahan@1 98
jcallahan@1 99 if x and y and (x > 0 or y > 0) then
jcallahan@1 100 _G.SetDungeonMapLevel(map_level)
jcallahan@1 101 map_level = level_index
jcallahan@1 102 break
jcallahan@1 103 end
jcallahan@1 104 end
jcallahan@1 105 end
jcallahan@1 106
jcallahan@1 107 if _G.DungeonUsesTerrainMap() then
jcallahan@1 108 map_level = map_level - 1
jcallahan@1 109 end
jcallahan@8 110 local _, instance_type = _G.IsInInstance()
jcallahan@8 111 return _G.GetRealZoneText(), ("%.2f"):format(x * 100), ("%.2f"):format(y * 100), map_level or 0, instance_type:upper()
jcallahan@1 112 end
jcallahan@1 113
jcallahan@1 114
jcallahan@1 115 local function ItemLinkToID(item_link)
jcallahan@1 116 if not item_link then
jcallahan@1 117 return
jcallahan@1 118 end
jcallahan@7 119 return tonumber(item_link:match("item:(%d+)"))
jcallahan@1 120 end
jcallahan@0 121
jcallahan@4 122
jcallahan@4 123 do
jcallahan@4 124 local UNIT_TYPE_BITMASK = 0x007
jcallahan@4 125
jcallahan@4 126 function WDP:ParseGUID(guid)
jcallahan@5 127 if not guid then
jcallahan@5 128 return
jcallahan@5 129 end
jcallahan@4 130 local types = private.UNIT_TYPES
jcallahan@4 131 local unit_type = _G.bit.band(tonumber(guid:sub(1, 5)), UNIT_TYPE_BITMASK)
jcallahan@4 132
jcallahan@10 133 if unit_type ~= types.PLAYER and unit_type ~= types.PET then
jcallahan@4 134 return unit_type, tonumber(guid:sub(-12, -9), 16)
jcallahan@4 135 end
jcallahan@4 136
jcallahan@4 137 return unit_type
jcallahan@4 138 end
jcallahan@4 139 end -- do-block
jcallahan@4 140
jcallahan@4 141
jcallahan@10 142 local function UpdateObjectLocation(identifier)
jcallahan@10 143 if not identifier then
jcallahan@10 144 return
jcallahan@10 145 end
jcallahan@10 146 local zone_name, x, y, map_level, instance_type = CurrentLocationData()
jcallahan@10 147 local object = UnitEntry("objects", identifier)
jcallahan@11 148 object.locations = object.locations or {}
jcallahan@10 149
jcallahan@11 150 if not object.locations[zone_name] then
jcallahan@11 151 object.locations[zone_name] = {}
jcallahan@10 152 end
jcallahan@11 153 object.locations[zone_name][("%s:%s:%s:%s"):format(instance_type, map_level, x, y)] = true
jcallahan@10 154 end
jcallahan@10 155
jcallahan@10 156
jcallahan@0 157 -----------------------------------------------------------------------
jcallahan@0 158 -- Methods.
jcallahan@0 159 -----------------------------------------------------------------------
jcallahan@0 160 function WDP:OnInitialize()
jcallahan@0 161 db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default").global
jcallahan@0 162 end
jcallahan@0 163
jcallahan@0 164
jcallahan@0 165 function WDP:OnEnable()
jcallahan@0 166 for event_name, mapping in pairs(EVENT_MAPPING) do
jcallahan@1 167 self:RegisterEvent(event_name, (_G.type(mapping) ~= "boolean") and mapping or nil)
jcallahan@0 168 end
jcallahan@0 169 durability_timer_handle = self:ScheduleRepeatingTimer("ProcessDurability", 30)
jcallahan@2 170 target_location_timer_handle = self:ScheduleRepeatingTimer("UpdateTargetLocation", 0.2)
jcallahan@0 171 end
jcallahan@0 172
jcallahan@0 173
jcallahan@0 174 local function RecordDurability(item_id, durability)
jcallahan@0 175 if not durability or durability <= 0 then
jcallahan@0 176 return
jcallahan@0 177 end
jcallahan@0 178
jcallahan@0 179 if not db.items[item_id] then
jcallahan@0 180 db.items[item_id] = {}
jcallahan@0 181 end
jcallahan@0 182 db.items[item_id].durability = durability
jcallahan@0 183 end
jcallahan@0 184
jcallahan@0 185
jcallahan@0 186 function WDP:ProcessDurability()
jcallahan@0 187 for slot_index = 0, _G.INVSLOT_LAST_EQUIPPED do
jcallahan@1 188 local item_id = _G.GetInventoryItemID("player", slot_index)
jcallahan@0 189
jcallahan@0 190 if item_id and item_id > 0 then
jcallahan@1 191 local _, max_durability = _G.GetInventoryItemDurability(slot_index)
jcallahan@0 192 RecordDurability(item_id, max_durability)
jcallahan@0 193 end
jcallahan@0 194 end
jcallahan@0 195
jcallahan@0 196 for bag_index = 0, _G.NUM_BAG_SLOTS do
jcallahan@0 197 for slot_index = 1, _G.GetContainerNumSlots(bag_index) do
jcallahan@1 198 local item_id = _G.GetContainerItemID(bag_index, slot_index)
jcallahan@0 199
jcallahan@0 200 if item_id and item_id > 0 then
jcallahan@1 201 local _, max_durability = _G.GetContainerItemDurability(bag_index, slot_index)
jcallahan@0 202 RecordDurability(item_id, max_durability)
jcallahan@0 203 end
jcallahan@0 204 end
jcallahan@0 205 end
jcallahan@0 206 end
jcallahan@0 207
jcallahan@0 208
jcallahan@2 209 function WDP:UpdateTargetLocation()
jcallahan@2 210 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or _G.UnitIsTapped("target") then
jcallahan@2 211 return
jcallahan@2 212 end
jcallahan@2 213
jcallahan@2 214 for index = 1, 4 do
jcallahan@2 215 if not _G.CheckInteractDistance("target", index) then
jcallahan@2 216 return
jcallahan@2 217 end
jcallahan@2 218 end
jcallahan@2 219
jcallahan@2 220 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
jcallahan@2 221
jcallahan@2 222 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
jcallahan@2 223 return
jcallahan@2 224 end
jcallahan@8 225 local zone_name, x, y, map_level, instance_type = CurrentLocationData()
jcallahan@10 226 local npc_data = UnitEntry("npcs", unit_idnum).stats[("level_%d"):format(_G.UnitLevel("target"))]
jcallahan@6 227 npc_data.locations = npc_data.locations or {}
jcallahan@2 228
jcallahan@2 229 if not npc_data.locations[zone_name] then
jcallahan@2 230 npc_data.locations[zone_name] = {}
jcallahan@2 231 end
jcallahan@8 232 npc_data.locations[zone_name][("%s:%s:%s:%s"):format(instance_type, map_level, x, y)] = true
jcallahan@2 233 end
jcallahan@2 234
jcallahan@2 235
jcallahan@0 236 -----------------------------------------------------------------------
jcallahan@0 237 -- Event handlers.
jcallahan@0 238 -----------------------------------------------------------------------
jcallahan@13 239 function WDP:LOOT_CLOSED()
jcallahan@13 240 table.wipe(action_data)
jcallahan@0 241 end
jcallahan@0 242
jcallahan@0 243
jcallahan@13 244 do
jcallahan@13 245 local re_gold = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)")
jcallahan@13 246 local re_silver = _G.SILVER_AMOUNT:gsub("%%d", "(%%d+)")
jcallahan@13 247 local re_copper = _G.COPPER_AMOUNT:gsub("%%d", "(%%d+)")
jcallahan@13 248
jcallahan@13 249
jcallahan@13 250 local function _moneyMatch(money, re)
jcallahan@13 251 return money:match(re) or 0
jcallahan@1 252 end
jcallahan@1 253
jcallahan@0 254
jcallahan@13 255 local function _toCopper(money)
jcallahan@13 256 if not money then
jcallahan@13 257 return 0
jcallahan@13 258 end
jcallahan@0 259
jcallahan@13 260 return _moneyMatch(money, re_gold) * 10000 + _moneyMatch(money, re_silver) * 100 + _moneyMatch(money, re_copper)
jcallahan@1 261 end
jcallahan@1 262
jcallahan@1 263
jcallahan@13 264 local LOOT_VERIFY_FUNCS = {
jcallahan@13 265 [AF.NPC] = function()
jcallahan@13 266 local fishing_loot = _G.IsFishingLoot()
jcallahan@1 267
jcallahan@13 268 if not fishing_loot and _G.UnitExists("target") and not _G.UnitIsFriend("player", "target") and _G.UnitIsDead("target") then
jcallahan@13 269 if _G.UnitIsPlayer("target") or _G.UnitPlayerControlled("target") then
jcallahan@13 270 return false
jcallahan@13 271 end
jcallahan@13 272 local unit_type, id_num = WDP:ParseGUID(_G.UnitGUID("target"))
jcallahan@13 273 action_data.id_num = id_num
jcallahan@13 274 end
jcallahan@13 275 return true
jcallahan@13 276 end,
jcallahan@13 277 [AF.OBJECT] = function()
jcallahan@13 278 return true
jcallahan@13 279 end,
jcallahan@13 280 }
jcallahan@13 281
jcallahan@13 282
jcallahan@13 283 local LOOT_UPDATE_FUNCS = {
jcallahan@13 284 [AF.NPC] = function()
jcallahan@13 285 local npc = UnitEntry("npcs", action_data.id_num)
jcallahan@13 286 local loot_type = action_data.loot_type or "drops"
jcallahan@13 287 npc[loot_type] = npc[loot_type] or {}
jcallahan@13 288
jcallahan@13 289 for index = 1, #action_data.drops do
jcallahan@13 290 table.insert(npc[loot_type], action_data.drops[index])
jcallahan@13 291 end
jcallahan@13 292 end,
jcallahan@13 293 [AF.OBJECT] = function()
jcallahan@13 294 local object = UnitEntry("objects", action_data.identifier)
jcallahan@13 295 object.drops = object.drops or {}
jcallahan@13 296
jcallahan@13 297 for index = 1, #action_data.drops do
jcallahan@13 298 table.insert(object.drops, action_data.drops[index])
jcallahan@13 299 end
jcallahan@13 300 end,
jcallahan@13 301 }
jcallahan@13 302
jcallahan@13 303
jcallahan@13 304 function WDP:LOOT_OPENED()
jcallahan@13 305 if not action_data.type then
jcallahan@13 306 action_data.type = AF.NPC
jcallahan@1 307 end
jcallahan@13 308 local verify_func = LOOT_VERIFY_FUNCS[action_data.type]
jcallahan@13 309 local update_func = LOOT_UPDATE_FUNCS[action_data.type]
jcallahan@13 310
jcallahan@13 311 if not verify_func or not update_func or not verify_func() then
jcallahan@13 312 return
jcallahan@13 313 end
jcallahan@13 314
jcallahan@13 315 local loot_registry = {}
jcallahan@13 316 action_data.drops = {}
jcallahan@13 317
jcallahan@13 318 for loot_slot = 1, _G.GetNumLootItems() do
jcallahan@13 319 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
jcallahan@13 320
jcallahan@13 321 if _G.LootSlotIsItem(loot_slot) then
jcallahan@13 322 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
jcallahan@13 323 loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity
jcallahan@13 324 elseif _G.LootSlotIsCoin(loot_slot) then
jcallahan@13 325 table.insert(action_data.drops, ("money:%d"):format(_toCopper(item_text)))
jcallahan@13 326 elseif _G.LootSlotIsCurrency(loot_slot) then
jcallahan@13 327 table.insert(action_data.drops, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
jcallahan@13 328 end
jcallahan@13 329 end
jcallahan@13 330
jcallahan@13 331 for item_id, quantity in pairs(loot_registry) do
jcallahan@13 332 table.insert(action_data.drops, ("%d:%d"):format(item_id, quantity))
jcallahan@13 333 end
jcallahan@13 334 update_func()
jcallahan@1 335 end
jcallahan@13 336 end -- do-block
jcallahan@0 337
jcallahan@0 338
jcallahan@5 339 local POINT_MATCH_PATTERNS = {
jcallahan@5 340 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING:gsub("%%d", "(%%d+)")), -- May no longer be necessary
jcallahan@5 341 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3:gsub("%%d", "(%%d+)")), -- May no longer be necessary
jcallahan@5 342 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_5V5:gsub("%%d", "(%%d+)")), -- May no longer be necessary
jcallahan@5 343 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_BG:gsub("%%d", "(%%d+)")),
jcallahan@5 344 ("^%s$"):format(_G.ITEM_REQ_ARENA_RATING_3V3_BG:gsub("%%d", "(%%d+)")),
jcallahan@5 345 }
jcallahan@5 346
jcallahan@5 347
jcallahan@7 348 function WDP:UpdateMerchantItems()
jcallahan@4 349 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
jcallahan@4 350
jcallahan@4 351 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
jcallahan@4 352 return
jcallahan@4 353 end
jcallahan@10 354 local merchant = UnitEntry("npcs", unit_idnum)
jcallahan@6 355 merchant.sells = merchant.sells or {}
jcallahan@5 356
jcallahan@5 357 for item_index = 1, _G.GetMerchantNumItems() do
jcallahan@5 358 local _, _, copper_price, stack_size, num_available, _, extended_cost = _G.GetMerchantItemInfo(item_index)
jcallahan@5 359 local item_id = ItemLinkToID(_G.GetMerchantItemLink(item_index))
jcallahan@5 360
jcallahan@5 361 if item_id and item_id > 0 then
jcallahan@5 362 local price_string = copper_price
jcallahan@5 363
jcallahan@5 364 if extended_cost then
jcallahan@5 365 local bg_points = 0
jcallahan@5 366 local personal_points = 0
jcallahan@5 367
jcallahan@5 368 DatamineTT:ClearLines()
jcallahan@5 369 DatamineTT:SetMerchantItem(item_index)
jcallahan@5 370
jcallahan@5 371 for line_index = 1, DatamineTT:NumLines() do
jcallahan@5 372 local current_line = _G["WDPDatamineTTTextLeft" .. line_index]
jcallahan@5 373
jcallahan@5 374 if not current_line then
jcallahan@5 375 break
jcallahan@5 376 end
jcallahan@5 377 local breakout
jcallahan@5 378
jcallahan@5 379 for match_index = 1, #POINT_MATCH_PATTERNS do
jcallahan@5 380 local match1, match2 = current_line:GetText():match(POINT_MATCH_PATTERNS[match_index])
jcallahan@5 381 personal_points = personal_points + (match1 or 0)
jcallahan@5 382 bg_points = bg_points + (match2 or 0)
jcallahan@5 383
jcallahan@5 384 if match1 or match2 then
jcallahan@5 385 breakout = true
jcallahan@5 386 break
jcallahan@5 387 end
jcallahan@5 388 end
jcallahan@5 389
jcallahan@5 390 if breakout then
jcallahan@5 391 break
jcallahan@5 392 end
jcallahan@5 393 end
jcallahan@5 394 local currency_list = {}
jcallahan@5 395
jcallahan@5 396 price_string = ("%s:%s:%s"):format(price_string, bg_points, personal_points)
jcallahan@5 397
jcallahan@5 398 for cost_index = 1, _G.GetMerchantItemCostInfo(item_index) do
jcallahan@5 399 local icon_texture, amount_required, currency_link = _G.GetMerchantItemCostItem(item_index, cost_index)
jcallahan@5 400 local currency_id = currency_link and ItemLinkToID(currency_link) or nil
jcallahan@5 401
jcallahan@5 402 if not currency_id or currency_id < 1 then
jcallahan@5 403 if not icon_texture then
jcallahan@5 404 return
jcallahan@5 405 end
jcallahan@5 406 currency_id = icon_texture:match("[^\\]+$"):lower()
jcallahan@5 407 end
jcallahan@5 408 currency_list[#currency_list + 1] = ("(%s:%s)"):format(amount_required, currency_id)
jcallahan@5 409 end
jcallahan@5 410
jcallahan@5 411 for currency_index = 1, #currency_list do
jcallahan@5 412 price_string = ("%s:%s"):format(price_string, currency_list[currency_index])
jcallahan@5 413 end
jcallahan@5 414 end
jcallahan@6 415 merchant.sells[("%s:%s:[%s]"):format(item_id, stack_size, price_string)] = num_available
jcallahan@5 416 end
jcallahan@4 417 end
jcallahan@4 418 end
jcallahan@4 419
jcallahan@4 420
jcallahan@2 421 local GENDER_NAMES = {
jcallahan@2 422 "UNKNOWN",
jcallahan@2 423 "MALE",
jcallahan@2 424 "FEMALE",
jcallahan@2 425 }
jcallahan@2 426
jcallahan@2 427
jcallahan@2 428 local REACTION_NAMES = {
jcallahan@2 429 "HATED",
jcallahan@2 430 "HOSTILE",
jcallahan@2 431 "UNFRIENDLY",
jcallahan@2 432 "NEUTRAL",
jcallahan@2 433 "FRIENDLY",
jcallahan@2 434 "HONORED",
jcallahan@2 435 "REVERED",
jcallahan@2 436 "EXALTED",
jcallahan@2 437 }
jcallahan@2 438
jcallahan@2 439
jcallahan@2 440 local POWER_TYPE_NAMES = {
jcallahan@2 441 ["0"] = "MANA",
jcallahan@2 442 ["1"] = "RAGE",
jcallahan@2 443 ["2"] = "FOCUS",
jcallahan@2 444 ["3"] = "ENERGY",
jcallahan@2 445 ["6"] = "RUNIC_POWER",
jcallahan@2 446 }
jcallahan@2 447
jcallahan@2 448
jcallahan@2 449 function WDP:PLAYER_TARGET_CHANGED()
jcallahan@2 450 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") then
jcallahan@2 451 return
jcallahan@2 452 end
jcallahan@2 453 local unit_type, unit_idnum = self:ParseGUID(_G.UnitGUID("target"))
jcallahan@2 454
jcallahan@2 455 if unit_type ~= private.UNIT_TYPES.NPC or not unit_idnum then
jcallahan@2 456 return
jcallahan@2 457 end
jcallahan@10 458 local npc = UnitEntry("npcs", unit_idnum)
jcallahan@2 459 local _, class_token = _G.UnitClass("target")
jcallahan@2 460 npc.class = class_token
jcallahan@2 461 -- TODO: Add faction here
jcallahan@2 462 npc.gender = GENDER_NAMES[_G.UnitSex("target")] or "UNDEFINED"
jcallahan@3 463 npc.is_pvp = _G.UnitIsPVP("target") and true or nil
jcallahan@2 464 npc.reaction = ("%s:%s:%s"):format(_G.UnitLevel("player"), _G.UnitFactionGroup("player"), REACTION_NAMES[_G.UnitReaction("player", "target")])
jcallahan@2 465 npc.stats = npc.stats or {}
jcallahan@2 466
jcallahan@2 467 local npc_level = ("level_%d"):format(_G.UnitLevel("target"))
jcallahan@2 468
jcallahan@2 469 if not npc.stats[npc_level] then
jcallahan@2 470 npc.stats[npc_level] = {
jcallahan@2 471 max_health = _G.UnitHealthMax("target"),
jcallahan@2 472 }
jcallahan@3 473
jcallahan@3 474 local max_power = _G.UnitManaMax("target")
jcallahan@3 475
jcallahan@3 476 if max_power > 0 then
jcallahan@3 477 local power_type = _G.UnitPowerType("target")
jcallahan@3 478 npc.stats[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power)
jcallahan@3 479 end
jcallahan@2 480 end
jcallahan@2 481 end
jcallahan@2 482
jcallahan@2 483
jcallahan@12 484 do
jcallahan@12 485 local function UpdateQuestJuncture(point)
jcallahan@12 486 local unit_name = _G.UnitName("questnpc")
jcallahan@9 487
jcallahan@12 488 if not unit_name then
jcallahan@12 489 return
jcallahan@12 490 end
jcallahan@12 491 local unit_type, unit_id = WDP:ParseGUID(_G.UnitGUID("questnpc"))
jcallahan@9 492
jcallahan@12 493 if unit_type == private.UNIT_TYPES.OBJECT then
jcallahan@12 494 UpdateObjectLocation(unit_id)
jcallahan@12 495 end
jcallahan@12 496 local quest = UnitEntry("quests", _G.GetQuestID())
jcallahan@12 497 quest[point] = quest[point] or {}
jcallahan@12 498 quest[point][("%s:%d"):format(private.UNIT_TYPE_NAMES[unit_type + 1], unit_id)] = true
jcallahan@12 499 end
jcallahan@10 500
jcallahan@12 501
jcallahan@12 502 function WDP:QUEST_COMPLETE()
jcallahan@12 503 UpdateQuestJuncture("end")
jcallahan@10 504 end
jcallahan@10 505
jcallahan@12 506
jcallahan@12 507 function WDP:QUEST_DETAIL()
jcallahan@12 508 UpdateQuestJuncture("begin")
jcallahan@10 509 end
jcallahan@12 510 end -- do-block
jcallahan@9 511
jcallahan@9 512
jcallahan@4 513 function WDP:QUEST_LOG_UPDATE()
jcallahan@4 514 self:UnregisterEvent("QUEST_LOG_UPDATE")
jcallahan@4 515 end
jcallahan@4 516
jcallahan@4 517
jcallahan@9 518 function WDP:QUEST_PROGRESS()
jcallahan@9 519 end
jcallahan@9 520
jcallahan@4 521 function WDP:UNIT_QUEST_LOG_CHANGED(event, unit_id)
jcallahan@4 522 if unit_id ~= "player" then
jcallahan@4 523 return
jcallahan@4 524 end
jcallahan@4 525 self:RegisterEvent("QUEST_LOG_UPDATE")
jcallahan@4 526 end
jcallahan@4 527
jcallahan@4 528
jcallahan@1 529 function WDP:UNIT_SPELLCAST_SENT(event_name, unit_id, spell_name, spell_rank, target_name, spell_line)
jcallahan@1 530 if private.tracked_line or unit_id ~= "player" then
jcallahan@1 531 return
jcallahan@1 532 end
jcallahan@1 533 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name]
jcallahan@1 534
jcallahan@1 535 if not spell_label then
jcallahan@1 536 return
jcallahan@1 537 end
jcallahan@1 538 action_data.type = nil -- This will be set as appropriate below
jcallahan@1 539
jcallahan@1 540 local tt_item_name, tt_item_link = _G.GameTooltip:GetItem()
jcallahan@1 541 local tt_unit_name, tt_unit_id = _G.GameTooltip:GetUnit()
jcallahan@1 542
jcallahan@1 543 if not tt_unit_name and _G.UnitName("target") == target_name then
jcallahan@1 544 tt_unit_name = target_name
jcallahan@1 545 tt_unit_id = "target"
jcallahan@1 546 end
jcallahan@1 547 local spell_flags = private.SPELL_FLAGS_BY_LABEL[spell_label]
jcallahan@1 548
jcallahan@1 549 if not tt_item_name and not tt_unit_name then
jcallahan@1 550 if target_name == "" then
jcallahan@1 551 return
jcallahan@1 552 end
jcallahan@1 553
jcallahan@8 554 local zone_name, x, y, map_level, instance_type = CurrentLocationData()
jcallahan@1 555
jcallahan@1 556 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then
jcallahan@11 557 local identifier = ("%s:%s"):format(spell_label, target_name)
jcallahan@11 558 UpdateObjectLocation(identifier)
jcallahan@11 559
jcallahan@8 560 action_data.instance_type = instance_type
jcallahan@1 561 action_data.map_level = map_level
jcallahan@1 562 action_data.name = target_name
jcallahan@1 563 action_data.type = AF.OBJECT
jcallahan@1 564 action_data.x = x
jcallahan@1 565 action_data.y = y
jcallahan@1 566 action_data.zone = zone_name
jcallahan@11 567 action_data.identifier = identifier
jcallahan@1 568 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then
jcallahan@1 569 print("Found spell flagged for ZONE")
jcallahan@1 570 end
jcallahan@1 571 elseif tt_unit_name and not tt_item_name then
jcallahan@1 572 if bit.band(spell_flags, AF.NPC) == AF.NPC then
jcallahan@13 573 if not tt_unit_id or tt_unit_name ~= target_name then
jcallahan@13 574 return
jcallahan@13 575 end
jcallahan@13 576 action_data.type = AF.NPC
jcallahan@13 577 action_data.loot_type = spell_label:lower()
jcallahan@1 578 end
jcallahan@1 579 elseif bit.band(spell_flags, AF.ITEM) == AF.ITEM then
jcallahan@1 580 print("Found spell flagged for ITEM")
jcallahan@1 581 else
jcallahan@1 582 print(("%s: We have an issue with types and flags."), event_name)
jcallahan@1 583 end
jcallahan@1 584
jcallahan@1 585 print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, target_name, spell_line))
jcallahan@1 586 private.tracked_line = spell_line
jcallahan@0 587 end
jcallahan@0 588
jcallahan@0 589
jcallahan@1 590 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
jcallahan@1 591 if unit_id ~= "player" then
jcallahan@1 592 return
jcallahan@1 593 end
jcallahan@1 594
jcallahan@1 595 if private.SPELL_LABELS_BY_NAME[spell_name] then
jcallahan@1 596 print(("%s: '%s', '%s', '%s', '%s', '%s'"):format(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id))
jcallahan@1 597 end
jcallahan@1 598 private.tracked_line = nil
jcallahan@0 599 end
jcallahan@0 600
jcallahan@1 601 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
jcallahan@1 602 if unit_id ~= "player" then
jcallahan@1 603 return
jcallahan@1 604 end
jcallahan@0 605
jcallahan@1 606 if private.tracked_line == spell_line then
jcallahan@1 607 private.tracked_line = nil
jcallahan@1 608 end
jcallahan@0 609 end