Skip to content

Commit

Permalink
Merge pull request #15 from Cjewett/bugfix/regex-not-language-agnostic
Browse files Browse the repository at this point in the history
Bugfix/regex not language agnostic
  • Loading branch information
mplachter authored Nov 28, 2019
2 parents 78e85d2 + 45b71c8 commit 83b18f8
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 28 deletions.
18 changes: 11 additions & 7 deletions HonorAssist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion HonorAssist.toc
Original file line number Diff line number Diff line change
@@ -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
Expand Down
53 changes: 34 additions & 19 deletions HonorAssistChatMessage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

text = 'You have killed ' .. playerKilled .. ' (' .. playerRank .. ') ' .. timesKilled .. ' ' .. timeText
.. '. This kill granted ' .. percentage * 100 .. '% value for ' .. realisticHonor .. ' honor ' .. string.match(text, "(%(.+)") .. '.'

return text
end
12 changes: 11 additions & 1 deletion HonorAssistDatabase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit 83b18f8

Please sign in to comment.