PkmnLib.NET/PkmnLib.Dynamic/Models/BattleRandom.cs

33 lines
1.2 KiB
C#

using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.Models;
/// <summary>
/// Random number generator for battles.
/// </summary>
public interface IBattleRandom : IRandom
{
/// <summary>
/// Gets whether or not a move triggers its secondary effect. This takes its chance, and
/// rolls whether it triggers. As a side effect this run scripts to allow modifying this random
/// chance.
/// </summary>
bool EffectChance(float chance, IExecutingMove executingMove, IPokemon target, byte hitNumber);
}
/// <inheritdoc cref="IBattleRandom"/>
public class BattleRandomImpl : RandomImpl, IBattleRandom
{
/// <inheritdoc />
public bool EffectChance(float chance, IExecutingMove executingMove, IPokemon target, byte hitNumber)
{
executingMove.RunScriptHook(script => script.ChangeEffectChance(executingMove, target, hitNumber, ref chance));
target.RunScriptHook(script => script.ChangeIncomingEffectChance(executingMove, target, hitNumber, ref chance));
if (chance > 100.0)
return true;
if (chance < 0.0)
return false;
return GetFloat() * 100.0 < chance;
}
}