using System.Collections.Generic;
using Continentis.MainGame.Character;
using Continentis.MainGame.UI;
using Lean.Pool;
using UnityEngine;
namespace Continentis.MainGame.Card
{
public partial class CardInstance
{
[Header("References")]
public DeckSubmodule deck;
//public string currentPileName;
public ICardOwner owner;
public CharacterBase user;
public CombatTeam team;
public CardLogicBase cardLogic;
public CardLocation cardLocation;
public HandCardView handCardView;
public IntentionCardView intentionCardView;
public CardInstance(CardLogicBase cardLogic, ICardOwner owner, string initialPileName, int index = -1)
{
cardLogic.cardInstance = this;
this.cardLogic = cardLogic;
this.owner = owner;
this.user = owner as CharacterBase;
if (this.owner is CombatTeam team)
{
this.team = team;
}
else if (this.owner is CharacterBase character)
{
this.team = character.team;
}
this.deck = owner.deckSubmodule;
this.cardLocation = new CardLocation(initialPileName, index);
if (index < 0)
{
this.deck.Pile(cardLocation.pileName).Add(this);
}
else
{
this.deck.Pile(cardLocation.pileName).Insert(index, this);
}
}
///
/// 根据CardLogic生成卡牌实例
///
/// 卡牌逻辑实例
/// 卡牌持有者
/// 初始卡堆名称"
/// 插入位置,默认为0
public static CardInstance GenerateCardInstance(CardLogicBase logic, ICardOwner owner, string pileName, int index = -1)
{
CardInstance cardInstance = new CardInstance(logic, owner, pileName, index);
//cardInstance.cardLogic.Initialize();
return cardInstance;
}
///
/// 根据CardData生成卡牌实例
///
/// 卡牌数据
/// 卡牌持有者
/// 初始卡堆名称"
/// 插入位置,默认为0
///
public static CardInstance GenerateCardInstance(CardData data, ICardOwner owner, string pileName, int index = -1)
{
CardInstance cardInstance = new CardInstance(CardLogicBase.GenerateCardLogic(data), owner, pileName, index);
cardInstance.cardLogic.Initialize();
return cardInstance;
}
public HandCardView GenerateHandCardView(string pileName, int index = -1)
{
PileBase pile = CombatUIManager.Instance.combatMainPage.Pile(pileName);
return GenerateHandCardView(pile, index);
}
///
/// 生成手牌
///
/// 手牌生成位置
/// 插入位置,-1为末尾
///
public HandCardView GenerateHandCardView(PileBase pile, int index = -1)
{
GameObject handCardObjectPrefab = MainGameManager.Instance.basePrefabs.handCardObject;
HandCardView handCardView = LeanPool.Spawn(handCardObjectPrefab, pile.rectTransform).GetComponent();
if (index >= 0)
{
pile.InsertCard(handCardView, index);
}
else
{
pile.AddCard(handCardView);
}
handCardView.cardInstance = this;
this.handCardView = handCardView;
handCardView.transform.localScale = pile is HandPile ? Vector3.one : Vector3.zero;
handCardView.Setup(this);
handCardView.currentPile = pile;
handCardView.cardOrb.gameObject.SetActive(false);
return handCardView;
}
public void DestroyHandCardView()
{
if (handCardView != null)
{
handCardView.currentPile.RemoveCard(handCardView);
LeanPool.Despawn(handCardView.gameObject);
handCardView = null;
}
}
public IntentionCardView GenerateIntentionCardView()
{
GameObject intentionCardObjectPrefab = MainGameManager.Instance.basePrefabs.intentionCardObject;
HUD_Intention intention = user.characterView.hudContainer.enablingHUDs["Intention"] as HUD_Intention;
IntentionCardView intentionCardView = LeanPool.Spawn(intentionCardObjectPrefab, intention.hudTransform).GetComponent();
intention.AddCard(intentionCardView);
intentionCardView.cardInstance = this;
this.intentionCardView = intentionCardView;
intentionCardView.transform.localScale = Vector3.one;
intentionCardView.Setup(this);
return intentionCardView;
}
public void DestroyIntentionCardView()
{
if (intentionCardView != null)
{
HUD_Intention intention = user.characterView.hudContainer.enablingHUDs["Intention"] as HUD_Intention;
intention.RemoveCard(intentionCardView);
intentionCardView = null;
}
}
}
public class CardLocation
{
public string pileName;
public int index;
public CardLocation(string pileName, int index)
{
this.pileName = pileName;
this.index = index;
}
}
}