Welcome to Wargaming.net Wiki!
Variants
Navigation

Module:WoWs GD

Jump to: navigation, search

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

local p = {}

local function clean(str)
    if not str then return "" end
    local s = tostring(str):gsub(" ", " "):gsub("[%z\1-\31\127]", "")
    return mw.text.trim(mw.text.decode(s))
end

local param_map = {
    -- Общее
    ["Боеспособность"] = "hull-health-d",
    ["ЦенаПокупки"] = "vehicle-price-d",
    ["УровеньБоевМин"] = "vehicle-battleLevelRangeMin",
	["УровеньБоевМакс"] = "vehicle-battleLevelRangeMax",
    -- ГК
	["НазваниеГК"] = "artillery-name", 
	["КолвоТочекГК1"] = "artillery-artillery_numGuns_0", 
	["СтвольностьТочекГК1"] = "artillery-artillery_numBarrels_0",
    ["КолвоТочекГК2"] = "artillery-artillery_numGuns_1", 
    ["СтвольностьТочекГК2"] = "artillery-artillery_numBarrels_1",
    ["ДальностьСтрельбыГК"] = "vehicle-artillery_maxDist", 
    ["ВремяПерезарядкиГК"] = "artillery-artillery_shotDelay", 
    ["МаксУронББГК"] = "artillery-artillery_damageAP", 
    ["МаксУронОФГК"] = "artillery-artillery_damageHE", 
    ["МаксУронПБГК"] = "artillery-artillery_damageCS",
    ["НазваниеСнарядаББ"] = "artillery-artillery_nameAP", 
    ["НазваниеСнарядаОФ"] = "artillery-artillery_nameHE", 
    ["ВероятностьПожараОФГК"] = "artillery-artillery_burnProbHE", 
    ["СкоростьББГК"] = "artillery-artillery_bulletSpeedAP", 
    ["СкоростьОФГК"] = "artillery-artillery_bulletSpeedHE", 
    ["СкоростьПБГК"] = "artillery-artillery_bulletSpeedCS",
    ["МассаББГК"] = "artillery-artillery_bulletMassAP", 
    ["МассаОФГК"] = "artillery-artillery_bulletMassHE", 
    ["МаксРассеиваниеГК"] = "artillery-artillery_dispersion",
    ["МаксДальностьСтрельбыГК"] = "vehicle-artillery_maxDist",
    ["СкорострельностьГК"] = "artillery-artillery_shotSpeed",
    ["ВремяПоворотаГК"] = "artillery-artillery_rotationTime",
    -- ТА
    ["НазваниеТА"] = "torpedoes-torpedoes_name_0", 
    ["КолвоТочекТА"] = "torpedoes-torpedoes_numGuns_0", 
    ["ТрубностьТА"] = "torpedoes-torpedoes_numBarrels_0",
    ["СкорострельностьТА"] = "torpedoes-torpedoes_shotSpeed",
    ["ВремяПерезарядкиТА"] = "torpedoes-torpedoes_shotDelay", 
    ["ВремяПоворотаТА"] = "torpedoes-torpedoes_rotationTime",
    ["НазваниеТорпедыТА"] = "torpedoes-torpedoes_nameTorp", 
    ["ДальностьХодаТА"] = "torpedoes-torpedoes_maxDist",
    ["СкоростьХодаТА"] = "torpedoes-torpedoes_speed", 
    ["МаксУронТА"] = "torpedoes-torpedoes_damage-d", 
    --["ЗаметностьТА"] = "3-tsb|4|idx|a",
    --["СкоростьПоворотаТА"] = "3-tsb|4|idx|4",

    -- ПВО

    -- Маневренность и маскировка
    ["РадиусЦиркуляции"] = "vehicle-mobility_turningRadius", 
    ["ВремяПерекладкиРуля"] = "hull-mobilityRuddertime",
    ["ВидимостьСКораблей"] = "vehicle-visibility_distByShip", 
    ["ВидимостьССамолетов"] = "vehicle-visibility_distByPlane",
    ["МаксСкоростьХода"] = "engine-mobility_maxSpeed",
    -- Бронирование
    ["МинБроняЦ"] = "3-tsb|3||8", 
    ["МаксБроняЦ"] = "3-tsb|3||9", 
    ["МинБроняК"] = "3-tsb|3||a", 
    ["МаксБроняК"] = "3-tsb|3||b",
    ["МинБроняО"] = "3-tsb|3||c", 
    ["МаксБроняО"] = "3-tsb|3||d", 
    ["МинБроняП"] = "3-tsb|3||e", 
    ["МаксБроняП"] = "3-tsb|3||f"
}

