|
local _G = _G |
|
local TL, TC, TR = 'TOPLEFT', 'TOP', 'TOPRIGHT' |
local ML, MC, MR = 'LEFT', 'CENTER', 'RIGHT' |
local BL, BC, BR = 'BOTTOMLEFT', 'BOTTOM', 'BOTTOMRIGHT' |
|
local eventframe = CreateFrame('Frame') |
local outputframe = _G.ChatFrame1 |
local eventframe = CreateFrame('Frame') |
|
local old = UnitXP('player') |
local out = '' |
local ExperienceLeft |
local ExperienceGain |
local RepetitionsNeeded |
local ExperienceRested |
|
local update |
local onevent |
local print |
local getExperienceLeft |
local Print |
local PLAYER_XP_UPDATE |
local PLAYER_LEVEL_UP |
local OnEvent |
|
function update () |
local xp, max = UnitXP('player'), UnitXPMax('player') |
local gained = xp - old |
function getExperienceLeft () |
return UnitXPMax('player') - UnitXP('player') |
end |
|
function Print () |
local rested = GetXPExhaustion() |
old = xp |
if rested and rested > 0 then |
rested = ' ('..math.ceil(GetXPExhaustion()/(UnitXPMax('player') - UnitXP('player'))*100)..'% rested)' |
if rested then |
outputframe:AddMessage(('%s / %s = %s (%s %s%%)'):format(ExperienceLeft, ExperienceGain, RepetitionsNeeded, rested, math.floor(rested*100/ExperienceLeft))) |
else |
rested = '' |
outputframe:AddMessage(ExperienceLeft..' / '..ExperienceGain..' = '..RepetitionsNeeded) |
end |
out = ('%s / %s = %s%s'):format(max - xp, gained, math.ceil((max - xp) / gained), rested) |
print() |
end |
|
function onevent (frame, event, ...) |
function PLAYER_XP_UPDATE () |
ExperienceGain = ExperienceLeft - getExperienceLeft() |
ExperienceLeft = getExperienceLeft() |
RepetitionsNeeded = math.ceil(ExperienceLeft / ExperienceGain) |
Print() |
end |
|
function PLAYER_LEVEL_UP () |
ExperienceLeft = getExperienceLeft() |
ExperienceGain = 0 |
RepetitionsNeeded = 0 |
end |
|
function OnEvent (frame, event, ...) |
ChatFrame1:AddMessage('DEBUG: '..event) |
if event == 'PLAYER_XP_UPDATE' then |
update() |
PLAYER_XP_UPDATE() |
elseif event == 'PLAYER_LEVEL_UP' then |
PLAYER_LEVEL_UP() |
end |
end |
|
function print () |
outputframe:AddMessage(out) |
end |
ExperienceLeft = getExperienceLeft() |
ExperienceGain = 0 |
RepetitionsNeeded = 0 |
|
eventframe:SetScript('OnEvent', onevent) |
SlashCmdList['IDEXPERIENCE_PRINTXP'] = Print |
SLASH_IDEXPERIENCE_PRINTXP1 = '/xp' |
|
eventframe:SetScript('OnEvent', OnEvent) |
eventframe:RegisterEvent('PLAYER_XP_UPDATE') |
eventframe:RegisterEvent('PLAYER_LEVEL_UP') |
|
SlashCmdList['IDEXPERIENCE_PRINTXP'] = print |
SLASH_IDEXPERIENCE_PRINTXP1 = '/xp' |
_G.idExperience = addon |
|