Module:CalculatedStats: Difference between revisions

Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 10: Line 10:
local function round(number)
local function round(number)
return math.floor(number + 0.5)
return math.floor(number + 0.5)
end
local function outputCells(stat1,stat2,stat3,stat4,stat5,stat6)
return string.format("| %s\n| %s\n| %s\n| %s\n| %s\n| %s",stat1,stat2,stat3,stat4,stat5,stat6)
end
end


function p.smt1(frame)
function p.smt1(frame)
local args = getArgs(frame)
local args = getArgs(frame)
local stat = string.lower(args[1])
local level = args[1] --Level
local level = args[2] --Level
local strength = args[2] --Strength
local strength = args[3] --Strength
local intelligence = args[3] --Intelligence
local intelligence = args[4] --Intelligence
local magic = args[4] --Magic
local magic = args[5] --Magic
local vitality = args[5] --Vitality
local vitality = args[6] --Vitality
local agility = args[6] --Agility
local agility = args[7] --Agility
local luck = args[7] --Luck
local luck = args[8] --Luck
local levelMinus19 = level - 19
local levelMinus19 = level - 19
if levelMinus19 < 0 then
if levelMinus19 < 0 then
Line 34: Line 37:
mefc = intelligence + round(magic/8)
mefc = intelligence + round(magic/8)
}
}
return statTable[stat]
return outputCells(statTable[atk],statTable[acc],statTable[def],statTable[eva],statTable[matk],statTable[mefc])
end
end


function p.smt2(frame)
function p.smt2(frame)
local args = getArgs(frame)
local args = getArgs(frame)
local stat = string.lower(args[1])
local level = args[1] --Level
local level = args[2] --Level
local strength = args[2] --Strength
local strength = args[3] --Strength
local intelligence = args[3] --Intelligence
local intelligence = args[4] --Intelligence
local magic = args[4] --Magic
local magic = args[5] --Magic
local vitality = args[5] --Vitality
local vitality = args[6] --Vitality
local agility = args[6] --Agility
local agility = args[7] --Agility
local luck = args[7] --Luck
local luck = args[8] --Luck
local statTable = {
local statTable = {
atk = (level + strength) * 2,
atk = (level + strength) * 2,
Line 55: Line 57:
mefc = intelligence + math.floor(magic/4)
mefc = intelligence + math.floor(magic/4)
}
}
return statTable[stat]
return outputCells(statTable[atk],statTable[acc],statTable[def],statTable[eva],statTable[matk],statTable[mefc])
end
end


