Explorar o código

Merge pull request #928 from DCGO2/x89rt2-patch-19

Update BT24_094.cs
hooperk hai 4 meses
pai
achega
15b8d4c29f
Modificáronse 1 ficheiros con 115 adicións e 27 borrados
  1. 115 27
      Assets/Scripts/CardEffect/BT24/Green/BT24_094.cs

+ 115 - 27
Assets/Scripts/CardEffect/BT24/Green/BT24_094.cs

@@ -34,7 +34,7 @@ namespace DCGO.CardEffects.BT24
 
             #endregion
 
-            #region All Turns - Security
+            #region All Turns - Security DP
 
             if (timing == EffectTiming.None)
             {
@@ -59,49 +59,137 @@ namespace DCGO.CardEffects.BT24
                     condition: CanUseCondition,
                     effectName: () => "All of your green or yellow [TS] trait Digimon get +2000 DP."));
                 #endregion
+            }
 
-                #region Alliance
-                AddSkillClass addSkillClass1 = new AddSkillClass();
-                addSkillClass1.SetUpICardEffect("Your Digimon gain <Alliance>", CanUseCondition1, card);
-                addSkillClass1.SetUpAddSkillClass(cardSourceCondition: CardSourceCondition, getEffects: GetEffects1);
-                cardEffects.Add(addSkillClass1);
+            #region All Turns - Security Alliance
+            string GrantedAllianceHashstring(CardSource cardSource) => $"BT24_090_Alliance_On_{cardSource.CardIndex}_From_{card.CardIndex}";//Get unique reference of this card granting to particular cardsource
 
-                bool CanUseCondition1(Hashtable hashtable)
+            /// Alliance effect which is granted to all of your Digimon while this card is face up in security
+            /// The effect itself tracks if the card granting it is still present and if the conditions for granting are still met
+            ICardEffect GetAllianceEffect(CardSource cardSource)
+            {
+                bool HasOXII(Permanent permanent)
                 {
-                    return CardEffectCommons.IsExistInSecurity(card, false) &&
-                           CardEffectCommons.HasMatchConditionOwnersPermanent(card, HasOXII);
+                    return permanent.TopCard.EqualsCardName("Merukimon")
+                        || permanent.TopCard.EqualsCardName("Minervamon");
                 }
 
-                bool CardSourceCondition(CardSource cardSource)
+                bool Condition()
                 {
-                    return CardEffectCommons.IsExistOnBattleAreaDigimon(cardSource) &&
-                           cardSource == cardSource.PermanentOfThisCard().TopCard &&
-                           PermanentCondition(cardSource.PermanentOfThisCard());
+                    return CardEffectCommons.IsExistInSecurity(card, false) //Is this card that provides the effect still providing the effect
+                        && cardSource == cardSource.PermanentOfThisCard().TopCard //Added effects don't check if it is inherited or not so have to check that this is the topcard
+                        && (cardSource.CardColors.Contains(CardColor.Blue) || cardSource.CardColors.Contains(CardColor.Yellow))
+                        && cardSource.HasTSTraits // Does this card meet conditions
+                        && CardEffectCommons.HasMatchConditionOwnersPermanent(card, HasOXII); // Is the condition for granting met
                 }
 
-                bool HasOXII(Permanent permanent)
-                {
-                    return permanent.TopCard.EqualsCardName("Merukimon")
-                        || permanent.TopCard.EqualsCardName("Minervamon");
-                }
+                ICardEffect cardEffect = CardEffectFactory.AllianceSelfEffect(false, cardSource, Condition);
+                cardEffect.SetHashString(GrantedAllianceHashstring(cardSource)); // Unique identifier using exact card object references
+                return cardEffect;
+            }
 
