More abilities
All checks were successful
Build / Build (push) Successful in 48s

This commit is contained in:
2025-06-09 13:44:26 +02:00
parent 00005aa4bf
commit 97868ab4c6
94 changed files with 829 additions and 150 deletions

View File

@@ -19,7 +19,7 @@ public class AngerPoint : Script
{
BatchId = batchId,
});
target.ChangeStatBoost(Statistic.Attack, 12, true, batchId);
target.ChangeStatBoost(Statistic.Attack, 12, true, false, batchId);
}
}
}

View File

@@ -18,6 +18,6 @@ public class BeastBoost : Script
{
BatchId = batchId,
});
move.User.ChangeStatBoost(highestStat, 1, true, batchId);
move.User.ChangeStatBoost(highestStat, 1, true, false, batchId);
}
}

View File

@@ -22,6 +22,6 @@ public class Berserk : Script
{
BatchId = batchId,
});
pokemon.ChangeStatBoost(Statistic.SpecialAttack, 1, true, batchId);
pokemon.ChangeStatBoost(Statistic.SpecialAttack, 1, true, false, batchId);
}
}

View File

@@ -13,7 +13,8 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
public class Comatose : Script
{
/// <inheritdoc />
public override void PreventStatusChange(IPokemon pokemonImpl, StringKey status, ref bool preventStatus)
public override void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted,
ref bool preventStatus)
{
if (status == ScriptUtils.ResolveName<Status.Sleep>())
{

View File

@@ -22,6 +22,6 @@ public class Competitive : Script
{
BatchId = batchId,
});
pokemon.ChangeStatBoost(Statistic.SpecialAttack, 2, true, batchId);
pokemon.ChangeStatBoost(Statistic.SpecialAttack, 2, true, false, batchId);
}
}

View File

@@ -22,6 +22,6 @@ public class Defiant : Script
{
BatchId = batchId,
});
pokemon.ChangeStatBoost(Statistic.Attack, 2, true, batchId);
pokemon.ChangeStatBoost(Statistic.Attack, 2, true, false, batchId);
}
}

View File

@@ -31,6 +31,6 @@ public class Download : Script
});
pokemon.ChangeStatBoost(
opponentAverageDefense < opponentAverageSpecialDefense ? Statistic.Attack : Statistic.SpecialAttack, 1,
true, batchId);
true, false, batchId);
}
}

View File

@@ -36,13 +36,13 @@ public class EffectSpore : Script
switch (chance)
{
case < 9:
move.User.SetStatus(ScriptUtils.ResolveName<Status.Poisoned>(), batchId);
move.User.SetStatus(ScriptUtils.ResolveName<Status.Poisoned>(), false, batchId);
break;
case < 19:
move.User.SetStatus(ScriptUtils.ResolveName<Status.Paralyzed>(), batchId);
move.User.SetStatus(ScriptUtils.ResolveName<Status.Paralyzed>(), false, batchId);
break;
case < 30:
move.User.SetStatus(ScriptUtils.ResolveName<Status.Sleep>(), batchId);
move.User.SetStatus(ScriptUtils.ResolveName<Status.Sleep>(), false, batchId);
break;
}
}

View File

@@ -20,6 +20,6 @@ public class FlameBody : Script
return;
move.Battle.EventHook.Invoke(new AbilityTriggerEvent(target));
move.User.SetStatus(ScriptUtils.ResolveName<Status.Burned>());
move.User.SetStatus(ScriptUtils.ResolveName<Status.Burned>(), false);
}
}

View File

@@ -16,14 +16,13 @@ public class FlashFire : Script
public override void ChangeIncomingEffectiveness(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref float effectiveness)
{
if (executingMove.GetHitData(target, hitIndex).Type?.Name == "fire")
{
effectiveness = 0f;
if (executingMove.GetHitData(target, hitIndex).Type?.Name != "fire")
return;
effectiveness = 0f;
if (target.Volatile.Contains<FlashFireEffect>())
return;
target.Volatile.Add(new FlashFireEffect());
executingMove.Battle.EventHook.Invoke(new AbilityTriggerEvent(target));
}
if (target.Volatile.Contains<FlashFireEffect>())
return;
target.Volatile.Add(new FlashFireEffect());
executingMove.Battle.EventHook.Invoke(new AbilityTriggerEvent(target));
}
}

