Further work on the script interface rework

This commit is contained in:
2025-07-05 11:30:18 +02:00
parent 1feb27e826
commit 4499927551
100 changed files with 418 additions and 352 deletions

View File

@@ -3,12 +3,12 @@ using PkmnLib.Plugin.Gen7.Scripts.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "autotomize")]
public class AutotomizeEffect : Script, IBatonPassException
public class AutotomizeEffect : Script, IBatonPassException, IScriptStack
{
public int Stacks { get; private set; } = 1;
/// <inheritdoc />
public override void Stack()
public void Stack()
{
Stacks++;
}

View File

@@ -3,7 +3,7 @@ using PkmnLib.Plugin.Gen7.Scripts.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "bide")]
public class BideEffect : Script, IScriptForceTurnSelection, IScriptOnIncomingHit
public class BideEffect : Script, IScriptForceTurnSelection, IScriptOnIncomingHit, IScriptOnDamage
{
private readonly IPokemon? _owner;
public byte Turns;
@@ -26,7 +26,7 @@ public class BideEffect : Script, IScriptForceTurnSelection, IScriptOnIncomingHi
}
/// <inheritdoc />
public override void OnDamage(IPokemon pokemon, DamageSource source, uint oldHealth, uint newHealth)
public void OnDamage(IPokemon pokemon, DamageSource source, uint oldHealth, uint newHealth)
{
DamageTaken += oldHealth - newHealth;
}

View File

@@ -1,7 +1,7 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "bind")]
public class BindEffect : Script, IScriptOnEndTurn
public class BindEffect : Script, IScriptOnEndTurn, IScriptPreventSelfSwitch, IScriptPreventSelfRunAway
{
private readonly IPokemon? _owner;
private int _turns;
@@ -29,8 +29,8 @@ public class BindEffect : Script, IScriptOnEndTurn
}
/// <inheritdoc />
public override void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = _turns > 0;
public void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = _turns > 0;
/// <inheritdoc />
public override void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = _turns > 0;
public void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = _turns > 0;
}

View File

@@ -1,11 +1,11 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "block")]
public class BlockEffect : Script
public class BlockEffect : Script, IScriptPreventSelfRunAway, IScriptPreventSelfSwitch
{
/// <inheritdoc />
public override void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = true;
public void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = true;
/// <inheritdoc />
public override void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = true;
public void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = true;
}

View File

