Dead by Daylight Wiki
Nie podano opisu zmian
Nie podano opisu zmian
(Nie pokazano 2 pośrednich wersji utworzonych przez tego samego użytkownika)
Linia 9: Linia 9:
 
perkValuesNotFound = "The Values for the perk wasn't found",
 
perkValuesNotFound = "The Values for the perk wasn't found",
 
unitNotFound = "The Unit value wasn't found",
 
unitNotFound = "The Unit value wasn't found",
notUniquePerk = "Perk is not unique to any character, thus no name provided"
+
notUniquePerk = "Perk is not unique to any character, thus no name provided",
  +
several = "several"
 
}
 
}
   
Linia 94: Linia 95:
   
 
--Function that actually returns string that will replace the placeholder
 
--Function that actually returns string that will replace the placeholder
function pl(id, tripplet)
+
function pl(id, tripplet, mode)
 
tripplet = tonumber(tripplet)
 
tripplet = tonumber(tripplet)
 
for _,perk in ipairs(perks) do
 
for _,perk in ipairs(perks) do
 
if perk.id == id then
 
if perk.id == id then
  +
if (mode and mode == "teachable") 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], 2) .. "'''/'''" .. utils.clr(perk.values[index + 1], 3) .. "'''/'''" .. utils.clr(perk.values[index + 2], 4) .. " " ..
+
return utils.clr(b(strings.several .. space .. getUnitById(perk.units[tripplet])), 13)
  +
else
--I remove the dynamic base level as long as the perks are not diversed anymore and all perks are uncommon/rare/very rare value
 
 
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], 2) .. "'''/'''" .. utils.clr(perk.values[index + 1], 3) .. "'''/'''" .. utils.clr(perk.values[index + 2], 4) .. " " ..
getUnitById(perk.units[tripplet]) .. "'''" --Units, Tripplet is an index in 'units' list
 
 
--I remove the dynamic base level as long as the perks are not diversed anymore and all perks are uncommon/rare/very rare value
 
--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
 
end
 
end
 
end
Linia 109: Linia 114:
   
 
--Function replaces "#pl(x)" string with tripplet value of according number in brackets
 
--Function replaces "#pl(x)" string with tripplet value of according number in brackets
function subValues(perkDesc)
+
function subValues(perkDesc, mode)
 
local regexString = "#pl%((%d)%)" -- looking and extracting number from "#pl(x)"
 
local regexString = "#pl%((%d)%)" -- looking and extracting number from "#pl(x)"
  +
if perkDesc.desc[1][1] ~= nil then
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)
+
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)
local currentRegexString = "#pl%(" .. tonumber(m) .. "%)" --you need to replace ONLY CURRENT INDEX, otherwise you'll get replaced all #pl(x) at once when going through the first time (i.e. the first tripplet will replace all #pl() in text
+
local currentRegexString = "#pl%(" .. tonumber(m) .. "%)" --you need to replace ONLY CURRENT INDEX, otherwise you'll get replaced all #pl(x) at once when going through the first time (i.e. the first tripplet will replace all #pl() in text
perkDesc.desc[1][1] = perkDesc.desc[1][1]:gsub(currentRegexString, pl(perkDesc.id, tonumber(m)))
 
--mw.log(perkDesc.desc[1][1])
+
perkDesc.desc[1][1] = perkDesc.desc[1][1]:gsub(currentRegexString, pl(perkDesc.id, tonumber(m), mode))
  +
--mw.log(perkDesc.desc[1][1])
  +
end
 
end
 
end
 
--mw.log("PL: " .. pl)
 
--mw.log("PL: " .. pl)
Linia 122: Linia 129:
 
function subNames(perkDesc)
 
function subNames(perkDesc)
 
local regexString = "#pn"
 
local regexString = "#pn"
  +
if perkDesc.desc[1][1] ~= nil then
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)
+
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)
perkDesc.desc[1][1] = perkDesc.desc[1][1]:gsub(regexString, "''".. p.GetPerkById(perkDesc.id).name .. "''")
 
 
perkDesc.desc[1][1] = perkDesc.desc[1][1]:gsub(regexString, "''".. p.GetPerkById(perkDesc.id).name .. "''")
  +
end
 
end
 
end
 
return perkDesc
 
return perkDesc
Linia 136: Linia 145:
 
