Dead by Daylight Wiki
Advertisement

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

local strings = {
	killers = "Killers",
	the = "The",
	unkwnKiller = "Unknown Killer",
	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",
	weapons = "Weapons",
	speed = "Movement Speed", --iconlink
	altSpeed = "Alternate Movement speed",
	metres = "metres",
	m = "m", --abbreviation of metres
	terror = "Terror Radius", --iconlink
	altTerror = "Alternate Terror Radius",
	lullabyRadius = "[[Lullaby]] Radius",
	height = "Height", --image
	tall = "Tall",
	avg = "Average",
	short = "Short",
	dlc = "DLC",
	actor = "Voice Actor",
	breathing = "Breathing",
	altBreathing = "Alternate Breathing",
	menuMusic = "Menu Music",
	terrorMusic = "Terror Radius Music",
	lullaby = "Lullaby",
	lullabies = "Lullabies",
	uknownActor = "Undisclosed Voice Actress",
	unkownPower = "Unknown Power",
	unkownSpeed = "Unknown Speed",

	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() .. space .. 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() .. space .. killer.name) == name then
			return ((not articleless and strings.the .. 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 | ' .. strings.the .. ' ' .. 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() .. space .. 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=' .. 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;">' ..
		'<div class = "heading">' .. the() .. space .. 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() .. space .. killer.name) .. '</div>' ..
			'<div class = "charLink killerLink link">' .. link(strings.the .. space .. 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 = ''
	local perkList = mPerks.getPerksByCharacter(character)
	
	utils.sortPerksByLevel(perkList)
	for _, perk in ipairs(perkList) do
		result = result .. link(cstr.file .. mPerks.getTeachablePerkIcon(perk) .. '|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 ..
		'| 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 .. '! [[' .. cstr.file .. perkImg.main(perk.techName or perk.name) .. '|33px]]' .. nl ..
			'! [[' .. perk.name .. ']]' .. nl ..
			'| ' .. utils.clr(perk.level, 6) .. 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
Advertisement