@@ -3,7 +3,8 @@ using PkmnLib.Plugin.Gen7.Scripts.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "charge_bounce")]
public class ChargeBounceEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomingMoveDamage
public class ChargeBounceEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomingMoveDamage,
IScriptBlockIncomingHit
{
private readonly IPokemon _owner;
@@ -20,7 +21,7 @@ public class ChargeBounceEffect : Script, IScriptForceTurnSelection, IScriptChan
}
/// <inheritdoc />
public override void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
public void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
{
if (!executingMove.UseMove.HasFlag("hit_flying"))
block = true;

View File

@@ -3,7 +3,8 @@ using PkmnLib.Plugin.Gen7.Scripts.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "charge_fly")]
public class ChargeFlyEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomingMoveDamage
public class ChargeFlyEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomingMoveDamage,
IScriptBlockIncomingHit
{
private readonly IPokemon _owner;
@@ -20,7 +21,7 @@ public class ChargeFlyEffect : Script, IScriptForceTurnSelection, IScriptChangeI
}
/// <inheritdoc />
public override void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
public void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
{
if (!executingMove.UseMove.HasFlag("hit_flying"))
block = true;

View File

@@ -3,7 +3,8 @@ using PkmnLib.Plugin.Gen7.Scripts.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "charge_sky_drop")]
public class ChargeSkyDropEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomingMoveDamage
public class ChargeSkyDropEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomingMoveDamage,
IScriptBlockIncomingHit
{
private readonly IPokemon _owner;
@@ -20,7 +21,7 @@ public class ChargeSkyDropEffect : Script, IScriptForceTurnSelection, IScriptCha
}
/// <inheritdoc />
public override void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
public void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
{
if (!executingMove.UseMove.HasFlag("hit_flying"))
block = true;

View File

@@ -1,10 +1,10 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "destiny_bond")]
public class DestinyBondEffect : Script, IScriptOnBeforeMove
public class DestinyBondEffect : Script, IScriptOnBeforeMove, IScriptOnFaint
{
/// <inheritdoc />
public override void OnFaint(IPokemon pokemon, DamageSource source)
public void OnFaint(IPokemon pokemon, DamageSource source)
{
if (source == DamageSource.MoveDamage)
{

View File

@@ -3,7 +3,7 @@ using PkmnLib.Plugin.Gen7.Scripts.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "dig")]
public class DigEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomingMoveDamage
public class DigEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomingMoveDamage, IScriptBlockIncomingHit
{
private readonly IPokemon _owner;
@@ -20,7 +20,7 @@ public class DigEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomin
}
/// <inheritdoc />
public override void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
public void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
{
if (!executingMove.UseMove.HasFlag("hit_underground"))
block = true;

View File

@@ -3,7 +3,7 @@ using PkmnLib.Plugin.Gen7.Scripts.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "dive")]
public class DiveEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomingMoveDamage
public class DiveEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomingMoveDamage, IScriptBlockIncomingHit
{
private readonly IPokemon _owner;
@@ -20,7 +20,7 @@ public class DiveEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomi
}
/// <inheritdoc />
public override void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
public void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
{
if (!executingMove.UseMove.HasFlag("hit_underwater"))
block = true;

View File

@@ -1,18 +1,18 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "embargo")]
public class EmbargoEffect : Script, IScriptOnEndTurn
public class EmbargoEffect : Script, IScriptOnEndTurn, IScriptStack, IScriptPreventHeldItemConsume
{
private int _turns = 5;
/// <inheritdoc />
public override void PreventHeldItemConsume(IPokemon pokemon, IItem heldItem, ref bool prevented)
public void PreventHeldItemConsume(IPokemon pokemon, IItem heldItem, ref bool prevented)
{
prevented = true;
}
/// <inheritdoc />
public override void Stack()
public void Stack()
{
_turns = 5;
}

View File

@@ -1,10 +1,10 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "endure")]
public class EndureEffect : Script, IScriptOnEndTurn
public class EndureEffect : Script, IScriptOnEndTurn, IScriptChangeIncomingDamage
{
/// <inheritdoc />
public override void ChangeIncomingDamage(IPokemon pokemon, DamageSource source, ref uint damage)
public void ChangeIncomingDamage(IPokemon pokemon, DamageSource source, ref uint damage)
{
if (damage > pokemon.CurrentHealth)
damage = pokemon.CurrentHealth - 1;

View File

@@ -1,7 +1,7 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "fire_spin")]
public class FireSpinEffect : Script, IScriptOnEndTurn
public class FireSpinEffect : Script, IScriptOnEndTurn, IScriptPreventSelfRunAway, IScriptPreventSelfSwitch
{
private readonly IPokemon _owner;
@@ -17,8 +17,8 @@ public class FireSpinEffect : Script, IScriptOnEndTurn
}
/// <inheritdoc />
public override void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = true;
public void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = true;
/// <inheritdoc />
public override void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = true;
public void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = true;
}

View File

@@ -1,7 +1,7 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "grudge")]
public class GrudgeEffect : Script, IScriptOnIncomingHit
public class GrudgeEffect : Script, IScriptOnIncomingHit, IScriptOnFaint
{
private ILearnedMove? _lastMove;
@@ -12,7 +12,7 @@ public class GrudgeEffect : Script, IScriptOnIncomingHit
}
/// <inheritdoc />
public override void OnFaint(IPokemon pokemon, DamageSource source)
public void OnFaint(IPokemon pokemon, DamageSource source)
{
if (_lastMove != null && source == DamageSource.MoveDamage)
{

View File

@@ -1,7 +1,7 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "infestation")]
public class InfestationEffect : Script, IScriptOnEndTurn
public class InfestationEffect : Script, IScriptOnEndTurn, IScriptPreventSelfSwitch, IScriptPreventSelfRunAway
{
private readonly IPokemon _owner;
private int _turns;
@@ -13,10 +13,10 @@ public class InfestationEffect : Script, IScriptOnEndTurn
}
/// <inheritdoc />
public override void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = true;
public void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = true;
/// <inheritdoc />
public override void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = true;
public void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = true;
/// <inheritdoc />
public void OnEndTurn(IScriptSource owner, IBattle battle)

