BlastDNADigivolution.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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> permanentSources = card.Owner.GetBattleAreaDigimons()
  29. .Clone()
  30. .Filter(permanent => permanent.TopCard.ContainsCardName(blastDNAConditions[0].Name)
  31. || permanent.TopCard.ContainsCardName(blastDNAConditions[1].Name));
  32. List<CardSource> handSources = card.Owner.HandCards
  33. .Clone()
  34. .Filter(cardSource => cardSource.ContainsCardName(blastDNAConditions[0].Name)
  35. || cardSource.ContainsCardName(blastDNAConditions[1].Name));
  36. ActivateClass activateClass = new ActivateClass();
  37. activateClass.SetUpICardEffect("Blast DNA Digivolve", CanUseCondition, card);
  38. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, DataBase.BlastDNADigivolveEffectDiscription());
  39. activateClass.SetIsCounterEffect(true);
  40. bool CanSelectPermanent(Permanent permanent)
  41. {
  42. return permanentSources.Contains(permanent);
  43. }
  44. bool CanSelectHandSource(CardSource cardSource)
  45. {
  46. return handSources.Contains(cardSource);
  47. }
  48. bool CanUseCondition(Hashtable hashtable)
  49. {
  50. Debug.Log($"CAN USE: {CardEffectCommons.CanTriggerOnPermanentAttack(hashtable, permanent => CardEffectCommons.IsOpponentPermanent(permanent, card))}");
  51. if (CardEffectCommons.CanTriggerOnPermanentAttack(hashtable, permanent => CardEffectCommons.IsOpponentPermanent(permanent, card)))
  52. {
  53. Debug.Log($"CAN USE: {card.Owner.HandCards.Contains(card)}");
  54. if (card.Owner.HandCards.Contains(card))
  55. {
  56. if (condition == null || condition())
  57. {
  58. Debug.Log($"CAN USE: TRUE");
  59. return true;
  60. }
  61. }
  62. }
  63. return false;
  64. }
  65. bool CanActivateCondition(Hashtable hashtable)
  66. {
  67. Debug.Log($"CAN ACTIVATE: {card.Owner.HandCards.Contains(card)}");
  68. if (card.Owner.HandCards.Contains(card))
  69. {
  70. Debug.Log($"CAN ACTIVATE: {CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanent)}");
  71. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanent))
  72. {
  73. if (condition == null || condition())
  74. {
  75. Debug.Log($"CAN ACTIVATE: TRUE");
  76. return true;
  77. }
  78. }
  79. }
  80. return false;
  81. }
  82. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  83. {
  84. Permanent selectedPermanent = null;
  85. CardSource selectedCardSource = null;
  86. /*permanentSources.ForEach(permanent =>
  87. {
  88. if (permanent.TopCard.ContainsCardName(blastDNAConditions[0].Name))
  89. blastDNAConditions[0].Permanents.Add(permanent);
  90. if (permanent.TopCard.ContainsCardName(blastDNAConditions[1].Name))
  91. blastDNAConditions[1].Permanents.Add(permanent);
  92. });
  93. handSources.ForEach(cardSource =>
  94. {
  95. if (cardSource.ContainsCardName(blastDNAConditions[0].Name))
  96. blastDNAConditions[0].CardSources.Add(cardSource);
  97. if (cardSource.ContainsCardName(blastDNAConditions[1].Name))
  98. blastDNAConditions[1].CardSources.Add(cardSource);
  99. });*/
  100. Debug.Log("ACTIVATE COROUTINE");
  101. yield return null;
  102. int maxCount = Math.Min(1, permanentSources.Count);
  103. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  104. selectPermanentEffect.SetUp(
  105. selectPlayer: card.Owner,
  106. canTargetCondition: CanSelectPermanent,
  107. canTargetCondition_ByPreSelecetedList: null,
  108. canEndSelectCondition: null,
  109. maxCount: maxCount,
  110. canNoSelect: false,
  111. canEndNotMax: false,
  112. selectPermanentCoroutine: SelectPermanentCoroutine,
  113. afterSelectPermanentCoroutine: null,
  114. mode: SelectPermanentEffect.Mode.Custom,
  115. cardEffect: activateClass);
  116. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to DNA digivolve.", "The opponent is selecting 1 Digimon to DNA digivolve.");
  117. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  118. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  119. {
  120. selectedPermanent = permanent;
  121. Debug.Log($"BLAST DNA: Selected Permanent: {selectedPermanent}");
  122. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  123. selectHandEffect.SetUp(
  124. selectPlayer: card.Owner,
  125. canTargetCondition: CanSelectHandSource,
  126. canTargetCondition_ByPreSelecetedList: null,
  127. canEndSelectCondition: null,
  128. maxCount: maxCount,
  129. canNoSelect: false,
  130. canEndNotMax: false,
  131. isShowOpponent: true,
  132. selectCardCoroutine: SelectCardCoroutine,
  133. afterSelectCardCoroutine: null,
  134. mode: SelectHandEffect.Mode.Custom,
  135. cardEffect: activateClass);
  136. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to DNA digivolve.", "The opponent is selecting 1 Digimon to DNA digivolve.");
  137. yield return ContinuousController.instance.StartCoroutine(selectHandEffect.Activate());
  138. yield return null;
  139. }
  140. IEnumerator SelectCardCoroutine(CardSource cardSource)
  141. {
  142. selectedCardSource = cardSource;
  143. Debug.Log($"BLAST DNA: Selected Cardsource: {selectedCardSource}");
  144. PlayCardClass playCardClass = new PlayCardClass(
  145. cardSources: new List<CardSource>() { selectedCardSource },
  146. hashtable: CardEffectCommons.CardEffectHashtable(activateClass),
  147. payCost: false,
  148. targetPermanent: null,
  149. isTapped: false,
  150. root: SelectCardEffect.Root.Hand,
  151. activateETB: false);
  152. yield return ContinuousController.instance.StartCoroutine(playCardClass.PlayCard());
  153. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { card }, "Played Card", true, true));
  154. int[] JogressEvoRootsFrameIDs = { selectedPermanent.PermanentFrame.FrameID, selectedCardSource.PermanentOfThisCard().PermanentFrame.FrameID };
  155. PlayCardClass playCard = new PlayCardClass(
  156. cardSources: new List<CardSource>() { card },
  157. hashtable: CardEffectCommons.CardEffectHashtable(activateClass),
  158. payCost: true,
  159. targetPermanent: null,
  160. isTapped: false,
  161. root: SelectCardEffect.Root.Hand,
  162. activateETB: true);
  163. playCard.SetJogress(JogressEvoRootsFrameIDs);
  164. yield return ContinuousController.instance.StartCoroutine(playCard.PlayCard());
  165. }
  166. #region Blast Digivolve
  167. /*Permanent selectedPermanent = null;
  168. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  169. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  170. selectPermanentEffect.SetUp(
  171. selectPlayer: card.Owner,
  172. canTargetCondition: CanSelectPermanentCondition,
  173. canTargetCondition_ByPreSelecetedList: null,
  174. canEndSelectCondition: null,
  175. maxCount: maxCount,
  176. canNoSelect: false,
  177. canEndNotMax: false,
  178. selectPermanentCoroutine: SelectPermanentCoroutine,
  179. afterSelectPermanentCoroutine: null,
  180. mode: SelectPermanentEffect.Mode.Custom,
  181. cardEffect: activateClass);
  182. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to digivolve.", "The opponent is selecting 1 Digimon to digivolve.");
  183. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  184. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  185. {
  186. selectedPermanent = permanent;
  187. yield return null;
  188. }
  189. if (selectedPermanent != null)
  190. {
  191. if (card.CanPlayCardTargetFrame(selectedPermanent.PermanentFrame, false, activateClass))
  192. {
  193. PlayCardClass playCardClass = new PlayCardClass(
  194. cardSources: new List<CardSource>() { card },
  195. hashtable: CardEffectCommons.CardEffectHashtable(activateClass),
  196. payCost: false,
  197. targetPermanent: selectedPermanent,
  198. isTapped: false,
  199. root: SelectCardEffect.Root.Hand,
  200. activateETB: true);
  201. yield return ContinuousController.instance.StartCoroutine(playCardClass.PlayCard());
  202. }
  203. }*/
  204. #endregion
  205. }
  206. return activateClass;
  207. }
  208. #endregion
  209. }