diff --git a/HonorAssist.lua b/HonorAssist.lua index 719ecb4..336fd25 100644 --- a/HonorAssist.lua +++ b/HonorAssist.lua @@ -39,14 +39,18 @@ function HonorAssist:Initialize() end function HonorAssist:ProcessChatMsgCombatHonorGain(honorGainedSummary) - if string.match(honorGainedSummary, "dies, honorable kill") then - local estimatedHonorGained = string.match(honorGainedSummary, "%d+") - local playerKilled = string.match(honorGainedSummary, "^([^%s]+)") - local eventTimeUtc = HonorAssist:GetCurrentTimeUtc() - HonorAssist:AddKillToMasterDatabase(playerKilled, estimatedHonorGained, eventTimeUtc) - local honorGained = HonorAssist:AddKillToDailyDatabase(playerKilled, estimatedHonorGained, eventTimeUtc, HonorAssistLogging) - HonorAssist:AddKillToHourlyDatabase(honorGained, eventTimeUtc) + local estimatedHonorGained = string.match(honorGainedSummary, "%d+") + local playerKilled = string.match(honorGainedSummary, "^([^%s]+)") + + -- It's a dishonorable kill. Just ignore it. + if estimatedHonorGained == nil or playerKilled == nil then + return end + + local eventTimeUtc = HonorAssist:GetCurrentTimeUtc() + HonorAssist:AddKillToMasterDatabase(playerKilled, estimatedHonorGained, eventTimeUtc) + local honorGained = HonorAssist:AddKillToDailyDatabase(playerKilled, estimatedHonorGained, eventTimeUtc, HonorAssistLogging) + HonorAssist:AddKillToHourlyDatabase(honorGained, eventTimeUtc) end function HonorAssist:OnUpdateTimer(timeSinceLastUpdate) diff --git a/HonorAssist.toc b/HonorAssist.toc index 0a03f54..bf0945d 100644 --- a/HonorAssist.toc +++ b/HonorAssist.toc @@ -1,7 +1,7 @@ ## Interface: 11302 ## Title: HonorAssist ## Author: Eulav, CptMerlot -## Version: 0.7 +## Version: 0.7.1 ## SavedVariablesPerCharacter: HonorAssistData, HonorAssistLogging, HonorAssistTrackerFramePositionX, HonorAssistTrackerFramePositionY, HonorAssistShowTrackerUi HonorAssist.lua diff --git a/HonorAssistChatMessage.lua b/HonorAssistChatMessage.lua index ef2f9a9..fc55fb2 100644 --- a/HonorAssistChatMessage.lua +++ b/HonorAssistChatMessage.lua @@ -4,24 +4,39 @@ HonorAssist = addonTable -- This runs after HonorAssistDailyCalculator. That means the kill is already added to that database, so we can use the times killed from that service. -- When calculating realistic honor we need to decrease by 1 to get the real value of the kill. ChatFrame_AddMessageEventFilter("CHAT_MSG_COMBAT_HONOR_GAIN", function(self, event, text, ...) - if string.match(text, "dies, honorable kill") then - local estimatedHonorGained = string.match(text, "%d+") - local playerKilled = string.match(text, "^([^%s]+)") - local playerRank = HonorAssist:Trim(string.match(text, "(Rank:.([^(]+))")) - local timesKilled = HonorAssist:GetTotalKillsDailyDatabase(playerKilled) - local percentage, realisticHonor = HonorAssist:CalculateRealisticHonor(timesKilled - 1, estimatedHonorGained) - local timeText = 'times' - - if timesKilled == 1 then - timeText = 'time' - end - - text = 'You have killed ' .. playerKilled .. ' (' .. playerRank .. ') ' .. timesKilled .. ' ' .. timeText - .. '. This kill granted ' .. percentage * 100 .. '% value for ' .. realisticHonor .. ' honor ' .. string.match(text, "(%(.+)") .. '.' - - return false, text, ... + local estimatedHonorGained = string.match(text, "%d+") + local playerKilled = string.match(text, "^([^%s]+)") + local playerRank = HonorAssist:Trim(string.match(text, "^(.([^(]+))")) -- Extracts message up until first open parentheses. + playerRank = string.match(playerRank, "(%a+:.+)") -- Pulls out "Rank: Title". + + if HonorAssist:IsHonorableKill(estimatedHonorGained, playerKilled, playerRank) then + text = HonorAssist:CreateHonorableKillMessage(estimatedHonorGained, playerKilled, playerRank, text) else - dkText = '|cFFFF0000' .. text - return false, dkText, ... + -- Don't need to do anything here for now. + end + + return false, text, ... +end) + +function HonorAssist:IsHonorableKill(estimatedHonorGained, playerKilled, playerRank) + if estimatedHonorGained == nil or playerKilled == nil or playerRank == nil then + return false + end + + return true +end + +function HonorAssist:CreateHonorableKillMessage(estimatedHonorGained, playerKilled, playerRank, text) + local timesKilled = HonorAssist:GetTotalKillsDailyDatabase(playerKilled) + local percentage, realisticHonor = HonorAssist:CalculateRealisticHonor(timesKilled - 1, estimatedHonorGained) + local timeText = 'times' + + if timesKilled == 1 then + timeText = 'time' end -end) \ No newline at end of file + + text = 'You have killed ' .. playerKilled .. ' (' .. playerRank .. ') ' .. timesKilled .. ' ' .. timeText + .. '. This kill granted ' .. percentage * 100 .. '% value for ' .. realisticHonor .. ' honor ' .. string.match(text, "(%(.+)") .. '.' + + return text +end \ No newline at end of file diff --git a/HonorAssistDatabase.lua b/HonorAssistDatabase.lua index 83c0034..834724e 100644 --- a/HonorAssistDatabase.lua +++ b/HonorAssistDatabase.lua @@ -12,7 +12,7 @@ end function HonorAssist:LoadDataSinceDateTimeUtc(dailyStartTimeEpoch, hourlyStartTimeEpoch) for enemyName, enemyKills in pairs(HonorAssistData) do for index, honorGained in pairs(enemyKills) do - if honorGained.Honor ~= nil then + if not HonorAssist:CheckIfInvalidKill(honorGained) then local percentage, realisticHonor = HonorAssist:CalculateRealisticHonor(index, honorGained.Honor) local timeKilledEpoch = HonorAssist:DatabaseTimeUtcToLuaTime(honorGained.DateUtc) @@ -30,6 +30,16 @@ function HonorAssist:LoadDataSinceDateTimeUtc(dailyStartTimeEpoch, hourlyStartTi end end +-- 11/24/2019: It was possible for the database to log dishonorable kills. That resulted in no Honor saved in the database and we were not handling nil values. This check is required as long as +-- we want to support early users (and we do). +function HonorAssist:CheckIfInvalidKill(honorGained) + if honorGained.Honor == nil or honorGained.DateUtc == nil then + return true + end + + return false +end + function HonorAssist:GetTotalKillsMasterDatabase(playerName) if HonorAssist:HasBeenKilled(HonorAssistData, playerName) == false then return 0