Created
August 19, 2024 23:44
-
-
Save Ddemon26/2e80cc0e854a44e841328509351d26c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| namespace TC._Project.Scripts | |
| { | |
| public class ExpTable | |
| { | |
| Dictionary<int, int> m_expTable = new Dictionary<int, int>(); | |
| /// <summary> | |
| /// Generates the experience points (EXP) table up to the specified maximum level. | |
| /// </summary> | |
| /// <param name="maxLevel">The maximum level for which to generate the EXP table.</param> | |
| public void GenerateExpTable(int maxLevel) | |
| { | |
| m_expTable = new Dictionary<int, int>(); | |
| for (var level = 1; level <= maxLevel; level++) | |
| { | |
| int expRequired = CalculateExpForLevel(level); | |
| m_expTable[level] = expRequired; | |
| } | |
| } | |
| /// <summary> | |
| /// Retrieves the experience points (EXP) required for a given level. | |
| /// </summary> | |
| /// <param name="level">The level for which to retrieve the required EXP.</param> | |
| /// <returns>The amount of EXP required to reach the specified level, or -1 if the level is not found.</returns> | |
| public int GetExpForLevel(int level) | |
| => m_expTable.GetValueOrDefault(level, -1); | |
| /// <summary> | |
| /// Calculates the experience points (EXP) required for a given level based on a complex formula. | |
| /// </summary> | |
| /// <param name="level">The level for which to calculate the required EXP.</param> | |
| /// <returns>The amount of EXP required to reach the specified level.</returns> | |
| static int CalculateExpForLevel(int level) | |
| { | |
| const int a2 = 100; // Coefficient for the quadratic term | |
| const int a1 = 50; // Coefficient for the linear term | |
| const int a0 = 500; // Constant term | |
| const int b = 2000; // Coefficient for inverse level term | |
| const int c1 = 5; // Offset for the inverse level term | |
| const int c2 = 30; // Amplitude for sine wave adjustment | |
| const double d = 0.5; // Frequency for sine wave adjustment | |
| const double e = Math.PI / 4; // Phase shift for sine wave adjustment | |
| const int f = 200; // Coefficient for logarithmic growth | |
| const double g = 1.5; // Base for logarithmic growth | |
| const int h = 10; // Offset for logarithmic growth | |
| // Calculate each component of the formula | |
| int quadraticComponent = a2 * level * level; | |
| int linearComponent = a1 * level; | |
| int inverseLevelComponent = b / (level + c1); | |
| double sineWaveComponent = c2 * Math.Sin(d * level + e); | |
| var logarithmicComponent = (int)(f * Math.Log(g * level + h)); | |
| // Sum all components to get the total EXP required for this level | |
| int expRequired = quadraticComponent + linearComponent + a0 | |
| + inverseLevelComponent + (int)sineWaveComponent + logarithmicComponent; | |
| return expRequired; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment