83 lines
3.2 KiB
C#
83 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Cysharp.Threading.Tasks;
|
|
using Continentis.MainGame.Card;
|
|
using Continentis.MainGame.Character;
|
|
using DG.Tweening;
|
|
using SLSFramework.General;
|
|
using UnityEngine;
|
|
using Random = UnityEngine.Random;
|
|
|
|
namespace Continentis.MainGame.Commands
|
|
{
|
|
public class Cmd_DiscardCards : CommandBase
|
|
{
|
|
private readonly DeckSubmodule deck;
|
|
private readonly List<CardInstance> cardsToDiscard;
|
|
private readonly bool isInitiative;
|
|
|
|
private float interval;
|
|
private const float SingleCardAnimationDuration = 0.5f;
|
|
|
|
public Cmd_DiscardCards(DeckSubmodule deck, List<CardInstance> cards, bool isInitiative, float interval)
|
|
{
|
|
this.deck = deck;
|
|
this.cardsToDiscard = cards;
|
|
this.isInitiative = isInitiative;
|
|
this.interval = interval;
|
|
}
|
|
|
|
protected override async UniTask ExecuteAsync(CommandContext outerContext)
|
|
{
|
|
if (cardsToDiscard == null || cardsToDiscard.Count == 0) return;
|
|
|
|
if (interval <= 0f)
|
|
{
|
|
await UniTask.WhenAll(cardsToDiscard.Select(card => DiscardCardAsync(card)));
|
|
}
|
|
else
|
|
{
|
|
var tasks = new UniTask[cardsToDiscard.Count];
|
|
for (int i = 0; i < cardsToDiscard.Count; i++)
|
|
{
|
|
CardInstance captured = cardsToDiscard[i];
|
|
tasks[i] = DiscardCardWithDelayAsync(captured, i * interval);
|
|
}
|
|
await UniTask.WhenAll(tasks);
|
|
}
|
|
}
|
|
|
|
private async UniTask DiscardCardWithDelayAsync(CardInstance card, float delay)
|
|
{
|
|
if (delay > 0f)
|
|
await UniTask.Delay(TimeSpan.FromSeconds(delay));
|
|
await DiscardCardAsync(card);
|
|
}
|
|
|
|
private async UniTask DiscardCardAsync(CardInstance card)
|
|
{
|
|
if (isInitiative && card.eventSubmodule.onInitiativeDiscard.GetChecks().Any())
|
|
{
|
|
CommandQueueManager.Instance.AddCommand(Cmd.Do(() =>
|
|
card.eventSubmodule.onInitiativeDiscard.GetEffects().ForEach(effect => effect.Invoke())));
|
|
return;
|
|
}
|
|
|
|
deck.TransferCard(deck.Pile(card.cardLocation.pileName), deck.DiscardPile, card);
|
|
card.handCardView.TransferCardView(CombatUIManager.Instance.combatMainPage.discardPile);
|
|
|
|
RectTransform cardTransform = card.handCardView.cardTransform;
|
|
Vector3 deltaMove = Vector3.zero - cardTransform.localPosition;
|
|
Vector3 randomLift = new Vector3(Random.Range(-200f, 200f), Random.Range(200f, 600f), 0f);
|
|
|
|
cardTransform.DOBlendableLocalMoveBy(deltaMove, SingleCardAnimationDuration).Play();
|
|
cardTransform.DOBlendableLocalMoveBy(randomLift, SingleCardAnimationDuration * 0.5f)
|
|
.SetLoops(2, LoopType.Yoyo).Play();
|
|
cardTransform.DOLocalRotate(new Vector3(0f, 0f, 720f), SingleCardAnimationDuration, RotateMode.FastBeyond360).Play();
|
|
cardTransform.DOScale(Vector3.zero, SingleCardAnimationDuration).SetEase(Ease.Linear).Play();
|
|
|
|
await UniTask.Delay(TimeSpan.FromSeconds(SingleCardAnimationDuration));
|
|
}
|
|
}
|
|
} |