From c689f37afc40ac4b2c9e495f081387c2ba4f417a Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Fri, 20 Dec 2024 22:57:42 -0600 Subject: [PATCH] Create EXP, point and stat functions --- src/math.php | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/math.php diff --git a/src/math.php b/src/math.php new file mode 100644 index 0000000..9605656 --- /dev/null +++ b/src/math.php @@ -0,0 +1,98 @@ + 5) throw new \InvalidArgumentException("Growth rate must be between 0 and 5"); + + return match($growthRate) { + 0 => calculate_erratic_exp($level), + 1 => (4 * pow($level, 3)) / 5, + 2 => pow($level, 3), + 3 => ((6 * pow($level, 3)) / 5) - (15 * pow($level, 2)) + (100 * $level) - 140, + 4 => (5 * pow($level, 3)) / 4, + 5 => calculate_fluctuating_exp($level), + }; +} + +/** + * Calculate the ***total*** EXP for a given level in the Erratic formula. + */ +function calculate_erratic_exp(int $level): int +{ + if ($level <= 50) { + return (pow($level, 3) * (100 - $level)) / 50; + } elseif ($level <= 68) { + return (pow($level, 3) * (150 - $level)) / 100; + } elseif ($level <= 98) { + return (pow($level, 3) * ((1911 - (10 * $level)) / 3)) / 500; + } else { + return (pow($level, 3) * (160 - $level)) / 100; + } +} + +/** + * Calculate the ***total*** EXP for a given level in the Fluctuating formula. + */ +function calculate_fluctuating_exp(int $level): int +{ + if ($level <= 15) { + return pow($level, 3) * ((((($level + 1) / 3) + 24) / 50)); + } elseif ($level <= 36) { + return pow($level, 3) * (($level + 14) / 50); + } else { + return pow($level, 3) * ((($level / 2) + 32) / 50); + } +} + +/** + * Calculate a points total from a base. Modes: 1 (weak), 2 (normal), 3 (strong) + */ +function calculate_points(int $base_points, int $level, int $mode = 2): int +{ + if ($level < 1) throw new \InvalidArgumentException("Level must be 1 or greater"); + + $growth_multiplier = match($mode) { + 1 => 0.75, + 2 => 1.0, + 3 => 1.5, + default => throw new \InvalidArgumentException("Invalid mode. Use 1 (weak), 2 (normal), or 3 (strong)") + }; + + return floor((2 * $base_points * $level * $growth_multiplier) / 100) + $level + 10; +} + +/** + * Calculate a stat total from a base. Modes: 1 (weak), 2 (normal), 3 (strong) + */ +function calculate_stat(int $base_stat, int $level, int $mode = 2): int +{ + if ($level < 1) throw new \InvalidArgumentException("Level must be 1 or greater"); + + $growth_multiplier = match($mode) { + 1 => 0.75, + 2 => 1.0, + 3 => 1.5, + default => throw new \InvalidArgumentException("Invalid mode. Use 1 (weak), 2 (normal), or 3 (strong)") + }; + + return floor((2 * $base_stat * $level * $growth_multiplier) / 100) + 5; +}