From 23387a78cac8224dcfb1f748120168d45ffd1333 Mon Sep 17 00:00:00 2001 From: xianyi Date: Tue, 26 Aug 2025 11:21:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=8C=E6=88=91=E5=8D=A1=E7=89=8C=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E6=AF=94=E8=BE=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Conditions/has_board_card_more.asset | 20 ++++ .../Conditions/has_board_card_more.asset.meta | 8 ++ .../Conditions/ConditionCountComparison.cs | 104 ++++++++++++++++++ .../ConditionCountComparison.cs.meta | 11 ++ 4 files changed, 143 insertions(+) create mode 100644 Assets/TcgEngine/Resources/Conditions/has_board_card_more.asset create mode 100644 Assets/TcgEngine/Resources/Conditions/has_board_card_more.asset.meta create mode 100644 Assets/TcgEngine/Scripts/Conditions/ConditionCountComparison.cs create mode 100644 Assets/TcgEngine/Scripts/Conditions/ConditionCountComparison.cs.meta diff --git a/Assets/TcgEngine/Resources/Conditions/has_board_card_more.asset b/Assets/TcgEngine/Resources/Conditions/has_board_card_more.asset new file mode 100644 index 0000000..ad9b0f8 --- /dev/null +++ b/Assets/TcgEngine/Resources/Conditions/has_board_card_more.asset @@ -0,0 +1,20 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: acf7b90eaf6054d2ebc6093003b274be, type: 3} + m_Name: has_board_card_more + m_EditorClassIdentifier: + comparison_target: 0 + pile: 0 + oper: 0 + has_type: 0 + has_team: {fileID: 0} + has_trait: {fileID: 0} diff --git a/Assets/TcgEngine/Resources/Conditions/has_board_card_more.asset.meta b/Assets/TcgEngine/Resources/Conditions/has_board_card_more.asset.meta new file mode 100644 index 0000000..00b9c1c --- /dev/null +++ b/Assets/TcgEngine/Resources/Conditions/has_board_card_more.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6836b69e4c9d2411593ab0deaaef4b98 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TcgEngine/Scripts/Conditions/ConditionCountComparison.cs b/Assets/TcgEngine/Scripts/Conditions/ConditionCountComparison.cs new file mode 100644 index 0000000..e3478b6 --- /dev/null +++ b/Assets/TcgEngine/Scripts/Conditions/ConditionCountComparison.cs @@ -0,0 +1,104 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace TcgEngine +{ + public enum ComparisonTarget + { + SelfVsOpponent = 0, // 我方比较 + OpponentVsSelf = 1, // 对方 + } + + /// + /// 比较敌我双方已上场卡牌的数量关系 + /// + + [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_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); + } + } +} \ No newline at end of file diff --git a/Assets/TcgEngine/Scripts/Conditions/ConditionCountComparison.cs.meta b/Assets/TcgEngine/Scripts/Conditions/ConditionCountComparison.cs.meta new file mode 100644 index 0000000..4a45b7c --- /dev/null +++ b/Assets/TcgEngine/Scripts/Conditions/ConditionCountComparison.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: acf7b90eaf6054d2ebc6093003b274be +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: