BT9_012.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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_012 : 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("Greymon");
  18. }
  19. cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(permanentCondition: PermanentCondition, digivolutionCost: 0, ignoreDigivolutionRequirement: false, card: card, condition: null));
  20. }
  21. if (timing == EffectTiming.WhenPermanentWouldBeDeleted || timing == EffectTiming.WhenReturntoHandAnyone || timing == EffectTiming.WhenReturntoLibraryAnyone)
  22. {
  23. ActivateClass activateClass = new ActivateClass();
  24. activateClass.SetUpICardEffect("Prevent this Digimon from being deleted or returned to hand or deck", CanUseCondition, card);
  25. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  26. activateClass.SetIsInheritedEffect(true);
  27. activateClass.SetHashString("Substitute_BT9_012");
  28. cardEffects.Add(activateClass);
  29. string EffectDiscription()
  30. {
  31. return "[All Turns] When this Digimon has [Greymon] or [Omnimon] in its name and an effect would delete it or return it to your hand or deck, you may trash 2 cards of the same level in this Digimon's digivolution cards to prevent it from leaving play.";
  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.IsByEffect(hashtable, null))
  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.HasGreymonName || 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 (CardEffectCommons.IsExistOnBattleArea(card))
  114. {
  115. Permanent selectedPermanent = card.PermanentOfThisCard();
  116. if (selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition) >= 2)
  117. {
  118. List<CardSource> selectedCards = new List<CardSource>();
  119. int maxCount = 2;
  120. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  121. selectCardEffect.SetUp(
  122. canTargetCondition: CanSelectCardCondition,
  123. canTargetCondition_ByPreSelecetedList: CanTargetCondition_ByPreSelecetedList,
  124. canEndSelectCondition: CanEndSelectCondition,
  125. canNoSelect: () => true,
  126. selectCardCoroutine: SelectCardCoroutine,
  127. afterSelectCardCoroutine: null,
  128. message: "Select cards to discard.",
  129. maxCount: maxCount,
  130. canEndNotMax: false,
  131. isShowOpponent: true,
  132. mode: SelectCardEffect.Mode.Custom,
  133. root: SelectCardEffect.Root.Custom,
  134. customRootCardList: selectedPermanent.DigivolutionCards,
  135. canLookReverseCard: true,
  136. selectPlayer: card.Owner,
  137. cardEffect: activateClass);
  138. selectCardEffect.SetNotShowCard();
  139. yield return StartCoroutine(selectCardEffect.Activate());
  140. bool CanEndSelectCondition(List<CardSource> cardSources)
  141. {
  142. if (CardEffectCommons.HasNoElement(cardSources))
  143. {
  144. return false;
  145. }
  146. List<int> levels = cardSources
  147. .Map(cardSource1 => cardSource1.Level)
  148. .Distinct()
  149. .ToList();
  150. if (levels.Count > 1)
  151. {
  152. return false;
  153. }
  154. return true;
  155. }
  156. bool CanTargetCondition_ByPreSelecetedList(List<CardSource> cardSources, CardSource cardSource)
  157. {
  158. List<int> levels = cardSources
  159. .Map(cardSource1 => cardSource1.Level)
  160. .Concat(new List<int>() { cardSource.Level })
  161. .Distinct()
  162. .ToList();
  163. if (levels.Count > 1)
  164. {
  165. return false;
  166. }
  167. return true;
  168. }
  169. IEnumerator SelectCardCoroutine(CardSource cardSource)
  170. {
  171. selectedCards.Add(cardSource);
  172. yield return null;
  173. }
  174. if (selectedCards.Count >= 1)
  175. {
  176. if (selectedCards.Count == 2)
  177. {
  178. selectedPermanent.willBeRemoveField = false;
  179. selectedPermanent.HideDeleteEffect();
  180. selectedPermanent.HideHandBounceEffect();
  181. selectedPermanent.HideDeckBounceEffect();
  182. }
  183. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(
  184. selectedPermanent,
  185. selectedCards,
  186. activateClass).TrashDigivolutionCards());
  187. }
  188. }
  189. }
  190. }
  191. }
  192. return cardEffects;
  193. }
  194. }