Implementation of Pokeballs
This commit is contained in:
@@ -10,11 +10,12 @@ namespace PkmnLib.Dynamic.ScriptHandling;
|
||||
public class ScriptResolver
|
||||
{
|
||||
private IReadOnlyDictionary<(ScriptCategory, StringKey), Func<Script>> _scriptCtors;
|
||||
private IReadOnlyDictionary<StringKey, Func<ItemScript>> _itemScriptCtors;
|
||||
private IReadOnlyDictionary<StringKey, Func<IItem, ItemScript>> _itemScriptCtors;
|
||||
private readonly Dictionary<IItem, ItemScript> _itemBattleScripts = new();
|
||||
|
||||
/// <inheritdoc cref="ScriptResolver"/>
|
||||
public ScriptResolver(IReadOnlyDictionary<(ScriptCategory, StringKey), Func<Script>> scriptCtors,
|
||||
IReadOnlyDictionary<StringKey, Func<ItemScript>> itemScriptCtors)
|
||||
IReadOnlyDictionary<StringKey, Func<IItem, ItemScript>> itemScriptCtors)
|
||||
{
|
||||
_scriptCtors = scriptCtors;
|
||||
_itemScriptCtors = itemScriptCtors;
|
||||
@@ -46,6 +47,11 @@ public class ScriptResolver
|
||||
/// </summary>
|
||||
public bool TryResolveBattleItemScript(IItem item, [MaybeNullWhen(false)] out ItemScript script)
|
||||
{
|
||||
if (_itemBattleScripts.TryGetValue(item, out script))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var effect = item.BattleEffect;
|
||||
if (effect == null)
|
||||
{
|
||||
@@ -58,8 +64,9 @@ public class ScriptResolver
|
||||
return false;
|
||||
}
|
||||
|
||||
script = scriptCtor();
|
||||
script = scriptCtor(item);
|
||||
script.OnInitialize(effect.Parameters);
|
||||
_itemBattleScripts[item] = script;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user