using PkmnLib.Static.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "confusion")]
public class Confusion : Script, IScriptStopBeforeMove
{
private int _turnsConfused;
///
public override void OnAddedToParent(IScriptSource source)
{
if (source is not IPokemon pokemon)
throw new InvalidOperationException("Confusion script can only be added to a Pokemon.");
var battleData = pokemon.BattleData;
if (battleData == null)
throw new InvalidOperationException("Confusion script requires a Pokemon to be in a battle.");
_turnsConfused = battleData.Battle.Random.GetInt(2, 5);
}
///
public void StopBeforeMove(IExecutingMove move, ref bool stop)
{
_turnsConfused--;
move.Battle.EventHook.Invoke(new DialogEvent("pokemon_is_confused", new Dictionary
{
{ "pokemon", move.User },
}));
if (_turnsConfused <= 0)
{
RemoveSelf();
move.Battle.EventHook.Invoke(new DialogEvent("pokemon_snapped_out_of_confusion",
new Dictionary
{
{ "pokemon", move.User },
}));
return;
}
if (move.Battle.Random.GetInt(0, 100) < 33)
{
var damage = move.Battle.Library.DamageCalculator.GetDamage(null, MoveCategory.Physical, move.User,
move.User, 1, 0, new ConfusionHitData());
EventBatchId batchId = new();
move.User.Damage(damage, DamageSource.Confusion, batchId);
move.Battle.EventHook.Invoke(new DialogEvent("pokemon_hit_itself_in_confusion",
new Dictionary
{
{ "pokemon", move.User },
{ "damage", damage },
})
{
BatchId = batchId,
});
stop = true;
}
}
private class ConfusionHitData : IHitData
{
///
public bool IsCritical => false;
///
public ushort BasePower => 40;
///
public float Effectiveness => 1.0f;
///
public uint Damage { get; } = 0;
///
public TypeIdentifier? Type => null;
///
public bool IsContact => true;
///
public bool HasFailed => false;
///
public void Fail()
{
}
///
public void SetFlag(StringKey flag)
{
}
///
public bool HasFlag(StringKey flag) => false;
}
}