using PkmnLib.Static.Species;
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
///
/// Disguise is an ability that allows the Pokémon to avoid damage from one attack.
/// After being hit, the disguise is broken and the Pokémon's appearance changes.
/// This ability is exclusive to Mimikyu.
///
/// Bulbapedia - Disguise
///
[Script(ScriptCategory.Ability, "disguise")]
public class Disguise : Script, IScriptChangeIncomingDamage
{
///
public void ChangeIncomingDamage(IPokemon pokemon, DamageSource source, ref uint damage)
{
if (pokemon.BattleData == null)
return;
if (source is not DamageSource.MoveDamage and not DamageSource.Confusion)
return;
if (pokemon.Form.Name == FormNames.Busted || pokemon.Form.Name == FormNames.TotemBusted)
return;
IForm form;
if (pokemon.Form.Name == FormNames.Default)
{
if (!pokemon.Species.TryGetForm(FormNames.Busted, out form!))
return;
}
else if (pokemon.Form.Name == FormNames.TotemDisguised)
{
if (!pokemon.Species.TryGetForm(FormNames.TotemBusted, out form!))
return;
}
else
{
return;
}
EventBatchId batchId = new();
pokemon.BattleData.Battle.EventHook.Invoke(new AbilityTriggerEvent(pokemon)
{
BatchId = batchId,
});
pokemon.ChangeForm(form, batchId);
damage = 0;
}
}