View File

@@ -0,0 +1,60 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Flower Gift is an ability that boosts the Attack and Special Defense of the Pokémon and its allies in sunlight.
/// This ability is exclusive to Cherrim.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Flower_Gift_(Ability)">Bulbapedia - Flower Gift</see>
/// </summary>
[Script(ScriptCategory.Ability, "flower_gift")]
public class FlowerGift : Script
{
private IPokemon? _pokemon;
/// <inheritdoc />
public override void OnAddedToParent(IScriptSource source)
{
if (source is not IPokemon pokemon)
throw new InvalidOperationException("Flower Gift can only be added to a Pokemon script source.");
_pokemon = pokemon;
var effect = _pokemon.BattleData?.BattleSide.VolatileScripts.Add(new Side.FlowerGiftEffect());
(effect?.Script as Side.FlowerGiftEffect)?.OnAdded(_pokemon);
}
/// <inheritdoc />
public override void OnWeatherChange(IBattle battle, StringKey? weatherName, StringKey? oldWeatherName)
{
if (_pokemon is null)
return;
if (weatherName != ScriptUtils.ResolveName<Weather.HarshSunlight>())
return;
if (_pokemon.Species.Name != "cherrim")
return;
EventBatchId batchId = new();
if (_pokemon.Species.TryGetForm("sunshine", out var form) && _pokemon.Form != form)
{
_pokemon.ChangeForm(form, batchId);
}
}
/// <inheritdoc />
public override void OnRemove()
{
if (_pokemon is null)
return;
if (_pokemon.BattleData?.BattleSide.VolatileScripts.TryGet<Side.FlowerGiftEffect>(out var script) == true)
{
script.OnRemoved(_pokemon);
}
if (_pokemon.Species.Name != "cherrim")
return;
EventBatchId batchId = new();
var defaultForm = _pokemon.Species.GetDefaultForm();
if (_pokemon.Form != defaultForm)
{
_pokemon.ChangeForm(defaultForm, batchId);
}
}
}

View File

@@ -0,0 +1,34 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Flower Veil is an ability that prevents Grass-type allies from having their stats lowered or being afflicted by status conditions.
/// This ability is exclusive to Florges and its evolutionary line.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Flower_Veil_(Ability)">Bulbapedia - Flower Veil</see>
/// </summary>
[Script(ScriptCategory.Ability, "flower_veil")]
public class FlowerVeil : Script
{
private IPokemon? _pokemon;
/// <inheritdoc />
public override void OnAddedToParent(IScriptSource source)
{
if (source is not IPokemon pokemon)
throw new InvalidOperationException("Flower Veil can only be added to a Pokemon script source.");
_pokemon = pokemon;
var effect = _pokemon.BattleData?.BattleSide.VolatileScripts.Add(new Side.FlowerVeilEffect());
(effect?.Script as Side.FlowerVeilEffect)?.OnAdded(_pokemon);
}
/// <inheritdoc />
public override void OnRemove()
{
if (_pokemon is null)
return;
if (_pokemon.BattleData?.BattleSide.VolatileScripts.TryGet<Side.FlowerVeilEffect>(out var script) == true)
{
script.OnRemoved(_pokemon);
}
}
}

View File

@@ -0,0 +1,24 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Fluffy is an ability that halves the damage taken from contact moves but doubles the damage taken from Fire-type moves.
/// This ability is exclusive to Stufful and Bewear.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Fluffy_(Ability)">Bulbapedia - Fluffy</see>
/// </summary>
[Script(ScriptCategory.Ability, "fluffy")]
public class Fluffy : Script
{
/// <inheritdoc />
public override void ChangeDamageModifier(IExecutingMove move, IPokemon target, byte hit, ref float modifier)
{
if (move.GetHitData(target, hit).Type?.Name == "fire")
{
modifier *= 2f;
}
if (move.UseMove.HasFlag("contact"))
{
modifier *= 0.5f;
}
}
}

