Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper

This commit is contained in:
2026-08-28 15:20:26 +02:00
parent 942be8eaeb
commit 8a2733a0a9
859 changed files with 4408 additions and 5331 deletions

View File

@@ -26,7 +26,7 @@ public class Gen7BattleStatCalculator : IBattleStatCalculator
}
/// <inheritdoc />
public void CalculateBoostedStats(IPokemon pokemon, StatisticSet<uint> stats)
public void CalculateBoostedStats(IBattlePokemon pokemon, StatisticSet<uint> stats)
{
stats.SetStatistic(Statistic.Hp, CalculateBoostedStat(pokemon, Statistic.Hp));
stats.SetStatistic(Statistic.Attack, CalculateBoostedStat(pokemon, Statistic.Attack));
@@ -37,7 +37,7 @@ public class Gen7BattleStatCalculator : IBattleStatCalculator
}
/// <inheritdoc />
public uint CalculateBoostedStat(IPokemon pokemon, Statistic stat)
public uint CalculateBoostedStat(IBattlePokemon pokemon, Statistic stat)
{
var flatStat = CalculateFlatStat(pokemon, stat);
var boostModifier = GetStatBoostModifier(pokemon.StatBoost.GetStatistic(stat));
@@ -48,7 +48,7 @@ public class Gen7BattleStatCalculator : IBattleStatCalculator
}
/// <inheritdoc />
public byte CalculateModifiedAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
public byte CalculateModifiedAccuracy(IExecutingMove executingMove, IBattlePokemon target, byte hitIndex,
byte moveAccuracy)
{
var accuracyModifier = 1.0f;

View File

@@ -15,7 +15,7 @@ public class Gen7CaptureLibrary : ICaptureLibrary
public bool HasPokemonBeenCaughtBefore(ISpecies species) => _configuration.TimesSpeciesCaught(species) > 0;
/// <inheritdoc />
public CaptureResult TryCapture(IPokemon target, IItem captureItem, IBattleRandom random)
public CaptureResult TryCapture(IBattlePokemon target, IItem captureItem, IBattleRandom random)
{
var maxHealth = target.BoostedStats.Hp;
var currentHealth = target.CurrentHealth;

View File

@@ -6,8 +6,8 @@ namespace PkmnLib.Plugin.Gen7.Libraries.Battling;
public class Gen7DamageCalculator(Gen7PluginConfiguration configuration) : IDamageCalculator
{
/// <inheritdoc />
public uint GetDamage(IExecutingMove? executingMove, MoveCategory category, IPokemon user, IPokemon target,
int targetCount, byte hitNumber, IHitData hitData)
public uint GetDamage(IExecutingMove? executingMove, MoveCategory category, IBattlePokemon user,
IBattlePokemon target, int targetCount, byte hitNumber, IHitData hitData)
{
if (category == MoveCategory.Status)
return 0;
@@ -36,7 +36,7 @@ public class Gen7DamageCalculator(Gen7PluginConfiguration configuration) : IDama
if (configuration.DamageCalculatorHasRandomness)
{
var battle = target.BattleData?.Battle;
var battle = target.Battle;
if (battle == null)
throw new InvalidOperationException("Randomness is enabled, but no battle is set.");
var random = battle.Random;
@@ -75,7 +75,7 @@ public class Gen7DamageCalculator(Gen7PluginConfiguration configuration) : IDama
}
/// <inheritdoc />
public ushort GetBasePower(IExecutingMove executingMove, IPokemon target, byte hitNumber, IHitData hitData)
public ushort GetBasePower(IExecutingMove executingMove, IBattlePokemon target, byte hitNumber, IHitData hitData)
{
if (executingMove.UseMove.Category == MoveCategory.Status)
return 0;
@@ -86,7 +86,7 @@ public class Gen7DamageCalculator(Gen7PluginConfiguration configuration) : IDama
}
/// <inheritdoc />
public bool IsCritical(IBattle battle, IExecutingMove executingMove, IPokemon target, byte hitNumber)
public bool IsCritical(IBattle battle, IExecutingMove executingMove, IBattlePokemon target, byte hitNumber)
{
if (executingMove.UseMove.Category == MoveCategory.Status)
return false;
@@ -104,8 +104,8 @@ public class Gen7DamageCalculator(Gen7PluginConfiguration configuration) : IDama
};
}
private static float GetStatModifier(IExecutingMove? executingMove, MoveCategory category, IPokemon user,
IPokemon target, byte hitNumber, IHitData hitData)
private static float GetStatModifier(IExecutingMove? executingMove, MoveCategory category, IBattlePokemon user,
IBattlePokemon target, byte hitNumber, IHitData hitData)
{
if (category == MoveCategory.Status)
return 1;
@@ -168,7 +168,7 @@ public class Gen7DamageCalculator(Gen7PluginConfiguration configuration) : IDama
/// Gets the damage modifier. This is a value that defaults to 1.0, but can be modified by scripts
/// to apply a raw modifier to the damage.
/// </summary>
private static float GetDamageModifier(IExecutingMove executingMove, IPokemon target, byte hitNumber)
private static float GetDamageModifier(IExecutingMove executingMove, IBattlePokemon target, byte hitNumber)
{
var modifier = 1.0f;

View File

@@ -11,7 +11,7 @@ public class Gen7MiscLibrary : IMiscLibrary
new SecondaryEffectImpl(-1, "struggle", new Dictionary<StringKey, object?>()), ["not_sketchable"]);
/// <inheritdoc />
public ITurnChoice ReplacementChoice(IPokemon user, byte targetSide, byte targetPosition) =>
public ITurnChoice ReplacementChoice(IBattlePokemon user, byte targetSide, byte targetPosition) =>
new MoveChoice(user, new LearnedMoveImpl(_struggleData, MoveLearnMethod.Unknown), targetSide, targetPosition);
/// <inheritdoc />
@@ -37,7 +37,7 @@ public class Gen7MiscLibrary : IMiscLibrary
public bool CanFlee(IBattle battle, IFleeChoice fleeChoice)
{
var user = fleeChoice.User;
var battleData = user.BattleData;
var battleData = user;
if (battleData == null)
return false;
var opponentSide = battle.Sides[battleData.SideIndex == 0 ? 1 : 0];