Files
Continentis/Assets/Scripts/MainGame/Card/CardInstance.cs
2025-10-31 10:02:30 -04:00

163 lines
5.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
}
/// <summary>
/// 根据CardLogic生成卡牌实例
/// </summary>
/// <param name="logic">卡牌逻辑实例</param>
/// <param name="owner">卡牌持有者</param>
/// <param name="pileName">初始卡堆名称"</param>
/// <param name="index">插入位置默认为0</param>
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;
}
/// <summary>
/// 根据CardData生成卡牌实例
/// </summary>
/// <param name="data">卡牌数据</param>
/// <param name="owner">卡牌持有者</param>
/// <param name="pileName">初始卡堆名称"</param>
/// <param name="index">插入位置默认为0</param>
/// <returns></returns>
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);
}
/// <summary>
/// 生成手牌
/// </summary>
/// <param name="pile">手牌生成位置</param>
/// <param name="index">插入位置,-1为末尾</param>
/// <returns></returns>
public HandCardView GenerateHandCardView(PileBase pile, int index = -1)
{
GameObject handCardObjectPrefab = MainGameManager.Instance.basePrefabs.handCardObject;
HandCardView handCardView = LeanPool.Spawn(handCardObjectPrefab, pile.rectTransform).GetComponent<HandCardView>();
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<IntentionCardView>();
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;
}
}
}