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

This commit is contained in:
2025-07-06 10:27:56 +02:00
parent 83f6a183e3
commit 7c270a6d52
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;