This commit is contained in:
57
Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/ShieldsDown.cs
Normal file
57
Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/ShieldsDown.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
|
||||
|
||||
/// <summary>
|
||||
/// Shields Down is an ability that changes Minior's form depending on its HP.
|
||||
///
|
||||
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Shields_Down_(Ability)">Bulbapedia - Shields Down</see>
|
||||
/// </summary>
|
||||
[Script(ScriptCategory.Ability, "shields_down")]
|
||||
public class ShieldsDown : Script
|
||||
{
|
||||
private IPokemon? _owningPokemon;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnAddedToParent(IScriptSource source)
|
||||
{
|
||||
if (source is not IPokemon pokemon)
|
||||
throw new ArgumentException("ShieldsDown script must be added to a Pokemon.", nameof(source));
|
||||
_owningPokemon = pokemon;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnSwitchIn(IPokemon pokemon, byte position) => ChangeFormIfNeeded(pokemon);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnEndTurn(IBattle battle) => ChangeFormIfNeeded(_owningPokemon);
|
||||
|
||||
private static void ChangeFormIfNeeded(IPokemon? pokemon)
|
||||
{
|
||||
if (pokemon is null)
|
||||
return;
|
||||
|
||||
if (pokemon.Species.Name != "minior" || pokemon.BattleData?.Battle == null)
|
||||
return;
|
||||
if (pokemon.CurrentHealth < pokemon.MaxHealth / 2 && pokemon.Form.Name.ToString().EndsWith("-meteor"))
|
||||
{
|
||||
var coreForm = pokemon.Form.Name.ToString().Replace("-meteor", "");
|
||||
if (coreForm == "blue")
|
||||
coreForm = "default";
|
||||
if (pokemon.Species.TryGetForm(coreForm, out var coreFormData))
|
||||
{
|
||||
pokemon.ChangeForm(coreFormData);
|
||||
}
|
||||
}
|
||||
else if (pokemon.CurrentHealth >= pokemon.MaxHealth / 2 &&
|
||||
pokemon.Form.Name.ToString().EndsWith("-meteor") == false)
|
||||
{
|
||||
var baseFormName = pokemon.Form.Name;
|
||||
if (baseFormName == "default")
|
||||
baseFormName = "blue";
|
||||
var meteorFormName = baseFormName + "-meteor";
|
||||
if (pokemon.Species.TryGetForm(meteorFormName, out var meteorFormData))
|
||||
{
|
||||
pokemon.ChangeForm(meteorFormData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user