Skip to content

Commit

Permalink
Loot History Logs, needs more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Anderson committed Sep 5, 2024
1 parent 2421c76 commit 2cb059a
Show file tree
Hide file tree
Showing 9 changed files with 398 additions and 144 deletions.
11 changes: 11 additions & 0 deletions AddonScope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ local dbName = addonName .. "DB"
local localeName = addonName .. "Locale"
G_RLF.RLF = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0", "AceTimer-3.0")
G_RLF.RLF:SetDefaultModuleState(true)
G_RLF.RLF:SetDefaultModulePrototype({
getLogger = function(self)
return G_RLF.RLF:GetModule("Logger")
end,
type = function(self)
if self then
return self.moduleName
end
return nil
end,
})
G_RLF.addonName = addonName
G_RLF.dbName = dbName
G_RLF.localeName = localeName
Expand Down
21 changes: 20 additions & 1 deletion Features/Currency.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,39 @@ function Currency:OnEnable()
self:RegisterEvent("CURRENCY_DISPLAY_UPDATE")
end

function Currency:CURRENCY_DISPLAY_UPDATE(_, ...)
function Currency:CURRENCY_DISPLAY_UPDATE(eventName, ...)
local currencyType, _quantity, quantityChange, _quantityGainSource, _quantityLostSource = ...

self:getLogger():Info(eventName, "WOWEVENT", self.moduleName, currencyType, eventName, quantityChange)

if currencyType == nil or not quantityChange or quantityChange <= 0 then
self:getLogger():Debug(
"Skip showing currency",
G_RLF.addonName,
self.moduleName,
currencyType,
"SKIP: Something was missing, don't display",
quantityChange
)
return
end

local info = C_CurrencyInfo.GetCurrencyInfo(currencyType)
if info == nil or info.description == "" or info.iconFileID == nil then
self:getLogger():Debug(
"Skip showing currency",
G_RLF.addonName,
self.moduleName,
currencyType,
"SKIP: Description or icon was empty",
quantityChange
)
return
end

