Work on item use/evolutions
All checks were successful
Build / Build (push) Successful in 1m7s

This commit is contained in:
2025-08-18 11:57:03 +02:00
parent e5041ec5f0
commit f061ba2455
7 changed files with 157 additions and 12 deletions

View File

@@ -46,12 +46,12 @@ public abstract class ItemScript : IDeepCloneable
/// <summary>
/// Returns whether the item can be held by a Pokémon.
/// </summary>
public virtual bool IsHoldable => false;
public virtual bool IsHoldable => true;
/// <summary>
/// Returns whether the item can be held by the given target.
/// </summary>
public virtual bool CanTargetHold(IPokemon pokemon) => false;
public virtual bool CanTargetHold(IPokemon pokemon) => true;
/// <summary>
/// Handles the use of the item.

View File

@@ -12,6 +12,7 @@ public class ScriptResolver
private IReadOnlyDictionary<(ScriptCategory, StringKey), Func<Script>> _scriptCtors;
private IReadOnlyDictionary<StringKey, Func<IItem, ItemScript>> _itemScriptCtors;
private readonly Dictionary<IItem, ItemScript> _itemBattleScripts = new();
private readonly Dictionary<IItem, ItemScript> _itemScripts = new();
/// <inheritdoc cref="ScriptResolver"/>
public ScriptResolver(IReadOnlyDictionary<(ScriptCategory, StringKey), Func<Script>> scriptCtors,
@@ -67,4 +68,32 @@ public class ScriptResolver
_itemBattleScripts[item] = script;
return true;
}
/// <summary>
/// Try and resolve an item script for the given item. If the item does not have a script, return false.
/// </summary>
public bool TryResolveItemScript(IItem item, [MaybeNullWhen(false)] out ItemScript script)
{
if (_itemScripts.TryGetValue(item, out script))
{
return true;
}
var effect = item.Effect;
if (effect == null)
{
script = null;
return false;
}
if (!_itemScriptCtors.TryGetValue(effect.Name, out var scriptCtor))
{
script = null;
return false;
}
script = scriptCtor(item);
script.OnInitialize(effect.Parameters);
_itemScripts[item] = script;
return true;
}
}