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

@@ -7,7 +7,7 @@ public class Gravity : Script, IScriptFailIncomingMove, IScriptOnEndTurn, IScrip
private int _turns = 5;
/// <inheritdoc />
public void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
public void ChangeTypesForIncomingMove(IExecutingMove executingMove, IBattlePokemon target, byte hitIndex,
IList<TypeIdentifier> types)
{
var typeLibrary = target.Library.StaticLibrary.Types;
@@ -19,14 +19,14 @@ public class Gravity : Script, IScriptFailIncomingMove, IScriptOnEndTurn, IScrip
}
/// <inheritdoc />
public void FailIncomingMove(IExecutingMove move, IPokemon target, ref bool fail)
public void FailIncomingMove(IExecutingMove move, IBattlePokemon target, ref bool fail)
{
if (move.UseMove.HasFlag(MoveFlags.Gravity))
fail = true;
}
/// <inheritdoc />
public void IsFloating(IPokemon pokemon, ref bool isFloating)
public void IsFloating(IBattlePokemon pokemon, ref bool isFloating)
{
// Gravity makes all Pokémon susceptible to Ground-type moves
isFloating = false;

View File

@@ -4,7 +4,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Battle;
public class IonDelugeEffect : Script, IScriptChangeMoveType, IScriptOnEndTurn
{
/// <inheritdoc />
public void ChangeMoveType(IExecutingMove move, IPokemon target, byte hit, ref TypeIdentifier? moveType)
public void ChangeMoveType(IExecutingMove move, IBattlePokemon target, byte hit, ref TypeIdentifier? moveType)
{
if (moveType?.Name == TypeNames.Normal &&
target.Library.StaticLibrary.Types.TryGetTypeIdentifier(TypeNames.Electric, out var electricType))

View File

@@ -6,7 +6,7 @@ public class MagicRoomEffect : Script, IScriptOnBeforeAnyHookInvoked, IScriptOnE
private int _turnsLeft = 4;
/// <inheritdoc />
public void PreventHeldItemConsume(IPokemon pokemon, IItem heldItem, ref bool prevented)
public void PreventHeldItemConsume(IBattlePokemon pokemon, IItem heldItem, ref bool prevented)
{
prevented = true;
}

View File

@@ -6,7 +6,7 @@ public class MudSportEffect : Script, IScriptChangeBasePower, IScriptOnEndTurn
private int _turnsLeft = 5;
/// <inheritdoc />
public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower)
public void ChangeBasePower(IExecutingMove move, IBattlePokemon target, byte hit, ref ushort basePower)
{
if (move.UseMove.MoveType.Name == TypeNames.Electric)
{

View File

@@ -6,23 +6,23 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Battle;
[Script(ScriptCategory.Battle, "snatch_effect")]
public class SnatchEffect : Script, IScriptStopBeforeMove, IScriptOnEndTurn
{
private Queue<IPokemon> _snatchers = new();
private Queue<IBattlePokemon> _snatchers = new();
public void AddSnatcher(IPokemon snatcher)
public void AddSnatcher(IBattlePokemon snatcher)
{
if (_snatchers.Contains(snatcher))
{
_snatchers = new Queue<IPokemon>(_snatchers.Where(s => s != snatcher));
_snatchers = new Queue<IBattlePokemon>(_snatchers.Where(s => s != snatcher));
}
_snatchers.Enqueue(snatcher);
}
private bool TryGetSnatcher([NotNullWhen(true)] out IPokemon? snatcher)
private bool TryGetSnatcher([NotNullWhen(true)] out IBattlePokemon? snatcher)
{
while (_snatchers.Any())
{
var s = _snatchers.Dequeue();
if (s.BattleData != null && s.IsUsable)
if (s.IsUsable)
{
snatcher = s;
return true;
@@ -38,7 +38,7 @@ public class SnatchEffect : Script, IScriptStopBeforeMove, IScriptOnEndTurn
if (move.UseMove.HasFlag(MoveFlags.Snatch) && TryGetSnatcher(out var snatcher))
{
stop = true;
var battleData = snatcher.BattleData;
var battleData = snatcher;
if (battleData == null)
return;

View File

@@ -4,18 +4,19 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Battle;
public class UproarEffect : Script, IScriptOnBeforeTurnStart, IScriptOnSecondaryEffect, IScriptOnEndTurn,
IScriptPreventStatusChange
{
private IPokemon? _placer;
private IBattlePokemon? _placer;
private bool _hasUsedUproar;
private int _turns = 3;
public void SetPlacer(IPokemon placer)
public void SetPlacer(IBattlePokemon placer)
{
_placer = placer;
_hasUsedUproar = true;
}
/// <inheritdoc />
public void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, ref bool preventStatus)
public void PreventStatusChange(IBattlePokemon pokemon, StringKey status, bool selfInflicted,
ref bool preventStatus)
{
if (status == ScriptUtils.ResolveName<Status.Sleep>())
{
@@ -30,7 +31,7 @@ public class UproarEffect : Script, IScriptOnBeforeTurnStart, IScriptOnSecondary
}
/// <inheritdoc />
public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
public void OnSecondaryEffect(IExecutingMove move, IBattlePokemon target, byte hit)
{
if (move.User == _placer && move.UseMove.Name == MoveNames.Uproar)
_hasUsedUproar = true;

View File

@@ -3,10 +3,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Battle;
[Script(ScriptCategory.Battle, "water_sport")]
public class WaterSportEffect : Script, IScriptChangeMoveDamage, IScriptOnSwitchOut
{
public readonly HashSet<IPokemon> Placers = new();
public readonly HashSet<IBattlePokemon> Placers = new();
/// <inheritdoc />
public void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
public void ChangeMoveDamage(IExecutingMove move, IBattlePokemon target, byte hit, ref uint damage)
{
if (move.UseMove.MoveType.Name == TypeNames.Fire)
{
@@ -15,7 +15,7 @@ public class WaterSportEffect : Script, IScriptChangeMoveDamage, IScriptOnSwitch
}
/// <inheritdoc />
public void OnSwitchOut(IPokemon oldPokemon, byte position)
public void OnSwitchOut(IBattlePokemon oldPokemon, byte position)
{
if (!Placers.Contains(oldPokemon))
return;

View File

@@ -8,7 +8,7 @@ public class WonderRoomEffect : Script, IScriptChangeDefensiveStatValue, IScript
public int TurnsLeft { get; private set; } = 5;
/// <inheritdoc />
public void ChangeDefensiveStatValue(IExecutingMove move, IPokemon target, byte hit, uint offensiveStat,
public void ChangeDefensiveStatValue(IExecutingMove move, IBattlePokemon target, byte hit, uint offensiveStat,
ImmutableStatisticSet<uint> targetStats, Statistic stat, ref uint value)
{
value = move.UseMove.Category switch