using System.Collections.Generic; using Cthangover.Core.Characters; namespace Cthangover.CardBattle.StatusEffect { /// /// Manages the collection of instances attached to a single . /// Implements so that individual effects can call back into the queue /// (e.g. to skip the turn). During , each effect's callback is invoked and /// its turn counter is decremented; expired effects are removed. is checked by /// to skip stunned enemies. /// Supports deep copying for character duplication via . /// public class StatusEffectQueue : IStatusActions { private readonly Character _character; private readonly List _effects = new(); /// /// Set to true when an effect calls during . /// Reset to false at the start of each turn before effects are processed. /// public bool SkipTurn { get; private set; } /// /// Creates a new queue bound to the given . /// public StatusEffectQueue(Character character) { _character = character; } /// /// Creates a deep copy of this queue bound to . /// effects are field-copied; other effect types are shared by reference. /// public StatusEffectQueue Copy(Character newCharacter) { var clone = new StatusEffectQueue(newCharacter); foreach (var effect in _effects) { if (effect is StatusEffectItem item) clone._effects.Add(item.Copy() as IStatusEffect); else clone._effects.Add(effect); } return clone; } /// /// Adds a new status effect to the end of the processing list. Effects are processed /// in reverse order during turn callbacks (last-added first). /// public void AddEffect(IStatusEffect effect) { _effects.Add(effect); } /// /// Processes all effects at the start of the character's turn: resets , /// calls for each effect in reverse order, /// decrements the turn counter, and removes expired effects. /// Called by and . /// public void OnTurnStart() { SkipTurn = false; for (int i = _effects.Count - 1; i >= 0; i--) { var effect = _effects[i]; effect.OnTurnStart(_character, this); effect.Turns--; if (effect.IsExpired) _effects.RemoveAt(i); } } /// /// Processes all effects at the end of the character's turn: calls /// in reverse order and removes expired effects. /// public void OnTurnEnd() { for (int i = _effects.Count - 1; i >= 0; i--) { var effect = _effects[i]; effect.OnTurnEnd(_character, this); if (effect.IsExpired) _effects.RemoveAt(i); } } void IStatusActions.SkipTurn() { SkipTurn = true; } void IStatusActions.RemoveStatus(IStatusEffect status) { _effects.Remove(status); } } }