Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper
This commit is contained in:
@@ -16,7 +16,7 @@ public class Burned : Script, IScriptChangeMoveDamage, IScriptOnEndTurn, IAIInfo
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
|
||||
public void ChangeMoveDamage(IExecutingMove move, IBattlePokemon target, byte hit, ref uint damage)
|
||||
{
|
||||
if (move.UseMove.Category == MoveCategory.Physical)
|
||||
{
|
||||
@@ -43,7 +43,7 @@ public class Burned : Script, IScriptChangeMoveDamage, IScriptOnEndTurn, IAIInfo
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ExpectedEndOfTurnDamage(IPokemon pokemon, ref int damage)
|
||||
public void ExpectedEndOfTurnDamage(IBattlePokemon pokemon, ref int damage)
|
||||
{
|
||||
if (_target != null)
|
||||
damage += (int)(_target.MaxHealth / 16f);
|
||||
|
||||
@@ -41,10 +41,12 @@ public class Frozen : Script, IScriptPreventMove, IScriptOnEndTurn
|
||||
/// <inheritdoc />
|
||||
public override void OnRemove()
|
||||
{
|
||||
_pokemon?.BattleData?.Battle.EventHook.Invoke(new DialogEvent("pokemon_thawed_out",
|
||||
new Dictionary<string, object>
|
||||
if (_pokemon is IBattlePokemon battlePokemon)
|
||||
{
|
||||
battlePokemon.Battle.EventHook.Invoke(new DialogEvent("pokemon_thawed_out", new Dictionary<string, object>
|
||||
{
|
||||
{ "pokemon", _pokemon },
|
||||
{ "pokemon", battlePokemon },
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,12 +27,13 @@ public class Poisoned : Script, IScriptOnEndTurn, IAIInfoScriptExpectedEndOfTurn
|
||||
if (damage == 0)
|
||||
damage = 1;
|
||||
|
||||
var battleData = _pokemon.BattleData;
|
||||
var args = new CustomTriggers.PoisonedDamageArgs(_pokemon, damage);
|
||||
if (_pokemon is not IBattlePokemon battlePokemon)
|
||||
return;
|
||||
var args = new CustomTriggers.PoisonedDamageArgs(battlePokemon, damage);
|
||||
_pokemon.RunScriptHook<IScriptCustomTrigger>(x => x.CustomTrigger(CustomTriggers.PoisonedDamage, args));
|
||||
|
||||
var eventBatchId = new EventBatchId();
|
||||
battleData?.Battle.EventHook.Invoke(new DialogEvent("poisoned_damage", new Dictionary<string, object>
|
||||
battle.EventHook.Invoke(new DialogEvent("poisoned_damage", new Dictionary<string, object>
|
||||
{
|
||||
{ "pokemon", _pokemon },
|
||||
{ "damage", damage },
|
||||
@@ -48,7 +49,7 @@ public class Poisoned : Script, IScriptOnEndTurn, IAIInfoScriptExpectedEndOfTurn
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void ExpectedEndOfTurnDamage(IPokemon pokemon, ref int damage)
|
||||
public virtual void ExpectedEndOfTurnDamage(IBattlePokemon pokemon, ref int damage)
|
||||
{
|
||||
if (_pokemon != null)
|
||||
damage += (int)(_pokemon.MaxHealth * GetPoisonMultiplier());
|
||||
|
||||
@@ -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 },
|
||||
|
||||
Reference in New Issue
Block a user