forked from TheOneReed/MobsToLevel
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMobsToLevel.lua
97 lines (88 loc) · 2.51 KB
/
MobsToLevel.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
----------------------------------------------------------------
-- EVTCalendar
-- Author: Reed
--
--
----------------------------------------------------------------
previousMobs = {};
killTimes = {};
function M2L_OnLoad()
this:RegisterEvent("ADDON_LOADED");
this:RegisterEvent("PLAYER_XP_UPDATE");
this:RegisterEvent("CHAT_MSG_COMBAT_XP_GAIN");
end
function M2L_OnEvent()
if event == "CHAT_MSG_COMBAT_XP_GAIN" then
if string.find(arg1, "(.+) dies") then
local _, _, killedMob, XPGain = string.find(arg1, "(.+) dies, you gain (%d+) experience.");
if GetXPExhaustion() then
table.insert(previousMobs, math.floor(XPGain/2));
table.insert(killTimes,time());
else
table.insert(previousMobs, math.floor(XPGain));
table.insert(killTimes,time());
end
if table.getn(previousMobs) > 3 then
table.remove(previousMobs, 1);
end
if table.getn(killTimes) > 10 then
table.remove(killTimes, 1);
end
M2L_Calc(XPGain);
end
elseif event == "PLAYER_XP_UPDATE" then
M2L_Calc();
end
end
function M2L_Calc(XPGain)
local restToGo, killsToGo;
local avgXP = 0;
if not XPGain then
XPGain = 0;
end
local restXP = GetXPExhaustion();
local curXP = UnitXP("player") + XPGain;
local maxXP = UnitXPMax("player");
if restXP then
for _,x in pairs(previousMobs) do
avgXP = avgXP + x;
end
avgXP = avgXP / table.getn(previousMobs);
if restXP > (maxXP - curXP) then
killsToGo = (maxXP - curXP)/(avgXP*2);
M2LString:SetText(killsToGo);
else
restToGo = (restXP / avgXP);
killsToGo = (maxXP - curXP - restXP)/(avgXP);
killsToGo = math.ceil((killsToGo + restToGo));
M2LString:SetText(killsToGo);
end
else
for _,x in pairs(previousMobs) do
avgXP = avgXP + x;
end
avgXP = avgXP / table.getn(previousMobs);
killsToGo = math.ceil((maxXP - curXP)/avgXP);
M2LString:SetText(killsToGo);
end
local timeStamp = 0;
local timeDifferences = {};
for _,x in pairs(killTimes) do
if (table.getn(killTimes) > _) then
table.insert(timeDifferences,((killTimes[_+1] - x)));
end
end
for _,x in pairs(timeDifferences) do
timeStamp = timeStamp + x;
end
timeStamp = timeStamp / table.getn(timeDifferences);
timeStamp = timeStamp * killsToGo;
M2LTimeString:SetText(tostring(date('%H:%M:%S',timeStamp)));
end
function M2L_print(str, err)
if err == nil then
DEFAULT_CHAT_FRAME:AddMessage("|c00FFFF00MobsToLevel: " .. tostring(str) .. "|r");
else
DEFAULT_CHAT_FRAME:AddMessage("|c00FFFF00MobsToLevel:|r " .. "|c00FF0000Error|r|c006969FF - " .. tostring(str) .. "|r");
end
end