全站通知:
模块:数据库调用-乘员
刷
历
编
跳到导航
跳到搜索
local p = {}
-- 加载指定页面
local getJsonPage = require('模块:数据库-乘员')
local getJsonPage_audio = require('模块:数据库-乘员/音频')
-- 基础参数
function RoleInfo_Base(frame, data)
-- 稀有度
frame:callParserFunction{
name = '#vardefine',
args = {'稀有度', data.rarity}
}
-- 站位
frame:callParserFunction{name = '#vardefine', args = {'站位', data.row}}
-- 技能1
frame:callParserFunction{
name = '#vardefine',
args = {'技能1', data.skill1_name}
}
-- 技能2
frame:callParserFunction{
name = '#vardefine',
args = {'技能2', data.skill2_name}
}
-- 得意技能
frame:callParserFunction{
name = '#vardefine',
args = {'得意技能', data.skill3_name}
}
-- 便当
frame:callParserFunction{name = '#vardefine', args = {'便当', data.bento}}
-- 便当加值
frame:callParserFunction{
name = '#vardefine',
args = {'便当加值', data.bentoAdd}
}
-- 便当保质期
frame:callParserFunction{
name = '#vardefine',
args = {'便当保质期', data.bentoValidity}
}
-- 便当便签
frame:callParserFunction{
name = '#vardefine',
args = {'便当便签', data.bentoMemo}
}
end
-- 等级和默契度面板
function RoleInfo_Value(frame, data)
-- 设置用于计算的值
frame:callParserFunction{
name = '#vardefine',
args = {'数值-基础', data.lv1Value}
}
frame:callParserFunction{
name = '#vardefine',
args = {'数值-成长', data.valueGrowth}
}
frame:callParserFunction{
name = '#vardefine',
args = {'数值-默契', data.tacit1Value}
}
-- 等级1数值
frame:callParserFunction{
name = '#vardefine',
args = {'等级1数值', data.lv1Value}
}
-- 等级1数值
frame:callParserFunction{
name = '#vardefine',
args = {'等级7数值', data.lv7Value}
}
-- 等级1数值
frame:callParserFunction{
name = '#vardefine',
args = {'等级14数值', data.lv14Value}
}
-- 等级1数值
frame:callParserFunction{
name = '#vardefine',
args = {'等级21数值', data.lv21Value}
}
-- 等级1数值
frame:callParserFunction{
name = '#vardefine',
args = {'等级28数值', data.lv28Value}
}
-- 等级1数值
frame:callParserFunction{
name = '#vardefine',
args = {'等级35数值', data.lv35Value}
}
-- 等级1数值
frame:callParserFunction{
name = '#vardefine',
args = {'等级60数值', data.lv60Value}
}
-- 默契度1数值
frame:callParserFunction{
name = '#vardefine',
args = {'默契度1数值', data.tacit1Value}
}
-- 默契度2数值
frame:callParserFunction{
name = '#vardefine',
args = {'默契度2数值', data.tacit2Value}
}
-- 默契度3数值
frame:callParserFunction{
name = '#vardefine',
args = {'默契度3数值', data.tacit3Value}
}
-- 默契度4数值
frame:callParserFunction{
name = '#vardefine',
args = {'默契度4数值', data.tacit4Value}
}
-- 默契度5数值
frame:callParserFunction{
name = '#vardefine',
args = {'默契度5数值', data.tacit5Value}
}
-- 默契度6数值
frame:callParserFunction{
name = '#vardefine',
args = {'默契度6数值', data.tacit6Value}
}
-- 默契度7数值
frame:callParserFunction{
name = '#vardefine',
args = {'默契度7数值', data.tacit7Value}
}
-- 默契度8数值
frame:callParserFunction{
name = '#vardefine',
args = {'默契度8数值', data.tacit8Value}
}
-- 默契度9数值
frame:callParserFunction{
name = '#vardefine',
args = {'默契度9数值', data.tacit9Value}
}
-- 默契度10数值
frame:callParserFunction{
name = '#vardefine',
args = {'默契度10数值', data.tacit10Value}
}
end
-- 养成(共振+觉醒)
function RoleInfo_Development(frame, data)
-- 共振1名称
frame:callParserFunction{
name = '#vardefine',
args = {'共振1名称', data.syntony1}
}
-- 共振1描述
frame:callParserFunction{
name = '#vardefine',
args = {'共振1描述', data.syntony1_info}
}
-- 共振2名称
frame:callParserFunction{
name = '#vardefine',
args = {'共振2名称', data.syntony2}
}
-- 共振2描述
frame:callParserFunction{
name = '#vardefine',
args = {'共振2描述', data.syntony2_info}
}
-- 共振4名称
frame:callParserFunction{
name = '#vardefine',
args = {'共振4名称', data.syntony4}
}
-- 共振4描述
frame:callParserFunction{
name = '#vardefine',
args = {'共振4描述', data.syntony4_info}
}
-- 共振5名称
frame:callParserFunction{
name = '#vardefine',
args = {'共振5名称', data.syntony5}
}
-- 共振5描述
frame:callParserFunction{
name = '#vardefine',
args = {'共振5描述', data.syntony5_info}
}
-- 生活技能1名称
frame:callParserFunction{
name = '#vardefine',
args = {'生活技能1名称', data.livingSkill1}
}
-- 生活技能1描述
frame:callParserFunction{
name = '#vardefine',
args = {'生活技能1描述', data.livingSkill1_info}
}
-- 生活技能2名称
frame:callParserFunction{
name = '#vardefine',
args = {'生活技能2名称', data.livingSkill2}
}
-- 生活技能2描述
frame:callParserFunction{
name = '#vardefine',
args = {'生活技能2描述', data.livingSkill2_info}
}
-- 生活技能+名称
frame:callParserFunction{
name = '#vardefine',
args = {'生活技能+名称', data.livingSkill5}
}
-- 生活技能+描述
frame:callParserFunction{
name = '#vardefine',
args = {'生活技能+描述', data.livingSkill5_info}
}
-- 觉醒1名称
frame:callParserFunction{
name = '#vardefine',
args = {'觉醒1名称', data.Awakening1}
}
-- 觉醒1描述
frame:callParserFunction{
name = '#vardefine',
args = {'觉醒1描述', data.Awakening1_info}
}
-- 觉醒2名称
frame:callParserFunction{
name = '#vardefine',
args = {'觉醒2名称', data.awakening2}
}
-- 觉醒2描述
frame:callParserFunction{
name = '#vardefine',
args = {'觉醒2描述', data.awakening2_info}
}
local atk_info = "攻击力+"
local def_info = "防御力+"
local info3 = ""
local info4 = ""
if data.rarity == "SSR" then
atk_info = atk_info .. "150"
def_info = def_info .. "150"
elseif data.rarity == "SR" then
atk_info = atk_info .. "100"
def_info = def_info .. "100"
elseif data.rarity == "R" then
atk_info = atk_info .. "60"
def_info = def_info .. "60"
elseif data.rarity == "N" then
atk_info = atk_info .. "40"
def_info = def_info .. "40"
end
if data.awakening3 == "强韧" then
info3 = def_info
elseif data.awakening3 == "斗志" then
info3 = atk_info
end
if data.awakening4 == "强韧" then
info4 = def_info
elseif data.awakening4 == "斗志" then
info4 = atk_info
end
-- 觉醒3名称
if data.awakening3 == "药师" then
info3 = "治疗量+20%"
end
frame:callParserFunction{
name = '#vardefine',
args = {'觉醒3名称', data.awakening3}
}
-- 觉醒3描述
frame:callParserFunction{
name = '#vardefine',
args = {'觉醒3描述', info3}
}
-- 觉醒4名称
frame:callParserFunction{
name = '#vardefine',
args = {'觉醒4名称', data.awakening4}
}
-- 觉醒4描述
frame:callParserFunction{
name = '#vardefine',
args = {'觉醒4描述', info4}
}
-- 觉醒5名称
frame:callParserFunction{
name = '#vardefine',
args = {'觉醒5名称', data.awakening5}
}
-- 觉醒5描述
frame:callParserFunction{
name = '#vardefine',
args = {'觉醒5描述', data.awakening5_info}
}
end
-- 档案
function RoleInfo_Record(frame, data)
-- 中文名
frame:callParserFunction{
name = '#vardefine',
args = {'中文名', data.name}
}
-- 英文名
frame:callParserFunction{
name = '#vardefine',
args = {'英文名', data.name_en}
}
-- 中文声优
frame:callParserFunction{
name = '#vardefine',
args = {'中文声优', data.cv_zh}
}
-- 日文声优
frame:callParserFunction{
name = '#vardefine',
args = {'日文声优', data.cv_jp}
}
-- 生日
frame:callParserFunction{
name = '#vardefine',
args = {'生日', data.birthday}
}
-- 性别
frame:callParserFunction{
name = '#vardefine',
args = {'性别', data.gender}
}
-- 身高
frame:callParserFunction{
name = '#vardefine',
args = {'身高', data.r_height}
}
-- 升构能力
frame:callParserFunction{
name = '#vardefine',
args = {'升构能力', data.structure}
}
-- 出身地
frame:callParserFunction{
name = '#vardefine',
args = {'出身地', data.hometown}
}
-- 现身份
frame:callParserFunction{
name = '#vardefine',
args = {'现身份', data.identity}
}
-- 势力
frame:callParserFunction{
name = '#vardefine',
args = {'势力', data.factions}
}
-- 自我介绍
frame:callParserFunction{
name = '#vardefine',
args = {'自我介绍', data.selfIntroduction}
}
-- 经历
frame:callParserFunction{
name = '#vardefine',
args = {'经历', data.resume}
} -- 档案1
frame:callParserFunction{
name = '#vardefine',
args = {'档案1', data.archives1}
} -- 档案2
frame:callParserFunction{
name = '#vardefine',
args = {'档案2', data.archives2}
} -- 档案3
frame:callParserFunction{
name = '#vardefine',
args = {'档案3', data.archives3}
} -- 档案4
frame:callParserFunction{
name = '#vardefine',
args = {'档案4', data.archives4}
} -- 特长
frame:callParserFunction{
name = '#vardefine',
args = {'特长', data.specialty}
} -- 喜爱
frame:callParserFunction{
name = '#vardefine',
args = {'喜爱', data.favourite}
} -- 厌恶
frame:callParserFunction{
name = '#vardefine',
args = {'厌恶', data.abomination}
} -- 更新档案 圣剑波克士专属
frame:callParserFunction{
name = '#vardefine',
args = {'更新档案', data.updateArchives}
}
end
-- 角色语音
function RoleInfo_Audio(frame, data)
frame:callParserFunction{
name = '#vardefine',
args = {'中文名', data.name}
}
-- 循环获取音频文本
for i = 1, 21 do
local loopIndex = string.format("%02d", i) -- 格式化为两位数,不足的补零
frame:callParserFunction{
name = '#vardefine',
args = {'audio_' .. loopIndex, data['audio_' .. loopIndex]}
}
end
end
-- 角色皮肤语音
function RoleSkinInfo_Audio(frame, data)
frame:callParserFunction{
name = '#vardefine',
args = {'中文名', data.name}
}
-- 循环获取音频文本
for i = 1, 15 do
local loopIndex = string.format("%02d", i) -- 格式化为两位数,不足的补零
frame:callParserFunction{
name = '#vardefine',
args = {'audio_' .. loopIndex, data['audio_' .. loopIndex]}
}
end
end
-- 从数据转换到筛选标签
function DataToFilterTag(data)
local outputStr = "" -- 将outputStr定义为一个字符串
-- 将"、"替换为逗号
data = string.gsub(data, "、", ",")
-- 循环每个数组执行下一步
for word in string.gmatch(data, "[^,]+") do
outputStr = outputStr .. word .. ","
end
-- 去掉最后一个逗号
outputStr = string.sub(outputStr, 1, -2)
return outputStr
end
-- 从数据转换到链接文本
function DataToLinkText(data, LineFeed)
-- 新建输出项
local outputStr = ""
if not LineFeed then LineFeed = false end
-- 将"、"替换为逗号
data = string.gsub(data, "、", ",")
-- 循环每个数组执行下一步
for item in string.gmatch(data, "[^,]+") do
outputStr = outputStr .. "[[" .. item .. "]]"
if LineFeed == true then
outputStr = outputStr .. "<br>"
else
outputStr = outputStr .. "、"
end
end
if LineFeed == true then
-- 去掉最后一个<br>
outputStr = string.sub(outputStr, 1, -5)
else
-- 去掉最后一个顿号
outputStr = string.sub(outputStr, 1, -4)
end
return outputStr
end
-- 角色获取
function p.Role(frame)
-- 获取输入角色名
local input = frame.args["name"]
local cacheJson = {}
cacheJson = getJsonPage.role
for i, data in ipairs(cacheJson) do
if input == data.name then -- 数据已确认,开始填充
RoleInfo_Base(frame, data)
RoleInfo_Value(frame, data)
RoleInfo_Development(frame, data)
RoleInfo_Record(frame, data)
break
end
end
cacheJson = getJsonPage_audio.roleAudio
for i, data in ipairs(cacheJson) do
if input == data.name then -- 数据已确认,开始填充
RoleInfo_Audio(frame, data)
break
end
end
end
-- 角色皮肤台词获取
function p.SkinAudio(frame)
-- 获取输入皮肤名
local input = frame.args["SkinName"]
local cacheJson = {}
cacheJson = getJsonPage_audio.skinAudio
for i, data in ipairs(cacheJson) do
if input == data.skin_name then -- 数据已确认,开始填充
RoleSkinInfo_Audio(frame, data)
break
end
end
end
-- 获取角色值行
function p.GetValueLine(frame)
-- 新建输出对象
local output = ""
-- 获取输入角色名
local type = frame.args["type"]
local level = tonumber(frame.args["level"])
if type == "等级" then
-- 设置用于计算的值
local valueBase = toFloatArray(split(
frame:callParserFunction{
name = '#var',
args = {'数值-基础'}
}, ","))
local valueGrowth = toFloatArray(split(
frame:callParserFunction{
name = '#var',
args = {'数值-成长'}
}, ","))
output = "<td>" ..
string.format("%.1f",
valueBase[1] + valueGrowth[1] * (level - 1)) ..
"</td><td>" ..
string.format("%.1f",
valueBase[2] + valueGrowth[2] * (level - 1)) ..
"</td><td>" ..
string.format("%.1f",
valueBase[2] + valueGrowth[2] * (level - 1)) ..
"</td>"
elseif type == "默契" then
local valuetacit = toFloatArray(split(
frame:callParserFunction{
name = '#var',
args = {'数值-默契'}
}, ","))
output = "<td>" .. string.format("%.1f", valuetacit[1] * level) ..
"</td><td>" .. string.format("%.1f", valuetacit[2] * level) ..
"</td><td>" .. string.format("%.1f", valuetacit[3] * level) ..
"</td>"
end
return output
end
-- 角色筛选项
function p.RoleFilterItem(frame)
-- 新建输出对象
local output = ""
local cacheJson = getJsonPage.role
for i, data in ipairs(cacheJson) do
local formattedData = p.setRoleItemData(data)
output = output ..
frame:expandTemplate{
title = '乘员筛选/列表',
args = formattedData
}
end
return output
end
-- 角色筛选项/一览版本
function p.RoleFilterItemList(frame)
-- 新建输出对象
local output = ""
local cacheJson = getJsonPage.role
for i, data in ipairs(cacheJson) do
local formattedData = p.setRoleItemData(data)
output = output ..
frame:expandTemplate{
title = '乘员筛选/一览',
args = formattedData
}
end
return output
end
-- 设置角色行所需内容
function p.setRoleItemData(data)
-- 创建输出对象
local formattedData = {}
local tag
-- 指定键值对,对应data参数
formattedData["1"] = data["name"]
formattedData["2"] = data["rarity"]
formattedData["3"] = data["gender"]
formattedData["4"] = data["row"]
formattedData["5"] = data["factions"]
if data["fightExTag"] ~= "" then
tag = data["fightTag"].."、"..data["fightExTag"]
else
tag = data["fightTag"]
end
formattedData["6"] = DataToLinkText(tag)
formattedData["getTag"] = DataToFilterTag(tag)
formattedData["7"] = DataToLinkText(data["livingSkillType"])
formattedData["8"] = DataToFilterTag(data["livingSkillType"])
formattedData["9"] = getSkillColor(data["skill1_name"],"一")
formattedData["10"] = getSkillColor(data["skill2_name"],"二")
formattedData["11"] = getSkillColor(data["skill3_name"],"三")
formattedData["12"] = data["name_en"]
if data["gender"] == "女(?)" or data["gender"] == "不详" then
formattedData["13"] = "不详"
else
formattedData["13"] = data["gender"]
end
return formattedData
end
-- 单独获取技能颜色
function getSkillColor(name, number)
-- 获取输入技能名
local outputStr = ""
local cacheJson = {}
-- 从全局变量getJsonPage中获取技能信息
cacheJson = getJsonPage.skill
-- 遍历技能信息数组
for i, data in ipairs(cacheJson) do
-- 如果输入技能名匹配,则开始处理
if name == data.name then
-- 格式化数据
outputStr="[[文件:" .. data.skillColor .."-技能" .. number ..".png|link=]]"
break
end
end
return outputStr
end
-- 技能调用 因无法处理衍生卡的问题,所以更换新的方式
function p.Skill(frame)
-- 获取输入技能名
local input = frame.args["name"]
local type = frame.args["type"]
-- 检查输入参数是否存在
if not type then
type = "" -- 如果不存在参数 i,则设置一个默认值
end
local outputStr = ""
local cacheJson = {}
-- 从全局变量getJsonPage中获取技能信息
cacheJson = getJsonPage.skill
-- 遍历技能信息数组
for i, data in ipairs(cacheJson) do
-- 如果输入技能名匹配,则开始处理
if input == data.name then
-- 格式化数据
local formattedData = p.formatSkillData(frame, data)
-- 扩展模板并拼接到输出字符串中
outputStr = outputStr .. frame:expandTemplate{
title = '乘员图鉴/技能' .. type,
args = formattedData
}
-- 将"、"替换为逗号
data.derivedCard = string.gsub(data.derivedCard, "、", ",")
-- 拆分 derivedCard 字符串并循环处理
for derived in string.gmatch(data.derivedCard, "[^,]+") do
for i, data in ipairs(cacheJson) do
-- 如果衍生技能匹配,则开始处理
if derived == data.name then
-- 格式化数据
local formattedData = p.formatSkillData(frame, data)
formattedData["衍生"] = "是"
-- 扩展模板并拼接到输出字符串中
outputStr = outputStr .. frame:expandTemplate{
title = '乘员图鉴/技能' .. type,
args = formattedData
}
break
end
end
end
break
end
end
return outputStr
end
-- 技能参数
function p.formatSkillData(frame, data)
local formattedData = {}
-- 指定键值对,而不是循环
formattedData["名称"] = data["name"]
formattedData["角色"] = data["vestIn"]
formattedData["费用"] = data["cost"]
formattedData["张数"] = data["num"]
formattedData["描述"] = data["describe"]
formattedData["引用词缀"] = data["affix"]
formattedData["队长技条件"] = data["captainCondition"]
formattedData["颜色"] = data["skillColor"]
if data['num3'] ~= "" or data['cost3'] ~= ""then
if data['describe3Stage'] == "" then
data['describe3Stage'] = "共振"
data['describe3'] = data['describe']
end
end
if data['num2'] ~= "" or data['cost2'] ~= ""then
if data['describe2Stage'] == "" then
data['describe2Stage'] = "觉醒"
data['describe2'] = data['describe']
end
end
if data['describe2Stage'] ~= "" or data['describe3Stage'] ~= "" then
formattedData["阶段提升"] = "是"
end
if data['describe2Stage'] ~= "" then
formattedData["觉醒提升"] = data['describe2Stage']
formattedData["觉醒描述"] = data['describe2']
if data['num2'] ~= "" then
formattedData["觉醒张数"] = data['num2']
else
formattedData["觉醒张数"] = data["num"]
end
if data['cost2'] ~= "" then
formattedData["觉醒费用"] = data['cost2']
else
formattedData["觉醒费用"] = data["cost"]
end
end
if data['describe3Stage'] ~= "" then
formattedData["共振提升"] = data['describe3Stage']
formattedData["共振描述"] = data['describe3']
if data['describe3_2Stage'] ~= nil and data['describe3_2Stage'] ~= "" then
formattedData["共振提升2"] = data['describe3_2Stage']
formattedData["共振描述2"] = data['describe3_2']
end
if data['num3'] ~= "" then
formattedData["共振张数"] = data['num3']
else
formattedData["共振张数"] = data["num"]
end
if data['cost3'] ~= "" then
formattedData["共振费用"] = data['cost3']
else
formattedData["共振费用"] = data["cost"]
end
end
if data['describe2Stage'] ~= "" and data['describe3Stage'] ~= "" then
formattedData["全部提升"] = "是"
formattedData["全部描述"] = data['describe4']
if data['num2'] ~= "" then
formattedData["全部张数"] = data['num2']
else
if data['num3'] ~= "" then
formattedData["全部张数"] = data['num3']
else
formattedData["全部张数"] = data['num']
end
end
if data['cost2'] ~= "" then
formattedData["全部费用"] = data['cost2']
else
if data['cost3'] ~= "" then
formattedData["全部费用"] = data['cost3']
else
formattedData["全部费用"] = data['cost']
end
end
end
return formattedData
end
-- 分割字符串函数
function split(str, sep)
local result = {}
for match in (str .. sep):gmatch("(.-)" .. sep) do
table.insert(result, match)
end
return result
end
-- 将字符串转换为浮点数的函数
function toFloatArray(strArray)
local result = {}
for _, str in ipairs(strArray) do table.insert(result, tonumber(str)) end
return result
end
return p -- 返回包含函数和数据的导出表