152 lines
5.6 KiB
C#
152 lines
5.6 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using Continentis.MainGame.Card;
|
|
using Continentis.MainGame.Commands;
|
|
using DG.Tweening;
|
|
using SoulliesFramework.General;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
|
|
namespace Continentis.MainGame.Character
|
|
{
|
|
public partial class DeckSubmodule : SubmoduleBase<CharacterBase>
|
|
{
|
|
public Dictionary<string, List<CardInstance>> piles;
|
|
|
|
public DeckSubmodule(CharacterBase character) : base(character)
|
|
{
|
|
piles = new Dictionary<string, List<CardInstance>>();
|
|
piles.Add("Hand", new List<CardInstance>());
|
|
piles.Add("Draw", new List<CardInstance>());
|
|
piles.Add("Discard", new List<CardInstance>());
|
|
piles.Add("Exhaust", new List<CardInstance>());
|
|
piles.Add("Pool", new List<CardInstance>());
|
|
piles.Add("Intention", new List<CardInstance>());
|
|
}
|
|
}
|
|
|
|
public partial class DeckSubmodule
|
|
{
|
|
public void SetUpCardViews()
|
|
{
|
|
DrawPile.ForEach(c=>c.GenerateHandCardView(CombatUIManager.Instance.deckPage.drawPile));
|
|
HandPile.ForEach(c=>c.GenerateHandCardView(CombatUIManager.Instance.deckPage.handPile));
|
|
DiscardPile.ForEach(c=>c.GenerateHandCardView(CombatUIManager.Instance.deckPage.discardPile));
|
|
ExhaustPile.ForEach(c=>c.GenerateHandCardView(CombatUIManager.Instance.deckPage.exhaustPile));
|
|
}
|
|
|
|
public void DrawCards(int cardCount, float interval)
|
|
{
|
|
if (cardCount > DrawPile.Count)
|
|
{
|
|
Debug.Log("抽牌堆牌数不足,洗牌。");
|
|
ReshuffleDeck();
|
|
}
|
|
|
|
Debug.Log($"准备抽取 {cardCount} 张卡牌。");
|
|
|
|
CommandContext context = new CommandContext();
|
|
CommandQueueManager.Instance.AddCommand(new Cmd_DrawCards(this, cardCount, interval), context);
|
|
CommandQueueManager.Instance.AddCommand(new Cmd_Function(0, () =>
|
|
{
|
|
//Debug.Log((context.sharedInfo["DrawnCards"] as List<CardInstance>).Count); //TODO: 抽牌后的处理
|
|
}));
|
|
//return context.sharedInfo["DrawnCards"] as List<CardBase>;
|
|
}
|
|
|
|
public void PlayCard(CardInstance card, List<CharacterBase> targetList)
|
|
{
|
|
card.cardLogic.Play(targetList, owner);
|
|
}
|
|
|
|
public void DiscardCard(CardInstance card, float interval = 0.1f)
|
|
{
|
|
CommandQueueManager.Instance.AddCommand(new Cmd_DiscardCards(this, new List<CardInstance> { card }, interval));
|
|
}
|
|
|
|
public void DiscardCards(List<CardInstance> cards, float interval = 0.1f)
|
|
{
|
|
CommandQueueManager.Instance.AddCommand(new Cmd_DiscardCards(this, cards, interval));
|
|
}
|
|
|
|
public void ExhaustCard(CardInstance card, float interval = 0.1f)
|
|
{
|
|
CommandQueueManager.Instance.AddCommand(new Cmd_ExhaustCards(this, new List<CardInstance> { card }, interval));
|
|
}
|
|
|
|
public void ExhaustCards(List<CardInstance> cards, float interval = 0.1f)
|
|
{
|
|
CommandQueueManager.Instance.AddCommand(new Cmd_ExhaustCards(this, cards, interval));
|
|
}
|
|
|
|
public void ReshuffleDeck(float interval = 0.1f)
|
|
{
|
|
CommandQueueManager.Instance.AddCommand(new Cmd_ReshuffleDeck(this, interval));
|
|
}
|
|
}
|
|
|
|
public partial class DeckSubmodule
|
|
{
|
|
public KeyValuePair<string, List<CardInstance>> GetCardLocation(CardInstance card, out int index)
|
|
{
|
|
index = -1;
|
|
|
|
foreach (KeyValuePair<string, List<CardInstance>> pile in piles)
|
|
{
|
|
index = pile.Value.IndexOf(card);
|
|
if (index != -1)
|
|
{
|
|
return pile;
|
|
}
|
|
}
|
|
|
|
throw new Exception("Card not found in any pile.");
|
|
}
|
|
|
|
public void TransferCard(string fromPileName, string toPileName, CardInstance card)
|
|
{
|
|
List<CardInstance> fromPile = Pile(fromPileName);
|
|
List<CardInstance> toPile = Pile(toPileName);
|
|
fromPile.Transfer(toPile, card);
|
|
card.currentPileName = toPileName;
|
|
}
|
|
|
|
public void TransferCard(List<CardInstance> fromPile, List<CardInstance> toPile, CardInstance card)
|
|
{
|
|
fromPile.Transfer(toPile, card);
|
|
card.currentPileName = piles.FirstOrDefault(pilePair => pilePair.Value == toPile).Key;
|
|
}
|
|
|
|
public List<CardInstance> GetAllCards()
|
|
{
|
|
List<CardInstance> allCards = new List<CardInstance>();
|
|
foreach (KeyValuePair<string, List<CardInstance>> pile in piles)
|
|
{
|
|
allCards.AddRange(pile.Value);
|
|
}
|
|
|
|
return allCards;
|
|
}
|
|
}
|
|
|
|
public partial class DeckSubmodule
|
|
{
|
|
public List<CardInstance> Pile(string pileName)
|
|
{
|
|
if (piles.TryGetValue(pileName, out List<CardInstance> pile))
|
|
{
|
|
return pile;
|
|
}
|
|
|
|
throw new KeyNotFoundException($"Pile '{pileName}' not found.");
|
|
}
|
|
|
|
public List<CardInstance> HandPile => Pile("Hand");
|
|
public List<CardInstance> DrawPile => Pile("Draw");
|
|
public List<CardInstance> DiscardPile => Pile("Discard");
|
|
public List<CardInstance> ExhaustPile => Pile("Exhaust");
|
|
public List<CardInstance> PoolPile => Pile("Pool");
|
|
public List<CardInstance> IntentionPile => Pile("Intention");
|
|
}
|
|
} |