|
|
|
|
@@ -3,17 +3,35 @@ using PkmnLib.Static.Utils;
|
|
|
|
|
|
|
|
|
|
namespace PkmnLib.Dynamic.AI.Explicit;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// An option where a move is used against a target
|
|
|
|
|
/// </summary>
|
|
|
|
|
public record struct MoveOption(AIMoveState Move, IBattle Battle, IPokemon? Target, uint EstimatedDamage = 0);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A function that takes an explicit AI and a move option and returns a boolean value.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public delegate bool AIBoolHandler(IExplicitAI ai, MoveOption option);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A function for returning whether a Pokemon should switch.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public delegate bool AISwitchBoolHandler(IExplicitAI ai, IPokemon pokemon, IBattle battle,
|
|
|
|
|
IReadOnlyList<IPokemon> reserves);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A function for returning the base power of a move.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public delegate void AIMoveBasePowerHandler(IExplicitAI ai, MoveOption option, ref int score);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A function for returning a score
|
|
|
|
|
/// </summary>
|
|
|
|
|
public delegate void AIScoreMoveHandler(IExplicitAI ai, MoveOption option, ref int score);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Explicit AI Handlers are a library that allow plugins to explicitly indicate AI preferences.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public interface IReadOnlyExplicitAIHandlers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
@@ -86,28 +104,50 @@ public interface IReadOnlyExplicitAIHandlers
|
|
|
|
|
/// </summary>
|
|
|
|
|
void ApplyGenerateMoveAgainstTargetScoreModifiers(IExplicitAI ai, MoveOption option, ref int score);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Functions that indicate whether a Pokemon should switch
|
|
|
|
|
/// </summary>
|
|
|
|
|
IReadOnlyDictionary<StringKey, AISwitchBoolHandler> ShouldSwitchFunctions { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates whether a Pokemon should switch into another Pokemon
|
|
|
|
|
/// </summary>
|
|
|
|
|
bool ShouldSwitch(IExplicitAI ai, IPokemon pokemon, IBattle battle, IReadOnlyList<IPokemon> reserves);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Functions that indicate whether a Pokemon should NOT switch
|
|
|
|
|
/// </summary>
|
|
|
|
|
IReadOnlyDictionary<StringKey, AISwitchBoolHandler> ShouldNotSwitchFunctions { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates whether a Pokemon should NOT switch into another Pokemon
|
|
|
|
|
/// </summary>
|
|
|
|
|
bool ShouldNotSwitch(IExplicitAI ai, IPokemon pokemon, IBattle battle, IReadOnlyList<IPokemon> reserves);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Scores abilities
|
|
|
|
|
/// </summary>
|
|
|
|
|
IReadOnlyDictionary<StringKey, AIScoreMoveHandler> AbilityRanking { get; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public class ExplicitAIHandlers : IReadOnlyExplicitAIHandlers
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
IReadOnlyDictionary<StringKey, AIBoolHandler> IReadOnlyExplicitAIHandlers.MoveFailureCheck => MoveFailureCheck;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks whether a move will fail
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FunctionHandlerDictionary<AIBoolHandler> MoveFailureCheck { get; } = new();
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public bool MoveWillFail(IExplicitAI ai, StringKey functionCode, MoveOption option) =>
|
|
|
|
|
MoveFailureCheck.TryGetValue(functionCode, out var handler) && handler(ai, option);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks whether a move will fail against a target
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FunctionHandlerDictionary<AIBoolHandler> MoveFailureAgainstTargetCheck { get; } = new();
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
@@ -118,12 +158,18 @@ public class ExplicitAIHandlers : IReadOnlyExplicitAIHandlers
|
|
|
|
|
public bool MoveWillFailAgainstTarget(IExplicitAI ai, StringKey functionCode, MoveOption option) =>
|
|
|
|
|
MoveFailureAgainstTargetCheck.TryGetValue(functionCode, out var handler) && handler(ai, option);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Functions to score a move
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FunctionHandlerDictionary<AIScoreMoveHandler> MoveEffectScore { get; } = [];
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
IReadOnlyDictionary<StringKey, AIScoreMoveHandler> IReadOnlyExplicitAIHandlers.MoveEffectScore =>
|
|
|
|
|
MoveEffectScore;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Functions to score a move against a target
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FunctionHandlerDictionary<AIScoreMoveHandler> MoveEffectAgainstTargetScore = [];
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
@@ -137,6 +183,9 @@ public class ExplicitAIHandlers : IReadOnlyExplicitAIHandlers
|
|
|
|
|
IReadOnlyDictionary<StringKey, AIScoreMoveHandler> IReadOnlyExplicitAIHandlers.MoveEffectAgainstTargetScore =>
|
|
|
|
|
MoveEffectAgainstTargetScore;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Functions that indicate a moves base power
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FunctionHandlerDictionary<AIMoveBasePowerHandler> MoveBasePower = [];
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
@@ -150,6 +199,9 @@ public class ExplicitAIHandlers : IReadOnlyExplicitAIHandlers
|
|
|
|
|
IReadOnlyDictionary<StringKey, AIMoveBasePowerHandler> IReadOnlyExplicitAIHandlers.MoveBasePower =>
|
|
|
|
|
MoveBasePower;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Functions that indicate a moves score
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FunctionHandlerDictionary<AIScoreMoveHandler> GeneralMoveScore = [];
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
@@ -193,6 +245,7 @@ public class ExplicitAIHandlers : IReadOnlyExplicitAIHandlers
|
|
|
|
|
IReadOnlyDictionary<StringKey, AISwitchBoolHandler> IReadOnlyExplicitAIHandlers.ShouldSwitchFunctions =>
|
|
|
|
|
ShouldSwitchFunctions;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public bool ShouldSwitch(IExplicitAI ai, IPokemon pokemon, IBattle battle, IReadOnlyList<IPokemon> reserves)
|
|
|
|
|
{
|
|
|
|
|
var shouldSwitch = false;
|
|
|
|
|
@@ -203,6 +256,9 @@ public class ExplicitAIHandlers : IReadOnlyExplicitAIHandlers
|
|
|
|
|
return shouldSwitch;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Functions that indicate whether we should not switch
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FunctionHandlerDictionary<AISwitchBoolHandler> ShouldNotSwitchFunctions = [];
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
@@ -210,6 +266,9 @@ public class ExplicitAIHandlers : IReadOnlyExplicitAIHandlers
|
|
|
|
|
IReadOnlyDictionary<StringKey, AISwitchBoolHandler> IReadOnlyExplicitAIHandlers.ShouldNotSwitchFunctions =>
|
|
|
|
|
ShouldNotSwitchFunctions;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Functions to rank an ability
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FunctionHandlerDictionary<AIScoreMoveHandler> AbilityRanking = [];
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|