Module:CalculatedStats: Difference between revisions

Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 90: Line 90:
local agility = args[7] --Agility
local agility = args[7] --Agility
local luck = args[8] --Luck
local luck = args[8] --Luck
local platform = ""
if args[9] then
if args[9] then
local platform = string.lower(args[9]) --game platform
platform = string.lower(args[9]) --game platform
else
local platform = ""
end
end
local statTable = {
local statTable = {

Revision as of 00:34, 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
	--Make PSP Devil Summoner functional; probably add additional argument for platform for this and MCD 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

function p.smt1(frame)
	local args = getArgs(frame)
	local stat = string.lower(args[1])
	local level = args[2] --Level
	local strength = args[3] --Strength
	local intelligence = args[4] --Intelligence
	local magic = args[5] --Magic
	local vitality = args[6] --Vitality
	local agility = args[7] --Agility
	local luck = args[8] --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 statTable[stat]
end

function p.smt2(frame)
	local args = getArgs(frame)
	local stat = string.lower(args[1])
	local level = args[2] --Level
	local strength = args[3] --Strength
	local intelligence = args[4] --Intelligence
	local magic = args[5] --Magic
	local vitality = args[6] --Vitality
	local agility = args[7] --Agility
	local luck = args[8] --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 statTable[stat]
end

function p.smtif(frame)
	local args = getArgs(frame)
	local stat = string.lower(args[1])
	local level = args[2] --Level
	local strength = args[3] --Strength
	local intelligence = args[4] --Intelligence
	local magic = args[5] --Magic
	local vitality = args[6] --Vitality
	local agility = args[7] --Agility
	local luck = args[8] --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 statTable[stat]
end

function p.desum(frame)
	local args = getArgs(frame)
	local stat = string.lower(args[1])
	local level = args[2] --Level
	local strength = args[3] --Strength
	local intelligence = args[4] --Intelligence
	local magic = args[5] --Magic
	local endurance = args[6] --Endurance
	local agility = args[7] --Agility
	local luck = args[8] --Luck
	local platform = ""
	if args[9] then
		platform = string.lower(args[9]) --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),
		atkpsp = (level + strength) * 2,
		accpsp = math.floor((level * 1.5) + agility + (strength + luck)/4),
		defpsp = (level + endurance) * 2,
		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))
	}
	if platform == "sat" then
		return statTable[stat]
	elseif platform == "psp" then
		return statTable[stat..platform]
	else
		if statTable[stat] == statTable[stat.."psp"] then
			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

return p