BT22_072.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. //BT22 Lekismon
  6. namespace DCGO.CardEffects.BT22
  7. {
  8. public class BT22_072 : CEntity_Effect
  9. {
  10. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  11. {
  12. List<ICardEffect> cardEffects = new List<ICardEffect>();
  13. #region Alt digivolution
  14. if(timing == EffectTiming.None)
  15. {
  16. bool PermanentCondition(Permanent permanent)
  17. {
  18. return permanent.Level == 3 && (permanent.TopCard.HasLightFangOrNightClawTraits || permanent.TopCard.HasCSTraits);
  19. }
  20. cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(PermanentCondition, 2, false, card, null));
  21. }
  22. #endregion
  23. #region When Digivolving
  24. if (timing == EffectTiming.OnEnterFieldAnyone)
  25. {
  26. ActivateClass activateClass = new ActivateClass();
  27. activateClass.SetUpICardEffect("Play tamer", CanUseCondition, card);
  28. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDescription());
  29. cardEffects.Add(activateClass);
  30. string EffectDescription() =>
  31. "[When Digivolving] If this Digimon's stack has 2 or more same-level cards, you may play 1 Tamer card with the [Night Claw] or [Light Fang] trait from your hand without paying the cost. This effect can't play cards with the same name as any of your Tamers.";
  32. bool CanUseCondition(Hashtable hashtable)
  33. {
  34. return CardEffectCommons.IsExistOnBattleAreaDigimon(card) && CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  35. }
  36. bool HasSameLevelDigivolutionCards(Permanent permanent)
  37. {
  38. return permanent.StackCards
  39. .Filter(x => !x.IsFlipped)
  40. .GroupBy(x => x.Level)
  41. .Any(g => g.Count() >= 2);
  42. }
  43. bool CanActivateCondition(Hashtable hashtable)
  44. {
  45. return CardEffectCommons.IsExistOnBattleAreaDigimon(card) && HasSameLevelDigivolutionCards(card.PermanentOfThisCard());
  46. }
  47. bool CanSelectCardCondition(CardSource cardSource)
  48. {
  49. return cardSource != null &&
  50. cardSource.HasLightFangOrNightClawTraits &&
  51. cardSource.IsTamer &&
  52. cardSource.Owner == card.Owner &&
  53. CardEffectCommons.CanPlayAsNewPermanent(cardSource: cardSource, payCost: false, cardEffect: activateClass) &&
  54. !card.Owner.GetBattleAreaPermanents().Any((permanent) => permanent.IsTamer && permanent.TopCard.HasSameCardName(cardSource));
  55. }
  56. IEnumerator ActivateCoroutine(Hashtable hashtable)
  57. {
  58. if (CardEffectCommons.HasMatchConditionOwnersHand(card, CanSelectCardCondition))
  59. {
  60. CardSource selectedCard = null;
  61. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionOwnersCardCountInHand(card, CanSelectCardCondition));
  62. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  63. selectHandEffect.SetUp(
  64. selectPlayer: card.Owner,
  65. canTargetCondition: CanSelectCardCondition,
  66. canTargetCondition_ByPreSelecetedList: null,
  67. canEndSelectCondition: null,
  68. maxCount: maxCount,
  69. canNoSelect: true,
  70. canEndNotMax: false,
  71. isShowOpponent: true,
  72. selectCardCoroutine: SelectCardCoroutine,
  73. afterSelectCardCoroutine: null,
  74. mode: SelectHandEffect.Mode.Custom,
  75. cardEffect: activateClass);
  76. selectHandEffect.SetUpCustomMessage("Select 1 card to play.", "The opponent is selecting 1 card to play.");
  77. selectHandEffect.SetUpCustomMessage_ShowCard("Played Card");
  78. yield return StartCoroutine(selectHandEffect.Activate());
  79. IEnumerator SelectCardCoroutine(CardSource cardSource)
  80. {
  81. selectedCard = cardSource;
  82. yield return null;
  83. }
  84. if (selectedCard != null) yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(cardSources: new List<CardSource>() { selectedCard }, activateClass: activateClass, payCost: false, isTapped: false, root: SelectCardEffect.Root.Hand, activateETB: true));
  85. }
  86. }
  87. }
  88. #endregion
  89. #region Inherit
  90. //This section may contain outdated ways of doing things as it was largely copy/pasted from Gracenova and is at the moment more complicated than is worth fiddling with
  91. if (timing == EffectTiming.WhenPermanentWouldBeDeleted)
  92. {
  93. ActivateClass activateClass = new ActivateClass();
  94. activateClass.SetUpICardEffect("Prevent this Digimon from being deleted", CanUseCondition, card);
  95. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, true, EffectDiscription());
  96. activateClass.SetHashString("Inherit-BT22-072");
  97. activateClass.SetIsInheritedEffect(true);
  98. cardEffects.Add(activateClass);
  99. string EffectDiscription()
  100. {
  101. return "[All Turns] [Once Per Turn] When this Digimon with the [Night Claw], [Light Fang] or [Galaxy] trait would be deleted, by trashing 2 same-level cards from its digivolution cards, it isn't deleted.";
  102. }
  103. bool CanSelectCardCondition(CardSource cardSource)
  104. {
  105. if (!cardSource.CanNotTrashFromDigivolutionCards(activateClass))
  106. {
  107. if (CardEffectCommons.IsExistOnBattleArea(card))
  108. {
  109. if (card.PermanentOfThisCard().DigivolutionCards.Contains(cardSource))
  110. {
  111. foreach (CardSource cardSource1 in card.PermanentOfThisCard().DigivolutionCards)
  112. {
  113. if (cardSource != cardSource1)
  114. {
  115. if (cardSource.Level == cardSource1.Level)
  116. {
  117. if (!cardSource1.CanNotTrashFromDigivolutionCards(activateClass))
  118. {
  119. if (cardSource.HasLevel && cardSource1.HasLevel)
  120. {
  121. return true;
  122. }
  123. }
  124. }
  125. }
  126. }
  127. }
  128. }
  129. }
  130. return false;
  131. }
  132. bool CanUseCondition(Hashtable hashtable)
  133. {
  134. return CardEffectCommons.IsExistOnBattleArea(card) &&
  135. CardEffectCommons.CanTriggerWhenRemoveField(hashtable, card) &&
  136. (card.PermanentOfThisCard().TopCard.EqualsTraits("Galaxy") || card.PermanentOfThisCard().TopCard.HasLightFangOrNightClawTraits);
  137. }
  138. bool CanActivateCondition(Hashtable hashtable)
  139. {
  140. if (CardEffectCommons.IsExistOnBattleArea(card))
  141. {
  142. if (card.PermanentOfThisCard().DigivolutionCards.Count(CanSelectCardCondition) >= 2)
  143. {
  144. List<CardSource> canSelectCards = new List<CardSource>();
  145. foreach (CardSource cardSource in card.PermanentOfThisCard().DigivolutionCards)
  146. {
  147. canSelectCards.Add(cardSource);
  148. }
  149. if (canSelectCards.Count >= 2)
  150. {
  151. List<CardSource[]> cardsList = ParameterComparer.Enumerate(canSelectCards, 2).ToList();
  152. foreach (CardSource[] cardSources in cardsList)
  153. {
  154. if (cardSources.Length == 2)
  155. {
  156. if (cardSources[0].Level == cardSources[1].Level)
  157. {
  158. if (cardSources[0].HasLevel && cardSources[1].HasLevel)
  159. {
  160. return true;
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. }
  168. return false;
  169. }
  170. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  171. {
  172. if (CardEffectCommons.IsExistOnBattleArea(card))
  173. {
  174. Permanent selectedPermanent = card.PermanentOfThisCard();
  175. if (selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition) >= 2)
  176. {
  177. List<CardSource> selectedCards = new List<CardSource>();
  178. int maxCount = 2;
  179. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  180. selectCardEffect.SetUp(
  181. canTargetCondition: CanSelectCardCondition,
  182. canTargetCondition_ByPreSelecetedList: CanTargetCondition_ByPreSelecetedList,
  183. canEndSelectCondition: CanEndSelectCondition,
  184. canNoSelect: () => true,
  185. selectCardCoroutine: SelectCardCoroutine,
  186. afterSelectCardCoroutine: null,
  187. message: "Select cards to discard.",
  188. maxCount: maxCount,
  189. canEndNotMax: false,
  190. isShowOpponent: true,
  191. mode: SelectCardEffect.Mode.Custom,
  192. root: SelectCardEffect.Root.Custom,
  193. customRootCardList: selectedPermanent.DigivolutionCards,
  194. canLookReverseCard: true,
  195. selectPlayer: card.Owner,
  196. cardEffect: activateClass);
  197. selectCardEffect.SetNotShowCard();
  198. yield return StartCoroutine(selectCardEffect.Activate());
  199. bool CanEndSelectCondition(List<CardSource> cardSources)
  200. {
  201. if (CardEffectCommons.HasNoElement(cardSources))
  202. {
  203. return false;
  204. }
  205. List<int> levels = cardSources
  206. .Map(cardSource1 => cardSource1.Level)
  207. .Distinct()
  208. .ToList();
  209. if (levels.Count > 1)
  210. {
  211. return false;
  212. }
  213. return true;
  214. }
  215. bool CanTargetCondition_ByPreSelecetedList(List<CardSource> cardSources, CardSource cardSource)
  216. {
  217. List<int> levels = cardSources
  218. .Map(cardSource1 => cardSource1.Level)
  219. .Concat(new List<int>() { cardSource.Level })
  220. .Distinct()
  221. .ToList();
  222. if (levels.Count > 1)
  223. {
  224. return false;
  225. }
  226. return true;
  227. }
  228. IEnumerator SelectCardCoroutine(CardSource cardSource)
  229. {
  230. selectedCards.Add(cardSource);
  231. yield return null;
  232. }
  233. if (selectedCards.Count >= 1)
  234. {
  235. if (selectedCards.Count == 2)
  236. {
  237. selectedPermanent.willBeRemoveField = false;
  238. selectedPermanent.HideDeleteEffect();
  239. selectedPermanent.HideHandBounceEffect();
  240. selectedPermanent.HideDeckBounceEffect();
  241. }
  242. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(
  243. selectedPermanent,
  244. selectedCards,
  245. activateClass).TrashDigivolutionCards());
  246. }
  247. }
  248. }
  249. }
  250. }
  251. #endregion
  252. return cardEffects;
  253. }
  254. }
  255. }