Line 64: Line 66:
function p.desum(frame)
function p.desum(frame)
local args = getArgs(frame)
local args = getArgs(frame)
local stat = string.lower(args[1])
local level = args[1] --Level
local level = args[2] --Level
local strength = args[2] --Strength
local strength = args[3] --Strength
local intelligence = args[3] --Intelligence
local intelligence = args[4] --Intelligence
local magic = args[4] --Magic
local magic = args[5] --Magic
local vitality = args[5] --Vitality
local endurance = args[6] --Endurance
local agility = args[6] --Agility
local agility = args[7] --Agility
local luck = args[7] --Luck
local luck = args[8] --Luck
local platform = ""
local platform = ""
if args[9] then
if args[8] then
platform = string.lower(args[9]) --game platform
platform = string.lower(args[8]) --game platform
end
end
local statTable = {
local statTable = {
Line 83: Line 84:
matk = math.floor(intelligence/2) + (magic*2),
matk = math.floor(intelligence/2) + (magic*2),
mdef = intelligence + math.floor(level/2) + math.floor(magic/4) + math.floor(endurance/2),
mdef = intelligence + math.floor(level/2) + math.floor(magic/4) + math.floor(endurance/2),
atkpsp = (level + strength) * 2,
accpsp = math.floor((level * 1.5) + agility + (strength + luck)/4),
accpsp = math.floor((level * 1.5) + agility + (strength + luck)/4),
defpsp = (level + endurance) * 2,
evapsp = math.floor((level * 1.5) + agility + (intelligence + luck)/4),
evapsp = math.floor((level * 1.5) + agility + (intelligence + luck)/4),
matkpsp = math.floor((intelligence/2) + (magic*2)),
matkpsp = math.floor((intelligence/2) + (magic*2)),
mdefpsp = math.floor(intelligence + (level/2) + (magic/4) + (endurance/2))
mdefpsp = math.floor(intelligence + (level/2) + (magic/4) + (endurance/2))
}
}
if platform == "sat" then
local function bothPlatsValue(stat)
return statTable[stat]
if platform == "psp" and (statTable[stat] ~= statTable[stat.."psp"]) then
elseif platform == "psp" then
return frame:expandTemplate{ title = "tt", args = { statTable[stat], "Sega Saturn" } } .. "/" .. frame:expandTemplate{ title = "tt", args = { statTable[stat.."psp"], "PlayStation Portable" } }
return statTable[stat..platform]
else
else
if statTable[stat] == statTable[stat.."psp"] then
return statTable[stat]
return statTable[stat]
else
return frame:expandTemplate{ title = "tt", args = { statTable[stat], "Sega Saturn" } } .. "/" .. frame:expandTemplate{ title = "tt", args = { statTable[stat.."psp"], "PlayStation Portable" } }
end
end
end
end
local outputAtk = statTable[atk]
local outputAcc = bothPlatsValue("acc")
local outputDef = statTable[def]
local outputEva = bothPlatsValue("eva")
local outputMatk = bothPlatsValue("matk")
local outputMdef = bothPlatsValue("mdef")
return outputCells(outputAtk,outputAcc,outputDef,outputEva,outputMatk,outputMdef)
end
end


return p
return p

Revision as of 01:12, 20 September 2024

Documentation

Basic use

To use this module, do as follows for most games:

