Support for changing turn choice when executing
All checks were successful
Build / Build (push) Successful in 50s

This commit is contained in:
Deukhoofd 2025-06-15 14:23:28 +02:00
parent b11203cb3a
commit e305cfaef6
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
23 changed files with 34 additions and 28 deletions

View File

@ -77,6 +77,7 @@ public static class TurnRunner
/// </summary> /// </summary>
public static void ExecuteChoice(IBattle battle, ITurnChoice choice) public static void ExecuteChoice(IBattle battle, ITurnChoice choice)
{ {
choice.RunScriptHook(x => x.ChangeTurnChoice(ref choice));
if (choice is IPassChoice) if (choice is IPassChoice)
return; return;
if (battle.HasEnded) if (battle.HasEnded)

View File

@ -296,7 +296,7 @@ public class BattleImpl : ScriptSource, IBattle
ITurnChoice? forcedChoice = null; ITurnChoice? forcedChoice = null;
pokemon.RunScriptHook(script => pokemon.RunScriptHook(script =>
script.ForceTurnSelection(battleData.SideIndex, battleData.Position, ref forcedChoice)); script.ForceTurnSelection(this, battleData.SideIndex, battleData.Position, ref forcedChoice));
choice = forcedChoice; choice = forcedChoice;
return choice != null; return choice != null;
} }

View File

@ -115,7 +115,7 @@ public abstract class Script : IDeepCloneable
/// Force a certain move choice to be selected. If the choice is set, the Pokemon will be forced /// Force a certain move choice to be selected. If the choice is set, the Pokemon will be forced
/// to use it, and will not be able to select any other choice. /// to use it, and will not be able to select any other choice.
/// </summary> /// </summary>
public virtual void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public virtual void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
} }
@ -302,7 +302,7 @@ public abstract class Script : IDeepCloneable
/// This function allows a script to change the damage modifier of a Same Type Attack Bonus, which /// This function allows a script to change the damage modifier of a Same Type Attack Bonus, which
/// occurs when the user has the move type as one of its own types. /// occurs when the user has the move type as one of its own types.
/// </summary> /// </summary>
public virtual void ChangeStabModifier(IExecutingMove executingMove, IPokemon target, byte hitNumber, public virtual void ChangeStabModifier(IExecutingMove executingMove, IPokemon target, byte hitNumber, bool isStab,
ref float modifier) ref float modifier)
{ {
} }
@ -851,4 +851,8 @@ public abstract class Script : IDeepCloneable
public virtual void OnAfterMoveChoice(IMoveChoice moveChoice) public virtual void OnAfterMoveChoice(IMoveChoice moveChoice)
{ {
} }
public virtual void ChangeTurnChoice(ref ITurnChoice choice)
{
}
} }

View File

@ -44,13 +44,16 @@ public class Gen7DamageCalculator(Gen7PluginConfiguration configuration) : IDama
floatDamage = MathF.Floor(floatDamage * randomFactor); floatDamage = MathF.Floor(floatDamage * randomFactor);
} }
var stabModifier = 1.0f;
var isStab = false;
if (hitData.Type != null && executingMove.User.Types.Contains(hitData.Type.Value)) if (hitData.Type != null && executingMove.User.Types.Contains(hitData.Type.Value))
{ {
var stabModifier = 1.5f; stabModifier = 1.5f;
executingMove.RunScriptHook(script => isStab = true;
script.ChangeStabModifier(executingMove, target, hitNumber, ref stabModifier));
floatDamage = MathF.Floor(floatDamage * stabModifier);
} }
executingMove.RunScriptHook(script =>
script.ChangeStabModifier(executingMove, target, hitNumber, isStab, ref stabModifier));
floatDamage = MathF.Floor(floatDamage * stabModifier);
floatDamage = MathF.Floor(floatDamage * hitData.Effectiveness); floatDamage = MathF.Floor(floatDamage * hitData.Effectiveness);
uint damage = floatDamage switch uint damage = floatDamage switch

View File

@ -10,10 +10,10 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
public class IncreasedStab : Script public class IncreasedStab : Script
{ {
/// <inheritdoc /> /// <inheritdoc />
public override void ChangeStabModifier(IExecutingMove executingMove, IPokemon target, byte hitNumber, public override void ChangeStabModifier(IExecutingMove executingMove, IPokemon target, byte hitNumber, bool isStab,
ref float modifier) ref float modifier)
{ {
if (!modifier.IsApproximatelyEqualTo(1.5f)) if (!isStab || !modifier.IsApproximatelyEqualTo(1.5f))
return; return;
executingMove.Battle.EventHook.Invoke(new AbilityTriggerEvent(executingMove.User)); executingMove.Battle.EventHook.Invoke(new AbilityTriggerEvent(executingMove.User));
modifier = 2.0f; modifier = 2.0f;

View File

@ -15,7 +15,7 @@ public abstract class BaseChargeEffect : Script
} }
/// <inheritdoc /> /// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public override void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0); var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0);
choice = TurnChoiceHelper.CreateMoveChoice(_owner, _moveName, opposingSideIndex, position); choice = TurnChoiceHelper.CreateMoveChoice(_owner, _moveName, opposingSideIndex, position);

View File

@ -34,7 +34,7 @@ public class BideEffect : Script
private ITurnChoice? _choice; private ITurnChoice? _choice;
/// <inheritdoc /> /// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public override void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
if (_owner == null) if (_owner == null)
return; return;

View File

@ -13,7 +13,7 @@ public class ChargeBounceEffect : Script
} }
/// <inheritdoc /> /// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public override void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0); var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0);
choice = TurnChoiceHelper.CreateMoveChoice(_owner, "bounce", opposingSideIndex, position); choice = TurnChoiceHelper.CreateMoveChoice(_owner, "bounce", opposingSideIndex, position);

