| Line 1: |
Line 1: |
| − | local U = require("Module:Utils") | + | local U = require("Module:Core") |
| | | | |
| | local Self = {} | | local Self = {} |
| Line 277: |
Line 277: |
| | | | |
| | Self.typeGroups = { | | Self.typeGroups = { |
| − | "Group 1", -- { "DE", "DD", "CL", "CLT", "SS", "AP", "CT", "AO" }, | + | [[<span class="explain" data-group="1" title="DE/DD/CL/CLT/SS/CT/AO">G1</span>]], -- { "DE", "DD", "CL", "CLT", "SS", "AP", "CT", "AO" }, |
| − | "Group 2", -- { "CA", "FBB", "BB", "XBB", "AR" }, | + | [[<span class="explain" data-group="2" title="CA/FBB/BB/AR">G2</span>]], -- { "CA", "FBB", "BB", "XBB", "AR" }, |
| − | "Group 3", -- { "CAV", "CVL", "BBV", "CV", "SSV", "AV", "LHA", "CVB", "AS" }, | + | [[<span class="explain" data-group="3" title="CAV/CVL/BBV/CV/SSV/AV/LHA/CVB/AS">G3</span>]], -- { "CAV", "CVL", "BBV", "CV", "SSV", "AV", "LHA", "CVB", "AS" }, |
| | } | | } |
| | | | |
| Line 289: |
Line 289: |
| | } | | } |
| | --]] | | --]] |
| − |
| |
| − | function findGroups(id)
| |
| − | local groups = {}
| |
| − | for typeGroup, resourceGroups in ipairs(Self.groups) do
| |
| − | for resourceGroup, equipment in ipairs(resourceGroups) do
| |
| − | if equipment[id] and equipment[id] > 0 then
| |
| − | groups[typeGroup] = groups[typeGroup] or {}
| |
| − | groups[typeGroup][resourceGroup] = equipment[id]
| |
| − | end
| |
| − | end
| |
| − | end
| |
| − | return groups
| |
| − | end
| |
| | | | |
| | function ensureResourceGroup(fuel, ammo, steel, bauxite, resourceGroup) | | function ensureResourceGroup(fuel, ammo, steel, bauxite, resourceGroup) |
| | local main = math.max(unpack({fuel, ammo, steel, bauxite})) | | local main = math.max(unpack({fuel, ammo, steel, bauxite})) |
| | + | function fix(x) |
| | + | return x < main and main + 1 or x |
| | + | end |
| | if resourceGroup == 1 then | | if resourceGroup == 1 then |
| − | return math.max(main + 1, fuel), ammo, math.max(main + 1, steel), bauxite | + | return fix(fuel), ammo, fix(steel), bauxite |
| | elseif resourceGroup == 2 then | | elseif resourceGroup == 2 then |
| − | return fuel, math.max(main + 1, ammo), steel, bauxite | + | return fuel, fix(ammo), steel, bauxite |
| | elseif resourceGroup == 3 then | | elseif resourceGroup == 3 then |
| − | return fuel, ammo, steel, math.max(main + 1, bauxite) | + | return fuel, ammo, steel, fix(bauxite) |
| | end | | end |
| | end | | end |
| | | | |
| − | function Self.formatResources(eq) | + | function Self.formatResources(eq, rates) |
| | if eq:buildable() then | | if eq:buildable() then |
| | local result = {} | | local result = {} |
| | local id = eq:id() | | local id = eq:id() |
| − | local groups = findGroups(id)
| |
| | local fuel = (eq:scrap().fuel or 1) * 10 | | local fuel = (eq:scrap().fuel or 1) * 10 |
| | local ammo = (eq:scrap().ammo or 1) * 10 | | local ammo = (eq:scrap().ammo or 1) * 10 |
| | local steel = (eq:scrap().steel or 1) * 10 | | local steel = (eq:scrap().steel or 1) * 10 |
| | local bauxite = (eq:scrap().bauxite or 1) * 10 | | local bauxite = (eq:scrap().bauxite or 1) * 10 |
| − | for typeGroup, resourceGroups in pairs(groups) do | + | local maxRate |
| − | for resourceGroup, _ in pairs(resourceGroups) do | + | for typeGroup, resourceGroups in ipairs(Self.groups) do |
| − | local fuel, ammo, steel, bauxite = ensureResourceGroup(fuel, ammo, steel, bauxite, resourceGroup) | + | for resourceGroup, equipment in ipairs(resourceGroups) do |
| − | table.insert(result, U.format{
| + | if equipment[id] and equipment[id] > 0 then |
| − | "${fuel}/${ammo}/${steel}/${bauxite} (${typeGroup})",
| + | local fuel, ammo, steel, bauxite = ensureResourceGroup(fuel, ammo, steel, bauxite, resourceGroup) |
| − | fuel = fuel, | + | local recipe = U.format{ |
| − | ammo = ammo,
| + | "${fuel}/${ammo}/${steel}/${bauxite}", |
| − | steel = steel,
| + | fuel = fuel, |
| − | bauxite = bauxite,
| + | ammo = ammo, |
| − | typeGroup = Self.typeGroups[typeGroup], | + | steel = steel, |
| − | }) | + | bauxite = bauxite, |
| | + | } |
| | + | result[recipe] = result[recipe] or { |
| | + | fuel = fuel, |
| | + | ammo = ammo, |
| | + | steel = steel, |
| | + | bauxite = bauxite, |
| | + | resourceGroup = resourceGroup, |
| | + | types = {}, |
| | + | } |
| | + | local rate = U.round(100 * equipment[id] / 50) |
| | + | result[recipe].types[Self.typeGroups[typeGroup]] = result[recipe].types[Self.typeGroups[typeGroup]] or { |
| | + | rate = rate, |
| | + | } |
| | + | if not maxRate or rate > maxRate then |
| | + | maxRate = rate |
| | + | end |
| | + | break |
| | + | end |
| | end | | end |
| | end | | end |
| − | return table.concat(result, "<br>") | + | return U.ijoin( |
| | + | U.imap( |
| | + | U.isort(U.keys(result)), |
| | + | function(recipe) |
| | + | local types = U.isort(U.keys(result[recipe].types)) |
| | + | local resourceGroup = result[recipe].resourceGroup |
| | + | return U.format{ |
| | + | rates and "${rates}" or "${recipe} (${types})", |
| | + | recipe = U.format{ |
| | + | "${fuel}/${ammo}/${steel}/${bauxite}", |
| | + | fuel = (resourceGroup == 1 and U.red or U.id)(result[recipe].fuel), |
| | + | ammo = (resourceGroup == 2 and U.red or U.id)(result[recipe].ammo), |
| | + | steel = (resourceGroup == 1 and U.red or U.id)(result[recipe].steel), |
| | + | bauxite = (resourceGroup == 3 and U.red or U.id)(result[recipe].bauxite), |
| | + | }, |
| | + | types = U.ijoin(U.imap(types, function(type) |
| | + | local rate = result[recipe].types[type].rate |
| | + | return (rate == maxRate and U.red or U.id)(type) |
| | + | end), "/"), |
| | + | rates = U.ijoin(U.imap(types, function(type) |
| | + | local rate = result[recipe].types[type].rate |
| | + | return (rate == maxRate and U.red or U.id)(tostring(rate) .. "%") |
| | + | end), "/"), |
| | + | } |
| | + | end |
| | + | ), |
| | + | "<br>" |
| | + | ) |
| | + | else |
| | + | return "-" |
| | + | end |
| | + | end |
| | + | |
| | + | function Self.formatRates(eq) |
| | + | return Self.formatResources(eq, true) |
| | + | end |
| | + | |
| | + | function Self.formatHQ(eq) |
| | + | if eq:buildable() then |
| | + | return math.max(math.max((eq:rarity() or 0) - 2, 0) * 10, 1) |
| | else | | else |
| − | return 'N/A' | + | return "-" |
| | end | | end |
| | end | | end |
| Line 344: |
Line 390: |
| | function Self.test() | | function Self.test() |
| | local Equipment = require("Module:Equipment") | | local Equipment = require("Module:Equipment") |
| − | return Self.formatResources(Equipment("46cm Triple Gun Mount")) | + | return |
| | + | Self.formatResources(Equipment("46cm Triple Gun Mount")) .. |
| | + | "\n" .. |
| | + | Self.formatRates(Equipment("46cm Triple Gun Mount")) .. |
| | + | "\n" .. |
| | + | Self.formatResources(Equipment("12cm Single Gun Mount")) |
| | end | | end |
| | + | -- print(p.test()) |
| | | | |
| | return Self | | return Self |