BT9_024.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.Linq;
  5. using Photon;
  6. using System;
  7. using Photon.Pun;
  8. public class BT9_024 : CEntity_Effect
  9. {
  10. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  11. {
  12. List<ICardEffect> cardEffects = new List<ICardEffect>();
  13. if (timing == EffectTiming.None)
  14. {
  15. bool PermanentCondition(Permanent targetPermanent)
  16. {
  17. return targetPermanent.TopCard.CardNames.Contains("Garurumon");
  18. }
  19. cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(permanentCondition: PermanentCondition, digivolutionCost: 0, ignoreDigivolutionRequirement: false, card: card, condition: null));
  20. }
  21. if (timing == EffectTiming.WhenPermanentWouldBeDeleted)
  22. {
  23. ActivateClass activateClass = new ActivateClass();
  24. activateClass.SetUpICardEffect("Prevent this Digimon from being deleted", CanUseCondition, card);
  25. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  26. activateClass.SetIsInheritedEffect(true);
  27. activateClass.SetHashString("Substitute_BT9_024");
  28. cardEffects.Add(activateClass);
  29. string EffectDiscription()
  30. {
  31. return "[All Turns] When this Digimon has [Garurumon] or [Omnimon] in its name and would be deleted in battle, you may trash 2 cards of the same level in this Digimon's digivolution cards to prevent that deletion.";
  32. }
  33. bool CanSelectCardCondition(CardSource cardSource)
  34. {
  35. if (!cardSource.CanNotTrashFromDigivolutionCards(activateClass))
  36. {
  37. if (CardEffectCommons.IsExistOnBattleArea(card))
  38. {
  39. if (card.PermanentOfThisCard().DigivolutionCards.Contains(card))
  40. {
  41. foreach (CardSource cardSource1 in card.PermanentOfThisCard().DigivolutionCards)
  42. {
  43. if (cardSource != cardSource1)
  44. {
  45. if (cardSource.Level == cardSource1.Level)
  46. {
  47. if (!cardSource1.CanNotTrashFromDigivolutionCards(activateClass))
  48. {
  49. if (cardSource.HasLevel && cardSource1.HasLevel)
  50. {
  51. return true;
  52. }
  53. }
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }
  60. return false;
  61. }
  62. bool CanUseCondition(Hashtable hashtable)
  63. {
  64. if (CardEffectCommons.IsExistOnBattleArea(card))
  65. {
  66. if (CardEffectCommons.CanTriggerWhenRemoveField(hashtable, card))
  67. {
  68. if (CardEffectCommons.IsByBattle(hashtable))
  69. {
  70. return true;
  71. }
  72. }
  73. }
  74. return false;
  75. }
  76. bool CanActivateCondition(Hashtable hashtable)
  77. {
  78. if (CardEffectCommons.IsExistOnBattleArea(card))
  79. {
  80. if (card.PermanentOfThisCard().TopCard.HasGarurumonName || card.PermanentOfThisCard().TopCard.ContainsCardName("Omnimon"))
  81. {
  82. if (card.PermanentOfThisCard().DigivolutionCards.Count(CanSelectCardCondition) >= 2)
  83. {
  84. List<CardSource> canSelectCards = new List<CardSource>();
  85. foreach (CardSource cardSource in card.PermanentOfThisCard().DigivolutionCards)
  86. {
  87. canSelectCards.Add(cardSource);
  88. }
  89. if (canSelectCards.Count >= 2)
  90. {
  91. List<CardSource[]> cardsList = ParameterComparer.Enumerate(canSelectCards, 2).ToList();
  92. foreach (CardSource[] cardSources in cardsList)
  93. {
  94. if (cardSources.Length == 2)
  95. {
  96. if (cardSources[0].Level == cardSources[1].Level)
  97. {
  98. if (cardSources[0].HasLevel && cardSources[1].HasLevel)
  99. {
  100. return true;
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }
  108. }
  109. return false;
  110. }
  111. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  112. {
  113. if (isExistOnField(card))
  114. {
  115. if (card.Owner.GetBattleAreaDigimons().Contains(card.PermanentOfThisCard()))
  116. {
  117. Permanent selectedPermanent = card.PermanentOfThisCard();
  118. if (selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition) >= 2)
  119. {
  120. List<CardSource> selectedCards = new List<CardSource>();
  121. int maxCount = 2;
  122. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  123. selectCardEffect.SetUp(
  124. canTargetCondition: CanSelectCardCondition,
  125. canTargetCondition_ByPreSelecetedList: CanTargetCondition_ByPreSelecetedList,
  126. canEndSelectCondition: CanEndSelectCondition,
  127. canNoSelect: () => true,
  128. selectCardCoroutine: SelectCardCoroutine,
  129. afterSelectCardCoroutine: null,
  130. message: "Select cards to discard.",
  131. maxCount: maxCount,
  132. canEndNotMax: false,
  133. isShowOpponent: true,
  134. mode: SelectCardEffect.Mode.Custom,
  135. root: SelectCardEffect.Root.Custom,
  136. customRootCardList: selectedPermanent.DigivolutionCards,
  137. canLookReverseCard: true,
  138. selectPlayer: card.Owner,
  139. cardEffect: activateClass);
  140. selectCardEffect.SetNotShowCard();
  141. yield return StartCoroutine(selectCardEffect.Activate());
  142. bool CanEndSelectCondition(List<CardSource> cardSources)
  143. {
  144. if (maxCount >= 1)
  145. {
  146. if (cardSources.Count <= 0)
  147. {
  148. return false;
  149. }
  150. }
  151. List<int> levels = new List<int>();
  152. foreach (CardSource cardSource1 in cardSources)
  153. {
  154. if (!levels.Contains(cardSource1.Level))
  155. {
  156. levels.Add(cardSource1.Level);
  157. }
  158. }
  159. levels = levels.Distinct().ToList();
  160. if (levels.Count > 1)
  161. {
  162. return false;
  163. }
  164. return true;
  165. }
  166. bool CanTargetCondition_ByPreSelecetedList(List<CardSource> cardSources, CardSource cardSource)
  167. {
  168. List<int> levels = new List<int>();
  169. foreach (CardSource cardSource1 in cardSources)
  170. {
  171. if (!levels.Contains(cardSource1.Level))
  172. {
  173. levels.Add(cardSource1.Level);
  174. }
  175. }
  176. if (!levels.Contains(cardSource.Level))
  177. {
  178. levels.Add(cardSource.Level);
  179. }
  180. levels = levels.Distinct().ToList();
  181. if (levels.Count > 1)
  182. {
  183. return false;
  184. }
  185. return true;
  186. }
  187. IEnumerator SelectCardCoroutine(CardSource cardSource)
  188. {
  189. selectedCards.Add(cardSource);
  190. yield return null;
  191. }
  192. if (selectedCards.Count >= 1)
  193. {
  194. if (selectedCards.Count == 2)
  195. {
  196. selectedPermanent.willBeRemoveField = false;
  197. selectedPermanent.HideDeleteEffect();
  198. }
  199. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(selectedPermanent, selectedCards, activateClass).TrashDigivolutionCards());
  200. }
  201. }
  202. }
  203. }
  204. }
  205. }
  206. return cardEffects;
  207. }
  208. }