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

General fixes to link applications

mbunch_kascope пре 1 година
родитељ
комит
2423c7540f

+ 43 - 0
Assets/Scripts/AutoProcessing.cs

@@ -216,6 +216,22 @@ public class AutoProcessing : MonoBehaviourPunCallbacks
         return false;
     }
 
+    bool IsDigimonLackLinkCount(Permanent permanent)
+    {
+        if (permanent != null)
+        {
+            if (permanent.TopCard != null)
+            {
+                if (permanent.LinkedCards.Count >= permanent.LinkedMax)
+                {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
+
     public IEnumerator RuleProcess()
     {
         while (DoRuleProcess())
@@ -239,6 +255,8 @@ public class AutoProcessing : MonoBehaviourPunCallbacks
             //Link Lacking condition
             yield return ContinuousController.instance.StartCoroutine(DigimonLackLinkConditionProcess());
 
+            //TODO: Add link count correction
+
             IsRuleProcessing = false;
         }
     }
@@ -283,6 +301,8 @@ public class AutoProcessing : MonoBehaviourPunCallbacks
         }
         #endregion
 
+        //TODO: Add link count condition
+
         return false;
     }
     #endregion
@@ -397,6 +417,29 @@ public class AutoProcessing : MonoBehaviourPunCallbacks
     }
     #endregion
 
+    #region Link Card Lacking Max Count handling
+    IEnumerator DigimonLackLinkMaxCountProcess()
+    {
+        List<Permanent> LackLinkCountPermanents = GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
+            .Map(player => player.GetFieldPermanents()
+            .Filter(IsDigimonLackLinkCount)).Flat();
+
+        if (LackLinkCountPermanents.Count >= 1)
+        {
+            foreach (Permanent permanent in LackLinkCountPermanents)
+            {
+                if (permanent.LinkedCards.Count >= permanent.LinkedMax)
+                {
+                    if (permanent.LinkedMax > 1)
+                        yield return ContinuousController.instance.StartCoroutine(permanent.RemoveLinkedCard(null, (permanent.LinkedCards.Count - permanent.LinkedMax)));
+                    else
+                        yield return ContinuousController.instance.StartCoroutine(permanent.RemoveLinkedCard(permanent.LinkedCards[0]));
+                }
+            }
+        }
+    }
+    #endregion
+
     #endregion
 
     #endregion

+ 271 - 0
Assets/Scripts/CardController.cs

@@ -2604,6 +2604,277 @@ public class IPlacePermanentToDigivolutionCards
 }
 #endregion
 
