-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.lua
More file actions
94 lines (81 loc) · 4.16 KB
/
core.lua
File metadata and controls
94 lines (81 loc) · 4.16 KB
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
-- TODO: Add show/hide toggle command
local lastTime = 0;
local lastRested = 0;
local restedRate = 0;
local LeftText = MainMenuExpBar:CreateFontString("ExperienceLeft", "OVERLAY", "GameTooltipText")
LeftText:SetFont("Fonts\\ARIALN.TTF", 12, "THINOUTLINE")
LeftText:SetPoint("LEFT", 10, 2)
LeftText:SetTextColor(1,1,1,1)
local RestedFrame = CreateFrame("Frame")
RestedFrame:RegisterEvent("ADDON_LOADED")
RestedFrame:RegisterEvent("PLAYER_XP_UPDATE")
RestedFrame:RegisterEvent("PLAYER_LEVEL_UP")
RestedFrame:RegisterEvent("UPDATE_EXHAUSTION")
RestedFrame:RegisterEvent("UNIT_PET")
RestedFrame:RegisterEvent("UNIT_PET_EXPERIENCE")
-- Suggested events from the `XPBarText` AddOn
RestedFrame:RegisterEvent("ZONE_CHANGED")
RestedFrame:RegisterEvent("ZONE_CHANGED_NEW_AREA")
RestedFrame:RegisterEvent("PLAYER_CONTROL_LOST")
RestedFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
RestedFrame:RegisterEvent("PLAYER_LEAVING_WORLD")
RestedFrame:RegisterEvent("CINEMATIC_START")
RestedFrame:RegisterEvent("CINEMATIC_STOP")
RestedFrame:SetScript("OnEvent", function()
if event == "ADDON_LOADED" and arg1 == "Rested" then
DEFAULT_CHAT_FRAME:AddMessage("[|cFF0ABCDERested|r] v" .. GetAddOnMetadata("Rested","Version"))
UpdateXPBarText()
elseif event == "PLAYER_XP_UPDATE" or event == "PLAYER_LEVEL_UP" or event == "UPDATE_EXHAUSTION" or event == "UNIT_PET" and arg1 == "player" or event == "UNIT_PET_EXPERIENCE" or event == "ZONE_CHANGED" or event == "ZONE_CHANGED_NEW_AREA" or event == "PLAYER_CONTROL_LOST" or event == "CINEMATIC_START" or event == "CINEMATIC_STOP" or event == "PLAYER_ENTERING_WORLD" then
UpdateXPBarText()
end
end)
function UpdateXPBarText()
local playerLevel = UnitLevel("player")
local restedXP = GetXPExhaustion() or 0
local isResting = IsResting()
local nextLevelXP = tonumber(UnitXPMax("player"))
-- local currentXP = tonumber(UnitXP("player"))
-- local xpleft = nextLevelXP - currentXP
local maxRest = nextLevelXP * 1.5
local restedPercent = tonumber(string.format("%.2f", restedXP / maxRest * 100)) or 0
local isRested = (restedPercent == 100)
-- local timeToFullRested = GetTimeToWellRested() or 0
if playerLevel < 60 then
if restedXP then
local txtRemainingTime = ""
if isResting and restedPercent < 100 then
local currentTime = GetTime() or 0;
local timeDelta = currentTime - lastTime;
local currentRested = GetXPExhaustion() or 0;
local restedDelta = currentRested - lastRested;
if timeDelta < 10 and restedDelta > 0 then
txtRemainingTime = " "
restedRate = (restedRate + (restedDelta / timeDelta)) / 2
-- restedRate = restedDelta / timeDelta
local remaingSeconds = (maxRest - restedXP) / restedRate;
if remaingSeconds > 60 then
local remainingMinutes = remaingSeconds / 60;
if remainingMinutes > 60 then
txtRemainingTime = txtRemainingTime .. math.floor(remainingMinutes / 60) .. "h left"
else
-- txtRemainingTime = txtRemainingTime .. math.floor(remaingSeconds / 60) .. "m " .. remaingSeconds % 60 .. "s left"
-- txtRemainingTime = txtRemainingTime .. math.floor(remaingSeconds / 60) .. "m " .. math.mod(remaingSeconds, 60) .. "s left"
txtRemainingTime = txtRemainingTime .. math.floor(remainingMinutes) .. "m left"
end
else
txtRemainingTime = txtRemainingTime .. "< 1m left"
end
end
lastTime = currentTime;
lastRested = currentRested;
else
restedRate = 0;
end
LeftText:SetText("Rested XP: " .. restedXP .. " / " .. maxRest .. " (|cFF0ABCDE" .. restedPercent .. "%|r)" .. txtRemainingTime)
else
LeftText:SetText("")
end
elseif playerLevel == 60 then
LeftText:SetTextColor(1,1,1,0)
end
end