PkmnLib.NET/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/Recoil.cs

30 lines
956 B
C#
Raw Normal View History

2025-01-26 10:55:13 +00:00
using System.Collections.Generic;
using PkmnLib.Dynamic.Models.BattleFlow;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "recoil")]
public class Recoil : Script
{
private float _recoilPercentage;
/// <inheritdoc />
public override void OnInitialize(IReadOnlyDictionary<StringKey, object?>? parameters)
{
if (parameters == null)
return;
if (parameters.TryGetValue("recoil_percentage", out var recoilPercentage))
_recoilPercentage = recoilPercentage as float? ?? 0f;
}
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
if (_recoilPercentage <= 0)
return;
var hitData = move.GetHitData(target, hit);
var recoilDamage = (uint)(hitData.Damage * _recoilPercentage);
move.User.Damage(recoilDamage, DamageSource.Misc);
}
}