Dead by Daylight Wiki
Dead by Daylight Wiki
Yupi101 (dyskusja | edycje)
Yupi101 (dyskusja | edycje)
 
Linia 31: Linia 31:
 
end
 
end
 
 
  +
return result
  +
end
  +
  +
function p.getCountPerksByType(pType)
  +
pType = ResolveStringParam(pType)
  +
local result = 0
  +
  +
for _, perk in ipairs(perks) do
  +
if perk.charType == pType and perk.unused ~= true then result = result + 1 end
  +
end
  +
--mw.log(result)
 
return result
 
return result
 
end
 
end

Aktualna wersja na dzień 07:29, 26 maj 2021


local p = {}
local frame = mw.getCurrentFrame()
local data = require("Module:Datatable")
local dataPerks = require("Module:Datatable/Perks")
local utils = require("Module:Utils")

local bar = "|" -- code for |
local nl = "\n"
local ntl = "|-" -- new table line

local strings = {
	perkValuesNotFound = "The Values for the perk wasn't found",
	unitNotFound = "The Unit value wasn't found"
}

function getUnusedPerksCount()
	local result = 0
	
	for _, perk in ipairs(perks) do
		if perk.unused == true then result = result + 1 end
	end

	return result
end

function getCommonPerksCount()
	local result = 0
	
	for _, perk in ipairs(perks) do
		if perk.character == nil and perk.unused ~= true then result = result + 1 end
	end
	
	return result
end

function p.getCountPerksByType(pType)
	pType = ResolveStringParam(pType)
	local result = 0
	
	for _, perk in ipairs(perks) do
		if perk.charType == pType and perk.unused ~= true then result = result + 1 end
	end
	--mw.log(result)
	return result
end

local _unusedPerksCount = getUnusedPerksCount()
local _commonPerksCount = getCommonPerksCount()
local _uniquePerksCount = table.getn(perks) - _unusedPerksCount - _commonPerksCount
local _nonUniquePerksCount = _unusedPerksCount + _commonPerksCount

p._nonUniquePerksCount = _nonUniquePerksCount
p._allPerksCount = table.getn(perks)

function p.getPerksCount() --active in game
	return _uniquePerksCount + _commonPerksCount
end

function ResolveIntParam(param)
	if type(param) == "table" and param.args[1] ~= nil then
		return tonumber(param.args[1])
	else
		return param
	end
end

function ResolveStringParam(param)
	if type(param) == "table" and param.args[1] ~= nil then
		return tostring(param.args[1])
	elseif param == nil then
		return mw.title.getCurrentTitle().text
	else
		return param
	end
end

function getUnitById(id)
	mw.log(id)
	for _,unit in ipairs(units) do
		if unit.id == id then return unit.value end
	end
	return unitNotFound
end

--Function that actually returns string that will replace the placeholder
function pl(id, tripplet)
	tripplet = tonumber(tripplet)
	for _,perk in ipairs(perks) do
		if perk.id == id then
			local index = 1 + ((tripplet - 1) * 3) --tripplet is an offset, +1 is indexing from 1 in LUA, * 3 is because every values are grouped by 3 values/tiers
			return "'''" .. utils.clr(perk.values[index], perk.baseLevel) .. "'''/'''" .. utils.clr(perk.values[index + 1], perk.baseLevel + 1) .. "'''/'''" .. utils.clr(perk.values[index + 2], perk.baseLevel + 2) .. " "
				.. getUnitById(perk.units[tripplet]) .. "'''" --Units, Tripplet is an index in 'units' list
		end
	end
	return "'''" .. strings.perkValuesNotFound .. "'''"
end

--Function replaces "#pl(x)" string with tripplet value of according number in brackets
function subValues(perkDesc)
	local result
	local regexString = "#pl%((%d)%)" -- looking and extracting number from "#pl(x)"
	for m in perkDesc.desc[1][1]:gmatch(regexString) do --TODO the first index shouldn't be hardcoded due to history log (if the description will be copied, then it won't be the first)
		mw.log(mw.dumpObject(m))
		result = perkDesc.desc[1][1]:gsub(regexString, pl(perkDesc.id, m))
		mw.log(result)
	end
	--mw.log("PL: " .. pl)
	return result
end

function p.GetPerkById(id)
	for _, perk in ipairs(perks) do
		if perk.id == id then
			return perk
		end
	end
end

function p.getPerkDescription(id)
	id = ResolveIntParam(id)
	
	for _, perkDesc in ipairs(perkDescription) do
		if perkDesc.id == id then
			mw.log(subValues(perkDesc))
			return subValues(perkDesc)
		end
	end
end

function p.getPerkTeachableDescription(id)
	id = ResolveIntParam(id)
	
	for _, perkDesc in ipairs(perkDescription) do
		if perkDesc.id == id then
			mw.log(perkDesc.teachDesc[1])
			return perkDesc.teachDesc[1]
		end
	end
end

function p.getPerkDescriptionByName(name)
	name = ResolveStringParam(name)

	for _, perk in ipairs(perks) do
		if perk.name == name then
			return p.getPerkDescription(perk.id)
		end
	end
end

function p.getPerkOwnerByPerk(perk)
	if perk.character == nil then return "Perk is not unique to any character, thus no name provided" end
	if perk.charType == 'S' then
		return utils.getCharacterById(perk.character, survivors)
	elseif perk.charType == 'K' then
		return utils.getCharacterById(perk.character, killers)
	else
		return "Unknown Character"
	end
end

function p.getPerksOwnerNameByPerk(perk) --Name
	return p.getPerkOwnerByPerk(perk).name
end

function p.getPortraitOfPerkOwnerByPerk(perk)
	return perk.charType .. string.format("%02d", p.getPerkOwnerByPerk(perk).id) .. '_charSelect_portrait.png'
end

return p