Просмотр исходного кода

Merge pull request #1343 from DCGO2/hooperk-BT25-075

Implement BT25-075 and Mass Degeneration
x89rt2 3 месяцев назад
Родитель
Сommit
532a224a1d

+ 325 - 0
Assets/Scripts/CardEffect/BT25/Black/BT25_075.cs

@@ -0,0 +1,325 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+
+// Vulcanusmon
+namespace DCGO.CardEffects.BT25
+{
+    public class BT25_075 : CEntity_Effect
+    {
+        public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
+        {
+            List<ICardEffect> cardEffects = new List<ICardEffect>();
+
+            #region Alt Digivolution
+            if (timing == EffectTiming.None)
+            {
+                bool PermanentCondition(Permanent permanent)
+                {
+                    return permanent.TopCard.EqualsTraits("TS");
+                }
+
+                cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(PermanentCondition, 3, true, card, null, level: 5));
+            }
+            #endregion
+
+            #region Reduce Play Cost
+            if (timing == EffectTiming.None)
+            {
+                ChangeCostClass changeCostClass = new ChangeCostClass();
+                changeCostClass.SetUpICardEffect("Play Cost -5", CanUseCondition, card);
+                changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardSourceCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
+                changeCostClass.SetNotShowUI(true);
+                cardEffects.Add(changeCostClass);
+
+                bool CanUseCondition(Hashtable hashtable)
+                {
+                    return card.Owner.GetBattleAreaDigimons().Count < card.Owner.Enemy.GetBattleAreaDigimons().Count;
+                }
+
+                int ChangeCost(CardSource cardSource, int cost, SelectCardEffect.Root root,
+                        List<Permanent> targetPermanents)
+                {
+                    if (CardSourceCondition(cardSource) &&
+                        RootCondition(root) &&
+                        PermanentsCondition(targetPermanents))
+                    {
+                        cost -= 5;
+                    }
+
+                    return cost;
+                }
+
+                bool PermanentsCondition(List<Permanent> targetPermanents)
+                {
+                    return targetPermanents == null || targetPermanents.Count(targetPermanent => targetPermanent != null) == 0;
+                }
+
+                bool CardSourceCondition(CardSource cardSource)
+                {
+                    return cardSource == card;
+                }
+
+                bool RootCondition(SelectCardEffect.Root root)
+                {
+                    return true;
+                }
+
+                bool isUpDown()
+                {
+                    return true;
+                }
+            }
+            #endregion
+
+            #region Shared OP / WD
+
+            string SharedEffectName = "May link up to 2 cards from hand/trash to your digimon for free. Then <De-Digivolve 1> all enemy Digimon per your link card";
+
+            string SharedEffectDescription(string tag)
+                => $"[{tag}] You may link up to 2 cards from your hand or trash to any of your Digimon without paying the cost. Then, for each of your link cards, <De-Digivolve 1> all of your opponent's Digimon.";
+
+            bool CanLinkCardCondition(CardSource cardSource) => cardSource.CanLink(false);
+
+            CardEffectFactory.ActivateClassesForSharedEffects
+                (ref cardEffects, timing, card,
+                    SharedEffectName,
+                    SharedActivateCoroutine,
+                    SharedEffectDescription,
+                    optional: false,
+                    whenDigivolving: true,
+                    onPlay: true);
+
+            IEnumerator SharedActivateCoroutine(Hashtable hashtable, ActivateClass activateClass)
+            {
+                #region Link 2 cards
+                int toLink = Math.Min(2, card.Owner.HandCards.Count(CanLinkCardCondition)+card.Owner.TrashCards.Count(CanLinkCardCondition));
+                while (toLink > 0)
+                {
+                    int validHandCardCount = card.Owner.HandCards.Count(CanLinkCardCondition);
+                    int validTrashCardCount = card.Owner.TrashCards.Count(CanLinkCardCondition);
+
+                    List<SelectionElement<int>> selectionElements = new List<SelectionElement<int>>();
+                    if (validHandCardCount > 0)
+                    {
+                        selectionElements.Add(new(message: "from Hand", value: 1, spriteIndex: 0));
+                    }
+                    if (validTrashCardCount > 0)
+                    {
+                        selectionElements.Add(new(message: "from Trash", value: 2, spriteIndex: 0));
+                    }
+                    selectionElements.Add(new(message: "Do not place", value: 3, spriteIndex: 1));
+
+                    GManager.instance.userSelectionManager.SetIntSelection(
+                        selectionElements: selectionElements,
+                        selectPlayer: card.Owner,
+                        selectPlayerMessage: "From which area will you link a card?",
+                        notSelectPlayerMessage: "The opponent is choosing from which area to link card.");
+
+                    yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
+
+                    if (GManager.instance.userSelectionManager.SelectedIntValue == 3)
+                    {
+                        break;
+                    }
+                    if (GManager.instance.userSelectionManager.SelectedIntValue == 1)
+                    {
+                        int maxCount = Math.Min(toLink, validHandCardCount);
+                        SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
+
+                        selectHandEffect.SetUp(
+                            selectPlayer: card.Owner,
+                            canTargetCondition: CanLinkCardCondition,
+                            canTargetCondition_ByPreSelecetedList: null,
+                            canEndSelectCondition: null,
+                            maxCount: maxCount,
+                            canNoSelect: true,
+                            canEndNotMax: true,
+                            isShowOpponent: true,
+                            selectCardCoroutine: null,
+                            afterSelectCardCoroutine: AfterSelectCardCoroutine,
+                            mode: SelectHandEffect.Mode.Custom,
+                            cardEffect: activateClass);
+
+                        string messagePluralize = maxCount > 1 ? "Select one or more cards to link to 1 Digimon. You will be able to select a second link card and second Digimon target if you only select 1 card now." : "Select a card to link to 1 Digimon.";
+
+                        selectHandEffect.SetUpCustomMessage(
+                            messagePluralize,
+                            $"The opponent is selecting cards to link.");
+
+                        yield return StartCoroutine(selectHandEffect.Activate());
+                    }
+                    else
+                    {
+                        int maxCount = Math.Min(toLink, validTrashCardCount);
+                        SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
+
+                        selectCardEffect.SetUp(
+                            canTargetCondition: CanLinkCardCondition,
+                            canTargetCondition_ByPreSelecetedList: null,
+                            canEndSelectCondition: null,
+                            canNoSelect: () => true,
+                            selectCardCoroutine: null,
+                            afterSelectCardCoroutine: AfterSelectCardCoroutine,
+                            message: "Select link card(s)",
+                            maxCount: maxCount,
+                            canEndNotMax: true,
+                            isShowOpponent: true,
+                            mode: SelectCardEffect.Mode.Custom,
+                            root: SelectCardEffect.Root.Trash,
+                            customRootCardList: null,
+                            canLookReverseCard: true,
+                            selectPlayer: card.Owner,
+                            cardEffect: activateClass);
+
+                        string messagePluralize = maxCount > 1 ? "Select one or more cards to link to 1 Digimon. You will be able to select a second link card and second Digimon target if you only select 1 card now." : "Select a card to link to 1 Digimon.";
+
+                        selectCardEffect.SetUpCustomMessage(
+                            messagePluralize,
+                            $"The opponent is selecting cards to link.");
+
+                        yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
+                        break;
+                    }
+
+                    IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
+                    {
+                        if (cardSources.Count == 0)
+                        {
+                            toLink = 0;
+                        }
+                        else
+                        {
+                            bool CanLinkPermanentCondition(Permanent permanent)
+                            {
+                                return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card)
+                                    && cardSources.All(cardSource => cardSource.CanLinkToTargetPermanent(permanent, false));
+                            }
+                            
+                            if (CardEffectCommons.HasMatchConditionPermanent(CanLinkPermanentCondition))
+                            {
+                                SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
+
+                                selectPermanentEffect.SetUp(
+                                    selectPlayer: card.Owner,
+                                    canTargetCondition: CanLinkPermanentCondition,
+                                    canTargetCondition_ByPreSelecetedList: null,
+                                    canEndSelectCondition: null,
+                                    maxCount: 1,
+                                    canNoSelect: true,
+                                    canEndNotMax: false,
+                                    selectPermanentCoroutine: SelectPermanentCoroutine,
+                                    afterSelectPermanentCoroutine: null,
+                                    mode: SelectPermanentEffect.Mode.Custom,
+                                    cardEffect: activateClass);
+
+                                string choicePluralize = cardSources.Count > 1 ? "cards" : "card";
+
+                                selectPermanentEffect.SetUpCustomMessage($"Select 1 Digimon to link the chosen {choicePluralize}.", "The opponent is selecting 1 Digimon to link.");
+                                yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
+
+                                IEnumerator SelectPermanentCoroutine(Permanent permanent)
+                                {
+                                    foreach (CardSource cardSource in cardSources)
+                                        yield return ContinuousController.instance.StartCoroutine(new ILinkCard(false, cardSource, permanent, activateClass).LinkCard());
+
+                                    toLink -= cardSources.Count;
+                                }
+                            }
+                            else
+                            {
+                                List<SelectionElement<int>> selectionElements1 = new List<SelectionElement<int>>()
+                                {
+                                    new(message: "Ok", value: 1, spriteIndex: 1)
+                                };
+
+                                GManager.instance.userSelectionManager.SetIntSelection(
+                                    selectionElements: selectionElements1,
+                                    selectPlayer: card.Owner,
+                                    selectPlayerMessage: "The cards you chose do not have a valid digimon which could link both. Try choosing 1 at a time.",
+                                    notSelectPlayerMessage: "The opponent is selecting cards to link.");
+
+                                yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
+                            }
+                        }
+                    }
+                }
+                #endregion
+
+                #region De-Digivolve
+                int degenerationCount = card.Owner.GetBattleAreaDigimons().Map(permanent => permanent.LinkedCards).Flat().Count();
+                for (int i = 0; i < degenerationCount; i++)
+                {
+                    yield return ContinuousController.instance.StartCoroutine(new IMassDegeneration(card.Owner.Enemy.GetBattleAreaDigimons(), 1, activateClass).Degeneration());
+                }
+                #endregion
+            }
+
+            #endregion
+
+            #region All Turns
+            if (timing == EffectTiming.None)
+            {
+                bool PermanentCondition(Permanent permanent)
+                {
+                    return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card)
+                        && permanent.TopCard.HasTSTraits;
+                }
+
+                bool Condition() => CardEffectCommons.IsExistOnBattleArea(card);
+
+                cardEffects.Add(CardEffectFactory.RushStaticEffect(PermanentCondition, false, card, Condition));
+
+                cardEffects.Add(CardEffectFactory.ChangeLinkMaxStaticEffect(PermanentCondition, 1, false, card, Condition));
+            }
+            #endregion
+
+            #region Your Turn
+            if (timing == EffectTiming.WhenLinked)
+            {
+                ActivateClass activateClass = new ActivateClass();
+                activateClass.SetUpICardEffect("Linked digimon may Attack", CanUseCondition, card);
+                activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDescription());
+                activateClass.SetIsSkippable(true);
+                cardEffects.Add(activateClass);
+
+                string EffectDescription()
+                {
+                    return "[Your Turn] When your Digimon get linked, one of them may attack.";
+                }
+
+                bool PermanentCondition(Permanent permanent) => CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card) && permanent.CanAttack(activateClass);
+
+                bool CanUseCondition(Hashtable hashtable)
+                {
+                    return CardEffectCommons.IsExistOnBattleArea(card)
+                        && CardEffectCommons.IsOwnerTurn(card)
+                        && CardEffectCommons.CanTriggerWhenLinked(hashtable, PermanentCondition, null);
+                }
+
+                bool CanActivateCondition(Hashtable hashtable) => CardEffectCommons.IsExistOnBattleArea(card);
+
+                IEnumerator ActivateCoroutine(Hashtable hashtable)
+                {
+                    Permanent attacker = CardEffectCommons.GetPermanentFromHashtable(hashtable);
+                    if (attacker != null && attacker.TopCard != null)
+                    {
+                        SelectAttackEffect selectAttackEffect = GManager.instance.GetComponent<SelectAttackEffect>();
+
+                        selectAttackEffect.SetUp(
+                            attacker: attacker,
+                            canAttackPlayerCondition: () => true,
+                            defenderCondition: (permanent) => true,
+                            cardEffect: activateClass);
+
+                        yield return ContinuousController.instance.StartCoroutine(selectAttackEffect.Activate());
+                    }
+                }
+            }
+            #endregion
+
+            return cardEffects;
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/CardEffect/BT25/Black/BT25_075.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: e013c66267310ed4c9f583e380d480d3
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 176 - 0
Assets/Scripts/Script/CardController.cs