+#region Place permanent to another permanent's Link cards
+public class IPlacePermanentToLinkCards
+{
+    public IPlacePermanentToLinkCards(
+        List<Permanent[]> permanentArrays,
+        ICardEffect cardEffect,
+        bool skipEffectAndActivateSkill = false)
+    {
+        permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
+        _cardEffect = cardEffect;
+        _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
+    }
+
+    public void SetNotShowCards()
+    {
+        _notShowCards = true;
+    }
+
+    List<Permanent[]> _permanentArrays = new List<Permanent[]>();
+    ICardEffect _cardEffect = null;
+    bool _notShowCards = false;
+    bool _skipEffectAndActivateSkill = false;
+    public bool Placed { get; private set; } = false;
+    public IEnumerator PlacePermanentToLinkCards()
+    {
+        if (_permanentArrays.Count == 0)
+        {
+            yield break;
+        }
+
+        List<CardSource> addedLinkCards = new List<CardSource>();
+
+        List<Permanent> removeFieldPermanents = new List<Permanent>();
+
+        foreach (Permanent[] permanentArray in _permanentArrays)
+        {
+            if (permanentArray.Length == 2)
+            {
+                Permanent LinkedPermanent = permanentArray[0];
+                Permanent getLinkPermanent = permanentArray[1];
+
+                if (LinkedPermanent != null && getLinkPermanent != null)
+                {
+                    if (LinkedPermanent.TopCard != null && getLinkPermanent.TopCard != null && !getLinkPermanent.IsToken)
+                    {
+                        if (_cardEffect != null)
+                        {
+                            if (LinkedPermanent.TopCard.CanNotBeAffected(_cardEffect) || getLinkPermanent.TopCard.CanNotBeAffected(_cardEffect))
+                            {
+                                continue;
+                            }
+                        }
+
+                        removeFieldPermanents.Add(LinkedPermanent);
+                    }
+                }
+            }
+        }
+
+        foreach (Permanent permanent in removeFieldPermanents)
+        {
+            permanent.willBeRemoveField = true;
+        }
+
+        if (removeFieldPermanents.Count == 0)
+        {
+            yield break;
+        }
+
+        #region Cut in Effects
+        List<SkillInfo> skillInfos = new List<SkillInfo>();
+
+        Hashtable hashtable1 =
+        CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
+                removeFieldPermanents,
+                _cardEffect,
+                null);
+
+        #region  "When permanents would remove field" effect
+
+        foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
+        {
+            #region permanents' effects
+            foreach (Permanent permanent1 in player.GetFieldPermanents())
+            {
+                foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
+                {
+                    if (cardEffect is ActivateICardEffect)
+                    {
+                        if (cardEffect.CanTrigger(hashtable1))
+                        {
+                            skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
+                        }
+                    }
+                }
+            }
+            #endregion
+
+            #region players' effects
+            foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
+            {
+                if (cardEffect is ActivateICardEffect)
+                {
+                    if (cardEffect.CanTrigger(hashtable1))
+                    {
+                        skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
+                    }
+                }
+            }
+            #endregion
+        }
+        #endregion
+
+        if (skillInfos.Count >= 1)
+        {
+            foreach (SkillInfo skillInfo in skillInfos)
+            {
+                GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
+            }
+
+            bool showEffect()
+            {
+                if (skillInfos.Count >= 2)
+                {
+                    return true;
+                }
+
+                else if (skillInfos.Count == 1)
+                {
+                    if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
+                    {
+                        return true;
+                    }
+                }
+
+                return false;
+            }
+
+            if (showEffect())
+            {
+                foreach (Permanent Permanent in removeFieldPermanents)
+                {
+                    if (Permanent != null)
+                    {
+                        if (Permanent.TopCard != null)
+                        {
+                            if (Permanent.willBeRemoveField)
+                            {
+                                if (Permanent.ShowingPermanentCard != null)
+                                {
+                                    if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
+                                    {
+                                        Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
+                                        Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+
+                #region shrink security Digimon display
+                if (GManager.instance.attackProcess.IsAttacking)
+                {
+                    if (GManager.instance.attackProcess.SecurityDigimon != null)
+                    {
+                        if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
+                        {
+                            yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
+                            yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
+                        }
+                    }
+                }
+                #endregion
+            }
+
+            // cut in effect process
+            yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
+
+            foreach (Permanent Permanent in removeFieldPermanents)
+            {
+                if (Permanent != null)
+                {
+                    if (Permanent.TopCard != null)
+                    {
+                        if (Permanent.ShowingPermanentCard != null)
+                        {
+                            if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
+                            {
+                                Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        #endregion
+
+        foreach (Permanent[] permanentArray in _permanentArrays)
+        {
+            if (permanentArray.Length == 2)
+            {
+                Permanent LinkedPermanent = permanentArray[0];
+                Permanent getLinkPermanent = permanentArray[1];
+
+                if (LinkedPermanent != null && getLinkPermanent != null)
+                {
+                    if (LinkedPermanent.TopCard != null && getLinkPermanent.TopCard != null && !getLinkPermanent.IsToken && LinkedPermanent.willBeRemoveField)
+                    {
+                        yield return ContinuousController.instance.StartCoroutine(LinkedPermanent.DiscardEvoRoots());
+
+                        CardSource cardSource = LinkedPermanent.TopCard;
+
+                        #region record used effect
+                        if (_cardEffect != null)
+                        {
+                            if (LinkedPermanent.TopCard != null)
+                            {
+                                LinkedPermanent.PlaceOtherPermanentEffect = _cardEffect;
+                            }
+                        }
+                        #endregion
+
+                        yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
+                            LinkedPermanent,
+                            ignoreOverflow: true));
+
+                        yield return ContinuousController.instance.StartCoroutine(getLinkPermanent.AddLinkCard(cardSource, _cardEffect));
+
+                        cardSource.cEntity_EffectController.InitUseCountThisTurn();
+
+                        addedLinkCards.Add(cardSource);
+
+                        Placed = true;
+                    }
+                }
+            }
+        }
+
+        #region add log
+        if (addedLinkCards.Count >= 1)
+        {
+            string log = "";
+
+            log += $"\nLink cards:";
+
+            foreach (CardSource cardSource in addedLinkCards)
+            {
+                log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
+            }
+
+            log += "\n";
+
+            PlayLog.OnAddLog?.Invoke(log);
+        }
+        #endregion
+
+        #region hide icon
+        if (addedLinkCards.Count >= 1)
+        {
+            if (!_notShowCards)
+            {
+                yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedLinkCards, "Link Cards", true, true));
+            }
+        }
+
+        #endregion
+    }
+}
+#endregion
+
 #region Place permanents to security
 
 public class IPutSecurityPermanent

+ 4 - 1
Assets/Scripts/CardEffectFactory/KeyWordEffects/Link.cs

@@ -98,7 +98,10 @@ public partial class CardEffectFactory
             {
                 yield return ContinuousController.instance.StartCoroutine(card.Owner.AddMemory(-card.linkCondition.cost, activateClass));
 
-                yield return ContinuousController.instance.StartCoroutine(selectedPermanent.AddLinkCard(card, activateClass));
+                if(CardEffectCommons.IsExistOnHand(card))
+                    yield return ContinuousController.instance.StartCoroutine(selectedPermanent.AddLinkCard(card, activateClass));
+                else
+                    yield return ContinuousController.instance.StartCoroutine(new IPlacePermanentToLinkCards(new List<Permanent[]>() { new Permanent[] { card.PermanentOfThisCard(), selectedPermanent } }, activateClass).PlacePermanentToLinkCards());
             }
         }
 

+ 50 - 6
Assets/Scripts/Permanent.cs

@@ -105,10 +105,12 @@ public class Permanent
     public IEnumerator DiscardEvoRoots(bool ignoreOverflow = false, bool putToTrash = true)
     {
         List<CardSource> evoRoots = DigivolutionCards.Clone();
+        List<CardSource> linkRoots = LinkedCards.Clone();
 
         if (!ignoreOverflow)
         {
             yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(evoRoots).Overflow());
+            yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(linkRoots).Overflow());
         }
 
         foreach (CardSource cardSource1 in evoRoots)
@@ -123,6 +125,19 @@ public class Permanent
                 yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource1));
             }
         }
+
+        foreach (CardSource cardSource2 in linkRoots)
+        {
+            if (putToTrash)
+            {
+                yield return ContinuousController.instance.StartCoroutine(RemoveLinkedCard(cardSource2));
+            }
+
+            else
+            {
+                yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource2));
+            }
+        }
     }
     #endregion
 
