199 lines
7.5 KiB
C#
199 lines
7.5 KiB
C#
using PkmnLib.Dynamic.Models;
|
|
using PkmnLib.Static.Utils;
|
|
|
|
namespace PkmnLib.Dynamic.AI.Explicit;
|
|
|
|
public record struct MoveOption(AIMoveState Move, IBattle Battle, IPokemon? Target, uint EstimatedDamage = 0);
|
|
|
|
public delegate bool AIBoolHandler(MoveOption option);
|
|
|
|
public delegate void AIMoveBasePowerHandler(MoveOption option, ref int score);
|
|
|
|
public delegate void AIScoreMoveHandler(MoveOption option, ref int score);
|
|
|
|
public interface IReadOnlyExplicitAIHandlers
|
|
{
|
|
/// <summary>
|
|
/// A list of checks to determine if a move will fail.
|
|
/// </summary>
|
|
IReadOnlyDictionary<StringKey, AIBoolHandler> MoveFailureCheck { get; }
|
|
|
|
/// <summary>
|
|
/// Checks if a move will fail based on the provided function code and options.
|
|
/// </summary>
|
|
bool MoveWillFail(StringKey functionCode, MoveOption option);
|
|
|
|
/// <summary>
|
|
/// A list of checks to determine if a move will fail against a target.
|
|
/// </summary>
|
|
IReadOnlyDictionary<StringKey, AIBoolHandler> MoveFailureAgainstTargetCheck { get; }
|
|
|
|
/// <summary>
|
|
/// Checks if a move will fail against a target based on the provided function code and options.
|
|
/// </summary>
|
|
bool MoveWillFailAgainstTarget(StringKey functionCode, MoveOption option);
|
|
|
|
/// <summary>
|
|
/// A list of handlers to apply scores for move effects.
|
|
/// </summary>
|
|
IReadOnlyDictionary<StringKey, AIScoreMoveHandler> MoveEffectScore { get; }
|
|
|
|
/// <summary>
|
|
/// Applies the score for a move effect based on the provided name and options.
|
|
/// </summary>
|
|
void ApplyMoveEffectScore(StringKey name, MoveOption option, ref int score);
|
|
|
|
/// <summary>
|
|
/// A list of handlers to apply scores for move effects against a target.
|
|
/// </summary>
|
|
IReadOnlyDictionary<StringKey, AIScoreMoveHandler> MoveEffectAgainstTargetScore { get; }
|
|
|
|
/// <summary>
|
|
/// Applies the score for a move effect against a target based on the provided name and options.
|
|
/// </summary>
|
|
void ApplyMoveEffectAgainstTargetScore(StringKey name, MoveOption option, ref int score);
|
|
|
|
/// <summary>
|
|
/// A list of handlers to determine the base power of a move.
|
|
/// </summary>
|
|
IReadOnlyDictionary<StringKey, AIMoveBasePowerHandler> MoveBasePower { get; }
|
|
|
|
/// <summary>
|
|
/// Applies the base power for a move based on the provided name and options.
|
|
/// </summary>
|
|
void GetBasePower(StringKey name, MoveOption option, ref int power);
|
|
|
|
/// <summary>
|
|
/// A list of handlers to apply scores for general move effectiveness.
|
|
/// </summary>
|
|
IReadOnlyDictionary<StringKey, AIScoreMoveHandler> GeneralMoveScore { get; }
|
|
|
|
/// <summary>
|
|
/// Applies the score for a general move based on the provided option.
|
|
/// </summary>
|
|
/// <param name="option"></param>
|
|
/// <param name="score"></param>
|
|
/// <returns></returns>
|
|
void ApplyGenerateMoveScoreModifiers(MoveOption option, ref int score);
|
|
|
|
/// <summary>
|
|
/// A list of handlers to apply scores for general move effectiveness against a target.
|
|
/// </summary>
|
|
IReadOnlyDictionary<StringKey, AIScoreMoveHandler> GeneralMoveAgainstTargetScore { get; }
|
|
|
|
/// <summary>
|
|
/// Applies the score for a general move against a target based on the provided option.
|
|
/// </summary>
|
|
void ApplyGenerateMoveAgainstTargetScoreModifiers(MoveOption option, ref int score);
|
|
|
|
IReadOnlyDictionary<StringKey, AIBoolHandler> ShouldSwitch { get; }
|
|
IReadOnlyDictionary<StringKey, AIBoolHandler> ShouldNotSwitch { get; }
|
|
IReadOnlyDictionary<StringKey, AIScoreMoveHandler> AbilityRanking { get; }
|
|
}
|
|
|
|
public class ExplicitAIHandlers : IReadOnlyExplicitAIHandlers
|
|
{
|
|
/// <inheritdoc />
|
|
IReadOnlyDictionary<StringKey, AIBoolHandler> IReadOnlyExplicitAIHandlers.MoveFailureCheck => MoveFailureCheck;
|
|
|
|
public FunctionHandlerDictionary<AIBoolHandler> MoveFailureCheck { get; } = new();
|
|
|
|
/// <inheritdoc />
|
|
public bool MoveWillFail(StringKey functionCode, MoveOption option) =>
|
|
MoveFailureCheck.TryGetValue(functionCode, out var handler) && handler(option);
|
|
|
|
public FunctionHandlerDictionary<AIBoolHandler> MoveFailureAgainstTargetCheck { get; } = new();
|
|
|
|
/// <inheritdoc />
|
|
IReadOnlyDictionary<StringKey, AIBoolHandler> IReadOnlyExplicitAIHandlers.MoveFailureAgainstTargetCheck =>
|
|
MoveFailureAgainstTargetCheck;
|
|
|
|
/// <inheritdoc />
|
|
public bool MoveWillFailAgainstTarget(StringKey functionCode, MoveOption option) =>
|
|
MoveFailureAgainstTargetCheck.TryGetValue(functionCode, out var handler) && handler(option);
|
|
|
|
public FunctionHandlerDictionary<AIScoreMoveHandler> MoveEffectScore { get; } = [];
|
|
|
|
/// <inheritdoc />
|
|
IReadOnlyDictionary<StringKey, AIScoreMoveHandler> IReadOnlyExplicitAIHandlers.MoveEffectScore =>
|
|
MoveEffectScore;
|
|
|
|
public FunctionHandlerDictionary<AIScoreMoveHandler> MoveEffectAgainstTargetScore = [];
|
|
|
|
/// <inheritdoc />
|
|
public void ApplyMoveEffectScore(StringKey name, MoveOption option, ref int score)
|
|
{
|
|
if (MoveEffectScore.TryGetValue(name, out var handler))
|
|
handler(option, ref score);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
IReadOnlyDictionary<StringKey, AIScoreMoveHandler> IReadOnlyExplicitAIHandlers.MoveEffectAgainstTargetScore =>
|
|
MoveEffectAgainstTargetScore;
|
|
|
|
public FunctionHandlerDictionary<AIMoveBasePowerHandler> MoveBasePower = [];
|
|
|
|
/// <inheritdoc />
|
|
public void ApplyMoveEffectAgainstTargetScore(StringKey name, MoveOption option, ref int score)
|
|
{
|
|
if (MoveEffectAgainstTargetScore.TryGetValue(name, out var handler))
|
|
handler(option, ref score);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
IReadOnlyDictionary<StringKey, AIMoveBasePowerHandler> IReadOnlyExplicitAIHandlers.MoveBasePower =>
|
|
MoveBasePower;
|
|
|
|
public FunctionHandlerDictionary<AIScoreMoveHandler> GeneralMoveScore = [];
|
|
|
|
/// <inheritdoc />
|
|
public void GetBasePower(StringKey name, MoveOption option, ref int power)
|
|
{
|
|
if (MoveBasePower.TryGetValue(name, out var handler))
|
|
handler(option, ref power);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
IReadOnlyDictionary<StringKey, AIScoreMoveHandler> IReadOnlyExplicitAIHandlers.GeneralMoveScore =>
|
|
GeneralMoveScore;
|
|
|
|
public FunctionHandlerDictionary<AIScoreMoveHandler> GeneralMoveAgainstTargetScore = [];
|
|
|
|
/// <inheritdoc />
|
|
public void ApplyGenerateMoveScoreModifiers(MoveOption option, ref int score)
|
|
{
|
|
foreach (var (_, handler) in GeneralMoveScore)
|
|
{
|
|
handler(option, ref score);
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
IReadOnlyDictionary<StringKey, AIScoreMoveHandler> IReadOnlyExplicitAIHandlers.GeneralMoveAgainstTargetScore =>
|
|
GeneralMoveAgainstTargetScore;
|
|
|
|
public FunctionHandlerDictionary<AIBoolHandler> ShouldSwitch = [];
|
|
|
|
/// <inheritdoc />
|
|
public void ApplyGenerateMoveAgainstTargetScoreModifiers(MoveOption option, ref int score)
|
|
{
|
|
foreach (var (_, handler) in GeneralMoveAgainstTargetScore)
|
|
{
|
|
handler(option, ref score);
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
IReadOnlyDictionary<StringKey, AIBoolHandler> IReadOnlyExplicitAIHandlers.ShouldSwitch => ShouldSwitch;
|
|
|
|
public FunctionHandlerDictionary<AIBoolHandler> ShouldNotSwitch = [];
|
|
|
|
/// <inheritdoc />
|
|
IReadOnlyDictionary<StringKey, AIBoolHandler> IReadOnlyExplicitAIHandlers.ShouldNotSwitch => ShouldNotSwitch;
|
|
|
|
public FunctionHandlerDictionary<AIScoreMoveHandler> AbilityRanking = [];
|
|
|
|
/// <inheritdoc />
|
|
IReadOnlyDictionary<StringKey, AIScoreMoveHandler> IReadOnlyExplicitAIHandlers.AbilityRanking =>
|
|
AbilityRanking;
|
|
} |