using PkmnLib.Plugin.Gen7.Scripts.Side;

namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

[Script(ScriptCategory.Move, "echoed_voice")]
public class EchoedVoice : Script, IScriptOnSecondaryEffect, IScriptChangeDamageModifier
{
    /// <inheritdoc />
    public void ChangeDamageModifier(IExecutingMove move, IPokemon target, byte hit, ref float modifier)
    {
        var battleData = move.User.BattleData;
        if (battleData == null)
            return;
        var side = battleData.Battle.Sides[battleData.SideIndex];
        var echoedVoiceData = side.VolatileScripts.Get<EchoedVoiceData>();
        if (echoedVoiceData == null)
            return;

        modifier *= 2;
    }

    /// <inheritdoc />
    public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
    {
        var battleData = move.User.BattleData;
        if (battleData == null)
            return;
        var side = battleData.Battle.Sides[battleData.SideIndex];
        side.VolatileScripts.Add(new EchoedVoiceData());
    }
}