| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- using System.Collections;
- using System.Collections.Generic;
- using System;
- using System.Linq;
- using UnityEngine;
- using Photon.Pun;
- public class BlastDNACondition
- {
- public string Name;
- public List<Permanent> Permanents;
- public List<CardSource> CardSources;
- public BlastDNACondition(string name)
- {
- Name = name;
- Permanents = new List<Permanent>();
- CardSources = new List<CardSource>();
- }
- }
- public partial class CardEffectFactory
- {
- #region Trigger effect of [Blast DNA Digivolve]
- public static ActivateClass BlastDNADigivolveEffect(CardSource card, List<BlastDNACondition> blastDNAConditions, Func<bool> condition)
- {
- if (card == null) return null;
- if (!CardEffectCommons.IsExistOnHand(card)) return null;
- if (card.Owner.GetBattleAreaPermanents().Count == 0) return null;
- if (card.Owner.HandCards.Count < 2) return null;
- List<Permanent> fieldPermanents = new List<Permanent>();
- List<Permanent> permanentSources = new List<Permanent>();
- List<CardSource> handSources = new List<CardSource>();
- void FilterDNAPermanents()
- {
- if (blastDNAConditions[0].Permanents.Count >= 1 && blastDNAConditions[0].CardSources.Count == 0)
- blastDNAConditions[1].Permanents.Clear();
- if (blastDNAConditions[1].Permanents.Count >= 1 && blastDNAConditions[1].CardSources.Count == 0)
- blastDNAConditions[0].Permanents.Clear();
- }
- void FilterDNAHandSources()
- {
- if (blastDNAConditions[0].CardSources.Count >= 1 && blastDNAConditions[0].CardSources.Count == 0)
- blastDNAConditions[1].CardSources.Clear();
- if (blastDNAConditions[1].CardSources.Count >= 1 && blastDNAConditions[1].CardSources.Count == 0)
- blastDNAConditions[0].CardSources.Clear();
- }
- bool HasValidDNATargets()
- {
- fieldPermanents = card.Owner.GetBattleAreaDigimons();
- foreach (BlastDNACondition DNACondition in blastDNAConditions)
- {
- DNACondition.Permanents = fieldPermanents.Filter(permanent => permanent.TopCard.EqualsCardName(DNACondition.Name));
- DNACondition.CardSources = card.Owner.HandCards.Filter(cardSource => cardSource.EqualsCardName(DNACondition.Name));
- permanentSources.AddRange(DNACondition.Permanents);
- handSources.AddRange(DNACondition.CardSources);
- }
- FilterDNAPermanents();
- FilterDNAHandSources();
- if (blastDNAConditions[0].Permanents.Count(permanent => !permanent.TopCard.CanNotEvolve(permanent)) > 0 && blastDNAConditions[1].CardSources.Count > 0)
- return true;
- if (blastDNAConditions[0].CardSources.Count > 0 && blastDNAConditions[1].Permanents.Count(permanent => !permanent.TopCard.CanNotEvolve(permanent)) > 0)
- return true;
- return false;
- }
- ActivateClass activateClass = new ActivateClass();
- activateClass.SetUpICardEffect("Blast DNA Digivolve", CanUseCondition, card);
- activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, DataBase.BlastDNADigivolveEffectDiscription());
- activateClass.SetIsCounterEffect(true);
- bool CanSelectPermanent(Permanent permanent)
- {
- if(CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card))
- {
- foreach (BlastDNACondition DNACondition in blastDNAConditions)
- {
- if (DNACondition.Permanents.Contains(permanent))
- return true;
- }
- }
- return false;
- }
- bool CanSelectHandSource(CardSource cardSource)
- {
- return handSources.Contains(cardSource);
- }
- bool CanUseCondition(Hashtable hashtable)
- {
- if (CardEffectCommons.CanTriggerOnPermanentAttack(hashtable, permanent => CardEffectCommons.IsOpponentPermanent(permanent, card)))
- {
- if (card.Owner.HandCards.Contains(card))
- {
- if (condition == null || condition())
- {
- return true;
- }
- }
- }
- return false;
- }
- bool CanActivateCondition(Hashtable hashtable)
- {
- if (card.Owner.HandCards.Contains(card))
- {
- if (HasValidDNATargets())
- {
- if (condition == null || condition())
- {
- return true;
- }
- }
- }
- return false;
- }
- IEnumerator ActivateCoroutine(Hashtable _hashtable)
- {
- Permanent selectedPermanent = null;
- CardSource selectedCardSource = null;
- int maxCount = Math.Min(1, permanentSources.Count);
- SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
- selectPermanentEffect.SetUp(
- selectPlayer: card.Owner,
- canTargetCondition: CanSelectPermanent,
- canTargetCondition_ByPreSelecetedList: null,
- canEndSelectCondition: null,
- maxCount: maxCount,
- canNoSelect: false,
- canEndNotMax: false,
- selectPermanentCoroutine: SelectPermanentCoroutine,
- afterSelectPermanentCoroutine: null,
- mode: SelectPermanentEffect.Mode.Custom,
- cardEffect: activateClass);
- selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to DNA digivolve.", "The opponent is selecting 1 Digimon to DNA digivolve.");
- yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
- IEnumerator SelectPermanentCoroutine(Permanent permanent)
- {
- selectedPermanent = permanent;
- foreach(string name in selectedPermanent.TopCard.CardNames)
- {
- handSources = handSources.Filter(source => !source.ContainsCardName(name));
- }
- maxCount = Math.Min(1, handSources.Count);
- SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
- selectHandEffect.SetUp(
- selectPlayer: card.Owner,
- canTargetCondition: CanSelectHandSource,
- canTargetCondition_ByPreSelecetedList: null,
- canEndSelectCondition: null,
- maxCount: maxCount,
- canNoSelect: false,
- canEndNotMax: false,
- isShowOpponent: true,
- selectCardCoroutine: SelectCardCoroutine,
- afterSelectCardCoroutine: null,
- mode: SelectHandEffect.Mode.Custom,
- cardEffect: activateClass);
- selectHandEffect.SetUpCustomMessage("Select 1 Digimon to DNA digivolve.", "The opponent is selecting 1 Digimon to DNA digivolve.");
- yield return ContinuousController.instance.StartCoroutine(selectHandEffect.Activate());
- }
- IEnumerator SelectCardCoroutine(CardSource cardSource)
- {
- selectedCardSource = cardSource;
- Permanent playedPermanent;
- int frameID = -1;
- foreach (FieldCardFrame fieldCardFrame in selectedCardSource.Owner.fieldCardFrames)
- {
- if (card.CanPlayCardTargetFrame(fieldCardFrame, false, null))
- {
- if (fieldCardFrame.IsEmptyFrame())
- {
- frameID = fieldCardFrame.FrameID;
- break;
- }
- }
- }
- if (0 <= frameID && frameID < card.Owner.fieldCardFrames.Count)
- {
- playedPermanent = new Permanent(new List<CardSource>() { selectedCardSource }) { IsSuspended = false };
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.CreateNewPermanent(playedPermanent, frameID));
- }
- int[] JogressEvoRootsFrameIDs = { 0, 0 };
- if (selectedPermanent.TopCard.EqualsCardName(blastDNAConditions[0].Name))
- {
- JogressEvoRootsFrameIDs[0] = selectedPermanent.PermanentFrame.FrameID;
- JogressEvoRootsFrameIDs[1] = selectedCardSource.PermanentOfThisCard().PermanentFrame.FrameID;
- }
- else
- {
- JogressEvoRootsFrameIDs[0] = selectedCardSource.PermanentOfThisCard().PermanentFrame.FrameID;
- JogressEvoRootsFrameIDs[1] = selectedPermanent.PermanentFrame.FrameID;
- }
- if (card.CanPlayJogress(true))
- {
- PlayCardClass playCard = new PlayCardClass(
- cardSources: new List<CardSource>() { card },
- hashtable: CardEffectCommons.CardEffectHashtable(activateClass),
- payCost: true,
- targetPermanent: null,
- isTapped: false,
- root: SelectCardEffect.Root.Hand,
- activateETB: true);
- playCard.SetJogress(JogressEvoRootsFrameIDs);
- yield return ContinuousController.instance.StartCoroutine(playCard.PlayCard());
- foreach (BlastDNACondition DNACondition in blastDNAConditions)
- {
- DNACondition.Permanents = new List<Permanent>();
- DNACondition.CardSources = new List<CardSource>();
- }
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCard(selectedCardSource, false));
- }
-
- }
- }
- return activateClass;
- }
- #endregion
- }
|