This commit is contained in:
@@ -36,7 +36,7 @@ public abstract class ItemScript : IDeepCloneable
|
||||
/// <summary>
|
||||
/// Returns whether the item requires a target to be used.
|
||||
/// </summary>
|
||||
public virtual bool RequiresTarget => false;
|
||||
public virtual ItemTargetType TargetType => ItemTargetType.None;
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether the item is usable on the given target.
|
||||
|
||||
@@ -29,7 +29,7 @@ public abstract class PokeballScript : ItemScript
|
||||
public override bool IsItemUsable => true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool RequiresTarget => true;
|
||||
public override ItemTargetType TargetType => ItemTargetType.FoePokemon;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool IsTargetValid(IPokemon target) =>
|
||||
|
||||
@@ -100,8 +100,8 @@ public static class ScriptExecution
|
||||
/// <summary>
|
||||
/// Executes a script on an item.
|
||||
/// </summary>
|
||||
public static void RunItemScript(this IItem item, ScriptResolver scriptResolver, IPokemon? target,
|
||||
EventHook eventHook)
|
||||
public static void RunItemScript(this IItem item, ScriptResolver scriptResolver, IPokemon? target, IPokemon user,
|
||||
IBattle battle, EventHook eventHook)
|
||||
{
|
||||
if (!scriptResolver.TryResolveBattleItemScript(item, out var itemScript))
|
||||
{
|
||||
@@ -111,16 +111,20 @@ public static class ScriptExecution
|
||||
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, eventHook);
|
||||
}
|
||||
else
|
||||
var targetType = itemScript.TargetType;
|
||||
if (targetType == ItemTargetType.None)
|
||||
{
|
||||
itemScript.OnUse(eventHook);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (target == null)
|
||||
throw new ArgumentNullException(nameof(target), "Item script requires a target.");
|
||||
if (!targetType.IsValidTarget(battle, user, target))
|
||||
throw new InvalidOperationException("Item script target is not valid for the required target type.");
|
||||
if (!itemScript.IsTargetValid(target))
|
||||
throw new InvalidOperationException("Item script target is not valid.");
|
||||
itemScript.OnUseWithTarget(target, eventHook);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user