More abilities

This commit is contained in:
Deukhoofd 2025-06-15 13:05:52 +02:00
parent 85d97cb9e6
commit ec8681eaa9
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
17 changed files with 294 additions and 59 deletions

View File

@ -46,6 +46,7 @@ public static class MoveTurnExecutor
moveChoice.Script.Clear(); moveChoice.Script.Clear();
} }
} }
moveChoice.RunScriptHook(x => x.OnBeforeMoveChoice(moveChoice));
var targetType = useMove.Target; var targetType = useMove.Target;
var targets = var targets =

View File

@ -89,6 +89,7 @@ public static class TurnRunner
{ {
case IMoveChoice moveChoice: case IMoveChoice moveChoice:
MoveTurnExecutor.ExecuteMoveChoice(battle, moveChoice); MoveTurnExecutor.ExecuteMoveChoice(battle, moveChoice);
moveChoice.RunScriptHook(script => script.OnAfterMoveChoice(moveChoice));
break; break;
case ISwitchChoice switchChoice: case ISwitchChoice switchChoice:
ExecuteSwitchChoice(battle, switchChoice); ExecuteSwitchChoice(battle, switchChoice);

View File

@ -843,4 +843,12 @@ public abstract class Script : IDeepCloneable
public virtual void ModifyPPUsedForIncomingMove(IExecutingMove executingMove, ref byte ppUsed) public virtual void ModifyPPUsedForIncomingMove(IExecutingMove executingMove, ref byte ppUsed)
{ {
} }
public virtual void OnBeforeMoveChoice(IMoveChoice moveChoice)
{
}
public virtual void OnAfterMoveChoice(IMoveChoice moveChoice)
{
}
} }

View File

