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

Untested Security Attack Inversion

mbunch_kascope пре 2 година
родитељ
комит
36490e3be9

+ 57 - 17
Assets/CardEffect/EX6/Yellow/Shakamon_EX6_031.cs

@@ -157,12 +157,6 @@ namespace DCGO.CardEffects.EX6
             
             #region On Play/ When Digivolving Shared
             
-            string EffectSharedDescription()
-            {
-                return
-                    "[When Digivolving] All Digimon gain <Security Attack -1> until the end of your opponent's turn.";
-            }
-            
             bool CanActivateSharedCondition(Hashtable hashtable)
             {
                 return CardEffectCommons.IsExistOnBattleArea(card);
@@ -177,9 +171,14 @@ namespace DCGO.CardEffects.EX6
                 ActivateClass activateClass = new ActivateClass();
                 activateClass.SetUpICardEffect("Security Attack -1", CanUseCondition, card);
                 activateClass.SetUpActivateClass(CanActivateSharedCondition, ActivateCoroutine, -1, false,
-                    EffectSharedDescription());
+                    EffectDescription());
                 cardEffects.Add(activateClass);
-                
+
+                string EffectDescription()
+                {
+                    return "[On Play] All Digimon gain <Security Attack -1> until the end of your opponent's turn.";
+                }
+
                 bool CanUseCondition(Hashtable hashtable)
                 {
                     return CardEffectCommons.CanTriggerOnPlay(hashtable, card);
@@ -218,9 +217,14 @@ namespace DCGO.CardEffects.EX6
                 ActivateClass activateClass = new ActivateClass();
                 activateClass.SetUpICardEffect("Security Attack -1", CanUseCondition, card);
                 activateClass.SetUpActivateClass(CanActivateSharedCondition, ActivateCoroutine, -1, false,
-                    EffectSharedDescription());
+                    EffectDescription());
                 cardEffects.Add(activateClass);
-                
+
+                string EffectDescription()
+                {
+                    return "[When Digivolving] All Digimon gain <Security Attack -1> until the end of your opponent's turn.";
+                }
+
                 bool CanUseCondition(Hashtable hashtable)
                 {
                     return CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
@@ -457,17 +461,53 @@ namespace DCGO.CardEffects.EX6
                     }
                 }
             }
-            
+
             #endregion
-            
+
             #region Your Turn
-            
-            //TODO Implement
-            
+
+            if (timing == EffectTiming.None)
+            {
+                bool Condition()
+                {
+                    if (CardEffectCommons.IsExistOnBattleArea(card))
+                    {
+                        if (CardEffectCommons.IsOwnerTurn(card))
+                        {
+                            return true;
+                        }
+                    }
+
+                    return false;
+                }
+
+                bool PermanentCondition(Permanent permanent)
+                {
+                    if (CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card))
+                    {
+                        if (permanent.HasSecurityAttackChanges)
+                        {
+                            return true;
+                        }
+                    }
+
+                    return false;
+                }
+
+
+
+                cardEffects.Add(CardEffectFactory.InvertSAttackStaticEffect(
+                    permanentCondition: PermanentCondition,
+                    changeValue: -1,
+                    isInheritedEffect: false,
+                    card: card,
+                    condition: Condition));
+            }
+
             #endregion
-            
+
             #region End of Opponent's Turn
-            
+
             if (timing == EffectTiming.OnEndTurn)
             {
                 ActivateClass activateClass = new ActivateClass();

+ 110 - 0
Assets/Scripts/CardEffectCommons/GiveEffect/GiveEffectToPermanent/ChangeSAttack.cs

@@ -117,4 +117,114 @@ public partial class CardEffectCommons
         }
     }
     #endregion
