Getting started with implementing an explicit AI, based on the Essentials one.
All checks were successful
Build / Build (push) Successful in 1m2s

This commit is contained in:
2025-07-11 17:03:08 +02:00
parent 084ae84130
commit a3a4993407
56 changed files with 2687 additions and 1274 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 ChangeUserStats : Script, IScriptOnInitialize, IScriptOnSecondaryEffect
@@ -31,6 +34,19 @@ public abstract class ChangeUserStats : Script, IScriptOnInitialize, IScriptOnSe
{
move.User.ChangeStatBoost(_stat, _amount, true, 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.GetScoreForTargetStatRaise(score, option.Move, option.Move.User, statisticSet);
}
}
[Script(ScriptCategory.Move, "change_user_attack")]
@@ -39,6 +55,10 @@ public class ChangeUserAttack : ChangeUserStats
public ChangeUserAttack() : base(Statistic.Attack)
{
}
[AIMoveScoreFunction]
public static void AIMoveEffectScore(MoveOption option, ref int score) =>
GetMoveEffectScore(option, Statistic.Attack, ref score);
}
[Script(ScriptCategory.Move, "change_user_defense")]
@@ -47,6 +67,10 @@ public class ChangeUserDefense : ChangeUserStats
public ChangeUserDefense() : base(Statistic.Defense)
{
}
[AIMoveScoreFunction]
public static void AIMoveEffectScore(MoveOption option, ref int score) =>
GetMoveEffectScore(option, Statistic.Defense, ref score);
}
[Script(ScriptCategory.Move, "change_user_special_attack")]
@@ -55,6 +79,10 @@ public class ChangeUserSpecialAttack : ChangeUserStats
public ChangeUserSpecialAttack() : base(Statistic.SpecialAttack)
{
}
[AIMoveScoreFunction]
public static void AIMoveEffectScore(MoveOption option, ref int score) =>
GetMoveEffectScore(option, Statistic.SpecialAttack, ref score);
}
[Script(ScriptCategory.Move, "change_user_special_defense")]
@@ -63,6 +91,10 @@ public class ChangeUserSpecialDefense : ChangeUserStats
public ChangeUserSpecialDefense() : base(Statistic.SpecialDefense)
{
}
[AIMoveScoreFunction]
public static void AIMoveEffectScore(MoveOption option, ref int score) =>
GetMoveEffectScore(option, Statistic.SpecialDefense, ref score);
}
[Script(ScriptCategory.Move, "change_user_speed")]
@@ -71,6 +103,10 @@ public class ChangeUserSpeed : ChangeUserStats
public ChangeUserSpeed() : base(Statistic.Speed)
{
}
[AIMoveScoreFunction]
public static void AIMoveEffectScore(MoveOption option, ref int score) =>
GetMoveEffectScore(option, Statistic.Speed, ref score);
}
[Script(ScriptCategory.Move, "change_user_accuracy")]
@@ -79,6 +115,10 @@ public class ChangeUserAccuracy : ChangeUserStats
public ChangeUserAccuracy() : base(Statistic.Accuracy)
{
}
[AIMoveScoreFunction]
public static void AIMoveEffectScore(MoveOption option, ref int score) =>
GetMoveEffectScore(option, Statistic.Accuracy, ref score);
}
[Script(ScriptCategory.Move, "change_user_evasion")]
@@ -87,4 +127,8 @@ public class ChangeUserEvasion : ChangeUserStats
public ChangeUserEvasion() : base(Statistic.Evasion)
{
}
[AIMoveScoreFunction]
public static void AIMoveEffectScore(MoveOption option, ref int score) =>
GetMoveEffectScore(option, Statistic.Evasion, ref score);
}

View File

@@ -13,11 +13,13 @@ public class MirrorMove : Script, IScriptChangeMove
return;
var battle = battleData.Battle;
var currentTurn = battle.ChoiceQueue!.LastRanChoice;
if (battle.ChoiceQueue == null)
return;
var currentTurn = battle.ChoiceQueue.LastRanChoice;
var lastMove = battle.PreviousTurnChoices.SelectMany(x => x).OfType<IMoveChoice>()
.TakeWhile(x => x != currentTurn).LastOrDefault(x => x.TargetPosition == choice.TargetPosition &&
x.TargetSide == choice.TargetSide &&
x.User.BattleData?.IsOnBattlefield == true);
.TakeWhile(x => !Equals(x, currentTurn)).LastOrDefault(x => x.TargetPosition == choice.TargetPosition &&
x.TargetSide == choice.TargetSide &&
x.User.BattleData?.IsOnBattlefield == true);
if (lastMove == null || !lastMove.ChosenMove.MoveData.CanCopyMove())
{
choice.Fail();