Further work on refactor to interface based scripts

This commit is contained in:
2025-06-28 18:40:33 +02:00
parent b7bdf2b744
commit 436d1899e0
352 changed files with 940 additions and 867 deletions

View File

@@ -126,7 +126,8 @@ public static class MoveTurnExecutor
private static void ExecuteMoveChoiceForTarget(IBattle battle, IExecutingMove executingMove, IPokemon target)
{
var failed = false;
target.RunScriptHook(x => x.FailIncomingMove(executingMove, target, ref failed));
target.RunScriptHookInterface<IScriptFailIncomingMove>(x =>
x.FailIncomingMove(executingMove, target, ref failed));
if (failed)
{
// TODO: fail handling
@@ -134,7 +135,8 @@ public static class MoveTurnExecutor
}
var isInvulnerable = false;
target.RunScriptHook(x => x.IsInvulnerableToMove(executingMove, target, ref isInvulnerable));
target.RunScriptHookInterface<IScriptIsInvulnerableToMove>(x =>
x.IsInvulnerableToMove(executingMove, target, ref isInvulnerable));
if (isInvulnerable)
{
battle.EventHook.Invoke(new MoveInvulnerableEvent(executingMove, target));
@@ -166,7 +168,8 @@ public static class MoveTurnExecutor
hitData.IsContact = isContact;
var hitType = (TypeIdentifier?)useMove.MoveType;
executingMove.RunScriptHook(x => x.ChangeMoveType(executingMove, target, hitIndex, ref hitType));
executingMove.RunScriptHookInterface<IScriptChangeMoveType>(x =>
x.ChangeMoveType(executingMove, target, hitIndex, ref hitType));
hitData.Type = hitType;
@@ -177,14 +180,17 @@ public static class MoveTurnExecutor
var effectiveness = hitType == null
? 1
: battle.Library.StaticLibrary.Types.GetEffectiveness(hitType.Value, types);
executingMove.RunScriptHook(x => x.ChangeEffectiveness(executingMove, target, hitIndex, ref effectiveness));
target.RunScriptHook(x =>
executingMove.RunScriptHookInterface<IScriptChangeEffectiveness>(x =>
x.ChangeEffectiveness(executingMove, target, hitIndex, ref effectiveness));
target.RunScriptHookInterface<IScriptChangeIncomingEffectiveness>(x =>
x.ChangeIncomingEffectiveness(executingMove, target, hitIndex, ref effectiveness));
hitData.Effectiveness = effectiveness;
var blockCritical = false;
executingMove.RunScriptHook(x => x.BlockCriticalHit(executingMove, target, hitIndex, ref blockCritical));
target.RunScriptHook(x => x.BlockIncomingCriticalHit(executingMove, target, hitIndex, ref blockCritical));
executingMove.RunScriptHookInterface<IScriptBlockCriticalHit>(x =>
x.BlockCriticalHit(executingMove, target, hitIndex, ref blockCritical));
target.RunScriptHookInterface<IScriptBlockIncomingCriticalHit>(x =>
x.BlockIncomingCriticalHit(executingMove, target, hitIndex, ref blockCritical));
if (!blockCritical)
{
var critical = battle.Library.DamageCalculator.IsCritical(battle, executingMove, target, hitIndex);
@@ -208,7 +214,7 @@ public static class MoveTurnExecutor
if (accuracy < 100 && battle.Random.GetInt(100) >= accuracy)
{
executingMove.RunScriptHook(x => x.OnMoveMiss(executingMove, target));
executingMove.RunScriptHookInterface<IScriptOnMoveMiss>(x => x.OnMoveMiss(executingMove, target));
battle.EventHook.Invoke(new MoveMissEvent(executingMove));
break;
}
@@ -230,7 +236,8 @@ public static class MoveTurnExecutor
var chance = secondaryEffect.Chance;
if (chance < 0 || battle.Random.EffectChance(chance, executingMove, target, hitIndex))
{
executingMove.RunScriptHook(x => x.OnSecondaryEffect(executingMove, target, hitIndex));
executingMove.RunScriptHookInterface<IScriptOnSecondaryEffect>(x =>
x.OnSecondaryEffect(executingMove, target, hitIndex));
}
}
}
@@ -252,9 +259,11 @@ public static class MoveTurnExecutor
});
target.Damage(damage, DamageSource.MoveDamage, hitEventBatch);
if (!target.IsFainted)
target.RunScriptHook(x => x.OnIncomingHit(executingMove, target, hitIndex));
target.RunScriptHookInterface<IScriptOnIncomingHit>(x =>
x.OnIncomingHit(executingMove, target, hitIndex));
else
executingMove.RunScriptHook(x => x.OnOpponentFaints(executingMove, target, hitIndex));
executingMove.RunScriptHookInterface<IScriptOnOpponentFaints>(x =>
x.OnOpponentFaints(executingMove, target, hitIndex));
if (!target.IsFainted)
{
@@ -273,13 +282,14 @@ public static class MoveTurnExecutor
var chance = secondaryEffect.Chance;
if (chance < 0 || battle.Random.EffectChance(chance, executingMove, target, hitIndex))
{
executingMove.RunScriptHook(x =>
executingMove.RunScriptHookInterface<IScriptOnSecondaryEffect>(x =>
x.OnSecondaryEffect(executingMove, target, hitIndex));
}
}
}
if (target.IsFainted)
executingMove.RunScriptHook(x => x.OnOpponentFaints(executingMove, target, hitIndex));
executingMove.RunScriptHookInterface<IScriptOnOpponentFaints>(x =>
x.OnOpponentFaints(executingMove, target, hitIndex));
}
}
}
@@ -287,7 +297,7 @@ public static class MoveTurnExecutor
if (numberOfHits == 0)
{
target.RunScriptHook(x => x.OnMoveMiss(executingMove, target));
target.RunScriptHookInterface<IScriptOnMoveMiss>(x => x.OnMoveMiss(executingMove, target));
battle.EventHook.Invoke(new MoveMissEvent(executingMove));
}