local function getPrem(frame, l_code)

    local status_map = {
        -- Группа 1
        ["PJSB508_Kii"] = 1, ["PFSD508_Le_Terrible"] = 1, ["PASC508_Wichita"] = 1,
        ["PASB518_Massachusetts"] = 1, ["PJSD518_Asashio"] = 1, ["PASD508_Kidd"] = 1,
        ["PJSB507_Ashitaka"] = 1, ["PUSD507_Haida"] = 1, ["PVSC507_Nueve_de_Julio_1951"] = 1,
        ["PJSC503_Katori"] = 1, ["PISD509_Paolo_Emilio"] = 1, ["PASC509_Vallejo"] = 1,
        ["PASB528_Alabama_VL"] = 1, ["PBSC716_Orion_1944"] = 1, ["PBSB727_Duke_of_Bronte"] = 1,
        ["PFSC716_Montcalm"] = 1, ["PJSS518_I56"] = 1, ["PBSS508_Alliance"] = 1,
        ["PRSS508_S_189"] = 1,

        -- Группа 2
        ["PJSC004_Yubari_1944"] = 2, ["PJSC038_Atago_1944"] = 2, ["PJSC705_Myoko"] = 2,
        ["PJSC707_Ashigara"] = 2, ["PJSC709_Haguro"] = 2, ["PJSC717_Yellow_Dragon"] = 2,
        ["PJSC727_Blue_Dragon"] = 2, ["PJSC737_Nachi"] = 2, ["PJSC708_ARP_Takao"] = 2,
        ["PJSB705_Kongou"] = 2, ["PJSB706_Kirishima"] = 2, ["PJSB707_Haruna"] = 2,
        ["PJSB708_Hiei_Arpeggio"] = 2, ["PASB708_Alabama"] = 2, ["PASC707_Flint"] = 2,
        ["PASC710_Salem"] = 2, ["PASD510_Somers"] = 2, ["PASB509_Missouri"] = 2,
        ["PJSB509_Musashi"] = 2, ["PASD709_Black"] = 2, ["PRSC606_Admiral_Makarov"] = 2,
        ["PRSC509_Kronshtadt"] = 2, ["PRSC510_Stalingrad"] = 2, ["PBSB517_Nelson"] = 2,
        ["PFSB518_Jean_Bart"] = 2, ["PBSB503_Dreadnought"] = 2, ["PFSB510_Bourgogne"] = 2,
        ["PASB507_West_Virginia"] = 2, ["PGSB506_Prinz_Eithel_Friedrich"] = 2,
        ["PASC510_Alaska"] = 2, ["PBSC505_Exeter"] = 2, ["PJSC510_Azumaya"] = 2,
        ["PWSD510_Friesland"] = 2, ["PRSC610_Smolensk"] = 2, ["PBSB510_Thunderer"] = 2,
        ["PRSD709_Pr_41_Neustrashimy"] = 2, ["PJSC520_Yoshino"] = 2, ["PFSC508_Bayard"] = 2,
        ["PFSD504_Siroco"] = 2, ["PFSC510_Colbert"] = 2, ["PASB510_Ohio"] = 2,
        ["PJSD507_Yudachi"] = 2, ["PBSA518_Ark_Royal"] = 2, ["PJSC505_Yahagi"] = 2,
        ["PWSB504_Viribus_Unitis"] = 2, ["PWSD610_Smaland"] = 2, ["PASS510_Gato"] = 2,
        ["PUSC510_Brisbane"] = 2, ["PUSD510_Vampire_2"] = 2, ["PGSB610_Mecklenburg"] = 2,
        ["PGSB110_Grossdeutschland"] = 2, ["PGSD610_Z_42"] = 2, ["PISC510_Napoli"] = 2,
        ["PISC590_Black_Napoli"] = 2, ["PJSD510_Hayate"] = 2, ["PJSB510_Shikishima"] = 2,
        ["PHSD610_Tromp"] = 2, ["PBSD510_Druid"] = 2, ["PBSC510_Plymouth"] = 2,
        ["PBSA510_Malta"] = 2, ["PBSC610_Gibraltar"] = 2, ["PASC810_Austin"] = 2,
        ["PASC610_Puerto_Rico"] = 2, ["PASA510_Roosevelt"] = 2, ["PRSC110_Pr_66_Moskva"] = 2,
        ["PRSB510_Slava"] = 2, ["PRSC710_Sevastopol"] = 2, ["PWSD710_Ragnar"] = 2,
        ["PFSD210_Marceau"] = 2, ["PGSA610_Max_Immelmann"] = 2, ["PJSB700_ARP_Yamato"] = 2,
        ["PJSC590_Black_Yoshino"] = 2, ["PSSD510_Alvaro_de_Bazan"] = 2, ["PASD610_Forrest_Sherman"] = 2,
        ["PBSB610_Incomparable"] = 2, ["PRSD110_Pr_24_Khabarovsk"] = 2, ["PGSC509_Siegfried"] = 2,
        ["PGSS510_U4501"] = 2, ["PJSA710_Shinano"] = 2, ["PASB730_Wisconsin"] = 2,
        ["PASB720_Rhode_Island"] = 2, ["PASB820_BA_Montana"] = 2, ["PASS710_Archerfish"] = 2,
        ["PJSD890_AZUR_Shimakaze"] = 2, ["PJSC610_Kitakami"] = 2, ["PJSC710_Yari"] = 2,
        ["PRSC530_Black_Smolensk"] = 2, ["PRSC810_Komissar"] = 2, ["PGSD710_Georg_Hoffmann"] = 2,
        ["PGSC710_Hildebrand"] = 2, ["PBSC020_Monmouth"] = 2, ["PBSC810_Defence"] = 2,
        ["PFSD810_Colorful_Kleber"] = 2, ["PFSC710_Brennus"] = 2, ["PISB710_Sicilia"] = 2,
        ["PISB510_Ruggiero_di_Lauria"] = 2, ["PHSC710_Prins_Van_Oranje"] = 2, ["PWSC710_Svea"] = 2,
        ["PVSD710_La_Pampa"] = 2, ["PZSD510_Lushun"] = 2, ["PZSC710_Incheon"] = 2,
        ["PUSC810_Black_Brisbane"] = 2
    }

    if status_map[l_code] then
        return status_map[l_code]
    end

    local isNotInShop = frame:preprocess("{{#shipchars:" .. l_code .. "|notInShop}}")
    if isNotInShop ~= "" then
        return 2
    end

    local isGold = frame:preprocess("{{#shipchars:" .. l_code .. "|gold}}")
    if isGold ~= "" then
        return 1
    end

    local group_digit = tonumber(mw.ustring.sub(l_code, 5, 5))
    if group_digit and group_digit >= 5 then
        return 1
    end

    return 0