-                List<ICardEffect> GetEffects1(CardSource cardSource, List<ICardEffect> effects, EffectTiming effectTiming)
+            ///Grant all cards in a permanent the effect permanently
+            ///Grants to every card so effect can survive through degeneration
+            ///The effect's CanUseCondition will deactivate when the conditions for granting are not met
+            void GrantEffect(List<Permanent> permanents)
+            {
+                foreach (Permanent permanent in permanents)
                 {
-                    if (effectTiming == EffectTiming.OnAllyAttack)
+                    foreach (CardSource cardSource in permanent.cardSources)
                     {
-                        bool Condition()
-                        {
-                            return CardSourceCondition(cardSource);
-                        }
+                        if (!cardSource.HasDP || permanent.EffectList_ForCard(EffectTiming.OnAllyAttack, cardSource).Any(effect => effect.HashString == GrantedAllianceHashstring(cardSource)))
+                            continue; // if the card could not be a relevant top card or if it already has the effect, don't grant the effect
 
-                        effects.Add(CardEffectFactory.AllianceSelfEffect(false, cardSource, Condition));
+                        Func<EffectTiming, ICardEffect> getCardEffect = CardEffectCommons.GetCardEffectByEffectTiming(timing: EffectTiming.OnAllyAttack, cardEffect: GetAllianceEffect(cardSource));
+
+                        permanent.PermanentEffects.Add(getCardEffect);
                     }
+                }
+            }
+
+            string SharedEffectDescription() => "(Security) [All Turns] All of your blue or yellow [TS] trait Digimon gain <Blocker>. While you have [Neptunemon] or [Venusmon], all of your blue or yellow [TS] trait Digimon gain <Alliance>.";
+
+            bool IsYourPermanent(Permanent permanent) => CardEffectCommons.IsPermanentExistsOnOwnerBattleArea(permanent, card);
+
+            #region Give permanents conditional Alliance on card added to security
+            if (timing == EffectTiming.OnAddSecurity)
+            {
+                ActivateClass activateClass = new();
+                activateClass.SetUpICardEffect("Set Up Alliance", CanUseCondition, card);
+                activateClass.SetUpActivateClass(null, ActivateCoroutine, -1, false, SharedEffectDescription());
+                activateClass.SetIsBackgroundProcess(true);
+                cardEffects.Add(activateClass);
 
-                    return effects;
+                bool CanUseCondition(Hashtable hashtable)
+                {
+                    return CardEffectCommons.IsExistInSecurity(card, false)
+                        && CardEffectCommons.GetCardSourcesFromHashtable(hashtable).Contains(card);
+                }
+
+                IEnumerator ActivateCoroutine(Hashtable hashtable)
+                {
+                    List<Permanent> permanents = card.Owner.GetBattleAreaPermanents();
+                    GrantEffect(permanents);
+                    yield return null;
+                }
+            }
+            #endregion
+
+            #region Give permanents conditional Alliance on permanent enter
+            if (timing == EffectTiming.OnEnterFieldAnyone)
+            {
+                ActivateClass activateClass = new();
+                activateClass.SetUpICardEffect("Set Up Alliance", CanUseCondition, card);
+                activateClass.SetUpActivateClass(null, ActivateCoroutine, -1, false, SharedEffectDescription());
+                activateClass.SetIsBackgroundProcess(true);
+                cardEffects.Add(activateClass);
+
+                bool CanUseCondition(Hashtable hashtable)
+                {
+                    return CardEffectCommons.IsExistInSecurity(card, false)
+                        && (CardEffectCommons.CanTriggerOnPermanentPlay(hashtable, IsYourPermanent)
+                            || CardEffectCommons.CanTriggerWhenPermanentDigivolving(hashtable, IsYourPermanent));
+                }
+
+                IEnumerator ActivateCoroutine(Hashtable hashtable)
+                {
+                    List<Permanent> permanents = CardEffectCommons.GetHashtablesFromHashtable(hashtable)
+                            .Map(CardEffectCommons.GetPermanentFromHashtable)
+                            .Filter(IsYourPermanent);
+                    GrantEffect(permanents);
+                    yield return null;
                 }
-                #endregion
             }
+            #endregion
+
+            #region Give permanents conditional Alliance on card added to permanent stack
+            if (timing == EffectTiming.OnAddDigivolutionCards)
+            {
+                ActivateClass activateClass = new();
+                activateClass.SetUpICardEffect("Set Up Alliance", CanUseCondition, card);
+                activateClass.SetUpActivateClass(null, ActivateCoroutine, -1, false, SharedEffectDescription());
+                activateClass.SetIsBackgroundProcess(true);
+                cardEffects.Add(activateClass);
+
+                bool CanUseCondition(Hashtable hashtable)
+                {
+                    return CardEffectCommons.IsExistInSecurity(card, false)
+                        && CardEffectCommons.CanTriggerOnAddDigivolutionCard(
+                                hashtable: hashtable,
+                                permanentCondition: IsYourPermanent,
+                                cardEffectCondition: null,
+                                cardCondition: null);
+                }
 
+                IEnumerator ActivateCoroutine(Hashtable hashtable)
+                {
+                    List<Permanent> permanents = new List<Permanent>() { CardEffectCommons.GetPermanentFromHashtable(hashtable) };
+                    GrantEffect(permanents);
+                    yield return null;
+                }
+            }
+            #endregion
+            #endregion
             #endregion
 
             #region Main Effect