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

Add Dual Card Implementation with ST24_07

hooperk 4 месяцев назад
Родитель
Сommit
267d2324ae

+ 2 - 2
Assets/Scripts/Script/CEntity_Base.cs

@@ -37,7 +37,7 @@ public class CEntity_Base : ScriptableObject
     [TextArea] public string LinkEffect = "";
     [TextArea] public string LinkRequirement = "";
 
-    public string dualEffect = "";
+    [TextArea] public string dualEffect = "";
     public List<CardColor> OptionCardColorRequirements = new List<CardColor>();
     [TextArea] public string OptionEffect = "";
 
@@ -74,7 +74,7 @@ public class CEntity_Base : ScriptableObject
     public bool IsACE => OverflowMemory >= 1;
     public bool IsStandardValid => true;
 
-    public bool IsDualCard => !dualEffect.IsNullOrEmpty();
+    public bool IsDualCard => !String.IsNullOrEmpty(dualEffect);
 
     #region regulation mark
     public string RegulationMark

+ 98 - 4
Assets/Scripts/Script/CardController.cs

@@ -301,6 +301,7 @@ public class PlayCardClass
     {
         bool burstDigivolved = false;
         bool appFusion = false;
+        bool isEvolution = false;
 
         List<CardSource> playedCards_fixed = new List<CardSource>();
 
@@ -389,8 +390,6 @@ public class PlayCardClass
 
             #region Determine if Evolution
 
-            bool isEvolution = false;
-
             if (targetPermanents.Count >= 1)
             {
                 if (!isJogress)
@@ -997,8 +996,9 @@ public class PlayCardClass
 
         #region filter cards
 
-        List<CardSource> permanentCards = playedCards_fixed.Filter(cardSource => cardSource.IsPermanent);
-        List<CardSource> optionCards = playedCards_fixed.Filter(cardSource => !cardSource.IsPermanent);
+        bool isDualCardAsOption(CardSource cardSource) => cardSource.IsDigimon && cardSource.IsOption && !isEvolution;
+        List<CardSource> permanentCards = playedCards_fixed.Filter(cardSource => cardSource.IsPermanent && !isDualCardAsOption(cardSource));
+        List<CardSource> optionCards = playedCards_fixed.Filter(cardSource => !cardSource.IsPermanent || isDualCardAsOption(cardSource));
 
         #region play permanent
 
@@ -1752,6 +1752,100 @@ public class UseOptionClass
 
             #endregion
 
+            if(card.Owner.ExecutingCards.Contains(card))
+            {
+                List<OptionResolutionClass> optionResolutionEffects = new List<OptionResolutionClass>();
+                foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
+                {
+                    #region Effects of permanents in play
+                    foreach (Permanent permanent in player.GetFieldPermanents())
+                    {
+                        foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
+                        {
+                            if (cardEffect is OptionResolutionClass)
+                            {
+                                if (cardEffect.CanTrigger(null))
+                                {
+                                    optionResolutionEffects.Add((OptionResolutionClass)cardEffect);
+                                }
+                            }
+                        }
+                    }
+                    #endregion
+
+                    #region Effects on the Player
+                    foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
+                    {
+                        if (cardEffect is OptionResolutionClass)
+                        {
+                            if (cardEffect.CanTrigger(null))
+                            {
+                                optionResolutionEffects.Add((OptionResolutionClass)cardEffect);
+                            }
+                        }
+                    }
+                    #endregion
+                }
+
+                foreach (ICardEffect cardEffect in card.EffectList(EffectTiming.None))
+                {
+                    if (cardEffect is OptionResolutionClass)
+                    {
+                        if (cardEffect.CanTrigger(null))
+                        {
+                            optionResolutionEffects.Add((OptionResolutionClass)cardEffect);
+                        }
+                    }
+                }
+
+                while (card.Owner.ExecutingCards.Contains(card) && optionResolutionEffects.Count(effect => effect.CanResolve()) > 0)
+                {
+                    List<OptionResolutionClass> possibleEffects = optionResolutionEffects.Filter(effect => effect.CanResolve());
+                    if (possibleEffects.Count() == 1)
+                    {
+                        OptionResolutionClass currentEffect = possibleEffects[0];
+                        if (currentEffect != null) yield return ContinuousController.instance.StartCoroutine(currentEffect.Resolve());
+                        optionResolutionEffects.Remove(currentEffect);
+                    }
+                    else
+                    {
+                        List<SkillInfo> skillInfos = possibleEffects.Map(effect => new SkillInfo(effect, null, EffectTiming.None));
+                        List<CardSource> rootCardSources = skillInfos.Map(skillInfo => skillInfo.CardEffect.EffectSourceCard);
+
+                        int skillIndex = -1;
+
+                        yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectCardPanel.OpenSelectCardPanel(
+                                Message: "Option has multiple resolutions instead of going to trash.\nChoose which to process.",
+                                RootCardSources: rootCardSources,
+                                _CanTargetCondition: _ => true,
+                                _CanTargetCondition_ByPreSelecetedList: null,
+                                _CanEndSelectCondition: null,
+                                _MaxCount: 1,
+                                _CanEndNotMax: false,
+                                _CanNoSelect: () => false,
+                                CanLookReverseCard: true,
+                                skillInfos: skillInfos,
+                                root: SelectCardEffect.Root.None));
+
+                        if (GManager.instance.selectCardPanel.SelectedIndex.Count > 0)
+                        {
+                            skillIndex = GManager.instance.selectCardPanel.SelectedIndex[0];
+                        }
+
+                        if (skillIndex >= 0)
+                        {
+                            OptionResolutionClass currentEffect = possibleEffects[skillIndex];
+                            if (currentEffect != null) yield return ContinuousController.instance.StartCoroutine(currentEffect.Resolve());
+                            optionResolutionEffects.Remove(currentEffect);
+                        }
+                        else
+                        {
+                            break; // Should not happen, unless we later allow denying all by no select
+                        }
+                    }
+                }
+            }
+
             if (card.Owner.ExecutingCards.Contains(card))
             {
                 if (_addSecurityEndOption && card.Owner.CanAddSecurity(CardEffect))

+ 64 - 0
Assets/Scripts/Script/CardEffectFactory/KeyWordEffects/ArtsDigivolve.cs

@@ -0,0 +1,64 @@
+using System.Collections;
+using System.Collections.Generic;
+using System;
+using System.Linq;
+using UnityEngine;
+
+public partial class CardEffectFactory
+{
+    #region Processing of [Arts Digivolve]
+    public static OptionResolutionClass ArtsDigivolveEffect(CardSource card)
+    {
+        if (card == null) return null;
+        OptionResolutionClass artsDigivolutionClass = new();
+        artsDigivolutionClass.SetUpOptionResolutionClass(ResolutionCoroutine(), CanResolveCondition);
+        return artsDigivolutionClass;
+
+        bool CanResolveCondition() => CardEffectCommons.HasMatchConditionOwnersPermanent(card, CanSelectPermanentCondition);
+
+        bool CanSelectPermanentCondition(Permanent permanent)
+        {
+            return (CardEffectCommons.IsPermanentExistsOnOwnerBattleArea(permanent, card)
+                    || CardEffectCommons.IsPermanentExistsOnOwnerBreedingArea(permanent, card))
+                && card.CanPlayCardTargetFrame(permanent.PermanentFrame, false, artsDigivolutionClass, SelectCardEffect.Root.Execution);
+        }
+        
+        IEnumerator ResolutionCoroutine()
+        {
+            SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
+    
+            selectPermanentEffect.SetUp(
+                selectPlayer: card.Owner,
+                canTargetCondition: CanSelectPermanentCondition,
+                canTargetCondition_ByPreSelecetedList: null,
+                canEndSelectCondition: null,
+                maxCount: 1,
+                canNoSelect: true,
+                canEndNotMax: false,
+                selectPermanentCoroutine: SelectPermanentCoroutine,
+                afterSelectPermanentCoroutine: null,
+                mode: SelectPermanentEffect.Mode.Custom,
+                cardEffect: artsDigivolutionClass);
+
+            selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to Arts Digivolve.", "The opponent is selecting 1 Digimon to Arts Digivolve.");
+
+            yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
+
+            IEnumerator SelectPermanentCoroutine(Permanent permanent)
+            {
+                yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.DigivolveIntoExcecutingAreaCard(
+                    permanent,
+                    null,
+                    false,
+                    null,
+                    null,
+                    -1,
+                    artsDigivolutionClass,
+                    null,
+                    ignoreSelection: true
+                ));
+            }
+        }
+    }
+    #endregion
+}

+ 8 - 0
Assets/Scripts/Script/CardEffectInterfaces.cs

@@ -510,4 +510,12 @@ public interface IVortexCanAttackPlayersEffect
 {
     bool VortexCanAttackPlayersPermanent(Permanent Attacker);
 }
+#endregion
+
+#region "Instead of trashing after use" effects
+public interface IOptionResolutionEffect
+{
+    bool CanResolve();
+    IEnumerator Resolve();
+}
 #endregion

+ 111 - 6
Assets/Scripts/Script/CardSource.cs

@@ -108,12 +108,12 @@ public class CardSource : MonoBehaviour
     {
         get
         {
-            if (CanNotPlayThisOption)
+            if (IsDigimon && Owner.GetBattleAreaDigimons().Some(permanent => CanPlayCardTargetFrame(permanent.PermanentFrame, true, null)))
             {
-                return false;
+                return true;
             }
 
-            if (_cEntity_Base.IsPermanent)
+            if (_cEntity_Base.IsPermanent && !IsOption)
             {
                 if (!CanPlayJogress(true))
                 {
@@ -125,6 +125,11 @@ public class CardSource : MonoBehaviour
             }
             else if (IsOption)
             {
+                if (CanNotPlayThisOption)
+                {
+                    return false;
+                }
+
                 #region whether cost can be paid
 
                 List<int> costs = new List<int>() { this.PayingCost(SelectCardEffect.Root.Hand, null, checkAvailability: true) };
@@ -267,9 +272,11 @@ public class CardSource : MonoBehaviour
 
                 #endregion
 
-                bool matchColorRequirement = CardColors.Every(cardColor =>
+                List<CardColor> colorsToCheck = IsDigimon ? DualCardColors : CardColors;
+
+                bool matchColorRequirement = colorsToCheck.Every(cardColor =>
                     Owner.GetFieldPermanents().Some(permanent =>
-                        !permanent.TopCard.IsOption && permanent.TopCard.CardColors.Contains(cardColor)));
+                        permanent.TopCard.IsPermanent && permanent.TopCard.HasCardColor(cardColor)));
 
                 if (!matchColorRequirement)
                 {
@@ -315,6 +322,8 @@ public class CardSource : MonoBehaviour
 
     public List<CardColor> BaseCardColorsFromEntity => _cEntity_Base.cardColors.Distinct().ToList();
 
+    public List<CardColor> BaseDualCardColorsFromEntity => _cEntity_Base.OptionCardColorRequirements.Distinct().ToList();
+
     #endregion
 
     #region base card colors
@@ -358,6 +367,45 @@ public class CardSource : MonoBehaviour
         }
     }
 
+    public List<CardColor> BaseDualCardColors
+    {
+        get
+        {
+            List<CardColor> baseCardColors = BaseDualCardColorsFromEntity;
+
+            #region the effects that changes base card colors
+
+            #region the effects of itself
+
+            if (PermanentOfThisCard() == null)
+            {
+                EffectList(EffectTiming.None)
+                    .Filter(cardEffect => cardEffect is IChangeBaseCardColorEffect && cardEffect.CanUse(null))
+                    .ForEach(cardEffect => baseCardColors = ((IChangeBaseCardColorEffect)cardEffect).GetBaseCardColors(baseCardColors, this));
+            }
+
+            #endregion
+
+            #region the effects of permanents
+
+            GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
+                .Map(player => player.GetFieldPermanents())
+                .Flat()
+                .Map(permanent => permanent.EffectList(EffectTiming.None))
+                .Flat()
+                .Filter(cardEffect => cardEffect is IChangeBaseCardColorEffect && cardEffect.CanUse(null))
+                .ForEach(cardEffect => baseCardColors = ((IChangeBaseCardColorEffect)cardEffect).GetBaseCardColors(baseCardColors, this));
+
+            #endregion
+
+            #endregion
+
+            baseCardColors = baseCardColors.Distinct().ToList();
+
+            return baseCardColors;
+        }
+    }
+
     #endregion
 
     #region card colors
@@ -401,6 +449,45 @@ public class CardSource : MonoBehaviour
         }
     }
 
+    public List<CardColor> DualCardColors
+    {
+        get
+        {
+            List<CardColor> cardColors = BaseDualCardColors;
+
+            #region the effects that changes card colors
+
+            #region the effects of itself
+
+            if (PermanentOfThisCard() == null)
+            {
+                EffectList(EffectTiming.None)
+                    .Filter(cardEffect => cardEffect is IChangeCardColorEffect && cardEffect.CanUse(null))
+                    .ForEach(cardEffect => cardColors = ((IChangeCardColorEffect)cardEffect).GetCardColors(cardColors, this));
+            }
+
+            #endregion
+
+            #region the effects of permanents
+
+            GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
+                .Map(player => player.GetFieldPermanents())
+                .Flat()
+                .Map(permanent => permanent.EffectList(EffectTiming.None))
+                .Flat()
+                .Filter(cardEffect => cardEffect is IChangeCardColorEffect && cardEffect.CanUse(null))
+                .ForEach(cardEffect => cardColors = ((IChangeCardColorEffect)cardEffect).GetCardColors(cardColors, this));
+
+            #endregion
+
+            #endregion
+
+            cardColors = cardColors.Distinct().ToList();
+
+            return cardColors;
+        }
+    }
+
     #endregion
 
     #region evoCosts from entity
@@ -1021,7 +1108,7 @@ public class CardSource : MonoBehaviour
             return false;
         }
 
