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;
|
||||
|
||||
|
||||
@@ -217,6 +217,13 @@ public class BattleSideImpl : ScriptSource, IBattleSide
|
||||
/// <inheritdoc />
|
||||
public void ForceClearPokemonFromField(byte index)
|
||||
{
|
||||
var pokemon = _pokemon[index];
|
||||
if (pokemon is not null)
|
||||
{
|
||||
pokemon.RunScriptHook(script => script.OnRemove());
|
||||
pokemon.SetOnBattlefield(false);
|
||||
}
|
||||
|
||||
_pokemon[index] = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -201,6 +201,8 @@ public interface IPokemon : IScriptSource, IDeepCloneable
|
||||
/// Whether or not this Pokemon was caught this battle.
|
||||
/// </summary>
|
||||
bool IsCaught { get; }
|
||||
|
||||
public void MarkAsCaught();
|
||||
|
||||
/// <summary>
|
||||
/// The script for the held item.
|
||||
@@ -632,6 +634,12 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
/// <inheritdoc />
|
||||
public bool IsCaught { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void MarkAsCaught()
|
||||
{
|
||||
IsCaught = true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ScriptContainer HeldItemTriggerScript { get; } = new();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user