Module:GeneralFunctions

local p = {} function p.getAttributeModifier(frame) local attribute_value = frame.args[1] local modfiers = { ["0"] = -5, ["1"] = -5, ["2"] = -4, ["3"] = -4, ["4"] = -3, ["5"] = -3,	   ["6"] = -2, ["7"] = -2, ["8"] = -1, ["9"] = -1, ["10"] = 0, ["11"] = 0,		["12"] = 1, ["13"] = 1,	["14"] = 2,	["15"] = 2,	["16"] = 3,	["17"] = 3,		["18"] = 4,	["19"] = 4,	["20"] = 5,	["21"] = 5,	["22"] = 6,	["23"] = 6,		["24"] = 7,	["25"] = 7,	["26"] = 8,	["27"] = 8,	["28"] = 9,	["29"] = 9,		["30"] = 10,	};    return modfiers[attribute_value] or attribute_value or "" end

function p.calculateSpeed(frame) local speed = 30; if(string.find(frame.args["race"], "dwarf")    	or string.find(frame.args["race"], "gnome")     	or string.find(frame.args["race"], "halfling")	) then speed = 25; end if(frame.args["race"] == "wood elf") then speed = 35; end local monk_speed = { ["1"] = 0, ["2"] = 10, ["3"] = 10, ["4"] = 10, ["5"] = 10, 	   ["6"] = 15, ["7"] = 15, ["8"] = 15, ["9"] = 15, ["10"] = 20, 	    ["11"] = 20, ["12"] = 20, ["13"] = 20, ["14"] = 25,	["15"] = 25,		["16"] = 25, ["17"] = 25, ["18"] = 30, ["19"] = 30,	["20"] = 30,	};

if(frame.args["class"] == "monk") then speed = speed + monk_speed[frame.args["class_lvl"]]; end if(frame.args["second_class"] == "monk") then speed = speed + monk_speed[frame.args["second_class_lvl"]]; end if(frame.args["speed_mod"]) then speed = speed + frame.args["speed_mod"] end return speed end

function p.calculateProficiencyBonus(frame) local proficiency_bonus = { ["1"] = 2, ["2"] = 2, ["3"] = 2, ["4"] = 2, ["5"] = 3, 	   ["6"] = 3, ["7"] = 3, ["8"] = 3, ["9"] = 4, ["10"] = 4, 	    ["11"] = 4, ["12"] = 4, ["13"] = 5, ["14"] = 5,	["15"] = 5,		["16"] = 5, ["17"] = 6, ["18"] = 6, ["19"] = 6,	["20"] = 6,	};

return proficiency_bonus[frame.args["lvl"]] or 2 end

function p.getSaves(frame) local class = frame.args["class"]; local saves = {["artificer"] = "con, int", ["barbarian"] = "str, con", ["bard"] = "dex, cha", ["cleric"] = "wis, cha", ["druid"] = "int, wis", ["fighter"] = "str, con", ["monk"] = "str, dex", ["paladin"] = "wis, cha", ["ranger"] = "str, dex", ["rogue"] = "dex, int", ["sorcerer"] = "con, cha", ["warlock"] = "wis, cha", ["wizard"] = "int, wis" };   local class_saves = saves[class]; if(class == "rogue" and tonumber(frame.args["lvl"]) >= 15) then class_saves = class_saves .. ", wis"; end return class_saves; end function p.calculateArmorProficiency(frame) local type = frame.args["type"]; local race = frame.args["race"]; local class = frame.args["class"]; local sub_class = frame.args["sub_class"]; local second_class = frame.args["second_class"]; local sub_second_class = frame.args["sub_second_class"]; local is_proficient = null; if(type == "light") then --Most have light armor proficiency, so we test for negatives if(not (class == "monk" or class =="sorcerer" or class =="wizard")) then is_proficient = true; end if(not is_proficient and not(second_class == "0" or second_class == "") and			not(second_class == "monk" or second_class =="sorcerer" or second_class =="wizard" or second_class =="barbarian" )		) then is_proficient = true; end if(race == "mountain dwarf") then is_proficient = true; end

return is_proficient; end if(type == "medium") then if(class == "artificer" 			or class == "barbarian" 			or class == "cleric"			or class == "druid"			or class == "fighter"			or class == "paladin"			or class == "ranger"		) then is_proficient = true; end if(not is_proficient and 			(second_class == "artificer" or second_class == "cleric" or second_class == "druid" or second_class == "fighter" or second_class == "paladin" or second_class == "ranger" )		) then is_proficient = true; end if(race == "mountain dwarf" 			or sub_class == "hexblade" 			or sub_second_class == "hexblade"		) then is_proficient = true; end return is_proficient; end if(type == "heavy") then if(class == "fighter"			or class == "paladin"			or sub_class == "life"			or sub_class == "war"			or sub_class == "nature"			or sub_class == "tempest"			or sub_second_class == "life"			or sub_second_class == "war"			or sub_second_class == "nature"			or sub_second_class == "tempest"		) then is_proficient = true; end return is_proficient; end if(type == "shield") then if(class == "artificer" 			or class == "barbarian" 			or class == "cleric"			or class == "druid"			or class == "fighter"			or class == "paladin"			or class == "ranger"		) then is_proficient = true; end if(not is_proficient and 			(second_class == "artificer" or second_class == "barbarian" or second_class == "cleric" or second_class == "druid" or second_class == "fighter" or second_class == "paladin" or second_class == "ranger" )		) then is_proficient = true; end if(sub_class == "hexblade" or sub_second_class == "hexblade") then is_proficient = true; end return is_proficient; end

