舰R百科是靠无数自愿编辑者持续地建设更新完善的。编辑非常简单,请勇于更新页面!
编辑入门 | 资助百科 | 留言讨论页 | 微博@舰R百科 | 百科编辑讨论Q群:366818861

模块:数据:修订间差异

来自舰R百科
跳转到导航 跳转到搜索
无编辑摘要
无编辑摘要
第75行: 第75行:
     local shipName = frame.args[1]
     local shipName = frame.args[1]
     return replaceCountryName(ships[shipName]['简介'])
     return replaceCountryName(ships[shipName]['简介'])
end
p['改造'] = function(frame)
    local shipName = frame.args[1]
    local mod = ships[shipName].mod
    if mod == nil then mod = '' end
    return mod
end
end



2016年10月16日 (日) 12:39的版本

修改数据[编辑源代码]

大部分游戏数据保存在模块:数据库,这些数据可以用Python脚本自动生成,不建议手动修改。一方面因为手动修改的内容很容易被别人用自动生成的覆盖,另一方面我们永远不知道HM偷偷改了哪些数据,所以只有自动程序才能保证没有遗漏。

如果台词中有错别字或语病等建议使用模板:台词的参数修改,而不要直接修改数据库。

少部分需要人工编辑的数据保存在模块:特殊数据中,主要包含以下两项:

  • 不属于日、德、英、美、意、法、苏、中这8个国家的船无法自动判断国籍,需要人工指定;
  • 炮弹等装备的特殊效果如果自动采集则会包含一些无意义的内容,需要人工组织语言。

如果必须人工编辑数据库,可以参照模块:对照表来理解英文缩写的含义。

使用[编辑源代码]

模板:台词[编辑源代码]

