Refactor move classes to implement respective interfaces for better structure
All checks were successful
Build / Build (push) Successful in 52s

This commit is contained in:
2025-06-28 12:02:24 +02:00
parent 2319160b52
commit b7bdf2b744
115 changed files with 407 additions and 348 deletions

View File

@@ -19,7 +19,7 @@ public static class MoveTurnExecutor
var useMove = chosenMove.MoveData;
var moveDataName = useMove.Name;
moveChoice.RunScriptHook(x => x.ChangeMove(moveChoice, ref moveDataName));
moveChoice.RunScriptHookInterface<IScriptChangeMove>(x => x.ChangeMove(moveChoice, ref moveDataName));
if (useMove.Name != moveDataName)
{
if (!battle.Library.StaticLibrary.Moves.TryGet(moveDataName, out useMove))
@@ -51,17 +51,22 @@ public static class MoveTurnExecutor
var targetType = useMove.Target;
var targets =
TargetResolver.ResolveTargets(battle, moveChoice.TargetSide, moveChoice.TargetPosition, targetType);
moveChoice.RunScriptHook(x => x.ChangeTargets(moveChoice, ref targets));
moveChoice.RunScriptHookInterface<IScriptChangeTargets>(x => x.ChangeTargets(moveChoice, ref targets));
if (targets.Count == 0)
{
moveChoice.Fail();
return;
}
targets.WhereNotNull().RunScriptHook(x => x.ChangeIncomingTargets(moveChoice, ref targets));
foreach (var target in targets.WhereNotNull())
{
target.RunScriptHookInterface<IScriptChangeIncomingTargets>(x =>
x.ChangeIncomingTargets(moveChoice, ref targets));
}
byte numberOfHits = 1;
moveChoice.RunScriptHook(x => x.ChangeNumberOfHits(moveChoice, ref numberOfHits));
moveChoice.RunScriptHookInterface<IScriptChangeNumberOfHits>(x =>
x.ChangeNumberOfHits(moveChoice, ref numberOfHits));
if (numberOfHits == 0)
{
return;
@@ -72,7 +77,7 @@ public static class MoveTurnExecutor
battle.EventHook.Invoke(new MoveUseEvent(executingMove));
var prevented = false;
executingMove.RunScriptHook(x => x.PreventMove(executingMove, ref prevented));
executingMove.RunScriptHookInterface<IScriptPreventMove>(x => x.PreventMove(executingMove, ref prevented));
if (prevented)
return;
@@ -83,7 +88,7 @@ public static class MoveTurnExecutor
return;
var failed = false;
executingMove.RunScriptHook(x => x.FailMove(executingMove, ref failed));
executingMove.RunScriptHookInterface<IScriptFailMove>(x => x.FailMove(executingMove, ref failed));
if (failed)
{
// TODO: fail handling
@@ -106,16 +111,16 @@ public static class MoveTurnExecutor
public static void ExecuteMove(IExecutingMove executingMove)
{
var stopped = false;
executingMove.RunScriptHook(x => x.StopBeforeMove(executingMove, ref stopped));
executingMove.RunScriptHookInterface<IScriptStopBeforeMove>(x => x.StopBeforeMove(executingMove, ref stopped));
if (stopped)
return;
executingMove.RunScriptHook(x => x.OnBeforeMove(executingMove));
executingMove.RunScriptHookInterface<IScriptOnBeforeMove>(x => x.OnBeforeMove(executingMove));
foreach (var target in executingMove.Targets.WhereNotNull())
{
ExecuteMoveChoiceForTarget(executingMove.Battle, executingMove, target);
}
executingMove.RunScriptHook(x => x.OnAfterMove(executingMove));
executingMove.RunScriptHookInterface<IScriptOnAfterMove>(x => x.OnAfterMove(executingMove));
}
private static void ExecuteMoveChoiceForTarget(IBattle battle, IExecutingMove executingMove, IPokemon 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.RunScriptHook(script => script.OnBeforeTurnStart(choice));
choice.RunScriptHookInterface<IScriptOnBeforeTurnStart>(script => script.OnBeforeTurnStart(choice));
}
// Now we can properly begin executing choices.