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,7 +1,8 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "bind")]
public class BindEffect : Script, IScriptOnEndTurn, IScriptPreventSelfSwitch, IScriptPreventSelfRunAway
public class BindEffect : Script, IScriptOnEndTurn, IScriptPreventSelfSwitch, IScriptPreventSelfRunAway,
IAIInfoScriptExpectedEndOfTurnDamage
{
private readonly IPokemon? _owner;
private int _turns;
@@ -33,4 +34,10 @@ public class BindEffect : Script, IScriptOnEndTurn, IScriptPreventSelfSwitch, IS
/// <inheritdoc />
public void PreventSelfRunAway(IFleeChoice choice, ref bool prevent) => prevent = _turns > 0;
/// <inheritdoc />
public void ExpectedEndOfTurnDamage(IPokemon pokemon, ref int damage)
{
damage += (int)(_owner?.MaxHealth * _percentOfMaxHealth ?? 0);
}
}

View File

@@ -1,7 +1,8 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "fire_spin")]
public class FireSpinEffect : Script, IScriptOnEndTurn, IScriptPreventSelfRunAway, IScriptPreventSelfSwitch
public class FireSpinEffect : Script, IScriptOnEndTurn, IScriptPreventSelfRunAway, IScriptPreventSelfSwitch,
IAIInfoScriptExpectedEndOfTurnDamage
{
private readonly IPokemon _owner;
@@ -21,4 +22,10 @@ public class FireSpinEffect : Script, IScriptOnEndTurn, IScriptPreventSelfRunAwa
/// <inheritdoc />
public void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = true;
/// <inheritdoc />
public void ExpectedEndOfTurnDamage(IPokemon pokemon, ref int damage)
{
damage += (int)(pokemon.MaxHealth / 8f);
}
}

View File

@@ -1,7 +1,7 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "ghostcurse")]
public class GhostCurseEffect : Script, IScriptOnEndTurn
public class GhostCurseEffect : Script, IScriptOnEndTurn, IAIInfoScriptExpectedEndOfTurnDamage
{
private IPokemon _pokemon;
@@ -15,4 +15,10 @@ public class GhostCurseEffect : Script, IScriptOnEndTurn
{
_pokemon.Damage(_pokemon.CurrentHealth / 4, DamageSource.Misc);
}
/// <inheritdoc />
public void ExpectedEndOfTurnDamage(IPokemon pokemon, ref int damage)
{
damage += (int)(_pokemon.CurrentHealth / 4f);
}
}

View File

@@ -1,7 +1,8 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "infestation")]
public class InfestationEffect : Script, IScriptOnEndTurn, IScriptPreventSelfSwitch, IScriptPreventSelfRunAway
public class InfestationEffect : Script, IScriptOnEndTurn, IScriptPreventSelfSwitch, IScriptPreventSelfRunAway,
IAIInfoScriptExpectedEndOfTurnDamage
{
private readonly IPokemon _owner;
private int _turns;
@@ -30,4 +31,10 @@ public class InfestationEffect : Script, IScriptOnEndTurn, IScriptPreventSelfSwi
RemoveSelf();
}
}
/// <inheritdoc />
public void ExpectedEndOfTurnDamage(IPokemon pokemon, ref int damage)
{
damage += (int)(_owner.MaxHealth / 8f);
}
}

View File

@@ -1,7 +1,7 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "leech_seed")]
public class LeechSeedEffect : Script, IScriptOnEndTurn
public class LeechSeedEffect : Script, IScriptOnEndTurn, IAIInfoScriptExpectedEndOfTurnDamage
{
private readonly IPokemon _owner;
private readonly IPokemon _placer;
@@ -15,7 +15,7 @@ public class LeechSeedEffect : Script, IScriptOnEndTurn
/// <inheritdoc />
public void OnEndTurn(IScriptSource owner, IBattle battle)
{
var damage = _owner.BoostedStats.Hp / 8;
var damage = _owner.MaxHealth / 8;
if (_owner.CurrentHealth <= damage)
damage = _owner.CurrentHealth;
@@ -25,4 +25,10 @@ public class LeechSeedEffect : Script, IScriptOnEndTurn
else
_placer.Heal(damage);
}
/// <inheritdoc />
public void ExpectedEndOfTurnDamage(IPokemon pokemon, ref int damage)
{
damage += (int)(_owner.MaxHealth / 8f);
}
}

