Adds bind
This commit is contained in:
parent
83b316ad53
commit
802481c1f5
|
@ -512,4 +512,8 @@ public abstract class Script : IDeepCloneable
|
|||
public virtual void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void CustomTrigger(StringKey eventName, IDictionary<StringKey, object?>? parameters)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
namespace PkmnLib.Static.Utils;
|
||||
|
||||
public static class DictionaryHelpers
|
||||
{
|
||||
public static TValue GetOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)
|
||||
{
|
||||
if (dictionary.TryGetValue(key, out var value))
|
||||
return value;
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
|
@ -845,7 +845,10 @@
|
|||
"contact",
|
||||
"protect",
|
||||
"mirror"
|
||||
]
|
||||
],
|
||||
"effect": {
|
||||
"name": "bind"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "bite",
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Plugin.Gen7.Scripts;
|
||||
|
||||
public static class CustomTriggers
|
||||
{
|
||||
public static readonly StringKey AuroraVeilDuration = "aurora_veil_duration";
|
||||
|
||||
public static readonly StringKey BindNumberOfTurns = "bind_number_of_turns";
|
||||
|
||||
public static readonly StringKey BindPercentOfMaxHealth = "bind_percent_of_max_health";
|
||||
}
|
|
@ -1,8 +1,11 @@
|
|||
using System.Collections.Generic;
|
||||
using PkmnLib.Dynamic.Models;
|
||||
using PkmnLib.Dynamic.ScriptHandling;
|
||||
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||
using PkmnLib.Plugin.Gen7.Scripts;
|
||||
using PkmnLib.Plugin.Gen7.Scripts.Side;
|
||||
using PkmnLib.Plugin.Gen7.Scripts.Weather;
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Plugin.Gen7.Moves;
|
||||
|
||||
|
@ -41,7 +44,15 @@ public class AuroraVeil : Script
|
|||
}
|
||||
|
||||
var side = battle.Sides[move.User.BattleData!.SideIndex];
|
||||
var numberOfTurns = move.User.HasHeldItem("light_clay") ? 8 : 5;
|
||||
|
||||
var numberOfTurns = 5;
|
||||
var dict = new Dictionary<StringKey, object?>()
|
||||
{
|
||||
{ "duration", numberOfTurns }
|
||||
};
|
||||
move.User.RunScriptHook(x => x.CustomTrigger(CustomTriggers.AuroraVeilDuration, dict));
|
||||
numberOfTurns = (int)dict.GetOrDefault("duration", numberOfTurns)!;
|
||||
|
||||
var script = side.VolatileScripts.StackOrAdd(ScriptUtils.ResolveName<AuroraVeilEffect>(), () =>
|
||||
{
|
||||
var effect = new AuroraVeilEffect(numberOfTurns);
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
using System.Collections.Generic;
|
||||
using PkmnLib.Dynamic.Models;
|
||||
using PkmnLib.Dynamic.ScriptHandling;
|
||||
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
|
||||
|
||||
[Script(ScriptCategory.Move, "bind")]
|
||||
public class Bind : Script
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
|
||||
{
|
||||
var bindTurnsParameters = new Dictionary<StringKey, object?> { { "bind_number_of_turns", 5 } };
|
||||
move.User.RunScriptHook(x => x.CustomTrigger(CustomTriggers.BindNumberOfTurns, bindTurnsParameters));
|
||||
var bindDamageParameters = new Dictionary<StringKey, object?> { { "bind_percent_of_max_health", 1f / 8f } };
|
||||
move.User.RunScriptHook(x => x.CustomTrigger(CustomTriggers.BindPercentOfMaxHealth, bindDamageParameters));
|
||||
|
||||
var bindTurns = bindTurnsParameters.GetOrDefault("bind_number_of_turns", 5) as int? ?? 5;
|
||||
var bindDamage = bindDamageParameters.GetOrDefault("bind_percent_of_max_health", 1f / 8f) as float? ?? 1f / 8f;
|
||||
|
||||
var bindEffect = new BindEffect(target, bindTurns, bindDamage);
|
||||
target.Volatile.Add(bindEffect);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
using PkmnLib.Dynamic.Models;
|
||||
using PkmnLib.Dynamic.Models.Choices;
|
||||
using PkmnLib.Dynamic.ScriptHandling;
|
||||
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||
|
||||
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
|
||||
|
||||
[Script(ScriptCategory.Pokemon, "bind")]
|
||||
public class BindEffect : Script
|
||||
{
|
||||
private readonly IPokemon? _owner;
|
||||
private int _turns;
|
||||
private readonly float _percentOfMaxHealth;
|
||||
|
||||
private BindEffect(float percentOfMaxHealth)
|
||||
{
|
||||
_percentOfMaxHealth = percentOfMaxHealth;
|
||||
}
|
||||
|
||||
public BindEffect(IPokemon owner, int turns, float percentOfMaxHealth)
|
||||
{
|
||||
_owner = owner;
|
||||
_turns = turns;
|
||||
_percentOfMaxHealth = percentOfMaxHealth;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnEndTurn(IBattle battle)
|
||||
{
|
||||
if (_owner == null)
|
||||
return;
|
||||
if (_turns > 0)
|
||||
{
|
||||
_turns--;
|
||||
_owner.Damage((uint)(_owner.MaxHealth * _percentOfMaxHealth), DamageSource.Misc);
|
||||
}
|
||||
if (_turns <= 0)
|
||||
RemoveSelf();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = _turns > 0;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = _turns > 0;
|
||||
}
|
Loading…
Reference in New Issue