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

adjusted link mechanic, added link max change, added when linked timing

mbunch_kascope пре 1 година
родитељ
комит
06fd41a214

+ 50 - 0
Assets/CardEffect/BT21/BT1_027.cs

@@ -1,5 +1,6 @@
 using System.Collections;
 using System.Collections.Generic;
+using System.Linq;
 
 namespace DCGO.CardEffects.BT1
 {
@@ -14,6 +15,36 @@ namespace DCGO.CardEffects.BT1
                 cardEffects.Add(CardEffectFactory.LinkEffect(card, 1, 2000));
             }
 
+            if(timing == EffectTiming.WhenLinked)
+            {
+                ActivateClass activateClass = new ActivateClass();
+                activateClass.SetUpICardEffect("Testing When Linked", CanUseCondition, card);
+                activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDiscription());
+                activateClass.SetIsLinkedEffect(true);
+                cardEffects.Add(activateClass);
+
+                string EffectDiscription()
+                {
+                    return "[When linked] Testing Log";
+                }
+
+                bool CanUseCondition(Hashtable hashtable)
+                {
+                    return CardEffectCommons.CanTriggerWhenLinked(hashtable, null, card);
+                }
+
+                bool CanActivateCondition(Hashtable hashtable)
+                {
+                    return isExistOnField(card);
+                }
+
+                IEnumerator ActivateCoroutine(Hashtable _hashtable)
+                {
+                    UnityEngine.Debug.Log("CARD SUCCESSFULLY LINKED");
+                    yield return null;
+                }
+            }
+
             if(timing == EffectTiming.None)
             {
                 bool CanUseCondition()
@@ -24,6 +55,25 @@ namespace DCGO.CardEffects.BT1
                 cardEffects.Add(CardEffectFactory.BlockerStaticEffect(permanentCondition: null, isInheritedEffect: true, card: card, condition: CanUseCondition));
             }
 
+            if (timing == EffectTiming.None)
+            {
+                bool Condition()
+                {
+                    if (CardEffectCommons.IsExistOnBattleArea(card))
+                    {
+                        return true;
+                    }
+
+                    return false;
+                }
+
+                cardEffects.Add(CardEffectFactory.ChangeSelfSAttackStaticEffect(
+                    changeValue: 1,
+                    isInheritedEffect: true,
+                    card: card,
+                    condition: Condition));
+            }
+
             return cardEffects;
         }
     }

+ 0 - 264
Assets/Scripts/CardController.cs

@@ -2524,270 +2524,6 @@ public class IPlacePermanentToDigivolutionCards
 }
 #endregion
 