@@ -960,7 +975,7 @@ public class Permanent
 
     #region Add Link cards
     /// <summary>
-    /// IEnumerator to add a list of CardSource to a permanents top sources, CAN NOT be used to put a field permanent under must use IPlacePermanentToDigivolutionCards
+    /// IEnumerator to add a list of CardSource to a permanents top sources, CAN NOT be used to put a field permanent under must use IPlacePermanentToLinkCards
     /// </summary>
     /// <param name="addedLinkCards"></param>
     /// <param name="cardEffect"></param>
@@ -979,9 +994,14 @@ public class Permanent
                 isFromDigimon = true;
             }
         }
-        Debug.Log($"LINK CARDS: {LinkedCards.Count} >= {LinkedMax}");
+
         if (LinkedCards.Count >= LinkedMax)
-            yield return ContinuousController.instance.StartCoroutine(RemoveLinkedCard(LinkedCards[0]));
+        {
+            if(LinkedMax > 1)
+                yield return ContinuousController.instance.StartCoroutine(RemoveLinkedCard(null,(LinkedCards.Count - LinkedMax)));
+            else
+                yield return ContinuousController.instance.StartCoroutine(RemoveLinkedCard(LinkedCards[0]));
+        }
 
         yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(addedLinkCard));
 
@@ -1030,18 +1050,42 @@ public class Permanent
     #endregion
 
     #region Remove Linked Card
-    public IEnumerator RemoveLinkedCard(CardSource cardSource)
+    public IEnumerator RemoveLinkedCard(CardSource cardSource, int removeCount = 0)
     {
         Debug.Log($"REMOVE LINK CARD: {LinkedCards.Count} >= {LinkedCards.Contains(cardSource)}");
         if (LinkedCards.Contains(cardSource))
         {
-
             LinkedDP -= cardSource.LinkDP;
             yield return ContinuousController.instance.StartCoroutine(RemoveCardSource(cardSource));
             yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
             LinkedCards.Remove(cardSource);
             Debug.Log($"REMOVE LINK CARD: {cardSource}");
-            
+        }
+
+        if(removeCount > 0)
+        {
+            int maxCount = Mathf.Min(removeCount, LinkedCards.Count);
+            SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
+
+            selectCardEffect.SetUp(
+                        canTargetCondition: (CardSource) => true,
+                        canTargetCondition_ByPreSelecetedList: null,
+                        canEndSelectCondition: null,
+                        canNoSelect: () => false,
+                        selectCardCoroutine: null,
+                        afterSelectCardCoroutine: null,
+                        message: $"Select {maxCount} card to trash.",
+                        maxCount: removeCount,
+                        canEndNotMax: false,
+                        isShowOpponent: true,
+                        mode: SelectCardEffect.Mode.Discard,
+                        root: SelectCardEffect.Root.Custom,
+                        customRootCardList: LinkedCards,
+                        canLookReverseCard: true,
+                        selectPlayer: TopCard.Owner,
+                        cardEffect: null);
+
+            yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
         }
 
         //TODO: Add event call if something was removed