Browse Source

ST17 Magnamon

Albert Vasconcellos 2 years ago
parent
commit
a8768761fc
2 changed files with 350 additions and 2 deletions
  1. 66 2
      Assets/CardEffect/ST17/Blue/Magnamon_ST17_13.cs
  2. 284 0
      Assets/Scripts/CardEffectCommons.cs

+ 66 - 2
Assets/CardEffect/ST17/Blue/Magnamon_ST17_13.cs

@@ -60,7 +60,22 @@ namespace DCGO.CardEffects.ST17
                     return false;
                     return false;
                 }
                 }
 
 
-                
+                bool CanSelectCardCondition(CardSource cardSource)
+                {
+                        if (cardSource.IsDigimon)
+                        {
+                            if (CardEffectCommons.IsExistOnBattleArea(card))
+                            {
+                            Debug.Log("Selecting");
+                                if (cardSource.CanPlayCardTargetFrame(card.PermanentOfThisCard().PermanentFrame, true, activateClass, root: SelectCardEffect.Root.Execution))
+                                {
+                                    return true;
+                                }
+                            }
+                        }
+
+                    return false;
+                }
 
 
                 IEnumerator ActivateCoroutine(Hashtable _hashtable)
                 IEnumerator ActivateCoroutine(Hashtable _hashtable)
                 {
                 {
@@ -83,6 +98,11 @@ namespace DCGO.CardEffects.ST17
                         return CardEffectCommons.IsPermanentExistsOnOpponentBattleAreaDigimon(permanent, card);
                         return CardEffectCommons.IsPermanentExistsOnOpponentBattleAreaDigimon(permanent, card);
                     }
                     }
 
 
+                    bool CanSelectPermanentCondition1(Permanent permanent)
+                    {
+                        return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card);
+                    }
+
                     bool CanUseCondition1(Hashtable hashtable)
                     bool CanUseCondition1(Hashtable hashtable)
                     {
                     {
                         return true;
                         return true;
@@ -130,7 +150,51 @@ namespace DCGO.CardEffects.ST17
                             }
                             }
                         }
                         }
 
 
-                        
+                        if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition1))
+                        {
+                            Permanent selectedPermanent = null;
+
+                            int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition1));
+
+                            SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
+
+                            selectPermanentEffect.SetUp(
+                                selectPlayer: card.Owner,
+                                canTargetCondition: CanSelectPermanentCondition1,
+                                canTargetCondition_ByPreSelecetedList: null,
+                                canEndSelectCondition: null,
+                                maxCount: maxCount,
+                                canNoSelect: true,
+                                canEndNotMax: false,
+                                selectPermanentCoroutine: SelectPermanentCoroutine,
+                                afterSelectPermanentCoroutine: null,
+                                mode: SelectPermanentEffect.Mode.Custom,
+                                cardEffect: activateClass);
+
+                            selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon that will digivolve.", "The opponent is selecting 1 Digimon that will digivolve.");
+
+                            yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
+
+                            IEnumerator SelectPermanentCoroutine(Permanent permanent)
+                            {
+                                selectedPermanent = permanent;
+
+                                yield return null;
+                            }
+
+                            if (selectedPermanent != null)
+                            {
+                                yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.DigivolveIntoExcecutingAreaCard(
+                                    targetPermanent: selectedPermanent,
+                                    cardCondition: CanSelectCardCondition,
+                                    payCost: false,
+                                    reduceCostTuple: null,
+                                    fixedCostTuple: null,
+                                    ignoreDigivolutionRequirementFixedCost: -1,
+                                    activateClass: activateClass,
+                                    successProcess: null));
+                            }
+                        }
 
 
                     }
                     }
 
 

+ 284 - 0
Assets/Scripts/CardEffectCommons.cs

@@ -635,6 +635,290 @@ public partial class CardEffectCommons
     }
     }
     #endregion
     #endregion
 
 
