Dead by Daylight Wiki
mNie podano opisu zmian
Nie podano opisu zmian
(Nie pokazano 18 pośrednich wersji utworzonych przez tego samego użytkownika)
Linia 3: Linia 3:
 
local mathOps = require("Module:MathOps")
 
local mathOps = require("Module:MathOps")
 
local utils = require("Module:Utils")
 
local utils = require("Module:Utils")
  +
local perksData = mw.loadData("Module:Datatable/Perks")
  +
local perkImg = require("Module:PerkImage")
  +
local str = require("Module:Strings")
 
local frame = mw.getCurrentFrame()
 
local frame = mw.getCurrentFrame()
local bar = "|" -- code for |
+
local _defaultSpeed = 4 --m/s | 100%
  +
local nl = "\n"
 
  +
local perks = perksData.perks
  +
  +
local strings = {
  +
file = "Plik",
  +
killers = "Zabójcy",
  +
the = "",
  +
unknownKiller = "UnknownKiller",
  +
realName = "Nazwa",
  +
noName = "Brak", --When the killer doesn't have the real name (ex. Demogorgon)
  +
altName = "Alias",
  +
gender = "Płeć",
  +
nationality = "Narodowość",
  +
realm = "Lokacja", --link
  +
power = "Moc", --link
  +
powerType = "Typ Mocy [[Atak|Ataku]]",
  +
spAttackTrue = "Specjalny Atak",
  +
spAttackFalse = "Podstawowy Atak",
  +
weapon = "Broń",
  +
weapons = "Bronie",
  +
speed = "Prędkość Ruchu", --iconlink
  +
altSpeed = "Alternatywna Prędkość ruchu",
  +
metres = "metrów",
  +
m = "m", --abbreviation of metres
  +
terror = "Zasięg Terroru", --iconlink
  +
altTerror = "Alternatywny Zasięg Terroru",
  +
lullabyRadius = "Zasięg [[Kołysanka|Kołysanki]]",
  +
height = "Wzrost", --image
  +
tall = "Wysoki",
  +
avg = "Średni",
  +
dlc = "DLC",
  +
actor = "Aktor Głosowy",
  +
breathing = "Oddech",
  +
altBreathing = "Alternatywny Oddech",
  +
menuMusic = "Muzyka Menu",
  +
terrorMusic = "Muzyka Zasięgu Terroru",
  +
lullaby = "Kołysanka",
  +
lullabies = "Kołysanki",
  +
uknownActor = "Nieujawniony Aktor Głosowy",
  +
unkownPower = "Nieznana Moc",
  +
unkownSpeed = "Nieznana Szybkość",
  +
  +
  +
mps = "m/s",
  +
err = "Error"
  +
}
   
 
function p.getCountOfKillers()
 
function p.getCountOfKillers()
Linia 11: Linia 59:
 
end
 
end
   
function getKillerIndexById(id)
+
function p.getKillerById(id)
for i, s in ipairs(killers) do
+
for _, killer in ipairs(killers) do
if s.id == id then return i end
+
if killer.id == id then return killer end
 
end
 
end
return 0
+
return nil
 
end
 
end
   
function p.resolveKillersTable()
+
function getKillerByName(name)
  +
for _, killer in ipairs(killers) do
local result = ""
 
  +
if killer.shortName == name or killer.realName == name or killer.name == name or (the(killer) .. killer.name) == name then
local name
 
  +
return killer
local fileName
 
  +
end
  +
end
  +
return false
  +
end
   
  +
function getKillerIdByName(name)
result = result .. "<div style=\"color: #fff;\">"
 
  +
local result = getKillerByName(name)
for i, killer in ipairs(killers) do
 
  +
return (result and result.id) or 0
name = killer.shortName or killer.realName or killer.name
 
  +
end
fileName = resolveKillersPortraitFileNameById(killer.id)
 
 
result = result .. "<div style=\"display: inline-block; text-align:center; margin: 10px\">[[" .. name .. "]] - " .. killer.name
 
result = result .. "[[File:" .. fileName .. ".png|center|frameless|link=" .. killer.name .. "]]</div>"
 
   
  +
function p.getKillersPowerByName(name)
  +
local result = getKillerByName(utils.resolveParameter(name))
  +
return (result and result.power) or strings.unkownPower
  +
end
  +
  +
function p.getKillersSpeedByName(name)
  +
local result = getKillerByName(utils.resolveParameter(name))
  +
if result then
  +
if type(result.speed) == types.table then
  +
return result.speed[0]
  +
else
  +
return result.speed
  +
end
 
end
 
end
  +
return strings.unkownSpeed
result = result .. "</div>"
 
  +
end
   
  +
--articleless => whether the nickname is supposed to return with "The " before the name itself
return result
 
  +
function p.getKillerNicknameByRealName(args, articleless)
  +
articleless = utils.bool(utils.resolveParameter(args, "articleless", true))
  +
name = utils.resolveParameter(args)
  +
for _, killer in ipairs(killers) do
  +
if killer.shortName == name or killer.realName == name or killer.name == name or (the(killer) .. killer.name) == name then
  +
return ((not articleless and the(killer) .. space) or cstr.empty) .. killer.name
  +
end
  +
end
  +
return strings.unkwnKiller
 
end
 
end
   
function p.resolveKillersTableMainPage()
+
function p.resolveKillerCharTable(name)
local result = ""
+
local dlcs = require("Module:DLCs")
  +
name = utils.resolveParameter(name)
local name
 
  +
killerId = getKillerIdByName(name)
local fileName
 
  +
killer = utils.getCharacterById(killerId, killers)
  +
reuslt = ""
  +
  +
if type(killer) ~= "table" then return killer end
  +
  +
result =
  +
'{| class = "infoboxtable"' .. nl ..
  +
ntl ..' class = "infoboxTitle" | ' .. nl ..
  +
'! class = "center bold" colspan = 2 | ' .. the(killer) .. ' ' .. killer.name .. nl .. ntl .. nl ..
  +
  +
-- '<tabber>' ..
  +
-- '|-|First=' ..
  +
-- 'First tab sample text.' ..
  +
-- '|-|Second=' ..
  +
-- 'Second tab content goes here. ' ..
  +
-- '|-|Third Tab Title=' ..
  +
-- 'Third tab content goes here.' ..
  +
