BlastDNADigivolution.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. using Photon.Pun;
  7. public class BlastDNACondition
  8. {
  9. public string Name;
  10. public List<Permanent> Permanents;
  11. public List<CardSource> CardSources;
  12. public BlastDNACondition(string name)
  13. {
  14. Name = name;
  15. Permanents = new List<Permanent>();
  16. CardSources = new List<CardSource>();
  17. }
  18. }
  19. public partial class CardEffectFactory
  20. {
  21. #region Trigger effect of [Blast DNA Digivolve]
  22. public static ActivateClass BlastDNADigivolveEffect(CardSource card, List<BlastDNACondition> blastDNAConditions, Func<bool> condition)
  23. {
  24. if (card == null) return null;
  25. if (!CardEffectCommons.IsExistOnHand(card)) return null;
  26. if (card.Owner.GetBattleAreaPermanents().Count == 0) return null;
  27. if (card.Owner.HandCards.Count < 2) return null;
  28. List<Permanent> fieldPermanents = card.Owner.GetBattleAreaDigimons();
  29. List<Permanent> permanentSources = new List<Permanent>();
  30. List<CardSource> handSources = new List<CardSource>();
  31. void FilterDNAPermanents()
  32. {
  33. if (blastDNAConditions[0].Permanents.Count >= 1 && blastDNAConditions[0].CardSources.Count == 0)
  34. blastDNAConditions[1].Permanents.Clear();
  35. if (blastDNAConditions[1].Permanents.Count >= 1 && blastDNAConditions[1].CardSources.Count == 0)
  36. blastDNAConditions[0].Permanents.Clear();
  37. }
  38. void FilterDNAHandSources()
  39. {
  40. if (blastDNAConditions[0].CardSources.Count >= 1 && blastDNAConditions[0].CardSources.Count == 0)
  41. blastDNAConditions[1].CardSources.Clear();
  42. if (blastDNAConditions[1].CardSources.Count >= 1 && blastDNAConditions[1].CardSources.Count == 0)
  43. blastDNAConditions[0].CardSources.Clear();
  44. }
  45. bool HasValidDNATargets()
  46. {
  47. foreach (BlastDNACondition DNACondition in blastDNAConditions)
  48. {
  49. DNACondition.Permanents = fieldPermanents.Filter(permanent => permanent.TopCard.EqualsCardName(DNACondition.Name));
  50. DNACondition.CardSources = card.Owner.HandCards.Filter(cardSource => cardSource.EqualsCardName(DNACondition.Name));
  51. permanentSources.AddRange(DNACondition.Permanents);
  52. handSources.AddRange(DNACondition.CardSources);
  53. }
  54. FilterDNAPermanents();
  55. FilterDNAHandSources();
  56. if (blastDNAConditions[0].Permanents.Count(permanent => !permanent.TopCard.CanNotEvolve(permanent)) > 0 && blastDNAConditions[1].CardSources.Count > 0)
  57. return true;
  58. if (blastDNAConditions[0].CardSources.Count > 0 && blastDNAConditions[1].Permanents.Count(permanent => !permanent.TopCard.CanNotEvolve(permanent)) > 0)
  59. return true;
  60. return false;
  61. }
  62. ActivateClass activateClass = new ActivateClass();
  63. activateClass.SetUpICardEffect("Blast DNA Digivolve", CanUseCondition, card);
  64. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, DataBase.BlastDNADigivolveEffectDiscription());
  65. activateClass.SetIsCounterEffect(true);
  66. bool CanSelectPermanent(Permanent permanent)
  67. {
  68. if(CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card))
  69. {
  70. foreach (BlastDNACondition DNACondition in blastDNAConditions)
  71. {
  72. if (DNACondition.Permanents.Contains(permanent))
  73. return true;
  74. }
  75. }
  76. return false;
  77. }
  78. bool CanSelectHandSource(CardSource cardSource)
  79. {
  80. return handSources.Contains(cardSource);
  81. }
  82. bool CanUseCondition(Hashtable hashtable)
  83. {
  84. if (CardEffectCommons.CanTriggerOnPermanentAttack(hashtable, permanent => CardEffectCommons.IsOpponentPermanent(permanent, card)))
  85. {
  86. if (card.Owner.HandCards.Contains(card))
  87. {
  88. if (condition == null || condition())
  89. {
  90. return true;
  91. }
  92. }
  93. }
  94. return false;
  95. }
  96. bool CanActivateCondition(Hashtable hashtable)
  97. {
  98. if (card.Owner.HandCards.Contains(card))
  99. {
  100. if (HasValidDNATargets())
  101. {
  102. if (condition == null || condition())
  103. {
  104. return true;
  105. }
  106. }
  107. }
  108. return false;
  109. }
  110. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  111. {
  112. Permanent selectedPermanent = null;
  113. CardSource selectedCardSource = null;
  114. int maxCount = Math.Min(1, permanentSources.Count);
  115. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  116. selectPermanentEffect.SetUp(
  117. selectPlayer: card.Owner,
  118. canTargetCondition: CanSelectPermanent,
  119. canTargetCondition_ByPreSelecetedList: null,
  120. canEndSelectCondition: null,
  121. maxCount: maxCount,
  122. canNoSelect: false,
  123. canEndNotMax: false,
  124. selectPermanentCoroutine: SelectPermanentCoroutine,
  125. afterSelectPermanentCoroutine: null,
  126. mode: SelectPermanentEffect.Mode.Custom,
  127. cardEffect: activateClass);
  128. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to DNA digivolve.", "The opponent is selecting 1 Digimon to DNA digivolve.");
  129. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  130. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  131. {
  132. selectedPermanent = permanent;
  133. foreach(string name in selectedPermanent.TopCard.CardNames)
  134. {
  135. handSources = handSources.Filter(source => !source.ContainsCardName(name));
  136. }
  137. maxCount = Math.Min(1, handSources.Count);
  138. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  139. selectHandEffect.SetUp(
  140. selectPlayer: card.Owner,
  141. canTargetCondition: CanSelectHandSource,
  142. canTargetCondition_ByPreSelecetedList: null,
  143. canEndSelectCondition: null,
  144. maxCount: maxCount,
  145. canNoSelect: false,
  146. canEndNotMax: false,
  147. isShowOpponent: true,
  148. selectCardCoroutine: SelectCardCoroutine,
  149. afterSelectCardCoroutine: null,
  150. mode: SelectHandEffect.Mode.Custom,
  151. cardEffect: activateClass);
  152. selectHandEffect.SetUpCustomMessage("Select 1 Digimon to DNA digivolve.", "The opponent is selecting 1 Digimon to DNA digivolve.");
  153. yield return ContinuousController.instance.StartCoroutine(selectHandEffect.Activate());
  154. }
  155. IEnumerator SelectCardCoroutine(CardSource cardSource)
  156. {
  157. selectedCardSource = cardSource;
  158. Permanent playedPermanent;
  159. int frameID = -1;
  160. foreach (FieldCardFrame fieldCardFrame in selectedCardSource.Owner.fieldCardFrames)
  161. {
  162. if (card.CanPlayCardTargetFrame(fieldCardFrame, false, null))
  163. {
  164. if (fieldCardFrame.IsEmptyFrame())
  165. {
  166. frameID = fieldCardFrame.FrameID;
  167. break;
  168. }
  169. }
  170. }
  171. if (0 <= frameID && frameID < card.Owner.fieldCardFrames.Count)
  172. {
  173. playedPermanent = new Permanent(new List<CardSource>() { selectedCardSource }) { IsSuspended = false };
  174. yield return ContinuousController.instance.StartCoroutine(CardObjectController.CreateNewPermanent(playedPermanent, frameID));
  175. }
  176. int[] JogressEvoRootsFrameIDs = { 0, 0 };
  177. if (selectedPermanent.TopCard.EqualsCardName(blastDNAConditions[0].Name))
  178. {
  179. JogressEvoRootsFrameIDs[0] = selectedPermanent.PermanentFrame.FrameID;
  180. JogressEvoRootsFrameIDs[1] = selectedCardSource.PermanentOfThisCard().PermanentFrame.FrameID;
  181. }
  182. else
  183. {
  184. JogressEvoRootsFrameIDs[0] = selectedCardSource.PermanentOfThisCard().PermanentFrame.FrameID;
  185. JogressEvoRootsFrameIDs[1] = selectedPermanent.PermanentFrame.FrameID;
  186. }
  187. if (card.CanPlayJogress(true))
  188. {
  189. PlayCardClass playCard = new PlayCardClass(
  190. cardSources: new List<CardSource>() { card },
  191. hashtable: CardEffectCommons.CardEffectHashtable(activateClass),
  192. payCost: true,
  193. targetPermanent: null,
  194. isTapped: false,
  195. root: SelectCardEffect.Root.Hand,
  196. activateETB: true);
  197. playCard.SetJogress(JogressEvoRootsFrameIDs);
  198. yield return ContinuousController.instance.StartCoroutine(playCard.PlayCard());
  199. foreach (BlastDNACondition DNACondition in blastDNAConditions)
  200. {
  201. DNACondition.Permanents = new List<Permanent>();
  202. DNACondition.CardSources = new List<CardSource>();
  203. }
  204. }
  205. else
  206. {
  207. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCard(selectedCardSource, false));
  208. }
  209. }
  210. }
  211. return activateClass;
  212. }
  213. #endregion
  214. }