/modules/loot.lua

https://code.google.com/ · Lua · 106 lines · 90 code · 16 blank · 0 comment · 12 complexity · 98fe18af6a8b665ef88f9ddf64ec438c MD5 · raw file

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