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

Difference between revisions of "Module:NanaminCombinedFleet"

From Kancolle Wiki
Jump to navigation Jump to search
m
m
Line 38: Line 38:
 
     local types_allowed = { [6] = true, [7] = true, [8] = true, [11] = true }
 
     local types_allowed = { [6] = true, [7] = true, [8] = true, [11] = true }
 
     if types_allowed[equip:type()] and equip:aa() then
 
     if types_allowed[equip:type()] and equip:aa() then
         self._fighter_power = self._fighter_power + math.floor(math.sqrt(planes) * equip:aa())
+
         NanaminCombinedFleet._fighter_power = NanaminCombinedFleet._fighter_power + math.floor(math.sqrt(planes) * equip:aa())
 
     end
 
     end
 
end
 
end
Line 50: Line 50:
 
     local multiplier = { [7] = 1.04, [8] = 1.04, [9] = 1.66, [10] = 2.00, [11] = 1.78, [12] = 1.00, [13] = 0.99, [29] = 0.91 }
 
     local multiplier = { [7] = 1.04, [8] = 1.04, [9] = 1.66, [10] = 2.00, [11] = 1.78, [12] = 1.00, [13] = 0.99, [29] = 0.91 }
 
     if multiplier[equip:type()] ~= nil and equip:los() then
 
     if multiplier[equip:type()] ~= nil and equip:los() then
         self._elos = self._elos + (equip:los() * multiplier[equip:type()])
+
         NanaminCombinedFleet._elos = NanaminCombinedFleet._elos + (equip:los() * multiplier[equip:type()])
 
     end
 
     end
 
end
 
end
Line 74: Line 74:
 
     else
 
     else
 
         local equipment = Equipment(item)
 
         local equipment = Equipment(item)
         self:add_to_fighter_power(equipment, plane_count)
+
         NanaminCombinedFleet:add_to_fighter_power(equipment, plane_count)
         self:add_to_elos(equipment)
+
         NanaminCombinedFleet:add_to_elos(equipment)
 
         return equipment, plane_count
 
         return equipment, plane_count
 
     end
 
     end
Line 82: Line 82:
 
function NanaminCombinedFleet:organize_args()
 
function NanaminCombinedFleet:organize_args()
 
     local ship_index, ship, los = 0
 
     local ship_index, ship, los = 0
     for index, item in ipairs(self._args) do
+
     for index, item in ipairs(NanaminCombinedFleet._args) do
 
         --Arguments that begin in ! will end up outside of this as args["!something"] - no need to check for it
 
         --Arguments that begin in ! will end up outside of this as args["!something"] - no need to check for it
 
         if mw.ustring.sub(item, 1, 1) ~= "#" then
 
         if mw.ustring.sub(item, 1, 1) ~= "#" then
Line 88: Line 88:
 
             if mw.ustring.find(item, '/') then
 
             if mw.ustring.find(item, '/') then
 
                 ship_index = ship_index + 1
 
                 ship_index = ship_index + 1
                 ship, los = self:process_ship(item)
+
                 ship, los = NanaminCombinedFleet:process_ship(item)
                 self._ship_list[ship_index] = { ship = ship, equips = {} }
+
                 NanaminCombinedFleet._ship_list[ship_index] = { ship = ship, equips = {} }
                 self._elos = self._elos + math.sqrt(los) * 1.69
+
                 NanaminCombinedFleet._elos = NanaminCombinedFleet._elos + math.sqrt(los) * 1.69
 
             else
 
             else
                 local slot = #self._ship_list[ship_index].equips + 1
+
                 local slot = #NanaminCombinedFleet._ship_list[ship_index].equips + 1
                 local equipment, planes = self:process_equipment(ship, item, slot)
+
                 local equipment, planes = NanaminCombinedFleet:process_equipment(ship, item, slot)
                 table.insert(self._ship_list[ship_index].equips, { equip = equipment, planes = planes })