end
 
end
   
function p.getPerkDescription(id)
+
function p.getPerkByName(name)
  +
name = utils.resolveParameter(args)
  +
for _, perk in ipairs(perks) do
  +
if perk.name == name then
  +
return perk
  +
end
  +
end
  +
end
  +
 
function p.getPerkDescription(id, mode)
 
id = ResolveIntParam(id)
 
id = ResolveIntParam(id)
mw.log(_historyText)
 
 
for _, perkDesc in ipairs(perkDescription) do
 
for _, perkDesc in ipairs(perkDescription) do
 
if perkDesc.id == id then
 
if perkDesc.id == id then
perkDesc = subValues(perkDesc) --pl(#) => Perk # trio Values
+
perkDesc = subValues(perkDesc, mode) --pl(#) => Perk # trio Values
 
perkDesc = subNames(perkDesc) -- #pn => Perk Name
 
perkDesc = subNames(perkDesc) -- #pn => Perk Name
 
 
Linia 149: Linia 166:
 
end
 
end
 
return ""
 
return ""
end
 
 
function p.getPerkHistoryDescription(id)
 
mw.log(_historyText)
 
_historyText = true
 
mw.log(_historyText)
 
return p.getPerkDescription(id)
 
 
end
 
end
   
Linia 234: Linia 244:
 
result = result .. hl .. '[[' .. cstr.file .. utils.getIcon(perk.name) .. '| ' .. perk.name .. ' | 100px]]' .. nl ..
 
result = result .. hl .. '[[' .. cstr.file .. utils.getIcon(perk.name) .. '| ' .. perk.name .. ' | 100px]]' .. nl ..
 
hl .. '[[' .. perk.name .. ']]' .. nl ..
 
hl .. '[[' .. perk.name .. ']]' .. nl ..
'| ' .. p.getPerkDescription(perk.id) .. nl
+
'| ' .. (p.getPerkDescription(perk.id) or '') .. nl
 
 
 
return result
 
return result
Linia 276: Linia 286:
 
mw.log(result)
 
mw.log(result)
 
return result
 
return result
  +
end
  +
  +
function p.getPerkIconFilename(args)
  +
local name = utils.resolveParameter(args)
  +
local ext = utils.resolveParameter(args, 2, true)
  +
  +
return utils.resolveFileName(name) .. ((ext and '.' .. ext) or '')
  +
end
  +
  +
function p.getTeachablePerkIconFilename(args)
  +
return "Teachable_" .. utils.FirstLetterLower(p.getPerkIconFilename(args))
  +
end
  +
  +
function p.getTeachableDescriptionById(id)
  +
return p.getPerkDescription(id, "teachable")
 
end
 
end
   

Wersja z 09:30, 9 paź 2021


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

local strings = {
	perkValuesNotFound = "The Values for the perk wasn't found",
	unitNotFound = "The Unit value wasn't found",
	notUniquePerk = "Perk is not unique to any character, thus no name provided",
	several = "several"
}

function getMaxPerkId()
	result = 0
	for _, perk in ipairs(perks) do
		if result < perk.id then result = perk.id end
	end
	return result
end

function p.getNextFreePerkId()
	return getMaxPerkId() + 1
end

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, mode)
	tripplet = tonumber(tripplet)
	for _,perk in ipairs(perks) do
		if perk.id == id then
			if (mode and mode == "teachable") then
				return utils.clr(b(strings.several .. space .. getUnitById(perk.units[tripplet])), 13)
			else
				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], 2) .. "'''/'''" .. utils.clr(perk.values[index + 1], 3) .. "'''/'''" .. utils.clr(perk.values[index + 2], 4) .. " " ..
				--I remove the dynamic base level as long as the perks are not diversed anymore and all perks are uncommon/rare/very rare value
				--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
	end
	return "'''" .. strings.perkValuesNotFound .. "'''"
end

--Function replaces "#pl(x)" string with tripplet value of according number in brackets
function subValues(perkDesc, mode)
	local regexString = "#pl%((%d)%)" -- looking and extracting number from "#pl(x)"
	if perkDesc.desc[1][1] ~= nil then
		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)
			local currentRegexString = "#pl%(" .. tonumber(m) .. "%)" --you need to replace ONLY CURRENT INDEX, otherwise you'll get replaced all #pl(x) at once when going through the first time (i.e. the first tripplet will replace all #pl() in text
			perkDesc.desc[1][1] = perkDesc.desc[1][1]:gsub(currentRegexString, pl(perkDesc.id, tonumber(m), mode))
			--mw.log(perkDesc.desc[1][1])
		end
	end
	--mw.log("PL: " .. pl)
	return perkDesc
