2016-01-16 01:26:33 -05:00
|
|
|
|
-----------------------------------
|
|
|
|
|
|
-- switch
|
|
|
|
|
|
-----------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
function switch(c)
|
2022-05-28 18:59:26 +03:00
|
|
|
|
local swtbl =
|
|
|
|
|
|
{
|
2018-05-01 21:53:02 -04:00
|
|
|
|
casevar = c,
|
|
|
|
|
|
caseof = function(self, code)
|
2018-06-22 03:20:06 -04:00
|
|
|
|
local f
|
2022-11-04 10:44:34 -04:00
|
|
|
|
if self.casevar then
|
2018-06-22 03:20:06 -04:00
|
|
|
|
f = code[self.casevar] or code.default
|
2018-05-01 21:53:02 -04:00
|
|
|
|
else
|
2018-06-22 03:20:06 -04:00
|
|
|
|
f = code.missing or code.default
|
2018-05-01 21:53:02 -04:00
|
|
|
|
end
|
2022-11-22 14:42:58 -05:00
|
|
|
|
|
2022-11-04 10:44:34 -04:00
|
|
|
|
if f then
|
2023-08-28 21:02:28 -04:00
|
|
|
|
if type(f) == 'function' then
|
2018-06-22 03:20:06 -04:00
|
|
|
|
return f(self.casevar, self)
|
2018-05-01 21:53:02 -04:00
|
|
|
|
else
|
2023-08-28 21:02:28 -04:00
|
|
|
|
error('case '..tostring(self.casevar)..' not a function')
|
2018-05-01 21:53:02 -04:00
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
2018-06-22 03:20:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
return swtbl
|
|
|
|
|
|
end
|
2016-01-16 01:26:33 -05:00
|
|
|
|
|
|
|
|
|
|
-----------------------------------
|
|
|
|
|
|
-- printf
|
|
|
|
|
|
-----------------------------------
|
|
|
|
|
|
|
2020-07-27 19:35:52 -07:00
|
|
|
|
function printf(s, ...)
|
2018-06-22 03:20:06 -04:00
|
|
|
|
print(s:format(...))
|
|
|
|
|
|
end
|
2016-01-16 01:26:33 -05:00
|
|
|
|
|
2020-02-23 07:05:57 -08:00
|
|
|
|
-----------------------------------
|
|
|
|
|
|
-- set()
|
|
|
|
|
|
-- Returns a set that can be checked against
|
|
|
|
|
|
-----------------------------------
|
|
|
|
|
|
function set(list)
|
|
|
|
|
|
local set = {}
|
|
|
|
|
|
for _, item in pairs(list) do
|
|
|
|
|
|
set[item] = true
|
|
|
|
|
|
end
|
2022-11-22 14:42:58 -05:00
|
|
|
|
|
2020-02-23 07:05:57 -08:00
|
|
|
|
return set
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2018-06-22 03:20:06 -04:00
|
|
|
|
-----------------------------------
|
|
|
|
|
|
-- getVanaMidnight(day)
|
|
|
|
|
|
-- Returns earth time value for midnight for current (or supplied day) in epoch format
|
|
|
|
|
|
-----------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
function getVanaMidnight(day)
|
2025-07-03 21:20:08 -04:00
|
|
|
|
local curtime = GetSystemTime()
|
2025-04-24 07:29:40 -04:00
|
|
|
|
local secondsToMidnight = xi.vanaTime.DAY - (VanadielTime() % xi.vanaTime.DAY)
|
|
|
|
|
|
|
2018-06-22 03:20:06 -04:00
|
|
|
|
if day ~= nil then
|
2025-04-24 07:29:40 -04:00
|
|
|
|
secondsToMidnight = secondsToMidnight + (day * xi.vanaTime.DAY)
|
2018-06-22 03:20:06 -04:00
|
|
|
|
end
|
2022-11-22 14:42:58 -05:00
|
|
|
|
|
2025-04-24 07:29:40 -04:00
|
|
|
|
return curtime + secondsToMidnight
|
2018-06-22 03:20:06 -04:00
|
|
|
|
end
|
2025-11-03 01:16:21 -05:00
|
|
|
|
|
|
|
|
|
|
-----------------------------------
|
|
|
|
|
|
-- getVanadielMoonCycle()
|
|
|
|
|
|
-- Returns the current moon cycle index (0–11) based on Vanadiel moon phase and direction
|
|
|
|
|
|
-----------------------------------
|
|
|
|
|
|
function getVanadielMoonCycle()
|
|
|
|
|
|
local phase = VanadielMoonPhase()
|
|
|
|
|
|
local direction = VanadielMoonDirection()
|
|
|
|
|
|
|
|
|
|
|
|
local moonTable =
|
|
|
|
|
|
{
|
|
|
|
|
|
-- Peak State
|
|
|
|
|
|
[0] =
|
|
|
|
|
|
{
|
|
|
|
|
|
{ 100, xi.moonCycle.FULL_MOON }, -- Full Moon - 100% Full
|
|
|
|
|
|
{ 0, xi.moonCycle.NEW_MOON }, -- New Moon - 0% Full
|
|
|
|
|
|
},
|
|
|
|
|
|
-- Descending
|
|
|
|
|
|
[1] =
|
|
|
|
|
|
{
|
|
|
|
|
|
{ 94, xi.moonCycle.FULL_MOON }, -- Full Moon - 100 to 94%
|
|
|
|
|
|
{ 77, xi.moonCycle.GREATER_WANING_GIBBOUS }, -- Greater Waning Gibbous - 93 to 77%
|
|
|
|
|
|
{ 61, xi.moonCycle.LESSER_WANING_GIBBOUS }, -- Lesser Waning Gibbous - 76 to 61%
|
|
|
|
|
|
{ 41, xi.moonCycle.THIRD_QUARTER }, -- Third Quarter - 60 to 41%
|
|
|
|
|
|
{ 25, xi.moonCycle.GREATER_WANING_CRESCENT }, -- Greater Waning Crescent - 40 to 25%
|
|
|
|
|
|
{ 11, xi.moonCycle.LESSER_WANING_CRESCENT }, -- Lesser Waning Crescent - 24 to 11%
|
|
|
|
|
|
{ 0, xi.moonCycle.NEW_MOON }, -- New Moon - 10 to 0%
|
|
|
|
|
|
},
|
|
|
|
|
|
-- Ascending
|
|
|
|
|
|
[2] =
|
|
|
|
|
|
{
|
|
|
|
|
|
{ 90, xi.moonCycle.FULL_MOON }, -- Full Moon - 100 to 90%
|
|
|
|
|
|
{ 72, xi.moonCycle.GREATER_WAXING_GIBBOUS }, -- Greater Waxing Gibbous - 89 to 72%
|
|
|
|
|
|
{ 56, xi.moonCycle.LESSER_WAXING_GIBBOUS }, -- Lesser Waxing Gibbous - 71 to 56%
|
|
|
|
|
|
{ 39, xi.moonCycle.FIRST_QUARTER }, -- First Quarter - 55 to 39%
|
|
|
|
|
|
{ 22, xi.moonCycle.GREATER_WAXING_CRESCENT }, -- Greater Waxing Crescent - 38 to 22%
|
|
|
|
|
|
{ 6, xi.moonCycle.LESSER_WAXING_CRESCENT }, -- Lesser Waxing Crescent - 21 to 6%
|
|
|
|
|
|
{ 0, xi.moonCycle.NEW_MOON }, -- New Moon - 5 to 0%
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
local directionTable = moonTable[direction]
|
|
|
|
|
|
if not directionTable then
|
|
|
|
|
|
return xi.moonCycle.GREATER_WANING_GIBBOUS -- Greater Waxing Gibbous is the least offensive as base case.
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- Itterate down and trigger on the first matching phase
|
|
|
|
|
|
for _, entry in ipairs(directionTable) do
|
|
|
|
|
|
local threshold, moonCycle = entry[1], entry[2]
|
|
|
|
|
|
if phase >= threshold then
|
|
|
|
|
|
return moonCycle
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return xi.moonCycle.GREATER_WANING_GIBBOUS -- Greater Waxing Gibbous is the least offensive as base case. (Shouldn't be able to hit this.)
|
|
|
|
|
|
end
|