模块:ItemInfo:修订间差异
跳转到导航
跳转到搜索
小
更新材料自动化
(优化读取) |
小 (更新材料自动化) |
||
第4行: | 第4行: | ||
local ci = require 'Module:CardInfo' | local ci = require 'Module:CardInfo' | ||
local ei = require 'Module:EnemyInfo' | local ei = require 'Module:EnemyInfo' | ||
local function getIdByCategoryAndIndex(game, category, index) | |||
if game == 'AT1' then | |||
local baseId = { | |||
['饰品'] = 0, | |||
['防具'] = 20, | |||
['重要'] = 49, | |||
['材料物品'] = 61, | |||
['合成材料'] = 95, | |||
['使用'] = 119, | |||
['武器'] = 191, | |||
['葛拉斯诺晶体'] = 226 | |||
} | |||
local categoryStartId = baseId[category] | |||
if categoryStartId then | |||
return categoryStartId + index - 1 | |||
else | |||
error("无效的物品类别: " .. tostring(category)) | |||
end | |||
end | |||
end | |||
local function getAt1MelcInfo(id) | |||
local recipes = mw.loadJsonData('数据:AT1/调合配方') | |||
local ret = {} | |||
ret.item_use_this = {} | |||
for i, recipe in ipairs(recipes) do | |||
if tonumber(recipe.id) == id then | |||
local mat = {} | |||
for i = 1, 4 do | |||
mat[i] = tonumber(recipe['mat'..i]) | |||
if mat[i] == -1 then mat[i] = nil end | |||
if mat[i] == 226 then mat[i] = -1 end | |||
end | |||
local nam = {} | |||
if recipe['orica-naming'] ~= '' then nam.orica = recipe['orica-naming'] end | |||
if recipe['misya-naming'] ~= '' then nam.misya = recipe['misya-naming'] end | |||
if recipe['shurelia-naming'] ~= '' then nam.shurelia = recipe['shurelia-naming'] end | |||
ret.material = mat | |||
ret.naming = nam | |||
else | |||
for i = 1, 4 do | |||
if tonumber(recipe['mat'..i]) == id then | |||
table.insert(ret.item_use_this, recipe['id']) | |||
end | |||
end | |||
end | |||
end | |||
return ret | |||
end | |||
function p.loadItemInfoByIndex(game, category, index) | function p.loadItemInfoByIndex(game, category, index) | ||
local id = getIdByCategoryAndIndex(game, category, index) | |||
-- 获取索引(综合数据) | -- 获取索引(综合数据) | ||
local matIdx = mw.loadJsonData('数据:' .. game .. '/' .. category .. '/索引') | local matIdx = mw.loadJsonData('数据:' .. game .. '/' .. category .. '/索引') | ||
local itemBase = matIdx[index] | local itemBase = matIdx[index] | ||
local status, data = pcall(mw.loadJsonData, '数据:' .. game .. '/' .. category .. '/' .. index) | local status, data = pcall(mw.loadJsonData, '数据:' .. game .. '/' .. category .. '/' .. index) | ||
local melc = getAt1MelcInfo(id) | |||
if status then | if status then | ||
ret = {} | ret = {} | ||
第18行: | 第76行: | ||
ret[k] = v | ret[k] = v | ||
end | end | ||
for k, v in pairs(melc) do | |||
ret[k] = v | |||
end | |||
ret.id = id | |||
return ret | return ret | ||
else | else | ||
return | ret = {} | ||
for k, v in pairs(itemBase) do | |||
ret[k] = v | |||
end | |||
for k, v in pairs(melc) do | |||
ret[k] = v | |||
end | |||
ret.id = id | |||
return ret | |||
end | end | ||
end | end |