end

function subNames(perkDesc)
	local regexString = "#pn"
	if perkDesc.desc[1][1] ~= nil then
		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)
			perkDesc.desc[1][1] = perkDesc.desc[1][1]:gsub(regexString, "''".. p.GetPerkById(perkDesc.id).name .. "''")
		end
	end
	return perkDesc
end

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

function p.getPerkByName(name)
	name = utils.resolveParameter(args)
	for _, perk in ipairs(perks) do
		if perk.name == name then
			return perk
		end
	end
end

function p.getPerkDescription(id, mode)
	id = ResolveIntParam(id)
	for _, perkDesc in ipairs(perkDescription) do
		if perkDesc.id == id then
			perkDesc = subValues(perkDesc, mode) --pl(#) => Perk # trio Values
			perkDesc = subNames(perkDesc) -- #pn => Perk Name
			
			mw.log(perkDesc.desc[1][1])
			return perkDesc.desc[1][1]
		end
	end
	return ""
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 notUniquePerk 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

--cat = category
--solution = defines which way the category should be processed
--charType = 'K' - Only Killers, 'S' - Only survivors, skipped - Both
function p.resolvePerkCategory(cat, solution, charType)
	category = utils.resolveParameter(cat)
	solution = solution or utils.resolveParameter(cat, 2)
	charType = charType or utils.resolveParameter(cat, 3, true)

	if		solution == "table"		then return getPerksTableByCategory(category, charType)
	--elseif	solution == "secondApproach"	then return functionReturningCategorisedPerks(cat, charType)
	else return solution
	end
end

function getPerksTableByCategory(cat, charType)
	local result = ''
	local perkList = getPerksByCategory(cat, charType)

	for _, perk in ipairs(perkList) do
		result = result .. getTableRowPerk(perk)
		if perk.id ~= perkList[#perkList].id then
			result = result .. ntl .. nl
		end
	end
	
	result = utils.wrapBasicTable(result)
	
	mw.log(result)
	return result
end

function getTableRowPerk(perk)
	result = ''
	
	result = result .. hl .. '[[' .. cstr.file .. utils.getIcon(perk.name) .. '| ' .. perk.name .. ' | 100px]]' .. nl ..
	hl .. '[[' .. perk.name .. ']]' .. nl ..
	'| ' .. (p.getPerkDescription(perk.id) or '') .. nl
	
	return result
end

function getPerksByCategory(cat, charType)
	local result = {}
	
	for _, perk in ipairs(perks) do
		if perk.tags ~= nil then
			for _, category in ipairs(perk.tags) do
				if category == cat and (charType == nil or perk.charType == charType) then
					result[#result + 1] = perk
					break
				end
			end
		end
	end

	return result
end

function p.getPerkDescriptions(params, last) --temporary function, not used anywhere permanently
	first = tonumber(utils.resolveParameter(params))
	last = tonumber(last or utils.resolveParameter(params, 2))
	local result = ''
	
	utils.sortTableById(perks)
	for _, perk in ipairs(perks) do
		if perk.id >= first and perk.id <= last then
			result = result .. hl .. perk.id .. nl .. 
			hl .. perk.name .. nl ..
			'| ' .. p.getPerkDescription(perk.id) .. nl
			if perk.id ~= last then
				result = result .. ntl .. nl
			end
		end
	end
	
	result = utils.wrapBasicTable(result)
	mw.log(result)
	return result
end

function p.getPerkIconFilename(args)
	local name = utils.resolveParameter(args)
	local ext = utils.resolveParameter(args, 2, true)

	return utils.resolveFileName(name) .. ((ext and  '.' .. ext) or '')
end

function p.getTeachablePerkIconFilename(args)
	return "Teachable_" ..	utils.FirstLetterLower(p.getPerkIconFilename(args))
end

function p.getTeachableDescriptionById(id)
	return p.getPerkDescription(id, "teachable")
end

return p