Implements AI Switching
All checks were successful
Build / Build (push) Successful in 58s

This commit is contained in:
2025-07-12 13:03:00 +02:00
parent 364d4b9080
commit bf83b25238
34 changed files with 903 additions and 226 deletions

View File

@@ -1,7 +1,7 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Side;
[Script(ScriptCategory.Side, "spikes")]
public class SpikesEffect : Script, IScriptOnSwitchIn, IScriptStack
public class SpikesEffect : Script, IScriptOnSwitchIn, IScriptStack, IAIInfoScriptExpectedEntryDamage
{
private int _layers = 1;
@@ -18,14 +18,7 @@ public class SpikesEffect : Script, IScriptOnSwitchIn, IScriptStack
if (pokemon.IsFloating)
return;
var modifier = _layers switch
{
1 => 1 / 16f,
2 => 3 / 16f,
3 => 1 / 4f,
_ => throw new ArgumentOutOfRangeException(),
};
var damage = (uint)(pokemon.MaxHealth * modifier);
var damage = CalculateDamage(pokemon);
EventBatchId eventBatch = new();
pokemon.Damage(damage, DamageSource.Misc, eventBatch);
@@ -37,4 +30,26 @@ public class SpikesEffect : Script, IScriptOnSwitchIn, IScriptStack
BatchId = eventBatch,
});
}
private uint CalculateDamage(IPokemon pokemon)
{
var modifier = _layers switch
{
1 => 1 / 16f,
2 => 3 / 16f,
3 => 1 / 4f,
_ => throw new ArgumentOutOfRangeException(),
};
var damage = (uint)(pokemon.MaxHealth * modifier);
return damage;
}
/// <inheritdoc />
public void ExpectedEntryDamage(IPokemon pokemon, ref uint damage)
{
if (pokemon.IsFloating)
return;
damage += CalculateDamage(pokemon);
}
}

View File

@@ -1,18 +1,12 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Side;
[Script(ScriptCategory.Side, "stealth_rock")]
public class StealthRockEffect : Script, IScriptOnSwitchIn
public class StealthRockEffect : Script, IScriptOnSwitchIn, IAIInfoScriptExpectedEntryDamage
{
/// <inheritdoc />
public void OnSwitchIn(IPokemon pokemon, byte position)
{
var typeLibrary = pokemon.Library.StaticLibrary.Types;
var effectiveness = 1.0f;
if (typeLibrary.TryGetTypeIdentifier("rock", out var rockType))
{
effectiveness = typeLibrary.GetEffectiveness(rockType, pokemon.Types);
}
var damage = (uint)(pokemon.MaxHealth / 8f * effectiveness);
var damage = CalculateStealthRockDamage(pokemon);
EventBatchId batchId = new();
pokemon.Damage(damage, DamageSource.Misc, batchId);
pokemon.BattleData?.Battle.EventHook.Invoke(new DialogEvent("stealth_rock_damage",
@@ -21,4 +15,21 @@ public class StealthRockEffect : Script, IScriptOnSwitchIn
{ "pokemon", pokemon },
}));
}
private static uint CalculateStealthRockDamage(IPokemon pokemon)
{
var typeLibrary = pokemon.Library.StaticLibrary.Types;
var effectiveness = 1.0f;
if (typeLibrary.TryGetTypeIdentifier("rock", out var rockType))
{
effectiveness = typeLibrary.GetEffectiveness(rockType, pokemon.Types);
}
return (uint)(pokemon.MaxHealth / 8f * effectiveness);
}
/// <inheritdoc />
public void ExpectedEntryDamage(IPokemon pokemon, ref uint damage)
{
damage += CalculateStealthRockDamage(pokemon);
}
}