-#region Link permanent to another permanent
-public class ILinkPermanentToPermanent
-{
-    public ILinkPermanentToPermanent(
-        List<Permanent[]> permanentArrays,
-        int DP,
-        ICardEffect cardEffect)
-    {
-        permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
-        _cardEffect = cardEffect;
-    }
-
-    public void SetNotShowCards()
-    {
-        _notShowCards = true;
-    }
-
-    List<Permanent[]> _permanentArrays = new List<Permanent[]>();
-    int _DP = 0;
-    ICardEffect _cardEffect = null;
-    bool _notShowCards = false;
-    public bool Linked { get; private set; } = false;
-    public IEnumerator LinkPermanent()
-    {
-        if (_permanentArrays.Count != 2)
-        {
-            yield break;
-        }
-
-        List<CardSource> addedLinkCards = new List<CardSource>();
-
-        List<Permanent> removeFieldPermanents = new List<Permanent>();
-
-        foreach (Permanent[] permanentArray in _permanentArrays)
-        {
-            Permanent LinkPermanent = permanentArray[0];
-            Permanent LinkedPermanent = permanentArray[1];
-
-            if (LinkPermanent != null && LinkedPermanent != null)
-            {
-                if (LinkPermanent.TopCard != null && LinkedPermanent.TopCard != null && !LinkedPermanent.IsToken)
-                {
-                    if (_cardEffect != null)
-                    {
-                        if (LinkPermanent.TopCard.CanNotBeAffected(_cardEffect) || LinkedPermanent.TopCard.CanNotBeAffected(_cardEffect))
-                        {
-                            continue;
-                        }
-                    }
-
-                    removeFieldPermanents.Add(LinkPermanent);
-                }
-            }
-        }
-
-        foreach (Permanent permanent in removeFieldPermanents)
-        {
-            permanent.willBeRemoveField = true;
-        }
-
-        if (removeFieldPermanents.Count == 0)
-        {
-            yield break;
-        }
-
-        #region When permanent would remove effect
-        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)
-        {
-            Permanent LinkPermanent = permanentArray[0];
-            Permanent LinkedPermanent = permanentArray[1];
-
-            if (LinkPermanent != null && LinkedPermanent != null)
-            {
-                if (LinkPermanent.TopCard != null && LinkedPermanent.TopCard != null && !LinkedPermanent.IsToken && LinkPermanent.willBeRemoveField)
-                {
-                    yield return ContinuousController.instance.StartCoroutine(LinkPermanent.DiscardEvoRoots());
-
-                    CardSource cardSource = LinkPermanent.TopCard;
-
-                    #region record used effect
-                    if (_cardEffect != null)
-                    {
-                        if (LinkPermanent.TopCard != null)
-                        {
-                            LinkPermanent.PlaceOtherPermanentEffect = _cardEffect;
-                        }
-                    }
-                    #endregion
-
-                    yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
-                        LinkPermanent,
-                        ignoreOverflow: true));
-
-                    yield return ContinuousController.instance.StartCoroutine(LinkedPermanent.AddLinkedCard(cardSource, _DP, _cardEffect));
-
-                    cardSource.cEntity_EffectController.InitUseCountThisTurn();
-
-                    addedLinkCards.Add(cardSource);
-
-                    Linked = true;
-                }
-            }
-        }
-
-        #region add log
-        if (addedLinkCards.Count >= 1)
-        {
-            string log = "";
-
-            log += $"Link:";
-
-            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

+ 44 - 0
Assets/Scripts/CardEffectCommons/CanUseEffects/WhenLinked.cs

@@ -0,0 +1,44 @@
+using System.Collections;
+using System.Collections.Generic;
+using System;
+using System.Linq;
+using UnityEngine;
+
+public partial class CardEffectCommons
+{
+    #region Can trigger "When card is linked" effect
+    public static bool CanTriggerWhenLinked(Hashtable hashtable, Func<Permanent, bool> permanentCondition, CardSource card)
+    {
+        if (hashtable != null)
+        {
+            Permanent Permanent = GetPermanentFromHashtable(hashtable);
+
+            if (Permanent != null)
+            {
+                if (Permanent.TopCard != null)
+                {
+                    if (permanentCondition == null || permanentCondition(Permanent))
+                    {
+                        ICardEffect CardEffect = GetCardEffectFromHashtable(hashtable);
+
+                        if (CardEffect != null)
+                        {
+                            CardSource cardSource = GetCardFromHashtable(hashtable);
+
+                            if (cardSource != null)
+                            {
+                                if (cardSource == card)
+                                {
+                                    return true;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        return false;
+    }
+    #endregion
+}

+ 11 - 0
Assets/Scripts/CardEffectCommons/CanUseEffects/WhenLinked.cs.meta

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

+ 143 - 0
Assets/Scripts/CardEffectFactory/ChangeLinkMax.cs

@@ -0,0 +1,143 @@
+using System.Collections;
+using System.Collections.Generic;
+using System;
+using System.Linq;
+using UnityEngine;
+
+public partial class CardEffectFactory
+{
+    #region Static effect that changes one's own Link Max
+    public static ChangeLinkMaxClass ChangeSelfLinkMaxStaticEffect<T>(
+        T changeValue,
+        bool isInheritedEffect,
+        CardSource card,
+        Func<bool> condition)
+    {
+        bool CanUseCondition()
+        {
+            if (CardEffectCommons.IsExistOnBattleAreaDigimon(card))
+            {
+                if (condition == null || condition())
+                {
+                    return true;
+                }
+            }
+
+            return false;
+        }
+
+        return ChangeTargetLinkMaxStaticEffect(
+            targetPermanent: card.PermanentOfThisCard(),
+            changeValue: changeValue,
+            isInheritedEffect: isInheritedEffect,
+            card: card,
+            condition: CanUseCondition);
+    }
+    #endregion
+
+    #region Static effect that changes LinkMax
+    public static ChangeLinkMaxClass ChangeTargetLinkMaxStaticEffect<T>(
+        Permanent targetPermanent,
+        T changeValue,
+        bool isInheritedEffect,
+        CardSource card,
+        Func<bool> condition,
+        string hashstring = null)
+    {
+        bool PermanentCondition(Permanent permanent)
+        {
+            return permanent == targetPermanent;
+        }
+
+        return ChangeLinkMaxStaticEffect(
+            permanentCondition: PermanentCondition,
+            changeValue: changeValue,
+            isInheritedEffect: isInheritedEffect,
+            card: card,
+            condition: condition,
+            hashstring: hashstring
+        );
+    }
+
+    public static ChangeLinkMaxClass ChangeLinkMaxStaticEffect<T>(
+        Func<Permanent, bool> permanentCondition,
+        T changeValue,
+        bool isInheritedEffect,
+        CardSource card,
+        Func<bool> condition,
+        string hashstring = null)
+    {
+        bool isInt = typeof(T) == typeof(int);
+        bool isIntFunc = typeof(T) == typeof(Func<int>);
+
+        if (!isInt && !isIntFunc) return null;
+
+        if (isInt && (int)(object)changeValue == 0) return null;
+        if (isIntFunc && changeValue as Func<int> == null) return null;
+
+        int _changeValue() => isInt ? (int)(object)changeValue : (changeValue as Func<int>)();
+        bool isUpValue() => _changeValue() > 0;
+        string effectName() => isUpValue() ? $"Link Max +{_changeValue()}" : $"Link Max {_changeValue()}";
+
+        ChangeLinkMaxClass changeLinkMaxClass = new ChangeLinkMaxClass();
+        changeLinkMaxClass.SetUpICardEffect("", CanUseCondition, card);
+        changeLinkMaxClass.SetUpChangeLinkMaxClass(changeLinkMaxFunc: ChangeLinkMax, permanentCondition: PermanentCondition, isUpDown: _isUpDown);
+
+        if (hashstring != null)
+        {
+            changeLinkMaxClass.SetHashString(hashstring);
+        }
+
+        if (isInheritedEffect)
+        {
+            changeLinkMaxClass.SetIsInheritedEffect(true);
+        }
+
+        bool CanUseCondition(Hashtable hashtable)
+        {
+            if (condition == null || condition())
+            {
+                changeLinkMaxClass.SetEffectName(effectName());
+
+                return true;
+            }
+
+            return false;
+        }
+
+        int ChangeLinkMax(Permanent permanent, int linkMax)
+        {
+            if (PermanentCondition(permanent))
+            {
+                linkMax += _changeValue();
+            }
+
+            return linkMax;
+        }
+
+        bool PermanentCondition(Permanent permanent)
+        {
+            if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
+            {
+                if (!permanent.TopCard.CanNotBeAffected(changeLinkMaxClass))
+                {
+                    if (permanentCondition == null || permanentCondition(permanent))
+                    {
+                        return true;
+                    }
+                }
+            }
+
+            return false;
+        }
+
+        CalculateOrder _isUpDown()
+        {
+            return CalculateOrder.UpDownValue;
+        }
+
+        return changeLinkMaxClass;
+    }
+    #endregion
+
+}

+ 11 - 0
Assets/Scripts/CardEffectFactory/ChangeLinkMax.cs.meta

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

+ 8 - 6
Assets/Scripts/CardEffectFactory/KeyWordEffects/Link.cs

@@ -31,9 +31,12 @@ public partial class CardEffectFactory
         {
             if (CardEffectCommons.IsPermanentExistsOnOwnerBattleArea(permanent, card))
             {
-                if (digimonCondition == null || digimonCondition(permanent))
+                if(permanent != card.PermanentOfThisCard())
                 {
-                    return true;
+                    if (digimonCondition == null || digimonCondition(permanent))
+                    {
+                        return true;
+                    }
                 }
             }
 
@@ -93,10 +96,9 @@ public partial class CardEffectFactory
 
             if (selectedPermanent != null)
             {
-                if (CardEffectCommons.IsExistOnHand(card))
-                    yield return ContinuousController.instance.StartCoroutine(selectedPermanent.AddLinkedCard(card, dp, activateClass));
-                else
-                    yield return ContinuousController.instance.StartCoroutine(new ILinkPermanentToPermanent(new List<Permanent[]>() { new Permanent[] { card.PermanentOfThisCard(), selectedPermanent } }, dp, activateClass).LinkPermanent());
+
+                yield return ContinuousController.instance.StartCoroutine(selectedPermanent.AddLinkCard(card, dp, activateClass));
+                    //yield return ContinuousController.instance.StartCoroutine(new ILinkPermanentToPermanent(new List<Permanent[]>() { new Permanent[] { card.PermanentOfThisCard(), selectedPermanent } }, dp, activateClass).LinkPermanent());
             }
         }
 

+ 9 - 0
Assets/Scripts/CardEffectInterfaces.cs

@@ -116,6 +116,15 @@ public interface IChangeSAttackEffect
 }
 #endregion
 
+#region "Change target permanent's Link Max" effect
+public interface IChangeLinkMaxEffect
+{
+    int GetLinkMax(int linkMax, Permanent permanent, int invertValue);
+    CalculateOrder isUpDown();
+    bool PermanentCondition(Permanent permanent);
+}
+#endregion
+
 #region "Invert target permanent's Security Attack" effect
 public interface IInvertSAttackEffect
 {

+ 72 - 0
Assets/Scripts/CardEffects/ChangeLinkMaxClass.cs

@@ -0,0 +1,72 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using System;
+using Unity.Mathematics;
+
+public class ChangeLinkMaxClass : ICardEffect, IChangeLinkMaxEffect
+{
+    public void SetUpChangeLinkMaxClass(Func<Permanent, int, int> changeLinkMaxFunc, Func<Permanent, bool> permanentCondition, Func<CalculateOrder> isUpDown)
+    {
+        _changeLinkMaxFunc = changeLinkMaxFunc;
+        _permanentCondition = permanentCondition;
+        _isUpDown = isUpDown;
+    }
+
+    Func<Permanent, int, int> _changeLinkMaxFunc = null;
+    Func<Permanent, bool> _permanentCondition = null;
+    Func<CalculateOrder> _isUpDown = null;
+
+    public int GetLinkMax(int LinkMax, Permanent permanent, int invertValue)
+    {
+        int changedLinkMax = LinkMax;
+
+        if (PermanentCondition(permanent))
+        {
+            changedLinkMax = _changeLinkMaxFunc(permanent, LinkMax);
+
+            switch (invertValue)
+            {
+                case -1:
+                    if(changedLinkMax < LinkMax)
+                        changedLinkMax = LinkMax + Mathf.Abs(changedLinkMax - LinkMax);
+                    break;
+                case 1:
+                    if (changedLinkMax > LinkMax)
+                        changedLinkMax = LinkMax - (changedLinkMax - LinkMax);
+                    break;
+            }
+        }
+
+        return changedLinkMax;
+    }
+
+    public CalculateOrder isUpDown()
+    {
+        if (_isUpDown != null)
+        {
+            return _isUpDown();
+        }
+
+        return CalculateOrder.UpToConstant;
+    }
+
+    public bool PermanentCondition(Permanent permanent)
+    {
+        if (permanent != null)
+        {
+            if (permanent.TopCard != null)
+            {
+                if (_permanentCondition != null)
+                {
+                    if (_permanentCondition(permanent))
+                    {
+                        return true;
+                    }
+                }
+            }
+        }
+
+        return false;
+    }
+}

+ 11 - 0
Assets/Scripts/CardEffects/ChangeLinkMaxClass.cs.meta

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

+ 5 - 0
Assets/Scripts/CardObjectController.cs

@@ -391,6 +391,11 @@ public class CardObjectController : MonoBehaviour
                 {
                     yield return ContinuousController.instance.StartCoroutine(permanent.RemoveCardSource(cardSource));
                 }
+
+                if(permanent.LinkedCards.Any(linked => linked.Source == cardSource))
+                {
+                    yield return ContinuousController.instance.StartCoroutine(permanent.RemoveLinkedCard(cardSource));
+                }
             }
         }
 

+ 2 - 1
Assets/Scripts/CardSource.cs

@@ -251,7 +251,8 @@ public class CardSource : MonoBehaviour
     #region Permanent in the field containing this card
     public Permanent PermanentOfThisCard()
     {
-        return Owner.GetFieldPermanents().Find(permanent => permanent.cardSources.Contains(this) && !IsFlipped);
+        return Owner.GetFieldPermanents().Find(permanent => 
+            (permanent.cardSources.Contains(this) || permanent.LinkedCards.Any(linked => linked.Source == this)) && !IsFlipped);
     }
     #endregion
 

+ 19 - 4
Assets/Scripts/ICardEffect.cs

@@ -27,6 +27,7 @@ public abstract class ICardEffect
         SetUseOptional(false);
         SetIsDeclarative(false);
         SetIsInheritedEffect(false);
+        SetIsLinkedEffect(false);
         SetIsSecurityEffect(false);
         SetIsCounterEffect(false);
         SetIsDigimonEffect(false);
@@ -273,15 +274,15 @@ public abstract class ICardEffect
             return false;
         }
         #endregion
-
-        #region Determination of availability for Inheritated Effect
+       
+        #region Determination of availability for Inheritated/Linked Effect
         if (this is ActivateICardEffect)
         {
             if (EffectSourceCard != null)
             {
                 if (EffectSourceCard.PermanentOfThisCard() != null)
                 {
-                    if (IsInheritedEffect)
+                    if (IsInheritedEffect || IsLinkedEffect)
                     {
                         if (EffectSourceCard == EffectSourceCard.PermanentOfThisCard().TopCard)
                         {
@@ -313,7 +314,7 @@ public abstract class ICardEffect
         #endregion
 
         #region Determination whether the permanent is same as when triggered
-        if (IsInheritedEffect)
+        if (IsInheritedEffect || IsLinkedEffect)
         {
             if (this is ActivateICardEffect)
             {
@@ -410,6 +411,19 @@ public abstract class ICardEffect
     }
     #endregion
 
+    #region Whether this effect is an Linked Effect
+    bool _isLinkededEffect = false;
+    public bool IsLinkedEffect
+    {
+        get { return _isLinkededEffect; }
+        private set { _isLinkededEffect = value; }
+    }
+    public void SetIsLinkedEffect(bool isLinkededEffect)
+    {
+        IsLinkedEffect = isLinkededEffect;
+    }
+    #endregion
+
     #region Whether this effect is an Security Effect
     bool _isSecurityEffect = false;
     public bool IsSecurityEffect
@@ -783,6 +797,7 @@ public enum EffectTiming
     OnReturnCardsToHandFromTrash,
     AfterEffectsActivate,
     WhenWouldDigivolutionCardDiscarded,
+    WhenLinked
 }
 #endregion
 

+ 2 - 2
Assets/Scripts/MultipleSkills.cs

@@ -129,7 +129,7 @@ public class MultipleSkills : MonoBehaviourPunCallbacks
                     }
                 }
 
-                if(skillInfo.CardEffect.ChainActivations > 0)
+                if (skillInfo.CardEffect.ChainActivations > 0)
                 {
                     if (GManager.instance.autoProcessing.IsCutInEffectUsedMaxCount(skillInfo.CardEffect))
                     {
@@ -157,7 +157,7 @@ public class MultipleSkills : MonoBehaviourPunCallbacks
 
             skillInfos_active = skillInfos_active.Filter(skillInfo => skillInfo != null && skillInfo.CardEffect != null
                 && skillInfo.CardEffect.CanActivate(skillInfo.Hashtable) && skillInfo.CardEffect.EffectSourceCard != null);
-
+            
             if (skillInfos_active.Count > 0)
             {
                 bool oldIsSecurityGlassBlue = player.securityObject.securityBreakGlass.IsBlueGlass && IsOnlyHandEffectStacked && IsOnlyOptionalEffectStacked && IsEachStackedEffectHasDistinctSourceCard;

+ 187 - 20
Assets/Scripts/Permanent.cs

@@ -635,7 +635,125 @@ public class Permanent
     #endregion
 
     #region Linked Cards
-    public int LinkedMax { get; set; } = 1;
+    public int LinkedMax
+    {
+        get
+        {
+            int Max = 1;
+
+            #region Effect of changing the number of sheets to undergo security check
+
+            List<ICardEffect> cardEffects_ChangeLinkedMax = new List<ICardEffect>();
+
+            foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
+            {
+                foreach (Permanent permanent in player.GetFieldPermanents())
+                {
+                    #region Effects of permanents in play
+                    foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
+                    {
+                        if (cardEffect is IChangeLinkMaxEffect)
+                        {
+                            if (((IChangeLinkMaxEffect)cardEffect).PermanentCondition(this))
+                            {
+                                if (cardEffect.CanUse(null))
+                                {
+                                    if (!TopCard.CanNotBeAffected(cardEffect))
+                                    {
+                                        cardEffects_ChangeLinkedMax.Add(cardEffect);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    #endregion
+                }
+
+                #region player effect
+                foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
+                {
+                    if (cardEffect is IChangeLinkMaxEffect)
+                    {
+                        if (((IChangeLinkMaxEffect)cardEffect).PermanentCondition(this))
+                        {
+                            if (cardEffect.CanUse(null))
+                            {
+                                if (!TopCard.CanNotBeAffected(cardEffect))
+                                {
+                                    cardEffects_ChangeLinkedMax.Add(cardEffect);
+                                }
+                            }
+                        }
+                    }
+                }
+                #endregion
+            }
+
+            List<ICardEffect> cardEffects_ChangeLinkedMax_UpToConstant = new List<ICardEffect>();
+            List<ICardEffect> cardEffects_ChangeLinkedMax_UpDownValue = new List<ICardEffect>();
+            List<ICardEffect> cardEffects_ChangeLinkedMax_DownToConstant = new List<ICardEffect>();
+
+            foreach (ICardEffect cardEffect in cardEffects_ChangeLinkedMax)
+            {
+                if (cardEffect is IChangeLinkMaxEffect)
+                {
+                    if (cardEffect.CanUse(null))
+                    {
+                        switch (((IChangeLinkMaxEffect)cardEffect).isUpDown())
+                        {
+                            case CalculateOrder.UpToConstant:
+                                cardEffects_ChangeLinkedMax_UpToConstant.Add(cardEffect);
+                                break;
+
+                            case CalculateOrder.UpDownValue:
+                                cardEffects_ChangeLinkedMax_UpDownValue.Add(cardEffect);
+                                break;
+
+                            case CalculateOrder.DownToConstant:
+                                cardEffects_ChangeLinkedMax_DownToConstant.Add(cardEffect);
+                                break;
+                        }
+                    }
+                }
+            }
+
+            foreach (ICardEffect cardEffect in cardEffects_ChangeLinkedMax_UpToConstant)
+            {
+                if (cardEffect is IChangeLinkMaxEffect)
+                {
+                    if (cardEffect.CanUse(null))
+                    {
+                        Max = ((IChangeLinkMaxEffect)cardEffect).GetLinkMax(Max, this, InvertSecutiryValue);
+                    }
+                }
+            }
+
+            foreach (ICardEffect cardEffect in cardEffects_ChangeLinkedMax_UpDownValue)
+            {
+                if (cardEffect is IChangeLinkMaxEffect)
+                {
+                    if (cardEffect.CanUse(null))
+                    {
+                        Max = ((IChangeLinkMaxEffect)cardEffect).GetLinkMax(Max, this, InvertSecutiryValue);
+                    }
+                }
+            }
+
+            foreach (ICardEffect cardEffect in cardEffects_ChangeLinkedMax_DownToConstant)
+            {
+                if (cardEffect is IChangeLinkMaxEffect)
+                {
+                    if (cardEffect.CanUse(null))
+                    {
+                        Max = ((IChangeLinkMaxEffect)cardEffect).GetLinkMax(Max, this, InvertSecutiryValue);
+                    }
+                }
+            }
+            #endregion
+
+            return Max;
+        }
+    }
     public struct LinkCard
     {
         public LinkCard(int dp, CardSource source)
@@ -820,26 +938,65 @@ public class Permanent
     }
     #endregion
 
-    #region Add Card Source
-    public IEnumerator AddLinkedCard(CardSource cardSource, int DP, ICardEffect cardEffect)
+    #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
+    /// </summary>
+    /// <param name="addedLinkCards"></param>
+    /// <param name="cardEffect"></param>
+    /// <param name="skipEffectAndActivateSkill"></param>
+    /// <returns></returns>
+    public IEnumerator AddLinkCard(CardSource addedLinkCard, int DP, ICardEffect cardEffect)
     {
-        yield return null;
+        bool addedCard = false;
 
-        if(LinkedCards.Count >= LinkedMax)
-            RemoveLinkedCard(null);
+        bool isFromDigimon = false;
+
+        if (CardEffectCommons.IsExistOnBattleArea(addedLinkCard))
+        {
+            if (addedLinkCard.PermanentOfThisCard().DigivolutionCards.Count >= 1)
+            {
+                isFromDigimon = true;
+            }
+        }
+        Debug.Log($"LINK CARDS: {LinkedCards.Count} >= {LinkedMax}");
+        if (LinkedCards.Count >= LinkedMax)
+            yield return ContinuousController.instance.StartCoroutine(RemoveCardSource(LinkedCards[0].Source));
 
-        yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
+        yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(addedLinkCard));
 
-        if (ShowingPermanentCard != null)
+        if (!this.IsToken && !addedLinkCard.IsToken)
         {
-            yield return ContinuousController.instance.StartCoroutine(ShowingPermanentCard.ShowAddDigivolutionCardEffect());
+            LinkedCards.Insert(0, new LinkCard(0, addedLinkCard));
+            LinkedDP += DP;
+
+            this.cardSources.Insert(1, addedLinkCard);
+            addedLinkCard.SetFace();
+            addedCard = true;
         }
 
-        LinkedCards.Insert(0, new LinkCard(0,cardSource));
-        LinkedDP += DP;
+        if (addedCard)
+        {
+            if (ShowingPermanentCard != null)
+            {
+                yield return ContinuousController.instance.StartCoroutine(ShowingPermanentCard.ShowAddDigivolutionCardEffect());
+            }
+
+            #region Add Linked Card
 
-        cardSources.Insert(1, cardSource);
-        cardSource.SetFace();
+            #region Hashtable Setting
+            Hashtable hashtable = new Hashtable()
+                {
+                    {"Permanent", this},
+                    {"CardEffect", cardEffect},
+                    {"Card", addedLinkCard},
+                    {"isFromDigimon", isFromDigimon},
+                };
+            #endregion
+
+            yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.WhenLinked));
+            #endregion
+        }
     }
     #endregion
 
@@ -853,14 +1010,23 @@ public class Permanent
     #endregion
 
     #region Remove Linked Card
-    public IEnumerator RemoveLinkedCard(ICardEffect cardEffect)
+    public IEnumerator RemoveLinkedCard(CardSource cardSource)
     {
-        //TODO: Add event call if something was removed
-        yield return null;
+        LinkCard linked = LinkedCards.Where(linked => linked.Source == cardSource).FirstOrDefault();
+
+        Debug.Log($"REMOVE LINK CARD: {LinkedCards.Count} >= {linked.Source}");
+        if (linked.Source != null)
+        {
+
+            LinkedDP -= linked.DP;
+            yield return ContinuousController.instance.StartCoroutine(RemoveCardSource(linked.Source));
+            yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(linked.Source));
+            LinkedCards.Remove(linked);
+            Debug.Log($"REMOVE LINK CARD: {linked.Source}");
+            
+        }
 
-        LinkedDP -= LinkedCards[0].DP;
-        RemoveCardSource(LinkedCards[0].Source);
-        LinkedCards.RemoveAt(0);
+        //TODO: Add event call if something was removed
     }
     #endregion
 
@@ -1014,6 +1180,7 @@ public class Permanent
         {
             foreach (CardSource cardSource in cardSources)
             {
+                
                 if (cardSource != null)
                 {
                     if (!cardSource.IsFlipped)
@@ -1032,7 +1199,7 @@ public class Permanent
                         {
                             if (cardEffect != null)
                             {
-                                if (isTopCard == cardEffect.IsInheritedEffect)
+                                if (isTopCard == cardEffect.IsInheritedEffect && isTopCard == cardEffect.IsLinkedEffect)
                                 {
                                     continue;
                                 }