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