Implementation of Pokeballs

This commit is contained in:
2025-01-10 11:58:23 +01:00
parent 0518499a4c
commit 42e3273483
15 changed files with 254 additions and 12 deletions

View File

@@ -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;