Module:Aichan:修订间差异
(bruh bruh bruh) |
(lasteternity 已修复(已测试游戏本体行为)) |
||
(未显示2个用户的7个中间版本) | |||
第1行: | 第1行: | ||
local getArgs = require | local getArgs = require 'Module:Arguments'.getArgs | ||
local mad = require 'Module:AnotherData' | local mad = require 'Module:AnotherData' | ||
local | local songlist = mad.listOf 'songs' | ||
local | local p = {} | ||
function initRandomizer(seed) | function initRandomizer(seed) | ||
local x, y, z = seed, seed, seed | |||
return function() | |||
x, y, z = (171 * x) % 30269, (172 * y) % 30307, (170 * z) % 30323 | |||
return (x / 30269 + y / 30307 + z / 30323) % 1 | |||
end | |||
end | end | ||
function | function isAvailable(song) | ||
return not song.deleted and song.id ~= 'lasteternity' | |||
-- 禁用删除曲和 lasteternity ( 已经测试为游戏本体当前行为) | |||
end | |||
return | |||
function isFree(song) | |||
return song.set=='base' or song.id=='innocence' | |||
end | end | ||
第33行: | 第36行: | ||
-- time: unix时间戳 | -- time: unix时间戳 | ||
-- date: YYYY/MM/DD格式的时间, 按这一天的北京时间12:30算 | -- date: YYYY/MM/DD格式的时间, 按这一天的北京时间12:30算 | ||
-- | -- 优先级: time > date > 读取当前时间 | ||
-- delay: 在得到的时间基础上再往后若干天 | |||
-- 建议用time={#timel函数}代替,例如: | |||
-- time={{#timel:U|@1713172637+12hours}} | |||
-- -- |time=1713172637 | |||
-- time={{#timel:U|2023-05-16+57days 12hours}} | |||
-- -- |date=2023/05/16|delay=57 | |||
-- limit: 假设songlist只保留前limit项(用于模拟过去) | |||
local time = args['time'] or dateStringToTime(args['date']) or os.time() | local time = args['time'] or dateStringToTime(args['date']) or os.time() | ||
local | time=time+86400*(args['delay'] or 0) | ||
local rand = initRandomizer(math.floor((time-144e2)/864e2)) | |||
local length=5000 | local length=5000 | ||
local arr={} | local arr={} | ||
第43行: | 第55行: | ||
end | end | ||
for i=length-1,1,-1 do | for i=length-1,1,-1 do | ||
local r= | local r=rand() | ||
local swapPos=math.floor(r*i) | local swapPos=math.floor(r*i) | ||
arr[i],arr[swapPos] = arr[swapPos],arr[i] | |||
end | end | ||
local | |||
local | local resultFree={} | ||
local | local currentFreeCount=0 | ||
local | local resultPaid={} | ||
local songSize= | local currentPaidCount=0 | ||
local songSize=tonumber(args['limit']) or #songlist | |||
local next=length | |||
for i=0,length-1,1 do | for i=0,length-1,1 do | ||
if | if currentFreeCount+currentPaidCount>=3 then break end | ||
local value=arr[i] | local value=arr[i] | ||
if value<songSize then | if value<songSize then | ||
local info=songlist[value+1] | local info=songlist[value+1] | ||
if info | if isAvailable(info) then | ||
if | if isFree(info) then | ||
if currentFreeCount<1 then | |||
currentFreeCount=currentFreeCount+1 | |||
resultFree[currentFreeCount]=info | |||
end | |||
else | |||
if currentPaidCount<2 then | |||
currentPaidCount=currentPaidCount+1 | |||
resultPaid[currentPaidCount]=info | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
local result | |||
if resultPaid[1].date<resultPaid[2].date then | |||
result={resultFree[1],resultPaid[1],resultPaid[2]} | |||
else | |||
result={resultFree[1],resultPaid[2],resultPaid[1]} | |||
end | |||
local frame = mw.getCurrentFrame() | local frame = mw.getCurrentFrame() | ||
local text = mw.html.create 'div' | local text = mw.html.create 'div' | ||
第84行: | 第103行: | ||
end | end | ||
text = text:wikitext(frame:expandTemplate {title = '组排列-end'}):done() | text = text:wikitext(frame:expandTemplate {title = '组排列-end'}):done() | ||
return text | return text | ||
end | end | ||
return p | return p |
2024年10月11日 (五) 15:15的最新版本
可在Module:Aichan/doc创建此模块的帮助文档
local getArgs = require 'Module:Arguments'.getArgs
local mad = require 'Module:AnotherData'
local songlist = mad.listOf 'songs'
local p = {}
function initRandomizer(seed)
local x, y, z = seed, seed, seed
return function()
x, y, z = (171 * x) % 30269, (172 * y) % 30307, (170 * z) % 30323
return (x / 30269 + y / 30307 + z / 30323) % 1
end
end
function isAvailable(song)
return not song.deleted and song.id ~= 'lasteternity'
-- 禁用删除曲和 lasteternity (已经测试为游戏本体当前行为)
end
function isFree(song)
return song.set=='base' or song.id=='innocence'
end
function dateStringToTime(date)
if date==nil then return nil end
local y,m,d = string.match(date, "([^/]+)/([^/]+)/([^/]+)")
return os.time({year=y,month=m,day=d,hour=12,min=30});
end
function p.main(frame)
local args = getArgs(frame)
return p._main(args)
end
function p._main(args)
-- args:
-- time: unix时间戳
-- date: YYYY/MM/DD格式的时间, 按这一天的北京时间12:30算
-- 优先级: time > date > 读取当前时间
-- delay: 在得到的时间基础上再往后若干天
-- 建议用time={#timel函数}代替,例如:
-- time={{#timel:U|@1713172637+12hours}}
-- -- |time=1713172637
-- time={{#timel:U|2023-05-16+57days 12hours}}
-- -- |date=2023/05/16|delay=57
-- limit: 假设songlist只保留前limit项(用于模拟过去)
local time = args['time'] or dateStringToTime(args['date']) or os.time()
time=time+86400*(args['delay'] or 0)
local rand = initRandomizer(math.floor((time-144e2)/864e2))
local length=5000
local arr={}
for i=0,length-1,1 do
arr[i]=i
end
for i=length-1,1,-1 do
local r=rand()
local swapPos=math.floor(r*i)
arr[i],arr[swapPos] = arr[swapPos],arr[i]
end
local resultFree={}
local currentFreeCount=0
local resultPaid={}
local currentPaidCount=0
local songSize=tonumber(args['limit']) or #songlist
local next=length
for i=0,length-1,1 do
if currentFreeCount+currentPaidCount>=3 then break end
local value=arr[i]
if value<songSize then
local info=songlist[value+1]
if isAvailable(info) then
if isFree(info) then
if currentFreeCount<1 then
currentFreeCount=currentFreeCount+1
resultFree[currentFreeCount]=info
end
else
if currentPaidCount<2 then
currentPaidCount=currentPaidCount+1
resultPaid[currentPaidCount]=info
end
end
end
end
end
local result
if resultPaid[1].date<resultPaid[2].date then
result={resultFree[1],resultPaid[1],resultPaid[2]}
else
result={resultFree[1],resultPaid[2],resultPaid[1]}
end
local frame = mw.getCurrentFrame()
local text = mw.html.create 'div'
text=text:wikitext(frame:expandTemplate {title = '组排列', args = {height = 'auto'}})
for i=1,3,1 do
local id=result[i].id
local title=result[i].title_localized.en
local link=mad.linkName(result[i]) or title
text:wikitext(frame:expandTemplate {title = '组排单元', args = {title,id,link=link}})
end
text = text:wikitext(frame:expandTemplate {title = '组排列-end'}):done()
return text
end
return p