+    #region Target permanent Digivolves into Digimon card execution area
+    public static IEnumerator DigivolveIntoExcecutingAreaCard(
+        Permanent targetPermanent,
+        Func<CardSource, bool> cardCondition,
+        bool payCost,
+        (int reduceCost, Func<CardSource, bool> reduceCostCardCondition)? reduceCostTuple,
+        (int fixedCost, Func<CardSource, bool> fixedCostCardCondition)? fixedCostTuple,
+        int ignoreDigivolutionRequirementFixedCost,
+        ICardEffect activateClass,
+        IEnumerator successProcess,
+        bool ignoreLevel = false,
+        bool ignoreSelection = false)
+    {
+        if (targetPermanent == null) yield break;
+        if (targetPermanent.TopCard == null) yield break;
+        if (activateClass == null) yield break;
+        if (activateClass.EffectSourceCard == null) yield break;
+
+        Player owner = targetPermanent.TopCard.Owner;
+        SelectCardEffect.Root root = SelectCardEffect.Root.Execution;
+        bool ignoreDigivolutionRequirement = ignoreDigivolutionRequirementFixedCost >= 0;
+
+        int fixedCost = -1;
+
+        if (fixedCostTuple != null)
+        {
+            fixedCost = fixedCostTuple.Value.fixedCost;
+        }
+
+        if (ignoreDigivolutionRequirement)
+        {
+            fixedCost = ignoreDigivolutionRequirementFixedCost;
+        }
+
+        bool CanSelectCardCondition(CardSource cardSource)
+        {
+            if (cardSource.IsDigimon)
+            {
+                if (cardCondition == null || cardCondition(cardSource))
+                {
+                    if (!cardSource.CanNotEvolve(targetPermanent))
+                    {
+                        if (ignoreLevel
+                        || cardSource.CanPlayCardTargetFrame(
+                            frame: targetPermanent.PermanentFrame,
+                            PayCost: payCost,
+                            cardEffect: activateClass,
+                            root: root,
+                            fixedCost: fixedCost))
+                        {
+                            return true;
+                        }
+                    }
+                }
+            }
+
+            return false;
+        }
+
+        #region reduce cost
+        Func<EffectTiming, ICardEffect> getChangeCostEffect = null;
+
+        if (reduceCostTuple != null)
+        {
+            bool PermanentCondition(Permanent permanent)
+            {
+                return permanent == targetPermanent;
+            }
+
+            bool CardCondition(CardSource cardSource)
+            {
+                if (cardSource != null)
+                {
+                    if (cardSource.Owner == owner)
+                    {
+                        if (reduceCostTuple.Value.reduceCostCardCondition == null || reduceCostTuple.Value.reduceCostCardCondition(cardSource))
+                        {
+                            return true;
+                        }
+                    }
+                }
+
+                return false;
+            }
+
+            getChangeCostEffect = ChangeDigivolutionCostPlayerEffect(
+                permanentCondition: PermanentCondition,
+                cardCondition: CardCondition,
+                rootCondition: null,
+                changeValue: -reduceCostTuple.Value.reduceCost,
+                activateClass: activateClass,
+                setFixedCost: false);
+
+            if (getChangeCostEffect != null)
+            {
+                AddEffectToPlayer(
+                    effectDuration: EffectDuration.UntilCalculateFixedCost,
+                    card: targetPermanent.TopCard,
+                    cardEffect: null,
+                    timing: EffectTiming.None,
+                    getCardEffect: getChangeCostEffect);
+            }
+        }
+        #endregion
+
+        #region set fixed cost
+        Func<EffectTiming, ICardEffect> getFixedCostEffect = null;
+
+        if (fixedCostTuple != null)
+        {
+            bool PermanentCondition(Permanent permanent)
+            {
+                return permanent == targetPermanent;
+            }
+
+            bool CardCondition(CardSource cardSource)
+            {
+                if (cardSource != null)
+                {
+                    if (cardSource.Owner == owner)
+                    {
+                        if (fixedCostTuple.Value.fixedCostCardCondition == null || fixedCostTuple.Value.fixedCostCardCondition(cardSource))
+                        {
+                            return true;
+                        }
+                    }
+                }
+
+                return false;
+            }
+
+            getFixedCostEffect = ChangeDigivolutionCostPlayerEffect(
+                permanentCondition: PermanentCondition,
+                cardCondition: CardCondition,
+                rootCondition: null,
+                changeValue: fixedCost,
+                activateClass: activateClass,
+                setFixedCost: true);
+
+            if (getChangeCostEffect != null)
+            {
+                AddEffectToPlayer(
+                    effectDuration: EffectDuration.UntilCalculateFixedCost,
+                    card: targetPermanent.TopCard,
+                    cardEffect: null,
+                    timing: EffectTiming.None,
+                    getCardEffect: getFixedCostEffect);
+            }
+        }
+        #endregion
+
+        #region ignore digivolution requirement
+        Func<EffectTiming, ICardEffect> getIgnoreDigivolutionRequirementEffect = null;
+
+        if (ignoreDigivolutionRequirement)
+        {
+            bool PermanentCondition(Permanent permanent)
+            {
+                return permanent == targetPermanent;
+            }
+
+            bool CardCondition(CardSource cardSource)
+            {
+                if (cardSource == null)
+                {
+                    return false;
+                }
+
+                if (cardSource.Owner != owner)
+                {
+                    return false;
+                }
+
+                if (cardCondition == null || cardCondition(cardSource))
+                {
+                    return true;
+                }
+
+                return false;
+            }
+
+            getIgnoreDigivolutionRequirementEffect = GainIgnoreDigivolutionRequirementPlayerEffect(
+                permanentCondition: PermanentCondition,
+                cardCondition: CardCondition,
+                ignoreDigivolutionRequirement: ignoreDigivolutionRequirement,
+                digivolutionCost: fixedCost,
+                activateClass: activateClass);
+
+            if (getIgnoreDigivolutionRequirementEffect != null)
+            {
+                AddEffectToPlayer(
+                effectDuration: EffectDuration.UntilCalculateFixedCost,
+                card: targetPermanent.TopCard,
+                cardEffect: null,
+                timing: EffectTiming.None,
+                getCardEffect: getIgnoreDigivolutionRequirementEffect);
+            }
+        }
+        #endregion
+
+        List<CardSource> selectedCards = new List<CardSource>();
+
+        IEnumerator SelectCardCoroutine(CardSource cardSource)
+        {
+            selectedCards.Add(cardSource);
+
+            yield return null;
+        }
+
+            if (owner.ExecutingCards.Count(CanSelectCardCondition) >= 1)
+            {
+                int maxCount = 1;
+
+                SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
+
+                selectCardEffect.SetUp(
+                            canTargetCondition: CanSelectCardCondition,
+                            canTargetCondition_ByPreSelecetedList: null,
+                            canEndSelectCondition: null,
+                            canNoSelect: () => true,
+                            selectCardCoroutine: SelectCardCoroutine,
+                            afterSelectCardCoroutine: null,
+                            message: "Select 1 card to digivolve.",
+                            maxCount: maxCount,
+                            canEndNotMax: false,
+                            isShowOpponent: true,
+                            mode: SelectCardEffect.Mode.Custom,
+                            root: SelectCardEffect.Root.Execution,
+                            customRootCardList: null,
+                            canLookReverseCard: true,
+                            selectPlayer: owner,
+                            cardEffect: activateClass);
+
+                selectCardEffect.SetUpCustomMessage("Select 1 card to digivolve.", "The opponent is selecting 1 card to digivolve.");
+                selectCardEffect.SetUpCustomMessage_ShowCard("Selected Card");
+
+                yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
+            }
+            else
+            {
+                selectedCards.Add(activateClass.EffectSourceCard);
+            }
+        
+
+        PlayCardClass playCardClass = new PlayCardClass(
+            cardSources: selectedCards,
+            hashtable: CardEffectHashtable(activateClass),
+            payCost: payCost,
+            targetPermanent: targetPermanent,
+            isTapped: false,
+            root: root,
+            activateETB: true);
+
+        if (ignoreLevel) playCardClass.SetIgnoreLevel();
+        if (!ignoreDigivolutionRequirement && fixedCost >= 0) playCardClass.SetFixedCost(fixedCost);
+
+        yield return ContinuousController.instance.StartCoroutine(playCardClass.PlayCard());
+
+        #region release effect
+        if (getChangeCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getChangeCostEffect);
+        #endregion
+
+        #region release effect
+        if (getFixedCostEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getFixedCostEffect);
+        #endregion
+
+        #region release effect
+        if (getIgnoreDigivolutionRequirementEffect != null) owner.UntilCalculateFixedCostEffect.Remove(getIgnoreDigivolutionRequirementEffect);
+        #endregion
+
+        if (selectedCards.Count >= 1)
+        {
+
+            if (IsDigivolvedByTheEffect(targetPermanent, selectedCards[0], activateClass))
+            {
+                if (successProcess != null)
+                {
+                    yield return ContinuousController.instance.StartCoroutine(successProcess);
+                }
+            }
+        }
+    }
+    #endregion
+
     #region Get the effect given by EffectTiming
     #region Get the effect given by EffectTiming
     public static Func<EffectTiming, ICardEffect> GetCardEffectByEffectTiming(EffectTiming timing, ICardEffect cardEffect) => (_timing) => _timing == timing ? cardEffect : null;
     public static Func<EffectTiming, ICardEffect> GetCardEffectByEffectTiming(EffectTiming timing, ICardEffect cardEffect) => (_timing) => _timing == timing ? cardEffect : null;
     #endregion
     #endregion