G_RLF:fn(function()
G_RLF.LootDisplay:ShowLoot(
"Currency",
info.currencyID,
C_CurrencyInfo.GetCurrencyLink(currencyType),
info.iconFileID,
Expand Down
12 changes: 9 additions & 3 deletions Features/Experience.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ function Xp:OnEnable()
end
end

function Xp:PLAYER_ENTERING_WORLD()
function Xp:PLAYER_ENTERING_WORLD(eventName)
self:getLogger():Info(eventName, "WOWEVENT", self.moduleName)
G_RLF:fn(initXpValues)
end

function Xp:PLAYER_XP_UPDATE(_, unitTarget)
function Xp:PLAYER_XP_UPDATE(eventName, unitTarget)
self:getLogger():Info(eventName, "WOWEVENT", self.moduleName, unitTarget)
G_RLF:fn(function()
if unitTarget == "player" then
local newLevel = UnitLevel(unitTarget)
local newCurrentXP = UnitXP(unitTarget)
local delta = 0
if newLevel == nil then
self:getLogger():Warn("Could not get player level", G_RLF.addonName, self.moduleName)
return
end
currentLevel = currentLevel or newLevel
Expand All @@ -51,7 +54,10 @@ function Xp:PLAYER_XP_UPDATE(_, unitTarget)
currentLevel = newLevel
currentMaxXP = UnitXPMax(unitTarget)
if delta > 0 then
G_RLF.LootDisplay:ShowXP(delta)
G_RLF.LootDisplay:ShowLoot("Experience", delta)
else
self:getLogger()
:Warn(eventName .. " fired but delta was not positive", G_RLF.addonName, self.moduleName)
end
end
end)
Expand Down
14 changes: 6 additions & 8 deletions Features/ItemLoot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function ItemLoot:OnInitialize()
else
self:Disable()
end
logger = G_RLF.RLF:GetModule("Logger")
end

function ItemLoot:OnDisable()
Expand All @@ -46,7 +45,7 @@ local function showItemLoot(msg, itemLink)
local _, _, itemQuality, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, sellPrice, classID, subclassID, bindType, expansionID, setID, isCraftingReagent =
C_Item.GetItemInfo(itemLink)
if not G_RLF.db.global.itemQualityFilter[itemQuality] then
logger:Info("Item Ignored by quality", G_RLF.addonName, "ItemLoot", "", msg, amount)
self:getLogger():Debug("Item Ignored by quality", G_RLF.addonName, "ItemLoot", "", msg, amount)
return
end
local itemId = itemLink:match("Hitem:(%d+)")
Expand All @@ -62,26 +61,25 @@ local function showItemLoot(msg, itemLink)
-- end

-- end
G_RLF.LootDisplay:ShowLoot(itemId, itemLink, itemTexture, amount)
G_RLF.LootDisplay:ShowLoot("ItemLoot", itemId, itemLink, itemTexture, amount)
end

function ItemLoot:CHAT_MSG_LOOT(_, ...)
function ItemLoot:CHAT_MSG_LOOT(eventName, ...)
local msg, _, _, _, _, _, _, _, _, _, _, guid = ...
local raidLoot = msg:match("HlootHistory:")
self:getLogger():Info(eventName, "WOWEVENT", self.moduleName, nil, eventName .. " " .. msg)
if raidLoot then
-- Ignore this message as it's a raid loot message
logger:Info("Raid Loot Ignored", "WOWEVENT", "ItemLoot", "", msg)
self:getLogger():Debug("Raid Loot Ignored", "WOWEVENT", "ItemLoot", "", msg)
return
end

local me = guid == GetPlayerGuid()
if not me then
logger:Info("Group Member Loot Ignored", "WOWEVENT", "ItemLoot", "", msg)
self:getLogger():Debug("Group Member Loot Ignored", "WOWEVENT", "ItemLoot", "", msg)
return
end

logger:Info("Self Loot Chat Event", "WOWEVENT", "ItemLoot", "", msg)

local itemLink = msg:match("|c%x+|Hitem:.-|h%[.-%]|h|r")
if itemLink then
G_RLF:fn(showItemLoot, msg, itemLink)
Expand Down
9 changes: 6 additions & 3 deletions Features/Money.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ function Money:OnEnable()
self:RegisterEvent("CHAT_MSG_MONEY")
end

function Money:LOOT_READY()
function Money:LOOT_READY(eventName)
-- Get current money to calculate the delta later
self:getLogger():Info(eventName, "WOWEVENT", self.moduleName)
startingMoney = GetMoney()
end

Expand All @@ -31,14 +32,16 @@ local function showMoneyLoot(msg)
if startingMoney == nil then
-- Old method that doesn't work well with locales that are missing translation
amountInCopper = oldMethod(msg)
self:getLogger():Debug("Old money method", G_RLF.addonName, self.moduleName)
else
amountInCopper = GetMoney() - startingMoney
end
startingMoney = GetMoney()
G_RLF.LootDisplay:ShowMoney(amountInCopper)
G_RLF.LootDisplay:ShowLoot("Money", amountInCopper)
end

function Money:CHAT_MSG_MONEY(_, msg)
function Money:CHAT_MSG_MONEY(eventName, msg)
self:getLogger():Info(eventName, "WOWEVENT", self.moduleName)
G_RLF:fn(showMoneyLoot, msg)
end

Expand Down
15 changes: 13 additions & 2 deletions Features/Reputation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ function Rep:OnEnable()
self:RegisterEvent("CHAT_MSG_COMBAT_FACTION_CHANGE")
end

function Rep:CHAT_MSG_COMBAT_FACTION_CHANGE(_, message)
function Rep:CHAT_MSG_COMBAT_FACTION_CHANGE(eventName, message)
self:getLogger():Info(eventName .. " " .. message, "WOWEVENT", self.moduleName)
G_RLF:fn(function()
local faction, repChange = extractFactionAndRep(message, increasePatterns)
if not faction then
Expand All @@ -110,6 +111,7 @@ function Rep:CHAT_MSG_COMBAT_FACTION_CHANGE(_, message)
local r, g, b, color
if G_RLF.db.global.factionMaps[locale][faction] == nil then
-- attempt to find the missing faction's ID
self:getLogger():Debug(faction .. " not cached for " .. locale, G_RLF.addonName, self.moduleName)
buildFactionLocaleMap(faction)
end

Expand All @@ -132,7 +134,16 @@ function Rep:CHAT_MSG_COMBAT_FACTION_CHANGE(_, message)
end

if faction and repChange then
G_RLF.LootDisplay:ShowRep(repChange, faction, r, g, b)
G_RLF.LootDisplay:ShowLoot("Reputation", repChange, faction, r, g, b)
else
self:getLogger():Warn(
"Could not determine faction and/or rep change",
G_RLF.addonName,
self.moduleName,
faction,
nil,
repChange
)
end
end)
end
Expand Down
Loading

0 comments on commit 2cb059a

Please sign in to comment.