Pārlūkot izejas kodu

Merge pull request #625 from DCGO2/hooperk-BT24-090

Fix BT24-090 Performance
x89rt2 4 mēneši atpakaļ
vecāks
revīzija
47d61d9186
1 mainītis faili ar 121 papildinājumiem un 29 dzēšanām
  1. 121 29
      Assets/Scripts/CardEffect/BT24/Blue/BT24_090.cs

+ 121 - 29
Assets/Scripts/CardEffect/BT24/Blue/BT24_090.cs

@@ -36,6 +36,7 @@ namespace DCGO.CardEffects.BT24
 
 
             #region All Turns - Security
             #region All Turns - Security
 
 
+            #region Blocker
             if (timing == EffectTiming.None)
             if (timing == EffectTiming.None)
             {
             {
                 bool PermanentCondition(Permanent permanent)
                 bool PermanentCondition(Permanent permanent)
@@ -45,56 +46,147 @@ namespace DCGO.CardEffects.BT24
                         && permanent.TopCard.HasTSTraits;
                         && permanent.TopCard.HasTSTraits;
                 }
                 }
 
 
-                #region Blocker
                 bool CanUseCondition()
                 bool CanUseCondition()
                 {
                 {
                     return CardEffectCommons.IsExistInSecurity(card, false);
                     return CardEffectCommons.IsExistInSecurity(card, false);
                 }
                 }
 
 
                 cardEffects.Add(CardEffectFactory.BlockerStaticEffect(permanentCondition: PermanentCondition, isInheritedEffect: false, card: card, condition: CanUseCondition));
                 cardEffects.Add(CardEffectFactory.BlockerStaticEffect(permanentCondition: PermanentCondition, isInheritedEffect: false, card: card, condition: CanUseCondition));
-                #endregion
-
-                #region Alliance
-                AddSkillClass addSkillClass1 = new AddSkillClass();
-                addSkillClass1.SetUpICardEffect("Your Digimon gain <Alliance>", CanUseCondition1, card);
-                addSkillClass1.SetUpAddSkillClass(cardSourceCondition: CardSourceCondition, getEffects: GetEffects1);
-                cardEffects.Add(addSkillClass1);
+                
+            }
+            #endregion
 
 
-                bool CardSourceCondition(CardSource cardSource)
-                {
-                    return CardEffectCommons.IsExistOnBattleAreaDigimon(cardSource) &&
-                           cardSource == cardSource.PermanentOfThisCard().TopCard &&
-                           PermanentCondition(cardSource.PermanentOfThisCard());
-                }
+            #region Alliance
 
 
-                bool CanUseCondition1(Hashtable hashtable)
-                {
-                    return CardEffectCommons.IsExistInSecurity(card, false) &&
-                           CardEffectCommons.HasMatchConditionOwnersPermanent(card, HasOXII);
-                }
+            string GrantedAllianceHashstring(CardSource cardSource) => $"BT24_090_Alliance_On_{cardSource.CardIndex}_From_{card.CardIndex}";//Get unique reference of this card granting to particular cardsource
 
 
+            /// 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)
                 bool HasOXII(Permanent permanent)
                 {
                 {
                     return permanent.TopCard.EqualsCardName("Neptunemon")
                     return permanent.TopCard.EqualsCardName("Neptunemon")
                         || permanent.TopCard.EqualsCardName("Venusmon");
                         || permanent.TopCard.EqualsCardName("Venusmon");
                 }
                 }
 
 
-                List<ICardEffect> GetEffects1(CardSource cardSource, List<ICardEffect> effects, EffectTiming effectTiming)
+                bool Condition()
+                {
+                    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
+                }
+
+                ICardEffect cardEffect = CardEffectFactory.AllianceSelfEffect(false, cardSource, Condition);
+                cardEffect.SetHashString(GrantedAllianceHashstring(cardSource)); // Unique identifier using exact card object references
+                return cardEffect;
+            }
+
+            ///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);
+
+                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
+
+            #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);
 
 
-                    return effects;
+                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
 
 
             #endregion
             #endregion
 
 
@@ -376,4 +468,4 @@ namespace DCGO.CardEffects.BT24
             return cardEffects;
             return cardEffects;
         }
         }
     }
     }
-}
+}