例: {{#invoke:数据|台词|胡德|获得}}

Lua错误 在模块:特殊数据的第3行:attempt to index local 'data' (a boolean value)

模板:舰娘[编辑源代码]

船的属性: {{#invoke:数据|属性|{{{船名}}}|{{{属性名}}}}}

例: {{#invoke:数据|属性|胡德|火力max}}

Lua错误 在模块:特殊数据的第3行:attempt to index local 'data' (a boolean value)

装备属性: {{#invoke:数据|装备属性|{{{船名}}}|{{{装备位置}}}}}

例: {{#invoke:数据|装备属性|胡德·改|1}}

Lua错误 在模块:特殊数据的第3行:attempt to index local 'data' (a boolean value)

敌舰[编辑源代码]

{{#invoke:敌舰队|<位置标识>|<显示位置>|<列数>}}

结果可视为列表的一行(实际上为1~3行), 每列内容分别是: 位置, 舰队名, 阵形, 配置(默认6列), 索敌, 制空, 航速

参数除位置标识外均可省略

位置标识格式为x-y/z, 例如1-1/A

显示位置为列表第一列显示的内容, 可以修改来表示 boss 点或迂回点等

列数为这张表中最多一队的敌舰个数, 比如1-1一个点最多有4艘船就设成4

例:
{| class='wikitable'
!位置!!舰队!!阵形!!colspan=6|配置!!索敌!!制空!!航速
|-
{{#invoke:数据|敌舰队|2-5/A|随便改改}}
|-
{{#invoke:数据|敌舰队|2-5/B}}
|}
Lua错误 在模块:特殊数据的第3行:attempt to index local 'data' (a boolean value)Lua错误 在模块:特殊数据的第3行:attempt to index local 'data' (a boolean value)
位置 舰队 阵形 配置 索敌 制空 航速

local tr = mw.loadData("模块:对照表")
local data = mw.loadData("模块:特殊数据")
local equipts = data.equipts
local ships = data.ships
local byIndex = data.byIndex
local enemy = mw.loadData("模块:敌舰数据")
local enemyShips = enemy.ships
local enemyFleets = enemy.fleets

p = { }

local function replaceCountryName(name)
    name = name:gsub('C国', '中国')
    name = name:gsub('E国', '英国')
    name = name:gsub('F国', '法国')
    name = name:gsub('G国', '德国')
    name = name:gsub('I国', '意大利')
    name = name:gsub('J国', '日本')
    name = name:gsub('S国', '苏联')
    name = name:gsub('U国', '美国')
    return name
end

local function getAttr(ship, attr, default)
    if tr[attr] ~= nil then attr = tr[attr] end
    if attr == '搭载' then
        return ship.cap1 + ship.cap2 + ship.cap3 + ship.cap4
    elseif attr:sub(1, 2) == 'eq' then
        return replaceCountryName(ship[attr])
    elseif ship[attr] ~= nil then
        return ship[attr]
    else
        return default
    end
end

local equiptAttrs = { '火力', '装甲', '鱼雷', '对空', '轰炸', '索敌', '对潜', '命中', '回避', '幸运', '射程', '对空补正' }
local rangeName = { '短', '中', '长', '超长' }

local function getEquiptAttrs(equipt)
    if equipt == nil then return '' end
    local ret = ''
    for i,attr in pairs(equiptAttrs) do
        local val = equipt[tr[attr]]
        if val ~= nil then
            if ret ~= '' then ret = ret .. '<br>' end
            ret = ret .. attr
            if attr == '射程' then
                ret = ret .. ': ' .. rangeName[val]
            elseif attr == '对空补正' then
                ret = ret .. ':<wbr>' .. val .. '%'
            elseif val > 0 then
                ret = ret .. '+' .. val
            else
                ret = ret .. val
            end
        end
    end
    if equipt.effect ~= nil then
        return ret .. '<br>' .. equipt.effect
    else
        return ret
    end
end

p['属性'] = function(frame)
    local shipName = frame.args[1]
    local attr = frame.args[2]
    local default = frame.args[3]
    if default == nil then default = '' end
    return getAttr(ships[shipName], attr, default)
end

p['简介'] = function(frame)
    local shipName = frame.args[1]
    return replaceCountryName(ships[shipName]['简介'])
end

p['改造'] = function(frame)
    local shipName = frame.args[1]
    local mod = ships[shipName].mod
    if mod == nil then mod = '' end
    return mod
end

p['台词'] = function(frame)
    local shipName = frame.args[1]
    local dialogue = frame.args[2]
    if shipName == '' then return '' end
    local ret = ships[shipName][dialogue]
    if ret == nil then ret = '' end
    return ret
end

p['查找编号'] = function(frame)
    return byIndex[tonumber(frame.args[1])]
end

p['页面'] = function(frame)
    local idx = ships[frame.args[1]].index
    return byIndex[idx % 1000]
end

local typeCode = { }
typeCode['航空母舰'] = 'cv'
typeCode['轻型航空母舰'] = 'cvl'
typeCode['装甲航母'] = 'av'
typeCode['战列舰'] = 'bb'
typeCode['航空战列舰'] = 'bbv'
typeCode['战列巡洋舰'] = 'bc'
typeCode['重巡洋舰'] = 'ca'
typeCode['轻巡洋舰'] = 'cl'
typeCode['浅水重炮舰'] = 'bm'
typeCode['驱逐舰'] = 'dd'
typeCode['重炮潜艇'] = 'sc'
typeCode['潜艇'] = 'ss'
typeCode['补给舰'] = 'ap'

local curFrame = nil
local function expand(idx)
    local name = byIndex[idx]
    local link = byIndex[idx % 1000]
    local ship = ships[name]
    local moe = ship['萌王']
    if moe == nil then moe = '' end
    local args = { idx, name:gsub('·改', ''), link, ship.rarity, typeCode[ship.type], moe }
    return curFrame:expandTemplate{ title = '图鉴立绘2', args = args }
end

local function genShipList(idx)
    local part1 = ''
    local part2 = ''
    local empty1 = true
    local empty2 = true
    local prefix = '\n|width="200px"|'
    for i = idx + 1, idx + 5 do
        part1 = part1 .. prefix
        if byIndex[i] ~= nil then
            part1 = part1 .. expand(i)
            empty1 = false
        end
    end
    if not empty1 then prefix = '\n|' end
    for i = idx + 6, idx + 10 do
        part2 = part2 .. prefix
        if byIndex[i] ~= nil then
            part2 = part2 .. expand(i)
            empty2 = false
        end
    end
    if empty1 and empty2 then
        return nil
    elseif empty1 then
        return '{|\n|- valign="bottom"' .. part2 .. '\n|}\n'
    elseif empty2 then
        return '{|\n|- valign="bottom"' .. part1 .. '\n|}\n'
    else
        return '{|\n|- valign="bottom"' .. part1 .. '\n|-' .. part2 .. '\n|}\n'
    end
end

p['图鉴'] = function(frame)
    curFrame = frame
    local l = math.floor((tonumber(frame.args[1]) - 1) / 10) * 10
    local r = math.floor((tonumber(frame.args[2]) - 1) / 10) * 10
    local ret = ''
    local buf = ''
    for i = l, r, 10 do
        local title = '===No.' .. (i + 1) .. '~' .. (i + 10) .. '===\n'
        local list = genShipList(i)
        if list ~= nil then
            ret = ret .. buf .. title .. list
            buf = ''
        else
            buf = buf .. title
        end
    end
    return ret
end

p['装备属性'] = function(frame)
    local shipName = frame.args[1]
    local index = frame.args[2]
    local attr = frame.args[3]
    local equiptName = ships[shipName]['eq' .. index]
    if attr ~= nil then
        return equipts[equiptName][tr[attr]]
    else
        return getEquiptAttrs(equipts[equiptName])
    end
end

p['敌舰属性'] = function(frame)
    local shipId = frame.args[1]
    local attr = frame.args[2]
    return getAttr(enemyShips[shipId], attr, '?')
end

p['敌舰装备属性'] = function(frame)
    local shipId = frame.args[1]
    local index = frame.args[2]
    local equiptName = enemyShips[shipId]['eq' .. index]
    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 or label == '' then label = node:sub(5,5) end
    local shipNum = frame.args[3]
    if shipNum == nil then shipNum = 6 end

    local ret = ''
    local n = 0
    for i, fleet in pairs(enemyFleets[node]) do
        if i ~= 1 then ret = ret .. '|-\n' end
        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, shipNum 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 .. '||' .. formatFloat(aa) .. '||' .. math.floor(s) .. '\n'
    end
    return '|rowspan=' .. n .. '|' .. label .. '|' .. ret
end

p.debug = function()
    f = { }
    f.args = {'1', '400' }
    return p['图鉴'](f)
end

return p