using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.Models;
///
/// Random number generator for battles.
///
public interface IBattleRandom : IRandom, IDeepCloneable
{
///
/// Gets whether or not a move triggers its secondary effect. This takes its chance as percent, and
/// rolls whether it triggers. As a side effect this run scripts to allow modifying this random
/// chance.
///
bool EffectChance(float chance, IExecutingMove executingMove, IPokemon target, byte hitNumber);
}
///
public class BattleRandomImpl : RandomImpl, IBattleRandom
{
///
///
/// This constructor is used to instantiate the class when no seed is provided. It uses a time-dependent default seed value.
///
public BattleRandomImpl()
{
}
///
///
/// This constructor is used to instantiate the class with a specific seed value.
///
public BattleRandomImpl(int seed) : base(seed)
{
}
///
public bool EffectChance(float chance, IExecutingMove executingMove, IPokemon target, byte hitNumber)
{
executingMove.RunScriptHookInterface(script =>
script.ChangeEffectChance(executingMove, target, hitNumber, ref chance));
target.RunScriptHookInterface(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;
}
}