全站通知:
模块:Shop
刷
历
编
跳到导航
跳到搜索
此模块的文档可以在模块:Shop/doc创建
local p = {}
-- 定义角色顺序
local characterOrder = {"沈星回", "黎深", "祁煜", "秦彻","夏以昼"}
local shop5Card = {
["沈星回"] = {"时光碎片","毛绒陷阱","流光轻跃","时光碎片","毛绒陷阱","流光轻跃","时光碎片","毛绒陷阱","流光轻跃","时光碎片","毛绒陷阱","流光轻跃"},
["黎深"] = {"余温过午","失序", "眷眷余晖", "余温过午","失序", "眷眷余晖", "余温过午","失序", "眷眷余晖", "余温过午","失序", "眷眷余晖"},
["祁煜"] = {"隐秘日出","闻香", "花落未夏", "隐秘日出","闻香", "花落未夏", "隐秘日出","闻香", "花落未夏", "隐秘日出","闻香", "花落未夏"},
["秦彻"] = {"方寸盈余","无效禁锢", "飞羽向夜", "方寸盈余","无效禁锢", "飞羽向夜", "方寸盈余","无效禁锢", "飞羽向夜", "方寸盈余","无效禁锢", "飞羽向夜"},
["夏以昼"] = {"限定余味","暗潮边缘", "无尽夏","限定余味","暗潮边缘", "无尽夏","限定余味","暗潮边缘", "无尽夏","限定余味","暗潮边缘", "无尽夏"}
}
-- 获取当前月份
local function getCurrentMonth()
if mw and mw.getContentLanguage then
local lang = mw.getContentLanguage()
return tonumber(lang:formatDate('n'))
else
return tonumber(os.date('%m'))
end
end
-- 新增函数:根据角色名获取当前上架卡片
function p.getCurrentCard(frame)
-- 获取传入的角色名参数
local characterName = frame.args[1]
-- 检查角色是否存在
if not shop5Card[characterName] then
return "错误:未找到角色 " .. characterName
end
-- 获取当前月份
local currentMonth = getCurrentMonth()
-- 返回该角色当前月份的卡片
return shop5Card[characterName][currentMonth]
end
-- 新增函数:获取指定角色的上/下月卡片
function p.getAdjacentCard(frame)
-- 获取传入的参数
local characterName = frame.args[1] -- 角色名
local direction = frame.args[2] -- "last" 或 "next"
-- 参数检查
if not characterName or not direction then
return "错误:参数不完整"
end
-- 检查角色是否存在
if not shop5Card[characterName] then
return "错误:未找到角色 " .. characterName
end
-- 检查方向参数是否有效
if direction ~= "last" and direction ~= "next" then
return "错误:第二个参数必须是 last 或 next"
end
-- 获取当前月份
local currentMonth = getCurrentMonth()
-- 计算目标月份
local targetMonth
if direction == "last" then
targetMonth = currentMonth - 1
if targetMonth < 1 then
targetMonth = 12
end
else -- direction == "next"
targetMonth = currentMonth + 1
if targetMonth > 12 then
targetMonth = 1
end
end
-- 返回对应的卡片
return shop5Card[characterName][targetMonth]
end
-- 新增函数:获取月份序列
function p.getMonth(frame)
local type = frame.args[1]
frame.args[1] = frame.args[2] or characterOrder[1] --重构frame方便调用p内函数
-- 参数检查
if not type then
return "错误:参数不完整"
end
local currentMonth = getCurrentMonth()
local months = {}
if type == "cur" then
-- 获取当前卡片
local currentCard = p.getCurrentCard(frame)
-- 查找当前卡片在 shop5Card 中的位置
for month, card in ipairs(shop5Card[frame.args[1]]) do
if card == currentCard then
table.insert(months, month .. "月")
end
end
elseif type == "next" then
-- 获取下个月的卡片
frame.args[2] = "next"
local nextCard = p.getAdjacentCard(frame)
-- 查找下个月卡片在 shop5Card 中的位置
for month, card in ipairs(shop5Card[frame.args[1]]) do
if card == nextCard then
table.insert(months, month .. "月")
end
end
elseif type == "last" then
-- 获取上个月的卡片
frame.args[2] = "last"
local lastCard = p.getAdjacentCard(frame)
-- 查找上个月卡片在 shop5Card 中的位置
for month, card in ipairs(shop5Card[frame.args[1]]) do
if card == lastCard then
table.insert(months, month .. "月")
end
end
end
-- 返回月份序列
return table.concat(months, ",")
end
return p