PageRenderTime 29ms CodeModel.GetById 12ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

/modules/loot.lua

https://code.google.com/
Lua | 106 lines | 90 code | 16 blank | 0 comment | 7 complexity | 98fe18af6a8b665ef88f9ddf64ec438c MD5 | raw file
  1local mod = EPGP:NewModule("loot", "AceEvent-3.0")
  2
  3local L = LibStub("AceLocale-3.0"):GetLocale("EPGP")
  4local LLN = LibStub("LibLootNotify-1.0")
  5local Coroutine = LibStub("LibCoroutine-1.0")
  6local DLG = LibStub("LibDialog-1.0")
  7
  8local ignored_items = {
  9  [20725] = true, -- Nexus Crystal
 10  [22450] = true, -- Void Crystal
 11  [34057] = true, -- Abyss Crystal
 12  [29434] = true, -- Badge of Justice
 13  [40752] = true, -- Emblem of Heroism
 14  [40753] = true, -- Emblem of Valor
 15  [45624] = true, -- Emblem of Conquest
 16  [47241] = true, -- Emblem of Triumph
 17  [49426] = true, -- Emblem of Frost
 18  [30311] = true, -- Warp Slicer
 19  [30312] = true, -- Infinity Blade
 20  [30313] = true, -- Staff of Disintegration
 21  [30314] = true, -- Phaseshift Bulwark
 22  [30316] = true, -- Devastation
 23  [30317] = true, -- Cosmic Infuser
 24  [30318] = true, -- Netherstrand Longbow
 25  [30319] = true, -- Nether Spikes
 26  [30320] = true, -- Bundle of Nether Spikes
 27  [94222] = true, -- Key to the Palace of Lei Shen  
 28}
 29
 30local in_combat = false
 31
 32local function ShowPopup(player, item, quantity)
 33  while in_combat or DLG:ActiveDialog("EPGP_CONFIRM_GP_CREDIT") do
 34    Coroutine:Sleep(0.1)
 35  end
 36
 37  if EPGP:GetEPGP(player) then
 38    local itemName, itemLink, itemRarity, _, _, _, _, _, _, itemTexture = GetItemInfo(item)
 39    DLG:Spawn("EPGP_CONFIRM_GP_CREDIT", {name = player, item = itemLink, icon = itemTexture})
 40  end
 41end
 42
 43local function LootReceived(event_name, player, itemLink, quantity)
 44  if EPGP:IsRLorML() and CanEditOfficerNote() then
 45    local itemID = tonumber(itemLink:match("item:(%d+)") or 0)
 46    if not itemID then return end
 47
 48    local itemRarity = select(3, GetItemInfo(itemID))
 49    if itemRarity < mod.db.profile.threshold then return end
 50
 51    if ignored_items[itemID] then return end
 52
 53    Coroutine:RunAsync(ShowPopup, player, itemLink, quantity)
 54  end
 55end
 56
 57function mod:PLAYER_REGEN_DISABLED()
 58  in_combat = true
 59end
 60
 61function mod:PLAYER_REGEN_ENABLED()
 62  in_combat = false
 63end
 64
 65mod.dbDefaults = {
 66  profile = {
 67    enabled = true,
 68    threshold = 4,  -- Epic quality items
 69  }
 70}
 71
 72function mod:OnInitialize()
 73  self.db = EPGP.db:RegisterNamespace("loot", mod.dbDefaults)
 74end
 75
 76mod.optionsName = L["Loot"]
 77mod.optionsDesc = L["Automatic loot tracking"]
 78mod.optionsArgs = {
 79  help = {
 80    order = 1,
 81    type = "description",
 82    name = L["Automatic loot tracking by means of a popup to assign GP to the toon that received loot. This option only has effect if you are in a raid and you are either the Raid Leader or the Master Looter."]
 83  },
 84  threshold = {
 85    order = 10,
 86    type = "select",
 87    name = L["Loot tracking threshold"],
 88    desc = L["Sets loot tracking threshold, to disable the popup on loot below this threshold quality."],
 89    values = {
 90      [2] = ITEM_QUALITY2_DESC,
 91      [3] = ITEM_QUALITY3_DESC,
 92      [4] = ITEM_QUALITY4_DESC,
 93      [5] = ITEM_QUALITY5_DESC,
 94    },
 95  },
 96}
 97
 98function mod:OnEnable()
 99  self:RegisterEvent("PLAYER_REGEN_DISABLED")
100  self:RegisterEvent("PLAYER_REGEN_ENABLED")
101  LLN.RegisterCallback(self, "LootReceived", LootReceived)
102end
103
104function mod:OnDisable()
105  LLN.UnregisterAllCallbacks(self)
106end