More move scripts

This commit is contained in:
2025-05-03 16:51:44 +02:00
parent f8c43b6ba0
commit 1973ff50fa
52 changed files with 704 additions and 78 deletions

View File

@@ -1,3 +1,4 @@
using System.Diagnostics;
using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.Models.Choices;
using PkmnLib.Dynamic.ScriptHandling.Registry;
@@ -12,6 +13,7 @@ namespace PkmnLib.Dynamic.ScriptHandling;
/// changes. This allows for easily defining generational differences, and add effects that the
/// developer might require.
/// </summary>
[DebuggerDisplay("{Category} - {Name}")]
public abstract class Script : IDeepCloneable
{
internal event Action<Script>? OnRemoveEvent;
@@ -683,4 +685,12 @@ public abstract class Script : IDeepCloneable
public virtual void OnBeforeHit(IExecutingMove move, IPokemon target, byte hitIndex)
{
}
public virtual void PreventStatusChange(IPokemon pokemonImpl, StringKey status, ref bool preventStatus)
{
}
public virtual void PreventVolatileAdd(Script script, ref bool preventVolatileAdd)
{
}
}

View File

@@ -1,4 +1,5 @@
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using PkmnLib.Dynamic.ScriptHandling.Registry;
using PkmnLib.Static.Utils;
@@ -14,8 +15,11 @@ public interface IScriptSet : IEnumerable<ScriptContainer>
/// <summary>
/// Adds a script to the set. If the script with that name already exists in this set, this
/// makes that script stack instead. The return value here is that script.
/// If the script was blocked from being added, this will return null.
/// </summary>
ScriptContainer Add(Script script);
/// <param name="script">The script to add.</param>
/// <param name="forceAdd">If true, the script cannot be blocked, and will always be added</param>
ScriptContainer? Add(Script script, bool forceAdd = false);
/// <summary>
/// Adds a script with a name to the set. If the script with that name already exists in this
@@ -77,8 +81,15 @@ public interface IScriptSet : IEnumerable<ScriptContainer>
/// <inheritdoc cref="IScriptSet"/>
public class ScriptSet : IScriptSet
{
private IScriptSource _source;
private readonly List<ScriptContainer> _scripts = [];
public ScriptSet(IScriptSource source)
{
_source = source;
}
/// <inheritdoc />
public IEnumerator<ScriptContainer> GetEnumerator() => _scripts.GetEnumerator();
@@ -86,8 +97,16 @@ public class ScriptSet : IScriptSet
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
/// <inheritdoc />
public ScriptContainer Add(Script script)
public ScriptContainer? Add(Script script, bool forceAdd = false)
{
if (!forceAdd)
{
var preventVolatileAdd = false;
_source.RunScriptHook(x => x.PreventVolatileAdd(script, ref preventVolatileAdd));
if (preventVolatileAdd)
return null;
}
var existing = _scripts.FirstOrDefault(s => s.Script?.Name == script.Name);
if (existing != null)
{