Преглед изворни кода

Implement AD1-019 and SelectEffect.Mode.PlayForCost

hooperk пре 5 месеци
родитељ
комит
0c76a3cc90

+ 114 - 0
Assets/Scripts/CardEffect/AD1/Blue/AD1_019.cs

@@ -0,0 +1,114 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+
+// Matt Ishida & T.K. Takaishi
+namespace DCGO.CardEffects.AD1
+{
+    public class AD1_019 : CEntity_Effect
+    {
+        public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
+        {
+            List<ICardEffect> cardEffects = new List<ICardEffect>();
+
+            #region Start of Your Main Phase
+            if (timing == EffectTiming.OnStartMainPhase)
+            {
+                cardEffects.Add(CardEffectFactory.Gain1MemoryTamerOpponentDigimonEffect(card));
+            }
+            #endregion
+
+            #region Your Turn
+            if (timing == EffectTiming.OnEnterFieldAnyone)
+            {
+                ActivateClass activateClass = new ();
+                activateClass.SetUpICardEffect("By suspending this tamer, you may play 1[ADVENTURE] Digimon for -1 cost per 2 colors on your Tamers.", CanUseCondition, card);
+                activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDescription());
+                cardEffects.Add(activateClass);
+
+                string EffectDescription()
+                    => "[Your Turn] When any of your Digimon digivolve into an [ADVENTURE] trait Digimon, by suspending this Tamer, you may play 1 [ADVENTURE] trait card from your hand. For every 2 of your Tamers' colors, reduce this effect's play cost by 1.";
+
+                bool CanUseCondition(Hashtable hashtable)
+                {
+                    return CardEffectCommons.IsExistOnBattleArea(card)
+                        && CardEffectCommons.IsOwnerTurn(card)
+                        && CardEffectCommons.CanTriggerWhenPermanentDigivolving(hashtable, PermanentCondition);
+                }
+
+                bool PermanentCondition(Permanent permanent)
+                {
+                    return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card)
+                        && permanent.TopCard.EqualsTraits("ADVENTURE");
+                }
+
+                bool CanActivateCondition(Hashtable hashtable)
+                {
+                    return CardEffectCommons.IsExistOnBattleArea(card)
+                        && CardEffectCommons.CanActivateSuspendCostEffect(card);
+                }
+
+                bool IsAdventureDigimon(CardSource cardSource)
+                {
+                    return cardSource.HasPlayCost
+                        && cardSource.EqualsTraits("ADVENTURE");
+                }
+
+                IEnumerator ActivateCoroutine(Hashtable hashtable)
+                {
+                    yield return ContinuousController.instance.StartCoroutine(new SuspendPermanentsClass(
+                        new List<Permanent>() { card.PermanentOfThisCard() },
+                        CardEffectCommons.CardEffectHashtable(activateClass)).Tap());
+
+                    if (CardEffectCommons.HasMatchConditionOwnersHand(card, IsAdventureDigimon))
+                    {
+                        List<CardSource> tamerCards = new List<CardSource>();
+
+                        foreach (Permanent permanent in card.Owner.GetBattleAreaPermanents())
+                        {
+                            if (permanent.IsTamer)
+                            {
+                                tamerCards.Add(permanent.TopCard);
+                            }
+                        }
+
+                        int reduceCost = Combinations.GetUniqueColorCardCount(tamerCards) / 2;
+
+                        SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
+
+                        selectHandEffect.SetUp(
+                            selectPlayer: card.Owner,
+                            canTargetCondition: IsAdventureDigimon,
+                            canTargetCondition_ByPreSelecetedList: null,
+                            canEndSelectCondition: null,
+                            maxCount: 1,
+                            canNoSelect: true,
+                            canEndNotMax: false,
+                            isShowOpponent: true,
+                            selectCardCoroutine: null,
+                            afterSelectCardCoroutine: null,
+                            mode: SelectHandEffect.Mode.PlayForCost,
+                            cardEffect: activateClass);
+
+                        selectHandEffect.SetReducedCostTuple((reduceCost, null));
+
+                        selectHandEffect.SetUpCustomMessage("Select 1 digimon to play", "The opponent is selecting 1 digimon to play");
+
+                        yield return ContinuousController.instance.StartCoroutine(selectHandEffect.Activate());
+                    }
+                }
+            }
+            #endregion
+
+            #region Security 
+            if (timing == EffectTiming.SecuritySkill)
+            {
+                cardEffects.Add(CardEffectFactory.PlaySelfTamerSecurityEffect(card));
+            }
+            #endregion
+
+            return cardEffects;
+        }
+    }
+}