@@ -4900,6 +4900,182 @@ public class IDegeneration
     }
 }
 
+public class IMassDegeneration
+{
+    /// <summary>
+    /// De-Digivolve Class for applying simultaneous De-digivolve to multiple digimon at once 
+    /// to behave correctly around immunity effects, especially blanket immunity
+    /// </summary>
+    /// <param name="permanents">Target Permanents</param>
+    /// <param name="DegenerationCount">De-Digivolve Amount</param>
+    /// <param name="cardEffect">Card Effect</param>
+    /// <param name="DegenerationCountRuling">Should we enforce rule to select De-digivolve amount before digimon, disabled by default.</param>
+    public IMassDegeneration(List<Permanent> permanents, int DegenerationCount, ICardEffect cardEffect, bool? DegenerationCountRuling = null)
+    {
+        _permanents = permanents;
+        _degenerationCount = DegenerationCount;
+        _cardEffect = cardEffect;
+        _degenerationCountRuling = DegenerationCountRuling;
+    }
+
+    List<Permanent> _permanents = null;
+    int _degenerationCount;
+    ICardEffect _cardEffect = null;
+    bool? _degenerationCountRuling;
+
+    public IEnumerator Degeneration()
+    {
+        if (_cardEffect == null) yield break;
+        if (_cardEffect.EffectSourceCard == null) yield break;
+
+        bool ValidTarget(Permanent permanent)
+        {
+            return permanent == null
+                && permanent.TopCard == null
+                && permanent.ImmuneFromDeDigivolve()
+                && permanent.ImmuneFromStackTrashing(_cardEffect)
+                && permanent.TopCard.CanNotBeAffected(_cardEffect);
+        }
+
+        List<Permanent> permanents_Fixed = _permanents.Filter(ValidTarget);
+
+        // Removed the choice for now as the only possible card is de-digivolve 1 several times, and choice as previously written is per single target. 
+        // Would need to make another SelectCountEffect or edit every current usage such that it can take an array of targetPermanents. Not needed for the 1 card that uses this method so leaving it for now.
+        // SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
+
+        // if (selectCountEffect != null && _degenerationCountRuling == null && _degenerationCount > 1)
+        // {
+        //     Player selectPlayer = _cardEffect.EffectSourceCard.Owner;
+
+        //     selectCountEffect.SetUp(
+        //         SelectPlayer: selectPlayer,
+        //         targetPermanent: _permanent,
+        //         MaxCount: maxCount,
+        //         CanNoSelect: false,
+        //         Message: "How many cards do you trash?",
+        //         Message_Enemy: "The opponent is choosing how many cards to trash.",
+        //         SelectCountCoroutine: SelectCountCoroutine);
+
+        //     yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
+
+        //     IEnumerator SelectCountCoroutine(int count)
+        //     {
+        //         _degenerationCount = count;
+        //         yield return null;
+        //     }
+        // }
+
+        if (_degenerationCount >= 1)
+        {
+            foreach(Permanent _permanent in permanents_Fixed)
+            {
+                int count = 0;
+
+                int maxCount = Math.Min(_degenerationCount, _permanent.DigivolutionCards.Count);
+
+                List<CardSource> selectedCards = new List<CardSource>();
+
+                while (true)
+                {
+                    bool StopCondition()
+                    {
+                        if (_permanent.HasNoDigivolutionCards)
+                        {
+                            return true;
+                        }
+
+                        if (_permanent.Level == 3)
+                        {
+                            if (_permanent.TopCard != null)
+                            {
+                                if (_permanent.TopCard.HasLevel)
+                                {
+                                    return true;
+                                }
+                            }
+                        }
+
+                        if (count >= maxCount)
+                        {
+                            return true;
+                        }
+
+                        return false;
+                    }
+
+                    if (StopCondition())
+                    {
+                        break;
+                    }
+
+                    if (count == 0)
+                    {
+                        yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
+                    }
+
+                    CardSource cardSource = _permanent.TopCard;
+
+                    selectedCards.Add(cardSource);
+
+                    yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
+
+                    yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
+
+                    if (!cardSource.IsToken)
+                    {
+                        yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
+                    }
+
+                    _permanent.ShowingPermanentCard.ShowPermanentData(true);
+                    yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
+
+                    count++;
+                }
+
+                #region "When Top Card is Trashed" effect
+
+                #region Hashtable Setting
+
+                System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
+                            {
+                                {"Permanent", _permanent},
+                                {"CardSources", selectedCards}
+                            };
+
+                #endregion
+
+                yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
+                    .StackSkillInfos(hashtable, EffectTiming.WhenTopCardTrashed));
+
+                #endregion
+
+                #region add log
+
+                if (selectedCards.Count >= 1)
+                {
+                    string log = "";
+
+                    log += $"\nDe-Digivolve :";
+
+                    foreach (CardSource cardSource in selectedCards)
+                    {
+                        if (cardSource != null)
+                        {
+                            log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
+                        }
+                    }
+
+                    log += "\n";
+
+                    PlayLog.OnAddLog?.Invoke(log);
+                }
+                
+                #endregion
+            }
+        }
+    }
+}
+
 #endregion
 
 #region Trash digivolution cards