View File

@ -13,7 +13,7 @@ public class ChargeFlyEffect : Script
} }
/// <inheritdoc /> /// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public override void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0); var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0);
choice = TurnChoiceHelper.CreateMoveChoice(_owner, "fly", opposingSideIndex, position); choice = TurnChoiceHelper.CreateMoveChoice(_owner, "fly", opposingSideIndex, position);

View File

@ -20,7 +20,7 @@ public class ChargeMoveEffect : Script
} }
/// <inheritdoc /> /// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public override void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
choice = TurnChoiceHelper.CreateMoveChoice(_user, MoveName, _targetSide, _targetPosition); choice = TurnChoiceHelper.CreateMoveChoice(_user, MoveName, _targetSide, _targetPosition);
} }

View File

@ -13,7 +13,7 @@ public class ChargeSkyDropEffect : Script
} }
/// <inheritdoc /> /// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public override void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0); var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0);
choice = TurnChoiceHelper.CreateMoveChoice(_owner, "sky_drop", opposingSideIndex, position); choice = TurnChoiceHelper.CreateMoveChoice(_owner, "sky_drop", opposingSideIndex, position);

View File

@ -13,7 +13,7 @@ public class DigEffect : Script
} }
/// <inheritdoc /> /// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public override void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0); var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0);
choice = TurnChoiceHelper.CreateMoveChoice(_owner, "dig", opposingSideIndex, position); choice = TurnChoiceHelper.CreateMoveChoice(_owner, "dig", opposingSideIndex, position);

View File

@ -13,7 +13,7 @@ public class DiveEffect : Script
} }
/// <inheritdoc /> /// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public override void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0); var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0);
choice = TurnChoiceHelper.CreateMoveChoice(_owner, "dive", opposingSideIndex, position); choice = TurnChoiceHelper.CreateMoveChoice(_owner, "dive", opposingSideIndex, position);

View File

@ -18,7 +18,7 @@ public class EncoreEffect : Script
} }
/// <inheritdoc /> /// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public override void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0); var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0);
choice = TurnChoiceHelper.CreateMoveChoice(_owner, _move, opposingSideIndex, position); choice = TurnChoiceHelper.CreateMoveChoice(_owner, _move, opposingSideIndex, position);

View File

@ -18,7 +18,7 @@ public class IceBallEffect : Script
} }
/// <inheritdoc /> /// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public override void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0); var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0);
choice = TurnChoiceHelper.CreateMoveChoice(_owner, _moveName, opposingSideIndex, position); choice = TurnChoiceHelper.CreateMoveChoice(_owner, _moveName, opposingSideIndex, position);

View File

@ -21,7 +21,7 @@ public abstract class OutrageLikeEffect : Script
} }
/// <inheritdoc /> /// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public override void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
choice = TurnChoiceHelper.CreateMoveChoice(_owner, _move, _targetSide, _targetPosition); choice = TurnChoiceHelper.CreateMoveChoice(_owner, _move, _targetSide, _targetPosition);
} }

View File

@ -13,7 +13,7 @@ public class PhantomForceCharge : Script
} }
/// <inheritdoc /> /// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public override void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0); var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0);
choice = TurnChoiceHelper.CreateMoveChoice(_owner, "phantom_force", opposingSideIndex, position); choice = TurnChoiceHelper.CreateMoveChoice(_owner, "phantom_force", opposingSideIndex, position);

View File

@ -11,7 +11,7 @@ public class RequiresRechargeEffect : Script
} }
/// <inheritdoc /> /// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public override void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
choice = new PassChoice(_owner); choice = new PassChoice(_owner);
} }

View File

@ -13,7 +13,7 @@ public class ShadowForceCharge : Script
} }
/// <inheritdoc /> /// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public override void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0); var opposingSideIndex = (byte)(_owner.BattleData?.SideIndex == 0 ? 1 : 0);
choice = TurnChoiceHelper.CreateMoveChoice(_owner, "shadow_force", opposingSideIndex, position); choice = TurnChoiceHelper.CreateMoveChoice(_owner, "shadow_force", opposingSideIndex, position);

View File

@ -13,7 +13,7 @@ public class SkullBashEffect : Script
} }
/// <inheritdoc /> /// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public override void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
choice = TurnChoiceHelper.CreateMoveChoice(_owner, "skull_bash", sideIndex, position); choice = TurnChoiceHelper.CreateMoveChoice(_owner, "skull_bash", sideIndex, position);
} }

View File

@ -13,7 +13,7 @@ public class SkyAttackEffect : Script
} }
/// <inheritdoc /> /// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public override void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
choice = TurnChoiceHelper.CreateMoveChoice(_owner, "sky_attack", sideIndex, position); choice = TurnChoiceHelper.CreateMoveChoice(_owner, "sky_attack", sideIndex, position);
} }

View File

@ -3,7 +3,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
public class TruantEffect(IPokemon owner) : Script public class TruantEffect(IPokemon owner) : Script
{ {
/// <inheritdoc /> /// <inheritdoc />
public override void ForceTurnSelection(byte sideIndex, byte position, ref ITurnChoice? choice) public override void ForceTurnSelection(IBattle battle, byte sideIndex, byte position, ref ITurnChoice? choice)
{ {
choice = new PassChoice(owner); choice = new PassChoice(owner);
} }

View File

@ -1,5 +1,3 @@
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Utils; namespace PkmnLib.Plugin.Gen7.Scripts.Utils;
public static class TurnChoiceHelper public static class TurnChoiceHelper