namespace PkmnLib.Plugin.Gen7.Scripts.Terrain;

[Script(ScriptCategory.Terrain, "misty_terrain")]
public class MistyTerrain : Script, IScriptChangeBasePower, IScriptPreventStatusChange
{
    private static bool IsAffectedByTerrain(IPokemon pokemon) =>
        !pokemon.IsFloating;

    /// <inheritdoc />
    public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower)
    {
        if (!IsAffectedByTerrain(target))
            return;
        if (move.GetHitData(target, hit).Type?.Name == "dragon")
        {
            basePower /= 2;
        }
    }

    /// <inheritdoc />
    public void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, ref bool preventStatus)
    {
        if (!IsAffectedByTerrain(pokemon))
            return;
        preventStatus = true;
    }
}