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

Module:ShipData

From Kancolle Wiki
Revision as of 15:51, 10 November 2015 by がか (talk | contribs) (Undo revision 500726 by がか (talk))
Jump to navigation Jump to search

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

local Equipment
local Formatting = require('Module:Formatting')
local Ship
local ShipClass = require('Module:ShipClass')

local BaseData = require("Module:BaseData")
local ShipData = BaseData{
	_constructor_module = "Module:Ship",
}

function ShipData:name()
	local suffix = self:display_suffix()
	if suffix then
		return self:base_name() .. " " .. suffix
	else
		return self:base_name()
	end
end

function ShipData:unique_name()
	local suffix = self:suffix()
	if suffix then
		return self:base_name() .. " " .. self:suffix()
	else
		return self:base_name()
	end
end

function ShipData:base_name()
	return self._name
end

function ShipData:suffix()
	return self._suffix
end

function ShipData:display_suffix()
	if self._display_suffix ~= nil then
		return self._display_suffix
	end
	return self._suffix
end

function ShipData:link()
	if self._page then
		return self._page, self:name()
	elseif self:suffix() then
		return self:base_name(), self:name()
	else
		return self:name()
	end
end

function ShipData:localized_name()
	return self._localized_name
end

function ShipData:nick()
	return self._nick
end

function ShipData:japanese_name()
	return self._japanese_name
end

function ShipData:japanese_nick()
	return self._japanese_nick
end

function ShipData:reading()
	return self._reading
end

function ShipData:reading_nick()
	return self._reading_nick
end

function ShipData:id()
	return self._id
end

function ShipData:api_id()
	return self._api_id
end

function ShipData:true_id()
	return self._true_id
end

function ShipData:rarity()
	return self._rarity
end

function ShipData:back()
	return self._back or self:rarity()
end

function ShipData:class()
	return self._class
end

function ShipData:class_number()
	return self._class_number
end

function ShipData:type()
	return self._type
end

function ShipData:is_installation()
	return self._installation
end

function ShipData:card()
	if self._card then
		return self._card
	elseif self._card_reference then
		Ship = Ship or require(self._constructor_module)
		return Ship:create_from_reference(self._card_reference, self):card()
	end
	api_id = self:api_id()
	if api_id then
		return Formatting:ship_card(api_id, self:unique_name(), self:type(), self._card_extension)
	end
	return self._card
end

function ShipData:card_damaged()
	if self._card_damaged then
		return self._card_damaged
	elseif self._card_damaged_reference then
		Ship = Ship or require(self._constructor_module)
		return Ship:create_from_reference(self._card_damaged_reference, self):card_damaged()
	end
	api_id = self:api_id()
	if api_id then
		return Formatting:ship_card_damaged(api_id, self:unique_name(), self:type(), self._card_damaged_extension)
	end
	return self._card_damaged
end

function ShipData:battle_card()
	if self._battle_card then
		return self._battle_card
	elseif self._battle_card_reference then
		Ship = Ship or require(self._constructor_module)
		return Ship:create_from_reference(self._battle_card_reference, self):battle_card()
	end
	api_id = self:api_id()
	if api_id then
		return Formatting:ship_battle_card(api_id, self:unique_name(), self:type(), self._battle_card_extension)
	end
	return self._battle_card
end

function ShipData:battle_card_layers()
	return self._battle_card_layers
end

function ShipData:battle_card_damaged()
	if self._battle_card_damaged then
		return self._battle_card_damaged
	elseif self._battle_card_damaged_reference then
		Ship = Ship or require(self._constructor_module)
		return Ship:create_from_reference(self._battle_card_damaged_reference, self):battle_card_damaged()
	end
	api_id = self:api_id()
	if api_id then
		return Formatting:ship_battle_card_damaged(api_id, self:unique_name(), self:type(), self._battle_card_damaged_extension)
	end
	return self._battle_card_damaged
end

