Cleanup, move OnBeforeAnyHookInvoked function to an interface

This commit is contained in:
2025-06-28 10:28:23 +02:00
parent 43813c1c1c
commit d719ce03ea
10 changed files with 49 additions and 95 deletions

View File

@@ -18,8 +18,6 @@ public abstract class Script : IDeepCloneable
{
internal event Action<Script>? OnRemoveEvent;
private int _suppressCount;
/// <summary>
/// Remove the script from its owner.
/// </summary>
@@ -41,40 +39,6 @@ public abstract class Script : IDeepCloneable
/// </summary>
public virtual ScriptCategory Category => this.ResolveCategory();
/// <summary>
/// A script can be suppressed by other scripts. If a script is suppressed by at least one script
/// we will not execute its methods. This should return the number of suppressions on the script.
/// </summary>
public int SuppressCount => _suppressCount;
/// <summary>
/// Helper function to check if there is at least one suppression on the script
/// </summary>
public bool IsSuppressed => _suppressCount > 0;
/// <summary>
/// Adds a suppression. This makes the script not run anymore. Note that adding this should also
/// remove the suppression later.
///
/// A common pattern for this is to run this in the <see cref="OnInitialize"/> and remove it in the
/// <see cref="OnRemove"/> function.
/// </summary>
public void Suppress() => _suppressCount++;
/// <summary>
/// Removes a suppression. This allows the script to run again (provided other scripts are not
/// suppressing it). Note that running this should only occur if <see cref="Suppress"/> was called earlier
/// </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)
{
}
/// <summary>
/// This function is ran when a volatile effect is added while that volatile effect already is
/// in place. Instead of adding the volatile effect twice, it will execute this function instead.
@@ -767,6 +731,9 @@ public abstract class Script : IDeepCloneable
{
}
/// <summary>
/// This function triggers after a status condition has been applied to a Pokemon.
/// </summary>
public virtual void OnAfterStatusChange(IPokemon pokemon, StringKey status, IPokemon? originPokemon)
{
}
@@ -796,6 +763,9 @@ public abstract class Script : IDeepCloneable
{
}
/// <summary>
/// This function triggers when the weather changes.
/// </summary>
public virtual void OnWeatherChange(IBattle battle, StringKey? weatherName, StringKey? oldWeatherName)
{
}
@@ -844,15 +814,38 @@ public abstract class Script : IDeepCloneable
{
}
/// <summary>
/// This function triggers just before a move choice is executed.
/// </summary>
public virtual void OnBeforeMoveChoice(IMoveChoice moveChoice)
{
}
/// <summary>
/// This function triggers after a move choice has been executed in its entirety.
/// </summary>
public virtual void OnAfterMoveChoice(IMoveChoice moveChoice)
{
}
/// <summary>
/// This function allows a script to change the turn choice that is made by a Pokemon.
/// </summary>
public virtual void ChangeTurnChoice(ref ITurnChoice choice)
{
}
}
/// <summary>
/// This interface is used to allow scripts to run before any hook is invoked. This allows for
/// suppressing certain categories of scripts, which can be useful for preventing certain effects
/// from running.
/// </summary>
public interface IScriptOnBeforeAnyHookInvoked
{
/// <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>
void OnBeforeAnyHookInvoked(ref List<ScriptCategory>? suppressedCategories);
}