-- '</tabber>' ..
   
  +
'! class = "center" colspan = 2 | ' .. link(cstr.file .. resolveKillerPortraitImageFileName(killer) .. '.png|150px') .. nl ..
result = result .. "<div class=\"fpbox\" id=\"fpkiller\" style=\"text-align: center;\">"
 
  +
ntl .. nl
result = result .. "<div class=\"heading\">[[Zabójcy]] [[File:IconHelpLoading killer.png|32px]]</div>"
 
  +
if killer.realName ~= nil then
result = result .. "<div class=\"fplinks\">"
 
  +
result = result .. '| class = "titleColumn" | ' .. strings.realName .. ' || class = "valueColumn" | ' .. (killer.shortName or killer.realName or strings.noName) .. nl .. ntl .. nl
for i, killer in ipairs(killers) do
 
  +
end
 
  +
if killer.altName ~= nil then
fileName = resolveKillersPortraitFileNameById(killer.id)
 
  +
result = result .. '| class = "titleColumn" | ' .. strings.altName .. ' || class = "valueColumn italic" | ' .. resolveAltName(killer) .. nl .. ntl .. nl
  +
end
  +
result = result ..
  +
'| class = "titleColumn" | ' .. strings.gender .. ' || class = "valueColumn" | ' .. utils.resolveGender(killer.gender) .. nl .. ntl .. nl ..
  +
'| class = "titleColumn" | ' .. strings.nationality .. ' || class = "valueColumn" | ' .. killer.nationality .. nl .. ntl .. nl
  +
if killer.realm ~= nil or killer.dlc ~= nil then
  +
local killerRealm = resolveKillerRealm(killer)
  +
if killerRealm ~= 0 then
  +
result = result .. '| class = "titleColumn" | ' .. link(strings.realm) .. ' || class = "valueColumn" | [[' .. killerRealm .. ']] ' .. nl .. ntl .. nl
  +
end
  +
end
  +
result = result ..
  +
'| class = "titleColumn" | ' .. link(strings.power) .. ' || class = "valueColumn" | ' .. link(killer.power) .. nl .. ntl .. nl
  +
if killer.specialAttack ~= nil then
  +
result = result .. '| class = "titleColumn" | ' .. strings.powerType .. ' || class = "valueColumn" | ' .. resolvePowerAttack(killer) .. nl .. ntl .. nl
  +
end
  +
result = result ..
  +
'| class = "titleColumn" | ' .. link(strings.weapon) .. ' || class = "valueColumn" | ' .. link(strings.weapons .. '#' .. the(killer) .. killer.name .. tl .. killer.weapon) .. nl .. ntl .. nl ..
  +
'| class = "titleColumn" | ' .. utils.IconLink(strings.speed) .. ' || class = "valueColumn" | ' .. resolveKillerSpeed(killer) .. nl .. ntl .. nl
  +
if killer.altSpeed ~= nil then
  +
result = result .. '| class = "titleColumn" | ' .. strings.altSpeed .. ' || class = "valueColumn" | ' .. resolveAltSpeed(killer) .. nl .. ntl .. nl
  +
end
  +
result = result ..
  +
'| class = "titleColumn" | ' .. utils.IconLink(strings.terror) .. ' || class = "valueColumn" | ' .. resolveTerrorRadius(killer) .. nl .. ntl .. nl
  +
local altTerror = resolveAltTerrorRadius(killer)
  +
if altTerror then
  +
result = result .. '| class = "titleColumn" | ' .. strings.altTerror .. ' || class = "valueColumn" | ' .. altTerror .. nl .. ntl .. nl
  +
end
  +
local lullabyRadius = resolveLullabyRadius(killer)
  +
if lullabyRadius then
  +
result = result .. '| class = "titleColumn" | ' .. strings.lullabyRadius .. ' || class = "valueColumn" | ' .. lullabyRadius .. nl .. ntl .. nl
  +
end
  +
result = result ..
  +
'| class = "titleColumn" | ' .. strings.height .. space .. utils.IconLink(strings.height, "img") .. ' || class = "valueColumn" | ' .. resolveHeight(killer) .. nl .. ntl .. nl
  +
if killer.dlc ~= nil then
  +
result = result .. '| class = "titleColumn" | ' .. strings.dlc .. ' || class = "valueColumn" | ' .. link(dlcs.getDlcById(killer.dlc).name) .. space .. nl .. ntl .. nl
  +
end
  +
result = result ..
  +
'| class = "titleColumn" | ' .. strings.actor .. ' || class = "valueColumn" | ' .. resolveActor(killer) .. nl
  +
local breathingMusic = resolveBreathingMusic(killer)
  +
if breathingMusic then
  +
result = result .. ntl .. nl ..
  +
'| class = "titleColumn center" colspan = 2 ' .. tl .. space .. strings.breathing .. nl .. ntl .. nl ..
  +
'| class = "valueColumn center soundColumn" colspan = 2 ' .. tl .. space .. breathingMusic .. nl
  +
end
  +
local altBreathing = resolveAltBreathing(killer)
  +
if altBreathing then
  +
result = result .. ntl .. nl ..
  +
tl .. ' class = "titleColumn center" colspan = 2 ' .. tl .. space .. strings.altBreathing .. nl .. ntl .. nl ..
  +
tl .. ' class = "valueColumn center soundColumn" colspan = 2 ' .. tl .. space .. altBreathing .. nl
  +
end
  +
local theme = resolveKillerThemeMusic(killer)
  +
if theme then
  +
result = result .. ntl .. nl ..
  +
'| class = "titleColumn center" colspan = 2 ' .. tl .. space .. strings.menuMusic .. nl .. ntl .. nl ..
  +
'| class = "valueColumn center soundColumn" colspan = 2 ' .. tl .. space .. theme .. nl
  +
end
  +
local terrorMusic = resolveTRMusic(killer)
  +
if terrorMusic then
  +
result = result .. ntl .. nl ..
  +
'| class = "titleColumn center" colspan = 2 ' .. tl .. space .. strings.terrorMusic .. nl .. ntl .. nl ..
  +
'| class = "valueColumn center soundColumn" colspan = 2 ' .. tl .. space .. terrorMusic .. nl
  +
end
  +
  +
local lullaby = resolveLullaby(killer, 1)
  +
