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

@@ -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;
}
}