+
                 table.insert(NanaminCombinedFleet._ship_list[ship_index].equips, { equip = equipment, planes = planes })
 
             end
 
             end
 
         end
 
         end
Line 101: Line 101:
  
 
function NanaminCombinedFleet:begin_tabber()
 
function NanaminCombinedFleet:begin_tabber()
     table.insert(self._rows, self._tabber_start)
+
     table.insert(NanaminCombinedFleet._rows, NanaminCombinedFleet._tabber_start)
 
end
 
end
  
 
function NanaminCombinedFleet:end_tabber()
 
function NanaminCombinedFleet:end_tabber()
     table.insert(self._rows, self._tabber_end)
+
     table.insert(NanaminCombinedFleet._rows, NanaminCombinedFleet._tabber_end)
 
end
 
end
  
 
function NanaminCombinedFleet:begin_table()
 
function NanaminCombinedFleet:begin_table()
     table.insert(self._rows, self._table_start)
+
     table.insert(NanaminCombinedFleet._rows, NanaminCombinedFleet._table_start)
 
end
 
end
  
 
function NanaminCombinedFleet:end_table()
 
function NanaminCombinedFleet:end_table()
     table.insert(self._rows, self._table_end)
+
     table.insert(NanaminCombinedFleet._rows, NanaminCombinedFleet._table_end)
 
end
 
end
  
 
function NanaminCombinedFleet:build_fleet_table(tab_name, i_start, i_end)
 
function NanaminCombinedFleet:build_fleet_table(tab_name, i_start, i_end)
     table.insert(self._rows, tab_name)
+
     table.insert(NanaminCombinedFleet._rows, tab_name)
     self:begin_table()
+
     NanaminCombinedFleet:begin_table()
 
     --Tentative style of 3 cards across the top
 
     --Tentative style of 3 cards across the top
 
     for a = i_start, i_end do
 
     for a = i_start, i_end do
 
         for b = 1, 3 do
 
         for b = 1, 3 do
 
             local ship_num = (a - 1) * 3 + b
 
             local ship_num = (a - 1) * 3 + b
             table.insert(self._rows, format{self._ship_image_template, values = {
+
             table.insert(NanaminCombinedFleet._rows, format{NanaminCombinedFleet._ship_image_template, values = {
                 bg_color = self._ship_image_bg,
+
                 bg_color = NanaminCombinedFleet._ship_image_bg,
                 ship_image = Formatting:format_image{self._ship_list[ship_num].ship:battle_card(), align = self._center_align}
+
                 ship_image = Formatting:format_image{NanaminCombinedFleet._ship_list[ship_num].ship:battle_card(), align = NanaminCombinedFleet._center_align}
 
             }})
 
             }})
 
         end
 
         end
         table.insert(self._rows, self._row_starter)
+
         table.insert(NanaminCombinedFleet._rows, NanaminCombinedFleet._row_starter)
 
         for b = 1, 4 do
 
         for b = 1, 4 do
 
             row = {}
 
             row = {}
 
             for c = 1, 3 do
 
             for c = 1, 3 do
 
                 local ship_num = (a - 1) * 3 + c
 
                 local ship_num = (a - 1) * 3 + c
                 local equip = self._ship_list[ship_num].equips[b].equip
+
                 local equip = NanaminCombinedFleet._ship_list[ship_num].equips[b].equip
 
                 local equip_icon, equip_link
 
                 local equip_icon, equip_link
 
                 if type(equip) == "string" then
 
                 if type(equip) == "string" then
Line 139: Line 139:
 
                     equip_link = equip
 
                     equip_link = equip
 
                 else
 
                 else
                     equip_icon = Formatting:format_image{Formatting:format_equipment_icon(equip:icon()), size = self._equip_icon_size}
