Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper

This commit is contained in:
2026-08-28 15:20:26 +02:00
parent 942be8eaeb
commit 8a2733a0a9
859 changed files with 4408 additions and 5331 deletions

View File

@@ -9,18 +9,18 @@ public class Sleep : Script, IScriptChangeNumberOfHits, IAIInfoScriptNumberTurns
/// <inheritdoc />
public override void OnAddedToParent(IScriptSource source)
{
// Rare case where the script is added again. Can happen for example when baton pass is used.
if (Turns != 0)
return;
if (source is not IPokemon pokemon)
throw new InvalidOperationException("Sleep script can only be added to a Pokemon.");
_pokemon = pokemon;
var battleData = pokemon.BattleData;
if (battleData != null)
// Rare case where the script is added again. Can happen for example when baton pass is used, or when
// an existing status is re-parented to the battle wrapper at the start of a battle.
if (Turns != 0)
return;
if (pokemon is IBattlePokemon battlePokemon)
{
// 1-3 turns of sleep
Turns = battleData.Battle.Random.GetInt(1, 4);
var args = new CustomTriggers.ModifySleepTurnsArgs(pokemon, Turns);
Turns = battlePokemon.Battle.Random.GetInt(1, 4);
var args = new CustomTriggers.ModifySleepTurnsArgs(battlePokemon, Turns);
source.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.ModifySleepTurns, args));
Turns = Math.Max(1, args.Turns);
}
@@ -55,7 +55,7 @@ public class Sleep : Script, IScriptChangeNumberOfHits, IAIInfoScriptNumberTurns
{
if (_pokemon is { IsFainted: false })
{
_pokemon.BattleData?.Battle.EventHook.Invoke(new DialogEvent("pokemon_woke_up",
(_pokemon as IBattlePokemon)?.Battle.EventHook.Invoke(new DialogEvent("pokemon_woke_up",
new Dictionary<string, object>
{
{ "pokemon", _pokemon },