function ShipData:cg()
	if self._cg then
		return self._cg
	elseif self._cg_reference then
		Ship = Ship or require(self._constructor_module)
		return Ship:create_from_reference(self._cg_reference, self):cg()
	end
	api_id = self:api_id()
	if api_id then
		return Formatting:ship_cg(api_id, self:unique_name(), self:type(), self._cg_extension)
	end
	return self._cg
end

function ShipData:cg_damaged()
	if self._cg_damaged then
		return self._cg_damaged
	elseif self._cg_damaged_reference then
		Ship = Ship or require(self._constructor_module)
		return Ship:create_from_reference(self._cg_damaged_reference, self):cg_damaged()
	end
	api_id = self:api_id()
	if api_id then
		return Formatting:ship_cg_damaged(api_id, self:unique_name(), self:type(), self._cg_damaged_extension)
	end
	return self._cg_damaged
end

function ShipData:level()
	return self._level
end

function ShipData:hp()
	return self._hp
end

function ShipData:hp_max()
	return self._hp_max
end

function ShipData:hp_leveled()
	local hp = self:hp()
	if self._level and self._level > 100 then
		return math.floor((self:hp_max() - hp) * (self._level - 99) / 51 + hp)
	end
	return hp
end

function ShipData:firepower()
	return self._firepower
end

function ShipData:firepower_max()
	return self._firepower_max
end

function ShipData:firepower_leveled()
	if self._firepower_leveled then
		return self._firepower_leveled
	end
	return self:firepower_max()
end

function ShipData:torpedo()
	return self._torpedo
end

function ShipData:torpedo_max()
	return self._torpedo_max
end

function ShipData:torpedo_leveled()
	if self._torpedo_leveled then
		return self._torpedo_leveled
	end
	return self:torpedo_max()
end

function ShipData:aa()
	return self._aa
end

function ShipData:aa_max()
	return self._aa_max
end

function ShipData:aa_leveled()
	if self._aa_leveled then
		return self._aa_leveled
	end
	return self:aa_max()
end

function ShipData:armor()
	return self._armor
end

function ShipData:armor_max()
	return self._armor_max
end

function ShipData:armor_leveled()
	if self._armor_leveled then
		return self._armor_leveled
	end
	return self:armor_max()
end

function ShipData:asw()
	return self._asw
end

function ShipData:asw_max()
	return self._asw_max
end

function ShipData:asw_leveled()
	if self._level then
		local asw = self:asw()
		return math.floor((self:asw_max() - asw) * self._level / 99 + asw)
	end
	return self:asw_max()
end

function ShipData:evasion()
	return self._evasion
end

function ShipData:evasion_max()
	return self._evasion_max
end

function ShipData:evasion_leveled()
	if self._level then
		local evasion = self:evasion()
		return math.floor((self:evasion_max() - evasion) * self._level / 99 + evasion)
	end
	return self:evasion_max()
end

function ShipData:los()
	return self._los
end

function ShipData:los_max()
	return self._los_max
end

function ShipData:los_leveled()
	if self._level then
		local los = self:los()
		return math.floor((self:los_max() - los) * self._level / 99 + los)
	end
	return self:los_max()
end

function ShipData:luck()
	return self._luck
end

function ShipData:luck_max()
	return self._luck_max
end

function ShipData:luck_leveled()
	if self._luck_leveled then
		return self._luck_leveled
	end
	return self:luck()
end

function ShipData:buildable()
	return self._buildable
end

function ShipData:buildable_lsc()
	return self._buildable_lsc
end

function ShipData:build_time()
	return self._build_time
end

function ShipData:remodel_from()
	return self._remodel_from
end

function ShipData:remodel_to()
	return self._remodel_to
end

function ShipData:remodel_level()
	return self._remodel_level
end

function ShipData:remodel_cost()
	return {fuel = false, ammo = self._remodel_ammo, steel = self._remodel_steel, bauxite = false, devmat = self._remodel_development_material, screw = false}
end