+
                     equip_icon = Formatting:format_image{Formatting:format_equipment_icon(equip:icon()), size = NanaminCombinedFleet._equip_icon_size}
 
                     equip_link = Formatting:format_link(equip:link())
 
                     equip_link = Formatting:format_link(equip:link())
 
                 end
 
                 end
                 table.insert(self._rows, format{self._equip_icon_template, values = {
+
                 table.insert(NanaminCombinedFleet._rows, format{NanaminCombinedFleet._equip_icon_template, values = {
                   bg_color = self._equip_icon_bg,
+
                   bg_color = NanaminCombinedFleet._equip_icon_bg,
 
                   equip_icon = equip_icon
 
                   equip_icon = equip_icon
 
                 }})
 
                 }})
                 table.insert(self._rows, format{self._equip_link_template, values = {
+
                 table.insert(NanaminCombinedFleet._rows, format{NanaminCombinedFleet._equip_link_template, values = {
                     bg_color = self._equip_link_bg,
+
                     bg_color = NanaminCombinedFleet._equip_link_bg,
 
                     equip_link = equip_link
 
                     equip_link = equip_link
 
                 }})
 
                 }})
 
             end
 
             end
             table.insert(self._rows, self._row_starter)
+
             table.insert(NanaminCombinedFleet._rows, NanaminCombinedFleet._row_starter)
 
         end
 
         end
 
     end
 
     end
     self:end_table()
+
     NanaminCombinedFleet:end_table()
 
end
 
end
  
 
function NanaminCombinedFleet:add_info(label, text)
 
