Further work on the script interface rework

This commit is contained in:
2025-07-05 11:30:18 +02:00
parent 1feb27e826
commit 4499927551
100 changed files with 418 additions and 352 deletions

View File

@@ -261,7 +261,7 @@ public class BattleSideImpl : ScriptSource, IBattleSide
var oldPokemon = _pokemon[position];
if (oldPokemon is not null)
{
oldPokemon.RunScriptHook(script => script.OnSwitchOut(oldPokemon, position));
oldPokemon.RunScriptHookInterface<IScriptOnSwitchOut>(script => script.OnSwitchOut(oldPokemon, position));
oldPokemon.RunScriptHook(script => script.OnRemove());
oldPokemon.SetOnBattlefield(false);
}
@@ -272,7 +272,7 @@ public class BattleSideImpl : ScriptSource, IBattleSide
pokemon.SetOnBattlefield(true);
pokemon.SetBattleSidePosition(position);
Battle.EventHook.Invoke(new SwitchEvent(Index, position, pokemon));
pokemon.RunScriptHook(script => script.OnSwitchIn(pokemon, position));
pokemon.RunScriptHookInterface<IScriptOnSwitchIn>(script => script.OnSwitchIn(pokemon, position));
foreach (var side in Battle.Sides)
{
@@ -286,9 +286,11 @@ public class BattleSideImpl : ScriptSource, IBattleSide
scripts.Clear();
opponent.GetOwnScripts(scripts);
opponent.RunScriptHook(script => script.OnOpponentSwitchIn(pokemon, position));
opponent.RunScriptHookInterface<IScriptOnOpponentSwitchIn>(script =>
script.OnOpponentSwitchIn(pokemon, position));
}
side.RunScriptHook(script => script.OnOpponentSwitchIn(pokemon, position));
side.RunScriptHookInterface<IScriptOnOpponentSwitchIn>(script =>
script.OnOpponentSwitchIn(pokemon, position));
}
}
else

View File

@@ -861,7 +861,8 @@ public class PokemonImpl : ScriptSource, IPokemon
if (BattleData != null)
{
var prevented = false;
this.RunScriptHook(script => script.PreventHeldItemConsume(this, HeldItem, ref prevented));
this.RunScriptHookInterface<IScriptPreventHeldItemConsume>(script =>
script.PreventHeldItemConsume(this, HeldItem, ref prevented));
if (prevented)
return false;
BattleData.MarkItemAsConsumed(HeldItem);
@@ -879,7 +880,7 @@ public class PokemonImpl : ScriptSource, IPokemon
{
// TODO: actually consume the item
this.RunScriptHook(x => x.OnAfterItemConsume(this, item));
this.RunScriptHookInterface<IScriptOnAfterItemConsume>(x => x.OnAfterItemConsume(this, item));
}
/// <inheritdoc />
@@ -1055,7 +1056,8 @@ public class PokemonImpl : ScriptSource, IPokemon
if (BattleData is not null && !forceDamage)
{
var dmg = damage;
this.RunScriptHook(script => script.ChangeIncomingDamage(this, source, ref dmg));
this.RunScriptHookInterface<IScriptChangeIncomingDamage>(script =>
script.ChangeIncomingDamage(this, source, ref dmg));
damage = dmg;
}
if (damage == 0)
@@ -1075,7 +1077,8 @@ public class PokemonImpl : ScriptSource, IPokemon
BatchId = batchId,
});
// And allow scripts to execute.
this.RunScriptHook(script => script.OnDamage(this, source, CurrentHealth, newHealth));
this.RunScriptHookInterface<IScriptOnDamage>(script =>
script.OnDamage(this, source, CurrentHealth, newHealth));
}
CurrentHealth = newHealth;
@@ -1104,10 +1107,10 @@ public class PokemonImpl : ScriptSource, IPokemon
BattleData.Battle.EventHook.Invoke(new FaintEvent(this));
// Allow scripts to trigger based on the faint.
this.RunScriptHook(script => script.OnFaint(this, source));
this.RunScriptHookInterface<IScriptOnFaint>(script => script.OnFaint(this, source));
foreach (var ally in BattleData.BattleSide.Pokemon.WhereNotNull().Where(x => x != this))
{
ally.RunScriptHook(script => script.OnAllyFaint(ally, this));
ally.RunScriptHookInterface<IScriptOnAllyFaint>(script => script.OnAllyFaint(ally, this));
}
// Make sure the OnRemove script is run.