Implements accuracy/evasion
This commit is contained in:
@@ -27,4 +27,9 @@ public interface IBattleStatCalculator
|
||||
/// Calculate a single boosted stat of a Pokemon, including stat boosts.
|
||||
/// </summary>
|
||||
uint CalculateBoostedStat(IPokemon pokemon, Statistic stat);
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the accuracy for a move, taking into account any accuracy modifiers.
|
||||
/// </summary>
|
||||
byte CalculateModifiedAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex, byte moveAccuracy);
|
||||
}
|
||||
@@ -140,10 +140,10 @@ internal static class MoveTurnExecutor
|
||||
// modifying it.
|
||||
if (accuracy != 255)
|
||||
{
|
||||
executingMove.RunScriptHook(x => x.ChangeAccuracy(executingMove, target, hitIndex, ref accuracy));
|
||||
accuracy = battle.Library.StatCalculator.CalculateModifiedAccuracy(executingMove, target,
|
||||
hitIndex, accuracy);
|
||||
}
|
||||
|
||||
// TODO: Deal with accuracy/evasion stats.
|
||||
if (accuracy < 100 && battle.Random.GetInt(100) >= accuracy)
|
||||
{
|
||||
executingMove.RunScriptHook(x => x.OnMoveMiss(executingMove, target));
|
||||
|
||||
@@ -43,9 +43,10 @@ public class ScriptRegistry
|
||||
if (type == null)
|
||||
throw new ArgumentNullException(nameof(type));
|
||||
|
||||
var constructor = type.GetConstructor(Type.EmptyTypes);
|
||||
var constructor = type.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
|
||||
null, Type.EmptyTypes, null);
|
||||
if (constructor == null)
|
||||
throw new ArgumentException("The type must have a parameterless constructor.");
|
||||
throw new ArgumentException($"Type {type} does not have a parameterless constructor.");
|
||||
|
||||
// We create a lambda that creates a new instance of the script type.
|
||||
// This is more performant than using Activator.CreateInstance.
|
||||
|
||||
@@ -207,7 +207,7 @@ public abstract class Script
|
||||
/// This function allows a script to modify the accuracy of a move used. This value represents
|
||||
/// the percentage accuracy, so anything above 100% will make it always hit.
|
||||
/// </summary>
|
||||
public virtual void ChangeAccuracy(IExecutingMove move, IPokemon target, byte hit, ref byte accuracy)
|
||||
public virtual void ChangeAccuracyModifier(IExecutingMove move, IPokemon target, byte hit, ref float modifier)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user