Bunch more moves, changes in how additional information for items works.

This commit is contained in:
2025-04-14 15:29:26 +02:00
parent 2adbb12367
commit 7c2845502d
60 changed files with 4275 additions and 963 deletions

View File

@@ -11,18 +11,18 @@ internal static class MoveTurnExecutor
internal static void ExecuteMoveChoice(IBattle battle, IMoveChoice moveChoice)
{
var chosenMove = moveChoice.ChosenMove;
var moveData = chosenMove.MoveData;
var useMove = chosenMove.MoveData;
var moveDataName = moveData.Name;
var moveDataName = useMove.Name;
moveChoice.RunScriptHook(x => x.ChangeMove(moveChoice, ref moveDataName));
if (moveData.Name != moveDataName)
if (useMove.Name != moveDataName)
{
if (!battle.Library.StaticLibrary.Moves.TryGet(moveDataName, out moveData))
if (!battle.Library.StaticLibrary.Moves.TryGet(moveDataName, out useMove))
{
throw new InvalidOperationException(
$"The move was changed to '{moveDataName}' by a script, but this move does not exist.");
}
var secondaryEffect = moveData.SecondaryEffect;
var secondaryEffect = useMove.SecondaryEffect;
if (secondaryEffect != null)
{
if (moveChoice.User.Library.ScriptResolver.TryResolve(ScriptCategory.Move, secondaryEffect.Name,
@@ -30,10 +30,18 @@ internal static class MoveTurnExecutor
{
moveChoice.Script.Set(script);
}
else
{
moveChoice.Script.Clear();
}
}
else
{
moveChoice.Script.Clear();
}
}
var targetType = moveData.Target;
var targetType = useMove.Target;
var targets =
TargetResolver.ResolveTargets(battle, moveChoice.TargetSide, moveChoice.TargetPosition, targetType);
moveChoice.RunScriptHook(x => x.ChangeTargets(moveChoice, ref targets));
@@ -45,7 +53,7 @@ internal static class MoveTurnExecutor
return;
}
var executingMove = new ExecutingMoveImpl(targets, numberOfHits, chosenMove, moveData, moveChoice);
var executingMove = new ExecutingMoveImpl(targets, numberOfHits, chosenMove, useMove, moveChoice);
var prevented = false;
executingMove.RunScriptHook(x => x.PreventMove(executingMove, ref prevented));
@@ -117,8 +125,14 @@ internal static class MoveTurnExecutor
var hitData = (HitData)executingMove.GetDataFromRawIndex(targetHitStat + i);
hitData.Type = hitType;
var effectiveness = battle.Library.StaticLibrary.Types.GetEffectiveness(hitType, target.Types);
var types = target.Types.ToList();
executingMove.RunScriptHook(x => x.ChangeTypesForMove(executingMove, target, hitIndex, types));
target.RunScriptHook(x => x.ChangeTypesForIncomingMove(executingMove, target, hitIndex, types));
var effectiveness = battle.Library.StaticLibrary.Types.GetEffectiveness(hitType, types);
executingMove.RunScriptHook(x => x.ChangeEffectiveness(executingMove, target, hitIndex, ref effectiveness));
target.RunScriptHook(x =>
x.ChangeIncomingEffectiveness(executingMove, target, hitIndex, ref effectiveness));
hitData.Effectiveness = effectiveness;
var blockCritical = false;

View File

@@ -235,6 +235,7 @@ public class BattleSideImpl : ScriptSource, IBattleSide
var oldPokemon = _pokemon[position];
if (oldPokemon is not null)
{
oldPokemon.RunScriptHook(script => script.OnSwitchOut(oldPokemon, position));
oldPokemon.RunScriptHook(script => script.OnRemove());
oldPokemon.SetOnBattlefield(false);
}

View File

@@ -183,6 +183,8 @@ public class ExecutingMoveImpl : ScriptSource, IExecutingMove
/// <inheritdoc />
public ScriptContainer Script => MoveChoice.Script;
public IScriptSet Volatile => MoveChoice.Volatile;
/// <inheritdoc />
public IHitData GetHitData(IPokemon target, byte hit)
{
@@ -224,18 +226,19 @@ public class ExecutingMoveImpl : ScriptSource, IExecutingMove
public IMoveChoice MoveChoice { get; }
/// <inheritdoc />
public override int ScriptCount => 1 + User.ScriptCount;
public override int ScriptCount => 2 + User.ScriptCount;
/// <inheritdoc />
public override void GetOwnScripts(List<IEnumerable<ScriptContainer>> scripts)
{
scripts.Add(Volatile);
scripts.Add(Script);
}
/// <inheritdoc />
public override void CollectScripts(List<IEnumerable<ScriptContainer>> scripts)
{
scripts.Add(Script);
GetOwnScripts(scripts);
User.CollectScripts(scripts);
}
}