local counter = ((lullaby and 1) or 0) --if you find a lullaby then set the counter to 1, otherwise 0
  +
local tempResult = cstr.empty
  +
while lullaby do
  +
tempResult = tempResult .. ntl .. nl ..
  +
'| class = "valueColumn center soundColumn" colspan = 2 ' .. tl .. space .. lullaby .. nl
 
 
  +
counter = counter + 1
result = result .. "<div class=\"fplink plainlinks image\"><div class=\"box\"><div class=\"row\"><div class=\"cell\">"
 
  +
lullaby = resolveLullaby(killer, counter)
result = result .. "<div class=\"image\">[[File:" .. fileName .. ".png|link=" .. killer.name .. "]]</div>"
 
result = result .. "<div class=\"link\">[[" .. killer.name .. "]]</div></div></div></div></div>"
 
 
end
 
end
  +
result = result .. "</div>"
 
  +
if counter > 0 then --if lullaby was found
result = result .. "</div>"
 
  +
result = result .. ntl .. nl .. '| class = "titleColumn center" colspan = 2 | ' .. ((counter > 2 and strings.lullabies) or strings.lullaby) .. nl .. tempResult
  +
end
  +
  +
result = result .. '|}'
  +
  +
mw.log(result)
  +
return result
  +
end
   
  +
function resolveAltTerrorRadius(killer)
  +
if not killer.altRadius then return false end
  +
local result = killer.altRadius
  +
if type(killer.altRadius) == "table" then
  +
result = cstr.empty
  +
for i, radius in ipairs(killer.altRadius) do
  +