function ShipData:remodel_blueprint()
	return self._remodel_blueprint
end

function ShipData:remodel_catapult()
	return self._remodel_catapult
end

function ShipData:remodel_to_level()
	return self._remodel_to_level
end

function ShipData:remodel_to_cost()
	return {fuel = false, ammo = self._remodel_to_ammo, steel = self._remodel_to_steel, bauxite = false, devmat = self._remodel_to_development_material, screw = false}
end

function ShipData:remodel_to_blueprint()
	return self._remodel_to_blueprint
end

function ShipData:remodel_to_catapult()
	return self._remodel_to_catapult
end

function ShipData:modernization()
	return {firepower = self._firepower_mod, torpedo = self._torpedo_mod, aa = self._aa_mod, armor = self._armor_mod, luck = self._luck_mod}
end

function ShipData:scrap()
	return {fuel = self._scrap_fuel, ammo = self._scrap_ammo, steel = self._scrap_steel, bauxite = self._scrap_baux, devmat = false, screw = false}
end

function ShipData:fuel()
	return self._fuel
end

function ShipData:ammo()
	return self._ammo
end

function ShipData:slot_space(slot)
	if self._equipment then
		local equipment_slot = self._equipment[slot]
		if equipment_slot then
			return equipment_slot.size, equipment_slot.estimation
		end
	end
	return nil
end

function ShipData:slot(slot)
	if self._equipment then
		local equipment_slot = self._equipment[slot]
		if equipment_slot then
			if type(equipment_slot.equipment) == "string" then
				self:_prepare_Equipment()
				equipment_slot.equipment = Equipment(equipment_slot.equipment)
			end
			return equipment_slot.equipment, equipment_slot.size, equipment_slot.estimation
		end
	end
	return nil
end

function ShipData:slots()
	if self._slots then
		return self._slots
	else
		return self:slots_length()
	end
end

function ShipData:slots_length()
	if self._equipment then
		return #self._equipment
	end
	return nil
end

function ShipData:total_space()
	if not self._equipment then
		return nil
	end
	local total_space = 0
	local size
	for _, v in ipairs(self._equipment) do
		size = v.size
		if size == nil then
			total_space = nil
			break
		elseif size == false then
		else
			total_space = total_space + size
		end
	end
	return total_space
end

function ShipData:speed()
	return self._speed
end

function ShipData:range()
	return self._range
end

function ShipData:air_power()
    local air_power = 0
    for i = 1, self:slots() or 0 do
        local slot_equipment, slot_space = self:slot(i)
        if slot_equipment == nil or slot_space == nil then
            --we have missing information, fall back to hard-coded air power
            air_power = self._as_rating
            break
        elseif slot_equipment ~= false then
            --if there is an equipment
            local slot_equipment_type = slot_equipment:type()
            local slot_equipment_aa = slot_equipment:aa()
            if slot_equipment_aa and
               (slot_equipment_type == 6 or 
                slot_equipment_type == 7 or 
                slot_equipment_type == 8 or 
                slot_equipment_type == 11) then
                air_power = air_power + 
                   math.floor(math.sqrt(slot_space) * slot_equipment_aa)
            elseif slot_equipment_aa == nil then
            --we have missing information, fall back to hard-coded air power
                air_power = self._as_rating
                break
            end
        end
    end
    return air_power
end
 
function ShipData:night_bombing()
	return self._night_bombing
end

function ShipData:opening_torpedo()
	return self._opening_torpedo
end

function ShipData:asw_attack()
	return self._asw_attack
end

function ShipData:seasonal()
	return self._seasonal
end

function ShipData:_prepare_Equipment()
	if not Equipment then
		Equipment = require('Module:Equipment')
	end
end

function ShipData:create(ship)
	ship = ship or {}
	if ship._class then
		ship._class = ShipClass(ship._class)
	end
	setmetatable(ship, ship)
	ship.__index = self
	ship.__call = self.__call
	return ship
end

return ShipData