View File

@@ -0,0 +1,71 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Forecast is an ability that changes the Pokémon's form depending on the weather.
/// This ability is exclusive to Castform.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Forecast_(Ability)">Bulbapedia - Forecast</see>
/// </summary>
[Script(ScriptCategory.Ability, "forecast")]
public class Forecast : Script
{
private IPokemon? _pokemon;
/// <inheritdoc />
public override void OnAddedToParent(IScriptSource source)
{
if (source is not IPokemon pokemon)
throw new InvalidOperationException("Forecast can only be added to a Pokemon script source.");
_pokemon = pokemon;
}
/// <inheritdoc />
public override void OnSwitchIn(IPokemon pokemon, byte position)
{
ChangeForm(pokemon, pokemon.BattleData?.Battle.WeatherName);
}
/// <inheritdoc />
public override void OnWeatherChange(IBattle battle, StringKey? weatherName, StringKey? oldWeatherName)
{
if (_pokemon is null)
return;
ChangeForm(_pokemon, weatherName);
}
/// <inheritdoc />
public override void OnRemove()
{
if (_pokemon is null)
return;
ChangeForm(_pokemon, null);
}
private static void ChangeForm(IPokemon pokemon, StringKey? weather)
{
if (pokemon.Species.Name != "castform")
return;
if (weather == ScriptUtils.ResolveName<Weather.HarshSunlight>() &&
pokemon.Species.TryGetForm("sunny", out var sunnyForm) && pokemon.Form != sunnyForm)
{
pokemon.ChangeForm(sunnyForm);
}
else if (weather == ScriptUtils.ResolveName<Weather.Rain>() &&
pokemon.Species.TryGetForm("rainy", out var rainyForm) && pokemon.Form != rainyForm)
{
pokemon.ChangeForm(rainyForm);
}
else if (weather == ScriptUtils.ResolveName<Weather.Hail>() &&
pokemon.Species.TryGetForm("snowy", out var snowyForm) && pokemon.Form != snowyForm)
{
pokemon.ChangeForm(snowyForm);
}
else if (pokemon.Form != pokemon.Species.GetDefaultForm())
{
pokemon.ChangeForm(pokemon.Species.GetDefaultForm());
}
}
}

View File

@@ -0,0 +1,64 @@
using PkmnLib.Static.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// 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.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Forewarn_(Ability)">Bulbapedia - Forewarn</see>
/// </summary>
[Script(ScriptCategory.Ability, "forewarn")]
public class Forewarn : Script
{
/// <inheritdoc />
public override 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<StringKey, object?>
{
{ "highest_power_move", highestPowerMove?.Move },
{ "power", highestPowerMove?.Power },
},
});
}
private static byte GetBasePower(IMoveData moveData)
{
// OHKO moves (handled by secondary effect)
if (moveData.SecondaryEffect?.Name == "one_hit_ko")
return 150;
return moveData.Name.ToString() switch
{
// 150 BP: Specific moves
"blast_burn" or "eruption" or "water_spout" or "fissure" or "guillotine" or "horn_drill"
or "sheer_cold" => 150,
// 120 BP: Counter, Metal Burst, Mirror Coat
"counter" or "metal_burst" or "mirror_coat" => 120,
// 80 BP: List of variable power and fixed-damage moves
"crush_grip" or "dragon_rage" or "electro_ball" or "endeavor" or "final_gambit" or "flail" or "fling"
or "frustration" or "grass_knot" or "guardian_of_alola" or "gyro_ball" or "heat_crash" or "heavy_slam"
or "hidden_power" or "low_kick" or "natural_gift" or "natures_madness" or "night_shade" or "present"
or "psywave" or "punishment" or "return" or "reversal" or "seismic_toss" or "sonic_boom" or "spit_up"
or "super_fang" or "trump_card" or "wring_out" => 80,
// 20 BP: Stored Power, Power Trip
"stored_power" or "power_trip" => 20,
_ => moveData.BasePower == 0 ? (byte)1 : moveData.BasePower,
};
}
}

