全站通知:
模块:数据库调用-敌人
刷
历
编
跳到导航
跳到搜索
此模块的文档可以在模块:数据库调用-敌人/doc创建
local p = {}
-- 加载指定页面
local getJsonPage = require('模块:数据库-敌人')
-- 基础参数
function EnemyInfo_Base(frame, data)
-- 敌人标号
frame:callParserFunction{
name = '#vardefine',
args = {'敌人标号', data.idName}
}
-- 阵营
frame:callParserFunction{
name = '#vardefine',
args = {'阵营', data.camp}
}
-- 分类
frame:callParserFunction{
name = '#vardefine',
args = {'分类', data['type']}
}
-- 类型
local enemysort
if data['sort'] == "BOSS" then
enemysort = "强大敌对目标"
end
if data['sort'] == "精英" then
enemysort = "精英敌对目标"
end
if data['sort'] == "小怪" then
enemysort = "一般敌对目标"
end
frame:callParserFunction{
name = '#vardefine',
args = {'类型', enemysort}
}
local ability = split(data.ability,"、")
local count = 1
for i in pairs(ability) do
frame:callParserFunction{
name = '#vardefine',
args = {'特性'..tostring(count), ability[count]}
}
count = count + 1
end
count = 1
local resistance = split(data.resistance,",")
for i in pairs(resistance) do
frame:callParserFunction{
name = '#vardefine',
args = {'抗性'..tostring(count), resistance[count]}
}
count = count + 1
end
count = 1
local resistanceNum = split(data.resistanceNum,",")
for i in pairs(resistanceNum) do
frame:callParserFunction{
name = '#vardefine',
args = {'抗性数值'..tostring(count), resistanceNum[count]}
}
count = count + 1
end
count = 1
local weakness = split(data.weakness,",")
for i in pairs(weakness) do
frame:callParserFunction{
name = '#vardefine',
args = {'弱点'..tostring(count), weakness[count]}
}
count = count + 1
end
count = 1
local weaknessNum = split(data.weaknessNum,",")
for i in pairs(weaknessNum) do
frame:callParserFunction{
name = '#vardefine',
args = {'弱点数值'..tostring(count), weaknessNum[count]}
}
count = count + 1
end
count = 1
-- 掉落
frame:callParserFunction{
name = '#vardefine',
args = {'掉落', data.drop}
}
-- 简述
frame:callParserFunction{
name = '#vardefine',
args = {'简述', data.info}
}
-- 描述
frame:callParserFunction{
name = '#vardefine',
args = {'描述', data.des}
}
-- 描述
frame:callParserFunction{
name = '#vardefine',
args = {'描述', data.des}
}
local actionSkillName = split(data.actionSkillName,"、")
for i in pairs(actionSkillName) do
frame:callParserFunction{
name = '#vardefine',
args = {'主动技名称'..tostring(count), actionSkillName[count]}
}
count = count + 1
end
count = 1
local actionSkillDes = split(data.actionSkillDes,"*")
for i in pairs(actionSkillDes) do
frame:callParserFunction{
name = '#vardefine',
args = {'主动技描述'..tostring(count), actionSkillDes[count]}
}
count = count + 1
end
count = 1
local passivSkillName = split(data.passivSkillName,"、")
for i in pairs(passivSkillName) do
frame:callParserFunction{
name = '#vardefine',
args = {'被动技名称'..tostring(count), passivSkillName[count]}
}
count = count + 1
end
count = 1
local passivSkillDes = split(data.passivSkillDes,"*")
for i in pairs(passivSkillDes) do
frame:callParserFunction{
name = '#vardefine',
args = {'被动技描述'..tostring(count), passivSkillDes[count]}
}
count = count + 1
end
end
-- 等级面板
function EnemyInfo_Value(frame, data)
-- 设置用于计算的值
frame:callParserFunction{
name = '#vardefine',
args = {'数值-基础', data.value}
}
frame:callParserFunction{
name = '#vardefine',
args = {'数值-成长', data.valueG}
}
frame:callParserFunction{
name = '#vardefine',
args = {'攻击评分', split(data.valueScore,",")[2]}
}
frame:callParserFunction{
name = '#vardefine',
args = {'生命评分', split(data.valueScore,",")[1]}
}
frame:callParserFunction{
name = '#vardefine',
args = {'防御评分', split(data.valueScore,",")[3]}
}
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.Enemy(frame)
-- 获取输入角色名
local input = frame.args["name"]
local cacheJson = {}
cacheJson = getJsonPage.enemy
for i, data in ipairs(cacheJson) do
if input == data.name then -- 数据已确认,开始填充
EnemyInfo_Base(frame, data)
EnemyInfo_Value(frame, data)
break
end
end
end
-- 角色筛选项/一览版本
function p.EnemyFilterItemList(frame)
-- 新建输出对象
local output = ""
local cacheJson = getJsonPage.enemy
for i, data in ipairs(cacheJson) do
local formattedData = p.setEnemyData(data)
output = output ..
frame:expandTemplate{
title = '敌人筛选/一览',
args = formattedData
}
end
return output
end
-- 设置敌人行所需内容
function p.setEnemyData(data)
-- 创建输出对象
local formattedData = {}
local tag
-- 指定键值对,对应data参数
formattedData["1"] = data["name"]
formattedData["2"] = data["idName"]
formattedData["3"] = data["type"]
formattedData["4"] = data["camp"]
formattedData["5"] = data["sort"]
formattedData["6"] = split(data["valueScore"],",")[1]
formattedData["7"] = split(data["valueScore"],",")[2]
formattedData["8"] = split(data["valueScore"],",")[3]
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 -- 返回包含函数和数据的导出表