Dead by Daylight Wiki

A documentação para este módulo pode ser criada na página Módulo:Survivors/doc

local p = {}
local utils = require("Module:Utils")
local data = require("Module:Datatable" .. utils.lang())
local perksData = mw.loadData("Module:Datatable/Loadout" .. utils.lang())
local perkImg = require("Module:PerkImage")
local str = require("Module:Strings")
local frame = mw.getCurrentFrame()

p.strings = {
	survNotFound = "Sobrevivente não encontrado",
	name = "Nome",
	altName = "Outro(s) Nome(s)",
	gender = "Gênero",
	role = "Papel",
	origin = "Origem",
	dlc  = "DLC",
	actor = "Dublador(a)",
	unknownActor = "Dublador(a) não revelado(a)", --unkown/undisclosed
	male = "Homem",
	female = "Mulher",
	transmale = "Homem Trans",
	transfemale = "Mulher Trans",
	undefined = "Indefinido",
	survivors = "Sobreviventes",
	menuMusic = "Mýsica do Menu",
	cost = "Custo",
	freeCost = "Free", --this string needs to be same as the string at DLCs that are free
	metadata = "Metadados",
	
	--Metadata
	charid = "CharID",
	themeFilename = "Theme Filename"
}
local strings = p.strings
----------------------------------------------
if utils.lang() ~= cstr.empty and (counter or 0) < 1 then
	counter = (counter or 0) + 1
	strings = require("Module:Survivors" .. utils.lang()).strings
end

local perks = perksData.perks

function p.getCountOfSurvivors()
	return utils.getCount("survivor")
end

function getSurvivorNameById(id) --not used
	for _, s in ipairs(survivors) do
		if s.id == id then return s.name end
	end
	return 0
end

function getSurvivorIdByName(name)
	for _, survivor in ipairs(survivors) do
		if survivor.name == name then
			return survivor.id
		end
	end
	
	return 0
end

function p.getSurvivorById(id)
	for _, survivor in ipairs(survivors) do
		if survivor.id == id then return survivor end
	end
	return nil
end

function p.resolveSurvivorsTableMainPage()
	local result = cstr.empty
	local name
	local fileName

	result = result ..
		'<div class = "fpbox" id = "fpsurvivors" style = "text-align: center;">' .. nl ..
			'<div class = "heading">' .. the(strings.survivors) .. space .. link(strings.survivors) .. space .. link(cstr.file .. 'IconHelpLoading survivor.png|32px') .. '</div>' .. nl ..
			'<div class = "fplinks charSection">' .. nl
			
		utils.sortTableById(survivors)
		local maxId = utils.getMaxId(survivors)
		for i, survivor in ipairs(survivors) do
			name = (survivor.moniker and the(survivor) .. survivor.moniker) or survivor.shortName or survivor.name
			fileName = utils.resolveCharacterPortraitFileName(survivor, maxId)
			
			result = result .. 
				'<div class = "fplink charMainPageBox plainlinks image">' .. nl ..
					'<div class = "box">' .. nl ..
						'<div class = "row">' .. nl ..
							'<div class = "cell">' .. nl ..
								'<div class = "image">' .. file(fileName .. dot .. cstr.png, 'link=' .. name) .. '</div>' .. nl ..
								'<div class = "charLink survivorLink link">' .. link(name) .. '</div>' .. nl ..
								'<div class = "charPerkBox">' .. resolveCharPerksMainPage(survivor) .. '</div>' .. nl ..
							'</div>' .. nl ..
						'</div>' .. nl ..
					'</div>' .. nl ..
				'</div>' .. nl
		end
		result = result ..
			'</div>' .. nl ..
		'</div>' .. nl

	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 .. utils.assembleImage("sosPerk", perk.name, 42)
	end
	--Teachable unknown.png
	return result
end

