Dead by Daylight Wiki
mNo edit summary
(Undo revision 95742 by RedStar76 (talk))
Tag: Undo
(16 intermediate revisions by 2 users not shown)
Line 78: Line 78:
 
if perk.id == id then
 
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
 
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) .. "''' "
+
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
+
.. getUnitById(perk.units[tripplet]) .. "'''" --Units, Tripplet is an index in 'units' list
 
end
 
end
 
end
 
end
return "'''" .. strings.perkValuesNotFound .. "''"
+
return "'''" .. strings.perkValuesNotFound .. "'''"
 
end
 
end
   
Line 96: Line 96:
 
--mw.log("PL: " .. pl)
 
--mw.log("PL: " .. pl)
 
return result
 
return result
  +
end
  +
  +
function p.GetPerkById(id)
  +
for _, perk in ipairs(perks) do
  +
if perk.id == id then
  +
return perk
  +
end
  +
end
 
end
 
end
   
Line 122: Line 130:
 
function p.getPerkDescriptionByName(name)
 
function p.getPerkDescriptionByName(name)
 
name = ResolveStringParam(name)
 
name = ResolveStringParam(name)
  +
 
 
for _, perk in ipairs(perks) do
 
for _, perk in ipairs(perks) do
 
if perk.name == name then
 
if perk.name == name then
Line 133: Line 141:
 
if perk.character == nil then return "Perk is not unique to any character, thus no name provided" end
 
if perk.character == nil then return "Perk is not unique to any character, thus no name provided" end
 
if perk.charType == 'S' then
 
if perk.charType == 'S' then
return utils.getCharacterById(perk.id, survivors)
+
return utils.getCharacterById(perk.character, survivors)
 
elseif perk.charType == 'K' then
 
elseif perk.charType == 'K' then
return utils.getCharacterById(perk.id, killers)
+
return utils.getCharacterById(perk.character, killers)
 
else
 
else
 
return "Unknown Character"
 
return "Unknown Character"

Revision as of 16:30, 31 December 2020


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

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