Files
Continentis/Assets/Scripts/MainGame/Commands/Cmd_ReboundCards.cs
SoulliesOfficial d09b58fd80 架构大更
2026-03-20 11:56:50 -04:00

73 lines
2.8 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_ReboundCards : CommandBase
{
private readonly List<CardInstance> cardsToRebound;
private readonly DeckSubmodule deck;
private readonly float interval;
private const float SingleCardAnimationDuration = 0.5f;
public Cmd_ReboundCards(DeckSubmodule deck, List<CardInstance> cards, float interval)
{
this.deck = deck;
this.cardsToRebound = cards;
this.interval = interval;
}
protected override async UniTask ExecuteAsync(CommandContext outerContext)
{
if (cardsToRebound == null || cardsToRebound.Count == 0) return;
if (interval <= 0f)
{
await UniTask.WhenAll(System.Linq.Enumerable.Select(cardsToRebound, card => ReboundCardAsync(card)));
}
else
{
var tasks = new UniTask[cardsToRebound.Count];
for (int i = 0; i < cardsToRebound.Count; i++)
{
CardInstance captured = cardsToRebound[i];
tasks[i] = ReboundCardWithDelayAsync(captured, i * interval);
}
await UniTask.WhenAll(tasks);
}
}
private async UniTask ReboundCardWithDelayAsync(CardInstance card, float delay)
{
if (delay > 0f)
await UniTask.Delay(TimeSpan.FromSeconds(delay));
await ReboundCardAsync(card);
}
private async UniTask ReboundCardAsync(CardInstance card)
{
deck.TransferCard(deck.Pile(card.cardLocation.pileName), deck.DrawPile, card);
card.handCardView.TransferCardView(CombatUIManager.Instance.combatMainPage.drawPile);
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));
}
}
}