模块:ItemInfo:修订间差异
跳转到导航
跳转到搜索
(函数名打错) |
(新增根据id查询索引的功能) |
||
第62行: | 第62行: | ||
end | end | ||
-- | -- 根据物品ID获取物品类别,及索引 | ||
local function queryCategoryById(game, id) | local function queryCategoryById(game, id) | ||
id = tonumber(id) | id = tonumber(id) | ||
第69行: | 第69行: | ||
if id >= 0 and id <= 19 then | if id >= 0 and id <= 19 then | ||
-- 饰品 | -- 饰品 | ||
return '装备', '饰品' | return '装备', '饰品', id + 1 | ||
elseif id >= 20 and id <= 20 + 28 then | elseif id >= 20 and id <= 20 + 28 then | ||
-- 防具 | -- 防具 | ||
return '装备', '防具' | return '装备', '防具', id - 20 + 1 | ||
elseif id >= 49 and id <= 49 + 11 then | elseif id >= 49 and id <= 49 + 11 then | ||
-- 重要 | -- 重要 | ||
return '重要', nil | return '重要', nil, id - 49 + 1 | ||
elseif id >= 61 and id <= 61 + 33 then | elseif id >= 61 and id <= 61 + 33 then | ||
-- 材料(采集) | -- 材料(采集) | ||
return '材料', '采集' | return '材料', '采集', id - 61 + 1 | ||
elseif id >= 95 and id <= 95 + 23 then | elseif id >= 95 and id <= 95 + 23 then | ||
-- 材料(合成) | -- 材料(合成) | ||
return '材料', '合成' | return '材料', '合成', id -95 + 1 | ||
elseif id >= 119 and id <= 119 + 71 then | elseif id >= 119 and id <= 119 + 71 then | ||
-- 使用类物品 | -- 使用类物品 | ||
return '使用', nil | return '使用', nil, id - 119 + 1 | ||
elseif id >= 191 and id <= 191 + 34 then | elseif id >= 191 and id <= 191 + 34 then | ||
-- 武器 | -- 武器 | ||
return '装备', '武器' | return '装备', '武器', id - 191 + 1 | ||
elseif id >= 226 and id <= 226 + 339 then | elseif id >= 226 and id <= 226 + 339 then | ||
-- 葛拉斯诺晶体 | -- 葛拉斯诺晶体 | ||
return '葛拉斯诺晶体', nil | return '葛拉斯诺晶体', nil, id - 226 + 1 | ||
end | end | ||
return nil, '获取数据失败,无效物品ID: ' .. id | return nil, '获取数据失败,无效物品ID: ' .. id | ||
第144行: | 第144行: | ||
function p.generateGrathnodeCrystalList() | function p.generateGrathnodeCrystalList() | ||
local result = {} | local result = {} | ||
local index = mw.loadJsonData('数据:AT1/葛拉斯诺晶体/索引') | |||
for i = 1, 339 do | for i = 1, 339 do | ||
local item = | local item = index[i] | ||
local type = tonumber(item.type) | local type = tonumber(item.type) | ||
第290行: | 第291行: | ||
function p.getItemName(frame) | function p.getItemName(frame) | ||
return getNameById(frame.args[1], frame.args[2]) | return getNameById(frame.args[1], frame.args[2]) | ||
end | |||
function p.getAuxDataLink(frame) | |||
local game = frame.args[1] | |||
local id = frame.args[2] | |||
local category, subcategory, index = queryCategoryById(game, id) | |||
local cate = category | |||
if category == '材料' then | |||
if subcategory == '采集' then | |||
cate = '材料物品' | |||
elseif subcategory == '合成' then | |||
cate = '合成材料' | |||
end | |||
end | |||
return '数据:' .. game .. '/' .. cate .. '/' .. index | |||
end | end | ||
2024年6月8日 (六) 21:42的版本
可在模块:ItemInfo/doc创建此模块的帮助文档
local p = {} local be = require 'Module:BattleEffect' local ci = require 'Module:CardInfo' local ei = require 'Module:EnemyInfo' function p.loadItemInfoByIndex(game, category, index) -- 获取索引(综合数据) local matIdx = mw.loadJsonData('数据:' .. game .. '/' .. category .. '/索引') local itemBase = matIdx[index] local status, data = pcall(mw.loadJsonData, '数据:' .. game .. '/' .. category .. '/' .. index) if status then ret = {} for k, v in pairs(data) do ret[k] = v end for k, v in pairs(itemBase) do ret[k] = v end return ret else return itemBase end end -- 根据物品Id获取物品信息 function p.loadItemById(game, id) id = tonumber(id) if game == 'AT1' then -- id 区间检查 if id >= 0 and id <= 19 then -- 饰品 return p.loadItemInfoByIndex(game, '饰品', id + 1) elseif id >= 20 and id <= 20 + 28 then -- 防具 return p.loadItemInfoByIndex(game, '防具', id - 20 + 1) elseif id >= 49 and id <= 49 + 11 then -- 重要 return p.loadItemInfoByIndex(game, '重要', id - 49 + 1) elseif id >= 61 and id <= 61 + 33 then -- 材料(采集) return p.loadItemInfoByIndex(game, '材料物品', id - 61 + 1) elseif id >= 95 and id <= 95 + 23 then -- 材料(合成) return p.loadItemInfoByIndex(game, '合成材料', id - 95 + 1) elseif id >= 119 and id <= 119 + 71 then -- 使用类物品 return p.loadItemInfoByIndex(game, '使用', id - 119 + 1) elseif id >= 191 and id <= 191 + 34 then -- 武器 return p.loadItemInfoByIndex(game, '武器', id - 191 + 1) elseif id >= 226 and id <= 226 + 339 then -- 葛拉斯诺晶体 return p.loadItemInfoByIndex(game, '葛拉斯诺晶体', id - 226 + 1) end return nil, '获取数据失败,无效物品ID: ' .. id elseif game == 'AT2' then elseif game == 'AT3' then end return nil, '获取数据失败,所指定的游戏不存在' end -- 根据物品ID获取物品类别,及索引 local function queryCategoryById(game, id) id = tonumber(id) if game == 'AT1' then -- id 区间检查 if id >= 0 and id <= 19 then -- 饰品 return '装备', '饰品', id + 1 elseif id >= 20 and id <= 20 + 28 then -- 防具 return '装备', '防具', id - 20 + 1 elseif id >= 49 and id <= 49 + 11 then -- 重要 return '重要', nil, id - 49 + 1 elseif id >= 61 and id <= 61 + 33 then -- 材料(采集) return '材料', '采集', id - 61 + 1 elseif id >= 95 and id <= 95 + 23 then -- 材料(合成) return '材料', '合成', id -95 + 1 elseif id >= 119 and id <= 119 + 71 then -- 使用类物品 return '使用', nil, id - 119 + 1 elseif id >= 191 and id <= 191 + 34 then -- 武器 return '装备', '武器', id - 191 + 1 elseif id >= 226 and id <= 226 + 339 then -- 葛拉斯诺晶体 return '葛拉斯诺晶体', nil, id - 226 + 1 end return nil, '获取数据失败,无效物品ID: ' .. id elseif game == 'AT2' then elseif game == 'AT3' then end return nil, '获取数据失败,所指定的游戏不存在' end -- 根据ID获取物品名 local function getNameById(game, id) local item, err = p.loadItemById(game, id) if err then return err end return item.name end -- 过滤重结晶项 local function recryFilter(recry) local game = 'AT1' local ret = {} if recry == nil then return ret end if recry.s_prod ~= '-1' then ret.s_prod = getNameById(game, recry.s_prod) end if recry.a_prod ~= '-1' then ret.a_prod = getNameById(game, recry.a_prod) end if recry.b_prod ~= '-1' then ret.b_prod = getNameById(game, recry.b_prod) end if recry.c_prod ~= '-1' then ret.c_prod = getNameById(game, recry.c_prod) end return ret end p.gcType = {'#b70000', '#0d57cb', '#139a00', '#9f0087'} local paramNames = {'hp', 'mp', 'atk', 'crit', 'def', 'agi', 'fdef', 'idef', 'tdef', 'wdef', 'fatk', 'iatk', 'tatk', 'watk', 'dmg_max', 'burst_spd', 'gd_resist', 'harmonics'} local paramDisplay = {'HP', 'MP', '攻击力', '暴击率', '防御力', '敏捷', '炎抗性', '冰抗性', '雷抗性', '风抗性', '炎攻击', '冰攻击', '雷攻击', '风攻击', '附加伤害', '爆发速率', 'GD抗性', '谐调强化'} local function checkAndMakeParamList(item) result = {} for i, v in ipairs(paramNames) do if item[v] ~= '0' then table.insert(result, '* ' .. paramDisplay[i] .. ':' .. item[v]) end end return table.concat(result, '\n') end function p.generateGrathnodeCrystalList() local result = {} local index = mw.loadJsonData('数据:AT1/葛拉斯诺晶体/索引') for i = 1, 339 do local item = index[i] local type = tonumber(item.type) -- 之后要替换为图片及标题的::before元素,提供更好的视觉效果 local icon = '<span style="background-color: ' .. p.gcType[type + 1] .. '; padding: 0 .25em; color: white">' .. item.level .. '</span>' local section = '==' .. item.name .. '==\n' .. item.desc local html = mw.html.create('table'):addClass('wikitable') html:tag('tr') :tag('th'):wikitext('类型'):done() :tag('th'):wikitext('品质'):done() :tag('th'):wikitext('GD'):done() :tag('th'):wikitext('价格'):done() :tag('th'):wikitext('稀有度'):done() :tag('th'):wikitext(be.getBattleEffectById('AT1', item.eff_key)):done() html:tag('tr') :tag('th'):wikitext(icon):done() :tag('td'):wikitext(item.quality):done() :tag('td'):wikitext(item.gd):done() :tag('td'):wikitext(string.sub(item.price, 0, -2)):done() :tag('td'):wikitext(item.rarity):done() :tag('td'):wikitext(item.eff_val):done() local list = checkAndMakeParamList(item) table.insert(result, section .. tostring(html) .. '\n' .. list) end return table.concat(result, '\n') end local function makeArgumentOfParameter(args, para) for i, v in ipairs(paramNames) do args[paramDisplay[i]] = para[v] end end local function generateArguments(item, category, subcategory) local filteredRecrystalisation = recryFilter(item.recry) local arguments = { ["物品名"] = item.name, ["图像"] = item.img, ["原文"] = item.ori, ["类别"] = category, ["子类别"] = subcategory, ["游戏"] = 'AT1', ["重结晶S"] = filteredRecrystalisation.s_prod, ["重结晶A"] = filteredRecrystalisation.a_prod, ["重结晶B"] = filteredRecrystalisation.b_prod, ["重结晶C"] = filteredRecrystalisation.c_prod, ["其他来源"] = item.alt_src, ["笔记"] = item.desc, ["特殊效果"] = item.effect } if item.base ~= nil then arguments["卖价"] = item.base.sell_price end if item.para ~= nil then makeArgumentOfParameter(arguments, item.para) end if item.base.synthesisable == '1' then arguments["配方"] = ci.getRecipeCardNameById(item.base.rc_id) end if item.src ~= nil then for i = 1, 5 do if item.src[i] ~= nil then arguments['来源' .. i .. '/类别'] = item.src[i].type if item.src[i].type == '敌' then arguments['来源' .. i .. '/详细'] = ei.getFoeInfoById('AT1', item.src[i].desc).name else arguments['来源' .. i .. '/详细'] = item.src[i].desc end end end end if item.item_use_this ~= nil then for i = 1, 12 do arguments['合成用途' .. i] = item.item_use_this[i] end end if item.naming ~= nil then arguments["欧莉卡命名"] = item.naming.orica arguments["弥纱命名"] = item.naming.misya arguments["修蕾莉亚命名"] = item.naming.syureria end if item.material ~= nil then for i = 1, 4 do arguments['材料' .. i] = item.material[i] end end if item.powered_slots ~= nil then local slots = '' for i = 1, 4 do if item.powered_slots[i] == '1' then slots = slots .. i end end arguments["强化槽位"] = slots end return arguments end -- 生成物品基本信息的方法,使用模板“物品信息” -- type:采集/合成 function p.at1ItemInfo(category, subcategory, index) local catName = category if category == '装备' then catName = subcategory else if subcategory == '合成' then catName = '合成材料' elseif subcategory == '采集' then catName = '材料物品' end end local item = p.loadItemInfoByIndex('AT1', catName, index) local arguments = generateArguments(item, category, subcategory) return mw.getCurrentFrame():expandTemplate { title = '物品信息', args = arguments } end -- AT1 物品信息卡(按ID) function p.makeAt1ItemInfo(frame) local id = frame.args[1] local item, err = p.loadItemById('AT1', id) if err ~= nil then return '获取物品数据出错:' .. err end local cat, subcat = queryCategoryById('AT1', id) local arguments = generateArguments(item, cat, subcat) return mw.getCurrentFrame():expandTemplate { title = '物品信息', args = arguments } end function p.getItemName(frame) return getNameById(frame.args[1], frame.args[2]) end function p.getAuxDataLink(frame) local game = frame.args[1] local id = frame.args[2] local category, subcategory, index = queryCategoryById(game, id) local cate = category if category == '材料' then if subcategory == '采集' then cate = '材料物品' elseif subcategory == '合成' then cate = '合成材料' end end return '数据:' .. game .. '/' .. cate .. '/' .. index end -- 列表生成相关函数 function p.listArmorsInAt1() local html = mw.html.create('table'):addClass('wikitable') html:tag('tr') :tag('th'):wikitext('ID'):done() :tag('th'):wikitext('索引'):done() :tag('th'):wikitext('名称'):done() :tag('th'):wikitext('卖价'):done() :tag('th'):wikitext('配方'):done() local baseIndex = 19 for i = 1, 29 do local item = p.loadItemInfoByIndex('AT1', '防具', i) local recipe = '-' if item.base.synthesisable ~= '0' then recipe = ci.getRecipeCardNameById(item.base.rc_id) end html:tag('tr') :tag('td'):wikitext(tostring(baseIndex + i)):done() :tag('td'):wikitext(tostring(i)):done() :tag('td'):wikitext('[[攻略:AT1/物品/' .. item.name .. '|' .. item.name .. ']]'):done() :tag('td'):wikitext(tostring(item.base.sell_price)):done() :tag('td'):wikitext(recipe):done() end return tostring(html) end function p.listWeaponsInAt1() local html = mw.html.create('table'):addClass('wikitable') html:tag('tr') :tag('th'):wikitext('ID'):done() :tag('th'):wikitext('索引'):done() :tag('th'):wikitext('名称'):done() :tag('th'):wikitext('卖价'):done() :tag('th'):wikitext('配方'):done() local baseIndex = 190 for i = 1, 35 do local item = p.loadItemInfoByIndex('AT1', '武器', i) local recipe = '-' if item.base.synthesisable ~= '0' then recipe = ci.getRecipeCardNameById(item.base.rc_id) end html:tag('tr') :tag('td'):wikitext(tostring(baseIndex + i)):done() :tag('td'):wikitext(tostring(i)):done() :tag('td'):wikitext('[[攻略:AT1/物品/' .. item.name .. '|' .. item.name .. ']]'):done() :tag('td'):wikitext(tostring(item.base.sell_price)):done() :tag('td'):wikitext(recipe):done() end return tostring(html) end function p.listAccessoriesInAt1() local html = mw.html.create('table'):addClass('wikitable') html:tag('tr') :tag('th'):wikitext('ID'):done() :tag('th'):wikitext('索引'):done() :tag('th'):wikitext('名称'):done() :tag('th'):wikitext('卖价'):done() :tag('th'):wikitext('配方'):done() local baseIndex = -1 for i = 1, 20 do local item = p.loadItemInfoByIndex('AT1', '饰品', i) local recipe = '-' if item.base.synthesisable ~= '0' then recipe = ci.getRecipeCardNameById(item.base.rc_id) end html:tag('tr') :tag('td'):wikitext(tostring(baseIndex + i)):done() :tag('td'):wikitext(tostring(i)):done() :tag('td'):wikitext('[[攻略:AT1/物品/' .. item.name .. '|' .. item.name .. ']]'):done() :tag('td'):wikitext(tostring(item.base.sell_price)):done() :tag('td'):wikitext(recipe):done() end return tostring(html) end function p.listMaterialsInAt1() local html = mw.html.create('table'):addClass('wikitable') html:tag('tr') :tag('th'):wikitext('ID'):done() :tag('th'):wikitext('索引'):done() :tag('th'):wikitext('名称'):done() :tag('th'):wikitext('卖价'):done() :tag('th'):wikitext('配方'):done() local baseIndex = 60 for i = 1, 34 do local item = p.loadItemInfoByIndex('AT1', '材料物品', i) local recipe = '-' if item.base.synthesisable ~= '0' then recipe = ci.getRecipeCardNameById(item.base.rc_id) end html:tag('tr') :tag('td'):wikitext(tostring(baseIndex + i)):done() :tag('td'):wikitext(tostring(i)):done() :tag('td'):wikitext('[[攻略:AT1/物品/' .. item.name .. '|' .. item.name .. ']]'):done() :tag('td'):wikitext(tostring(item.base.sell_price)):done() :tag('td'):wikitext(recipe):done() end return tostring(html) end function p.listMelcMaterialsInAt1() local html = mw.html.create('table'):addClass('wikitable') html:tag('tr') :tag('th'):wikitext('ID'):done() :tag('th'):wikitext('索引'):done() :tag('th'):wikitext('名称'):done() :tag('th'):wikitext('卖价'):done() :tag('th'):wikitext('配方'):done() local baseIndex = 94 for i = 1, 24 do local item = p.loadItemInfoByIndex('AT1', '合成材料', i) local recipe = '-' if item.base.synthesisable ~= '0' then recipe = ci.getRecipeCardNameById(item.base.rc_id) end html:tag('tr') :tag('td'):wikitext(tostring(baseIndex + i)):done() :tag('td'):wikitext(tostring(i)):done() :tag('td'):wikitext('[[攻略:AT1/物品/' .. item.name .. '|' .. item.name .. ']]'):done() :tag('td'):wikitext(tostring(item.base.sell_price)):done() :tag('td'):wikitext(recipe):done() end return tostring(html) end function p.listKeysInAt1() local html = mw.html.create('table'):addClass('wikitable') html:tag('tr') :tag('th'):wikitext('ID'):done() :tag('th'):wikitext('索引'):done() :tag('th'):wikitext('名称'):done() :tag('th'):wikitext('卖价'):done() :tag('th'):wikitext('配方'):done() local baseIndex = 48 for i = 1, 12 do local item = p.loadItemInfoByIndex('AT1', '重要', i) local recipe = '-' if item.base.synthesisable ~= '0' then recipe = ci.getRecipeCardNameById(item.base.rc_id) end html:tag('tr') :tag('td'):wikitext(tostring(baseIndex + i)):done() :tag('td'):wikitext(tostring(i)):done() :tag('td'):wikitext('[[攻略:AT1/物品/' .. item.name .. '|' .. item.name .. ']]'):done() :tag('td'):wikitext(tostring(item.base.sell_price)):done() :tag('td'):wikitext(recipe):done() end return tostring(html) end function p.listUseInAt1() local html = mw.html.create('table'):addClass('wikitable') html:tag('tr') :tag('th'):wikitext('ID'):done() :tag('th'):wikitext('索引'):done() :tag('th'):wikitext('名称'):done() :tag('th'):wikitext('卖价'):done() :tag('th'):wikitext('配方'):done() local baseIndex = 118 for i = 1, 72 do local item = p.loadItemInfoByIndex('AT1', '使用', i) local recipe = '-' if item.base.synthesisable ~= '0' then recipe = ci.getRecipeCardNameById(item.base.rc_id) end html:tag('tr') :tag('td'):wikitext(tostring(baseIndex + i)):done() :tag('td'):wikitext(tostring(i)):done() :tag('td'):wikitext('[[攻略:AT1/物品/' .. item.name .. '|' .. item.name .. ']]'):done() :tag('td'):wikitext(tostring(item.base.sell_price)):done() :tag('td'):wikitext(recipe):done() end return tostring(html) end return p