This commit is contained in:
@@ -3,14 +3,45 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
|
||||
[Script(ScriptCategory.Pokemon, "stockpile_effect")]
|
||||
public class StockpileEffect : Script
|
||||
{
|
||||
private IPokemon? _pokemon;
|
||||
public int StockpileCount { get; set; } = 1;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnAddedToParent(IScriptSource source)
|
||||
{
|
||||
if (source is not IPokemon pokemon)
|
||||
{
|
||||
throw new InvalidOperationException("StockpileEffect can only be added to a Pokemon.");
|
||||
}
|
||||
_pokemon = pokemon;
|
||||
EventBatchId batchId = new();
|
||||
pokemon.ChangeStatBoost(Statistic.Defense, 1, true, batchId);
|
||||
pokemon.ChangeStatBoost(Statistic.SpecialDefense, 1, true, batchId);
|
||||
StockpileCount = 1;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Stack()
|
||||
{
|
||||
if (StockpileCount < 3)
|
||||
{
|
||||
EventBatchId batchId = new();
|
||||
_pokemon?.ChangeStatBoost(Statistic.Defense, 1, true, batchId);
|
||||
_pokemon?.ChangeStatBoost(Statistic.SpecialDefense, 1, true, batchId);
|
||||
StockpileCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnRemove()
|
||||
{
|
||||
if (_pokemon == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
EventBatchId batchId = new();
|
||||
_pokemon.ChangeStatBoost(Statistic.Defense, (sbyte)-StockpileCount, true, batchId);
|
||||
_pokemon.ChangeStatBoost(Statistic.SpecialDefense, (sbyte)-StockpileCount, true, batchId);
|
||||
StockpileCount = 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user