• Welcome to the Kancolle Wiki!
  • If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord

Changes

Jump to navigation Jump to search
m
17 revisions imported
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 = {
     [[<span class="explain" title="DE/DD/CL/CLT/SS/CT/AO">G1</span>]], -- { "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" },
     [[<span class="explain" title="CA/FBB/BB/AR">G2</span>]], -- { "CA", "FBB", "BB", "XBB", "AR" },
+
     [[<span class="explain" data-group="2" title="CA/FBB/BB/AR">G2</span>]], -- { "CA", "FBB", "BB", "XBB", "AR" },
     [[<span class="explain" title="CAV/CVL/BBV/CV/SSV/AV/LHA/CVB/AS">G3</span>]], -- { "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)
Line 317: Line 304:  
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
                local recipe = U.format{
+
                 if equipment[id] and equipment[id] > 0 then
                    "${fuel}/${ammo}/${steel}/${bauxite}",
+
                    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,
                }
+
                        steel = steel,
                result[recipe] = result[recipe] or {}
+
                        bauxite = bauxite,
                result[recipe][Self.typeGroups[typeGroup]] = true
+
                    }
 +
                    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
Line 344: Line 347:  
                 U.isort(U.keys(result)),
 
                 U.isort(U.keys(result)),
 
                 function(recipe)
 
                 function(recipe)
 +
                    local types = U.isort(U.keys(result[recipe].types))
 +
                    local resourceGroup = result[recipe].resourceGroup
 
                     return U.format{
 
                     return U.format{
                         "${recipe} (${types})",
+
                         rates and "${rates}" or "${recipe} (${types})",
                         recipe = recipe,
+
                         recipe = U.format{
                         types = U.ijoin(U.isort(U.keys(result[recipe])), "/")
+
                          "${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
 
                 end
Line 354: Line 372:  
         )
 
         )
 
     else
 
     else
         return 'N/A'
+
         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
 +
        return "-"
 
     end
 
     end
 
end
 
end
Line 362: Line 392:  
     return
 
     return
 
         Self.formatResources(Equipment("46cm Triple Gun Mount")) ..
 
         Self.formatResources(Equipment("46cm Triple Gun Mount")) ..
 +
        "\n" ..
 +
        Self.formatRates(Equipment("46cm Triple Gun Mount")) ..
 
         "\n" ..
 
         "\n" ..
 
         Self.formatResources(Equipment("12cm Single Gun Mount"))
 
         Self.formatResources(Equipment("12cm Single Gun Mount"))
Bots, gkautomate
13,304

edits

Navigation menu