Implement most pokeballs
All checks were successful
Build / Build (push) Successful in 1m2s

This commit is contained in:
2025-07-20 11:15:45 +02:00
parent db3f7f2403
commit 77d7b86a3c
19 changed files with 452 additions and 38 deletions

View File

@@ -1,4 +1,5 @@
using PkmnLib.Dynamic.Libraries;
using PkmnLib.Static.Species;
namespace PkmnLib.Plugin.Gen7.Libraries.Battling;
@@ -11,6 +12,8 @@ public class Gen7CaptureLibrary : ICaptureLibrary
_configuration = configuration;
}
public bool HasPokemonBeenCaughtBefore(ISpecies species) => _configuration.TimesSpeciesCaught(species) > 0;
/// <inheritdoc />
public CaptureResult TryCapture(IPokemon target, IItem captureItem, IBattleRandom random)
{
@@ -18,18 +21,17 @@ public class Gen7CaptureLibrary : ICaptureLibrary
var currentHealth = target.CurrentHealth;
var catchRate = target.Species.CaptureRate;
byte bonusBall = 1;
if (target.Library.ScriptResolver.TryResolveBattleItemScript(captureItem, out var script) &&
script is PokeballScript pokeballScript)
{
bonusBall = pokeballScript.GetCatchRate(target);
pokeballScript.ChangeCatchRate(target, ref catchRate);
}
byte bonusStatus = 1;
target.RunScriptHook<IScriptChangeCatchRateBonus>(x =>
x.ChangeCatchRateBonus(target, captureItem, ref bonusStatus));
var modifiedCatchRate = (3.0f * maxHealth - 2.0f * currentHealth) * catchRate * bonusBall / (3.0f * maxHealth);
var modifiedCatchRate = (3.0f * maxHealth - 2.0f * currentHealth) * catchRate / (3.0f * maxHealth);
modifiedCatchRate *= bonusStatus;
var shakeProbability = 65536 / Math.Pow(255 / modifiedCatchRate, 0.1875f);