Implementation of Pokeballs
This commit is contained in:
25
PkmnLib.Dynamic/Libraries/CaptureLibrary.cs
Normal file
25
PkmnLib.Dynamic/Libraries/CaptureLibrary.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using PkmnLib.Dynamic.Models;
|
||||
using PkmnLib.Static;
|
||||
|
||||
namespace PkmnLib.Dynamic.Libraries;
|
||||
|
||||
public record struct CaptureResult
|
||||
{
|
||||
public CaptureResult(bool IsCaught, int Shakes, bool CriticalCapture)
|
||||
{
|
||||
this.IsCaught = IsCaught;
|
||||
this.Shakes = Shakes;
|
||||
this.CriticalCapture = CriticalCapture;
|
||||
}
|
||||
|
||||
public bool IsCaught { get; init; }
|
||||
public int Shakes { get; init; }
|
||||
public bool CriticalCapture { get; init; }
|
||||
|
||||
public static CaptureResult Failed => new CaptureResult(false, 0, false);
|
||||
}
|
||||
|
||||
public interface ICaptureLibrary
|
||||
{
|
||||
CaptureResult TryCapture(IPokemon target, IItem captureItem, IBattleRandom random);
|
||||
}
|
||||
@@ -32,6 +32,11 @@ public interface IDynamicLibrary
|
||||
/// </summary>
|
||||
IMiscLibrary MiscLibrary { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The capture library deals with the calculation of the capture rate of a Pokémon.
|
||||
/// </summary>
|
||||
ICaptureLibrary CaptureLibrary { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A holder of the script types that can be resolved by this library.
|
||||
/// </summary>
|
||||
@@ -58,19 +63,22 @@ public class DynamicLibraryImpl : IDynamicLibrary
|
||||
throw new InvalidOperationException("Stat calculator not found in plugins.");
|
||||
if (registry.MiscLibrary is null)
|
||||
throw new InvalidOperationException("Misc library not found in plugins.");
|
||||
if (registry.CaptureLibrary is null)
|
||||
throw new InvalidOperationException("Capture library not found in plugins.");
|
||||
var scriptResolver = new ScriptResolver(registry.ScriptTypes, registry.ItemScriptTypes);
|
||||
return new DynamicLibraryImpl(staticLibrary, registry.BattleStatCalculator,
|
||||
registry.DamageCalculator, registry.MiscLibrary, scriptResolver);
|
||||
registry.DamageCalculator, registry.MiscLibrary, registry.CaptureLibrary, scriptResolver);
|
||||
}
|
||||
|
||||
private DynamicLibraryImpl(IStaticLibrary staticLibrary, IBattleStatCalculator statCalculator,
|
||||
IDamageCalculator damageCalculator, IMiscLibrary miscLibrary, ScriptResolver scriptResolver)
|
||||
IDamageCalculator damageCalculator, IMiscLibrary miscLibrary, ICaptureLibrary captureLibrary, ScriptResolver scriptResolver)
|
||||
{
|
||||
StaticLibrary = staticLibrary;
|
||||
StatCalculator = statCalculator;
|
||||
DamageCalculator = damageCalculator;
|
||||
MiscLibrary = miscLibrary;
|
||||
ScriptResolver = scriptResolver;
|
||||
CaptureLibrary = captureLibrary;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -84,7 +92,10 @@ public class DynamicLibraryImpl : IDynamicLibrary
|
||||
|
||||
/// <inheritdoc />
|
||||
public IMiscLibrary MiscLibrary { get; }
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public ICaptureLibrary CaptureLibrary { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public ScriptResolver ScriptResolver { get; }
|
||||
}
|
||||
Reference in New Issue
Block a user