BlastDNADigivolution.cs 10 KB

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