模块:数据:修订间差异
跳转到导航
跳转到搜索
无编辑摘要 |
无编辑摘要 |
||
第5行: | 第5行: | ||
local enemy = mw.loadData("模块:敌舰数据") | local enemy = mw.loadData("模块:敌舰数据") | ||
local enemyShips = enemy.ships | local enemyShips = enemy.ships | ||
local enemyFleets = enemy.fleets | |||
p = { } | p = { } | ||
第107行: | 第108行: | ||
local equiptName = enemyShips[shipId]['eq' .. index] | local equiptName = enemyShips[shipId]['eq' .. index] | ||
return getEquiptAttrs(equipts[equiptName]) | return getEquiptAttrs(equipts[equiptName]) | ||
end | |||
local speedType = { } | |||
speedType['航空母舰'] = 1 | |||
speedType['轻型航空母舰'] = 1 | |||
speedType['战列舰'] = 1 | |||
speedType['航空战列舰'] = 1 | |||
speedType['战列巡洋舰'] = 1 | |||
speedType['重巡洋舰'] = 2 | |||
speedType['重雷装巡洋舰'] = 2 | |||
speedType['轻巡洋舰'] = 2 | |||
speedType['驱逐舰'] = 2 | |||
speedType['补给舰'] = 2 | |||
speedType['潜艇'] = 3 | |||
local colorName = { 'black', 'green', 'blue', 'purple', 'orange', 'red' } | |||
local function formatEnemyShip(ship) | |||
local ret = '[' | |||
local len = mw.ustring.len(ship.title) | |||
if mw.ustring.sub(ship.title, len, len) == '型' and mw.ustring.sub(ship.title, len - 2, len - 2) == '级' then | |||
ret = ret .. mw.ustring.sub(ship.title, 1, len - 2) | |||
else | |||
ret = ret .. ship.title | |||
end | |||
return ret .. "|<span style='color:" .. colorName[ship.rarity] .. ";'>" .. ship.title .. "</span>]" | |||
end | |||
local function calcAa(ship) | |||
local ret = 0 | |||
local n = math.floor(ship.atk / 5) + 3 | |||
for i = 1, 4 do | |||
local e = ship['eq' .. i] | |||
if e:find('战斗机') ~= nil then | |||
local f = math.log(math.min(n, ship['cap' .. i]) * 2 + 2) | |||
ret = ret + f * equipts[e].aa | |||
end | |||
end | |||
return ret | |||
end | |||
local function formatFloat(x) | |||
if x == 0 then return 0 end | |||
x = math.floor(x * 100 + 0.5) / 100 | |||
return string.format('%.2f', x) | |||
end | |||
p['敌舰队'] = function(frame) | |||
local node = frame.args[1] | |||
local label = frame.args[2] | |||
if label == nil then label = node:sub(5,5) end | |||
local ret = '' | |||
local n = 0 | |||
for i, fleet in pairs(enemyFleets[node]) do | |||
ret = ret .. '|' .. fleet.title .. '||' .. fleet.formation | |||
n = n + 1 | |||
local rec = 0 | |||
local aa = 0 | |||
local speed = { 0, 0, 0 } | |||
local speedCnt = { 0, 0, 0 } | |||
local m = 0 | |||
for j, shipId in pairs(fleet.ships) do | |||
m = m + 1 | |||
local ship = enemyShips[shipId] | |||
ret = ret .. '||' .. formatEnemyShip(ship) | |||
rec = rec + ship.rec | |||
aa = aa + calcAa(ship) | |||
local st = speedType[ship.type] | |||
speed[st] = speed[st] + ship.speed | |||
speedCnt[st] = speedCnt[st] + 1 | |||
end | |||
for j = m + 1, 6 do | |||
ret = ret .. '||' | |||
end | |||
local s1 = 999 | |||
local s2 = 999 | |||
if speedCnt[1] ~= 0 then s1 = speed[1] / speedCnt[1] end | |||
if speedCnt[2] ~= 0 then s2 = speed[2] / speedCnt[2] end | |||
local s = math.min(s1, s2) | |||
if speedCnt[1] == 0 and speedCnt[2] == 0 then | |||
s = speed[3] / speedCnt[3] | |||
end | |||
ret = ret .. '||' .. rec .. '||' .. math.floor(s) .. '||' .. formatFloat(aa) .. '\n|-\n' | |||
end | |||
return '|rowspan=' .. n .. '|' .. label .. '|' .. ret | |||
end | end | ||
p.debug = function() | p.debug = function() | ||
f = { } | f = { } | ||
f.args = { ' | f.args = { '2-5/B' } | ||
return p[' | return p['敌舰队'](f) | ||
end | end | ||
return p | return p |