Files
tcg-client/Assets/TcgEngine/Scripts/Conditions/ConditionCountComparison.cs
2025-08-26 11:21:24 +08:00

104 lines
3.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace TcgEngine
{
public enum ComparisonTarget
{
SelfVsOpponent = 0, // 我方比较
OpponentVsSelf = 1, // 对方
}
/// <summary>
/// 比较敌我双方已上场卡牌的数量关系
/// </summary>
[CreateAssetMenu(fileName = "condition", menuName = "TcgEngine/Condition/CountComparison", order = 10)]
public class ConditionCountComparison : ConditionData
{
[Header("比较设置")]
public ComparisonTarget comparison_target;
public PileType pile; // 手牌/场上/装备/墓地/秘密/临时
public ConditionOperatorInt oper;
[Header("卡牌特征筛选")]
public CardType has_type;
public TeamData has_team;
public TraitData has_trait;
public override bool IsTriggerConditionMet(Game data, AbilityData ability, Card caster)
{
Player self_player = data.GetPlayer(caster.player_id);
Player opponent_player = data.GetOpponentPlayer(caster.player_id);
if (self_player == null || opponent_player == null)
return false;
int self_count = CountPile(self_player, pile);
int opponent_count = CountPile(opponent_player, pile);
if (comparison_target == ComparisonTarget.SelfVsOpponent)
{
return CompareInt(self_count, oper, opponent_count);
}
else // OpponentVsSelf
{
// 对手已上场卡牌与我方已上场卡牌比较
return CompareInt(opponent_count, oper, self_count);
}
}
private int CountPile(Player player, PileType pile)
{
if (player == null)
return 0;
List<Card> card_pile = null;
if (pile == PileType.Hand)
card_pile = player.cards_hand;
if (pile == PileType.Board)
card_pile = player.cards_board;
if (pile == PileType.Equipped)
card_pile = player.cards_equip;
if (pile == PileType.Deck)
card_pile = player.cards_deck;
if (pile == PileType.Discard)
card_pile = player.cards_discard;
if (pile == PileType.Secret)
card_pile = player.cards_secret;
if (pile == PileType.Temp)
card_pile = player.cards_temp;
if (card_pile != null)
{
int count = 0;
foreach (Card card in card_pile)
{
if (card != null && IsTrait(card))
count++;
}
return count;
}
return 0;
}
private bool IsTrait(Card card)
{
if (card?.CardData == null)
return false;
bool is_type = card.CardData.type == has_type || has_type == CardType.None;
bool is_team = card.CardData.team == has_team || has_team == null;
bool is_trait = card.HasTrait(has_trait) || has_trait == null;
return (is_type && is_team && is_trait);
}
}
}