70 lines
2.6 KiB
C#
70 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
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_ReshuffleDeck : CommandBase
|
|
{
|
|
private readonly DeckSubmodule deck;
|
|
private readonly float interval;
|
|
|
|
private const float SingleCardAnimationDuration = 0.5f;
|
|
|
|
public Cmd_ReshuffleDeck(DeckSubmodule deck, float interval)
|
|
{
|
|
this.deck = deck;
|
|
this.interval = interval;
|
|
}
|
|
|
|
protected override async UniTask ExecuteAsync(CommandContext outerContext)
|
|
{
|
|
var cards = new List<CardInstance>(deck.DiscardPile);
|
|
if (cards.Count == 0) return;
|
|
|
|
// 使用 Interval 语义:第一张卡在 t=interval 开始(与旧版 Observable.Interval 一致)
|
|
var tasks = new UniTask[cards.Count];
|
|
for (int i = 0; i < cards.Count; i++)
|
|
{
|
|
CardInstance captured = cards[i];
|
|
tasks[i] = MoveCardWithDelayAsync(captured, (i + 1) * interval);
|
|
}
|
|
await UniTask.WhenAll(tasks);
|
|
|
|
deck.DrawPile.Shuffle();
|
|
}
|
|
|
|
private async UniTask MoveCardWithDelayAsync(CardInstance card, float delay)
|
|
{
|
|
if (delay > 0f)
|
|
await UniTask.Delay(TimeSpan.FromSeconds(delay));
|
|
await MoveCardToDrawPileAsync(card);
|
|
}
|
|
|
|
private async UniTask MoveCardToDrawPileAsync(CardInstance card)
|
|
{
|
|
deck.TransferCard(deck.DiscardPile, deck.DrawPile, card);
|
|
card.handCardView.TransferCardView(CombatUIManager.Instance.combatMainPage.drawPile);
|
|
|
|
Vector3 deltaMove = Vector3.zero - card.handCardView.cardTransform.localPosition;
|
|
Vector3 randomLift = new Vector3(Random.Range(-200f, 200f), Random.Range(200f, 600f), 0f);
|
|
|
|
card.handCardView.cardOrb.gameObject.SetActive(true);
|
|
card.handCardView.cardTransform
|
|
.DOBlendableLocalMoveBy(deltaMove, SingleCardAnimationDuration)
|
|
.OnComplete(() => card.handCardView.cardOrb.gameObject.SetActive(false)).Play();
|
|
card.handCardView.cardTransform
|
|
.DOBlendableLocalMoveBy(randomLift, SingleCardAnimationDuration * 0.5f)
|
|
.SetLoops(2, LoopType.Yoyo).Play();
|
|
card.handCardView.cardTransform.DOScale(Vector3.zero, SingleCardAnimationDuration).Play();
|
|
|
|
await UniTask.Delay(TimeSpan.FromSeconds(SingleCardAnimationDuration));
|
|
}
|
|
}
|
|
} |