diff --git a/AddonScope.lua b/AddonScope.lua index dcee3cc..fdd8c98 100644 --- a/AddonScope.lua +++ b/AddonScope.lua @@ -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 diff --git a/Features/Currency.lua b/Features/Currency.lua index d400de5..53204f2 100644 --- a/Features/Currency.lua +++ b/Features/Currency.lua @@ -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, diff --git a/Features/Experience.lua b/Features/Experience.lua index effe96b..0c6f21f 100644 --- a/Features/Experience.lua +++ b/Features/Experience.lua @@ -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 @@ -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) diff --git a/Features/ItemLoot.lua b/Features/ItemLoot.lua index 89cf102..acf4c2f 100644 --- a/Features/ItemLoot.lua +++ b/Features/ItemLoot.lua @@ -30,7 +30,6 @@ function ItemLoot:OnInitialize() else self:Disable() end - logger = G_RLF.RLF:GetModule("Logger") end function ItemLoot:OnDisable() @@ -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+)") @@ -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) diff --git a/Features/Money.lua b/Features/Money.lua index a13cf72..9abe3f7 100644 --- a/Features/Money.lua +++ b/Features/Money.lua @@ -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 @@ -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 diff --git a/Features/Reputation.lua b/Features/Reputation.lua index 3913054..8676946 100644 --- a/Features/Reputation.lua +++ b/Features/Reputation.lua @@ -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 @@ -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 @@ -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 diff --git a/Logger.lua b/Logger.lua index 04966e8..3378655 100644 --- a/Logger.lua +++ b/Logger.lua @@ -1,4 +1,5 @@ local Logger = G_RLF.RLF:NewModule("Logger", "AceEvent-3.0") +local gui = LibStub("AceGUI-3.0") local loggerName = G_RLF.addonName .. "Logger" local defaults = { @@ -6,52 +7,144 @@ local defaults = { logs = {}, } -function dump(o) - if type(o) == "table" then - local s = "{ " - for k, v in pairs(o) do - if type(k) ~= "number" then - k = '"' .. k .. '"' - end - s = s .. "[" .. k .. "] = " .. dump(v) .. "," +local updateContent +local getLogger +local WOWEVENT = "WOWEVENT" + +local eventSource = { + [G_RLF.addonName] = true, + [WOWEVENT] = false, +} +local function OnEventSourceChange(_, _, k, v) + eventSource[k] = v + updateContent() +end + +local debug = "DEBUG" +local info = "INFO" +local warn = "WARN" +local error = "ERROR" +local eventLevel = { + [debug] = false, + [info] = true, + [warn] = true, + [error] = true, +} +local function OnEventLevelChange(_, _, k, v) + eventLevel[k] = v + updateContent() +end + +local ItemLoot = "ItemLoot" +local Currency = "Currency" +local Money = "Money" +local Reputation = "Reputation" +local Experience = "Experience" +local eventType = { + [ItemLoot] = true, + [Currency] = true, + [Money] = true, + [Reputation] = true, + [Experience] = true, +} +local function OnEventTypeChange(_, _, k, v) + eventType[k] = v + updateContent() +end + +local function OnClearLog() + local count = #getLogger() + for i = 0, count do + getLogger()[i] = nil + end + updateContent() +end + +local frame, contentBox +local function initializeFrame() + if not frame then + frame = gui:Create("Frame") + frame:SetTitle("Loot Log") + frame:EnableResize(false) + frame:SetCallback("OnClose", function(widget) + gui:Release(widget) + frame = nil + end) + frame:SetLayout("Flow") + + local filterBar = gui:Create("SimpleGroup") + filterBar:SetFullWidth(true) + filterBar:SetLayout("Flow") + frame:AddChild(filterBar) + + contentBox = gui:Create("MultiLineEditBox") + contentBox:SetLabel("Logs") + contentBox:DisableButton(true) + contentBox:SetFullWidth(true) + contentBox:SetNumLines(23) + frame:AddChild(contentBox) + + local logSources = gui:Create("Dropdown") + logSources:SetLabel("Log Sources") + logSources:SetMultiselect(true) + logSources:SetList({ + [G_RLF.addonName] = G_RLF.addonName, + [WOWEVENT] = WOWEVENT, + }, { + G_RLF.addonName, + WOWEVENT, + }) + logSources:SetCallback("OnValueChanged", OnEventSourceChange) + for k, v in pairs(eventSource) do + logSources:SetItemValue(k, v) end - return s .. "} " - else - return tostring(o) + filterBar:AddChild(logSources) + + local logLevels = gui:Create("Dropdown") + logLevels:SetLabel("Log Levels") + logLevels:SetMultiselect(true) + logLevels:SetList({ + [debug] = debug, + [info] = info, + [warn] = warn, + [error] = error, + }) + logLevels:SetCallback("OnValueChanged", OnEventLevelChange) + for k, v in pairs(eventLevel) do + logLevels:SetItemValue(k, v) + end + filterBar:AddChild(logLevels) + + local logTypes = gui:Create("Dropdown") + logTypes:SetLabel("Log Types") + logTypes:SetMultiselect(true) + logTypes:SetList({ + [ItemLoot] = ItemLoot, + [Currency] = Currency, + [Money] = Money, + [Reputation] = Reputation, + [Experience] = Experience, + }) + logTypes:SetCallback("OnValueChanged", OnEventTypeChange) + for k, v in pairs(eventType) do + logTypes:SetItemValue(k, v) + end + filterBar:AddChild(logTypes) + + local clearButton = gui:Create("Button") + clearButton:SetText("Clear Current Log") + clearButton:SetCallback("OnClick", OnClearLog) + filterBar:AddChild(clearButton) + + frame:DoLayout() end end -local frame, editBox +getLogger = function() + return G_RLF.db.global.logger.logs[G_RLF.db.global.logger.sessionsLogged] +end function Logger:OnInitialize() - G_RLF:Print("Logger Initialized") - frame = CreateFrame("Frame", "RPGLootFeedLogFrame", UIParent, "BasicFrameTemplateWithInset") - frame:SetSize(500, 400) -- Width, Height - frame:SetPoint("CENTER") -- Position on the screen - frame:SetMovable(true) - frame:EnableMouse(true) - frame:RegisterForDrag("LeftButton") - frame:SetScript("OnDragStart", frame.StartMoving) - frame:SetScript("OnDragStop", frame.StopMovingOrSizing) - - local scrollFrame = CreateFrame("ScrollFrame", nil, frame, "UIPanelScrollFrameTemplate") - scrollFrame:SetSize(475, 360) - scrollFrame:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, -25) - - local content = CreateFrame("Frame", nil, scrollFrame) - content:SetSize(480, 370) -- Scrollable area - scrollFrame:SetScrollChild(content) - - editBox = CreateFrame("EditBox", nil, content) - editBox:SetMultiLine(true) - editBox:SetFontObject("ChatFontNormal") - editBox:SetSize(480, 300) - editBox:SetPoint("TOPLEFT", 10, -15) - editBox:SetAutoFocus(false) - editBox:SetScript("OnEscapePressed", function() - frame:Hide() - end) - frame:Hide() self:RegisterEvent("PLAYER_ENTERING_WORLD") end @@ -65,19 +158,97 @@ function Logger:PLAYER_ENTERING_WORLD(_, isLogin, isReload) tremove(G_RLF.db.global.logger.logs, 1) G_RLF.db.global.logger.sessionsLogged = G_RLF.db.global.logger.sessionsLogged - 1 end + self:Debug("Logger is ready", G_RLF.addonName) end end -local function getLogger() - return G_RLF.db.global.logger.logs[G_RLF.db.global.logger.sessionsLogged] +local function getLevel(logEntry) + local level = logEntry.level + local levelColors = { + [debug] = "|cFF808080{D}|r", -- Gray for DEBUG + [info] = "|cFFADD8E6{I}|r", -- Light blue for INFO (ADD8E6 in hex) + [warn] = "|cFFFFD700{W}|r", -- Gold for WARN + [error] = "|cFFFF0000{E}|r", -- Red for ERROR + } + + -- Return the formatted level or an empty string if the level is not recognized + return levelColors[level] or "" end -local function updateContent() +local function getType(logEntry) + local type = logEntry.type + local typeColors = { + [ItemLoot] = "|cFF00FF00[ITEM]|r ", -- Green for item loot + [Currency] = "|cFFFFD700[CURR]|r ", -- Gold for currency + [Money] = "|cFFC0C0C0[GOLD]|r ", -- Silver/Gray for money + [Reputation] = "|cFF1E90FF[REPU]|r ", -- Blue for reputation + [Experience] = "|cFF9932CC[EXPR]|r ", -- Purple for experience + } + + -- Return an empty string for "General" and the corresponding value for others + return typeColors[type] or "" +end + +local function getTimestamp(logEntry) + -- Extract the time portion from the timestamp using pattern matching + local timeOnly = logEntry.timestamp:match("%d%d:%d%d:%d%d") + + -- Return the formatted timestamp with dark gray color + return "|cFF808080" .. timeOnly .. "|r" +end + +local function getContent(logEntry) + if logEntry.content == "" then + return logEntry.message + end + return logEntry.content +end + +local function getAmount(logEntry) + if logEntry.amount == "" then + return "" + end + return format(" x%s", logEntry.amount) +end + +local function isUpdatedRow(logEntry) + if logEntry.new == false then + return " ~UPDATE~" + end + return "" +end + +local function getId(logEntry) + if logEntry.id == "" then + return "" + end + return format(" [%s]", logEntry.id) +end + +updateContent = function() local text = "" + + local function addText(logEntry) + text = format( + "[%s] %s: %s%s%s%s%s\n", + getTimestamp(logEntry), + getLevel(logEntry), + getType(logEntry), + getContent(logEntry), + getAmount(logEntry), + isUpdatedRow(logEntry), + getId(logEntry) + ) .. text + end + for i, logEntry in ipairs(getLogger()) do - text = text .. format("[%s] %s: %s\n", logEntry.timestamp, logEntry.level, logEntry.content) + if eventSource[logEntry.source] then + if eventLevel[logEntry.level] then + addText(logEntry) + end + end end - editBox:SetText(text) + contentBox:SetText(text) end local function addLogEntry(level, message, source, type, id, content, amount, isNew) @@ -89,34 +260,46 @@ local function addLogEntry(level, message, source, type, id, content, amount, is id = id or "", content = content or "", amount = amount or "", - new = isNew or false, + new = isNew, message = message, } - table.insert(getLogger(), entry) - updateContent() -end - -function Logger:Info(message, source, type, id, content, amount, isNew) - addLogEntry("INFO", message, source, type, id, content, amount, isNew) + local logTable = getLogger() + if not logTable then + error("Log Table not ready") + return + end + table.insert(logTable, entry) + if frame and frame:IsShown() then + updateContent() + end end function Logger:Debug(message, source, type, id, content, amount, isNew) - addLogEntry("DEBUG", message, source, type, id, content, amount, isNew) + addLogEntry(debug, message, source, type, id, content, amount, isNew) end -function Logger:Error(message, source, type, id, content, amount, isNew) - addLogEntry("ERROR", message, source, type, id, content, amount, isNew) +function Logger:Info(message, source, type, id, content, amount, isNew) + addLogEntry(info, message, source, type, id, content, amount, isNew) end function Logger:Warn(message, source, type, id, content, amount, isNew) - addLogEntry("WARN", message, source, type, id, content, amount, isNew) + addLogEntry(warn, message, source, type, id, content, amount, isNew) end -function Logger:Dump() - G_RLF:Print(dump(getLogger())) +function Logger:Error(message, source, type, id, content, amount, isNew) + addLogEntry(error, message, source, type, id, content, amount, isNew) end function Logger:Show() - updateContent() - frame:Show() + if frame then + self:Hide() + else + initializeFrame() + updateContent() + frame:Show() + end +end + +function Logger:Hide() + frame:Hide() end diff --git a/LootDisplay.lua b/LootDisplay.lua index 1acd651..2c4922b 100644 --- a/LootDisplay.lua +++ b/LootDisplay.lua @@ -111,13 +111,28 @@ function LootDisplay:UpdateFadeDelay() end end -function LootDisplay:ShowLoot(id, link, icon, amountLooted) - local key = tostring(id) -- Use ID as a unique key +function LootDisplay:ShowLoot(type, ...) + if type == "Currency" or type == "ItemLoot" then + self:ShowLinks(...) + elseif type == "Money" then + self:ShowMoney(...) + elseif type == "Experience" then + self:ShowXP(...) + elseif type == "Reputation" then + self:ShowRep(...) + end +end +function LootDisplay:ShowLinks(id, link, icon, amountLooted) + local key = tostring(id) -- Use ID as a unique key + local new = true + local isItem = true -- Check if the item or currency is already displayed local row = getRow(key) + isItem = string.find(link, "item:") ~= nil if row then -- Update existing entry + new = false row.amount = row.amount + amountLooted if not G_RLF.db.global.disableRowHighlight then row.highlightAnimation:Stop() @@ -136,8 +151,7 @@ function LootDisplay:ShowLoot(id, link, icon, amountLooted) -- Initialize row content rowStyles(row) if Masque and iconGroup then - local found = string.find(link, "item:") - if found then + if isItem then row.icon:SetItem(link) else local quality = C_CurrencyInfo.GetCurrencyInfo(id).quality @@ -154,8 +168,17 @@ function LootDisplay:ShowLoot(id, link, icon, amountLooted) row.fadeOutAnimation:Play() end row.amountText:SetText(row.link .. " x" .. row.amount) - - logger:Info("Item Loot Shown", G_RLF.addonName, "ItemLoot", key, row.link, row.amount, new) + local amountLogText = row.amount + if not new then + amountLogText = format("%d (+%d)", row.amount, amountLooted) + end + local messageLogText = "Item Loot Shown" + local logType = "ItemLoot" + if not isItem then + messageLogText = "Currency Loot Shown" + logType = "Currency" + end + logger:Info(messageLogText, G_RLF.addonName, logType, key, row.link, amountLogText, new) -- Add Tooltip row.amountText:SetScript("OnEnter", function() row.fadeOutAnimation:Stop() @@ -192,8 +215,10 @@ function LootDisplay:ShowMoney(copper) -- Check if the item or currency is already displayed local row = getRow(key) + local new = true if row then -- Update existing entry + new = false row.copper = row.copper + copper row.highlightAnimation:Stop() row.highlightAnimation:Play() @@ -211,6 +236,14 @@ function LootDisplay:ShowMoney(copper) text = C_CurrencyInfo.GetCoinTextureString(row.copper) row.amountText:SetText(text) + local amountLogText = row.copper + if not new then + amountLogText = format("%s (+%s)", row.copper, copper) + end + local messageLogText = "Money Shown" + local logType = "Money" + logger:Info(messageLogText, G_RLF.addonName, logType, key, text, amountLogText, new) + row.fadeOutAnimation:Stop() row.fadeOutAnimation:Play() end @@ -221,8 +254,10 @@ function LootDisplay:ShowXP(experience) -- Check if the item or currency is already displayed local row = getRow(key) + local new = true if row then -- Update existing entry + new = false row.experience = row.experience + experience row.highlightAnimation:Stop() row.highlightAnimation:Play() @@ -240,6 +275,13 @@ function LootDisplay:ShowXP(experience) text = "+" .. row.experience .. " " .. G_RLF.L["XP"] row.amountText:SetText(text) row.amountText:SetTextColor(1, 0, 1, 0.8) + local amountLogText = row.experience + if not new then + amountLogText = format("%s (+%s)", row.experience, experience) + end + local messageLogText = "XP Shown" + local logType = "Experience" + logger:Info(messageLogText, G_RLF.addonName, logType, key, text, amountLogText, new) row.fadeOutAnimation:Stop() row.fadeOutAnimation:Play() diff --git a/TestMode.lua b/TestMode.lua index a879444..9f25f55 100644 --- a/TestMode.lua +++ b/TestMode.lua @@ -1,5 +1,7 @@ TestMode = {} +local logger + local function idExistsInTable(id, table) for _, item in pairs(table) do if item.id == id then @@ -10,20 +12,7 @@ local function idExistsInTable(id, table) end -- Initial test items with color variables -local testItemIds = { - 50818, - 2589, - 2592, - 1515, - 730, - 19019, - 128507, - 132842, - 23538, - 11754, - 128827, - 219325, -} +local testItemIds = { 50818, 2589, 2592, 1515, 730, 19019, 128507, 132842, 23538, 11754, 128827, 219325 } local testItems = {} local function initializeTestItems() @@ -42,23 +31,7 @@ local function initializeTestItems() end end -local testCurrencyIds = { - 2245, - 1191, - 1828, - 1792, - 1755, - 1580, - 1273, - 1166, - 515, - 241, - 1813, - 2778, - 3089, - 1101, - 1704, -} +local testCurrencyIds = { 2245, 1191, 1828, 1792, 1755, 1580, 1273, 1166, 515, 241, 1813, 2778, 3089, 1101, 1704 } local testCurrencies = {} local function initializeTestCurrencies() @@ -77,8 +50,12 @@ local function initializeTestCurrencies() end end -local ItemLoot, Currency, Xp, Rep, Money -local playerGuid = GetPlayerGuid() +local testFactions = { + "Undercity", + "Thunder Bluff", + "Orgrimmar", +} + local function generateRandomLoot() if #testItems ~= #testItemIds then initializeTestItems() @@ -88,43 +65,45 @@ local function generateRandomLoot() initializeTestCurrencies() end -- Randomly decide whether to generate an item or currency - local rng = math.random() - if rng < 0.8 then - -- Generate random item - local item = testItems[math.random(#testItems)] - local amountLooted = math.random(1, 5) - -- Choose the appropriate format based on the quantity - local lootMessage - if amountLooted > 1 then - lootMessage = format(LOOT_ITEM_SELF_MULTIPLE, item.link, amountLooted) - else - lootMessage = format(LOOT_ITEM_SELF, item.link) + local numberOfRowsToGenerate = math.random(1, 5) + for i = 1, numberOfRowsToGenerate do + local rng = math.random() + + if rng >= 0.8 then + local experienceGained = math.random(100, 10000) + G_RLF.LootDisplay:ShowLoot("Experience", experienceGained) end - -- Call the CHAT_MSG_LOOT event handler directly - ItemLoot:CHAT_MSG_LOOT(nil, lootMessage, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, playerGuid) - if rng < 0.1 then + + if rng <= 0.2 then local copper = math.random(1, 100000000) - G_RLF.LootDisplay:ShowMoney(copper) + G_RLF.LootDisplay:ShowLoot("Money", copper) + end + + -- 50% chance to show items + if rng > 0.2 and rng <= 0.7 then + local item = testItems[math.random(#testItems)] + local amountLooted = math.random(1, 5) + G_RLF.LootDisplay:ShowLoot("ItemLoot", item.id, item.link, item.icon, amountLooted) + + -- 15% chance to show currency + elseif rng > 0.7 and rng <= 0.85 then + local currency = testCurrencies[math.random(#testCurrencies)] + local amountLooted = math.random(1, 500) + G_RLF.LootDisplay:ShowLoot("Currency", currency.id, currency.link, currency.icon, amountLooted) + + -- 10% chance to show reputation (least frequent) + elseif rng > 0.85 then + local reputationGained = math.random(10, 100) + local factionName = testFactions[math.random(#testFactions)] + G_RLF.LootDisplay:ShowLoot("Reputation", reputationGained, factionName) end - else - -- Generate random currency - local currency = testCurrencies[math.random(#testCurrencies)] - local amountLooted = math.random(1, 500) - Currency:CURRENCY_DISPLAY_UPDATE(nil, currency.id, nil, amountLooted) end end -local logger function TestMode:ToggleTestMode() - if not (ItemLoot and Currency and Money and Xp and Rep) then - ItemLoot = G_RLF.RLF:GetModule("ItemLoot") - Currency = G_RLF.RLF:GetModule("Currency") - Money = G_RLF.RLF:GetModule("Money") - Xp = G_RLF.RLF:GetModule("Experience") - Rep = G_RLF.RLF:GetModule("Reputation") + if not logger then logger = G_RLF.RLF:GetModule("Logger") end - if self.testMode then -- Stop test mode self.testMode = false @@ -133,10 +112,12 @@ function TestMode:ToggleTestMode() self.testTimer = nil end G_RLF:Print(G_RLF.L["Test Mode Disabled"]) + logger:Debug("Test Mode Disabled", G_RLF.addonName, "TestMode") else -- Start test mode self.testMode = true G_RLF:Print(G_RLF.L["Test Mode Enabled"]) + logger:Debug("Test Mode Enabled", G_RLF.addonName, "TestMode") self.testTimer = C_Timer.NewTicker(1.5, function() G_RLF:fn(generateRandomLoot) end)