265 lines
11 KiB
C#
265 lines
11 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using Continentis.MainGame.Card;
|
|
using Continentis.MainGame.Commands;
|
|
using DG.Tweening;
|
|
using SLSFramework.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("Storage", new 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("Grave", new List<CardInstance>());
|
|
piles.Add("Pool", new List<CardInstance>());
|
|
piles.Add("Intention", new List<CardInstance>());
|
|
}
|
|
}
|
|
|
|
public partial class DeckSubmodule
|
|
{
|
|
public void SetUpHandCardViews()
|
|
{
|
|
DrawPile.ForEach(card=> card.GenerateHandCardView(CombatUIManager.Instance.combatMainPage.drawPile));
|
|
HandPile.ForEach(card =>
|
|
{
|
|
if(!card.playSubmodule.isDuringPlayEffect)
|
|
card.GenerateHandCardView(CombatUIManager.Instance.combatMainPage.handPile);
|
|
});
|
|
DiscardPile.ForEach(c=>c.GenerateHandCardView(CombatUIManager.Instance.combatMainPage.discardPile));
|
|
ExhaustPile.ForEach(c=>c.GenerateHandCardView(CombatUIManager.Instance.combatMainPage.exhaustPile));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 抽取指定数量的卡牌,返回一个包含抽牌指令的指令组。
|
|
/// </summary>
|
|
public CommandGroup DrawCards(int cardCount, float interval = 0.1f)
|
|
{
|
|
if (owner.statusSubmodule.HasStatus(StatusType.Heavy)) //沉重状态无法抽牌
|
|
{
|
|
MainGameManager.GenerateInfoText("Heavy: Can not draw cards", owner.characterView);
|
|
return new CommandGroup(ExecutionMode.Sequential);
|
|
}
|
|
|
|
if (cardCount > DrawPile.Count && DiscardPile.Count > 0)
|
|
{
|
|
Debug.Log("抽牌堆牌数不足,且弃牌堆有牌,正在洗牌...");
|
|
ReshuffleDeck();
|
|
}
|
|
|
|
Debug.Log($"准备抽取 {cardCount} 张卡牌。");
|
|
|
|
CommandContext context = new CommandContext();
|
|
CommandGroup drawCardsGroup = new CommandGroup(ExecutionMode.Sequential, context,
|
|
new Cmd_DrawCards(this, cardCount, interval),
|
|
new Cmd_Function(0, () =>
|
|
{
|
|
//Debug.Log((context.sharedInfo["DrawnCards"] as List<CardInstance>).Count); //TODO: 抽牌后的处理
|
|
}));
|
|
|
|
return drawCardsGroup;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 从指令组的上下文中获取抽到的卡牌列表。
|
|
/// </summary>
|
|
public List<CardInstance> GetDrawnCards(CommandGroup drawCardsGroup)
|
|
{
|
|
CommandContext context = drawCardsGroup.groupContext;
|
|
return context.GetInfo<List<CardInstance>>("DrawnCards");
|
|
}
|
|
|
|
public void PlayCard(CardInstance card, List<CharacterBase> targetList)
|
|
{
|
|
card.Play(targetList, owner);
|
|
}
|
|
|
|
public CommandGroup DiscardCard(CardInstance card, bool initiative, float interval = 0.1f)
|
|
{
|
|
CommandContext context = new CommandContext();
|
|
CommandGroup discardCardGroup = new CommandGroup(ExecutionMode.Sequential, context,
|
|
new Cmd_DiscardCards(card.deck, new List<CardInstance>() { card }, initiative, interval),
|
|
new Cmd_Function(0, () =>
|
|
{
|
|
CombatUIManager.Instance.combatMainPage.teamSwitchButton.UpdateTeamPileText(owner.team);
|
|
//Debug.Log((context.sharedInfo["DrawnCards"] as List<CardInstance>).Count); //TODO: 弃牌后的处理
|
|
}));
|
|
|
|
return discardCardGroup;
|
|
}
|
|
|
|
public CommandGroup DiscardCards(List<CardInstance> cards,bool initiative, float interval = 0.1f)
|
|
{
|
|
Dictionary<DeckSubmodule, List<CardInstance>> groupedCards = cards.GroupBy(card => card.deck)
|
|
.ToDictionary(group => group.Key, group => group.ToList());
|
|
CommandContext context = new CommandContext();
|
|
CommandGroup discardCardGroup = new CommandGroup(ExecutionMode.Sequential, context);
|
|
foreach (var kvp in groupedCards)
|
|
{
|
|
discardCardGroup.AddCommand(new Cmd_DiscardCards(kvp.Key, kvp.Value, initiative, interval));
|
|
}
|
|
discardCardGroup.AddCommand(new Cmd_Function(0, () =>
|
|
{
|
|
CombatUIManager.Instance.combatMainPage.teamSwitchButton.UpdateTeamPileText(owner.team);
|
|
//Debug.Log((context.sharedInfo["DrawnCards"] as List<CardInstance>).Count); //TODO: 弃牌后的处理
|
|
}));
|
|
|
|
return discardCardGroup;
|
|
}
|
|
|
|
public CommandGroup ExhaustCard(CardInstance card, float interval = 0.1f)
|
|
{
|
|
CommandContext context = new CommandContext();
|
|
CommandGroup discardCardGroup = new CommandGroup(ExecutionMode.Sequential, context,
|
|
new Cmd_ExhaustCards(owner is PlayerHero, card.deck, new List<CardInstance>() { card }, interval),
|
|
new Cmd_Function(0, () =>
|
|
{
|
|
CombatUIManager.Instance.combatMainPage.teamSwitchButton.UpdateTeamPileText(owner.team);
|
|
//Debug.Log((context.sharedInfo["DrawnCards"] as List<CardInstance>).Count); //TODO: 消耗牌后的处理
|
|
}));
|
|
return discardCardGroup;
|
|
}
|
|
|
|
public CommandGroup ExhaustCards(List<CardInstance> cards, float interval = 0.1f)
|
|
{
|
|
Dictionary<DeckSubmodule, List<CardInstance>> groupedCards = cards.GroupBy(card => card.deck)
|
|
.ToDictionary(group => group.Key, group => group.ToList());
|
|
CommandContext context = new CommandContext();
|
|
CommandGroup discardCardGroup = new CommandGroup(ExecutionMode.Sequential, context);
|
|
foreach (var kvp in groupedCards)
|
|
{
|
|
discardCardGroup.AddCommand(new Cmd_ExhaustCards(owner is PlayerHero, kvp.Key, kvp.Value, interval));
|
|
}
|
|
discardCardGroup.AddCommand(new Cmd_Function(0, () =>
|
|
{
|
|
CombatUIManager.Instance.combatMainPage.teamSwitchButton.UpdateTeamPileText(owner.team);
|
|
//Debug.Log((context.sharedInfo["DrawnCards"] as List<CardInstance>).Count); //TODO: 弃牌后的处理
|
|
}));
|
|
|
|
return discardCardGroup;
|
|
}
|
|
|
|
public CommandGroup UsePowerCard(CardInstance card, float interval = 0.1f)
|
|
{
|
|
CommandContext context = new CommandContext();
|
|
CommandGroup discardCardGroup = new CommandGroup(ExecutionMode.Sequential, context,
|
|
new Cmd_UsePowerCards(owner is PlayerHero, card.deck, new List<CardInstance>() { card }, interval),
|
|
new Cmd_Function(0, () =>
|
|
{
|
|
CombatUIManager.Instance.combatMainPage.teamSwitchButton.UpdateTeamPileText(owner.team);
|
|
//Debug.Log((context.sharedInfo["DrawnCards"] as List<CardInstance>).Count); //TODO: 消耗牌后的处理
|
|
}));
|
|
|
|
return discardCardGroup;
|
|
}
|
|
|
|
public CommandGroup UsePowerCards(List<CardInstance> cards, float interval = 0.1f)
|
|
{
|
|
Dictionary<DeckSubmodule, List<CardInstance>> groupedCards = cards.GroupBy(card => card.deck)
|
|
.ToDictionary(group => group.Key, group => group.ToList());
|
|
CommandContext context = new CommandContext();
|
|
CommandGroup discardCardGroup = new CommandGroup(ExecutionMode.Sequential, context);
|
|
foreach (var kvp in groupedCards)
|
|
{
|
|
discardCardGroup.AddCommand(new Cmd_UsePowerCards(owner is PlayerHero, kvp.Key, kvp.Value, interval));
|
|
}
|
|
discardCardGroup.AddCommand(new Cmd_Function(0, () =>
|
|
{
|
|
CombatUIManager.Instance.combatMainPage.teamSwitchButton.UpdateTeamPileText(owner.team);
|
|
//Debug.Log((context.sharedInfo["DrawnCards"] as List<CardInstance>).Count); //TODO: 弃牌后的处理
|
|
}));
|
|
|
|
return discardCardGroup;
|
|
}
|
|
|
|
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 pileName, int index, CardInstance card)
|
|
{
|
|
List<CardInstance> pile = Pile(pileName);
|
|
pile.Transfer(card, index);
|
|
card.cardLocation = new CardLocation(pileName, index);
|
|
}
|
|
|
|
public void TransferCard(string fromPileName, string toPileName, CardInstance card)
|
|
{
|
|
List<CardInstance> fromPile = Pile(fromPileName);
|
|
List<CardInstance> toPile = Pile(toPileName);
|
|
fromPile.Transfer(toPile, card);
|
|
card.cardLocation = new CardLocation(toPileName, toPile.IndexOf(card));
|
|
}
|
|
|
|
public void TransferCard(List<CardInstance> fromPile, List<CardInstance> toPile, CardInstance card)
|
|
{
|
|
fromPile.Transfer(toPile, card);
|
|
card.cardLocation = new CardLocation(GetCardLocation(card, out _).Key, toPile.IndexOf(card));
|
|
}
|
|
|
|
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> StoragePile => Pile("Storage");
|
|
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> GravePile => Pile("Grave");
|
|
public List<CardInstance> PoolPile => Pile("Pool");
|
|
public List<CardInstance> IntentionPile => Pile("Intention");
|
|
}
|
|
} |