View File

@@ -1,7 +1,8 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "ingrain")]
public class IngrainEffect : Script, IScriptFailIncomingMove, IScriptOnEndTurn
public class IngrainEffect : Script, IScriptFailIncomingMove, IScriptOnEndTurn, IScriptPreventSelfSwitch,
IScriptPreventSelfRunAway
{
private readonly IPokemon _owner;
@@ -11,10 +12,10 @@ public class IngrainEffect : Script, IScriptFailIncomingMove, IScriptOnEndTurn
}
/// <inheritdoc />
public override void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = true;
public void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = true;
/// <inheritdoc />
public override void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = true;
public void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = true;
/// <inheritdoc />
public void OnEndTurn(IScriptSource owner, IBattle battle)

View File

@@ -1,7 +1,7 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "magma_storm")]
public class MagmaStormEffect : Script, IScriptOnEndTurn
public class MagmaStormEffect : Script, IScriptOnEndTurn, IScriptPreventSelfRunAway, IScriptPreventSelfSwitch
{
private readonly IPokemon _owner;
@@ -17,8 +17,8 @@ public class MagmaStormEffect : Script, IScriptOnEndTurn
}
/// <inheritdoc />
public override void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = true;
public void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = true;
/// <inheritdoc />
public override void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = true;
public void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = true;
}

View File

@@ -19,11 +19,11 @@ public class MeanLookEffectUser : Script
}
[Script(ScriptCategory.Pokemon, "mean_look_target")]
public class MeanLookEffectTarget : Script
public class MeanLookEffectTarget : Script, IScriptPreventSelfSwitch, IScriptPreventSelfRunAway
{
/// <inheritdoc />
public override void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = true;
public void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = true;
/// <inheritdoc />
public override void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = true;
public void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = true;
}

View File

@@ -3,7 +3,7 @@ using PkmnLib.Plugin.Gen7.Scripts.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "phantom_force")]
public class PhantomForceCharge : Script, IScriptForceTurnSelection
public class PhantomForceCharge : Script, IScriptForceTurnSelection, IScriptBlockIncomingHit
{
private readonly IPokemon _owner;
@@ -20,7 +20,7 @@ public class PhantomForceCharge : Script, IScriptForceTurnSelection
}
/// <inheritdoc />
public override void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
public void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
{
block = true;
}

View File

@@ -1,11 +1,11 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "powder")]
public class PowderEffect : Script
public class PowderEffect : Script, IScriptBlockOutgoingHit
{
/// <inheritdoc />
/// <inheritdoc />
public override void BlockOutgoingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
public void BlockOutgoingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
{
var hit = executingMove.GetHitData(target, hitIndex);
if (hit.Type?.Name == "fire")

View File

@@ -1,16 +1,16 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "prevent_foes_exit_effect")]
public class PreventFoesExitEffect : Script
public class PreventFoesExitEffect : Script, IScriptPreventOpponentSwitch, IScriptPreventOpponentRunAway
{
/// <inheritdoc />
public override void PreventOpponentSwitch(ISwitchChoice choice, ref bool prevent)
public void PreventOpponentSwitch(ISwitchChoice choice, ref bool prevent)
{
prevent = true;
}
/// <inheritdoc />
public override void PreventOpponentRunAway(IFleeChoice choice, ref bool prevent)
public void PreventOpponentRunAway(IFleeChoice choice, ref bool prevent)
{
prevent = true;
}

View File

@@ -1,10 +1,10 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "protect")]
public class ProtectionEffectScript : Script
public class ProtectionEffectScript : Script, IScriptBlockIncomingHit
{
/// <inheritdoc />
public override void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
public virtual void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
{
if (target.BattleData == null)
return;

View File

@@ -3,7 +3,7 @@ using PkmnLib.Dynamic.BattleFlow;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "pursuit")]
public class PursuitEffect : Script
public class PursuitEffect : Script, IScriptOnSwitchOut
{
private readonly IMoveChoice _choice;
@@ -13,7 +13,7 @@ public class PursuitEffect : Script
}
/// <inheritdoc />
public override void OnSwitchOut(IPokemon oldPokemon, byte position)
public void OnSwitchOut(IPokemon oldPokemon, byte position)
{
var battleData = oldPokemon.BattleData;
if (battleData == null)

View File

@@ -3,7 +3,7 @@ using PkmnLib.Plugin.Gen7.Scripts.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "shadow_force")]
public class ShadowForceCharge : Script, IScriptForceTurnSelection
public class ShadowForceCharge : Script, IScriptForceTurnSelection, IScriptBlockIncomingHit
{
private readonly IPokemon _owner;
@@ -20,7 +20,7 @@ public class ShadowForceCharge : Script, IScriptForceTurnSelection
}
/// <inheritdoc />
public override void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
public void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
{
block = true;
}

