More moves implemented
This commit is contained in:
62
Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/SnatchEffect.cs
Normal file
62
Plugins/PkmnLib.Plugin.Gen7/Scripts/Battle/SnatchEffect.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using PkmnLib.Dynamic.Models.BattleFlow;
|
||||
|
||||
namespace PkmnLib.Plugin.Gen7.Scripts.Battle;
|
||||
|
||||
[Script(ScriptCategory.Battle, "snatch_effect")]
|
||||
public class SnatchEffect : Script
|
||||
{
|
||||
private Queue<IPokemon> _snatchers = new();
|
||||
|
||||
public void AddSnatcher(IPokemon snatcher)
|
||||
{
|
||||
if (_snatchers.Contains(snatcher))
|
||||
{
|
||||
_snatchers = new Queue<IPokemon>(_snatchers.Where(s => s != snatcher));
|
||||
}
|
||||
_snatchers.Enqueue(snatcher);
|
||||
}
|
||||
|
||||
private bool TryGetSnatcher([NotNullWhen(true)] out IPokemon? snatcher)
|
||||
{
|
||||
while (_snatchers.Any())
|
||||
{
|
||||
var s = _snatchers.Dequeue();
|
||||
if (s.BattleData != null && s.IsUsable)
|
||||
{
|
||||
snatcher = s;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
snatcher = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void StopBeforeMove(IExecutingMove move, ref bool stop)
|
||||
{
|
||||
if (move.UseMove.HasFlag("snatch") && TryGetSnatcher(out var snatcher))
|
||||
{
|
||||
stop = true;
|
||||
var battleData = snatcher.BattleData;
|
||||
if (battleData == null)
|
||||
return;
|
||||
|
||||
var moveChoice = new MoveChoice(snatcher, move.MoveChoice.ChosenMove, battleData.SideIndex,
|
||||
battleData.Position);
|
||||
var executingMove = new ExecutingMoveImpl([snatcher], move.NumberOfHits, move.ChosenMove, move.UseMove,
|
||||
moveChoice, move.Battle);
|
||||
// ExecuteMove will once again call StopBeforeMove, which will try to pass the move to the next snatcher
|
||||
// if one exists.
|
||||
MoveTurnExecutor.ExecuteMove(executingMove);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnEndTurn(IBattle battle)
|
||||
{
|
||||
RemoveSelf();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user