Implements experience gain
All checks were successful
Build / Build (push) Successful in 1m49s

This commit is contained in:
2025-11-02 23:20:07 +01:00
parent f00453448f
commit 90eaeb1a72
7 changed files with 83 additions and 2 deletions

View File

@@ -49,6 +49,7 @@ public class Gen7Plugin : Plugin<Gen7PluginConfiguration>, IResourceProvider
registry.RegisterDamageCalculator(new Gen7DamageCalculator(Configuration));
registry.RegisterMiscLibrary(new Gen7MiscLibrary());
registry.RegisterCaptureLibrary(new Gen7CaptureLibrary(Configuration));
registry.RegisterExperienceGainCalculator(new Gen7ExperienceGainCalculator());
ExplicitAIFunctionRegistration.RegisterAIFunctions(registry.ExplicitAIHandlers);
}

View File

@@ -0,0 +1,40 @@
using System.Diagnostics.CodeAnalysis;
using PkmnLib.Dynamic.Libraries;
namespace PkmnLib.Plugin.Gen7.Libraries.Battling;
/// <inheritdoc />
public class Gen7ExperienceGainCalculator : IExperienceGainCalculator
{
/// <inheritdoc />
[SuppressMessage("ReSharper", "UselessBinaryOperation")]
public uint CalculateExperienceGain(IPokemon defeatedPokemon, IPokemon victoriousPokemon)
{
var b = defeatedPokemon.Form.BaseExperience;
var levelFainted = defeatedPokemon.Level;
var levelOpponent = victoriousPokemon.Level;
// TODO: Experience share, in which case s = 2 for Pokemon that did not participate in battle
var s = 1;
var v1 = b * levelFainted / 5 * (1 / s);
var v2 = (2 * levelFainted + 10) / (levelFainted + levelOpponent + 10);
var res = v1 * Math.Pow(v2, 2.5) + 1;
// TODO: t = 1.5 if the Pokemon is traded, and 1.7 is traded and has a different language
var t = 1;
res *= t;
// TODO: script modifier, which is e.
var e = 1;
res *= e;
// TODO: v = 1.2 if the Pokemon is at or past the level where it evolves
var v = 1;
res *= v;
return res switch
{
> uint.MaxValue => uint.MaxValue,
< 0 => 0,
_ => (uint)res,
};
}
}