87 lines
3.1 KiB
C#
87 lines
3.1 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_UsePowerCards : CommandBase
|
|
{
|
|
private readonly bool isPlayer;
|
|
private readonly DeckSubmodule deck;
|
|
private readonly List<CardInstance> cardsToUse;
|
|
private readonly float interval;
|
|
|
|
private const float SingleCardAnimationDuration = 0.5f;
|
|
|
|
public Cmd_UsePowerCards(bool isPlayer, DeckSubmodule deck, List<CardInstance> cards, float interval)
|
|
{
|
|
this.isPlayer = isPlayer;
|
|
this.deck = deck;
|
|
this.cardsToUse = cards;
|
|
this.interval = interval;
|
|
}
|
|
|
|
protected override async UniTask ExecuteAsync(CommandContext outerContext)
|
|
{
|
|
if (cardsToUse == null || cardsToUse.Count == 0) return;
|
|
|
|
if (interval <= 0f)
|
|
{
|
|
await UniTask.WhenAll(cardsToUse.Select(card => UsePowerCardAsync(card)));
|
|
}
|
|
else
|
|
{
|
|
var tasks = new UniTask[cardsToUse.Count];
|
|
for (int i = 0; i < cardsToUse.Count; i++)
|
|
{
|
|
CardInstance captured = cardsToUse[i];
|
|
tasks[i] = UsePowerCardWithDelayAsync(captured, i * interval);
|
|
}
|
|
await UniTask.WhenAll(tasks);
|
|
}
|
|
}
|
|
|
|
private async UniTask UsePowerCardWithDelayAsync(CardInstance card, float delay)
|
|
{
|
|
if (delay > 0f)
|
|
await UniTask.Delay(TimeSpan.FromSeconds(delay));
|
|
await UsePowerCardAsync(card);
|
|
}
|
|
|
|
private async UniTask UsePowerCardAsync(CardInstance card)
|
|
{
|
|
if (isPlayer)
|
|
await PlayerUsePowerAsync(card);
|
|
else
|
|
await NpcUsePowerAsync(card);
|
|
}
|
|
|
|
private async UniTask PlayerUsePowerAsync(CardInstance card)
|
|
{
|
|
deck.TransferCard(deck.Pile(card.cardLocation.pileName), deck.GravePile, card);
|
|
card.handCardView.TransferCardView(CombatUIManager.Instance.combatMainPage.gravePile);
|
|
|
|
RectTransform cardTransform = card.handCardView.cardTransform;
|
|
Vector2 userViewPosition = card.user.characterView.hudContainer.GetComponent<RectTransform>().position;
|
|
|
|
cardTransform.DOMove(userViewPosition, SingleCardAnimationDuration).SetEase(Ease.Linear).Play();
|
|
cardTransform.DOScale(Vector3.zero, SingleCardAnimationDuration).SetEase(Ease.Linear)
|
|
.OnComplete(() => cardTransform.anchoredPosition = Vector2.zero).Play();
|
|
|
|
await UniTask.Delay(TimeSpan.FromSeconds(SingleCardAnimationDuration));
|
|
}
|
|
|
|
private async UniTask NpcUsePowerAsync(CardInstance card)
|
|
{
|
|
deck.TransferCard(deck.Pile(card.cardLocation.pileName), deck.GravePile, card);
|
|
await UniTask.Delay(TimeSpan.FromSeconds(SingleCardAnimationDuration));
|
|
}
|
|
}
|
|
} |