Implementation of Pokeballs
This commit is contained in:
@@ -36,5 +36,6 @@ public class Gen7Plugin : Dynamic.ScriptHandling.Registry.Plugin
|
||||
registry.RegisterBattleStatCalculator(new Gen7BattleStatCalculator());
|
||||
registry.RegisterDamageCalculator(new Gen7DamageCalculator(_configuration.DamageCalculatorHasRandomness));
|
||||
registry.RegisterMiscLibrary(new Gen7MiscLibrary());
|
||||
registry.RegisterCaptureLibrary(new Gen7CaptureLibrary());
|
||||
}
|
||||
}
|
||||
53
Plugins/PkmnLib.Plugin.Gen7/Libraries/Gen7CaptureLibrary.cs
Normal file
53
Plugins/PkmnLib.Plugin.Gen7/Libraries/Gen7CaptureLibrary.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using PkmnLib.Dynamic.Libraries;
|
||||
using PkmnLib.Dynamic.Models;
|
||||
using PkmnLib.Dynamic.ScriptHandling;
|
||||
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||
using PkmnLib.Static;
|
||||
|
||||
namespace PkmnLib.Plugin.Gen7.Libraries;
|
||||
|
||||
public class Gen7CaptureLibrary : ICaptureLibrary
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public CaptureResult TryCapture(IPokemon target, IItem captureItem, IBattleRandom random)
|
||||
{
|
||||
var maxHealth = target.BoostedStats.Hp;
|
||||
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);
|
||||
}
|
||||
|
||||
byte bonusStatus = 1;
|
||||
target.RunScriptHook(x => x.ChangeCatchRateBonus(target, captureItem, ref bonusStatus));
|
||||
|
||||
var modifiedCatchRate =
|
||||
(((3.0 * maxHealth) - (2.0 * currentHealth)) * catchRate * bonusBall) / (3.0 * maxHealth);
|
||||
modifiedCatchRate *= bonusStatus;
|
||||
|
||||
var shakeProbability = 65536 / Math.Pow((255 / modifiedCatchRate), 0.1875);
|
||||
byte shakes = 0;
|
||||
if (modifiedCatchRate >= 255)
|
||||
{
|
||||
shakes = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME: Implement critical capture
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
if (random.GetInt(0, 65536) < shakeProbability)
|
||||
{
|
||||
shakes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
var success = shakes >= 3;
|
||||
return new CaptureResult(success, shakes, false);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
||||
using PkmnLib.Dynamic.Models;
|
||||
using PkmnLib.Dynamic.ScriptHandling;
|
||||
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||
using PkmnLib.Static;
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Plugin.Gen7.Scripts.Items;
|
||||
@@ -11,6 +12,11 @@ public class HealingItem : ItemScript
|
||||
{
|
||||
private uint _healAmount;
|
||||
|
||||
/// <inheritdoc />
|
||||
public HealingItem(IItem item) : base(item)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool IsItemUsable => true;
|
||||
|
||||
|
||||
40
Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/StaticPokeball.cs
Normal file
40
Plugins/PkmnLib.Plugin.Gen7/Scripts/Items/StaticPokeball.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using PkmnLib.Dynamic.Models;
|
||||
using PkmnLib.Dynamic.ScriptHandling;
|
||||
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||
using PkmnLib.Static;
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Plugin.Gen7.Scripts.Items;
|
||||
|
||||
/// <summary>
|
||||
/// An implementation of a pokeball script that just has a flat catch rate bonus.
|
||||
/// </summary>
|
||||
[ItemScript("pokeball")]
|
||||
public class StaticPokeball : PokeballScript
|
||||
{
|
||||
private byte _catchRate;
|
||||
|
||||
/// <inheritdoc />
|
||||
public StaticPokeball(IItem item) : base(item)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnInitialize(IReadOnlyDictionary<StringKey, object?>? parameters)
|
||||
{
|
||||
if (parameters == null || !parameters.TryGetValue("catchRate", out var catchRateObj) ||
|
||||
catchRateObj is not byte catchRate)
|
||||
{
|
||||
catchRate = 1;
|
||||
}
|
||||
|
||||
_catchRate = catchRate;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override byte GetCatchRate(IPokemon target)
|
||||
{
|
||||
return _catchRate;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user