+ 157 - 2
Assets/Scripts/Script/SelectCardEffect.cs

@@ -113,6 +113,16 @@ public class SelectCardEffect : MonoBehaviourPunCallbacks
         _skillInfos = skillInfos.Clone();
     }
 
+    public void SetReducedCostTuple((int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? reduceCostTuple)
+    {
+        _reduceCostTuple = reduceCostTuple;
+    }
+
+    public void SetFixedCostTuple((int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? fixedCostTuple)
+    {
+        _fixedCostTuple = fixedCostTuple;
+    }
+
     public void SetUpCustomMessage(string CustomMessage, string CustomMessage_Enemy)
     {
         _customMessage = CustomMessage;
@@ -168,15 +178,18 @@ public class SelectCardEffect : MonoBehaviourPunCallbacks
     bool _isAssembly = false;
     bool _isSecurity = false;
     bool _allowFaceDown = false;
+    (int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? _reduceCostTuple = null;
+    (int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? _fixedCostTuple = null;
 
     public enum Mode
     {
         AddHand,
         Discard,
-        PlayForFree,
 
         // PutLibraryTop,
         // PutLibraryBottom,
+        PlayForFree,
+        PlayForCost,
         Custom,
     }
 
@@ -412,6 +425,10 @@ public class SelectCardEffect : MonoBehaviourPunCallbacks
                                 message = "Select cards to play without paying the cost.";
                                 break;
 
+                            case Mode.PlayForCost:
+                                message = "Select cards to play.";
+                                break;
+
                             case Mode.Custom:
                                 message = "Select cards.";
                                 break;
@@ -679,7 +696,9 @@ public class SelectCardEffect : MonoBehaviourPunCallbacks
                                     yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Cards put on the trash", true, true));
                                     break;
 
+
                                 case Mode.PlayForFree:
+                                case Mode.PlayForCost:
                                     yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Played cards", true, true));
                                     break;
 
@@ -765,7 +784,7 @@ public class SelectCardEffect : MonoBehaviourPunCallbacks
                     break;
 
                 case Mode.PlayForFree:
-                        yield return ContinuousController.instance.StartCoroutine(
+                    yield return ContinuousController.instance.StartCoroutine(
                             CardEffectCommons.PlayPermanentCards(
                                 cardSources: _targetCards, 
                                 activateClass: _cardEffect, 
@@ -773,7 +792,143 @@ public class SelectCardEffect : MonoBehaviourPunCallbacks
                                 isTapped: false, 
                                 root: _root, 
                                 activateETB: true));
+                    break;
+
+                case Mode.PlayForCost:
+                    {
+                        bool PermanentsCondition(List<Permanent> targetPermanents)
+                        {
+                            if (targetPermanents == null)
+                            {
+                                return true;
+                            }
+
+                            else
+                            {
+                                if (targetPermanents.Count((targetPermanent) => targetPermanent != null) == 0)
+                                {
+                                    return true;
+                                }
+                            }
+
+                            return false;
+                        }
+
+                        bool SharedCardCondition(CardSource cardSource) => _targetCards.Contains(cardSource);
+                        bool RootCondition(SelectCardEffect.Root root) => true;
+                        bool CanUseCondition(Hashtable hashtable) => true;
+
+                        #region reduce cost
+
+                        Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
+
+                        if (_reduceCostTuple != null)
+                        {
+                            bool CardCondition(CardSource cardSource)
+                            {
+                                return SharedCardCondition(cardSource)
+                                    && (_reduceCostTuple.Value.reduceCostCardCondition == null || _reduceCostTuple.Value.reduceCostCardCondition(cardSource));
+                            }
+
+                            int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
+                            {
+                                if (PermanentsCondition(targetPermanents))
+                                {
+                                    Cost += _reduceCostTuple.Value.reduceCost;
+                                }
+
+                                return Cost;
+                            }
+
+                            bool isUpDown() => true;
+
+                            ChangeCostClass changeCostClass = new ChangeCostClass();
+                            changeCostClass.SetUpICardEffect($"Play Cost -{_reduceCostTuple.Value.reduceCost}", CanUseCondition, _cardEffect.EffectSourceCard);
+                            changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
+
+                            ICardEffect GetCardEffect(EffectTiming _timing)
+                            {
+                                if (_timing == EffectTiming.None)
+                                {
+                                    return changeCostClass;
+                                }
+
+                                return null;
+                            }
+
+                            if (getChangeCostEffect != null)
+                            {
+                                _selectPlayer.UntilCalculateFixedCostEffect.Add(GetCardEffect);
+                            }
+                        }
+
+                        #endregion
+
+                        #region set fixed cost
+
+                        Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
+
+                        if (_fixedCostTuple != null)
+                        {
+                            bool CardCondition(CardSource cardSource)
+                            {
+                                return SharedCardCondition(cardSource)
+                                    && (_fixedCostTuple.Value.fixedCostCardCondition == null || _fixedCostTuple.Value.fixedCostCardCondition(cardSource));
+                            }
+
+                            int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
+                            {
+                                if (PermanentsCondition(targetPermanents))
+                                {
+                                    Cost = _fixedCostTuple.Value.fixedCost;
+                                }
+
+                                return Cost;
+                            }
+
+                            bool isUpDown() => false;
+
+                            ChangeCostClass changeCostClass = new ChangeCostClass();
+                            changeCostClass.SetUpICardEffect($"Play Cost -{_reduceCostTuple.Value.reduceCost}", CanUseCondition, _cardEffect.EffectSourceCard);
+                            changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
+
+                            ICardEffect GetCardEffect(EffectTiming _timing)
+                            {
+                                if (_timing == EffectTiming.None)
+                                {
+                                    return changeCostClass;
+                                }
+
+                                return null;
+                            }
+
+                            if (getChangeCostEffect != null)
+                            {
+                                _selectPlayer.UntilCalculateFixedCostEffect.Add(GetCardEffect);
+                            }
+                        }
+
+                        #endregion
+
+                        yield return ContinuousController.instance.StartCoroutine(
+                            CardEffectCommons.PlayPermanentCards(
+                                cardSources: _targetCards, 
+                                activateClass: _cardEffect, 
+                                payCost: true, 
+                                isTapped: false, 
+                                root: SelectCardEffect.Root.Hand, 
+                                activateETB: true));
+                        
+                        #region release effect
+                        if (getChangeCostEffect != null) _selectPlayer.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
+                        #endregion
+
+                        #region release effect
+                        if (getFixedCostEffect != null) _selectPlayer.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
+                        #endregion
+
                         break;
+                    }
 
                 case Mode.Custom:
                     if (_selectCardCoroutine != null)

+ 156 - 2
Assets/Scripts/Script/SelectHandEffect.cs

@@ -65,6 +65,16 @@ public class SelectHandEffect : MonoBehaviourPunCallbacks
         _isFaceUp = true;
     }
 
+    public void SetReducedCostTuple((int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? reduceCostTuple)
+    {
+        _reduceCostTuple = reduceCostTuple;
+    }
+
+    public void SetFixedCostTuple((int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? fixedCostTuple)
+    {
+        _fixedCostTuple = fixedCostTuple;
+    }
+
     public void SetUpCustomMessage_ShowCard(string CustomMessage_ShowCard)
     {
         _customMessage_ShowCard = CustomMessage_ShowCard;
@@ -109,6 +119,8 @@ public class SelectHandEffect : MonoBehaviourPunCallbacks
     bool _digiXros = false;
     bool _isLocal = false;
     bool _isFaceUp = false;
+    (int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? _reduceCostTuple = null;
+    (int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? _fixedCostTuple = null;
 
     public enum Mode
     {
@@ -117,6 +129,7 @@ public class SelectHandEffect : MonoBehaviourPunCallbacks
         PutLibraryBottom,
         PutSecurityBottom,
         PlayForFree,
+        PlayForCost,
         Custom
     }
 
@@ -225,7 +238,11 @@ public class SelectHandEffect : MonoBehaviourPunCallbacks
                             break;
 
                         case Mode.PlayForFree:
-                            message = "Select cards to play for free.";
+                            message = "Select cards to play for without paying the cost.";
+                            break;
+
+                        case Mode.PlayForCost:
+                            message = "Select cards to play.";
                             break;
 
                         case Mode.Custom:
@@ -656,6 +673,7 @@ public class SelectHandEffect : MonoBehaviourPunCallbacks
                                     break;
 
                                 case Mode.PlayForFree:
+                                case Mode.PlayForCost:
 
                                     yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_targetCards, "Played cards", true, true));
 
@@ -725,7 +743,143 @@ public class SelectHandEffect : MonoBehaviourPunCallbacks
                                 root: SelectCardEffect.Root.Hand, 
                                 activateETB: true));
                         break;
-                }  
+
+                    case Mode.PlayForCost:
+                        {
+                            bool PermanentsCondition(List<Permanent> targetPermanents)
+                            {
+                                if (targetPermanents == null)
+                                {
+                                    return true;
+                                }
+
+                                else
+                                {
+                                    if (targetPermanents.Count((targetPermanent) => targetPermanent != null) == 0)
+                                    {
+                                        return true;
+                                    }
+                                }
+
+                                return false;
+                            }
+
+                            bool SharedCardCondition(CardSource cardSource) => _targetCards.Contains(cardSource);
+                            bool RootCondition(SelectCardEffect.Root root) => true;
+                            bool CanUseCondition(Hashtable hashtable) => true;
+
+                            #region reduce cost
+
+                            Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
+
+                            if (_reduceCostTuple != null)
+                            {
+                                bool CardCondition(CardSource cardSource)
+                                {
+                                    return SharedCardCondition(cardSource)
+                                        && (_reduceCostTuple.Value.reduceCostCardCondition == null || _reduceCostTuple.Value.reduceCostCardCondition(cardSource));
+                                }
+
+                                int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
+                                {
+                                    if (PermanentsCondition(targetPermanents))
+                                    {
+                                        Cost += _reduceCostTuple.Value.reduceCost;
+                                    }
+
+                                    return Cost;
+                                }
+
+                                bool isUpDown() => true;
+
+                                ChangeCostClass changeCostClass = new ChangeCostClass();
+                                changeCostClass.SetUpICardEffect($"Play Cost -{_reduceCostTuple.Value.reduceCost}", CanUseCondition, _cardEffect.EffectSourceCard);
+                                changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
+
+                                ICardEffect GetCardEffect(EffectTiming _timing)
+                                {
+                                    if (_timing == EffectTiming.None)
+                                    {
+                                        return changeCostClass;
+                                    }
+
+                                    return null;
+                                }
+
+                                if (getChangeCostEffect != null)
+                                {
+                                    _selectPlayer.UntilCalculateFixedCostEffect.Add(GetCardEffect);
+                                }
+                            }
+
+                            #endregion
+
+                            #region set fixed cost
+
+                            Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
+
+                            if (_fixedCostTuple != null)
+                            {
+                                bool CardCondition(CardSource cardSource)
+                                {
+                                    return SharedCardCondition(cardSource)
+                                        && (_fixedCostTuple.Value.fixedCostCardCondition == null || _fixedCostTuple.Value.fixedCostCardCondition(cardSource));
+                                }
+
+                                int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
+                                {
+                                    if (PermanentsCondition(targetPermanents))
+                                    {
+                                        Cost = _fixedCostTuple.Value.fixedCost;
+                                    }
+
+                                    return Cost;
+                                }
+
+                                bool isUpDown() => false;
+
+                                ChangeCostClass changeCostClass = new ChangeCostClass();
+                                changeCostClass.SetUpICardEffect($"Play Cost -{_reduceCostTuple.Value.reduceCost}", CanUseCondition, _cardEffect.EffectSourceCard);
+                                changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
+
+                                ICardEffect GetCardEffect(EffectTiming _timing)
+                                {
+                                    if (_timing == EffectTiming.None)
+                                    {
+                                        return changeCostClass;
+                                    }
+
+                                    return null;
+                                }
+
+                                if (getChangeCostEffect != null)
+                                {
+                                    _selectPlayer.UntilCalculateFixedCostEffect.Add(GetCardEffect);
+                                }
+                            }
+
+                            #endregion
+
+                            yield return ContinuousController.instance.StartCoroutine(
+                                CardEffectCommons.PlayPermanentCards(
+                                    cardSources: _targetCards, 
+                                    activateClass: _cardEffect, 
+                                    payCost: true, 
+                                    isTapped: false, 
+                                    root: SelectCardEffect.Root.Hand, 
+                                    activateETB: true));
+                            
+                            #region release effect
+                            if (getChangeCostEffect != null) _selectPlayer.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
+                            #endregion
+
+                            #region release effect
+                            if (getFixedCostEffect != null) _selectPlayer.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
+                            #endregion
+
+                            break;
+                        }
+                }
                 #endregion
 
                 if (discardHands.Count > 0)