using System; using System.Collections.Generic; using System.Linq; using Continentis.MainGame.Card; using Continentis.MainGame.Character; using Cysharp.Threading.Tasks; using DG.Tweening; using SLSUtilities.General; using UnityEngine; using Random = UnityEngine.Random; namespace Continentis.MainGame.Commands { public class Cmd_ExhaustCards : CommandBase { private readonly bool isPlayer; private readonly DeckSubmodule deck; private readonly List cardsToExhaust; private readonly float interval; private const float SingleCardAnimationDuration = 0.5f; public Cmd_ExhaustCards(bool isPlayer, DeckSubmodule deck, List cards, float interval) { this.isPlayer = isPlayer; this.deck = deck; this.cardsToExhaust = cards; this.interval = interval; } protected override async UniTask ExecuteAsync(CommandContext outerContext) { if (cardsToExhaust == null || cardsToExhaust.Count == 0) return; if (interval <= 0f) { await UniTask.WhenAll(cardsToExhaust.Select(card => ExhaustCardAsync(card))); } else { var tasks = new UniTask[cardsToExhaust.Count]; for (int i = 0; i < cardsToExhaust.Count; i++) { CardInstance captured = cardsToExhaust[i]; tasks[i] = ExhaustCardWithDelayAsync(captured, i * interval); } await UniTask.WhenAll(tasks); } } private async UniTask ExhaustCardWithDelayAsync(CardInstance card, float delay) { if (delay > 0f) await UniTask.Delay(TimeSpan.FromSeconds(delay)); await ExhaustCardAsync(card); } private async UniTask ExhaustCardAsync(CardInstance card) { if (isPlayer) await PlayerExhaustCardAsync(card); else await NpcExhaustCardAsync(card); } private async UniTask PlayerExhaustCardAsync(CardInstance card) { deck.TransferCard(deck.Pile(card.cardLocation.pileName), deck.ExhaustPile, card); card.eventSubmodule.onExhaust.Invoke(); card.handCardView.TransferCardView(CombatUIManager.Instance.combatMainPage.exhaustPile); RectTransform cardTransform = card.handCardView.cardTransform; Vector3 randomLift = new Vector3(0f, Random.Range(200f, 600f), 0f); cardTransform.DOBlendableLocalMoveBy(randomLift, SingleCardAnimationDuration * 0.5f) .SetLoops(2, LoopType.Yoyo).Play(); cardTransform.DOScale(Vector3.zero, SingleCardAnimationDuration).SetEase(Ease.Linear) .OnComplete(() => cardTransform.anchoredPosition = Vector2.zero).Play(); await UniTask.Delay(TimeSpan.FromSeconds(SingleCardAnimationDuration)); } private async UniTask NpcExhaustCardAsync(CardInstance card) { deck.TransferCard(deck.Pile(card.cardLocation.pileName), deck.ExhaustPile, card); card.eventSubmodule.onExhaust.Invoke(); await UniTask.Delay(TimeSpan.FromSeconds(SingleCardAnimationDuration)); } } }