return is_proficient end

function p.calculateWeaponProficiency(frame) local type = frame.args["type"]; local race = frame.args["race"]; local class = frame.args["class"]; local sub_class = frame.args["sub_class"]; local second_class = frame.args["second_class"]; local sub_second_class = frame.args["sub_second_class"]; local is_proficient = null; if(type == "simple") then --Most have simple weapon proficiency, so we test for negatives if(not (class == "druid" or class =="sorcerer" or class =="wizard")) then is_proficient = true; end if(not is_proficient and 			(second_class == "barbarian" or second_class =="fighter" or second_class =="monk" or second_class =="paladin" or second_class =="ranger" or second_class =="warlock" )		) then is_proficient = true; end end if(type == "martial") then if(class == "barbarian" 			or class == "fighter"			or class == "paladin"			or class == "ranger"			or sub_class == "war"			or sub_class == "tempest"		) then is_proficient = true; end if(not is_proficient and 			(second_class == "barbarian" or second_class == "fighter" or second_class == "paladin" or second_class == "ranger" or sub_second_class == "war" or sub_second_class == "tempest" )		) then is_proficient = true; end if(sub_class == "hexblade" or sub_second_class == "hexblade") then is_proficient = true; end end

return is_proficient; end

function p.calculatePartialWeaponProficiencies(frame) local type = frame.args["type"]; local race = frame.args["race"]; local class = frame.args["class"]; local second_class = frame.args["second_class"]; local proficiencies = {}; if(type == "simple") then if(class == "druid") then proficiencies = {"clubs", "daggers", "darts", "javelins", "maces", "quarterstaffs", "sickles", "slings", "spears" }		elseif(class == "sorcerer" or class == "wizard") then proficiencies = {"daggers", "darts", "quarterstaffs", "light crossbows", "slings" }		end if(string.find(race, "dwarf")) then table.insert(proficiencies, "handaxe"); table.insert(proficiencies, "light hammer"); table.insert(proficiencies, "warhammer"); end end if(type == "martial") then if(class == "bard" or class == "rogue") then proficiencies = {"hand crossbows, longswords, rapiers, shortswords"}; elseif(class == "druid") then table.insert(proficiencies, "scimitars"); elseif(class == "monk" or second_class == "monk") then table.insert(proficiencies, "shortswords"); end if(string.find(race, "dwarf")) then table.insert(proficiencies, "battleaxe"); elseif(race == "dark elf") then table.insert(proficiencies, "rapiers"); table.insert(proficiencies, "shortswords"); table.insert(proficiencies, "hand crossbows"); elseif(race == "high elf" or race == "wood elf") then table.insert(proficiencies, "longsword"); table.insert(proficiencies, "shortswords"); table.insert(proficiencies, "shortbows"); table.insert(proficiencies, "longbows"); end end

return table.concat(proficiencies, ","); end

function p.calculateHP(frame) local race = frame.args["race"]; local first_class = frame.args["class"]; local class_lvl = tonumber(frame.args["class_lvl"]); local second_class = frame.args["second_class"]; local second_class_lvl = 0; if(second_class) then second_class_lvl = tonumber(frame.args["second_class_lvl"]); end local lvl = class_lvl if(second_class_lvl) then lvl = lvl + second_class_lvl; end local con_mod = tonumber(frame.args["con_mod"]); local hit_dice = { ["sorcerer"] = {hd=6,hd_lvl=4}, ["wizard"] = {hd=6,hd_lvl=4}, ["artificer"] = {hd=8,hd_lvl=5}, ["bard"] = {hd=8,hd_lvl=5}, ["cleric"] = {hd=8,hd_lvl=5}, ["druid"] = {hd=8,hd_lvl=5}, ["monk"] = {hd=8,hd_lvl=5}, ["wizard"] = {hd=8,hd_lvl=5}, ["rogue"] = {hd=8,hd_lvl=5}, ["warlock"] = {hd=8,hd_lvl=5}, ["fighter"] = {hd=10,hd_lvl=6}, ["paladin"] = {hd=10,hd_lvl=6}, ["ranger"] = {hd=10,hd_lvl=6}, ["barbarian"] = {hd=12,hd_lvl=7}, }	local hp = hit_dice[first_class].hd + hit_dice[first_class].hd_lvl * (class_lvl - 1); if(second_class_lvl) then hp = hp + hit_dice[second_class].hd_lvl * second_class_lvl; end hp = hp + con_mod * lvl; if(race == "hill dwarf") then hp = hp + lvl; end

return hp or 0 end return p