View File

@@ -1,7 +1,8 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "magma_storm")]
public class MagmaStormEffect : Script, IScriptOnEndTurn, IScriptPreventSelfRunAway, IScriptPreventSelfSwitch
public class MagmaStormEffect : Script, IScriptOnEndTurn, IScriptPreventSelfRunAway, IScriptPreventSelfSwitch,
IAIInfoScriptExpectedEndOfTurnDamage
{
private readonly IPokemon _owner;
@@ -21,4 +22,10 @@ public class MagmaStormEffect : Script, IScriptOnEndTurn, IScriptPreventSelfRunA
/// <inheritdoc />
public void PreventSelfSwitch(ISwitchChoice choice, ref bool prevent) => prevent = true;
/// <inheritdoc />
public void ExpectedEndOfTurnDamage(IPokemon pokemon, ref int damage)
{
damage += (int)(pokemon.MaxHealth / 16f);
}
}

View File

@@ -3,7 +3,7 @@ using PkmnLib.Plugin.Gen7.Scripts.Status;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "nightmare")]
public class NightmareEffect : Script, IScriptOnEndTurn
public class NightmareEffect : Script, IScriptOnEndTurn, IAIInfoScriptExpectedEndOfTurnDamage
{
private readonly IPokemon _owner;
@@ -23,4 +23,10 @@ public class NightmareEffect : Script, IScriptOnEndTurn
var maxHp = _owner.MaxHealth;
_owner.Damage(maxHp / 4, DamageSource.Misc);
}
/// <inheritdoc />
public void ExpectedEndOfTurnDamage(IPokemon pokemon, ref int damage)
{
damage += (int)(_owner.MaxHealth / 4f);
}
}

View File

@@ -3,7 +3,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "substitute")]
public class SubstituteEffect(uint health) : Script, IScriptBlockIncomingHit
{
private uint _health = health;
public uint Health { get; private set; } = health;
/// <inheritdoc />
public void BlockIncomingHit(IExecutingMove executingMove, IPokemon target, byte hitIndex, ref bool block)
@@ -19,12 +19,12 @@ public class SubstituteEffect(uint health) : Script, IScriptBlockIncomingHit
block = true;
var damage = executingMove.GetHitData(target, hitIndex).Damage;
if (damage >= _health)
if (damage >= Health)
{
executingMove.Battle.EventHook.Invoke(new DialogEvent("substitute_broken"));
RemoveSelf();
return;
}
_health -= damage;
Health -= damage;
}
}

View File

@@ -1,7 +1,8 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "whirlpool")]
public class WhirlpoolEffect : Script, IScriptOnEndTurn, IScriptPreventOpponentRunAway, IScriptPreventOpponentSwitch
public class WhirlpoolEffect : Script, IScriptOnEndTurn, IScriptPreventOpponentRunAway, IScriptPreventOpponentSwitch,
IAIInfoScriptExpectedEndOfTurnDamage
{
public record PokemonTurn
{
@@ -80,4 +81,14 @@ public class WhirlpoolEffect : Script, IScriptOnEndTurn, IScriptPreventOpponentR
_targetedPokemon.Remove(turn);
}
}
/// <inheritdoc />
public void ExpectedEndOfTurnDamage(IPokemon pokemon, ref int damage)
{
var turn = _targetedPokemon.FirstOrDefault(x => x.Pokemon == pokemon);
if (turn != null)
{
damage += (int)(pokemon.MaxHealth * turn.DamagePercent);
}
}
}