This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user