-        if (PayCost && frame.GetFramePermanent() == null)
+        if (PayCost && frame.GetFramePermanent() == null && !IsOption)
         {
             int cost = PayingCost(root, new List<Permanent>() { frame.GetFramePermanent() }, checkAvailability: true, FixedCost: fixedCost);
 
@@ -1390,6 +1477,24 @@ public class CardSource : MonoBehaviour
 
     #endregion
 
+    #region whether this card has the mentioned color
+
+    public bool HasCardColor(CardColor cardColor, bool isOptionOnly = false)
+    {
+        if (isOptionOnly)
+        {
+            if (!IsOption)
+                return false;
+            if (IsDigimon)
+            {
+                return DualCardColors.Contains(cardColor);
+            }
+        }
+        return CardColors.Contains(cardColor) || DualCardColors.Contains(cardColor);
+    }
+
+    #endregion
+
     #region whether this card has at least 1 card name that contains "Greymon"
 
     public bool HasGreymonName

+ 34 - 0
Assets/Scripts/Script/OptionResolutionClass.cs

@@ -0,0 +1,34 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using System.Linq;
+using Photon;
+using System;
+
+public class OptionResolutionClass : ICardEffect, IOptionResolutionEffect
+{
+    public void SetUpOptionResolutionClass(IEnumerator resolutionCoroutine, Func<bool> resolutionCondition = null)
+    {
+        ResolutionCoroutine = resolutionCoroutine;
+        ResolutionCondition = resolutionCondition;
+    }
+
+    Func<bool> ResolutionCondition { get; set; }
+    IEnumerator ResolutionCoroutine { get; set; }
+
+    public bool CanResolve()
+    {
+        return ResolutionCondition == null || ResolutionCondition();
+    }
+
+    public IEnumerator Resolve()
+    {
+        if (CanResolve())
+        {
+            if (ResolutionCoroutine != null)
+            {
+                yield return ContinuousController.instance.StartCoroutine(ResolutionCoroutine);
+            }
+        }
+    }
+}

+ 11 - 8
Assets/Scripts/Script/TurnStateMachine.cs

@@ -2107,7 +2107,7 @@ public class TurnStateMachine : MonoBehaviourPunCallbacks
 
                                 foreach (FieldCardFrame fieldCardFrame in GManager.instance.You.fieldCardFrames)
                                 {
-                                    if (fieldCardFrame.IsEmptyFrame())
+                                    if (fieldCardFrame.IsEmptyFrame() && !handCard1.cardSource.IsOption)
                                     {
                                         if (handCard1.cardSource.CanPlayCardTargetFrame(fieldCardFrame, true, null))
                                         {
@@ -2141,7 +2141,7 @@ public class TurnStateMachine : MonoBehaviourPunCallbacks
                             #endregion
 
                             #region オプション
-                            else if (handCard1.cardSource.IsOption)
+                            if (handCard1.cardSource.IsOption)
                             {
                                 GManager.instance.You.playMatCardFrame.Frame.transform.parent.gameObject.SetActive(true);
                                 GManager.instance.You.playMatCardFrame.OnFrame_Select(DataBase.SelectColor_Blue);
@@ -2570,14 +2570,17 @@ public class TurnStateMachine : MonoBehaviourPunCallbacks
 
                                     bool CanPlayEmptyFrame = false;
 
-                                    foreach (FieldCardFrame fieldCardFrame in GManager.instance.You.fieldCardFrames)
+                                    if (!handCard.cardSource.IsOption)
                                     {
-                                        if (fieldCardFrame.IsEmptyFrame())
+                                        foreach (FieldCardFrame fieldCardFrame in GManager.instance.You.fieldCardFrames)
                                         {
-                                            if (handCard.cardSource.CanPlayCardTargetFrame(fieldCardFrame, true, null))
+                                            if (fieldCardFrame.IsEmptyFrame())
                                             {
-                                                CanPlayEmptyFrame = true;
-                                                break;
+                                                if (handCard.cardSource.CanPlayCardTargetFrame(fieldCardFrame, true, null))
+                                                {
+                                                    CanPlayEmptyFrame = true;
+                                                    break;
+                                                }
                                             }
                                         }
                                     }
@@ -2619,7 +2622,7 @@ public class TurnStateMachine : MonoBehaviourPunCallbacks
                                 #endregion
 
                                 #region option
-                                else if (handCard.cardSource.IsOption)
+                                if (handCard.cardSource.IsOption)
                                 {
                                     #region Check for drops on the playmat
                                     if (dropAreas.Count((dropArea) => dropArea.IsChildThisDropArea(GManager.instance.You.playMatCardFrame.Frame)) > 0)