This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user