+
+
+    #region Invert target 1 Digimon's SAttack
+    public static IEnumerator InverteDigimonSAttack(Permanent targetPermanent, int changeValue, EffectDuration effectDuration, ICardEffect activateClass)
+    {
+        if (targetPermanent == null) yield break;
+        if (!IsPermanentExistsOnBattleArea(targetPermanent)) yield break;
+        if (changeValue == 0) yield break;
+        if (activateClass == null) yield break;
+        if (activateClass.EffectSourceCard == null) yield break;
+
+        CardSource card = activateClass.EffectSourceCard;
+        bool isUpValue = changeValue > 0;
+
+        bool CanUseCondition()
+        {
+            if (IsPermanentExistsOnBattleArea(targetPermanent))
+            {
+                if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
+                {
+                    return true;
+                }
+            }
+
+            return false;
+        }
+
+        InvertSAttackClass invertSAttackClass = CardEffectFactory.InvertTargetSAttackStaticEffect(
+                    targetPermanent: targetPermanent,
+                    changeValue: changeValue,
+                    isInheritedEffect: false,
+                    card: card,
+                    condition: CanUseCondition);
+
+        AddEffectToPermanent(
+            targetPermanent: targetPermanent,
+            effectDuration: effectDuration,
+            card: card,
+            cardEffect: invertSAttackClass,
+            timing: EffectTiming.None);
+
+        if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
+        {
+            if (!isUpValue)
+            {
+                yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateBuffEffect(targetPermanent));
+            }
+
+            else
+            {
+                yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(targetPermanent));
+            }
+        }
+    }
+
+    public static IEnumerator InvertDigimonSAttack(Permanent targetPermanent, int changeValue, EffectDuration effectDuration, ICardEffect activateClass, bool activateAnimation)
+    {
+        if (targetPermanent == null) yield break;
+        if (!IsPermanentExistsOnBattleArea(targetPermanent)) yield break;
+        if (changeValue == 0) yield break;
+        if (activateClass == null) yield break;
+        if (activateClass.EffectSourceCard == null) yield break;
+
+        CardSource card = activateClass.EffectSourceCard;
+        bool isUpValue = changeValue > 0;
+
+        bool CanUseCondition()
+        {
+            if (IsPermanentExistsOnBattleArea(targetPermanent))
+            {
+                if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
+                {
+                    return true;
+                }
+            }
+
+            return false;
+        }
+
+        InvertSAttackClass invertSAttackClass = CardEffectFactory.InvertTargetSAttackStaticEffect(
+                    targetPermanent: targetPermanent,
+                    changeValue: changeValue,
+                    isInheritedEffect: false,
+                    card: card,
+                    condition: CanUseCondition);
+
+        AddEffectToPermanent(
+            targetPermanent: targetPermanent,
+            effectDuration: effectDuration,
+            card: card,
+            cardEffect: invertSAttackClass,
+            timing: EffectTiming.None);
+
+        if (!targetPermanent.TopCard.CanNotBeAffected(activateClass))
+        {
+            if (activateAnimation)
+            {
+                if (!isUpValue)
+                {
+                    yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateBuffEffect(targetPermanent));
+                }
+
+                else
+                {
+                    yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(targetPermanent));
+                }
+            }
+        }
+    }
+    #endregion
 }

+ 63 - 0
Assets/Scripts/CardEffectCommons/GiveEffect/GiveEffectToPlayer/ChangeSAttack.cs

@@ -67,4 +67,67 @@ public partial class CardEffectCommons
         }
     }
     #endregion
+
+
+    #region Player gains effect to invert Digimon's SAttack
+    public static IEnumerator InvertDigimonSAttackPlayerEffect(
+        Func<Permanent, bool> permanentCondition,
+        int changeValue,
+        EffectDuration effectDuration,
+        ICardEffect activateClass)
+    {
+        if (activateClass == null) yield break;
+        if (activateClass.EffectSourceCard == null) yield break;
+        if (changeValue == 0) yield break;
+
+        CardSource card = activateClass.EffectSourceCard;
+        bool isUpValue = changeValue > 0;
+
+        bool PermanentCondition(Permanent permanent)
+        {
+            if (IsPermanentExistsOnBattleArea(permanent))
+            {
+                if (!permanent.TopCard.CanNotBeAffected(activateClass))
+                {
+                    if (permanentCondition == null || permanentCondition(permanent))
+                    {
+                        return true;
+                    }
+                }
+            }
+
+            return false;
+        }
+
+        bool CanUseCondition()
+        {
+            return true;
+        }
+
+        InvertSAttackClass invertSAttackClass = CardEffectFactory.InvertSAttackStaticEffect(
+            permanentCondition: PermanentCondition,
+            changeValue: changeValue,
+            isInheritedEffect: false,
+            card: card,
+            condition: CanUseCondition);
+
+        AddEffectToPlayer(effectDuration: effectDuration, card: card, cardEffect: invertSAttackClass, timing: EffectTiming.None);
+
+        foreach (Permanent permanent in GManager.instance.turnStateMachine.gameContext.PermanentsForTurnPlayer)
+        {
+            if (PermanentCondition(permanent))
+            {
+                if (!isUpValue)
+                {
+                    yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateBuffEffect(permanent));
+                }
+
+                else
+                {
+                    yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(permanent));
+                }
+            }
+        }
+    }
+    #endregion
 }

+ 122 - 0
Assets/Scripts/CardEffectFactory/ChangeSAttack.cs

@@ -131,4 +131,126 @@ public partial class CardEffectFactory
         return changeSAttackClass;
     }
     #endregion