function p.resolveSurvivorCharTable(charName)
	local dlcs = require("Module:DLCs")
	local various = require("Module:Various")
	charName = utils.resolveParameter(charName, 1, false)
	local survivorId = getSurvivorIdByName(charName)

	local surv = utils.getCharacterById(survivorId, survivors)
	if not surv then return strings.survNotFound end
	local result = cstr.empty
	
	surv.dlcList = dlcs.getDlcsByCharacter(surv)
	surv.dlc = dlcs.getMainDlc(surv.dlcList) --Main DLC
	surv.isPriceHalved = dlcs.isPriceHalved(surv.dlcList)
	
	if type(surv) ~= types.table then return utils.resolveParameter(charName) end
	
	result = 
		'{| class = "infoboxtable charInfoboxTable survivorInfobox"' .. nl ..
		ntl ..' class = "infoboxTitle" | ' .. nl ..
		'! class = "center bold" colspan = 2 | ' .. ((surv.moniker and the(surv) .. surv.moniker) or surv.shortName or surv.name) .. nl ..
		ntl .. nl ..
		'! class = "center charInfoboxImage" colspan = 2 | ' .. various.getCharPortrait(surv, nil, false) .. nl ..
		ntl .. nl
	
	if surv.moniker ~= nil then
		result = result .. tl .. class('titleColumn') .. tl .. strings.name .. dtl .. class('valueColumn') .. tl .. (surv.shortName or surv.name) .. nl .. ntl .. nl
	end	
	if surv.altName ~= nil then
		result = result .. tl .. class('titleColumn') .. tl .. strings.altName .. dtl .. class('valueColumn') .. tl .. surv.altName .. nl .. ntl .. nl
	end
	result = result ..
		tl .. class('titleColumn') .. tl .. strings.gender .. dtl .. class('valueColumn') .. tl .. surv.gender .. nl ..
		ntl .. nl ..
		((surv.role and tl .. class('titleColumn') .. tl .. strings.role .. dtl .. class('valueColumn') .. tl .. surv.role .. nl ..
		ntl .. nl) or cstr.empty) ..
		tl .. class('titleColumn') .. tl .. strings.origin .. dtl .. class('valueColumn') .. tl .. surv.origin .. nl ..
		ntl .. nl
	if surv.dlc ~= nil then
		result = result .. tl .. class('titleColumn') .. tl .. strings.dlc .. dtl .. class('valueColumn') .. tl .. dlcs.getDlcFullNameByCharacter(surv) .. nl .. ntl .. nl
	end
	result = result ..
		tl .. class('titleColumn') .. tl .. strings.actor .. dtl .. class('valueColumn') .. tl .. (surv.actor or strings.uknownActor) .. nl
	if surv.dlc and 
		(
			(not surv.dlc.retracted and (surv.dlc.cost == nil or type(surv.dlc.cost) == types.table or (type(surv.dlc.cost) == types.string and surv.dlc.cost ~= strings.freeCost)))
		or	(surv.dlc.retracted and surv.isPriceHalved)
		)
		then
			
		local ac = utils.getCcyById(5) --we retrieve the ac and is currency (mainly due to other non-en wikis)
		local is = utils.getCcyById(3)
		result = result .. ntl .. nl .. 
			tl .. class('titleColumn') .. tl .. strings.cost .. dtl .. class('valueColumn') .. tl .. 
			((not surv.dlc.licensed and utils.commaFormat((surv.isPriceHalved and data.charISCost / 2) or data.charISCost) .. space .. utils.IconLink(is.plural or is.name .. "s") .. nl) or cstr.empty) ..
			utils.commaFormat((surv.isPriceHalved and data.charACCost / 2) or data.charACCost) .. space .. utils.IconLink(ac.plural or ac.name .. "s") .. nl
	end
	local theme, themeSuccess = various.resolveCharacterThemeMusic(surv, true)
	if themeSuccess then
		result = result .. ntl .. nl ..
		tl .. class("titleColumn", "center") .. colspan(2) .. tl .. space .. strings.menuMusic .. nl .. ntl .. nl ..
		tl .. class("valueColumn", "center", "soundColumn") .. colspan(2) .. tl .. space .. theme .. nl
	end
	
	--Metadata
	local metadataNewLine = ntl .. class("metadata") .. nl .. tl .. class("titleColumn") .. tl
	result = result ..
		ntl .. nl ..
		tl .. colspan(2) .. space .. class("metadata") .. tl .. center(b(strings.metadata)) .. nl ..
		metadataNewLine .. strings.charid .. dtl .. utils.getCharacterIdentifier(surv) .. nl ..
		(surv.theme ~= false and (not themeSuccess and various.shouldHaveTheme(surv) and metadataNewLine .. strings.themeFilename .. dtl .. theme .. nl) or cstr.empty)
	
	result = result .. 
		'|}'
		
	--mw.log(result)
	return result
end

return p