更新发送到功能
更新仇恨计算方式 还在开发 更新其他细节
This commit is contained in:
87
Utils.lua
Normal file
87
Utils.lua
Normal file
@@ -0,0 +1,87 @@
|
||||
local NanamiDPS = NanamiDPS
|
||||
|
||||
function NanamiDPS.round(input, places)
|
||||
if not places then places = 0 end
|
||||
if type(input) == "number" and type(places) == "number" then
|
||||
local pow = 1
|
||||
for i = 1, places do pow = pow * 10 end
|
||||
return floor(input * pow + 0.5) / pow
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
function NanamiDPS.trim(str)
|
||||
if not str then return "" end
|
||||
return gsub(str, "^%s*(.-)%s*$", "%1")
|
||||
end
|
||||
|
||||
function NanamiDPS.spairs(t, order)
|
||||
local keys = {}
|
||||
for k in pairs(t) do
|
||||
table.insert(keys, k)
|
||||
end
|
||||
if order then
|
||||
table.sort(keys, function(a, b) return order(t, a, b) end)
|
||||
else
|
||||
table.sort(keys)
|
||||
end
|
||||
local i = 0
|
||||
return function()
|
||||
i = i + 1
|
||||
if keys[i] then
|
||||
return keys[i], t[keys[i]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local rgbcache = {}
|
||||
function NanamiDPS.str2rgb(text)
|
||||
if not text then return 1, 1, 1 end
|
||||
if rgbcache[text] then return unpack(rgbcache[text]) end
|
||||
local counter = 1
|
||||
local l = string.len(text)
|
||||
for i = 1, l, 3 do
|
||||
counter = mod(counter * 8161, 4294967279) +
|
||||
(string.byte(text, i) * 16776193) +
|
||||
((string.byte(text, i + 1) or (l - i + 256)) * 8372226) +
|
||||
((string.byte(text, i + 2) or (l - i + 256)) * 3932164)
|
||||
end
|
||||
local hash = mod(mod(counter, 4294967291), 16777216)
|
||||
local r = (hash - (mod(hash, 65536))) / 65536
|
||||
local g = ((hash - r * 65536) - (mod((hash - r * 65536), 256))) / 256
|
||||
local b = hash - r * 65536 - g * 256
|
||||
rgbcache[text] = { r / 255, g / 255, b / 255 }
|
||||
return unpack(rgbcache[text])
|
||||
end
|
||||
|
||||
function NanamiDPS.formatNumber(num)
|
||||
if not num then return "0" end
|
||||
if num >= 1000000 then
|
||||
return NanamiDPS.round(num / 1000000, 1) .. "M"
|
||||
elseif num >= 1000 then
|
||||
return NanamiDPS.round(num / 1000, 1) .. "K"
|
||||
end
|
||||
return tostring(math.floor(num))
|
||||
end
|
||||
|
||||
function NanamiDPS.formatTime(seconds)
|
||||
if not seconds or seconds <= 0 then return "0:00" end
|
||||
local m = math.floor(seconds / 60)
|
||||
local s = math.floor(seconds - m * 60)
|
||||
if s < 10 then
|
||||
return m .. ":0" .. s
|
||||
end
|
||||
return m .. ":" .. s
|
||||
end
|
||||
|
||||
function NanamiDPS.GetClassColor(class)
|
||||
if class and RAID_CLASS_COLORS and RAID_CLASS_COLORS[class] then
|
||||
return RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b
|
||||
end
|
||||
return 0.6, 0.6, 0.6
|
||||
end
|
||||
|
||||
NanamiDPS.validClasses = {
|
||||
WARRIOR = true, MAGE = true, ROGUE = true, DRUID = true, HUNTER = true,
|
||||
SHAMAN = true, PRIEST = true, WARLOCK = true, PALADIN = true,
|
||||
}
|
||||
Reference in New Issue
Block a user