namespace PkmnLib.Plugin.Gen7.Scripts.Side;

[Script(ScriptCategory.Side, "friend_guard")]
public class FriendGuardEffect : Script, IScriptChangeIncomingMoveDamage
{
    private readonly HashSet<IPokemon> _placerPokemon = [];

    public void OnAdded(IPokemon placer)
    {
        _placerPokemon.Add(placer);
    }

    public void OnRemoved(IPokemon placer)
    {
        _placerPokemon.Remove(placer);
        if (_placerPokemon.Count == 0)
        {
            RemoveSelf();
        }
    }

    /// <inheritdoc />
    public void ChangeIncomingMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
    {
        var modifier = Math.Pow(0.75f, _placerPokemon.Count);
        damage = (uint)(damage * modifier);
    }
}