View File

@@ -1,19 +1,19 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "spider_web_effect")]
public class SpiderWebEffect : Script
public class SpiderWebEffect : Script, IScriptPreventOpponentRunAway, IScriptPreventOpponentSwitch
{
private HashSet<IPokemon> _targets = new();
/// <inheritdoc />
public override void PreventOpponentRunAway(IFleeChoice choice, ref bool prevent)
public void PreventOpponentRunAway(IFleeChoice choice, ref bool prevent)
{
if (_targets.Contains(choice.User))
prevent = true;
}
/// <inheritdoc />
public override void PreventOpponentSwitch(ISwitchChoice choice, ref bool prevent)
public void PreventOpponentSwitch(ISwitchChoice choice, ref bool prevent)
{
if (_targets.Contains(choice.User))
prevent = true;

View File

@@ -1,7 +1,7 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "stockpile_effect")]
public class StockpileEffect : Script
public class StockpileEffect : Script, IScriptStack
{
private IPokemon? _pokemon;
public int StockpileCount { get; set; } = 1;
@@ -21,7 +21,7 @@ public class StockpileEffect : Script
}
/// <inheritdoc />
public override void Stack()
public void Stack()
{
if (StockpileCount < 3)
{

View File

@@ -1,12 +1,12 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "substitute")]
public class SubstituteEffect(uint health) : Script
public class SubstituteEffect(uint health) : Script, IScriptBlockIncomingHit
{
private uint _health = health;
/// <inheritdoc />
public override void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
public void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
{
if (executingMove.UseMove.HasFlag("ignore-substitute"))
return;

View File

@@ -1,11 +1,11 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "thousand_waves")]
public class ThousandWavesEffect : Script
public class ThousandWavesEffect : Script, IScriptPreventSelfSwitch, IScriptPreventSelfRunAway
{
/// <inheritdoc />
public override void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = true;
public void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = true;
/// <inheritdoc />
public override void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = true;
public void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = true;
}

View File

@@ -1,7 +1,7 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "whirlpool")]
public class WhirlpoolEffect : Script, IScriptOnEndTurn
public class WhirlpoolEffect : Script, IScriptOnEndTurn, IScriptPreventOpponentRunAway, IScriptPreventOpponentSwitch
{
public record PokemonTurn
{
@@ -42,14 +42,14 @@ public class WhirlpoolEffect : Script, IScriptOnEndTurn
}
/// <inheritdoc />
public override void PreventOpponentRunAway(IFleeChoice choice, ref bool prevent)
public void PreventOpponentRunAway(IFleeChoice choice, ref bool prevent)
{
if (_targetedPokemon.Any(x => x.Pokemon == choice.User))
prevent = true;
}
/// <inheritdoc />
public override void PreventOpponentSwitch(ISwitchChoice choice, ref bool prevent)
public void PreventOpponentSwitch(ISwitchChoice choice, ref bool prevent)
{
if (_targetedPokemon.Any(x => x.Pokemon == choice.User))
prevent = true;