+
+
+    #region Static effect that inverts one's own SAttack
+    public static InvertSAttackClass InvertSelfSAttackStaticEffect<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 InvertTargetSAttackStaticEffect(
+            targetPermanent: card.PermanentOfThisCard(),
+            changeValue: changeValue,
+            isInheritedEffect: isInheritedEffect,
+            card: card,
+            condition: CanUseCondition);
+    }
+    #endregion
+
+    #region Static effect that inverts SAttack
+    public static InvertSAttackClass InvertTargetSAttackStaticEffect<T>(
+        Permanent targetPermanent,
+        T changeValue,
+        bool isInheritedEffect,
+        CardSource card,
+        Func<bool> condition)
+    {
+        bool PermanentCondition(Permanent permanent)
+        {
+            return permanent == targetPermanent;
+        }
+
+        return InvertSAttackStaticEffect(
+            permanentCondition: PermanentCondition,
+            changeValue: changeValue,
+            isInheritedEffect: isInheritedEffect,
+            card: card,
+            condition: condition
+        );
+    }
+
+    public static InvertSAttackClass InvertSAttackStaticEffect<T>(
+        Func<Permanent, bool> permanentCondition,
+        T changeValue,
+        bool isInheritedEffect,
+        CardSource card,
+        Func<bool> condition)
+    {
+        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() ? $"<Security A. +> are turned into <Security A. ->" : $"<Security A. -> are turned into <Security A. +>";
+
+        InvertSAttackClass invertSAttackClass = new InvertSAttackClass();
+        invertSAttackClass.SetUpICardEffect("", CanUseCondition, card);
+        invertSAttackClass.SetUpChangeSAttackClass(changeInvertFunc: InvertValue, permanentCondition: PermanentCondition);
+
+        if (isInheritedEffect)
+        {
+            invertSAttackClass.SetIsInheritedEffect(true);
+        }
+
+        bool CanUseCondition(Hashtable hashtable)
+        {
+            if (condition == null || condition())
+            {
+                invertSAttackClass.SetEffectName(effectName());
+
+                return true;
+            }
+
+            return false;
+        }
+
+        int InvertValue(Permanent permanent, int invertValue)
+        {
+            if (PermanentCondition(permanent))
+            {
+                invertValue += _changeValue();
+            }
+
+            return invertValue;
+        }
+
+        bool PermanentCondition(Permanent permanent)
+        {
+            if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
+            {
+                if (!permanent.TopCard.CanNotBeAffected(invertSAttackClass))
+                {
+                    if (permanentCondition == null || permanentCondition(permanent))
+                    {
+                        return true;
+                    }
+                }
+            }
+
+            return false;
+        }
+
+        return invertSAttackClass;
+    }
+    #endregion
 }

+ 9 - 1
Assets/Scripts/CardEffectInterfaces.cs

@@ -89,12 +89,20 @@ public interface ICanNotTrashFromDigivolutionCardsEffect
 #region "Change target permanent's Security Attack" effect
 public interface IChangeSAttackEffect
 {
-    int GetSAttack(int SAttack, Permanent permanent);
+    int GetSAttack(int SAttack, Permanent permanent, int invertValue);
     CalculateOrder isUpDown();
     bool PermanentCondition(Permanent permanent);
 }
 #endregion
 