function NanaminCombinedFleet:add_info(label, text)
     table.insert(self._rows, format{self._info_template, values = {
+
     table.insert(NanaminCombinedFleet._rows, format{NanaminCombinedFleet._info_template, values = {
 
         label = label,
 
         label = label,
 
         text = text
 
         text = text
Line 166: Line 166:
 
function NanaminCombinedFleet:build_info_tab()
 
function NanaminCombinedFleet:build_info_tab()
 
     --Finish eLoS calculation
 
     --Finish eLoS calculation
     self._hq_level = tonumber(self._args["!hq"]) - (tonumber(self._args["!hq"]) % 5)
+
     NanaminCombinedFleet._hq_level = tonumber(NanaminCombinedFleet._args["!hq"]) - (tonumber(NanaminCombinedFleet._args["!hq"]) % 5)
     if tonumber(self._args["!hq"]) % 5 ~= 0 then
+
     if tonumber(NanaminCombinedFleet._args["!hq"]) % 5 ~= 0 then
         self._hq_level = self._hq_level + 5
+
         NanaminCombinedFleet._hq_level = NanaminCombinedFleet._hq_level + 5
 
     end
 
     end
     self._elos = self._elos - (self._hq_level * 0.61)
+
     NanaminCombinedFleet._elos = NanaminCombinedFleet._elos - (NanaminCombinedFleet._hq_level * 0.61)
 
      
 
      
     table.insert(self._rows, "|-|Information=")
+
     table.insert(NanaminCombinedFleet._rows, "|-|Information=")
     table.insert(self._rows, self._info_container_start)
+
     table.insert(NanaminCombinedFleet._rows, NanaminCombinedFleet._info_container_start)
     self:add_info("Route Taken", self._args["!route"] or "Unavailable")
+
     NanaminCombinedFleet:add_info("Route Taken", NanaminCombinedFleet._args["!route"] or "Unavailable")
     self:add_info("Fighter Power", self._fighter_power or 0)
+
     NanaminCombinedFleet:add_info("Fighter Power", NanaminCombinedFleet._fighter_power or 0)
     self:add_info("Effective Line of Sight", string.format("%.2f", self._elos) or 0)
+
     NanaminCombinedFleet:add_info("Effective Line of Sight", string.format("%.2f", NanaminCombinedFleet._elos) or 0)
     self:add_info("HQ Level", self._args["!hq"] or "Unavailable")
+
     NanaminCombinedFleet:add_info("HQ Level", NanaminCombinedFleet._args["!hq"] or "Unavailable")
     table.insert(self._rows, self._info_container_end)
+
     table.insert(NanaminCombinedFleet._rows, NanaminCombinedFleet._info_container_end)
 
end
 
end
  
 
function NanaminCombinedFleet:join_rows()
 
function NanaminCombinedFleet:join_rows()
     return table.concat(self._rows, "\n")
+
     return table.concat(NanaminCombinedFleet._rows, "\n")
 
end
 
end
  
 
function NanaminCombinedFleet:Fleetbox(args)
 
function NanaminCombinedFleet:Fleetbox(args)
     self._args = args
+
     NanaminCombinedFleet._args = args
 
      
 
      
     self:organize_args()
+
     NanaminCombinedFleet:organize_args()
 
      
 
      
     self:begin_tabber()
+
     NanaminCombinedFleet:begin_tabber()
     self:build_fleet_table("Main Fleet=", 1, 2)
+
     NanaminCombinedFleet:build_fleet_table("Main Fleet=", 1, 2)
     self:build_fleet_table("|-|Escort Fleet=", 3, 4)
+
     NanaminCombinedFleet:build_fleet_table("|-|Escort Fleet=", 3, 4)
     self:build_info_tab()
+
     NanaminCombinedFleet:build_info_tab()
     self:end_tabber()
+
     NanaminCombinedFleet:end_tabber()
 
      
 
      
     return self:join_rows()
+
     return NanaminCombinedFleet:join_rows()
 
end
 
end
  

Revision as of 12:16, 13 April 2015

Documentation for this module may be created at Module:NanaminCombinedFleet/doc

local Ship = require("Module:Ship")
local Equipment = require("Module:Equipment")
local Formatting = require("Module:Formatting")
local format = require("Module:StringInterpolation").format

local NanaminCombinedFleet = {
    _rows = {},
    _ship_list = {},
    
    _tabber_start = [[<tabber>]],
    _tabber_end = [[</tabber>]],
    _table_start = [[{|]],
    _table_end = [[|}]],
    _row_starter = "|-",
    _info_container_start = [[<div style="padding: 10px;">]],
    _info_container_end = [[</div>]],
    
    _transparent = "transparent",
    _ship_image_bg = "#7FB8D6",
    _equip_icon_bg = "#8DCDEE",
    _equip_link_bg = "#E4F3FB",
    _equip_locked_bg = "#CDDBE2",
    _equip_icon_size = "22x22px",
    _center_align = "center",
    
    _ship_image_template = [[| colspan="2" style="background-color: ${values.bg_color};" |${values.ship_image}]],
    _equip_icon_template = [[| style="text-align: center; background-color: ${values.bg_color};" |${values.equip_icon}]],
    _equip_link_template = [[| style="width: 175px; text-align: center; background: ${values.bg_color};" |${values.equip_link}]],
    _info_template = [[<b>${values.label}</b>: ${values.text}<br />]],
    
    _fighter_power = 0,
    _elos = 0,
    _hq_level = 0
}

function NanaminCombinedFleet:add_to_fighter_power(equip, planes)
    --Only fighter planes, dive bombers, torpedo bombers and seaplane bombers with an AA stat are counted
    local types_allowed = { [6] = true, [7] = true, [8] = true, [11] = true }
    if types_allowed[equip:type()] and equip:aa() then
        NanaminCombinedFleet._fighter_power = NanaminCombinedFleet._fighter_power + math.floor(math.sqrt(planes) * equip:aa())
    end
end

function NanaminCombinedFleet:add_to_elos(equip)
    --[[Effective LoS = Dive Bomber LoS x (1.04) + Torpedo Bomber LoS x (1.37)
    + Carrier-based Recon Plane LoS x (1.66) + Recon Seaplane LoS x (2.00)
    + Seaplane Bomber LoS x (1.78) + Small Radar LoS x (1.00) + Large Radar LoS x (0.99)
    + Searchlight LoS x (0.91) + √(base LoS of each ship) * (1.69)
    + (HQ Lv. rounded up to the next multiple of 5) x (-0.61)--]]
    local multiplier = { [7] = 1.04, [8] = 1.04, [9] = 1.66, [10] = 2.00, [11] = 1.78, [12] = 1.00, [13] = 0.99, [29] = 0.91 }
    if multiplier[equip:type()] ~= nil and equip:los() then
        NanaminCombinedFleet._elos = NanaminCombinedFleet._elos + (equip:los() * multiplier[equip:type()])
    end
end

function NanaminCombinedFleet:process_ship(item)
    --Will come in as "Ship/Remodel"
    local split = mw.ustring.find(item, '/')
    local ship_name = mw.ustring.sub(item, 1, split - 1)
    local temp = mw.ustring.sub(item, split + 1)
    split = mw.ustring.find(temp, '/')
    local ship_suffix = mw.ustring.sub(temp, 1, split - 1)
    local los = mw.ustring.sub(temp, split + 1)
    return Ship(ship_name, ship_suffix), los
end

function NanaminCombinedFleet:process_equipment(ship, item, slot)
    --Check if it's a locked slot
    local slot_info, plane_count = ship:slot(slot)
    if slot_info == nil then
        return "- Locked -", 0
    elseif item == "-" then
        return "- Unequipped -", plane_count
    else
        local equipment = Equipment(item)
        NanaminCombinedFleet:add_to_fighter_power(equipment, plane_count)
        NanaminCombinedFleet:add_to_elos(equipment)
        return equipment, plane_count
    end
end

function NanaminCombinedFleet:organize_args()
    local ship_index, ship, los = 0
    for index, item in ipairs(NanaminCombinedFleet._args) do
        --Arguments that begin in ! will end up outside of this as args["!something"] - no need to check for it
        if mw.ustring.sub(item, 1, 1) ~= "#" then
            --Assume that people are not crazy and will actually put their equips below the ship designation
            if mw.ustring.find(item, '/') then
                ship_index = ship_index + 1
                ship, los = NanaminCombinedFleet:process_ship(item)
                NanaminCombinedFleet._ship_list[ship_index] = { ship = ship, equips = {} }
                NanaminCombinedFleet._elos = NanaminCombinedFleet._elos + math.sqrt(los) * 1.69
            else
                local slot = #NanaminCombinedFleet._ship_list[ship_index].equips + 1
                local equipment, planes = NanaminCombinedFleet:process_equipment(ship, item, slot)
                table.insert(NanaminCombinedFleet._ship_list[ship_index].equips, { equip = equipment, planes = planes })
            end
        end
    end
end

function NanaminCombinedFleet:begin_tabber()
    table.insert(NanaminCombinedFleet._rows, NanaminCombinedFleet._tabber_start)
end

function NanaminCombinedFleet:end_tabber()
    table.insert(NanaminCombinedFleet._rows, NanaminCombinedFleet._tabber_end)
end

function NanaminCombinedFleet:begin_table()
    table.insert(NanaminCombinedFleet._rows, NanaminCombinedFleet._table_start)
end

function NanaminCombinedFleet:end_table()
    table.insert(NanaminCombinedFleet._rows, NanaminCombinedFleet._table_end)
end

function NanaminCombinedFleet:build_fleet_table(tab_name, i_start, i_end)
    table.insert(NanaminCombinedFleet._rows, tab_name)
    NanaminCombinedFleet:begin_table()
    --Tentative style of 3 cards across the top
    for a = i_start, i_end do
        for b = 1, 3 do
            local ship_num = (a - 1) * 3 + b
            table.insert(NanaminCombinedFleet._rows, format{NanaminCombinedFleet._ship_image_template, values = {
                bg_color = NanaminCombinedFleet._ship_image_bg,
                ship_image = Formatting:format_image{NanaminCombinedFleet._ship_list[ship_num].ship:battle_card(), align = NanaminCombinedFleet._center_align}
            }})
        end
        table.insert(NanaminCombinedFleet._rows, NanaminCombinedFleet._row_starter)
        for b = 1, 4 do
            row = {}
            for c = 1, 3 do
                local ship_num = (a - 1) * 3 + c
                local equip = NanaminCombinedFleet._ship_list[ship_num].equips[b].equip
                local equip_icon, equip_link
                if type(equip) == "string" then
                    equip_icon = ""
                    equip_link = equip
                else
                    equip_icon = Formatting:format_image{Formatting:format_equipment_icon(equip:icon()), size = NanaminCombinedFleet._equip_icon_size}
                    equip_link = Formatting:format_link(equip:link())
                end
                table.insert(NanaminCombinedFleet._rows, format{NanaminCombinedFleet._equip_icon_template, values = {
                   bg_color = NanaminCombinedFleet._equip_icon_bg,
                   equip_icon = equip_icon
                }})
                table.insert(NanaminCombinedFleet._rows, format{NanaminCombinedFleet._equip_link_template, values = {
                    bg_color = NanaminCombinedFleet._equip_link_bg,
                    equip_link = equip_link
                }})
            end
            table.insert(NanaminCombinedFleet._rows, NanaminCombinedFleet._row_starter)
        end
    end
    NanaminCombinedFleet:end_table()
end

function NanaminCombinedFleet:add_info(label, text)
    table.insert(NanaminCombinedFleet._rows, format{NanaminCombinedFleet._info_template, values = {
        label = label,
        text = text
    }})
end

function NanaminCombinedFleet:build_info_tab()
    --Finish eLoS calculation
    NanaminCombinedFleet._hq_level = tonumber(NanaminCombinedFleet._args["!hq"]) - (tonumber(NanaminCombinedFleet._args["!hq"]) % 5)
    if tonumber(NanaminCombinedFleet._args["!hq"]) % 5 ~= 0 then
        NanaminCombinedFleet._hq_level = NanaminCombinedFleet._hq_level + 5
    end
    NanaminCombinedFleet._elos = NanaminCombinedFleet._elos - (NanaminCombinedFleet._hq_level * 0.61)
    
    table.insert(NanaminCombinedFleet._rows, "|-|Information=")
    table.insert(NanaminCombinedFleet._rows, NanaminCombinedFleet._info_container_start)
    NanaminCombinedFleet:add_info("Route Taken", NanaminCombinedFleet._args["!route"] or "Unavailable")
    NanaminCombinedFleet:add_info("Fighter Power", NanaminCombinedFleet._fighter_power or 0)
    NanaminCombinedFleet:add_info("Effective Line of Sight", string.format("%.2f", NanaminCombinedFleet._elos) or 0)
    NanaminCombinedFleet:add_info("HQ Level", NanaminCombinedFleet._args["!hq"] or "Unavailable")
    table.insert(NanaminCombinedFleet._rows, NanaminCombinedFleet._info_container_end)
end

function NanaminCombinedFleet:join_rows()
    return table.concat(NanaminCombinedFleet._rows, "\n")
end

function NanaminCombinedFleet:Fleetbox(args)
    NanaminCombinedFleet._args = args
    
    NanaminCombinedFleet:organize_args()
    
    NanaminCombinedFleet:begin_tabber()
    NanaminCombinedFleet:build_fleet_table("Main Fleet=", 1, 2)
    NanaminCombinedFleet:build_fleet_table("|-|Escort Fleet=", 3, 4)
    NanaminCombinedFleet:build_info_tab()
    NanaminCombinedFleet:end_tabber()
    
    return NanaminCombinedFleet:join_rows()
end

function NanaminCombinedFleet:Testbox(args)
    return NanaminCombinedFleet:Fleetbox(args)
end

return NanaminCombinedFleet