Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user