{{#invoke:CalculatedStats|<function>|<level>|<strength>|<intelligence>|<magic>|<vitality/endurance>|<agility>|<luck>}}

For Persona 2: Innocent Sin, do as follows for basic use:

{{#invoke:CalculatedStats|<function>|<level>|<strength>|<vitality>|<dexterity>|<agility>|<luck>}}

This module should not be invoked directly in the mainspace and should be part of a template, with the values filled with template parameters.

Valid values for function (case sensitive):

  • smt1 for Shin Megami Tensei
  • smt2 for Shin Megami Tensei II
  • smtif for Shin Megami Tensei if... (alias for smt2)
  • smtn for Shin Megami Tensei: Nine
  • desum for Shin Megami Tensei: Devil Summoner
  • sh1 for Devil Summoner: Soul Hackers
  • p2is for Persona 2: Innocent Sin

Platform

Shin Megami Tensei has different formulas for the Mega-CD version. Set the named parameter platform to MCD (case insensitive) to output the Mega-CD stats.

Shin Megami Tensei: Devil Summoner by default shows both the Sega Saturn and PlayStation Portable values for Magic Defense. Set the named parameter platform to either SAT or PSP (case insensitive) to display only one of them.

Persona 2: Innocent Sin is similar to Devil Summoner but it applies for all stats. Set the named parameter platform to PS or PSP to show only one platform's set of stats.

Boss

Shin Megami Tensei (Mega-CD) uses different stat calculations for bosses than it does for regular demons. Set the named parameter boss to something (recommended: y) to use the boss calculations.

Manual stat inputting

Devil Summoner: Soul Hackers and Shin Megami Tensei: Nine support manual input of stats through named arguments (see the code to know what to use). This is because some of the calculations for Devil Summoner: Soul Hackers and Shin Megami Tensei: Nine are not yet perfect.

Sources

All sources were verified and, if they were wrong, corrected formulas are used in this module.


--For calculated stats in SMT1, SMT2, SMTif, SMT Devil Summoner
--To do:
	--Mega-CD SMT1
	--Find out Soul Hackers formulas
	--Add MT1, MT2, KMT support

local getArgs = require('Module:Arguments').getArgs
local p = {}

local function round(number)
	return math.floor(number + 0.5)
end

local function outputCells(stat1,stat2,stat3,stat4,stat5,stat6)
	return string.format("| %s\n| %s\n| %s\n| %s\n| %s\n| %s",stat1,stat2,stat3,stat4,stat5,stat6)
end

function p.smt1(frame)
	local args = getArgs(frame)
	local level = args[1] --Level
	local strength = args[2] --Strength
	local intelligence = args[3] --Intelligence
	local magic = args[4] --Magic
	local vitality = args[5] --Vitality
	local agility = args[6] --Agility
	local luck = args[7] --Luck
	local levelMinus19 = level - 19
	if levelMinus19 < 0 then
		levelMinus19 = 0
	end
	local statTable = {
		atk = levelMinus19 + (strength * 3) + round(vitality/4),
		acc = round(strength/4) + agility,
		def = round(levelMinus19/2) + round(strength/4) + (vitality * 2),
		eva = round(intelligence/8) + agility,
		matk = round(intelligence/8) + magic,
		mefc = intelligence + round(magic/8)
	}
	return outputCells(statTable[atk],statTable[acc],statTable[def],statTable[eva],statTable[matk],statTable[mefc])
end

function p.smt2(frame)
	local args = getArgs(frame)
	local level = args[1] --Level
	local strength = args[2] --Strength
	local intelligence = args[3] --Intelligence
	local magic = args[4] --Magic
	local vitality = args[5] --Vitality
	local agility = args[6] --Agility
	local luck = args[7] --Luck
	local statTable = {
		atk = (level + strength) * 2,
		acc = math.floor(level * 1.5) + agility + math.floor((strength + luck)/4),
		def = (level + vitality) * 2,
		eva = math.floor(level * 1.5) + agility + math.floor((intelligence + luck)/4),
		matk = math.floor(intelligence/4) + magic,
		mefc = intelligence + math.floor(magic/4)
	}
	return outputCells(statTable[atk],statTable[acc],statTable[def],statTable[eva],statTable[matk],statTable[mefc])
end

function p.smtif(frame)
	return p.smt2(frame)
end

function p.desum(frame)
	local args = getArgs(frame)
	local level = args[1] --Level
	local strength = args[2] --Strength
	local intelligence = args[3] --Intelligence
	local magic = args[4] --Magic
	local vitality = args[5] --Vitality
	local agility = args[6] --Agility
	local luck = args[7] --Luck
	local platform = ""
	if args[8] then
		platform = string.lower(args[8]) --game platform
	end
	local statTable = {
		atk = (level + strength) * 2,
		acc = math.floor(level * 1.5) + agility + math.floor((strength + luck)/4),
		def = (level + endurance) * 2,
		eva = math.floor(level * 1.5) + agility + math.floor((intelligence + luck)/4),
		matk = math.floor(intelligence/2) + (magic*2),
		mdef = intelligence + math.floor(level/2) + math.floor(magic/4) + math.floor(endurance/2),
		accpsp = math.floor((level * 1.5) + agility + (strength + luck)/4),
		evapsp = math.floor((level * 1.5) + agility + (intelligence + luck)/4),
		matkpsp = math.floor((intelligence/2) + (magic*2)),
		mdefpsp = math.floor(intelligence + (level/2) + (magic/4) + (endurance/2))
	}
	local function bothPlatsValue(stat)
		if platform == "psp" and (statTable[stat] ~= statTable[stat.."psp"]) then
			return frame:expandTemplate{ title = "tt", args = { statTable[stat], "Sega Saturn" } } .. "/" .. frame:expandTemplate{ title = "tt", args = { statTable[stat.."psp"], "PlayStation Portable" } }
		else
			return statTable[stat]
		end
	end
	local outputAtk = statTable[atk]
	local outputAcc = bothPlatsValue("acc")
	local outputDef = statTable[def]
	local outputEva = bothPlatsValue("eva")
	local outputMatk = bothPlatsValue("matk")
	local outputMdef = bothPlatsValue("mdef")

	return outputCells(outputAtk,outputAcc,outputDef,outputEva,outputMatk,outputMdef)
end

return p