此模块的文档可以在Module:List/doc创建
local p = {}
local ship_data = mw.loadData('Module:ship.data')
local slotitem_data = mw.loadData('Module:slotitem.data')
local spd = {[5]='低', [10]='高', [0]='-', ['']='?'}
local leng = {'短', '中', '長', '超長', [0]='-'}
function sortDesc(a, b) return b[1] < a[1] end
function sortAsc(a, b) return b[1] > a[1] end
function p.ship(frame)
local cat = frame.args[1] or 1
local stype = frame.args[2] or 0
local res = {}
local ship_idx = {}
if cat == '' then cat = 1 end
if stype == '' then stype = 0 end
if frame.args[2] == nil or frame.args[2] == '' then frame.args[2] = 0 end
res[#res+1] = '<table border="0" cellpadding="1" cellspacing="1" class="wikitable sortable mw-datatable" style="font-size:14px; line-height:22px;"><tr><th>編號</th><th>艦名</th><th>艦種</th><th>耐力</th><th>火力</th><th>裝甲</th><th>雷裝</th><th>迴避</th><th>對空</th><th>搭載</th><th>對潛</th><th>速力</th><th>索敵</th><th>射程</th><th>運氣</th><th>裝備</th><th>燃料</th><th>彈藥</th></tr>'
for key, value in pairs(ship_data) do
local res_tmp = {}
local sortkey
-- repeat
i = 2
local sid = 0
if ship_data[key][1] ~= '' then sid = ship_data[key][1] end
if (math.ceil(sid/(sid+1)) == cat*1 or cat*1 == -1)
and (ship_data[key][4] == frame.args[i]*1 or stype*1 == 0) then
if ship_data[key][1] == '' then
res_tmp[#res_tmp+1] = '<tr><td data-sort-value="' .. key+200000 .. '">-</td>'
sortkey = key+200000
else
res_tmp[#res_tmp+1] = '<tr><td data-sort-value="' .. ship_data[key][1]+100000 .. '">' .. string.format('%03d', ship_data[key][1]) .. '</td>'
sortkey = ship_data[key][1]+100000
end
res_tmp[#res_tmp+1] = '<td>[[' .. ship_data[key][2] .. ']]</td>'
res_tmp[#res_tmp+1] = '<td>' .. ship_data[key][4] .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. ship_data[key][7] .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. ship_data[key][12] .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. ship_data[key][10] .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. ship_data[key][14] .. '</td>'
res_tmp[#res_tmp+1] = '<td>?</td>'
res_tmp[#res_tmp+1] = '<td>' .. ship_data[key][16] .. '</td>'
if ship_data[key][1] == '' then
res_tmp[#res_tmp+1] = '<td></td>'
else
res_tmp[#res_tmp+1] = '<td>' .. ship_data[key][22] .. '/' .. ship_data[key][23] .. '/' .. ship_data[key][24] .. '/' .. ship_data[key][25] .. '</td>'
end
res_tmp[#res_tmp+1] = '<td>?</td>'
res_tmp[#res_tmp+1] = '<td>' .. spd[ship_data[key][19]] .. '</td>'
res_tmp[#res_tmp+1] = '<td>?</td>'
if ship_data[key][20] == '' then
res_tmp[#res_tmp+1] = '<td></td>'
else
res_tmp[#res_tmp+1] = '<td>' .. leng[ship_data[key][20]] .. '</td>'
end
res_tmp[#res_tmp+1] = '<td>' .. ship_data[key][18] .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. ship_data[key][21] .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. ship_data[key][40] .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. ship_data[key][41] .. '</td></tr>'
end
ship_idx[#ship_idx+1] = {sortkey, table.concat(res_tmp)}
i = i + 1
-- until frame.args[i] == nil or frame.args[i] == ''
end
table.sort(ship_idx, sortAsc)
for _, value in ipairs(ship_idx) do
res[#res+1] = value[2]
end
res[#res+1] = '</table>'
return table.concat(res)
end
function p.slotitem(frame)
local cat1 = frame.args[1] or 1
local cat2 = frame.args['type'] or 0 --type
local rare = frame.args[2] or -1
local res = {}
local sitem_idx = {}
local slotitem_type = mw.loadData('Module:slotitem.type')
if cat1 == '' then cat1 = 1 end
if cat2 == '' then cat2 = 0 end
if rare == '' then rare = -1 end
local str_split = function(s, p)
local rt = {}
string.gsub(s, '[^'..p..']+', function(w) table.insert(rt,w) end )
return rt
end
local si_type = str_split(cat2,',')
res[#res+1] = '<table border="0" cellpadding="1" cellspacing="1" class="wikitable sortable mw-datatable" style="width:100%; text-align:center; font-size:14px; line-height:22px;"><tr><th style="width:40px;">編號</th><th>名稱</th><th style="width:100px;">類別</th><th style="width:30px;">[[File:Icon_Range.png|18px|link=]]</th><th style="width:30px;">[[File:Icon_Gun.png|18px|link=]]</th><th style="width:30px;">[[File:Icon_AA.png|18px|link=]]</th><th style="width:30px;">[[File:Icon_ASW.png|18px|link=]]</th><th style="width:30px;">[[File:Icon_Torpedo.png|18px|link=]]</th><th style="width:30px;">[[File:Icon_Dive.png|18px|link=]]</th><th style="width:30px;">[[File:Icon_Hit.png|18px|link=]]</th><th style="width:30px;">[[File:Icon_LOS.png|18px|link=]]</th><th style="width:30px;">[[File:Icon_Evasion.png|18px|link=]]</th><th style="width:30px;">[[File:Icon_Armor.png|18px|link=]]</th></tr>'
for key, value in pairs(slotitem_data) do
local res_tmp = {}
if (math.ceil(value[1]/(value[1]+1)) == cat1*1 or cat1*1 == -1)
and (value[25] == rare*1 or rare*1 == -1) then
for j=1,#si_type do
if cat2 == 0 or value[5] == si_type[j]*1 then
if value[1] == 0 then
res_tmp[#res_tmp+1] = '<tr><td data-sort-value="' .. key .. '">-</td>'
else
res_tmp[#res_tmp+1] = '<tr><td data-sort-value="' .. key .. '">' .. string.format('%03d', value[1]) .. '</td>'
end
res_tmp[#res_tmp+1] = '<td style="text-align:left;">[[' .. value[2] .. ']]</td>'
res_tmp[#res_tmp+1] = '<td>' .. slotitem_type[value[5]] .. '</td>'
--res_tmp[#res_tmp+1] = '<td>' .. value[25] .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. leng[value[24]] .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. para_num(value[9]) .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. para_num(value[13]) .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. para_num(value[14]) .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. para_num(value[10]) .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. para_num(value[12]) .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. para_num(value[16]) .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. para_num(value[21]) .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. para_num(value[18]) .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. para_num(value[8]) .. '</td>'
res_tmp[#res_tmp+1] = '</tr>'
break
end
end
end
sitem_idx[#sitem_idx+1] = {key, table.concat(res_tmp)}
end
table.sort(sitem_idx, sortAsc)
for _, value in ipairs(sitem_idx) do
res[#res+1] = value[2]
end
res[#res+1] = '</table>'
return table.concat(res)
end
function p.gomi_ship()
local res = {}
res[#res+1] = '<table border="0" cellpadding="1" cellspacing="1" class="wikitable sortable mw-datatable" style="font-size:14px; line-height:22px;"><tr><th>編號</th><th>艦名</th><th class="unsortable"></th><th>火力</th><th>雷裝</th><th>對空</th><th>裝甲</th><th class="unsortable"></th><th>燃料</th><th>彈藥</th><th>鋼材</th><th>鋁土</th></tr>'
for key, value in pairs(ship_data) do
if ship_data[key][1] ~= '' then
res[#res+1] = '<tr><td>' .. string.format('%03d', ship_data[key][1]) .. '</td>'
res[#res+1] = '<td>[[' .. ship_data[key][2] .. ']]</td><td></td>'
res[#res+1] = '<td>' .. ship_data[key][32] .. '</td>'
res[#res+1] = '<td>' .. ship_data[key][33] .. '</td>'
res[#res+1] = '<td>' .. ship_data[key][34] .. '</td>'
res[#res+1] = '<td>' .. ship_data[key][35] .. '</td><td></td>'
res[#res+1] = '<td>' .. ship_data[key][28] .. '</td>'
res[#res+1] = '<td>' .. ship_data[key][29] .. '</td>'
res[#res+1] = '<td>' .. ship_data[key][30] .. '</td>'
res[#res+1] = '<td>' .. ship_data[key][31] .. '</td></tr>'
end
end
return table.concat(res)
end
function p.gomi_slotitem()
local res = {}
local sitem_idx = {}
res[#res+1] = '<table border="0" cellpadding="1" cellspacing="1" class="wikitable sortable mw-datatable" style="font-size:14px; line-height:22px;"><tr><th>編號</th><th>名稱</th><th>燃料</th><th>彈藥</th><th>鋼材</th><th>鋁土</th></tr>'
for key, value in pairs(slotitem_data) do
local res_tmp = {}
if slotitem_data[key][1] > 0 then
res_tmp[#res_tmp+1] = '<tr><td>' .. string.format('%03d', slotitem_data[key][1]) .. '</td>'
res_tmp[#res_tmp+1] = '<td>[[' .. slotitem_data[key][2] .. ']]</td>'
res_tmp[#res_tmp+1] = '<td>' .. slotitem_data[key][26] .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. slotitem_data[key][27] .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. slotitem_data[key][28] .. '</td>'
res_tmp[#res_tmp+1] = '<td>' .. slotitem_data[key][29] .. '</td></tr>'
sitem_idx[#sitem_idx+1] = {key, table.concat(res_tmp)}
end
end
table.sort(sitem_idx, sortAsc)
for _, value in ipairs(sitem_idx) do
res[#res+1] = value[2]
end
res[#res+1] = '</table>'
return table.concat(res)
end
function p.kaizou()
local res = {}
res[#res+1] = '<table border="0" cellpadding="1" cellspacing="1" class="wikitable sortable mw-datatable" style="font-size:14px; line-height:22px;"><tr><th>No.</th><th>name</th><th>k.lv</th><th>kaizou list</th></tr>'
for key, value in pairs(ship_data) do
if ship_data[key][1] ~= '' and ship_data[key][5] > 0 then
local pid = key
local i = 1
res[#res+1] = '<tr><td>' .. string.format('%03d', ship_data[key][1]) .. '</td>'
res[#res+1] = '<td>[[' .. ship_data[key][2] .. ']]</td>'
res[#res+1] = '<td>' .. ship_data[key][5] .. '</td>'
res[#res+1] = '<td>' .. ship_data[key][2]
while ship_data[pid][5] > 0 do --and i <= 5 do
res[#res+1] = '(' .. ship_data[pid][5] .. ') → ' .. ship_data[ship_data[pid][6]][2]
if ship_data[ship_data[pid][6]][6] == pid then
pid = ship_data[pid][6]
res[#res+1] = '(' .. ship_data[pid][5] .. ') → ' .. ship_data[ship_data[pid][6]][2]
break
end
pid = ship_data[pid][6]
--if pid == 466 or pid == 467 then i = 5 end
i = i + 1
end
res[#res+1] = '</td></tr>'
end
end
return table.concat(res)
end
function para_num(num)
local res = {}
if num == 0 then
res[#res+1] = '<span style="color:#C4C4C4;">0</span>'
elseif num < 0 then
res[#res+1] = '<span style="color:red;">'
res[#res+1] = num
res[#res+1] = '</span>'
elseif num > 0 then
res[#res+1] = '+'
res[#res+1] = num
end
return table.concat(res)
end
return p