@ -407,7 +407,11 @@
"effect": "overcoat" "effect": "overcoat"
}, },
"overgrow": { "overgrow": {
"effect": "overgrow" "effect": "power_up_type_at_low_health",
"parameters": {
"type": "grass",
"threshold": 0.33333
}
}, },
"own_tempo": { "own_tempo": {
"effect": "own_tempo" "effect": "own_tempo"
@ -625,26 +629,67 @@
"storm_drain": { "storm_drain": {
"effect": "storm_drain" "effect": "storm_drain"
}, },
"strong_jaw": {}, "strong_jaw": {
"sturdy": {}, "effect": "strong_jaw"
"suction_cups": {}, },
"super_luck": {}, "sturdy": {
"surge_surfer": {}, "effect": "sturdy"
"swarm": {}, },
"sweet_veil": {}, "suction_cups": {
"swift_swim": {}, "effect": "suction_cups"
"symbiosis": {}, },
"synchronize": {}, "super_luck": {
"tangled_feet": {}, "effect": "super_luck"
"tangling_hair": {}, },
"technician": {}, "surge_surfer": {
"telepathy": {}, "effect": "surge_surfer"
"teravolt": {}, },
"thick_fat": {}, "swarm": {
"tinted_lens": {}, "effect": "power_up_type_at_low_health",
"torrent": {}, "parameters": {
"tough_claws": {}, "type": "bug",
"toxic_boost": {}, "threshold": 0.33333
}
},
"sweet_veil": {
"effect": "sweet_veil"
},
"swift_swim": {
"effect": "swift_swim"
},
"symbiosis": {
"effect": "symbiosis"
},
"synchronize": {
"effect": "synchronize"
},
"tangled_feet": {
"effect": "tangled_feet"
},
"tangling_hair": {
"effect": "tangling_hair"
},
"technician": {
"effect": "technician"
},
"telepathy": {
"effect": "telepathy"
},
"teravolt": {
"effect": "teravolt"
},
"thick_fat": {
"effect": "thick_fat"
},
"tinted_lens": {
"effect": "tinted_lens"
},
"tough_claws": {
"effect": "tough_claws"
},
"toxic_boost": {
"effect": "toxic_boost"
},
"trace": { "trace": {
"flags": [ "flags": [
"cant_be_copied" "cant_be_copied"

View File

@ -1,17 +0,0 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Overgrow is an ability that boosts the power of Grass-type moves when the Pokémon's HP is low.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Overgrow_(Ability)">Bulbapedia - Overgrow</see>
/// </summary>
[Script(ScriptCategory.Ability, "overgrow")]
public class Overgrow : Script
{
/// <inheritdoc />
public override void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower)
{
if (move.GetHitData(target, hit).Type?.Name == "grass" && target.CurrentHealth <= target.BoostedStats.Hp / 3)
basePower = basePower.MultiplyOrMax(1.5f);
}
}

View File

@ -27,7 +27,7 @@ public class PowerUpTypeAtLowHealth : Script
if (!parameters.TryGetValue("threshold", out var threshold) || threshold is not float thresholdValue) if (!parameters.TryGetValue("threshold", out var threshold) || threshold is not float thresholdValue)
throw new ArgumentException("Parameter 'threshold' is required and must be a float.", nameof(parameters)); throw new ArgumentException("Parameter 'threshold' is required and must be a float.", nameof(parameters));
if (thresholdValue < 0 || thresholdValue > 1) if (thresholdValue is < 0 or > 1)
throw new ArgumentOutOfRangeException(nameof(threshold), "Threshold must be between 0 and 1."); throw new ArgumentOutOfRangeException(nameof(threshold), "Threshold must be between 0 and 1.");
_type = typeName; _type = typeName;

View File

@ -1,20 +0,0 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Swarm is an ability that powers up Bug-type moves when the Pokémon's HP is low.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Swarm_(Ability)">Bulbapedia - Swarm</see>
/// </summary>
[Script(ScriptCategory.Ability, "swarm")]
public class Swarm : Script
{
/// <inheritdoc />
public override void ChangeOffensiveStatValue(IExecutingMove move, IPokemon target, byte hit, uint defensiveStat,
ImmutableStatisticSet<uint> targetStats, Statistic stat, ref uint value)
{
if (move.GetHitData(target, hit).Type?.Name == "bug" && target.CurrentHealth <= target.MaxHealth / 3)
{
value = value.MultiplyOrMax(1.5f);
}
}
}

View File

@ -0,0 +1,20 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Tangled Feet is an ability that raises evasion if the Pokémon is confused.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Tangled_Feet_(Ability)">Bulbapedia - Tangled Feet</see>
/// </summary>
[Script(ScriptCategory.Ability, "tangled_feet")]
public class TangledFeet : Script
{
/// <inheritdoc />
public override void ChangeIncomingAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref int modifiedAccuracy)
{
if (modifiedAccuracy != 255 && target.Volatile.Contains<Pokemon.Confusion>())
{
modifiedAccuracy /= 2;
}
}
}

View File

@ -0,0 +1,24 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Tangling Hair is an ability that lowers the Speed of attackers making contact.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Tangling_Hair_(Ability)">Bulbapedia - Tangling Hair</see>
/// </summary>
[Script(ScriptCategory.Ability, "tangling_hair")]
public class TanglingHair : Script
{
/// <inheritdoc />
public override void OnIncomingHit(IExecutingMove move, IPokemon target, byte hit)
{
if (!move.GetHitData(target, hit).IsContact)
return;
EventBatchId batchId = new();
move.Battle.EventHook.Invoke(new AbilityTriggerEvent(target)
{
BatchId = batchId,
});
move.User.ChangeStatBoost(Statistic.Speed, -1, false, false, batchId);
}
}

View File

@ -0,0 +1,19 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Technician is an ability that boosts the power of the Pokémon's weaker moves.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Technician_(Ability)">Bulbapedia - Technician</see>
/// </summary>
[Script(ScriptCategory.Ability, "technician")]
public class Technician : Script
{
/// <inheritdoc />
public override void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower)
{
if (move.UseMove.BasePower <= 60)
{
basePower = basePower.MultiplyOrMax(1.5f);
}
}
}

View File

@ -0,0 +1,17 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Telepathy is an ability that prevents damage from allies' moves.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Telepathy_(Ability)">Bulbapedia - Telepathy</see>
/// </summary>
[Script(ScriptCategory.Ability, "telepathy")]
public class Telepathy : Script
{
/// <inheritdoc />
public override void IsInvulnerableToMove(IExecutingMove move, IPokemon target, ref bool invulnerable)
{
if (move.User.BattleData?.BattleSide == target.BattleData?.BattleSide)
invulnerable = true;
}
}

View File

@ -0,0 +1,41 @@
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
using PkmnLib.Plugin.Gen7.Scripts.Side;
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Teravolt is an ability that allows moves to ignore the target's abilities if they could hinder or prevent the move.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Teravolt_(Ability)">Bulbapedia - Teravolt</see>
/// </summary>
[Script(ScriptCategory.Ability, "teravolt")]
public class Teravolt : Script
{
/// <inheritdoc />
public override void OnBeforeMoveChoice(IMoveChoice moveChoice)
{
var battleData = moveChoice.User.BattleData;
if (battleData is null)
return;
var sides = battleData.Battle.Sides.Where(x => x != battleData.BattleSide);
foreach (var side in sides)
{
side.VolatileScripts.Add(new TeravoltEffect());
}
}
/// <inheritdoc />
public override void OnAfterMoveChoice(IMoveChoice move)
{
var battleData = move.User.BattleData;
if (battleData is null)
return;
var sides = battleData.Battle.Sides.Where(x => x != battleData.BattleSide);
foreach (var side in sides)
{
side.VolatileScripts.Remove<TeravoltEffect>();
}
}
}

View File

@ -0,0 +1,20 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Thick Fat is an ability that halves the damage taken from Fire- and Ice-type moves.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Thick_Fat_(Ability)">Bulbapedia - Thick Fat</see>
/// </summary>
[Script(ScriptCategory.Ability, "thick_fat")]
public class ThickFat : Script
{
/// <inheritdoc />
public override void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
var type = move.GetHitData(target, hit).Type;
if (type is not null && (type.Value.Name == "ice" || type.Value.Name == "fire"))
{
damage /= 2;
}
}
}

View File

@ -0,0 +1,19 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Tinted Lens is an ability that doubles the damage of not very effective moves.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Tinted_Lens_(Ability)">Bulbapedia - Tinted Lens</see>
/// </summary>
[Script(ScriptCategory.Ability, "tinted_lens")]
public class TintedLens : Script
{
/// <inheritdoc />
public override void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
if (move.GetHitData(target, hit).Effectiveness < 1.0f)
{
damage = damage.MultiplyOrMax(2);
}
}
}

View File

@ -0,0 +1,19 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Tough Claws is an ability that boosts the power of contact moves.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Tough_Claws_(Ability)">Bulbapedia - Tough Claws</see>
/// </summary>
[Script(ScriptCategory.Ability, "tough_claws")]
public class ToughClaws : Script
{
/// <inheritdoc />
public override void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
if (move.GetHitData(target, hit).IsContact)
{
damage = damage.MultiplyOrMax(5325 / 4096f);
}
}
}

View File

@ -0,0 +1,20 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Toxic Boost is an ability that increases Attack when the Pokémon is poisoned.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Toxic_Boost_(Ability)">Bulbapedia - Toxic Boost</see>
/// </summary>
[Script(ScriptCategory.Ability, "toxic_boost")]
public class ToxicBoost : Script
{
/// <inheritdoc />
public override void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
if (move.User.HasStatus(ScriptUtils.ResolveName<Status.Poisoned>()) ||
move.User.HasStatus(ScriptUtils.ResolveName<Status.BadlyPoisoned>()))
{
damage = damage.MultiplyOrMax(1.5f);
}
}
}

View File

@ -0,0 +1,18 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Side;
[Script(ScriptCategory.Side, "teravolt")]
public class TeravoltEffect : Script
{
/// <inheritdoc />
public override void OnBeforeAnyHookInvoked(ref List<ScriptCategory>? suppressedCategories)
{
suppressedCategories ??= [];
suppressedCategories.Add(ScriptCategory.Ability);
}
/// <inheritdoc />
public override void OnEndTurn(IScriptSource owner, IBattle battle)
{
RemoveSelf();
}
}