Finish script interface refactor
All checks were successful
Build / Build (push) Successful in 1m1s

This commit is contained in:
Deukhoofd 2025-07-06 10:27:56 +02:00
parent 83f6a183e3
commit 7c270a6d52
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
117 changed files with 669 additions and 648 deletions

View File

@ -19,7 +19,7 @@ public static class MoveTurnExecutor
var useMove = chosenMove.MoveData;
var moveDataName = useMove.Name;
moveChoice.RunScriptHookInterface<IScriptChangeMove>(x => x.ChangeMove(moveChoice, ref moveDataName));
moveChoice.RunScriptHook<IScriptChangeMove>(x => x.ChangeMove(moveChoice, ref moveDataName));
if (useMove.Name != moveDataName)
{
if (!battle.Library.StaticLibrary.Moves.TryGet(moveDataName, out useMove))
@ -46,12 +46,12 @@ public static class MoveTurnExecutor
moveChoice.Script.Clear();
}
}
moveChoice.RunScriptHook(x => x.OnBeforeMoveChoice(moveChoice));
moveChoice.RunScriptHook<IScriptOnBeforeMoveChoice>(x => x.OnBeforeMoveChoice(moveChoice));
var targetType = useMove.Target;
var targets =
TargetResolver.ResolveTargets(battle, moveChoice.TargetSide, moveChoice.TargetPosition, targetType);
moveChoice.RunScriptHookInterface<IScriptChangeTargets>(x => x.ChangeTargets(moveChoice, ref targets));
moveChoice.RunScriptHook<IScriptChangeTargets>(x => x.ChangeTargets(moveChoice, ref targets));
if (targets.Count == 0)
{
moveChoice.Fail();
@ -60,13 +60,11 @@ public static class MoveTurnExecutor
foreach (var target in targets.WhereNotNull())
{
target.RunScriptHookInterface<IScriptChangeIncomingTargets>(x =>
x.ChangeIncomingTargets(moveChoice, ref targets));
target.RunScriptHook<IScriptChangeIncomingTargets>(x => x.ChangeIncomingTargets(moveChoice, ref targets));
}
byte numberOfHits = 1;
moveChoice.RunScriptHookInterface<IScriptChangeNumberOfHits>(x =>
x.ChangeNumberOfHits(moveChoice, ref numberOfHits));
moveChoice.RunScriptHook<IScriptChangeNumberOfHits>(x => x.ChangeNumberOfHits(moveChoice, ref numberOfHits));
if (numberOfHits == 0)
{
return;
@ -77,18 +75,20 @@ public static class MoveTurnExecutor
battle.EventHook.Invoke(new MoveUseEvent(executingMove));
var prevented = false;
executingMove.RunScriptHookInterface<IScriptPreventMove>(x => x.PreventMove(executingMove, ref prevented));
executingMove.RunScriptHook<IScriptPreventMove>(x => x.PreventMove(executingMove, ref prevented));
if (prevented)
return;
byte ppUsed = 1;
executingMove.RunScriptHook(x => x.ModifyPPUsed(executingMove, ref ppUsed));
targets.WhereNotNull().RunScriptHook(x => x.ModifyPPUsedForIncomingMove(executingMove, ref ppUsed));
executingMove.RunScriptHook<IScriptModifyPPUsed>(x => x.ModifyPPUsed(executingMove, ref ppUsed));
targets.WhereNotNull()
.RunScriptHook<IScriptModifyPPUsedForIncomingMove>(x =>
x.ModifyPPUsedForIncomingMove(executingMove, ref ppUsed));
if (!executingMove.ChosenMove.TryUse(ppUsed))
return;
var failed = false;
executingMove.RunScriptHookInterface<IScriptFailMove>(x => x.FailMove(executingMove, ref failed));
executingMove.RunScriptHook<IScriptFailMove>(x => x.FailMove(executingMove, ref failed));
if (failed)
{
// TODO: fail handling
@ -111,16 +111,16 @@ public static class MoveTurnExecutor
public static void ExecuteMove(IExecutingMove executingMove)
{
var stopped = false;
executingMove.RunScriptHookInterface<IScriptStopBeforeMove>(x => x.StopBeforeMove(executingMove, ref stopped));
executingMove.RunScriptHook<IScriptStopBeforeMove>(x => x.StopBeforeMove(executingMove, ref stopped));
if (stopped)
return;
executingMove.RunScriptHookInterface<IScriptOnBeforeMove>(x => x.OnBeforeMove(executingMove));
executingMove.RunScriptHook<IScriptOnBeforeMove>(x => x.OnBeforeMove(executingMove));
foreach (var target in executingMove.Targets.WhereNotNull())
{
ExecuteMoveChoiceForTarget(executingMove.Battle, executingMove, target);
}
executingMove.RunScriptHookInterface<IScriptOnAfterMove>(x => x.OnAfterMove(executingMove));
executingMove.RunScriptHook<IScriptOnAfterMove>(x => x.OnAfterMove(executingMove));
}
private static readonly ThreadLocal<List<TypeIdentifier>> TypeListCache = new(() => []);
@ -128,8 +128,7 @@ public static class MoveTurnExecutor
private static void ExecuteMoveChoiceForTarget(IBattle battle, IExecutingMove executingMove, IPokemon target)
{
var failed = false;
target.RunScriptHookInterface<IScriptFailIncomingMove>(x =>
x.FailIncomingMove(executingMove, target, ref failed));
target.RunScriptHook<IScriptFailIncomingMove>(x => x.FailIncomingMove(executingMove, target, ref failed));
if (failed)
{
// TODO: fail handling
@ -137,7 +136,7 @@ public static class MoveTurnExecutor
}
var isInvulnerable = false;
target.RunScriptHookInterface<IScriptIsInvulnerableToMove>(x =>
target.RunScriptHook<IScriptIsInvulnerableToMove>(x =>
x.IsInvulnerableToMove(executingMove, target, ref isInvulnerable));
if (isInvulnerable)
{
@ -158,7 +157,7 @@ public static class MoveTurnExecutor
break;
var hitIndex = i;
executingMove.RunScriptHook(x => x.OnBeforeHit(executingMove, target, hitIndex));
executingMove.RunScriptHook<IScriptOnBeforeHit>(x => x.OnBeforeHit(executingMove, target, hitIndex));
var hitData = (HitData)executingMove.GetDataFromRawIndex(targetHitStat + i);
if (hitData.HasFailed)
break;
@ -166,11 +165,12 @@ public static class MoveTurnExecutor
var useMove = executingMove.UseMove;
var isContact = useMove.HasFlag("contact");
executingMove.RunScriptHook(x => x.ModifyIsContact(executingMove, target, hitIndex, ref isContact));
executingMove.RunScriptHook<IScriptModifyIsContact>(x =>
x.ModifyIsContact(executingMove, target, hitIndex, ref isContact));
hitData.IsContact = isContact;
var hitType = (TypeIdentifier?)useMove.MoveType;
executingMove.RunScriptHookInterface<IScriptChangeMoveType>(x =>
executingMove.RunScriptHook<IScriptChangeMoveType>(x =>
x.ChangeMoveType(executingMove, target, hitIndex, ref hitType));
hitData.Type = hitType;
@ -180,22 +180,24 @@ public static class MoveTurnExecutor
types.Clear();
types.AddRange(target.Types);
executingMove.RunScriptHook(x => x.ChangeTypesForMove(executingMove, target, hitIndex, types));
target.RunScriptHook(x => x.ChangeTypesForIncomingMove(executingMove, target, hitIndex, types));
executingMove.RunScriptHook<IScriptChangeTypesForMove>(x =>
x.ChangeTypesForMove(executingMove, target, hitIndex, types));
target.RunScriptHook<IScriptChangeTypesForIncomingMove>(x =>
x.ChangeTypesForIncomingMove(executingMove, target, hitIndex, types));
var effectiveness = hitType == null
? 1
: battle.Library.StaticLibrary.Types.GetEffectiveness(hitType.Value, types);
executingMove.RunScriptHookInterface<IScriptChangeEffectiveness>(x =>
executingMove.RunScriptHook<IScriptChangeEffectiveness>(x =>
x.ChangeEffectiveness(executingMove, target, hitIndex, ref effectiveness));
target.RunScriptHookInterface<IScriptChangeIncomingEffectiveness>(x =>
target.RunScriptHook<IScriptChangeIncomingEffectiveness>(x =>
x.ChangeIncomingEffectiveness(executingMove, target, hitIndex, ref effectiveness));
hitData.Effectiveness = effectiveness;
var blockCritical = false;
executingMove.RunScriptHookInterface<IScriptBlockCriticalHit>(x =>
executingMove.RunScriptHook<IScriptBlockCriticalHit>(x =>
x.BlockCriticalHit(executingMove, target, hitIndex, ref blockCritical));
target.RunScriptHookInterface<IScriptBlockIncomingCriticalHit>(x =>
target.RunScriptHook<IScriptBlockIncomingCriticalHit>(x =>
x.BlockIncomingCriticalHit(executingMove, target, hitIndex, ref blockCritical));
if (!blockCritical)
{
@ -220,22 +222,23 @@ public static class MoveTurnExecutor
if (accuracy < 100 && battle.Random.GetInt(100) >= accuracy)
{
executingMove.RunScriptHookInterface<IScriptOnMoveMiss>(x => x.OnMoveMiss(executingMove, target));
executingMove.RunScriptHook<IScriptOnMoveMiss>(x => x.OnMoveMiss(executingMove, target));
battle.EventHook.Invoke(new MoveMissEvent(executingMove));
break;
}
var blockIncomingHit = false;
target.RunScriptHookInterface<IScriptBlockIncomingHit>(x =>
target.RunScriptHook<IScriptBlockIncomingHit>(x =>
x.BlockIncomingHit(executingMove, target, hitIndex, ref blockIncomingHit));
executingMove.RunScriptHookInterface<IScriptBlockOutgoingHit>(x =>
executingMove.RunScriptHook<IScriptBlockOutgoingHit>(x =>
x.BlockOutgoingHit(executingMove, target, hitIndex, ref blockIncomingHit));
if (blockIncomingHit)
break;
if (executingMove.GetHitData(target, hitIndex).HasFailed)
break;
var category = useMove.Category;
executingMove.RunScriptHook(x => x.ChangeCategory(executingMove, target, hitIndex, ref category));
executingMove.RunScriptHook<IScriptChangeCategory>(x =>
x.ChangeCategory(executingMove, target, hitIndex, ref category));
if (category == MoveCategory.Status)
{
var secondaryEffect = useMove.SecondaryEffect;
@ -244,7 +247,7 @@ public static class MoveTurnExecutor
var chance = secondaryEffect.Chance;
if (chance < 0 || battle.Random.EffectChance(chance, executingMove, target, hitIndex))
{
executingMove.RunScriptHookInterface<IScriptOnSecondaryEffect>(x =>
executingMove.RunScriptHook<IScriptOnSecondaryEffect>(x =>
x.OnSecondaryEffect(executingMove, target, hitIndex));
}
}
@ -268,12 +271,12 @@ public static class MoveTurnExecutor
target.Damage(damage, DamageSource.MoveDamage, hitEventBatch);
if (!target.IsFainted)
{
target.RunScriptHookInterface<IScriptOnIncomingHit>(x =>
target.RunScriptHook<IScriptOnIncomingHit>(x =>
x.OnIncomingHit(executingMove, target, hitIndex));
}
else
{
executingMove.RunScriptHookInterface<IScriptOnOpponentFaints>(x =>
executingMove.RunScriptHook<IScriptOnOpponentFaints>(x =>
x.OnOpponentFaints(executingMove, target, hitIndex));
}
@ -283,9 +286,9 @@ public static class MoveTurnExecutor
if (secondaryEffect != null)
{
var preventSecondary = false;
executingMove.RunScriptHookInterface<IScriptPreventSecondaryEffect>(x =>
executingMove.RunScriptHook<IScriptPreventSecondaryEffect>(x =>
x.PreventSecondaryEffect(executingMove, target, hitIndex, ref preventSecondary));
target.RunScriptHookInterface<IScriptPreventIncomingSecondaryEffect>(x =>
target.RunScriptHook<IScriptPreventIncomingSecondaryEffect>(x =>
x.PreventIncomingSecondaryEffect(executingMove, target, hitIndex,
ref preventSecondary));
@ -294,14 +297,14 @@ public static class MoveTurnExecutor
var chance = secondaryEffect.Chance;
if (chance < 0 || battle.Random.EffectChance(chance, executingMove, target, hitIndex))
{
executingMove.RunScriptHookInterface<IScriptOnSecondaryEffect>(x =>
executingMove.RunScriptHook<IScriptOnSecondaryEffect>(x =>
x.OnSecondaryEffect(executingMove, target, hitIndex));
}
}
}
if (target.IsFainted)
{
executingMove.RunScriptHookInterface<IScriptOnOpponentFaints>(x =>
executingMove.RunScriptHook<IScriptOnOpponentFaints>(x =>
x.OnOpponentFaints(executingMove, target, hitIndex));
}
}
@ -311,13 +314,13 @@ public static class MoveTurnExecutor
if (numberOfHits == 0)
{
target.RunScriptHookInterface<IScriptOnMoveMiss>(x => x.OnMoveMiss(executingMove, target));
target.RunScriptHook<IScriptOnMoveMiss>(x => x.OnMoveMiss(executingMove, target));
battle.EventHook.Invoke(new MoveMissEvent(executingMove));
}
if (!executingMove.User.IsFainted)
{
executingMove.RunScriptHookInterface<IScriptOnAfterHits>(x => x.OnAfterHits(executingMove, target));
executingMove.RunScriptHook<IScriptOnAfterHits>(x => x.OnAfterHits(executingMove, target));
}
}
}

View File

@ -31,7 +31,7 @@ public static class TurnRunner
// they can then know this later on.)
foreach (var choice in queue.GetChoices().WhereNotNull())
{
choice.RunScriptHookInterface<IScriptOnBeforeTurnStart>(script => script.OnBeforeTurnStart(choice));
choice.RunScriptHook<IScriptOnBeforeTurnStart>(script => script.OnBeforeTurnStart(choice));
}
// Now we can properly begin executing choices.
@ -60,15 +60,15 @@ public static class TurnRunner
{
scripts.Clear();
pokemon.GetOwnScripts(scripts);
scripts.RunScriptHookInterface<IScriptOnEndTurn>(x => x.OnEndTurn(pokemon, battle));
scripts.RunScriptHook<IScriptOnEndTurn>(x => x.OnEndTurn(pokemon, battle));
}
scripts.Clear();
side.GetOwnScripts(scripts);
scripts.RunScriptHookInterface<IScriptOnEndTurn>(x => x.OnEndTurn(side, battle));
scripts.RunScriptHook<IScriptOnEndTurn>(x => x.OnEndTurn(side, battle));
}
scripts.Clear();
battle.GetOwnScripts(scripts);
scripts.RunScriptHookInterface<IScriptOnEndTurn>(x => x.OnEndTurn(battle, battle));
scripts.RunScriptHook<IScriptOnEndTurn>(x => x.OnEndTurn(battle, battle));
}
}
@ -77,7 +77,7 @@ public static class TurnRunner
/// </summary>
public static void ExecuteChoice(IBattle battle, ITurnChoice choice)
{
choice.RunScriptHook(x => x.ChangeTurnChoice(ref choice));
choice.RunScriptHook<IScriptChangeTurnChoice>(x => x.ChangeTurnChoice(ref choice));
if (choice is IPassChoice)
return;
if (battle.HasEnded)
@ -90,7 +90,7 @@ public static class TurnRunner
{
case IMoveChoice moveChoice:
MoveTurnExecutor.ExecuteMoveChoice(battle, moveChoice);
moveChoice.RunScriptHook(script => script.OnAfterMoveChoice(moveChoice));
moveChoice.RunScriptHook<IScriptOnAfterMoveChoice>(script => script.OnAfterMoveChoice(moveChoice));
break;
case ISwitchChoice switchChoice:
ExecuteSwitchChoice(battle, switchChoice);
@ -111,7 +111,7 @@ public static class TurnRunner
if (battleData == null)
return;
var preventSwitch = false;
fleeChoice.RunScriptHookInterface<IScriptPreventSelfSwitch>(script =>
fleeChoice.RunScriptHook<IScriptPreventSelfSwitch>(script =>
script.PreventSelfSwitch(fleeChoice, ref preventSwitch));
if (preventSwitch)
return;
@ -121,7 +121,7 @@ public static class TurnRunner
continue;
foreach (var pokemon in side.Pokemon.WhereNotNull())
{
pokemon.RunScriptHookInterface<IScriptPreventOpponentSwitch>(script =>
pokemon.RunScriptHook<IScriptPreventOpponentSwitch>(script =>
script.PreventOpponentSwitch(fleeChoice, ref preventSwitch));
if (preventSwitch)
return;
@ -142,7 +142,7 @@ public static class TurnRunner
return;
var preventFlee = false;
fleeChoice.RunScriptHookInterface<IScriptPreventSelfRunAway>(script =>
fleeChoice.RunScriptHook<IScriptPreventSelfRunAway>(script =>
script.PreventSelfRunAway(fleeChoice, ref preventFlee));
if (preventFlee)
return;
@ -153,7 +153,7 @@ public static class TurnRunner
continue;
foreach (var pokemon in side.Pokemon.WhereNotNull())
{
pokemon.RunScriptHookInterface<IScriptPreventOpponentRunAway>(script =>
pokemon.RunScriptHook<IScriptPreventOpponentRunAway>(script =>
script.PreventOpponentRunAway(fleeChoice, ref preventFlee));
if (preventFlee)
return;

View File

@ -311,7 +311,7 @@ public class BattleImpl : ScriptSource, IBattle
}
ITurnChoice? forcedChoice = null;
pokemon.RunScriptHookInterface<IScriptForceTurnSelection>(script =>
pokemon.RunScriptHook<IScriptForceTurnSelection>(script =>
script.ForceTurnSelection(this, battleData.SideIndex, battleData.Position, ref forcedChoice));
choice = forcedChoice;
return choice != null;
@ -336,7 +336,7 @@ public class BattleImpl : ScriptSource, IBattle
moveChoice.ChosenMove.MoveData.Target, moveChoice.User))
return false;
var preventMove = false;
choice.RunScriptHookInterface<IScriptPreventMoveSelection>(script =>
choice.RunScriptHook<IScriptPreventMoveSelection>(script =>
script.PreventMoveSelection(moveChoice, ref preventMove));
if (preventMove)
return false;
@ -394,13 +394,13 @@ public class BattleImpl : ScriptSource, IBattle
if (choice is IMoveChoice moveChoice)
{
var priority = moveChoice.ChosenMove.MoveData.Priority;
choice.RunScriptHookInterface<IScriptChangePriority>(script =>
choice.RunScriptHook<IScriptChangePriority>(script =>
script.ChangePriority(moveChoice, ref priority));
moveChoice.Priority = priority;
}
var speed = choice.User.BoostedStats.Speed;
choice.RunScriptHookInterface<IScriptChangeSpeed>(script => script.ChangeSpeed(choice, ref speed));
choice.RunScriptHook<IScriptChangeSpeed>(script => script.ChangeSpeed(choice, ref speed));
choice.Speed = speed;
choice.RandomValue = (uint)Random.GetInt();
@ -434,7 +434,8 @@ public class BattleImpl : ScriptSource, IBattle
public bool SetWeather(StringKey? weatherName, int duration, EventBatchId batchId = default)
{
var preventWeatherChange = false;
this.RunScriptHook(x => x.PreventWeatherChange(weatherName, ref preventWeatherChange));
this.RunScriptHook<IScriptPreventWeatherChange>(x =>
x.PreventWeatherChange(weatherName, ref preventWeatherChange));
if (preventWeatherChange)
return false;
@ -446,7 +447,8 @@ public class BattleImpl : ScriptSource, IBattle
// Extend duration of existing weather
if (_weatherScript.Script is ILimitedTurnsScript existingWeatherScript)
{
this.RunScriptHook(x => x.ChangeWeatherDuration(weatherName.Value, ref duration));
this.RunScriptHook<IScriptChangeWeatherDuration>(x =>
x.ChangeWeatherDuration(weatherName.Value, ref duration));
if (duration < existingWeatherScript.TurnsRemaining)
return true;
existingWeatherScript.SetTurns(duration);
@ -458,7 +460,8 @@ public class BattleImpl : ScriptSource, IBattle
if (script is ILimitedTurnsScript weatherScript)
{
this.RunScriptHook(x => x.ChangeWeatherDuration(weatherName.Value, ref duration));
this.RunScriptHook<IScriptChangeWeatherDuration>(x =>
x.ChangeWeatherDuration(weatherName.Value, ref duration));
weatherScript.SetTurns(duration);
}
@ -474,7 +477,7 @@ public class BattleImpl : ScriptSource, IBattle
BatchId = batchId,
});
Sides.SelectMany(x => x.Pokemon).WhereNotNull()
.RunScriptHook(x => x.OnWeatherChange(this, weatherName, oldWeatherName));
.RunScriptHook<IScriptOnWeatherChange>(x => x.OnWeatherChange(this, weatherName, oldWeatherName));
return true;
}

View File

@ -72,7 +72,7 @@ public class BattleChoiceQueue : IDeepCloneable
continue;
// Ensure that the speed is up to date
var speed = choice.User.BoostedStats.Speed;
choice.User.RunScriptHookInterface<IScriptChangeSpeed>(script => script.ChangeSpeed(choice, ref speed));
choice.User.RunScriptHook<IScriptChangeSpeed>(script => script.ChangeSpeed(choice, ref speed));
choice.Speed = speed;
}

View File

@ -38,9 +38,9 @@ public class BattleRandomImpl : RandomImpl, IBattleRandom
/// <inheritdoc />
public bool EffectChance(float chance, IExecutingMove executingMove, IPokemon target, byte hitNumber)
{
executingMove.RunScriptHookInterface<IScriptChangeEffectChance>(script =>
executingMove.RunScriptHook<IScriptChangeEffectChance>(script =>
script.ChangeEffectChance(executingMove, target, hitNumber, ref chance));
target.RunScriptHookInterface<IScriptChangeIncomingEffectChance>(script =>
target.RunScriptHook<IScriptChangeIncomingEffectChance>(script =>
script.ChangeIncomingEffectChance(executingMove, target, hitNumber, ref chance));
if (chance > 100.0)
return true;

View File

@ -248,7 +248,7 @@ public class BattleSideImpl : ScriptSource, IBattleSide
var pokemon = _pokemon[index];
if (pokemon is not null)
{
pokemon.RunScriptHook(script => script.OnRemove());
pokemon.RunScriptHook<IScriptOnRemove>(script => script.OnRemove());
pokemon.SetOnBattlefield(false);
}
@ -261,8 +261,8 @@ public class BattleSideImpl : ScriptSource, IBattleSide
var oldPokemon = _pokemon[position];
if (oldPokemon is not null)
{
oldPokemon.RunScriptHookInterface<IScriptOnSwitchOut>(script => script.OnSwitchOut(oldPokemon, position));
oldPokemon.RunScriptHook(script => script.OnRemove());
oldPokemon.RunScriptHook<IScriptOnSwitchOut>(script => script.OnSwitchOut(oldPokemon, position));
oldPokemon.RunScriptHook<IScriptOnRemove>(script => script.OnRemove());
oldPokemon.SetOnBattlefield(false);
}
_pokemon[position] = pokemon;
@ -272,7 +272,7 @@ public class BattleSideImpl : ScriptSource, IBattleSide
pokemon.SetOnBattlefield(true);
pokemon.SetBattleSidePosition(position);
Battle.EventHook.Invoke(new SwitchEvent(Index, position, pokemon));
pokemon.RunScriptHookInterface<IScriptOnSwitchIn>(script => script.OnSwitchIn(pokemon, position));
pokemon.RunScriptHook<IScriptOnSwitchIn>(script => script.OnSwitchIn(pokemon, position));
foreach (var side in Battle.Sides)
{
@ -286,11 +286,10 @@ public class BattleSideImpl : ScriptSource, IBattleSide
scripts.Clear();
opponent.GetOwnScripts(scripts);
opponent.RunScriptHookInterface<IScriptOnOpponentSwitchIn>(script =>
opponent.RunScriptHook<IScriptOnOpponentSwitchIn>(script =>
script.OnOpponentSwitchIn(pokemon, position));
}
side.RunScriptHookInterface<IScriptOnOpponentSwitchIn>(script =>
script.OnOpponentSwitchIn(pokemon, position));
side.RunScriptHook<IScriptOnOpponentSwitchIn>(script => script.OnOpponentSwitchIn(pokemon, position));
}
}
else

View File

@ -684,7 +684,7 @@ public class PokemonImpl : ScriptSource, IPokemon
var weight = Form.Weight;
if (BattleData is not null)
// ReSharper disable once AccessToModifiedClosure
this.RunScriptHook(script => script.ModifyWeight(ref weight));
this.RunScriptHook<IScriptModifyWeight>(script => script.ModifyWeight(ref weight));
if (weight < 0.1f)
weight = 0.1f;
return weight;
@ -793,7 +793,7 @@ public class PokemonImpl : ScriptSource, IPokemon
{
var previous = HeldItem;
HeldItem = item;
this.RunScriptHook(x => x.OnAfterHeldItemChange(this, previous, item));
this.RunScriptHook<IScriptOnAfterHeldItemChange>(x => x.OnAfterHeldItemChange(this, previous, item));
return previous;
}
@ -809,7 +809,7 @@ public class PokemonImpl : ScriptSource, IPokemon
}
var previous = HeldItem;
HeldItem = null;
this.RunScriptHook(x => x.OnAfterHeldItemChange(this, previous, null));
this.RunScriptHook<IScriptOnAfterHeldItemChange>(x => x.OnAfterHeldItemChange(this, previous, null));
return previous;
}
@ -833,7 +833,8 @@ public class PokemonImpl : ScriptSource, IPokemon
return false;
}
var prevent = false;
this.RunScriptHook(script => script.PreventHeldItemSteal(this, HeldItem, ref prevent));
this.RunScriptHook<IScriptPreventHeldItemSteal>(script =>
script.PreventHeldItemSteal(this, HeldItem, ref prevent));
if (prevent)
{
item = null;
@ -861,7 +862,7 @@ public class PokemonImpl : ScriptSource, IPokemon
if (BattleData != null)
{
var prevented = false;
this.RunScriptHookInterface<IScriptPreventHeldItemConsume>(script =>
this.RunScriptHook<IScriptPreventHeldItemConsume>(script =>
script.PreventHeldItemConsume(this, HeldItem, ref prevented));
if (prevented)
return false;
@ -880,7 +881,7 @@ public class PokemonImpl : ScriptSource, IPokemon
{
// TODO: actually consume the item
this.RunScriptHookInterface<IScriptOnAfterItemConsume>(x => x.OnAfterItemConsume(this, item));
this.RunScriptHook<IScriptOnAfterItemConsume>(x => x.OnAfterItemConsume(this, item));
}
/// <inheritdoc />
@ -890,11 +891,11 @@ public class PokemonImpl : ScriptSource, IPokemon
if (!force)
{
var prevented = false;
this.RunScriptHookInterface<IScriptPreventStatBoostChange>(script =>
this.RunScriptHook<IScriptPreventStatBoostChange>(script =>
script.PreventStatBoostChange(this, stat, change, selfInflicted, ref prevented));
if (prevented)
return false;
this.RunScriptHookInterface<IScriptChangeStatBoostChange>(script =>
this.RunScriptHook<IScriptChangeStatBoostChange>(script =>
script.ChangeStatBoostChange(this, stat, selfInflicted, ref change));
if (change == 0)
return false;
@ -919,7 +920,7 @@ public class PokemonImpl : ScriptSource, IPokemon
}
RecalculateBoostedStats();
this.RunScriptHookInterface<IScriptOnAfterStatBoostChange>(script =>
this.RunScriptHook<IScriptOnAfterStatBoostChange>(script =>
script.OnAfterStatBoostChange(this, stat, selfInflicted, change));
return true;
}
@ -1075,7 +1076,7 @@ public class PokemonImpl : ScriptSource, IPokemon
if (BattleData is not null && !forceDamage)
{
var dmg = damage;
this.RunScriptHookInterface<IScriptChangeIncomingDamage>(script =>
this.RunScriptHook<IScriptChangeIncomingDamage>(script =>
script.ChangeIncomingDamage(this, source, ref dmg));
damage = dmg;
}
@ -1096,8 +1097,7 @@ public class PokemonImpl : ScriptSource, IPokemon
BatchId = batchId,
});
// And allow scripts to execute.
this.RunScriptHookInterface<IScriptOnDamage>(script =>
script.OnDamage(this, source, CurrentHealth, newHealth));
this.RunScriptHook<IScriptOnDamage>(script => script.OnDamage(this, source, CurrentHealth, newHealth));
}
CurrentHealth = newHealth;
@ -1126,14 +1126,14 @@ public class PokemonImpl : ScriptSource, IPokemon
BattleData.Battle.EventHook.Invoke(new FaintEvent(this));
// Allow scripts to trigger based on the faint.
this.RunScriptHookInterface<IScriptOnFaint>(script => script.OnFaint(this, source));
this.RunScriptHook<IScriptOnFaint>(script => script.OnFaint(this, source));
foreach (var ally in BattleData.BattleSide.Pokemon.WhereNotNull().Where(x => x != this))
{
ally.RunScriptHookInterface<IScriptOnAllyFaint>(script => script.OnAllyFaint(ally, this));
ally.RunScriptHook<IScriptOnAllyFaint>(script => script.OnAllyFaint(ally, this));
}
// Make sure the OnRemove script is run.
this.RunScriptHook(script => script.OnRemove());
this.RunScriptHook<IScriptOnRemove>(script => script.OnRemove());
// Mark the position as unfillable if it can't be filled by any party.
if (!BattleData.Battle.CanSlotBeFilled(BattleData.SideIndex, BattleData.Position))
@ -1162,7 +1162,7 @@ public class PokemonImpl : ScriptSource, IPokemon
if (!forceHeal)
{
var prevented = false;
this.RunScriptHook(x => x.PreventHeal(this, heal, allowRevive, ref prevented));
this.RunScriptHook<IScriptPreventHeal>(x => x.PreventHeal(this, heal, allowRevive, ref prevented));
if (prevented)
return false;
}
@ -1226,7 +1226,8 @@ public class PokemonImpl : ScriptSource, IPokemon
var selfInflicted = originPokemon == this;
var preventStatus = false;
this.RunScriptHook(script => script.PreventStatusChange(this, status, selfInflicted, ref preventStatus));
this.RunScriptHook<IScriptPreventStatusChange>(script =>
script.PreventStatusChange(this, status, selfInflicted, ref preventStatus));
if (preventStatus)
return false;
@ -1236,7 +1237,8 @@ public class PokemonImpl : ScriptSource, IPokemon
{
BatchId = batchId,
});
this.RunScriptHook(script => script.OnAfterStatusChange(this, status, originPokemon));
this.RunScriptHook<IScriptOnAfterStatusChange>(script =>
script.OnAfterStatusChange(this, status, originPokemon));
return true;
}
@ -1375,7 +1377,7 @@ public class PokemonImpl : ScriptSource, IPokemon
get
{
var isFloating = Types.Any(x => x.Name == "flying");
this.RunScriptHook(x => x.IsFloating(this, ref isFloating));
this.RunScriptHook<IScriptIsFloating>(x => x.IsFloating(this, ref isFloating));
return isFloating;
}
}

View File

@ -14,7 +14,7 @@ namespace PkmnLib.Dynamic.ScriptHandling;
/// developer might require.
/// </summary>
[DebuggerDisplay("{Category} - {Name}")]
public abstract class Script : IDeepCloneable
public abstract class Script : IDeepCloneable, IScriptOnRemove
{
internal event Action<Script>? OnRemoveEvent;
@ -52,239 +52,17 @@ public abstract class Script : IDeepCloneable
public virtual void OnAddedToParent(IScriptSource source)
{
}
}
/// <summary>
/// This interface is used to allow scripts to run when they are removed from their owner.
/// </summary>
public interface IScriptOnRemove
{
/// <summary>
/// This function is triggered on a Pokemon and its parents when the given Pokemon gains experience,
/// and allows for changing this amount of experience.
/// This function is ran when this script stops being in effect, and is removed from its owner.
/// </summary>
public virtual void ChangeExperienceGained(IPokemon faintedPokemon, IPokemon winningPokemon, ref uint amount)
{
}
/// <summary>
/// This function is triggered on a Pokemon and its parents when the given Pokemon gains experience,
/// and allows for making the experience be shared across multiple Pokemon.
/// Amount is the modifier for how much experience is shared, with 1 being the default amount.
/// </summary>
public virtual void ShareExperience(IPokemon faintedPokemon, IPokemon winningPokemon, ref bool share,
ref float amount)
{
}
/// <summary>
/// This function is triggered on a battle and its parents when something attempts to change the
/// weather, and allows for blocking the weather change.
/// </summary>
public virtual void BlockWeatherChange(IBattle battle, ref bool block)
{
}
/// <summary>
/// This function is called when a Pokeball is thrown at a Pokemon, and allows modifying the catch
/// rate of this attempt. Pokeball modifier effects should be implemented here, as well as for
/// example status effects that change capture rates.
/// </summary>
public virtual void ChangeCatchRateBonus(IPokemon pokemon, IItem pokeball, ref byte modifier)
{
}
/// <summary>
/// Custom triggers for scripts. This allows scripts to run custom events that are not part of the
/// standard battle flow.
/// </summary>
/// <param name="eventName">
/// The name of the event that is triggered. This should be unique for each different event. Overriding scripts
/// should validate the event name is one they should handle.
/// </param>
/// <param name="args">
/// The parameters that are passed to the event.
/// </param>
public virtual void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
}
/// <summary>
/// This function allows a script to change the accuracy of a move used. The value for accuracy is in percentage.
/// A custom case goes when 255 is returned, in which case the entire accuracy check is skipped, and the move
/// will always hit.
/// </summary>
/// <param name="executingMove"></param>
/// <param name="target"></param>
/// <param name="hitIndex"></param>
/// <param name="modifiedAccuracy"></param>
public virtual void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref int modifiedAccuracy)
{
}
/// <summary>
/// This function allows a script to change the accuracy of a move that is incoming. The value for accuracy is in percentage.
/// A custom case goes when 255 is returned, in which case the entire accuracy check is skipped, and the move
/// will always hit.
/// </summary>
public virtual void ChangeIncomingAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref int modifiedAccuracy)
{
}
/// <summary>
/// This function allows a script to change the weather duration of a weather effect.
/// </summary>
public virtual void ChangeWeatherDuration(StringKey weatherName, ref int duration)
{
}
/// <summary>
/// This function allows a script to prevent a Pokemon from being healed.
/// </summary>
public virtual void PreventHeal(IPokemon pokemon, uint heal, bool allowRevive, ref bool prevented)
{
}
/// <summary>
/// This function allows a script to change the types a target has. Multiple types can be set, and will be used
/// for the effectiveness calculation.
/// </summary>
public virtual void ChangeTypesForMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
IList<TypeIdentifier> types)
{
}
/// <summary>
/// This function allows a script to change the types a Pokemon has for a move that's incoming. Multiple types can
/// be set, and will be used for the effectiveness calculation.
/// </summary>
public virtual void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
IList<TypeIdentifier> types)
{
}
/// <summary>
/// This function allows a script to change the handling of the move category. This is used for moves that
/// are sometimes a status move, and sometimes a damaging move, such as pollen puff.
/// </summary>
public virtual void ChangeCategory(IExecutingMove move, IPokemon target, byte hitIndex, ref MoveCategory category)
{
}
/// <summary>
/// Triggers first when we're about to hit a target.
/// </summary>
public virtual void OnBeforeHit(IExecutingMove move, IPokemon target, byte hitIndex)
{
}
/// <summary>
/// This function allows a script to prevent a Pokemon from being affected by a status condition.
/// </summary>
public virtual void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted,
ref bool preventStatus)
{
}
/// <summary>
/// This function triggers after a status condition has been applied to a Pokemon.
/// </summary>
public virtual void OnAfterStatusChange(IPokemon pokemon, StringKey status, IPokemon? originPokemon)
{
}
/// <summary>
/// This function allows a script to prevent a Pokémon from being affected by a volatile status condition.
/// </summary>
public virtual void PreventVolatileAdd(IScriptSource parent, Script script, ref bool preventVolatileAdd)
{
}
/// <summary>
/// This function allows a script to make the Pokémon it is attached to float. This is used for moves
/// such as levitate, and allows for moves such as earthquake to not hit the Pokémon.
/// </summary>
/// <param name="pokemon"></param>
/// <param name="isFloating"></param>
public virtual void IsFloating(IPokemon pokemon, ref bool isFloating)
{
}
/// <summary>
/// This function allows a script to prevent the weather from changing. This is used for abilities such as
/// Delta Stream, which prevent the weather from changing to anything other than strong winds.
/// </summary>
public virtual void PreventWeatherChange(StringKey? weatherName, ref bool preventWeatherChange)
{
}
/// <summary>
/// This function triggers when the weather changes.
/// </summary>
public virtual void OnWeatherChange(IBattle battle, StringKey? weatherName, StringKey? oldWeatherName)
{
}
/// <summary>
/// Modifies the weight of a Pokemon.
/// </summary>
/// <param name="weight">The weight in kilograms</param>
public virtual void ModifyWeight(ref float weight)
{
}
/// <summary>
/// Modifies whether a move is a contact move or not. This is used for abilities such as Long Reach.
/// </summary>
public virtual void ModifyIsContact(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref bool isContact)
{
}
/// <summary>
/// This function allows a script to prevent a held item from being stolen by an effect such as Thief or Covet.
/// </summary>
public virtual void PreventHeldItemSteal(IPokemon pokemon, IItem heldItem, ref bool prevent)
{
}
/// <summary>
/// This function allows a script to run after a held item has changed.
/// </summary>
public virtual void OnAfterHeldItemChange(IPokemon pokemon, IItem? previous, IItem? item)
{
}
/// <summary>
/// This function allows a script to modify the PP used by a move.
/// </summary>
public virtual void ModifyPPUsed(IExecutingMove executingMove, ref byte ppUsed)
{
}
/// <summary>
/// This function allows a script to modify the PP used by an incoming move. This is used for abilities such as Pressure.
/// </summary>
public virtual void ModifyPPUsedForIncomingMove(IExecutingMove executingMove, ref byte ppUsed)
{
}
/// <summary>
/// This function triggers just before a move choice is executed.
/// </summary>
public virtual void OnBeforeMoveChoice(IMoveChoice moveChoice)
{
}
/// <summary>
/// This function triggers after a move choice has been executed in its entirety.
/// </summary>
public virtual void OnAfterMoveChoice(IMoveChoice moveChoice)
{
}
/// <summary>
/// This function allows a script to change the turn choice that is made by a Pokemon.
/// </summary>
public virtual void ChangeTurnChoice(ref ITurnChoice choice)
{
}
void OnRemove();
}
/// <summary>
@ -1102,4 +880,328 @@ public interface IScriptChangeIncomingDamage
/// This function allows a script to change any kind of damage that is incoming.
/// </summary>
void ChangeIncomingDamage(IPokemon pokemon, DamageSource source, ref uint damage);
}
/// <summary>
/// This interface allows scripts to change the weather duration of a weather effect.
/// </summary>
public interface IScriptChangeWeatherDuration
{
/// <summary>
/// This function allows a script to change the weather duration of a weather effect.
/// </summary>
void ChangeWeatherDuration(StringKey weatherName, ref int duration);
}
/// <summary>
/// This interface allows scripts to prevent a Pokemon from being healed.
/// </summary>
public interface IScriptPreventHeal
{
/// <summary>
/// This function allows a script to prevent a Pokemon from being healed.
/// </summary>
void PreventHeal(IPokemon pokemon, uint heal, bool allowRevive, ref bool prevented);
}
/// <summary>
/// This interface allows scripts to change the types a target has for effectiveness calculation.
/// </summary>
public interface IScriptChangeTypesForMove
{
/// <summary>
/// This function allows a script to change the types a target has. Multiple types can be set, and will be used
/// for the effectiveness calculation.
/// </summary>
void ChangeTypesForMove(IExecutingMove executingMove, IPokemon target, byte hitIndex, IList<TypeIdentifier> types);
}
/// <summary>
/// This interface allows scripts to change the types a Pokemon has for incoming moves.
/// </summary>
public interface IScriptChangeTypesForIncomingMove
{
/// <summary>
/// This function allows a script to change the types a Pokemon has for a move that's incoming. Multiple types can
/// be set, and will be used for the effectiveness calculation.
/// </summary>
void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
IList<TypeIdentifier> types);
}
/// <summary>
/// This interface allows scripts to change the handling of the move category.
/// </summary>
public interface IScriptChangeCategory
{
/// <summary>
/// This function allows a script to change the handling of the move category. This is used for moves that
/// are sometimes a status move, and sometimes a damaging move, such as pollen puff.
/// </summary>
void ChangeCategory(IExecutingMove move, IPokemon target, byte hitIndex, ref MoveCategory category);
}
/// <summary>
/// This interface allows scripts to trigger when about to hit a target.
/// </summary>
public interface IScriptOnBeforeHit
{
/// <summary>
/// Triggers first when we're about to hit a target.
/// </summary>
void OnBeforeHit(IExecutingMove move, IPokemon target, byte hitIndex);
}
/// <summary>
/// This interface allows scripts to prevent a Pokemon from being affected by a status condition.
/// </summary>
public interface IScriptPreventStatusChange
{
/// <summary>
/// This function allows a script to prevent a Pokemon from being affected by a status condition.
/// </summary>
void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, ref bool preventStatus);
}
/// <summary>
/// This interface allows scripts to trigger after a status condition has been applied.
/// </summary>
public interface IScriptOnAfterStatusChange
{
/// <summary>
/// This function triggers after a status condition has been applied to a Pokemon.
/// </summary>
void OnAfterStatusChange(IPokemon pokemon, StringKey status, IPokemon? originPokemon);
}
/// <summary>
/// This interface allows scripts to prevent a Pokemon from being affected by a volatile status condition.
/// </summary>
public interface IScriptPreventVolatileAdd
{
/// <summary>
/// This function allows a script to prevent a Pokémon from being affected by a volatile status condition.
/// </summary>
void PreventVolatileAdd(IScriptSource parent, Script script, ref bool preventVolatileAdd);
}
/// <summary>
/// This interface allows scripts to make the Pokemon float.
/// </summary>
public interface IScriptIsFloating
{
/// <summary>
/// This function allows a script to make the Pokémon it is attached to float. This is used for moves
/// such as levitate, and allows for moves such as earthquake to not hit the Pokémon.
/// </summary>
void IsFloating(IPokemon pokemon, ref bool isFloating);
}
/// <summary>
/// This interface allows scripts to prevent weather from changing.
/// </summary>
public interface IScriptPreventWeatherChange
{
/// <summary>
/// This function allows a script to prevent the weather from changing. This is used for abilities such as
/// Delta Stream, which prevent the weather from changing to anything other than strong winds.
/// </summary>
void PreventWeatherChange(StringKey? weatherName, ref bool preventWeatherChange);
}
/// <summary>
/// This interface allows scripts to trigger when the weather changes.
/// </summary>
public interface IScriptOnWeatherChange
{
/// <summary>
/// This function triggers when the weather changes.
/// </summary>
void OnWeatherChange(IBattle battle, StringKey? weatherName, StringKey? oldWeatherName);
}
/// <summary>
/// This interface allows scripts to modify the weight of a Pokemon.
/// </summary>
public interface IScriptModifyWeight
{
/// <summary>
/// Modifies the weight of a Pokemon.
/// </summary>
void ModifyWeight(ref float weight);
}
/// <summary>
/// This interface allows scripts to modify whether a move makes contact.
/// </summary>
public interface IScriptModifyIsContact
{
/// <summary>
/// Modifies whether a move is a contact move or not. This is used for abilities such as Long Reach.
/// </summary>
void ModifyIsContact(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool isContact);
}
/// <summary>
/// This interface allows scripts to prevent held item theft.
/// </summary>
public interface IScriptPreventHeldItemSteal
{
/// <summary>
/// This function allows a script to prevent a held item from being stolen by an effect such as Thief or Covet.
/// </summary>
void PreventHeldItemSteal(IPokemon pokemon, IItem heldItem, ref bool prevent);
}
/// <summary>
/// This interface allows scripts to trigger after held item changes.
/// </summary>
public interface IScriptOnAfterHeldItemChange
{
/// <summary>
/// This function allows a script to run after a held item has changed.
/// </summary>
void OnAfterHeldItemChange(IPokemon pokemon, IItem? previous, IItem? item);
}
/// <summary>
/// This interface allows scripts to modify the PP used by a move.
/// </summary>
public interface IScriptModifyPPUsed
{
/// <summary>
/// This function allows a script to modify the PP used by a move.
/// </summary>
void ModifyPPUsed(IExecutingMove executingMove, ref byte ppUsed);
}
/// <summary>
/// This interface allows scripts to modify the PP used by an incoming move.
/// </summary>
public interface IScriptModifyPPUsedForIncomingMove
{
/// <summary>
/// This function allows a script to modify the PP used by an incoming move. This is used for abilities such as Pressure.
/// </summary>
void ModifyPPUsedForIncomingMove(IExecutingMove executingMove, ref byte ppUsed);
}
/// <summary>
/// This interface allows scripts to trigger just before a move choice is executed.
/// </summary>
public interface IScriptOnBeforeMoveChoice
{
/// <summary>
/// This function triggers just before a move choice is executed.
/// </summary>
void OnBeforeMoveChoice(IMoveChoice moveChoice);
}
/// <summary>
/// This interface allows scripts to trigger after a move choice has been executed.
/// </summary>
public interface IScriptOnAfterMoveChoice
{
/// <summary>
/// This function triggers after a move choice has been executed in its entirety.
/// </summary>
void OnAfterMoveChoice(IMoveChoice moveChoice);
}
/// <summary>
/// This interface allows scripts to change the turn choice that is made by a Pokemon.
/// </summary>
public interface IScriptChangeTurnChoice
{
/// <summary>
/// This function allows a script to change the turn choice that is made by a Pokemon.
/// </summary>
void ChangeTurnChoice(ref ITurnChoice choice);
}
/// <summary>
/// This interface allows scripts to change the experience gained when a Pokemon faints.
/// </summary>
public interface IScriptChangeExperienceGained
{
/// <summary>
/// This function is triggered on a Pokemon and its parents when the given Pokemon gains experience,
/// and allows for changing this amount of experience.
/// </summary>
void ChangeExperienceGained(IPokemon faintedPokemon, IPokemon winningPokemon, ref uint amount);
}
/// <summary>
/// This interface allows scripts to share experience across multiple Pokemon.
/// </summary>
public interface IScriptShareExperience
{
/// <summary>
/// This function is triggered on a Pokemon and its parents when the given Pokemon gains experience,
/// and allows for making the experience be shared across multiple Pokemon.
/// Amount is the modifier for how much experience is shared, with 1 being the default amount.
/// </summary>
void ShareExperience(IPokemon faintedPokemon, IPokemon winningPokemon, ref bool share, ref float amount);
}
/// <summary>
/// This interface allows scripts to block weather changes.
/// </summary>
public interface IScriptBlockWeatherChange
{
/// <summary>
/// This function allows a script to block weather changes.
/// </summary>
void BlockWeatherChange(IBattle battle, ref bool block);
}
/// <summary>
/// This interface allows scripts to change the catch rate bonus when a Pokeball is thrown.
/// </summary>
public interface IScriptChangeCatchRateBonus
{
/// <summary>
/// This function is called when a Pokeball is thrown at a Pokemon, and allows modifying the catch
/// rate of this attempt. Pokeball modifier effects should be implemented here, as well as for
/// example status effects that change capture rates.
/// </summary>
void ChangeCatchRateBonus(IPokemon pokemon, IItem pokeball, ref byte modifier);
}
/// <summary>
/// This interface allows scripts to handle custom trigger events.
/// </summary>
public interface IScriptCustomTrigger
{
/// <summary>
/// Custom triggers for scripts. This allows scripts to run custom events that are not part of the
/// standard battle flow.
/// </summary>
void CustomTrigger(StringKey eventName, ICustomTriggerArgs args);
}
/// <summary>
/// This interface allows scripts to change the accuracy of a move.
/// </summary>
public interface IScriptChangeAccuracy
{
/// <summary>
/// This function allows a script to change the accuracy of a move used. The value for accuracy is in percentage.
/// A custom case goes when 255 is returned, in which case the entire accuracy check is skipped, and the move
/// will always hit.
/// </summary>
void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref int modifiedAccuracy);
}
/// <summary>
/// This interface allows scripts to change the accuracy of an incoming move.
/// </summary>
public interface IScriptChangeIncomingAccuracy
{
/// <summary>
/// This function allows a script to change the accuracy of a move that is incoming. The value for accuracy is in percentage.
/// A custom case goes when 255 is returned, in which case the entire accuracy check is skipped, and the move
/// will always hit.
/// </summary>
void ChangeIncomingAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref int modifiedAccuracy);
}

View File

@ -13,33 +13,7 @@ public static class ScriptExecution
/// <summary>
/// Executes a hook on all scripts in a source.
/// </summary>
public static void RunScriptHook(this IScriptSource source, Action<Script> hook)
{
var iterator = source.GetScripts();
List<ScriptCategory>? suppressedCategories = null;
foreach (var container in iterator)
{
if (container.IsEmpty)
continue;
var script = container.Script;
if (script is IScriptOnBeforeAnyHookInvoked onBeforeAnyHookInvoked)
onBeforeAnyHookInvoked.OnBeforeAnyHookInvoked(ref suppressedCategories);
}
foreach (var container in iterator)
{
if (container.IsEmpty)
continue;
var script = container.Script;
if (suppressedCategories != null && suppressedCategories.Contains(script.Category))
continue;
hook(script);
}
}
/// <summary>
/// Executes a hook on all scripts in a source.
/// </summary>
public static void RunScriptHookInterface<TScriptHook>(this IScriptSource source, Action<TScriptHook> hook)
public static void RunScriptHook<TScriptHook>(this IScriptSource source, Action<TScriptHook> hook)
{
var iterator = source.GetScripts();
List<ScriptCategory>? suppressedCategories = null;
@ -68,35 +42,7 @@ public static class ScriptExecution
/// Executes a hook on all scripts in a source.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void RunScriptHook(this IEnumerable<IScriptSource> sources, Action<Script> hook)
{
var iterator = sources.Distinct().SelectMany(x => x.GetScripts()).ToArray();
List<ScriptCategory>? suppressedCategories = null;
foreach (var container in iterator)
{
if (container.IsEmpty)
continue;
var script = container.Script;
if (script is IScriptOnBeforeAnyHookInvoked onBeforeAnyHookInvoked)
onBeforeAnyHookInvoked.OnBeforeAnyHookInvoked(ref suppressedCategories);
}
foreach (var container in iterator)
{
if (container.IsEmpty)
continue;
var script = container.Script;
if (suppressedCategories != null && suppressedCategories.Contains(script.Category))
continue;
hook(script);
}
}
/// <summary>
/// Executes a hook on all scripts in a source.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void RunScriptHookInterface<TScriptHook>(this IEnumerable<IScriptSource> sources,
Action<TScriptHook> hook)
public static void RunScriptHook<TScriptHook>(this IEnumerable<IScriptSource> sources, Action<TScriptHook> hook)
{
var iterator = sources.Distinct().SelectMany(x => x.GetScripts()).ToArray();
List<ScriptCategory>? suppressedCategories = null;
@ -125,33 +71,7 @@ public static class ScriptExecution
/// Executes a hook on all scripts in a list of sources. Note that this does not walk through the parents of the
/// sources, but only the sources themselves.
/// </summary>
public static void RunScriptHook(this IReadOnlyList<IEnumerable<ScriptContainer>> source, Action<Script> hook)
{
List<ScriptCategory>? suppressedCategories = null;
foreach (var container in source.SelectMany(x => x))
{
if (container.IsEmpty)
continue;
var script = container.Script;
if (script is IScriptOnBeforeAnyHookInvoked onBeforeAnyHookInvoked)
onBeforeAnyHookInvoked.OnBeforeAnyHookInvoked(ref suppressedCategories);
}
foreach (var container in source.SelectMany(x => x))
{
if (container.IsEmpty)
continue;
var script = container.Script;
if (suppressedCategories != null && suppressedCategories.Contains(script.Category))
continue;
hook(script);
}
}
/// <summary>
/// Executes a hook on all scripts in a list of sources. Note that this does not walk through the parents of the
/// sources, but only the sources themselves.
/// </summary>
public static void RunScriptHookInterface<TScriptHook>(this IReadOnlyList<IEnumerable<ScriptContainer>> source,
public static void RunScriptHook<TScriptHook>(this IReadOnlyList<IEnumerable<ScriptContainer>> source,
Action<TScriptHook> hook)
{
List<ScriptCategory>? suppressedCategories = null;

View File

@ -108,7 +108,8 @@ public class ScriptSet : IScriptSet
if (!forceAdd)
{
var preventVolatileAdd = false;
_source.RunScriptHook(x => x.PreventVolatileAdd(_source, script, ref preventVolatileAdd));
_source.RunScriptHook<IScriptPreventVolatileAdd>(x =>
x.PreventVolatileAdd(_source, script, ref preventVolatileAdd));
if (preventVolatileAdd)
return null;
}

View File

@ -52,19 +52,21 @@ public class Gen7BattleStatCalculator : IBattleStatCalculator
byte moveAccuracy)
{
var accuracyModifier = 1.0f;
executingMove.RunScriptHookInterface<IScriptChangeAccuracyModifier>(x =>
executingMove.RunScriptHook<IScriptChangeAccuracyModifier>(x =>
x.ChangeAccuracyModifier(executingMove, target, hitIndex, ref accuracyModifier));
var modifiedAccuracy = (int)(moveAccuracy * accuracyModifier);
// ReSharper disable once AccessToModifiedClosure
executingMove.RunScriptHook(x => x.ChangeAccuracy(executingMove, target, hitIndex, ref modifiedAccuracy));
executingMove.RunScriptHook<IScriptChangeAccuracy>(x =>
x.ChangeAccuracy(executingMove, target, hitIndex, ref modifiedAccuracy));
if (modifiedAccuracy >= 255)
return 255;
target.RunScriptHook(x => x.ChangeIncomingAccuracy(executingMove, target, hitIndex, ref modifiedAccuracy));
target.RunScriptHook<IScriptChangeIncomingAccuracy>(x =>
x.ChangeIncomingAccuracy(executingMove, target, hitIndex, ref modifiedAccuracy));
if (modifiedAccuracy >= 255)
return 255;
var targetEvasion = target.StatBoost.Evasion;
var ignoreEvasion = false;
executingMove.RunScriptHookInterface<IScriptBypassEvasionStatBoosts>(x =>
executingMove.RunScriptHook<IScriptBypassEvasionStatBoosts>(x =>
x.BypassEvasionStatBoosts(executingMove, target, hitIndex, ref ignoreEvasion));
if (ignoreEvasion)
targetEvasion = 0;

View File

@ -26,7 +26,8 @@ public class Gen7CaptureLibrary : ICaptureLibrary
}
byte bonusStatus = 1;
target.RunScriptHook(x => x.ChangeCatchRateBonus(target, captureItem, ref bonusStatus));
target.RunScriptHook<IScriptChangeCatchRateBonus>(x =>
x.ChangeCatchRateBonus(target, captureItem, ref bonusStatus));
var modifiedCatchRate = (3.0f * maxHealth - 2.0f * currentHealth) * catchRate * bonusBall / (3.0f * maxHealth);
modifiedCatchRate *= bonusStatus;

View File

@ -29,7 +29,7 @@ public class Gen7DamageCalculator(Gen7PluginConfiguration configuration) : IDama
if (hitData.IsCritical)
{
var critModifier = 1.5f;
executingMove?.RunScriptHookInterface<IScriptChangeCriticalModifier>(script =>
executingMove?.RunScriptHook<IScriptChangeCriticalModifier>(script =>
script.ChangeCriticalModifier(executingMove, target, hitNumber, ref critModifier));
floatDamage = MathF.Floor(floatDamage * critModifier);
}
@ -51,7 +51,7 @@ public class Gen7DamageCalculator(Gen7PluginConfiguration configuration) : IDama
stabModifier = 1.5f;
isStab = true;
}
executingMove?.RunScriptHookInterface<IScriptChangeStabModifier>(script =>
executingMove?.RunScriptHook<IScriptChangeStabModifier>(script =>
script.ChangeStabModifier(executingMove, target, hitNumber, isStab, ref stabModifier));
floatDamage = MathF.Floor(floatDamage * stabModifier);
@ -65,9 +65,9 @@ public class Gen7DamageCalculator(Gen7PluginConfiguration configuration) : IDama
if (executingMove is not null)
{
executingMove.RunScriptHookInterface<IScriptChangeMoveDamage>(script =>
executingMove.RunScriptHook<IScriptChangeMoveDamage>(script =>
script.ChangeMoveDamage(executingMove, target, hitNumber, ref damage));
target.RunScriptHookInterface<IScriptChangeIncomingMoveDamage>(script =>
target.RunScriptHook<IScriptChangeIncomingMoveDamage>(script =>
script.ChangeIncomingMoveDamage(executingMove, target, hitNumber, ref damage));
}
@ -80,7 +80,7 @@ public class Gen7DamageCalculator(Gen7PluginConfiguration configuration) : IDama
if (executingMove.UseMove.Category == MoveCategory.Status)
return 0;
var basePower = (ushort)executingMove.UseMove.BasePower;
executingMove.RunScriptHookInterface<IScriptChangeBasePower>(script =>
executingMove.RunScriptHook<IScriptChangeBasePower>(script =>
script.ChangeBasePower(executingMove, target, hitNumber, ref basePower));
return basePower;
}
@ -91,7 +91,7 @@ public class Gen7DamageCalculator(Gen7PluginConfiguration configuration) : IDama
if (executingMove.UseMove.Category == MoveCategory.Status)
return false;
byte critStage = 0;
executingMove.RunScriptHookInterface<IScriptChangeCriticalStage>(script =>
executingMove.RunScriptHook<IScriptChangeCriticalStage>(script =>
script.ChangeCriticalStage(executingMove, target, hitNumber, ref critStage));
var random = battle.Random;
@ -120,14 +120,14 @@ public class Gen7DamageCalculator(Gen7PluginConfiguration configuration) : IDama
// move is critical, and the target has a defensive stat boost of > 0, but a script is
// allowed to change this.
var bypassDefense = hitData.IsCritical && target.StatBoost.GetStatistic(defensive) > 0;
executingMove?.RunScriptHookInterface<IScriptBypassDefensiveStatBoosts>(script =>
executingMove?.RunScriptHook<IScriptBypassDefensiveStatBoosts>(script =>
script.BypassDefensiveStatBoosts(executingMove, target, hitNumber, ref bypassDefense));
// Check if we can bypass the offensive stat boost on the user. We default to this if the
// move is critical, and the user has an offensive stat boost of < 0, but a script is
// allowed to change this.
var bypassOffense = hitData.IsCritical && user.StatBoost.GetStatistic(offensive) < 0;
executingMove?.RunScriptHookInterface<IScriptBypassOffensiveStatBoosts>(script =>
executingMove?.RunScriptHook<IScriptBypassOffensiveStatBoosts>(script =>
script.BypassOffensiveStatBoosts(executingMove, target, hitNumber, ref bypassOffense));
var userStats = user.BoostedStats;
@ -143,22 +143,22 @@ public class Gen7DamageCalculator(Gen7PluginConfiguration configuration) : IDama
if (executingMove != null)
{
executingMove.RunScriptHookInterface<IScriptChangeOffensiveStatValue>(script =>
executingMove.RunScriptHook<IScriptChangeOffensiveStatValue>(script =>
script.ChangeOffensiveStatValue(executingMove, target, hitNumber, defensiveStat, targetStats, offensive,
ref offensiveStat));
executingMove.RunScriptHookInterface<IScriptChangeDefensiveStatValue>(script =>
executingMove.RunScriptHook<IScriptChangeDefensiveStatValue>(script =>
script.ChangeDefensiveStatValue(executingMove, target, hitNumber, origOffensiveStat, targetStats,
defensive, ref defensiveStat));
target.RunScriptHookInterface<IScriptChangeIncomingMoveOffensiveStatValue>(script =>
target.RunScriptHook<IScriptChangeIncomingMoveOffensiveStatValue>(script =>
script.ChangeIncomingMoveOffensiveStatValue(executingMove, target, hitNumber, defensiveStat,
targetStats, offensive, ref offensiveStat));
target.RunScriptHookInterface<IScriptChangeIncomingMoveDefensiveStatValue>(script =>
target.RunScriptHook<IScriptChangeIncomingMoveDefensiveStatValue>(script =>
script.ChangeIncomingMoveDefensiveStatValue(executingMove, target, hitNumber, origOffensiveStat,
targetStats, defensive, ref defensiveStat));
}
var modifier = (float)offensiveStat / defensiveStat;
executingMove?.RunScriptHookInterface<IScriptChangeDamageStatModifier>(script =>
executingMove?.RunScriptHook<IScriptChangeDamageStatModifier>(script =>
script.ChangeDamageStatModifier(executingMove, target, hitNumber, ref modifier));
return modifier;
@ -172,9 +172,9 @@ public class Gen7DamageCalculator(Gen7PluginConfiguration configuration) : IDama
{
var modifier = 1.0f;
executingMove.RunScriptHookInterface<IScriptChangeDamageModifier>(script =>
executingMove.RunScriptHook<IScriptChangeDamageModifier>(script =>
script.ChangeDamageModifier(executingMove, target, hitNumber, ref modifier));
target.RunScriptHookInterface<IScriptChangeIncomingMoveDamageModifier>(script =>
target.RunScriptHook<IScriptChangeIncomingMoveDamageModifier>(script =>
script.ChangeIncomingMoveDamageModifier(executingMove, target, hitNumber, ref modifier));
return modifier;

View File

@ -7,10 +7,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Aura_Break_(Ability)">Bulbapedia - Aura Break</see>
/// </summary>
[Script(ScriptCategory.Ability, "aura_break")]
public class AuraBreak : Script
public class AuraBreak : Script, IScriptCustomTrigger
{
/// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName != CustomTriggers.ModifyAuraEffect || args is not CustomTriggers.ModifyAuraEffectArgs auraArgs)
return;

View File

@ -8,11 +8,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Comatose_(Ability)">Bulbapedia - Comatose</see>
/// </summary>
[Script(ScriptCategory.Ability, "comatose")]
public class Comatose : Script
public class Comatose : Script, IScriptPreventStatusChange, IScriptCustomTrigger
{
/// <inheritdoc />
public override void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted,
ref bool preventStatus)
public void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, ref bool preventStatus)
{
if (status == ScriptUtils.ResolveName<Status.Sleep>())
{
@ -21,7 +20,7 @@ public class Comatose : Script
}
/// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName == CustomTriggers.BypassSleep && args is CustomTriggers.BypassSleepArgs bypassArgs)
{

View File

@ -7,10 +7,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Compound_Eyes_(Ability)">Bulbapedia - Compound Eyes</see>
/// </summary>
[Script(ScriptCategory.Ability, "compound_eyes")]
public class CompoundEyes : Script
public class CompoundEyes : Script, IScriptChangeAccuracy
{
/// <inheritdoc />
public override void ChangeAccuracy(IExecutingMove move, IPokemon target, byte hit, ref int modifiedAccuracy)
public void ChangeAccuracy(IExecutingMove move, IPokemon target, byte hit, ref int modifiedAccuracy)
{
move.Battle.EventHook.Invoke(new AbilityTriggerEvent(move.User));
modifiedAccuracy = (int)(modifiedAccuracy * 1.3f);

View File

@ -17,7 +17,7 @@ public class DarkAura : Script, IScriptChangeDamageModifier
var auraModifier = 5448f / 4096f;
var args = new CustomTriggers.ModifyAuraEffectArgs(move, target, hit, auraModifier);
move.Battle.Sides.SelectMany(side => side.Pokemon).WhereNotNull()
.RunScriptHook(x => x.CustomTrigger(CustomTriggers.ModifyAuraEffect, args));
.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.ModifyAuraEffect, args));
auraModifier = args.AuraEffect;
modifier *= auraModifier;
move.Battle.EventHook.Invoke(new AbilityTriggerEvent(move.User));

View File

@ -8,10 +8,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Early_Bird_(Ability)">Bulbapedia - Early Bird</see>
/// </summary>
[Script(ScriptCategory.Ability, "early_bird")]
public class EarlyBird : Script
public class EarlyBird : Script, IScriptCustomTrigger
{
/// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName != CustomTriggers.ModifySleepTurns)
return;

View File

@ -18,7 +18,7 @@ public class FairyAura : Script, IScriptChangeDamageModifier
var auraModifier = 5448f / 4096f;
var args = new CustomTriggers.ModifyAuraEffectArgs(move, target, hit, auraModifier);
move.Battle.Sides.SelectMany(side => side.Pokemon).WhereNotNull()
.RunScriptHook(x => x.CustomTrigger(CustomTriggers.ModifyAuraEffect, args));
.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.ModifyAuraEffect, args));
auraModifier = args.AuraEffect;
modifier *= auraModifier;
move.Battle.EventHook.Invoke(new AbilityTriggerEvent(move.User));

View File

@ -7,7 +7,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Flower_Gift_(Ability)">Bulbapedia - Flower Gift</see>
/// </summary>
[Script(ScriptCategory.Ability, "flower_gift")]
public class FlowerGift : Script
public class FlowerGift : Script, IScriptOnWeatherChange
{
private IPokemon? _pokemon;
@ -22,7 +22,7 @@ public class FlowerGift : Script
}
/// <inheritdoc />
public override void OnWeatherChange(IBattle battle, StringKey? weatherName, StringKey? oldWeatherName)
public void OnWeatherChange(IBattle battle, StringKey? weatherName, StringKey? oldWeatherName)
{
if (_pokemon is null)
return;

View File

@ -7,7 +7,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Forecast_(Ability)">Bulbapedia - Forecast</see>
/// </summary>
[Script(ScriptCategory.Ability, "forecast")]
public class Forecast : Script, IScriptOnSwitchIn
public class Forecast : Script, IScriptOnSwitchIn, IScriptOnWeatherChange
{
private IPokemon? _pokemon;
@ -26,7 +26,7 @@ public class Forecast : Script, IScriptOnSwitchIn
}
/// <inheritdoc />
public override void OnWeatherChange(IBattle battle, StringKey? weatherName, StringKey? oldWeatherName)
public void OnWeatherChange(IBattle battle, StringKey? weatherName, StringKey? oldWeatherName)
{
if (_pokemon is null)
return;

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Heavy_Metal_(Ability)">Bulbapedia - Heavy Metal</see>
/// </summary>
[Script(ScriptCategory.Ability, "heavy_metal")]
public class HeavyMetal : Script
public class HeavyMetal : Script, IScriptModifyWeight
{
/// <inheritdoc />
public override void ModifyWeight(ref float weight)
public void ModifyWeight(ref float weight)
{
weight *= 2f;
}

View File

@ -8,7 +8,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Hustle_(Ability)">Bulbapedia - Hustle</see>
/// </summary>
[Script(ScriptCategory.Ability, "hustle")]
public class Hustle : Script, IScriptChangeOffensiveStatValue
public class Hustle : Script, IScriptChangeOffensiveStatValue, IScriptChangeAccuracy
{
/// <inheritdoc />
public void ChangeOffensiveStatValue(IExecutingMove move, IPokemon target, byte hit, uint defensiveStat,
@ -20,8 +20,7 @@ public class Hustle : Script, IScriptChangeOffensiveStatValue
}
/// <inheritdoc />
public override void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref int modifiedAccuracy)
public void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref int modifiedAccuracy)
{
if (executingMove.UseMove.Category == MoveCategory.Physical)
{

View File

@ -6,7 +6,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Ice_Body_(Ability)">Bulbapedia - Ice Body</see>
/// </summary>
[Script(ScriptCategory.Ability, "ice_body")]
public class IceBody : Script, IScriptOnEndTurn
public class IceBody : Script, IScriptOnEndTurn, IScriptCustomTrigger
{
private IPokemon? _pokemon;
@ -41,7 +41,7 @@ public class IceBody : Script, IScriptOnEndTurn
}
/// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName != CustomTriggers.IgnoreHail || args is not CustomTriggers.IgnoreHailArgs ignoreHailArgs)
return;

View File

@ -6,11 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Immunity_(Ability)">Bulbapedia - Immunity</see>
/// </summary>
[Script(ScriptCategory.Ability, "immunity")]
public class Immunity : Script
public class Immunity : Script, IScriptPreventStatusChange
{
/// <inheritdoc />
public override void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted,
ref bool preventStatus)
public void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, ref bool preventStatus)
{
if (status == ScriptUtils.ResolveName<Status.Poisoned>() ||
status == ScriptUtils.ResolveName<Status.BadlyPoisoned>())

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Infiltrator_(Ability)">Bulbapedia - Infiltrator</see>
/// </summary>
[Script(ScriptCategory.Ability, "infiltrator")]
public class Infiltrator : Script
public class Infiltrator : Script, IScriptCustomTrigger
{
/// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName == CustomTriggers.BypassSubstitute && args is CustomTriggers.BypassSubstituteArgs bypassArgs)
{

View File

@ -8,7 +8,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Inner_Focus_(Ability)">Bulbapedia - Inner Focus</see>
/// </summary>
[Script(ScriptCategory.Ability, "inner_focus")]
public class InnerFocus : Script
public class InnerFocus : Script, IScriptPreventVolatileAdd
{
private IPokemon? _pokemon;
@ -21,7 +21,7 @@ public class InnerFocus : Script
}
/// <inheritdoc />
public override void PreventVolatileAdd(IScriptSource parent, Script script, ref bool preventVolatileAdd)
public void PreventVolatileAdd(IScriptSource parent, Script script, ref bool preventVolatileAdd)
{
if (script is not FlinchEffect)
return;

View File

@ -6,11 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Insomnia_(Ability)">Bulbapedia - Insomnia</see>
/// </summary>
[Script(ScriptCategory.Ability, "insomnia")]
public class Insomnia : Script
public class Insomnia : Script, IScriptPreventStatusChange
{
/// <inheritdoc />
public override void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted,
ref bool preventStatus)
public void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, ref bool preventStatus)
{
if (status != ScriptUtils.ResolveName<Status.Sleep>())
return;

View File

@ -6,11 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Leaf_Guard_(Ability)">Bulbapedia - Leaf Guard</see>
/// </summary>
[Script(ScriptCategory.Ability, "leaf_guard")]
public class LeafGuard : Script
public class LeafGuard : Script, IScriptPreventStatusChange
{
/// <inheritdoc />
public override void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted,
ref bool preventStatus)
public void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, ref bool preventStatus)
{
if (pokemon.BattleData?.Battle.WeatherName != ScriptUtils.ResolveName<Weather.HarshSunlight>())
return;

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Levitate_(Ability)">Bulbapedia - Levitate</see>
/// </summary>
[Script(ScriptCategory.Ability, "levitate")]
public class Levitate : Script
public class Levitate : Script, IScriptIsFloating
{
/// <inheritdoc />
public override void IsFloating(IPokemon pokemon, ref bool isFloating)
public void IsFloating(IPokemon pokemon, ref bool isFloating)
{
isFloating = true;
}

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Light_Metal_(Ability)">Bulbapedia - Light Metal</see>
/// </summary>
[Script(ScriptCategory.Ability, "light_metal")]
public class LightMetal : Script
public class LightMetal : Script, IScriptModifyWeight
{
/// <inheritdoc />
public override void ModifyWeight(ref float weight)
public void ModifyWeight(ref float weight)
{
weight *= 0.5f;
}

View File

@ -6,11 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Limber_(Ability)">Bulbapedia - Limber</see>
/// </summary>
[Script(ScriptCategory.Ability, "limber")]
public class Limber : Script
public class Limber : Script, IScriptPreventStatusChange
{
/// <inheritdoc />
public override void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted,
ref bool preventStatus)
public void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, ref bool preventStatus)
{
if (status != ScriptUtils.ResolveName<Status.Paralyzed>())
return;

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Liquid_Ooze_(Ability)">Bulbapedia - Liquid Ooze</see>
/// </summary>
[Script(ScriptCategory.Ability, "liquid_ooze")]
public class LiquidOoze : Script
public class LiquidOoze : Script, IScriptCustomTrigger
{
/// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName != CustomTriggers.ModifyDrain || args is not CustomTriggers.ModifyDrainArgs parameters)
return;

View File

@ -6,11 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Long_Reach_(Ability)">Bulbapedia - Long Reach</see>
/// </summary>
[Script(ScriptCategory.Ability, "long_reach")]
public class LongReach : Script
public class LongReach : Script, IScriptModifyIsContact
{
/// <inheritdoc />
public override void ModifyIsContact(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref bool isContact)
public void ModifyIsContact(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool isContact)
{
isContact = false;
}

View File

@ -6,11 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Magma_Armor_(Ability)">Bulbapedia - Magma Armor</see>
/// </summary>
[Script(ScriptCategory.Ability, "magma_armor")]
public class MagmaArmor : Script, IScriptOnSwitchIn
public class MagmaArmor : Script, IScriptOnSwitchIn, IScriptPreventStatusChange
{
/// <inheritdoc />
public override void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted,
ref bool preventStatus)
public void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, ref bool preventStatus)
{
if (status == ScriptUtils.ResolveName<Status.Frozen>())
{

View File

@ -6,7 +6,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Mega_Launcher_(Ability)">Bulbapedia - Mega Launcher</see>
/// </summary>
[Script(ScriptCategory.Ability, "mega_launcher")]
public class MegaLauncher : Script, IScriptChangeBasePower
public class MegaLauncher : Script, IScriptChangeBasePower, IScriptCustomTrigger
{
/// <inheritdoc />
public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower)
@ -18,7 +18,7 @@ public class MegaLauncher : Script, IScriptChangeBasePower
}
/// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName != CustomTriggers.ModifyHealPercent || args is not CustomTriggers.ModifyHealPercentArgs healArgs)
return;

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Multitype_(Ability)">Bulbapedia - Multitype</see>
/// </summary>
[Script(ScriptCategory.Ability, "multitype")]
public class Multitype : Script
public class Multitype : Script, IScriptOnAfterHeldItemChange
{
/// <inheritdoc />
public override void OnAfterHeldItemChange(IPokemon pokemon, IItem? previous, IItem? item)
public void OnAfterHeldItemChange(IPokemon pokemon, IItem? previous, IItem? item)
{
if (pokemon.Species.Name != "arceus")
return;

View File

@ -6,18 +6,17 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/No_Guard_(Ability)">Bulbapedia - No Guard</see>
/// </summary>
[Script(ScriptCategory.Ability, "no_guard")]
public class NoGuard : Script
public class NoGuard : Script, IScriptChangeAccuracy, IScriptChangeIncomingAccuracy
{
/// <inheritdoc />
public override void ChangeIncomingAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
public void ChangeIncomingAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref int modifiedAccuracy)
{
modifiedAccuracy = 2000;
}
/// <inheritdoc />
public override void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref int modifiedAccuracy)
public void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref int modifiedAccuracy)
{
modifiedAccuracy = 2000;
}

View File

@ -8,10 +8,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Oblivious_(Ability)">Bulbapedia - Oblivious</see>
/// </summary>
[Script(ScriptCategory.Ability, "oblivious")]
public class Oblivious : Script
public class Oblivious : Script, IScriptPreventVolatileAdd
{
/// <inheritdoc />
public override void PreventVolatileAdd(IScriptSource parent, Script script, ref bool preventVolatileAdd)
public void PreventVolatileAdd(IScriptSource parent, Script script, ref bool preventVolatileAdd)
{
preventVolatileAdd = script switch
{

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Overcoat_(Ability)">Bulbapedia - Overcoat</see>
/// </summary>
[Script(ScriptCategory.Ability, "overcoat")]
public class Overcoat : Script, IScriptIsInvulnerableToMove
public class Overcoat : Script, IScriptIsInvulnerableToMove, IScriptCustomTrigger
{
/// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName == CustomTriggers.IgnoreHail && args is CustomTriggers.IgnoreHailArgs hailArgs)
{

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Own_Tempo_(Ability)">Bulbapedia - Own Tempo</see>
/// </summary>
[Script(ScriptCategory.Ability, "own_tempo")]
public class OwnTempo : Script
public class OwnTempo : Script, IScriptPreventVolatileAdd
{
/// <inheritdoc />
public override void PreventVolatileAdd(IScriptSource parent, Script script, ref bool preventVolatileAdd)
public void PreventVolatileAdd(IScriptSource parent, Script script, ref bool preventVolatileAdd)
{
if (script is Pokemon.Confusion)
preventVolatileAdd = true;

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Poison_Heal_(Ability)">Bulbapedia - Poison Heal</see>
/// </summary>
[Script(ScriptCategory.Ability, "poison_heal")]
public class PoisonHeal : Script
public class PoisonHeal : Script, IScriptCustomTrigger
{
/// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName != CustomTriggers.PoisonedDamage)
return;

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Pressure_(Ability)">Bulbapedia - Pressure</see>
/// </summary>
[Script(ScriptCategory.Ability, "pressure")]
public class Pressure : Script
public class Pressure : Script, IScriptModifyPPUsedForIncomingMove
{
/// <inheritdoc />
public override void ModifyPPUsedForIncomingMove(IExecutingMove executingMove, ref byte ppUsed)
public void ModifyPPUsedForIncomingMove(IExecutingMove executingMove, ref byte ppUsed)
{
if (ppUsed == byte.MaxValue)
return;

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/RKS_System_(Ability)">Bulbapedia - RKS System</see>
/// </summary>
[Script(ScriptCategory.Ability, "rks_system")]
public class RKSSystem : Script
public class RKSSystem : Script, IScriptOnAfterHeldItemChange
{
/// <inheritdoc />
public override void OnAfterHeldItemChange(IPokemon pokemon, IItem? previous, IItem? item)
public void OnAfterHeldItemChange(IPokemon pokemon, IItem? previous, IItem? item)
{
if (pokemon.Species.Name != "silvally")
return;

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Rock_Head_(Ability)">Bulbapedia - Rock Head</see>
/// </summary>
[Script(ScriptCategory.Ability, "rock_head")]
public class RockHead : Script
public class RockHead : Script, IScriptCustomTrigger
{
/// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName != CustomTriggers.ModifyRecoil)
return;

View File

@ -6,7 +6,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Sand_Force_(Ability)">Bulbapedia - Sand Force</see>
/// </summary>
[Script(ScriptCategory.Ability, "sand_force")]
public class SandForce : Script, IScriptChangeBasePower
public class SandForce : Script, IScriptChangeBasePower, IScriptCustomTrigger
{
/// <inheritdoc />
public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower)
@ -23,7 +23,7 @@ public class SandForce : Script, IScriptChangeBasePower
}
/// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName == CustomTriggers.BypassSandstormDamage &&
args is CustomTriggers.BypassSandstormDamageArgs bypassArgs)

View File

@ -6,7 +6,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Sand_Rush_(Ability)">Bulbapedia - Sand Rush</see>
/// </summary>
[Script(ScriptCategory.Ability, "sand_rush")]
public class SandRush : Script, IScriptChangeSpeed
public class SandRush : Script, IScriptChangeSpeed, IScriptCustomTrigger
{
/// <inheritdoc />
public void ChangeSpeed(ITurnChoice choice, ref uint speed)
@ -18,7 +18,7 @@ public class SandRush : Script, IScriptChangeSpeed
}
/// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName == CustomTriggers.BypassSandstormDamage &&
args is CustomTriggers.BypassSandstormDamageArgs bypassArgs)

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Sand_Veil_(Ability)">Bulbapedia - Sand Veil</see>
/// </summary>
[Script(ScriptCategory.Ability, "sand_veil")]
public class SandVeil : Script
public class SandVeil : Script, IScriptCustomTrigger, IScriptChangeIncomingAccuracy
{
/// <inheritdoc />
public override void ChangeIncomingAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
public void ChangeIncomingAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref int modifiedAccuracy)
{
if (executingMove.Battle.WeatherName != ScriptUtils.ResolveName<Weather.Sandstorm>())
@ -19,7 +19,7 @@ public class SandVeil : Script
}
/// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName == CustomTriggers.BypassSandstormDamage &&
args is CustomTriggers.BypassSandstormDamageArgs bypassArgs)

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Scrappy_(Ability)">Bulbapedia - Scrappy</see>
/// </summary>
[Script(ScriptCategory.Ability, "scrappy")]
public class Scrappy : Script
public class Scrappy : Script, IScriptChangeTypesForMove
{
/// <inheritdoc />
public override void ChangeTypesForMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
public void ChangeTypesForMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
IList<TypeIdentifier> types)
{
var hitType = executingMove.GetHitData(target, hitIndex).Type;

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Skill_Link_(Ability)">Bulbapedia - Skill Link</see>
/// </summary>
[Script(ScriptCategory.Ability, "skill_link")]
public class SkillLink : Script
public class SkillLink : Script, IScriptCustomTrigger
{
/// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName != CustomTriggers.Modify2_5HitMove)
return;

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Snow_Cloak_(Ability)">Bulbapedia - Snow Cloak</see>
/// </summary>
[Script(ScriptCategory.Ability, "snow_cloak")]
public class SnowCloak : Script
public class SnowCloak : Script, IScriptCustomTrigger, IScriptChangeIncomingAccuracy
{
/// <inheritdoc />
public override void ChangeIncomingAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
public void ChangeIncomingAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref int modifiedAccuracy)
{
// If the weather is hail, increase evasion by 20%
@ -19,7 +19,7 @@ public class SnowCloak : Script
}
}
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName == CustomTriggers.IgnoreHail && args is CustomTriggers.IgnoreHailArgs hailArgs)
hailArgs.Ignore = true;

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Steadfast_(Ability)">Bulbapedia - Steadfast</see>
/// </summary>
[Script(ScriptCategory.Ability, "steadfast")]
public class Steadfast : Script
public class Steadfast : Script, IScriptCustomTrigger
{
/// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName != CustomTriggers.OnFlinch)
return;

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Sticky_Hold_(Ability)">Bulbapedia - Sticky Hold</see>
/// </summary>
[Script(ScriptCategory.Ability, "sticky_hold")]
public class StickyHold : Script
public class StickyHold : Script, IScriptPreventHeldItemSteal
{
/// <inheritdoc />
public override void PreventHeldItemSteal(IPokemon pokemon, IItem heldItem, ref bool prevent)
public void PreventHeldItemSteal(IPokemon pokemon, IItem heldItem, ref bool prevent)
{
prevent = true;
}

View File

@ -6,11 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Sweet_Veil_(Ability)">Bulbapedia - Sweet Veil</see>
/// </summary>
[Script(ScriptCategory.Ability, "sweet_veil")]
public class SweetVeil : Script
public class SweetVeil : Script, IScriptPreventStatusChange
{
/// <inheritdoc />
public override void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted,
ref bool preventStatus)
public void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, ref bool preventStatus)
{
if (status == ScriptUtils.ResolveName<Status.Sleep>())
{

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Synchronize_(Ability)">Bulbapedia - Synchronize</see>
/// </summary>
[Script(ScriptCategory.Ability, "synchronize")]
public class Synchronize : Script
public class Synchronize : Script, IScriptOnAfterStatusChange
{
/// <inheritdoc />
public override void OnAfterStatusChange(IPokemon pokemon, StringKey status, IPokemon? originPokemon)
public void OnAfterStatusChange(IPokemon pokemon, StringKey status, IPokemon? originPokemon)
{
if (originPokemon == null || pokemon == originPokemon)
return;

View File

@ -6,10 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Tangled_Feet_(Ability)">Bulbapedia - Tangled Feet</see>
/// </summary>
[Script(ScriptCategory.Ability, "tangled_feet")]
public class TangledFeet : Script
public class TangledFeet : Script, IScriptChangeIncomingAccuracy
{
/// <inheritdoc />
public override void ChangeIncomingAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
public void ChangeIncomingAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref int modifiedAccuracy)
{
if (modifiedAccuracy != 255 && target.Volatile.Contains<Pokemon.Confusion>())

View File

@ -8,10 +8,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Teravolt_(Ability)">Bulbapedia - Teravolt</see>
/// </summary>
[Script(ScriptCategory.Ability, "teravolt")]
public class Teravolt : Script
public class Teravolt : Script, IScriptOnBeforeMoveChoice, IScriptOnAfterMoveChoice
{
/// <inheritdoc />
public override void OnBeforeMoveChoice(IMoveChoice moveChoice)
public void OnBeforeMoveChoice(IMoveChoice moveChoice)
{
var battleData = moveChoice.User.BattleData;
if (battleData is null)
@ -25,7 +25,7 @@ public class Teravolt : Script
}
/// <inheritdoc />
public override void OnAfterMoveChoice(IMoveChoice move)
public void OnAfterMoveChoice(IMoveChoice move)
{
var battleData = move.User.BattleData;
if (battleData is null)

View File

@ -6,11 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Victory_Star_(Ability)">Bulbapedia - Victory Star</see>
/// </summary>
[Script(ScriptCategory.Ability, "victory_star")]
public class VictoryStar : Script
public class VictoryStar : Script, IScriptChangeAccuracy
{
/// <inheritdoc />
public override void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref int modifiedAccuracy)
public void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref int modifiedAccuracy)
{
modifiedAccuracy = modifiedAccuracy.MultiplyOrMax(1.1f);
}

View File

@ -6,11 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Vital_Spirit_(Ability)">Bulbapedia - Vital Spirit</see>
/// </summary>
[Script(ScriptCategory.Ability, "vital_spirit")]
public class VitalSpirit : Script
public class VitalSpirit : Script, IScriptPreventStatusChange
{
/// <inheritdoc />
public override void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted,
ref bool preventStatus)
public void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, ref bool preventStatus)
{
if (status == ScriptUtils.ResolveName<Status.Sleep>() && !selfInflicted)
{

View File

@ -6,11 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Water_Bubble_(Ability)">Bulbapedia - Water Bubble</see>
/// </summary>
[Script(ScriptCategory.Ability, "water_bubble")]
public class WaterBubble : Script, IScriptChangeIncomingMoveDamage, IScriptChangeMoveDamage
public class WaterBubble : Script, IScriptChangeIncomingMoveDamage, IScriptChangeMoveDamage, IScriptPreventStatusChange
{
/// <inheritdoc />
public override void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted,
ref bool preventStatus)
public void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, ref bool preventStatus)
{
if (status == ScriptUtils.ResolveName<Status.Burned>())
preventStatus = true;

View File

@ -6,11 +6,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Water_Veil_(Ability)">Bulbapedia - Water Veil</see>
/// </summary>
[Script(ScriptCategory.Ability, "water_veil")]
public class WaterVeil : Script
public class WaterVeil : Script, IScriptPreventStatusChange
{
/// <inheritdoc />
public override void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted,
ref bool preventStatus)
public void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, ref bool preventStatus)
{
if (status == ScriptUtils.ResolveName<Status.Burned>())
preventStatus = true;

View File

@ -8,10 +8,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Wonder_Skin_(Ability)">Bulbapedia - Wonder Skin</see>
/// </summary>
[Script(ScriptCategory.Ability, "wonder_skin")]
public class WonderSkin : Script
public class WonderSkin : Script, IScriptChangeIncomingAccuracy
{
/// <inheritdoc />
public override void ChangeIncomingAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
public void ChangeIncomingAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref int modifiedAccuracy)
{
if (executingMove.UseMove.Category == MoveCategory.Status && executingMove.UseMove.Accuracy != 255)

View File

@ -1,12 +1,13 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Battle;
[Script(ScriptCategory.Battle, "gravity")]
public class Gravity : Script, IScriptFailIncomingMove, IScriptOnEndTurn
public class Gravity : Script, IScriptFailIncomingMove, IScriptOnEndTurn, IScriptChangeTypesForIncomingMove,
IScriptIsFloating
{
private int _turns = 5;
/// <inheritdoc />
public override void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
public void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
IList<TypeIdentifier> types)
{
var typeLibrary = target.Library.StaticLibrary.Types;
@ -25,7 +26,7 @@ public class Gravity : Script, IScriptFailIncomingMove, IScriptOnEndTurn
}
/// <inheritdoc />
public override void IsFloating(IPokemon pokemon, ref bool isFloating)
public void IsFloating(IPokemon pokemon, ref bool isFloating)
{
// Gravity makes all Pokémon susceptible to Ground-type moves
isFloating = false;

View File

@ -1,7 +1,8 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Battle;
[Script(ScriptCategory.Battle, "uproar_effect")]
public class UproarEffect : Script, IScriptOnBeforeTurnStart, IScriptOnSecondaryEffect, IScriptOnEndTurn
public class UproarEffect : Script, IScriptOnBeforeTurnStart, IScriptOnSecondaryEffect, IScriptOnEndTurn,
IScriptPreventStatusChange
{
private IPokemon? _placer;
private bool _hasUsedUproar;
@ -14,8 +15,7 @@ public class UproarEffect : Script, IScriptOnBeforeTurnStart, IScriptOnSecondary
}
/// <inheritdoc />
public override void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted,
ref bool preventStatus)
public void PreventStatusChange(IPokemon pokemon, StringKey status, bool selfInflicted, ref bool preventStatus)
{
if (status == ScriptUtils.ResolveName<Status.Sleep>())
{

View File

@ -1,10 +1,10 @@
namespace PkmnLib.Plugin.Gen7.Scripts.MoveVolatile;
[Script(ScriptCategory.MoveVolatile, "bypass_sleep")]
public class BypassSleepVolatile : Script
public class BypassSleepVolatile : Script, IScriptCustomTrigger
{
/// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName == CustomTriggers.BypassSleep && args is CustomTriggers.BypassSleepArgs bypassArgs)
bypassArgs.Bypass = true;

View File

@ -40,7 +40,7 @@ public class AuroraVeil : Script, IScriptOnSecondaryEffect
var side = battle.Sides[move.User.BattleData!.SideIndex];
var args = new CustomTriggers.AuroraVeilDurationArgs(move, 5);
move.User.RunScriptHook(x => x.CustomTrigger(CustomTriggers.AuroraVeilDuration, args));
move.User.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.AuroraVeilDuration, args));
var numberOfTurns = args.Duration;
var script = side.VolatileScripts.StackOrAdd(ScriptUtils.ResolveName<AuroraVeilEffect>(), () =>

View File

@ -9,7 +9,7 @@ public class Bind : Script, IScriptOnSecondaryEffect
public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
var args = new CustomTriggers.ModifyBindArgs(move);
move.User.RunScriptHook(x => x.CustomTrigger(CustomTriggers.ModifyBind, args));
move.User.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.ModifyBind, args));
var bindTurns = args.Duration;
var bindDamage = args.DamagePercent;

View File

@ -8,7 +8,7 @@ public class ChargeMove : Script, IScriptPreventMove
public void PreventMove(IExecutingMove move, ref bool prevent)
{
var args = new CustomTriggers.BypassChargeMoveArgs(move, false);
move.RunScriptHook(script => script.CustomTrigger(CustomTriggers.BypassChargeMove, args));
move.RunScriptHook<IScriptCustomTrigger>(script => script.CustomTrigger(CustomTriggers.BypassChargeMove, args));
if (args.Bypass)
return;

View File

@ -24,7 +24,7 @@ public class Drain : Script, IScriptOnInitialize, IScriptOnSecondaryEffect
var invert = false;
var args = new CustomTriggers.ModifyDrainArgs(move, target, hit, damage, healed, invert);
target.RunScriptHook(x => x.CustomTrigger(CustomTriggers.ModifyDrain, args));
target.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.ModifyDrain, args));
invert = args.Invert;
healed = args.Healed;

View File

@ -20,7 +20,7 @@ public class DreamEater : Script, IScriptOnSecondaryEffect, IScriptBlockOutgoing
healed = (uint)(healed * 1.3f);
var args = new CustomTriggers.ModifyDrainArgs(move, target, hit, damage, healed, false);
target.RunScriptHook(x => x.CustomTrigger(CustomTriggers.ModifyDrain, args));
target.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.ModifyDrain, args));
var invert = args.Invert;
healed = args.Healed;

View File

@ -3,10 +3,10 @@ using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "feint")]
public class Feint : Script
public class Feint : Script, IScriptOnBeforeHit
{
/// <inheritdoc />
public override void OnBeforeHit(IExecutingMove move, IPokemon target, byte hitIndex)
public void OnBeforeHit(IExecutingMove move, IPokemon target, byte hitIndex)
{
if (target.Volatile.Contains<ProtectionEffectScript>())
{

View File

@ -14,7 +14,7 @@ public class FlareBlitz : Script, IScriptOnSecondaryEffect
var recoilDamage = hitData.Damage * (1 / 3);
var triggerArgs = new CustomTriggers.ModifyRecoilArgs(move, target, hit, hitData.Damage, recoilDamage);
move.RunScriptHook(x => x.CustomTrigger(CustomTriggers.ModifyRecoil, triggerArgs));
move.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.ModifyRecoil, triggerArgs));
if (triggerArgs.Prevent)
return;

View File

@ -1,10 +1,10 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "flying_press")]
public class FlyingPress : Script
public class FlyingPress : Script, IScriptChangeTypesForMove
{
/// <inheritdoc />
public override void ChangeTypesForMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
public void ChangeTypesForMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
IList<TypeIdentifier> types)
{
var typeLibrary = executingMove.User.Library.StaticLibrary.Types;

View File

@ -18,7 +18,7 @@ public class HealPercent : Script, IScriptOnInitialize, IScriptOnSecondaryEffect
public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
var args = new CustomTriggers.ModifyHealPercentArgs(move, target, hit, _healPercent);
move.RunScriptHook(x => x.CustomTrigger(CustomTriggers.ModifyHealPercent, args));
move.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.ModifyHealPercent, args));
var healPercent = args.HealPercent;
target.Heal(target.BoostedStats.Hp.MultiplyOrMax(healPercent));

View File

@ -13,7 +13,7 @@ public class LightScreen : Script, IScriptOnSecondaryEffect
return;
var args = new CustomTriggers.LightScreenNumberOfTurnsArgs(move, 5);
move.RunScriptHook(x => x.CustomTrigger(CustomTriggers.LightScreenNumberOfTurns, args));
move.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.LightScreenNumberOfTurns, args));
var turns = args.Duration;
battleData.BattleSide.VolatileScripts.StackOrAdd(ScriptUtils.ResolveName<LightScreenEffect>(),

View File

@ -20,7 +20,7 @@ public class MultiHitMove : Script, IScriptChangeNumberOfHits
_ => 5,
};
var triggerArgs = new CustomTriggers.Modify2_5HitMoveArgs(choice, (byte)newHits);
choice.RunScriptHook(x => x.CustomTrigger(CustomTriggers.Modify2_5HitMove, triggerArgs));
choice.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.Modify2_5HitMove, triggerArgs));
newHits = triggerArgs.NumberOfHits;
numberOfHits = (byte)newHits;

View File

@ -1,11 +1,10 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "one_hit_ko")]
public class OneHitKo : Script, IScriptChangeMoveDamage
public class OneHitKo : Script, IScriptChangeMoveDamage, IScriptChangeAccuracy
{
/// <inheritdoc />
public override void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref int modifiedAccuracy)
public void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref int modifiedAccuracy)
{
var levelDifference = executingMove.User.Level - target.Level;
if (levelDifference < 0)

View File

@ -3,11 +3,11 @@ using PkmnLib.Static.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "pollen_puff")]
public class PollenPuff : Script, IScriptOnSecondaryEffect
public class PollenPuff : Script, IScriptOnSecondaryEffect, IScriptChangeCategory
{
/// <inheritdoc />
/// <inheritdoc />
public override void ChangeCategory(IExecutingMove move, IPokemon target, byte hitIndex, ref MoveCategory category)
public void ChangeCategory(IExecutingMove move, IPokemon target, byte hitIndex, ref MoveCategory category)
{
var battleData = move.User.BattleData;
var targetBattleData = target.BattleData;

View File

@ -3,13 +3,14 @@ using PkmnLib.Static.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "present")]
public class Present : Script, IScriptOnSecondaryEffect, IScriptChangeBasePower
public class Present : Script, IScriptOnSecondaryEffect, IScriptChangeBasePower, IScriptChangeCategory,
IScriptOnBeforeHit
{
private bool _isHealing;
private byte _basePower;
/// <inheritdoc />
public override void OnBeforeHit(IExecutingMove move, IPokemon target, byte hitIndex)
public void OnBeforeHit(IExecutingMove move, IPokemon target, byte hitIndex)
{
var battleRandom = move.User.BattleData?.Battle.Random;
if (battleRandom == null)
@ -33,7 +34,7 @@ public class Present : Script, IScriptOnSecondaryEffect, IScriptChangeBasePower
}
/// <inheritdoc />
public override void ChangeCategory(IExecutingMove move, IPokemon target, byte hitIndex, ref MoveCategory category)
public void ChangeCategory(IExecutingMove move, IPokemon target, byte hitIndex, ref MoveCategory category)
{
if (_isHealing)
category = MoveCategory.Status;

View File

@ -23,7 +23,7 @@ public class Recoil : Script, IScriptOnInitialize, IScriptOnSecondaryEffect
var recoilDamage = (uint)(hitData.Damage * _recoilPercentage);
var triggerArgs = new CustomTriggers.ModifyRecoilArgs(move, target, hit, hitData.Damage, recoilDamage);
move.RunScriptHook(x => x.CustomTrigger(CustomTriggers.ModifyRecoil, triggerArgs));
move.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.ModifyRecoil, triggerArgs));
if (triggerArgs.Prevent)
return;

View File

@ -12,7 +12,7 @@ public class Reflect : Script, IScriptOnSecondaryEffect
var numberOfTurns = 5;
var args = new CustomTriggers.ReflectNumberOfTurnsArgs(move, numberOfTurns);
move.User.RunScriptHook(x => x.CustomTrigger(CustomTriggers.ReflectNumberOfTurns, args));
move.User.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.ReflectNumberOfTurns, args));
numberOfTurns = args.Duration;
battleData.BattleSide.VolatileScripts.Add(new Side.ReflectEffect(numberOfTurns));

View File

@ -1,10 +1,10 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "spectral_thief")]
public class SpectralThief : Script
public class SpectralThief : Script, IScriptOnBeforeHit
{
/// <inheritdoc />
public override void OnBeforeHit(IExecutingMove move, IPokemon target, byte hitIndex)
public void OnBeforeHit(IExecutingMove move, IPokemon target, byte hitIndex)
{
var positiveStats = target.StatBoost.Where(x => x.value > 0).ToArray();
if (positiveStats.Length > 0)

View File

@ -3,10 +3,10 @@ using PkmnLib.Static.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "sucker_punch")]
public class SuckerPunch : Script
public class SuckerPunch : Script, IScriptOnBeforeHit
{
/// <inheritdoc />
public override void OnBeforeHit(IExecutingMove move, IPokemon target, byte hitIndex)
public void OnBeforeHit(IExecutingMove move, IPokemon target, byte hitIndex)
{
var targetChoice = move.Battle.ChoiceQueue?.Where(x => x.User == target).FirstOrDefault();
if (targetChoice is not IMoveChoice moveChoice ||

View File

@ -14,7 +14,7 @@ public class Whirlpool : Script, IScriptOnSecondaryEffect
var turns = move.Battle.Random.GetInt(4, 6);
var damagePercent = 0.125f;
var args = new CustomTriggers.WhirlpoolArgs(move, target, hit, turns, damagePercent);
move.RunScriptHook(x => x.CustomTrigger(CustomTriggers.Whirlpool, args));
move.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.Whirlpool, args));
turns = args.Turns;
damagePercent = args.DamagePercent;
whirlpoolEffect.AddTargetedPokemon(target, turns, damagePercent);

View File

@ -3,7 +3,7 @@ using PkmnLib.Plugin.Gen7.Scripts.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "autotomize")]
public class AutotomizeEffect : Script, IBatonPassException, IScriptStack
public class AutotomizeEffect : Script, IBatonPassException, IScriptStack, IScriptModifyWeight
{
public int Stacks { get; private set; } = 1;
@ -14,7 +14,7 @@ public class AutotomizeEffect : Script, IBatonPassException, IScriptStack
}
/// <inheritdoc />
public override void ModifyWeight(ref float weight)
public void ModifyWeight(ref float weight)
{
weight -= 100f * Stacks;
}

View File

@ -4,7 +4,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "charge_bounce")]
public class ChargeBounceEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomingMoveDamage,
IScriptBlockIncomingHit
IScriptBlockIncomingHit, IScriptOnAfterMoveChoice
{
private readonly IPokemon _owner;
@ -35,7 +35,7 @@ public class ChargeBounceEffect : Script, IScriptForceTurnSelection, IScriptChan
}
/// <inheritdoc />
public override void OnAfterMoveChoice(IMoveChoice moveChoice)
public void OnAfterMoveChoice(IMoveChoice moveChoice)
{
if (moveChoice.AdditionalData?.ContainsKey("bounce_charge") != true)
{

View File

@ -4,7 +4,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "charge_fly")]
public class ChargeFlyEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomingMoveDamage,
IScriptBlockIncomingHit
IScriptBlockIncomingHit, IScriptOnAfterMoveChoice
{
private readonly IPokemon _owner;
@ -35,7 +35,7 @@ public class ChargeFlyEffect : Script, IScriptForceTurnSelection, IScriptChangeI
}
/// <inheritdoc />
public override void OnAfterMoveChoice(IMoveChoice moveChoice)
public void OnAfterMoveChoice(IMoveChoice moveChoice)
{
if (moveChoice.AdditionalData?.ContainsKey("fly_charge") != true)
{

View File

@ -4,7 +4,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "charge_sky_drop")]
public class ChargeSkyDropEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomingMoveDamage,
IScriptBlockIncomingHit
IScriptBlockIncomingHit, IScriptOnAfterMoveChoice
{
private readonly IPokemon _owner;
@ -35,7 +35,7 @@ public class ChargeSkyDropEffect : Script, IScriptForceTurnSelection, IScriptCha
}
/// <inheritdoc />
public override void OnAfterMoveChoice(IMoveChoice moveChoice)
public void OnAfterMoveChoice(IMoveChoice moveChoice)
{
if (moveChoice.AdditionalData?.ContainsKey("sky_drop_charge") != true)
{

View File

@ -3,7 +3,8 @@ using PkmnLib.Plugin.Gen7.Scripts.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "dig")]
public class DigEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomingMoveDamage, IScriptBlockIncomingHit
public class DigEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomingMoveDamage, IScriptBlockIncomingHit,
IScriptOnAfterMoveChoice
{
private readonly IPokemon _owner;
@ -34,7 +35,7 @@ public class DigEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomin
}
/// <inheritdoc />
public override void OnAfterMoveChoice(IMoveChoice moveChoice)
public void OnAfterMoveChoice(IMoveChoice moveChoice)
{
if (moveChoice.AdditionalData?.ContainsKey("dig_charge") != true)
{

View File

@ -3,7 +3,8 @@ using PkmnLib.Plugin.Gen7.Scripts.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "dive")]
public class DiveEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomingMoveDamage, IScriptBlockIncomingHit
public class DiveEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomingMoveDamage, IScriptBlockIncomingHit,
IScriptOnAfterMoveChoice
{
private readonly IPokemon _owner;
@ -34,7 +35,7 @@ public class DiveEffect : Script, IScriptForceTurnSelection, IScriptChangeIncomi
}
/// <inheritdoc />
public override void OnAfterMoveChoice(IMoveChoice moveChoice)
public void OnAfterMoveChoice(IMoveChoice moveChoice)
{
if (moveChoice.AdditionalData?.ContainsKey("dive_charge") != true)
{

View File

@ -8,7 +8,7 @@ public class FlinchEffect : Script, IScriptPreventMove
{
prevent = true;
var args = new CustomTriggers.OnFlinchArgs(move);
move.RunScriptHook(x => x.CustomTrigger(CustomTriggers.OnFlinch, args));
move.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.OnFlinch, args));
if (args.Prevent)
return;

View File

@ -3,7 +3,7 @@ using PkmnLib.Static.Libraries;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "foresight")]
public class ForesightEffect : Script, IScriptPreventStatBoostChange
public class ForesightEffect : Script, IScriptPreventStatBoostChange, IScriptChangeTypesForIncomingMove
{
private readonly TypeIdentifier _normalType;
private readonly TypeIdentifier _fightingType;
@ -25,7 +25,7 @@ public class ForesightEffect : Script, IScriptPreventStatBoostChange
}
/// <inheritdoc />
public override void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
public void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
IList<TypeIdentifier> types)
{
if (executingMove.UseMove.MoveType == _normalType || executingMove.UseMove.MoveType == _fightingType)

View File

@ -1,7 +1,8 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "heal_block")]
public class HealBlockEffect : Script, IScriptPreventMoveSelection, IScriptPreventMove, IScriptOnEndTurn
public class HealBlockEffect : Script, IScriptPreventMoveSelection, IScriptPreventMove, IScriptOnEndTurn,
IScriptPreventHeal
{
private int _duration;
@ -33,7 +34,7 @@ public class HealBlockEffect : Script, IScriptPreventMoveSelection, IScriptPreve
}
/// <inheritdoc />
public override void PreventHeal(IPokemon pokemon, uint heal, bool allowRevive, ref bool prevented)
public void PreventHeal(IPokemon pokemon, uint heal, bool allowRevive, ref bool prevented)
{
prevented = true;
}

View File

@ -2,7 +2,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "ingrain")]
public class IngrainEffect : Script, IScriptFailIncomingMove, IScriptOnEndTurn, IScriptPreventSelfSwitch,
IScriptPreventSelfRunAway
IScriptPreventSelfRunAway, IScriptChangeTypesForIncomingMove
{
private readonly IPokemon _owner;
@ -34,7 +34,7 @@ public class IngrainEffect : Script, IScriptFailIncomingMove, IScriptOnEndTurn,
}
/// <inheritdoc />
public override void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
public void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
IList<TypeIdentifier> types)
{
if (executingMove.UseMove.MoveType.Name == "ground")

View File

@ -1,7 +1,7 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "lock_on")]
public class LockOnEffect : Script, IScriptOnEndTurn
public class LockOnEffect : Script, IScriptOnEndTurn, IScriptChangeAccuracy
{
private readonly IPokemon _placer;
@ -11,8 +11,7 @@ public class LockOnEffect : Script, IScriptOnEndTurn
}
/// <inheritdoc />
public override void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
ref int modifiedAccuracy)
public void ChangeAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref int modifiedAccuracy)
{
if (_placer != target)
return;

View File

@ -1,7 +1,7 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "miracle_eye")]
public class MiracleEyeEffect : Script, IScriptPreventStatBoostChange
public class MiracleEyeEffect : Script, IScriptPreventStatBoostChange, IScriptChangeTypesForIncomingMove
{
/// <inheritdoc />
public void PreventStatBoostChange(IPokemon target, Statistic stat, sbyte amount, bool selfInflicted,
@ -12,7 +12,7 @@ public class MiracleEyeEffect : Script, IScriptPreventStatBoostChange
}
/// <inheritdoc />
public override void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
public void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
IList<TypeIdentifier> types)
{
if (executingMove.UseMove.MoveType.Name != "psychic")

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, IScriptBlockIncomingHit
public class PhantomForceCharge : Script, IScriptForceTurnSelection, IScriptBlockIncomingHit, IScriptOnAfterMoveChoice
{
private readonly IPokemon _owner;
@ -26,7 +26,7 @@ public class PhantomForceCharge : Script, IScriptForceTurnSelection, IScriptBloc
}
/// <inheritdoc />
public override void OnAfterMoveChoice(IMoveChoice moveChoice)
public void OnAfterMoveChoice(IMoveChoice moveChoice)
{
if (moveChoice.AdditionalData?.ContainsKey("phantom_force_charge") != true)
{

View File

@ -12,7 +12,8 @@ public class ProtectionEffectScript : Script, IScriptBlockIncomingHit
if (!executingMove.UseMove.HasFlag("protect"))
return;
var args = new CustomTriggers.BypassProtectionArgs(executingMove, target, hitIndex, false);
executingMove.User.RunScriptHook(x => x.CustomTrigger(CustomTriggers.BypassProtection, args));
executingMove.User.RunScriptHook<IScriptCustomTrigger>(x =>
x.CustomTrigger(CustomTriggers.BypassProtection, args));
if (args.Bypass)
return;

View File

@ -1,10 +1,10 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "roost_effect")]
public class RoostEffect : Script, IScriptOnEndTurn
public class RoostEffect : Script, IScriptOnEndTurn, IScriptChangeTypesForIncomingMove
{
/// <inheritdoc />
public override void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
public void ChangeTypesForIncomingMove(IExecutingMove executingMove, IPokemon target, byte hitIndex,
IList<TypeIdentifier> types)
{
types.RemoveAll(x => x.Name == "flying");

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, IScriptBlockIncomingHit
public class ShadowForceCharge : Script, IScriptForceTurnSelection, IScriptBlockIncomingHit, IScriptOnAfterMoveChoice
{
private readonly IPokemon _owner;
@ -26,7 +26,7 @@ public class ShadowForceCharge : Script, IScriptForceTurnSelection, IScriptBlock
}
/// <inheritdoc />
public override void OnAfterMoveChoice(IMoveChoice moveChoice)
public void OnAfterMoveChoice(IMoveChoice moveChoice)
{
if (moveChoice.AdditionalData?.ContainsKey("shadow_force_charge") != true)
{

Some files were not shown because too many files have changed in this diff Show More