From 856520aab845ccf411a2aa3546073735dde03a53 Mon Sep 17 00:00:00 2001 From: Cjewett Date: Tue, 26 Nov 2019 22:53:24 -0500 Subject: [PATCH 1/3] make some localization changes while still protecting database from dishonorable kills --- HonorAssist.lua | 18 ++++++++----- HonorAssistChatMessage.lua | 52 ++++++++++++++++++++++++-------------- HonorAssistDatabase.lua | 12 ++++++++- 3 files changed, 55 insertions(+), 27 deletions(-) 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/HonorAssistChatMessage.lua b/HonorAssistChatMessage.lua index ef2f9a9..165dd9a 100644 --- a/HonorAssistChatMessage.lua +++ b/HonorAssistChatMessage.lua @@ -4,24 +4,38 @@ 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, "(Rank:.([^(]+))")) + + 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 From fefb2ecddd5fd934583dc0e8d3ac4774d6cc66c9 Mon Sep 17 00:00:00 2001 From: Cjewett Date: Wed, 27 Nov 2019 00:33:41 -0500 Subject: [PATCH 2/3] pull rank using regex after colon is found, no language specific text (i think) --- HonorAssistChatMessage.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/HonorAssistChatMessage.lua b/HonorAssistChatMessage.lua index 165dd9a..fc55fb2 100644 --- a/HonorAssistChatMessage.lua +++ b/HonorAssistChatMessage.lua @@ -6,7 +6,8 @@ HonorAssist = addonTable ChatFrame_AddMessageEventFilter("CHAT_MSG_COMBAT_HONOR_GAIN", function(self, event, text, ...) local estimatedHonorGained = string.match(text, "%d+") local playerKilled = string.match(text, "^([^%s]+)") - local playerRank = HonorAssist:Trim(string.match(text, "(Rank:.([^(]+))")) + 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) From 45b71c884d67f857c7509df7f51e42a0b0ec69ae Mon Sep 17 00:00:00 2001 From: Cjewett Date: Wed, 27 Nov 2019 20:49:51 -0500 Subject: [PATCH 3/3] update version --- HonorAssist.toc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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