Implement stat drop handling for AI, Fixes for Conversion2
All checks were successful
Build / Build (push) Successful in 39s

This commit is contained in:
2026-05-23 12:57:15 +02:00
parent a5ef757b01
commit be5100df8a
5 changed files with 286 additions and 8 deletions

View File

@@ -1,3 +1,6 @@
using PkmnLib.Dynamic.AI.Explicit;
using PkmnLib.Plugin.Gen7.AI;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
public abstract class ChangeTargetStats : Script, IScriptOnInitialize, IScriptOnSecondaryEffect
@@ -31,6 +34,19 @@ public abstract class ChangeTargetStats : Script, IScriptOnInitialize, IScriptOn
{
target.ChangeStatBoost(_stat, _amount, target == move.User, false);
}
protected static void GetMoveEffectScore(MoveOption option, Statistic stat, ref int score)
{
if (option.Move.Move.SecondaryEffect == null ||
!option.Move.Move.SecondaryEffect.Parameters.TryGetValue("amount", out var amountObj) ||
amountObj is not int amount)
{
return;
}
var statisticSet = new StatBoostStatisticSet();
statisticSet.SetStatistic(stat, (sbyte)amount);
score = AIHelperFunctions.GetScoreForTargetStatDrop(score, option.Move, option.Move.User, statisticSet);
}
}
[Script(ScriptCategory.Move, "change_target_attack")]
@@ -39,6 +55,10 @@ public class ChangeTargetAttack : ChangeTargetStats
public ChangeTargetAttack() : base(Statistic.Attack)
{
}
[AIMoveScoreFunction]
public static void AIMoveEffectScore(IExplicitAI ai, MoveOption option, ref int score) =>
GetMoveEffectScore(option, Statistic.Attack, ref score);
}
[Script(ScriptCategory.Move, "change_target_defense")]
@@ -47,6 +67,10 @@ public class ChangeTargetDefense : ChangeTargetStats
public ChangeTargetDefense() : base(Statistic.Defense)
{
}
[AIMoveScoreFunction]
public static void AIMoveEffectScore(IExplicitAI ai, MoveOption option, ref int score) =>
GetMoveEffectScore(option, Statistic.Defense, ref score);
}
[Script(ScriptCategory.Move, "change_target_special_attack")]
@@ -55,6 +79,10 @@ public class ChangeTargetSpecialAttack : ChangeTargetStats
public ChangeTargetSpecialAttack() : base(Statistic.SpecialAttack)
{
}
[AIMoveScoreFunction]
public static void AIMoveEffectScore(IExplicitAI ai, MoveOption option, ref int score) =>
GetMoveEffectScore(option, Statistic.SpecialAttack, ref score);
}
[Script(ScriptCategory.Move, "change_target_special_defense")]
@@ -63,6 +91,10 @@ public class ChangeTargetSpecialDefense : ChangeTargetStats
public ChangeTargetSpecialDefense() : base(Statistic.SpecialDefense)
{
}
[AIMoveScoreFunction]
public static void AIMoveEffectScore(IExplicitAI ai, MoveOption option, ref int score) =>
GetMoveEffectScore(option, Statistic.SpecialDefense, ref score);
}
[Script(ScriptCategory.Move, "change_target_speed")]
@@ -71,6 +103,10 @@ public class ChangeTargetSpeed : ChangeTargetStats
public ChangeTargetSpeed() : base(Statistic.Speed)
{
}
[AIMoveScoreFunction]
public static void AIMoveEffectScore(IExplicitAI ai, MoveOption option, ref int score) =>
GetMoveEffectScore(option, Statistic.Speed, ref score);
}
[Script(ScriptCategory.Move, "change_target_accuracy")]
@@ -79,6 +115,10 @@ public class ChangeTargetAccuracy : ChangeTargetStats
public ChangeTargetAccuracy() : base(Statistic.Accuracy)
{
}
[AIMoveScoreFunction]
public static void AIMoveEffectScore(IExplicitAI ai, MoveOption option, ref int score) =>
GetMoveEffectScore(option, Statistic.Accuracy, ref score);
}
[Script(ScriptCategory.Move, "change_target_evasion")]
@@ -87,4 +127,8 @@ public class ChangeTargetEvasion : ChangeTargetStats
public ChangeTargetEvasion() : base(Statistic.Evasion)
{
}
[AIMoveScoreFunction]
public static void AIMoveEffectScore(IExplicitAI ai, MoveOption option, ref int score) =>
GetMoveEffectScore(option, Statistic.Evasion, ref score);
}