View File

@@ -0,0 +1,34 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Friend Guard is an ability that reduces the damage taken by allies by 25%.
/// This ability is commonly associated with Clefairy and Vivillon.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Friend_Guard_(Ability)">Bulbapedia - Friend Guard</see>
/// </summary>
[Script(ScriptCategory.Ability, "friend_guard")]
public class FriendGuard : Script
{
private IPokemon? _pokemon;
/// <inheritdoc />
public override void OnAddedToParent(IScriptSource source)
{
if (source is not IPokemon pokemon)
throw new InvalidOperationException("Friend Guard can only be added to a Pokemon script source.");
_pokemon = pokemon;
var effect = _pokemon.BattleData?.BattleSide.VolatileScripts.Add(new Side.FriendGuardEffect());
(effect?.Script as Side.FriendGuardEffect)?.OnAdded(_pokemon);
}
/// <inheritdoc />
public override void OnRemove()
{
if (_pokemon is null)
return;
if (_pokemon.BattleData?.BattleSide.VolatileScripts.TryGet<Side.FriendGuardEffect>(out var script) == true)
{
script.OnRemoved(_pokemon);
}
}
}

View File

@@ -0,0 +1,43 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Frisk is an ability that reveals the held items of opposing Pokémon when the Pokémon enters battle.
/// This ability is commonly associated with Banette and Gothitelle.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Frisk_(Ability)">Bulbapedia - Frisk</see>
/// </summary>
[Script(ScriptCategory.Ability, "frisk")]
public class Frisk : Script
{
/// <inheritdoc />
public override void OnSwitchIn(IPokemon pokemon, byte position)
{
if (pokemon.BattleData?.BattleSide is null)
return;
// Check if the Pokémon has an opposing side
var opposingSide =
pokemon.BattleData.Battle.Sides.FirstOrDefault(side => side != pokemon.BattleData.BattleSide);
if (opposingSide is null)
return;
EventBatchId batchId = new();
// Iterate through the opposing Pokémon
foreach (var opponent in opposingSide.Pokemon.WhereNotNull())
{
// If the opponent has a held item, reveal it
if (opponent.HeldItem != null)
{
pokemon.BattleData.Battle.EventHook.Invoke(new AbilityTriggerEvent(pokemon)
{
Metadata = new Dictionary<StringKey, object?>
{
{ "opponent", opponent },
{ "held_item", opponent.HeldItem },
},
BatchId = batchId,
});
}
}
}
}

View File

@@ -0,0 +1,21 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Full Metal Body is an ability that prevents the Pokémon's stats from being lowered by other Pokémon's moves or abilities.
/// This ability is exclusive to Solgaleo.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Full_Metal_Body_(Ability)">Bulbapedia - Full Metal Body</see>
/// </summary>
[Script(ScriptCategory.Ability, "full_metal_body")]
public class FullMetalBody : Script
{
/// <inheritdoc />
public override void PreventStatBoostChange(IPokemon target, Statistic stat, sbyte amount, bool selfInflicted,
ref bool prevent)
{
if (selfInflicted)
return;
prevent = true;
}
}

View File

@@ -0,0 +1,22 @@
using PkmnLib.Static.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Fur Coat is an ability that halves the damage taken from physical moves.
/// This ability is exclusive to Furfrou.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Fur_Coat_(Ability)">Bulbapedia - Fur Coat</see>
/// </summary>
[Script(ScriptCategory.Ability, "fur_coat")]
public class FurCoat : Script
{
/// <inheritdoc />
public override void ChangeIncomingMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
if (move.UseMove.Category == MoveCategory.Physical)
{
damage /= 2;
}
}
}