Getting started with implementing an explicit AI, based on the Essentials one.
All checks were successful
Build / Build (push) Successful in 1m2s

This commit is contained in:
2025-07-11 17:03:08 +02:00
parent 084ae84130
commit a3a4993407
56 changed files with 2687 additions and 1274 deletions

View File

@@ -1,66 +0,0 @@
namespace PkmnLib.Dynamic.ScriptHandling.Registry;
/// <summary>
/// A plugin is a way to register scripts and other components to the script registry.
/// </summary>
public interface IPlugin
{
/// <summary>
/// The configuration for the plugin. This is used to pass in any configuration options.
/// </summary>
IPluginConfiguration Configuration { get; }
/// <summary>
/// The name of the plugin. Mostly used for debugging purposes.
/// </summary>
string Name { get; }
/// <summary>
/// When the plugin should be loaded. Lower values are loaded first.
/// 0 should be reserved for the core battle scripts.
/// </summary>
uint LoadOrder { get; }
/// <summary>
/// Run the registration of the plugin when we're building the library.
/// </summary>
void Register(ScriptRegistry registry);
}
/// <inheritdoc cref="IPlugin"/>
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
public abstract class Plugin<TConfiguration> : IPlugin where TConfiguration : IPluginConfiguration
{
/// <inheritdoc />
IPluginConfiguration IPlugin.Configuration => Configuration;
/// <inheritdoc cref="IPlugin.Configuration"/>
public TConfiguration Configuration { get; }
/// <inheritdoc cref="Plugin{TConfiguration}"/>
protected Plugin(TConfiguration configuration)
{
Configuration = configuration;
}
/// <summary>
/// The name of the plugin. Mostly used for debugging purposes.
/// </summary>
public abstract string Name { get; }
/// <summary>
/// When the plugin should be loaded. Lower values are loaded first.
/// 0 should be reserved for the core battle scripts.
/// </summary>
public abstract uint LoadOrder { get; }
/// <summary>
/// Run the registration of the plugin when we're building the library.
/// </summary>
public abstract void Register(ScriptRegistry registry);
}
/// <summary>
/// Base class for plugin configuration.
/// </summary>
public interface IPluginConfiguration;

View File

@@ -1,35 +0,0 @@
using PkmnLib.Dynamic.Libraries.DataLoaders.Models;
using PkmnLib.Static;
namespace PkmnLib.Dynamic.ScriptHandling.Registry;
/// <summary>
/// Interface for plugins that can mutate data.
/// </summary>
public interface IPluginDataMutator
{
/// <summary>
/// Mutates move data after it has been loaded, before it is used to convert to a static library.
/// </summary>
void MutateMoveData(SerializedMoveDataWrapper data);
/// <summary>
/// Mutates item data after it has been loaded, before it is used to convert to a static library.
/// </summary>
void MutateItemData(List<SerializedItem> data);
/// <summary>
/// Mutates ability data after it has been loaded, before it is used to convert to a static library.
/// </summary>
void MutateAbilityData(Dictionary<string, SerializedAbility> data);
/// <summary>
/// Mutates growth rate data after it has been loaded, before it is used to convert to a static library.
/// </summary>
void MutateGrowthRateData(List<IGrowthRate> data);
/// <summary>
/// Mutates species data after it has been loaded, before it is used to convert to a static library.
/// </summary>
void MutateSpeciesData(Dictionary<string, SerializedSpecies> data);
}

View File

@@ -1,99 +0,0 @@
using System.Reflection;
using PkmnLib.Static.Libraries;
namespace PkmnLib.Dynamic.ScriptHandling.Registry;
/// <summary>
/// Interface for plugins that provide resources.
/// </summary>
public interface IResourceProvider
{
/// <summary>
/// The settings for the library. This is used to configure the library and its resources.
/// </summary>
LibrarySettings? Settings { get; }
/// <summary>
/// Gets the resource for the given type. This is used to load resources from the plugin. Returns null if the
/// plugin does not provide the resource.
/// </summary>
IResourceResult? GetResource(ResourceFileType request);
}
/// <summary>
/// Enum for the different types of resources that can be loaded.
/// </summary>
public enum ResourceFileType
{
/// <summary>
/// Unknown type. This is used for errors and should not be used in normal code.
/// </summary>
Unknown,
/// <summary>
/// The type for the types of Pokémon. This includes the type effectiveness chart and the type names.
/// </summary>
Types,
/// <summary>
/// The type for the natures of Pokémon. This includes the nature names and the nature effects.
/// </summary>
Natures,
/// <summary>
/// The type for the moves of Pokémon. This includes the move names and the move effects.
/// </summary>
Moves,
/// <summary>
/// The type for the items of Pokémon. This includes the item names and the item effects.
/// </summary>
Items,
/// <summary>
/// The type for the abilities of Pokémon. This includes the ability names and the ability effects.
/// </summary>
Abilities,
/// <summary>
/// The type for the growth rates of Pokémon. This includes the growth rate names and the growth rate effects.
/// </summary>
GrowthRates,
/// <summary>
/// The type for the species of Pokémon. This includes the species names and the species effects.
/// </summary>
Species,
}
/// <summary>
/// Interface for a resource result. This is used to load resources from the plugin.
/// </summary>
public interface IResourceResult
{
/// <summary>
/// Opens the resource and returns a stream. This is used to load the resource from the plugin.
/// </summary>
Stream Open();
}
/// <summary>
/// Class for a resource result that is loaded from an embedded resource in an assembly.
/// </summary>
public class AssemblyResourceResult : IResourceResult
{
private readonly string _resourceName;
private readonly Assembly _assembly;
/// <inheritdoc cref="AssemblyResourceResult" />
public AssemblyResourceResult(string resourceName, Assembly assembly)
{
_resourceName = resourceName;
_assembly = assembly;
}
/// <inheritdoc />
public Stream Open() => _assembly.GetManifestResourceStream(_resourceName) ??
throw new InvalidOperationException(
$"Resource '{_resourceName}' not found in assembly '{_assembly.FullName}'.");
}

View File

@@ -1,5 +1,6 @@
using System.Linq.Expressions;
using System.Reflection;
using PkmnLib.Dynamic.AI.Explicit;
using PkmnLib.Dynamic.Libraries;
using PkmnLib.Static;
using PkmnLib.Static.Utils;
@@ -115,4 +116,5 @@ public class ScriptRegistry
internal IDamageCalculator? DamageCalculator => _damageCalculator;
internal IMiscLibrary? MiscLibrary => _miscLibrary;
internal ICaptureLibrary? CaptureLibrary => _captureLibrary;
public ExplicitAIHandlers ExplicitAIHandlers { get; } = new();
}