+#region "Invert target permanent's Security Attack" effect
+public interface IInvertSAttackEffect
+{
+    int InversionValue(Permanent permanent, int invertValue);
+    bool PermanentCondition(Permanent permanent);
+}
+#endregion
+
 #region "Change target card's card names" effect
 public interface IChangeCardNamesEffect
 {

+ 18 - 3
Assets/Scripts/CardEffects/ChangeSAttackClass.cs

@@ -2,6 +2,7 @@ using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using System;
+using Unity.Mathematics;
 
 public class ChangeSAttackClass : ICardEffect, IChangeSAttackEffect
 {
@@ -16,14 +17,28 @@ public class ChangeSAttackClass : ICardEffect, IChangeSAttackEffect
     Func<Permanent, bool> _permanentCondition = null;
     Func<CalculateOrder> _isUpDown = null;
 
-    public int GetSAttack(int SAttack, Permanent permanent)
+    public int GetSAttack(int SAttack, Permanent permanent, int invertValue)
     {
+        int changedSAttack = SAttack;
+
         if (PermanentCondition(permanent))
         {
-            SAttack = _changeSAttackFunc(permanent, SAttack);
+            changedSAttack = _changeSAttackFunc(permanent, SAttack);
+
+            switch (invertValue)
+            {
+                case -1:
+                    if(changedSAttack < SAttack)
+                        changedSAttack = SAttack + Mathf.Abs(changedSAttack - SAttack);
+                    break;
+                case 1:
+                    if (changedSAttack > SAttack)
+                        changedSAttack = SAttack - (changedSAttack - SAttack);
+                    break;
+            }
         }
 
-        return SAttack;
+        return changedSAttack;
     }
 
     public CalculateOrder isUpDown()

+ 46 - 0
Assets/Scripts/CardEffects/InvertSAttackClass.cs

@@ -0,0 +1,46 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using System;
+using Unity.Mathematics;
+
+public class InvertSAttackClass : ICardEffect, IInvertSAttackEffect
+{
+    public void SetUpChangeSAttackClass(Func<Permanent, int, int> changeInvertFunc, Func<Permanent, bool> permanentCondition)
+    {
+        _changeInvertFunc = changeInvertFunc;
+        _permanentCondition = permanentCondition;
+    }
+
+    Func<Permanent, int, int> _changeInvertFunc = null;
+    Func<Permanent, bool> _permanentCondition = null;
+
+    public int InversionValue(Permanent permanent, int invertValue)
+    {
+        if (PermanentCondition(permanent))
+        {
+            invertValue = _changeInvertFunc(permanent, invertValue);
+        }
+
+        return invertValue;
+    }
+
+    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/InvertSAttackClass.cs.meta

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

+ 62 - 8
Assets/Scripts/Permanent.cs

@@ -1066,7 +1066,61 @@ public class Permanent
     }
     #endregion
 
-    #region セキュリティチェックを行う枚数
+    #region Number of sheets to undergo security check
+    public int InvertSecutiryValue
+    {
+        get
+        {
+            int Invert = 0;
+
+            List<ICardEffect> cardEffects_InvertStrike = 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 IInvertSAttackEffect)
+                        {
+                            if (cardEffect.CanUse(null))
+                            {
+                                if (!TopCard.CanNotBeAffected(cardEffect))
+                                {
+                                    cardEffects_InvertStrike.Add(cardEffect);
+                                }
+                            }
+                        }
+                    }
+                    #endregion
+                }
+
+                #region player effect
+                foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
+                {
+                    if (cardEffect is IInvertSAttackEffect)
+                    {
+                        if (cardEffect.CanUse(null))
+                        {
+                            if (!TopCard.CanNotBeAffected(cardEffect))
+                            {
+                                cardEffects_InvertStrike.Add(cardEffect);
+                            }
+                        }
+                    }
+                }
+                #endregion
+            }
+
+            foreach (ICardEffect cardEffect in cardEffects_InvertStrike)
+            {
+                Invert = ((IInvertSAttackEffect)cardEffect).InversionValue(this, Invert);
+            }
+
+            return Mathf.Clamp(Invert,-1,1);
+        }
+    }
     public List<int> SecurityAttackChanges
     {
         get
@@ -1127,7 +1181,7 @@ public class Permanent
                 {
                     if (cardEffect.CanUse(null))
                     {
-                        int Strike1 = ((IChangeSAttackEffect)cardEffect).GetSAttack(Strike, this);
+                        int Strike1 = ((IChangeSAttackEffect)cardEffect).GetSAttack(Strike, this, InvertSecutiryValue);
 
                         if (Strike1 != Strike)
                         {
@@ -1160,7 +1214,7 @@ public class Permanent
         {
             int Strike = 1;
 
-            #region セキュリティチェックを行う枚数を変更する効果
+            #region Effect of changing the number of sheets to undergo security check
 
             List<ICardEffect> cardEffects_ChangeDirectStrike = new List<ICardEffect>();
 
@@ -1168,7 +1222,7 @@ public class Permanent
             {
                 foreach (Permanent permanent in player.GetFieldPermanents())
                 {
-                    #region 場のパーマネントの効果
+                    #region Effects of permanents in play
                     foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
                     {
                         if (cardEffect is IChangeSAttackEffect)
@@ -1188,7 +1242,7 @@ public class Permanent
                     #endregion
                 }
 
-                #region プレイヤーの効果
+                #region player effect
                 foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
                 {
                     if (cardEffect is IChangeSAttackEffect)
@@ -1242,7 +1296,7 @@ public class Permanent
                 {
                     if (cardEffect.CanUse(null))
                     {
-                        Strike = ((IChangeSAttackEffect)cardEffect).GetSAttack(Strike, this);
+                        Strike = ((IChangeSAttackEffect)cardEffect).GetSAttack(Strike, this, InvertSecutiryValue);
                     }
                 }
             }
@@ -1253,7 +1307,7 @@ public class Permanent
                 {
                     if (cardEffect.CanUse(null))
                     {
-                        Strike = ((IChangeSAttackEffect)cardEffect).GetSAttack(Strike, this);
+                        Strike = ((IChangeSAttackEffect)cardEffect).GetSAttack(Strike, this, InvertSecutiryValue);
                     }
                 }
             }
@@ -1264,7 +1318,7 @@ public class Permanent
                 {
                     if (cardEffect.CanUse(null))
                     {
-                        Strike = ((IChangeSAttackEffect)cardEffect).GetSAttack(Strike, this);
+                        Strike = ((IChangeSAttackEffect)cardEffect).GetSAttack(Strike, this, InvertSecutiryValue);
                     }
                 }
             }