Implementation of Pokeballs
This commit is contained in:
@@ -3,6 +3,7 @@ using PkmnLib.Dynamic.Libraries;
|
||||
using PkmnLib.Dynamic.Models.BattleFlow;
|
||||
using PkmnLib.Dynamic.Models.Choices;
|
||||
using PkmnLib.Dynamic.ScriptHandling;
|
||||
using PkmnLib.Static;
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Dynamic.Models;
|
||||
@@ -116,6 +117,8 @@ public interface IBattle : IScriptSource, IDeepCloneable
|
||||
/// for a single turn. The outer list is ordered from oldest to newest turn.
|
||||
/// </summary>
|
||||
IReadOnlyList<IReadOnlyList<ITurnChoice>> PreviousTurnChoices { get; }
|
||||
|
||||
CaptureResult AttempCapture(byte sideIndex, byte position, IItem item);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IBattle"/>
|
||||
@@ -335,6 +338,24 @@ public class BattleImpl : ScriptSource, IBattle
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<IReadOnlyList<ITurnChoice>> PreviousTurnChoices => _previousTurnChoices;
|
||||
|
||||
/// <inheritdoc />
|
||||
public CaptureResult AttempCapture(byte sideIndex, byte position, IItem item)
|
||||
{
|
||||
var target = GetPokemon(sideIndex, position);
|
||||
if (target is not { IsUsable: true })
|
||||
return CaptureResult.Failed;
|
||||
|
||||
var attemptCapture = Library.CaptureLibrary.TryCapture(target, item, Random);
|
||||
if (attemptCapture.IsCaught)
|
||||
{
|
||||
target.MarkAsCaught();
|
||||
var side = Sides[target.BattleData!.SideIndex];
|
||||
side.ForceClearPokemonFromField(target.BattleData.Position);
|
||||
}
|
||||
EventHook.Invoke(new CaptureAttemptEvent(target, attemptCapture));
|
||||
return attemptCapture;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int ScriptCount => 2;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user