PkmnLib.NET/Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/FlameBurst.cs

43 lines
1.2 KiB
C#
Raw Normal View History

2025-03-02 13:03:51 +00:00
using System.Collections.Generic;
using System.Linq;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "flame_burst")]
public class FlameBurst : Script
{
/// <inheritdoc />
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
var adjacentFoes = GetAdjacentFoes(move.User).WhereNotNull();
EventBatchId batchId = new();
foreach (var adjacentFoe in adjacentFoes)
{
adjacentFoe.Damage(adjacentFoe.BoostedStats.Hp / 16, DamageSource.Misc, batchId);
}
}
private static IEnumerable<IPokemon?> GetAdjacentFoes(IPokemon pokemon)
{
var battleData = pokemon.BattleData;
if (battleData == null)
yield break;
if (battleData.Battle.PositionsPerSide == 1)
yield break;
var position = battleData.Position;
var side = battleData.Battle.Sides[battleData.SideIndex];
if (position == 0)
{
yield return side.Pokemon[1];
}
else
{
yield return side.Pokemon[position - 1];
if (position < side.Pokemon.Count - 1)
yield return side.Pokemon[position + 1];
}
}
}