This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
|
||||
|
||||
[Script(ScriptCategory.Pokemon, "whirlpool")]
|
||||
public class WhirlpoolEffect : Script
|
||||
{
|
||||
public record PokemonTurn
|
||||
{
|
||||
public PokemonTurn(IPokemon pokemon, int turns, float damagePercent)
|
||||
{
|
||||
Pokemon = pokemon;
|
||||
Turns = turns;
|
||||
DamagePercent = damagePercent;
|
||||
}
|
||||
|
||||
public IPokemon Pokemon { get; }
|
||||
public int Turns { get; set; }
|
||||
public float DamagePercent { get; }
|
||||
}
|
||||
|
||||
private IPokemon? _user;
|
||||
private readonly IList<PokemonTurn> _targetedPokemon = [];
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnAddedToParent(IScriptSource source)
|
||||
{
|
||||
if (source is IPokemon pokemon)
|
||||
{
|
||||
_user = pokemon;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("WhirlpoolEffect can only be added to a Pokemon.");
|
||||
}
|
||||
}
|
||||
|
||||
public void AddTargetedPokemon(IPokemon pokemon, int turns, float damagePercent)
|
||||
{
|
||||
if (_targetedPokemon.All(x => x.Pokemon != pokemon))
|
||||
{
|
||||
_targetedPokemon.Add(new PokemonTurn(pokemon, turns, damagePercent));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void PreventOpponentRunAway(IFleeChoice choice, ref bool prevent)
|
||||
{
|
||||
if (_targetedPokemon.Any(x => x.Pokemon == choice.User))
|
||||
prevent = true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void PreventOpponentSwitch(ISwitchChoice choice, ref bool prevent)
|
||||
{
|
||||
if (_targetedPokemon.Any(x => x.Pokemon == choice.User))
|
||||
prevent = true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnEndTurn(IBattle battle)
|
||||
{
|
||||
if (_user == null)
|
||||
return;
|
||||
|
||||
foreach (var pokemonTurn in _targetedPokemon.Where(x => x.Pokemon.BattleData?.IsOnBattlefield == true))
|
||||
{
|
||||
var pokemon = pokemonTurn.Pokemon;
|
||||
pokemon.Damage((uint)(pokemon.MaxHealth * pokemonTurn.DamagePercent), DamageSource.Misc);
|
||||
pokemonTurn.Turns--;
|
||||
if (pokemonTurn.Turns <= 0)
|
||||
{
|
||||
_targetedPokemon.Remove(pokemonTurn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user