local p = {}
local data = require("Module:Datatable")
local mathOps = require("Module:MathOps")
local utils = require("Module:Utils")
local frame = mw.getCurrentFrame()
local defaultSpeed = 4 --m/s | 100%
local bar = "|" -- code for |
local nl = "\n"
local ntl = "|-"
local strings = {
file = "File",
killers = "Killers",
the = "The",
unknownKiller = "UnknownKiller",
realName = "Name",
noName = "None", --When the killer doesn't have the real name (ex. Demogorgon)
altName = "Game Alias(es)",
gender = "Gender",
nationality = "Nationality",
realm = "Realm", --link
power = "Power", --link
powerType = "Power [[Attack]] Type",
spAttackTrue = "Special Attack",
spAttackFalse = "Basic Attack",
weapon = "Weapon",
speed = "Movement speed", --iconlink
altSpeed = "Alternate Movement speed",
metres = "metres",
m = "m", --abbreviation of metres
terror = "Terror Radius", --iconlink
lullabyRadius = "[[Lullaby]] Radius",
height = "Height", --image
tall = "Tall",
avg = "Average",
dlc = "DLC",
actor = "Voice Actor",
breathing = "Breathing",
altBreathing = "Alternate Breathing",
menuMusic = "Menu Music",
terrorMusic = "Terror Radius Music",
lullaby = "Lullaby",
lullabies = "Lullabies",
mps = "m/s",
err = "Error"
}
function p.getCountOfKillers()
return utils.getCount("killer")
end
function getKillerIndexById(id) --not used
for i, s in ipairs(killers) do
if s.id == id then return i end
end
return 0
end
function getKillerIdByName(name)
for _, killer in ipairs(killers) do
if killer.realName == name then
return killer.id
end
end
return 0
end
function p.resolveKillerCharTable(name)
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 | ' .. strings.the .. ' ' .. killer.name .. nl ..
ntl .. nl ..
'! class = "center" colspan = 2 | [[' .. strings.file .. ':' .. resolveKillerPortraitImageFileName(killer) .. '.png|150px]]' .. nl ..
ntl .. nl
if killer.realName ~= nil then
result = result .. '| class = "titleColumn" | ' .. strings.realName .. ' || class = "valueColumn" | ' .. (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" | ' .. strings.realm .. ' || class = "valueColumn" | [[' .. killerRealm .. ']] ' .. nl .. ntl .. nl
end
end
result = result ..
'| class = "titleColumn" | ' .. strings.power .. ' || class = "valueColumn" | [[' .. 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" | ' .. strings.weapon .. ' || class = "valueColumn" | [[' .. killer.weapon .. ']]' .. nl ..
ntl .. nl ..
'| class = "titleColumn" | ' .. strings.speed .. ' || class = "valueColumn" | ' .. resolveKillerSpeed(killer) .. nl ..
ntl .. nl
if killer.altSpeed ~= nil then
result = result .. '| class = "titleColumn" | ' .. strings.dlc .. ' || class = "valueColumn" | ' .. resolveAltSpeed(killer) .. nl .. ntl .. nl
end
result = result ..
'| class = "titleColumn" | ' .. strings.terror .. ' || class = "valueColumn" | ' .. resolveTerrorRadius(killer) .. nl ..
ntl .. nl ..
'| class = "titleColumn" | ' .. strings.height .. ' || class = "valueColumn" | ' .. resolveHeight(killer) .. nl ..
ntl .. nl
if killer.dlc ~= nil then
result = result .. '| class = "titleColumn" | ' .. strings.dlc .. ' || class = "valueColumn" | [[' .. getDlcById(killer.dlc).name .. ']] ' .. nl .. ntl .. nl
end
result = result ..
'| class = "titleColumn" | ' .. strings.actor .. ' || class = "valueColumn" | ' .. (killer.actor or strings.uknownActor) .. nl ..
--TODO Check all music existence, this should be in separate table, Twinsuse Twins as a reference
ntl .. nl ..
'| class = "titleColumn center" colspan = 2 | ' .. strings.breathing .. nl ..
ntl .. nl ..
'| class = "valueColumn" | ' .. "Breathing" .. nl ..
ntl .. nl ..
'| class = "titleColumn center" colspan = 2 | ' .. strings.menuMusic .. nl ..
ntl .. nl ..
'| class = "valueColumn" | ' .. "Menu Music" .. nl ..
ntl .. nl ..
'| class = "titleColumn center" colspan = 2 | ' .. strings.terrorMusic .. nl ..
ntl .. nl ..
'| class = "valueColumn" | ' .. "Terror Radius Music" .. nl ..
ntl .. nl ..
'| class = "titleColumn center" colspan = 2 | ' .. strings.lullaby .. nl ..
ntl .. nl ..
'| class = "valueColumn" | ' .. "Lullaby" .. nl ..
'|}'
mw.log(result)
return result
end
function resolveKillerPortraitImageFileName(killer)
local fileConst = "_charSelect_portrait"
return "K" .. string.format("%02d", killer.id) .. 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 .. nl
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 i, dlc in ipairs(killer) do
if dlc.id == dlc[i] then return realm.name end
end
end
end
end
return 0
end
function resolveKillerSpeed(killer)
local speedPercent = 0
local speedMps = 0
local note
local result
if type(killer.speed) == "number" then
speedPercent = killer.speed
speedMps = defaultSpeed * (killer.speed / 100) --speed is in percentage
else --so the killer speed is table
speedPercent = killer.speed[1]
speedMps = defaultSpeed * (killer.speed[1] / 100)
note = killer.speed[2]
end
result = speedPercent .. " % <b>" .. bar .. "</b> " .. speedMps .. " " .. strings.mps
if note ~= nil then
result = result .. nl .. "(" .. note .. ")"
end
return result
end
function resolveAltSpeed(killer)
local result = ""
local speedMps
for i, altSpeed in ipairs(killer.altSpeed) do
speedMps = defaultSpeed * (altSpeed[1] / 100)
result = result .. altSpeed[1] .. " % <b>" .. bar .. "</b> " .. speedMps .. " " .. strings.mps
if altSpeed[2] ~= nil then
result = result .. "(" .. altSpeed[2] .. ")"
end
if i < #killer.altSpeed then
result = result .. nl
end
end
return result
end
function resolveTerrorRadius(killer)
result = ""
if type(killer.radius) == "number" then
return killer.radius .. " 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 .. " (" .. 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
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
else return strings.err
end
end
function p.resolveKillersTable()
local result = ""
local name
local fileName
result = result .. "<div style=\"color: #fff;\">"
for i, killer in ipairs(killers) do
name = killer.shortName or killer.realName or killer.name
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=" .. strings.the .. " " .. 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;\">"
result = result .. "<div class=\"heading\">The [[" .. strings.killers .. "]] [[File:IconHelpLoading killer.png|32px]]</div>"
result = result .. "<div class=\"fplinks\">"
for i, killer in ipairs(killers) do
fileName = resolveKillersPortraitFileNameById(killer.id)
result = result .. "<div class=\"fplink plainlinks image\"><div class=\"box\"><div class=\"row\"><div class=\"cell\">"
result = result .. "<div class=\"image\">[[File:" .. fileName .. ".png|link=" .. strings.the .. " " .. killer.name .. "]]</div>"
result = result .. "<div class=\"link\">[[" .. strings.the .. " " .. killer.name .. "]]</div></div></div></div></div>"
end
result = result .. "</div>"
result = result .. "</div>"
return result
end
function resolveKillersPortraitFileNameById(id)
local fileConst = "_charPreview_portrait"
local fileName
fileName = getFileNameFromTableById(id) --get custom name from table
if not utils.isValidFileName(fileName) then --K{ID}_charPreview_portrait
fileName = "K" .. string.format("%02d", id) .. fileConst
end
if not utils.isValidFileName(fileName) then --File not Found
fileName = strings.unknownKiller .. fileConst
end
mw.log(fileName)
return fileName
end
function getFileNameFromTableById(id)
mw.log(id)
for j, sImage in ipairs(killerImages) do
if sImage.id == id then
return sImage.preview
end
end
return ""
end
function getDlcById(id)
for _, dlc in ipairs(dlcs) do
if dlc.id == id then return dlc end
end
end
return p
Advertisement
Module:Killers
Advertisement