using PkmnLib.Static.Moves; namespace PkmnLib.Plugin.Gen7.Scripts.Abilities; /// /// Forewarn is an ability that reveals the opponent's move with the highest base power when the Pokémon enters battle. /// This ability is commonly associated with Drowzee and Hypno. /// /// Bulbapedia - Forewarn /// [Script(ScriptCategory.Ability, "forewarn")] public class Forewarn : Script, IScriptOnSwitchIn { /// public void OnSwitchIn(IPokemon pokemon, byte position) { var battleData = pokemon.BattleData; if (battleData == null) return; var opponents = battleData.Battle.Sides.Where(x => x != battleData.BattleSide).SelectMany(x => x.Pokemon) .WhereNotNull(); var highestPowerMove = opponents.SelectMany(opponent => opponent.Moves).WhereNotNull().Select(move => new { Move = move, Power = GetBasePower(move.MoveData), }).OrderByDescending(move => move.Power).FirstOrDefault(); battleData.Battle.EventHook.Invoke(new AbilityTriggerEvent(pokemon) { Metadata = new Dictionary { { "highest_power_move", highestPowerMove?.Move }, { "power", highestPowerMove?.Power }, }, }); } private static readonly Dictionary FixedBasePowers = new() { // 150 BP: Specific moves [MoveNames.BlastBurn] = 150, [MoveNames.Eruption] = 150, [MoveNames.WaterSpout] = 150, [MoveNames.Fissure] = 150, [MoveNames.Guillotine] = 150, [MoveNames.HornDrill] = 150, [MoveNames.SheerCold] = 150, // 120 BP: Counter, Metal Burst, Mirror Coat [MoveNames.Counter] = 120, [MoveNames.MetalBurst] = 120, [MoveNames.MirrorCoat] = 120, // 80 BP: List of variable power and fixed-damage moves [MoveNames.CrushGrip] = 80, [MoveNames.DragonRage] = 80, [MoveNames.ElectroBall] = 80, [MoveNames.Endeavor] = 80, [MoveNames.FinalGambit] = 80, [MoveNames.Flail] = 80, [MoveNames.Fling] = 80, [MoveNames.Frustration] = 80, [MoveNames.GrassKnot] = 80, [MoveNames.GuardianOfAlola] = 80, [MoveNames.GyroBall] = 80, [MoveNames.HeatCrash] = 80, [MoveNames.HeavySlam] = 80, [MoveNames.HiddenPower] = 80, [MoveNames.LowKick] = 80, [MoveNames.NaturalGift] = 80, [MoveNames.NaturesMadness] = 80, [MoveNames.NightShade] = 80, [MoveNames.Present] = 80, [MoveNames.Psywave] = 80, [MoveNames.Punishment] = 80, [MoveNames.Return] = 80, [MoveNames.Reversal] = 80, [MoveNames.SeismicToss] = 80, [MoveNames.SonicBoom] = 80, [MoveNames.SpitUp] = 80, [MoveNames.SuperFang] = 80, [MoveNames.TrumpCard] = 80, [MoveNames.WringOut] = 80, // 20 BP: Stored Power, Power Trip [MoveNames.StoredPower] = 20, [MoveNames.PowerTrip] = 20, }; private static byte GetBasePower(IMoveData moveData) { // OHKO moves (handled by secondary effect) if (moveData.SecondaryEffect?.Name == MoveEffectNames.OneHitKo) return 150; if (FixedBasePowers.TryGetValue(moveData.Name, out var fixedBasePower)) return fixedBasePower; return moveData.BasePower == 0 ? (byte)1 : moveData.BasePower; } }