BlastDNADigivolution.cs 9.2 KB

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