-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHonorHistory.lua
156 lines (134 loc) · 5.06 KB
/
HonorHistory.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
local ADDON_NAME, H = ...
H.modules = {}
local date, time = date, time
local str_find = string.find
local tonumber = tonumber
local CreateFrame = CreateFrame
local PVPHonor = _G["PVPHonor"]
local HonorHistory = CreateFrame("Frame", "HonorHistory", UIParent)
H.HonorHistory = HonorHistory
function HonorHistory:Initialize()
-- add lines
PVPHonor.honorLabel = PVPHonor:CreateFontString("PVPHonorHonorLabel", "BACKGROUND", "GameFontDisableSmall")
PVPHonor.honorLabel:SetPoint("TOPRIGHT", PVPHonorKillsLabel, "BOTTOMRIGHT")
PVPHonor.honorLabel:SetJustifyH("RIGHT")
PVPHonor.honorLabel:SetText(HONOR)
PVPHonor.todayHonor = PVPHonor:CreateFontString("PVPHonorTodayHonor", "BACKGROUND", "GameFontHighlightSmall")
PVPHonor.todayHonor:SetPoint("TOP", PVPHonorTodayKills, "BOTTOM")
PVPHonor.yesterdayHonor = PVPHonor:CreateFontString("PVPHonorYesterdayHonor", "BACKGROUND", "GameFontHighlightSmall")
PVPHonor.yesterdayHonor:SetPoint("TOP", PVPHonorYesterdayKills, "BOTTOM")
self:Call("Initialize")
end
----------------------
-- EVENTS
----------------------
HonorHistory:RegisterEvent("ADDON_LOADED")
HonorHistory:RegisterEvent("PLAYER_LOGOUT")
HonorHistory:RegisterEvent("CHAT_MSG_COMBAT_HONOR_GAIN")
HonorHistory:SetScript("OnEvent", function(self, event, msg)
self[event](self, msg)
end)
local updateInterval, lastUpdate = 20, 0
HonorHistory:SetScript("OnUpdate", function(self, elapsed)
lastUpdate = lastUpdate + elapsed
if lastUpdate > updateInterval then
self:UpdateSavedVariables()
lastUpdate = 0;
end
end)
function HonorHistory:ADDON_LOADED(msg)
if msg ~= ADDON_NAME then
return
end
H.db = HonorHistorySV
if H.db == nil then
H.db = { today = { date = date("%m/%d/%y"), honor = 0},
yesterday = { date = date("%m/%d/%y", time()-24*60*60), honor = 0}
}
end
self:Initialize()
self:UpdateSavedVariables()
self:UpdateHonor()
end
function HonorHistory:PLAYER_LOGOUT()
HonorHistorySV = H.db
end
function HonorHistory:CHAT_MSG_COMBAT_HONOR_GAIN(msg)
local honor = HonorHistory:FindHonor(msg)
if honor then
H.db["today"].honor = H.db["today"].honor + honor -- add honor here
self:UpdateHonor(honor)
self:Call("UpdateHonor", honor)
end
end
----------------------
-- HELPER
----------------------
function HonorHistory:Call(func, ...)
for _, module in pairs(H.modules) do
module[func](module, ...)
end
end
function HonorHistory:UpdateHonor()
PVPHonor.todayHonor:SetText(H.db["today"] and H.db["today"].honor or 0)
PVPHonor.yesterdayHonor:SetText(H.db["yesterday"] and H.db["yesterday"].honor or 0)
end
function HonorHistory:UpdateSavedVariables()
local dateToday = date("%m/%d/%y")
local dateYesterday = date("%m/%d/%y", time()-24*60*60)
if H.db["today"] and H.db["today"].date ~= dateToday then
H.db["yesterday"] = {
date = H.db["today"].date,
honor = H.db["today"].honor
}
H.db["today"] = { date = dateToday, honor = 0}
end
if H.db["yesterday"] and H.db["yesterday"].date ~= dateYesterday then
H.db["yesterday"] = {
date = dateYesterday,
honor = 0
}
end
self:Call("UpdateSavedVariables", dateToday, dateYesterday)
end
----------------------
-- PATTERN + MATCHER
----------------------
local function createPattern(str)
return str:gsub("(%()", "%%(")
:gsub("(%))", "%%)")
:gsub("(%%s)", ".+")
:gsub("(%%d)", "(.+)")
end
local COMBATLOG_HONORGAIN_pattern = createPattern(COMBATLOG_HONORGAIN)
local COMBATLOG_HONORGAIN_NO_RANK_pattern = createPattern(COMBATLOG_HONORGAIN_NO_RANK)
local COMBATLOG_HONORGAIN_EXHAUSTION1_pattern = createPattern(COMBATLOG_HONORGAIN_EXHAUSTION1)
local COMBATLOG_HONORGAIN_NO_RANK_EXHAUSTION1_pattern = createPattern(COMBATLOG_HONORGAIN_NO_RANK_EXHAUSTION1)
local COMBATLOG_HONORAWARD_pattern = COMBATLOG_HONORAWARD:gsub("(%%d)", "(%%d+)")
function HonorHistory:Extract(str, pattern)
if not pattern or not str then
return nil
end
local find = str_find(str, pattern) and {str_find(str, pattern)} or nil
return find and find[3] and tonumber(find[3]) or nil
end
function HonorHistory:FindHonor(msg)
if not msg then
return nil
end
if HonorHistory:Extract(msg, COMBATLOG_HONORGAIN_pattern) then
return HonorHistory:Extract(msg, COMBATLOG_HONORGAIN_pattern)
end
if HonorHistory:Extract(msg, COMBATLOG_HONORAWARD_pattern) then
return HonorHistory:Extract(msg, COMBATLOG_HONORAWARD_pattern)
end
if HonorHistory:Extract(msg, COMBATLOG_HONORGAIN_EXHAUSTION1_pattern) then
return HonorHistory:Extract(msg, COMBATLOG_HONORGAIN_EXHAUSTION1_pattern)
end
if HonorHistory:Extract(msg, COMBATLOG_HONORGAIN_NO_RANK_EXHAUSTION1_pattern) then
return HonorHistory:Extract(msg, COMBATLOG_HONORGAIN_NO_RANK_EXHAUSTION1_pattern)
end
if HonorHistory:Extract(msg, COMBATLOG_HONORGAIN_NO_RANK_pattern) then
return HonorHistory:Extract(msg, COMBATLOG_HONORGAIN_NO_RANK_pattern)
end
end