end

function p.get(frame)
    local args = frame.args
    local p_name = clean(args[1])
    local code = clean(args[2])
    
    if code == "" then code = clean(frame:preprocess("{{#var:code}}")) end

    if p_name == "Прем" then
        return getPrem(frame, code)
    end
    
    if p_name == "Описание" then
		local parts = mw.text.split(code, "_")
		local prefix = parts[1]
		return frame:preprocess('{{WoWs_str|IDS_' .. prefix .. '_descr}}')
	end


    local ts = args[3] or "stock"
    local idx = args[4] or "0"
    local tsb = (ts == "top") and "1" or "0"

    local calc = {
        ["СкорострельностьПМК"] = {"2", "5", 60}
    }
    if calc[p_name] then
        local c = calc[p_name]
        local raw = frame:preprocess('{{WoWs_DataList|' .. code .. '|' .. tsb .. '|' .. c[1] .. '|' .. idx .. '|' .. c[2] .. '}}')
        local n = tonumber(clean(raw))
        if not n or n == 0 then return "" end
        return string.format("%.2f", c[3] / n):gsub("%.00$", "")
    end

    local rule = param_map[p_name]
    if not rule then return "" end
    
    local query = rule:gsub("tsb", tsb):gsub("idx", idx)

    local parts = mw.text.split(query, "-")
    local final = ""
    
    if parts[1] == "3" then
        local d = mw.text.split(parts[2], "|")
        final = frame:preprocess('{{WoWs_DataList|' .. code .. '|' .. d[1] .. '|' .. (d[2] or "") .. '|' .. (d[3] or "") .. '|' .. d[4] .. '}}')
    else
        final = frame:preprocess('{{#shipchars:' .. parts[1] .. ':' .. code .. '::' .. ts .. '|' .. parts[2] .. '}}')
    end

    final = clean(final)
    if final == "" or final:find("Неудалось") then return "" end
    
    if p_name == "Уровень" then
        return frame:preprocess("{{Level|" .. frame:preprocess("{{#shipattr:level}}") .. "}}")
    end
    
    if p_name == "Категория" then
        return frame:preprocess("{{WoWs_Class|" .. frame:preprocess("{{#shipattr:class}}") .. "|ss}}")
    end

    if parts[3] == "str" then return frame:preprocess('{{WoWs_str|' .. final .. '}}') end
    if parts[3] == "d" then return frame:preprocess('{{formatnum:' .. final .. '}}') end
    return final
end

return p