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

@@ -9,15 +9,15 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
[Script(ScriptCategory.Ability, "friend_guard")]
public class FriendGuard : Script
{
private IPokemon? _pokemon;
private IBattlePokemon? _pokemon;
/// <inheritdoc />
public override void OnAddedToParent(IScriptSource source)
{
if (source is not IPokemon pokemon)
if (source is not IBattlePokemon pokemon)
throw new InvalidOperationException("Friend Guard can only be added to a Pokemon script source.");
_pokemon = pokemon;
var effect = _pokemon.BattleData?.BattleSide.VolatileScripts.Add(new Side.FriendGuardEffect());
var effect = _pokemon.BattleSide.VolatileScripts.Add(new Side.FriendGuardEffect());
(effect?.Script as Side.FriendGuardEffect)?.OnAdded(_pokemon);
}
@@ -26,7 +26,7 @@ public class FriendGuard : Script
{
if (_pokemon is null)
return;
if (_pokemon.BattleData?.BattleSide.VolatileScripts.TryGet<Side.FriendGuardEffect>(out var script) == true)
if (_pokemon.BattleSide.VolatileScripts.TryGet<Side.FriendGuardEffect>(out var script) == true)
{
script.OnRemoved(_pokemon);
}