Add all missing docs

This commit is contained in:
2025-05-03 14:18:12 +02:00
parent 4d5dfd0342
commit 441f5dddaf
40 changed files with 400 additions and 21 deletions

View File

@@ -1,6 +1,12 @@
namespace PkmnLib.Dynamic.ScriptHandling;
/// <summary>
/// Helper interface for weather scripts.
/// </summary>
public interface IWeatherScript
{
/// <summary>
/// Sets the number of turns the weather will last.
/// </summary>
public void SetTurns(int turns);
}

View File

@@ -4,13 +4,20 @@ using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.ScriptHandling;
/// <summary>
/// Base class for item scripts.
/// </summary>
public abstract class ItemScript : IDeepCloneable
{
/// <inheritdoc cref="ItemScript"/>
protected ItemScript(IItem item)
{
Item = item;
}
/// <summary>
/// The item associated with this script.
/// </summary>
protected IItem Item { get; private set; }
/// <summary>

View File

@@ -3,6 +3,9 @@ using PkmnLib.Static;
namespace PkmnLib.Dynamic.ScriptHandling;
/// <summary>
/// Base class for Pokéball scripts.
/// </summary>
public abstract class PokeballScript : ItemScript
{
/// <inheritdoc />
@@ -10,6 +13,9 @@ public abstract class PokeballScript : ItemScript
{
}
/// <summary>
/// Returns the catch rate of the Pokéball against the given target Pokémon.
/// </summary>
public abstract byte GetCatchRate(IPokemon target);
/// <inheritdoc />

View File

@@ -3,6 +3,9 @@ using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.ScriptHandling.Registry;
/// <summary>
/// Attribute to mark a class as an item script.
/// </summary>
[AttributeUsage(AttributeTargets.Class), MeansImplicitUse]
public class ItemScriptAttribute : Attribute
{

View File

@@ -8,10 +8,12 @@ namespace PkmnLib.Dynamic.ScriptHandling.Registry;
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
public abstract class Plugin
{
/// <inheritdoc cref="Plugin"/>
protected Plugin()
{
}
/// <inheritdoc cref="Plugin"/>
protected Plugin(PluginConfiguration configuration)
{
}
@@ -33,6 +35,9 @@ public abstract class Plugin
public abstract void Register(ScriptRegistry registry);
}
/// <summary>
/// Base class for plugin configuration.
/// </summary>
public abstract class PluginConfiguration
{
}

View File

@@ -18,6 +18,9 @@ public abstract class Script : IDeepCloneable
private int _suppressCount;
/// <summary>
/// Remove the script from its owner.
/// </summary>
public void RemoveSelf()
{
OnRemoveEvent?.Invoke(this);
@@ -62,6 +65,10 @@ public abstract class Script : IDeepCloneable
/// </summary>
public void Unsuppress() => _suppressCount--;
/// <summary>
/// This function is ran before any hook is invoked. This allows for suppressing certain categories
/// of scripts. This is useful for example to prevent certain effects from running.
/// </summary>
public virtual void OnBeforeAnyHookInvoked(ref List<ScriptCategory>? suppressedCategories)
{
}
@@ -95,6 +102,10 @@ public abstract class Script : IDeepCloneable
{
}
/// <summary>
/// Force a certain move choice to be selected. If the choice is set, the Pokemon will be forced
/// to use it, and will not be able to select any other choice.
/// </summary>
public virtual void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice)
{
}
@@ -140,6 +151,9 @@ public abstract class Script : IDeepCloneable
{
}
/// <summary>
/// This function allows you to change the targets of a move choice before the move starts.
/// </summary>
public virtual void ChangeIncomingTargets(IMoveChoice moveChoice, ref IReadOnlyList<IPokemon?> targets)
{
}
@@ -230,6 +244,9 @@ public abstract class Script : IDeepCloneable
{
}
/// <summary>
/// This function allows the script to override how effective a move is on a target.
/// </summary>
public virtual void ChangeIncomingEffectiveness(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref float effectiveness)
{
@@ -504,6 +521,10 @@ public abstract class Script : IDeepCloneable
{
}
/// <summary>
/// This function is triggered on a Pokemon and its parents when the given Pokemon switches out
/// of the battlefield.
/// </summary>
public virtual void OnSwitchOut(IPokemon oldPokemon, byte position)
{
}
@@ -559,10 +580,16 @@ public abstract class Script : IDeepCloneable
{
}
/// <summary>
/// This function allows a script to block an incoming hit.
/// </summary>
public virtual void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
{
}
/// <summary>
/// This function allows a script to block an outgoing hit.
/// </summary>
public virtual void BlockOutgoingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
{
}
@@ -582,23 +609,44 @@ public abstract class Script : IDeepCloneable
{
}
/// <summary>
/// This function allows a script to prevent a held item from being consumed.
/// </summary>
public virtual void PreventHeldItemConsume(IPokemon pokemon, IItem heldItem, ref bool prevented)
{
}
/// <summary>
/// This function allows a script to change any kind of damage that is incoming.
/// </summary>
public virtual void ChangeIncomingDamage(IPokemon pokemon, DamageSource source, ref uint damage)
{
}
/// <summary>
/// This function allows a script to change the accuracy of a move used. The value for accuracy is in percentage.
/// A custom case goes when 255 is returned, in which case the entire accuracy check is skipped, and the move
/// will always hit.
/// </summary>
/// <param name="executingMove"></param>
/// <param name="target"></param>
/// <param name="hitIndex"></param>
/// <param name="modifiedAccuracy"></param>
public virtual void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref int modifiedAccuracy)
{
}
/// <summary>
/// This function allows a script to change the weather duration of a weather effect.
/// </summary>
public virtual void ChangeWeatherDuration(StringKey weatherName, ref int duration)
{
}
/// <summary>
/// This function allows a script to prevent a Pokemon from being healed.
/// </summary>
public virtual void PreventHeal(IPokemon pokemon, uint heal, bool allowRevive, ref bool prevented)
{
}

View File

@@ -55,6 +55,9 @@ public enum ScriptCategory
/// </summary>
Weather = 7,
/// <summary>
/// A special script for terrain, for use on battles.
/// </summary>
Terrain = 8,
/// <summary>

View File

@@ -4,6 +4,10 @@ using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.ScriptHandling;
/// <summary>
/// A holder class for a script. This is used so we can cache a list of these, and iterate over them, even when
/// the underlying script changes.
/// </summary>
public interface IReadOnlyScriptContainer : IEnumerable<ScriptContainer>, IDeepCloneable
{
/// <summary>
@@ -17,10 +21,7 @@ public interface IReadOnlyScriptContainer : IEnumerable<ScriptContainer>, IDeepC
public Script? Script { get; }
}
/// <summary>
/// A holder class for a script. This is used so we can cache a list of these, and iterate over them, even when
/// the underlying script changes.
/// </summary>
/// <inheritdoc cref="IReadOnlyScriptContainer"/>
public class ScriptContainer : IReadOnlyScriptContainer
{
/// <inheritdoc cref="ScriptContainer"/>
@@ -73,6 +74,11 @@ public class ScriptContainer : IReadOnlyScriptContainer
return script;
}
/// <summary>
/// Removes the script from this container, but does not call <see cref="Script.OnRemove"/>.
/// Be very careful with this, as it can lead to unexpected behavior. An example of a valid use is Baton-Pass,
/// where scripts are being removed to be added to another Pokemon, so we want them to remain active.
/// </summary>
public void ClearWithoutRemoving()
{
Script = null;

View File

@@ -64,6 +64,9 @@ public static class ScriptExecution
}
}
/// <summary>
/// Executes a script on an item.
/// </summary>
public static void RunItemScript(this IItem item, ScriptResolver scriptResolver, IPokemon? target)
{
if (!scriptResolver.TryResolveBattleItemScript(item, out var itemScript))