Adds a lot more move effects

This commit is contained in:
2025-01-26 11:55:13 +01:00
parent 802481c1f5
commit 549b92048a
75 changed files with 563 additions and 230 deletions

View File

@@ -1,4 +1,6 @@
using System.Runtime.CompilerServices;
using PkmnLib.Dynamic.Models;
using PkmnLib.Static;
namespace PkmnLib.Dynamic.ScriptHandling;
@@ -42,4 +44,27 @@ public static class ScriptExecution
}
}
public static void RunItemScript(this IItem item, ScriptResolver scriptResolver, IPokemon? target)
{
if (!scriptResolver.TryResolveBattleItemScript(item, out var itemScript))
{
return;
}
if (!itemScript.IsItemUsable)
return;
itemScript.OnInitialize(item.BattleEffect!.Parameters);
var requiresTarget = itemScript.RequiresTarget;
if (requiresTarget)
{
if (target == null)
throw new ArgumentNullException(nameof(target), "Item script requires a target.");
itemScript.OnUseWithTarget(target);
}
else
{
itemScript.OnUse();
}
}
}

View File

@@ -32,7 +32,7 @@ public interface IScriptSet : IEnumerable<ScriptContainer>
/// Gets a script from the set using its type.
/// </summary>
T? Get<T>() where T : Script;
/// <summary>
/// Removes a script from the set using its unique name.
/// </summary>
@@ -43,6 +43,11 @@ public interface IScriptSet : IEnumerable<ScriptContainer>
/// </summary>
void Clear();
/// <summary>
/// Checks if the set has a script with the given type.
/// </summary>
bool Contains<T>() where T : Script => Contains(ScriptUtils.ResolveName<T>());
/// <summary>
/// Checks if the set has a script with the given name.
/// </summary>