result = result .. radius[1] .. space .. brackets(radius[2]) .. ((i < #killer.altRadius and dnl) or cstr.empty)
  +
end
  +
end
 
return result
 
return result
 
end
 
end
   
function resolveKillersPortraitFileNameById(id)
+
function resolveActor(killer)
  +
local result = strings.uknownActor
i = getKillerIndexById(id)
 
local fileConst = "_charPreview_portrait"
 
local fileName
 
 
 
  +
if type(killer.actor) == "string" then
fileName = getFileNameFromTableById(id)
 
  +
result = killer.actor
if not isValidFileName(fileName) then --Szukanie nowych nazw plików
 
  +
elseif type(killer.actor) == "table" then
fileName = resolveNewInitialsByIndex(i) .. fileConst
 
  +
result = cstr.empty
  +
for i, actor in ipairs(killer.actor) do
  +
result = result .. actor .. ((i < #killer.actor and dnl) or cstr.empty)
  +
end
 
end
 
end
  +
return result
if not isValidFileName(fileName) then --Szukanie starych nazw plików
 
  +
end
mw.log("File not found. Looking further...")
 
  +
fileName = getKillersInitialsByIndex(i) .. fileConst
 
  +
function resolveLullabyRadius(killer)
  +
if not killer.lullabyRadius then return false end
  +
local result = cstr.empty
  +
  +
if type(killer.lullabyRadius) == "table" then
  +
for i, lullaby in ipairs(killer.lullabyRadius) do
  +
result = result .. lullaby[1] .. space .. strings.metres .. space .. brackets(lullaby[2])
  +
if i < #killer.lullabyRadius then
  +
result = result .. dnl
  +
end
  +
end
  +
else
  +
result = (killer.lullabyRadius and killer.lullabyRadius .. space ..strings.metres) or cstr.empty
 
end
 
end
  +
if not isValidFileName(fileName) then --Plik nie został znaleziony
 
  +
return result
fileName = "UnknownKiller" .. fileConst
 
  +
end
  +
  +
function resolveBreathingMusic(killer)
  +
file = (killer.techName or killer.name) .. space .. 'Breathing'
  +
valid = utils.isValidFileName(file, cstr.ogg)
  +
return (valid and link(cstr.file .. file .. dot .. cstr.ogg)) or valid
  +
end
  +
  +
function resolveAltBreathing(killer, index)
  +
file = (killer.techName or killer.name) .. space .. 'Breathing' .. space .. (index or 2)
  +
valid = utils.isValidFileName(file, cstr.ogg)
  +
return (valid and link(cstr.file .. file .. dot .. cstr.ogg)) or valid
  +
end
  +
  +
function resolveKillerThemeMusic(killer)
  +
local dlcs = require("Module:DLCs")
  +
local dlc = dlcs.getDlcById(killer.dlc)
  +
local fileConst = '_Theme_Music'
  +
local file = cstr.empty
  +
if not killer.dlc then
  +
file = killer.techName or killer.name
  +
else
  +
file = utils.resolveFileName(utils.CapitalizeName(dlc.name), true, true)
  +
end
  +
file = (file or cstr.empty) .. fileConst
  +
if killer.dlc then
  +
for _, theme in ipairs(dlcThemes) do
  +
if theme.id == dlc.id then
  +
file = theme.fileName
  +
end
  +
end
  +
end
  +
local valid = utils.isValidFileName(file, cstr.ogg)
  +
return (valid and link(cstr.file .. file .. dot .. cstr.ogg)) or valid
  +
end
  +
  +
function resolveTRMusic(killer)
  +
file = 'TerrorRadius_' .. (killer.techName or killer.name)
  +
local valid = utils.isValidFileName(file, cstr.ogg)
  +
return (valid and link(cstr.file .. file .. dot .. cstr.ogg)) or valid
  +
end
  +
  +
function resolveLullaby(killer, index)
  +
file = (killer.techName or killer.name) .. space .. 'Lullaby' .. ((index and space .. index) or cstr.empty)
  +
valid = utils.isValidFileName(file, cstr.ogg)
  +
return (valid and link(cstr.file .. file .. dot .. cstr.ogg)) or valid
  +
end
  +
  +
--addon is for cosmetics portraits (used in Module:Cosmetics)
  +
function resolveKillerPortraitImageFileName(killer, addon)
  +
local fileConst = "_charSelect_portrait"
  +
return "K" .. string.format("%02d", killer.id) .. ((addon and space .. addon) or cstr.empty) .. fileConst
  +
end
  +
  +
function resolveAltName(killer)
  +
if type(killer.altName) == "string" then return '"' .. killer.altName .. '"'
  +
elseif type(killer.altName) == "table" then
  +
local result = ""
  +
for i, name in ipairs(killer.altName) do
  +
result = result .. '"' .. name .. '"'
  +
if i < #killer.altName then
  +
result = result .. dnl
  +
end
  +
end
  +
return result
 
end
 
end
 
 
  +
return strings.err
fileName = fileName
 
mw.log(fileName)
 
return fileName
 
 
end
 
end
   
function isValidFileName(name)
+
function resolvePowerAttack(killer)
  +
result = ""
return not (name == "" or not mw.title.new("File:" .. name .. ".png").exists)
 
  +
  +
if killer.specialAttack then
  +
result = strings.spAttackTrue
  +
else
  +
result = strings.spAttackFalse
  +
end
  +
  +
if killer.altAttackNote ~= nil then
  +
result = result .. nl .. "(" .. killer.altAttackNote .. ")"
  +
end
  +
  +
return result
 
end
 
end
   
function getFileNameFromTableById(id)
+
function resolveKillerRealm(killer)
  +
if killer.dlc == nil then
mw.log(id)
 
for j, sImage in ipairs(killerImages) do
+
for _, realm in ipairs(realms) do
if sImage.id == id then
+
if realm.id == killer.realm then return realm.name end
  +
end
return sImage.preview
 
  +
else
  +
for _, realm in ipairs(realms) do
  +
if type(realm.dlc) == "number" and killer.dlc == realm.dlc then return realm.name
  +
elseif type(realm.dlc) == "table" then
  +
for _, dlcId in ipairs(realm.dlc) do
  +
if dlcId == killer.dlc then return realm.name end
  +
end
  +
end
 
end
 
end
 
end
 
end
return ""
+
return 0
 
end
 
end
   
function resolveNewInitialsByIndex(i)
+
function resolveKillerSpeed(killer)
  +
local result = cstr.empty
if killers[i] == nil then
 
  +
return ""
 
  +
if type(killer.speed) == "number" then
  +
result = getPercentSpeed(killer.speed) .. space .. '%' .. space .. b(bar) .. space .. killer.speed .. space .. strings.mps
  +
else --so the killer speed is table
  +
result = getPercentSpeed(killer.speed[1]) .. space .. '%' .. space .. b(bar) .. space .. killer.speed[1] .. space .. strings.mps .. space .. brackets(killer.speed[2])
 
end
 
end
  +
local k = killers
 
  +
return result
local initials = getKillersInitialsByIndex(i)
 
  +
end
local dlcCodeName =""
 
  +
if k[i].dlc ~= nil and dlcs[k[i].dlc] ~= nil then
 
  +
function resolveAltSpeed(killer)
dlcCodeName = getDlcById(k[i].dlc).codeName
 
  +
local result = ""
  +
local speedPercent
  +
  +
for i, altSpeed in ipairs(killer.altSpeed) do
  +
speedPercent = getPercentSpeed(altSpeed[1])
  +
  +
result = result .. speedPercent .. " % " .. b(bar) .. space .. altSpeed[1] .. space .. strings.mps
  +
if altSpeed[2] ~= nil then
  +
result = result .. pg .. "(" .. altSpeed[2] .. ")"
  +
end
  +
  +
if i < #killer.altSpeed then
  +
result = result .. "<hr>" --.. nl .. nl
  +
end
 
end
 
end
 
 
  +
return result
local dlcInitial = dlcCodeName:match("^(%S).*$") or "A" --A jest dla postaci z podstawowej gry które nie mają DLC albo kryptonimu DLC
 
  +
end
   
  +
function getPercentSpeed(speed)
mw.log(dlcInitial .. "K " .. initials)
 
return dlcInitial .. "K " .. initials
+
return (speed / _defaultSpeed) * 100
 
end
 
end
   
function getKillersInitialsByIndex(i)
+
function resolveTerrorRadius(killer)
  +
result = ""
if killers[i] == nil then
 
  +
return ""
 
  +
if type(killer.radius) == "number" then
  +
return killer.radius .. space .. strings.metres
  +
elseif type(killer.radius) == "table" then
  +
for i, radius in ipairs(killer.radius) do
  +
if radius[3] ~= nil then --open span with title hover
  +
result = result .. '<span class = "valueTooltip" title = "' .. radius[3] .. '">'
  +
end
  +
result = result .. radius[1] --metres value
  +
if radius[2] ~= nil then --note for alt speed, if there is a note for the speed the abbreviation for metres is used instead of full name
  +
result = result .. strings.m .. space .. brackets(radius[2])
  +
else
  +
result = result .. " " .. strings.metres
  +
end
  +
if radius[3] ~= nil then --close span hover
  +
result = result .. '</span>'
  +
end
  +
if i < #killer.radius then
  +
result = result .. nl .. nl
  +
end
  +
end
 
end
 
end
  +
return result
  +
end
  +
  +
function resolveHeight(killer)
  +
if killer.height == 'T' then return strings.tall
  +
elseif killer.height == 'A' then return strings.avg
  +
elseif killer.height == 'S' then return strings.short
  +
else return strings.err
  +
end
  +
end
  +
  +
function p.resolveKillersTable()
  +
local result = ""
  +
local name
  +
local fileName
  +
  +
result = result .. '<div style="color: #fff;">'
  +
maxId = utils.getMaxId(killers)
  +
for i, killer in ipairs(killers) do
  +
name = killer.shortName or killer.realName or killer.name
  +
fileName = utils.resolveCharacterPortraitFileName(killer, maxId)
  +
  +
result = result ..
  +
'<div style="display: inline-block; text-align:center; margin: 10px">' .. link(name) .. ' - ' .. killer.name ..
  +
link(cstr.file .. fileName .. '.png|center|frameless|link=' .. the(killer) .. " " .. killer.name) .. '</div>'
  +
end
  +
result = result .. '</div>'
  +
  +
return result
  +
end
  +
  +
function p.resolveKillersTableMainPage()
  +
local result = ""
  +
local name
  +
local fileName
  +
  +
result = result ..
  +
'<div class = "fpbox" id = "fpkiller" style = "text-align: center;">' ..
  +
'<div class = "heading">' .. the(strings.killers) .. link(strings.killers) .. space .. link(cstr.file .. 'IconHelpLoading killer.png|32px') .. '</div>' ..
  +
'<div class = "fplinks charSection">'
  +
  +
maxId = utils.getMaxId(killers)
  +
for i, killer in ipairs(killers) do
  +
fileName = utils.resolveCharacterPortraitFileName(killer, maxId)
  +
  +
result = result ..
  +
'<div class = "fplink charMainPageBox plainlinks image"><div class="box"><div class="row"><div class="cell">' ..
  +
'<div class = "image">' .. link(cstr.file .. fileName .. '.png|link=' .. the(killer) .. killer.name) .. '</div>' ..
  +
'<div class = "charLink killerLink link">' .. link(the(killer) .. killer.name) .. '</div>' ..
  +
'<div class = "charPerkBox">' .. resolveCharPerksMainPage(killer) .. '</div>' ..
  +
'</div></div></div></div>'
  +
end
  +
result = result ..
  +
'</div>' ..
  +
'</div>'
  +
  +
return result
  +
end
  +
  +
function resolveCharPerksMainPage(character)
  +
local mPerks = require("Module:Perks")
  +
local result = cstr.empty
  +
local perkList = mPerks.getPerksByCharacter(character)
 
 
  +
utils.sortPerksByLevel(perkList)
local firstLetter, secondLetter
 
  +
for _, perk in ipairs(perkList) do
  +
result = result .. file(mPerks.getTeachablePerkIcon(perk, true), 'link=' .. perk.name, '42px')
  +
end
 
 
  +
return result
firstLetter, secondLetter = killers[i].name:match("^(%S)(%S).*$") --could be merged but I keep it separated for case of need
 
  +
end
  +
  +
function getKillerListWithPerks()
  +
local perkTable = {}
  +
for _,perk in ipairs(perks) do
  +
if perk.character ~= nil and perk.charType == 'K' then
  +
if perkTable[perk.character] == nil then
  +
perkTable[perk.character] = {}
  +
end
  +
perkTable[perk.character].id = perk.character
  +
perkTable[perk.character][#perkTable[perk.character]+1] = perk
  +
end
  +
end
 
 
  +
return perkTable
return string.upper(firstLetter .. secondLetter)
 
 
end
 
end
   
function getDlcById(id)
+
function p.resolveKillersEntries()
  +
local perkTable = getKillerListWithPerks()
for _, dlc in ipairs(dlcs) do
 
  +
local result = ""
if dlc.id == id then return dlc end
 
  +
  +
result = result .. '<div style = "display: flex; flex-flow: row wrap; justify-content:center;">' .. nl
  +
  +
for _, trio in ipairs(perkTable) do
  +
result = result .. '<div class = "entryTable">' .. nl ..
  +
'{| class = "wikitable"' .. nl
  +
  +
killer = p.getKillerById(trio.id)
  +
result = result .. '|+ ' .. killer.name .. nl ..
  +
ntl .. nl ..
  +
tl .. 'rowspan = 3 | [[' .. cstr.file .. resolveKillerPortraitImageFileName(killer) .. '.png|99px|link=' .. (killer.shortName or killer.realName or killer.name) .. ']]' .. nl
  +
utils.sortPerksByLevel(trio)
  +
for i, perk in ipairs(trio) do
  +
result = result .. hl .. file(perkImg.main(perk.techName or perk.name),"33px") .. nl ..
  +
hl ..link(perk.name) .. nl ..
  +
tl .. clr(6, perk.level) .. nl
  +
if i < #trio then
  +
result = result .. ntl .. nl
  +
end
  +
end
  +
result = result .. '|}' .. nl ..
  +
'</div>' .. nl
 
end
 
end
  +
  +
result = result .. '</div>' .. nl
  +
  +
--mw.log(result)
  +
--mw.log(mw.dumpObject(perkTable))
  +
return result
 
end
 
end
   

Wersja z 11:34, 4 lip 2022


local p = {}
local data = require("Module:Datatable")
local mathOps = require("Module:MathOps")
local utils = require("Module:Utils")
local perksData = mw.loadData("Module:Datatable/Perks")
local perkImg = require("Module:PerkImage")
local str = require("Module:Strings")
local frame = mw.getCurrentFrame()
local _defaultSpeed = 4 --m/s | 100%

local perks = perksData.perks

local strings = {
	file = "Plik",
	killers = "Zabójcy",
	the = "",
	unknownKiller = "UnknownKiller",
	realName = "Nazwa",
	noName = "Brak", --When the killer doesn't have the real name (ex. Demogorgon)
	altName = "Alias",
	gender = "Płeć",
	nationality = "Narodowość",
	realm = "Lokacja", --link
	power = "Moc", --link
	powerType = "Typ Mocy [[Atak|Ataku]]",
	spAttackTrue = "Specjalny Atak",
	spAttackFalse = "Podstawowy Atak",
	weapon = "Broń",
	weapons = "Bronie",
	speed = "Prędkość Ruchu", --iconlink
	altSpeed = "Alternatywna Prędkość ruchu",
	metres = "metrów",
	m = "m", --abbreviation of metres
	terror = "Zasięg Terroru", --iconlink
	altTerror = "Alternatywny Zasięg Terroru",
	lullabyRadius = "Zasięg [[Kołysanka|Kołysanki]]",
	height = "Wzrost", --image
	tall = "Wysoki",
	avg = "Średni",
	dlc = "DLC",
	actor = "Aktor Głosowy",
	breathing = "Oddech",
	altBreathing = "Alternatywny Oddech",
	menuMusic = "Muzyka Menu",
	terrorMusic = "Muzyka Zasięgu Terroru",
	lullaby = "Kołysanka",
	lullabies = "Kołysanki",
	uknownActor = "Nieujawniony Aktor Głosowy",
	unkownPower = "Nieznana Moc",
	unkownSpeed = "Nieznana Szybkość",


	mps = "m/s",
	err = "Error"
}

function p.getCountOfKillers()
	return utils.getCount("killer")
end

function p.getKillerById(id)
	for _, killer in ipairs(killers) do
		if killer.id == id then return killer end
	end
	return nil
end

function getKillerByName(name)
	for _, killer in ipairs(killers) do
		if killer.shortName == name or killer.realName == name or killer.name == name or (the(killer) .. killer.name) == name then
			return killer
		end
	end
	return false
end

function getKillerIdByName(name)
	local result = getKillerByName(name)
	return (result and result.id) or 0
end

function p.getKillersPowerByName(name)
	local result = getKillerByName(utils.resolveParameter(name))
	return (result and result.power) or strings.unkownPower
end

function p.getKillersSpeedByName(name)
	local result = getKillerByName(utils.resolveParameter(name))
	if result then
		if type(result.speed) == types.table then
			return result.speed[0]
		else
			return result.speed
		end
	end
	return strings.unkownSpeed
end

--articleless => whether the nickname is supposed to return with "The " before the name itself
function p.getKillerNicknameByRealName(args, articleless)
	articleless = utils.bool(utils.resolveParameter(args, "articleless", true))
	name = utils.resolveParameter(args)
	for _, killer in ipairs(killers) do
		if killer.shortName == name or killer.realName == name or killer.name == name or (the(killer) .. killer.name) == name then
			return ((not articleless and the(killer) .. space) or cstr.empty) .. killer.name
		end
	end
	return strings.unkwnKiller
end

function p.resolveKillerCharTable(name)
	local dlcs = require("Module:DLCs")
	name = utils.resolveParameter(name)
	killerId = getKillerIdByName(name)
	killer = utils.getCharacterById(killerId, killers)
	reuslt = ""
	
	if type(killer) ~= "table" then return killer end
	
	result = 
	'{| class = "infoboxtable"' .. nl ..
	ntl ..' class = "infoboxTitle" | ' .. nl ..
	'! class = "center bold" colspan = 2 | ' .. the(killer) .. ' ' .. killer.name .. nl .. ntl .. nl ..
	
--	'<tabber>' ..
--	'|-|First=' ..
--	'First tab sample text.' ..
--	'|-|Second=' ..
--	'Second tab content goes here. ' ..
--	'|-|Third Tab Title=' ..
--	'Third tab content goes here.' ..
--	'</tabber>' ..

	'! class = "center" colspan = 2 | ' .. link(cstr.file .. resolveKillerPortraitImageFileName(killer) .. '.png|150px') .. nl ..
	ntl .. nl
	if killer.realName ~= nil then
		result = result .. '| class = "titleColumn" | ' .. strings.realName .. ' || class = "valueColumn" | ' .. (killer.shortName or killer.realName or strings.noName) .. nl .. ntl .. nl
	end
	if killer.altName ~= nil then
		result = result .. '| class = "titleColumn" | ' .. strings.altName .. ' || class = "valueColumn italic" | ' .. resolveAltName(killer) .. nl .. ntl .. nl
	end
	result = result ..
	'| class = "titleColumn" | ' .. strings.gender .. ' || class = "valueColumn" | ' .. utils.resolveGender(killer.gender) .. nl .. ntl .. nl ..
	'| class = "titleColumn" | ' .. strings.nationality .. ' || class = "valueColumn" | ' .. killer.nationality .. nl .. ntl .. nl
	if killer.realm ~= nil or killer.dlc ~= nil then
		local killerRealm = resolveKillerRealm(killer)
		if killerRealm ~= 0 then
			result = result .. '| class = "titleColumn" | ' .. link(strings.realm) .. ' || class = "valueColumn" | [[' .. killerRealm .. ']] ' .. nl .. ntl .. nl
		end
	end
	result = result ..
	'| class = "titleColumn" | ' .. link(strings.power) .. ' || class = "valueColumn" | ' .. link(killer.power) .. nl .. ntl .. nl
	if killer.specialAttack ~= nil then
		result = result .. '| class = "titleColumn" | ' .. strings.powerType .. ' || class = "valueColumn" | ' .. resolvePowerAttack(killer) .. nl .. ntl .. nl
	end
	result = result ..
	'| class = "titleColumn" | ' .. link(strings.weapon) .. ' || class = "valueColumn" | ' .. link(strings.weapons .. '#' .. the(killer) .. killer.name .. tl .. killer.weapon) .. nl .. ntl .. nl ..
	'| class = "titleColumn" | ' .. utils.IconLink(strings.speed) .. ' || class = "valueColumn" | ' .. resolveKillerSpeed(killer) .. nl .. ntl .. nl
	if killer.altSpeed ~= nil then
		result = result .. '| class = "titleColumn" | ' .. strings.altSpeed .. ' || class = "valueColumn" | ' .. resolveAltSpeed(killer) .. nl .. ntl .. nl
	end
	result = result ..
	'| class = "titleColumn" | ' .. utils.IconLink(strings.terror) .. ' || class = "valueColumn" | ' .. resolveTerrorRadius(killer) .. nl .. ntl .. nl
	local altTerror = resolveAltTerrorRadius(killer)
	if altTerror then
		result = result .. '| class = "titleColumn" | ' .. strings.altTerror .. ' || class = "valueColumn" | ' .. altTerror .. nl .. ntl .. nl		
	end
	local lullabyRadius = resolveLullabyRadius(killer)
	if lullabyRadius then
		result = result .. '| class = "titleColumn" | ' .. strings.lullabyRadius .. ' || class = "valueColumn" | ' .. lullabyRadius .. nl .. ntl .. nl
	end
	result = result ..
	'| class = "titleColumn" | ' .. strings.height .. space .. utils.IconLink(strings.height, "img") .. ' || class = "valueColumn" | ' .. resolveHeight(killer) .. nl .. ntl .. nl
	if killer.dlc ~= nil then
		result = result .. '| class = "titleColumn" | ' .. strings.dlc .. ' || class = "valueColumn" | ' .. link(dlcs.getDlcById(killer.dlc).name) .. space .. nl .. ntl .. nl
	end
	result = result ..
	'| class = "titleColumn" | ' .. strings.actor .. ' || class = "valueColumn" | ' .. resolveActor(killer) .. nl
	local breathingMusic = resolveBreathingMusic(killer)
	if breathingMusic then
		result = result .. ntl .. nl ..
		'| class = "titleColumn center" colspan = 2 ' .. tl .. space .. strings.breathing .. nl .. ntl .. nl ..
		'| class = "valueColumn center soundColumn" colspan = 2 ' .. tl .. space .. breathingMusic .. nl
	end
	local altBreathing = resolveAltBreathing(killer)
	if altBreathing then 
		result = result .. ntl .. nl ..
		tl .. ' class = "titleColumn center" colspan = 2 ' .. tl .. space .. strings.altBreathing .. nl .. ntl .. nl ..
		tl .. ' class = "valueColumn center soundColumn" colspan = 2 ' .. tl .. space .. altBreathing .. nl
	end
	local theme = resolveKillerThemeMusic(killer)
	if theme then
		result = result .. ntl .. nl ..
		'| class = "titleColumn center" colspan = 2 ' .. tl .. space .. strings.menuMusic .. nl .. ntl .. nl ..
		'| class = "valueColumn center soundColumn" colspan = 2 ' .. tl .. space .. theme .. nl
	end
	local terrorMusic = resolveTRMusic(killer)
	if terrorMusic then
		result = result .. ntl .. nl ..
		'| class = "titleColumn center" colspan = 2 ' .. tl .. space .. strings.terrorMusic .. nl ..	ntl .. nl ..
		'| class = "valueColumn center soundColumn" colspan = 2 ' .. tl .. space .. terrorMusic .. nl
	end

	local lullaby = resolveLullaby(killer, 1)
	local counter = ((lullaby and 1) or 0) --if you find a lullaby then set the counter to 1, otherwise 0
	local tempResult = cstr.empty
	while lullaby do
		tempResult = tempResult .. ntl .. nl ..
		'| class = "valueColumn center soundColumn" colspan = 2 ' .. tl .. space .. lullaby .. nl
		
		counter = counter + 1
		lullaby = resolveLullaby(killer, counter)
	end
	
	if counter > 0 then --if lullaby was found
		result = result .. ntl .. nl .. '| class = "titleColumn center" colspan = 2 | ' .. ((counter > 2 and strings.lullabies) or strings.lullaby) .. nl .. tempResult
	end
	
	result = result .. '|}'
	
	mw.log(result)
	return result
end

function resolveAltTerrorRadius(killer)
	if not killer.altRadius then return false end
	local result = killer.altRadius
	if type(killer.altRadius) == "table" then
		result = cstr.empty
		for i, radius in ipairs(killer.altRadius) do
			result = result .. radius[1] .. space .. brackets(radius[2]) .. ((i < #killer.altRadius and dnl) or cstr.empty)
		end
	end
	return result
end

function resolveActor(killer)
	local result = strings.uknownActor
	
	if type(killer.actor) == "string" then
		result = killer.actor
	elseif type(killer.actor) == "table" then
		result = cstr.empty
		for i, actor in ipairs(killer.actor) do
			result = result .. actor .. ((i < #killer.actor and dnl) or cstr.empty)
		end
	end
	return result
end

function resolveLullabyRadius(killer)
	if not killer.lullabyRadius then return false end
	local result = cstr.empty
	
	if type(killer.lullabyRadius) == "table" then
		for i, lullaby in ipairs(killer.lullabyRadius) do
			result = result .. lullaby[1] .. space .. strings.metres .. space .. brackets(lullaby[2])
			if i < #killer.lullabyRadius then
				result = result .. dnl
			end
		end
	else
		result = (killer.lullabyRadius and killer.lullabyRadius .. space ..strings.metres) or cstr.empty
	end
	
	return result
end

function resolveBreathingMusic(killer)
	file = (killer.techName or killer.name) .. space .. 'Breathing'
	valid = utils.isValidFileName(file, cstr.ogg)
	return (valid and link(cstr.file .. file .. dot .. cstr.ogg)) or valid
end

function resolveAltBreathing(killer, index)
	file = (killer.techName or killer.name) .. space .. 'Breathing' .. space .. (index or 2)
	valid = utils.isValidFileName(file, cstr.ogg)
	return (valid and link(cstr.file .. file .. dot .. cstr.ogg)) or valid
end

function resolveKillerThemeMusic(killer)
	local dlcs = require("Module:DLCs")
	local dlc = dlcs.getDlcById(killer.dlc)
	local fileConst = '_Theme_Music'
	local file = cstr.empty
	if not killer.dlc then
		file = killer.techName or killer.name
	else
		file = utils.resolveFileName(utils.CapitalizeName(dlc.name), true, true)
	end
	file = (file or cstr.empty) .. fileConst
	if killer.dlc then
		for _, theme in ipairs(dlcThemes) do
			if theme.id == dlc.id then
				file = theme.fileName
			end
		end
	end
	local valid = utils.isValidFileName(file, cstr.ogg)
	return (valid and link(cstr.file .. file .. dot .. cstr.ogg)) or valid
end

function resolveTRMusic(killer)
	file = 'TerrorRadius_' .. (killer.techName or killer.name)
	local valid = utils.isValidFileName(file, cstr.ogg)
	return (valid and link(cstr.file .. file .. dot .. cstr.ogg)) or valid
end

function resolveLullaby(killer, index)
	file = (killer.techName or killer.name) .. space .. 'Lullaby' .. ((index and space .. index) or cstr.empty)
	valid = utils.isValidFileName(file, cstr.ogg)
	return (valid and link(cstr.file .. file .. dot .. cstr.ogg)) or valid
end

--addon is for cosmetics portraits (used in Module:Cosmetics)
function resolveKillerPortraitImageFileName(killer, addon)
	local fileConst = "_charSelect_portrait"
	return "K" .. string.format("%02d", killer.id) .. ((addon and space .. addon) or cstr.empty) .. fileConst
end

function resolveAltName(killer)
	if type(killer.altName) == "string" then return '"' .. killer.altName .. '"'
	elseif type(killer.altName) == "table" then
		local result = ""
		for i, name in ipairs(killer.altName) do
			result = result .. '"' .. name .. '"'
			if i < #killer.altName then 
				result = result .. dnl
			end
		end
		return result
	end
	
	return strings.err
end

function resolvePowerAttack(killer)
	result = ""
	
	if killer.specialAttack then 
		result = strings.spAttackTrue
	else
		result = strings.spAttackFalse
	end
	
	if killer.altAttackNote ~= nil then
		result = result .. nl .. "(" .. killer.altAttackNote .. ")"
	end
	
	return result
end

function resolveKillerRealm(killer)
	if killer.dlc == nil then
		for _, realm in ipairs(realms) do
			if realm.id == killer.realm then return realm.name end
		end
	else
		for _, realm in ipairs(realms) do
			if type(realm.dlc) == "number" and killer.dlc == realm.dlc then return realm.name
			elseif type(realm.dlc) == "table" then
				for _, dlcId in ipairs(realm.dlc) do
					if dlcId == killer.dlc then return realm.name end
				end
			end
		end
	end
	return 0
end

function resolveKillerSpeed(killer)
	local result = cstr.empty
	
	if type(killer.speed) == "number" then
		result = getPercentSpeed(killer.speed) .. space .. '%' .. space .. b(bar) .. space .. killer.speed .. space .. strings.mps
	else --so the killer speed is table
		result = getPercentSpeed(killer.speed[1]) .. space .. '%' .. space .. b(bar) .. space .. killer.speed[1] .. space .. strings.mps .. space .. brackets(killer.speed[2])
	end

	return result
end

function resolveAltSpeed(killer)
	local result = ""
	local speedPercent
	
	for i, altSpeed in ipairs(killer.altSpeed) do
		speedPercent = getPercentSpeed(altSpeed[1])
		
		result = result .. speedPercent .. " % " .. b(bar) .. space .. altSpeed[1] .. space .. strings.mps
		if altSpeed[2] ~= nil then
			result = result .. pg .. "(" .. altSpeed[2] .. ")"
		end
		
		if i < #killer.altSpeed then 
			result = result .. "<hr>" --.. nl .. nl
		end
	end
	
	return result
end

function getPercentSpeed(speed)
	return (speed / _defaultSpeed) * 100
end

function resolveTerrorRadius(killer)
	result = ""
	
	if type(killer.radius) == "number" then
		return killer.radius .. space .. strings.metres
	elseif type(killer.radius) == "table" then
		for i, radius in ipairs(killer.radius) do
			if radius[3] ~= nil then --open span with title hover
				result = result .. '<span class = "valueTooltip" title = "' .. radius[3] .. '">'
			end
			result = result .. radius[1] --metres value
			if radius[2] ~= nil then --note for alt speed, if there is a note for the speed the abbreviation for metres is used instead of full name
				result = result .. strings.m .. space .. brackets(radius[2])
			else
				result = result .. " " .. strings.metres
			end
			if radius[3] ~= nil then --close span hover
				result = result .. '</span>'
			end
			if i < #killer.radius then 
				result = result .. nl .. nl
			end
		end
	end
	return result
end

function resolveHeight(killer)
	if		killer.height == 'T'	then return strings.tall
	elseif	killer.height == 'A'	then return strings.avg
	elseif	killer.height == 'S'	then return strings.short
	else								 return strings.err
	end
end

function p.resolveKillersTable()
	local result = ""
	local name
	local fileName

	result = result .. '<div style="color: #fff;">'
	maxId = utils.getMaxId(killers)
	for i, killer in ipairs(killers) do
		name = killer.shortName or killer.realName or killer.name
		fileName = utils.resolveCharacterPortraitFileName(killer, maxId)
		
		result = result .. 
			'<div style="display: inline-block; text-align:center; margin: 10px">' .. link(name) .. ' - ' .. killer.name ..
			link(cstr.file .. fileName .. '.png|center|frameless|link=' .. the(killer) .. " " .. killer.name) .. '</div>'
	end
	result = result .. '</div>'

	return result
end

function p.resolveKillersTableMainPage()
	local result = ""
	local name
	local fileName

	result = result .. 
		'<div class = "fpbox" id = "fpkiller" style = "text-align: center;">' ..
		'<div class = "heading">' .. the(strings.killers) .. link(strings.killers) .. space .. link(cstr.file .. 'IconHelpLoading killer.png|32px') .. '</div>' ..
		'<div class = "fplinks charSection">'
		
	maxId = utils.getMaxId(killers)
	for i, killer in ipairs(killers) do
		fileName = utils.resolveCharacterPortraitFileName(killer, maxId)
		
		result = result .. 
		'<div class = "fplink charMainPageBox plainlinks image"><div class="box"><div class="row"><div class="cell">' ..
			'<div class = "image">' .. link(cstr.file .. fileName .. '.png|link=' .. the(killer) .. killer.name) .. '</div>' ..
			'<div class = "charLink killerLink link">' .. link(the(killer) .. killer.name) .. '</div>' .. 
			'<div class = "charPerkBox">' .. resolveCharPerksMainPage(killer) .. '</div>' ..
		'</div></div></div></div>'
	end
	result = result .. 
		'</div>' ..
		'</div>'

	return result
end

function resolveCharPerksMainPage(character)
	local mPerks = require("Module:Perks")
	local result = cstr.empty
	local perkList = mPerks.getPerksByCharacter(character)
	
	utils.sortPerksByLevel(perkList)
	for _, perk in ipairs(perkList) do
		result = result .. file(mPerks.getTeachablePerkIcon(perk, true), 'link=' .. perk.name, '42px')
	end
	
	return result
end

function getKillerListWithPerks()
	local perkTable = {}
	for _,perk in ipairs(perks) do
		if perk.character ~= nil and perk.charType == 'K' then
			if perkTable[perk.character] == nil then
				perkTable[perk.character] = {}
			end
			perkTable[perk.character].id = perk.character
			perkTable[perk.character][#perkTable[perk.character]+1] = perk
		end
	end
	
	return perkTable
end

function p.resolveKillersEntries()
	local perkTable = getKillerListWithPerks()
	local result = ""
	
	result = result .. '<div style = "display: flex; flex-flow: row wrap; justify-content:center;">' .. nl
	
	for _, trio in ipairs(perkTable) do
		result = result .. '<div class = "entryTable">' .. nl ..
		'{| class = "wikitable"' .. nl
		
		killer = p.getKillerById(trio.id)
		result = result .. '|+ ' .. killer.name .. nl ..
		ntl .. nl ..
		tl .. 'rowspan = 3 | [[' .. cstr.file .. resolveKillerPortraitImageFileName(killer) .. '.png|99px|link=' .. (killer.shortName or killer.realName or killer.name) .. ']]' .. nl
		utils.sortPerksByLevel(trio)
		for i, perk in ipairs(trio) do
			result = result .. hl .. file(perkImg.main(perk.techName or perk.name),"33px") .. nl ..
			hl ..link(perk.name) .. nl ..
			tl .. clr(6, perk.level) .. nl
			if i < #trio then
				result = result .. ntl .. nl
			end
		end
		result = result .. '|}' .. nl ..
		'</div>' .. nl
	end
	
	result = result .. '</div>' .. nl
	
	--mw.log(result)
	--mw.log(mw.dumpObject(perkTable))
	return result
end

return p