BT22_073.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. //BT22 Crescemon
  6. namespace DCGO.CardEffects.BT22
  7. {
  8. public class BT22_073 : 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 == 4 && (permanent.TopCard.HasLightFangOrNightClawTraits || permanent.TopCard.HasCSTraits);
  19. }
  20. cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(PermanentCondition, 3, false, card, null));
  21. }
  22. #endregion
  23. #region Jamming
  24. if (timing == EffectTiming.None)
  25. {
  26. cardEffects.Add(CardEffectFactory.JammingSelfStaticEffect(
  27. isInheritedEffect: false,
  28. card: card,
  29. condition: null));
  30. }
  31. #endregion
  32. #region When Digivolving
  33. if(timing == EffectTiming.OnEnterFieldAnyone)
  34. {
  35. ActivateClass activateClass = new ActivateClass();
  36. activateClass.SetUpICardEffect("Draw 1 trash 1 freeze 1", CanUseCondition, card);
  37. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDescription());
  38. cardEffects.Add(activateClass);
  39. string EffectDescription() => "[When Digivolving] <Draw 1> and trash 1 card in your hand. Then, if this Digimon's stack has 2 or more same-level cards, 1 of your opponent's Digimon or Tamers can't suspend until their turn ends.";
  40. bool CanUseCondition(Hashtable hashtable)
  41. {
  42. return CardEffectCommons.IsExistOnBattleAreaDigimon(card) && CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  43. }
  44. bool HasSameLevelDigivolutionCards(Permanent permanent)
  45. {
  46. return permanent.StackCards
  47. .Filter(x => !x.IsFlipped)
  48. .GroupBy(x => x.Level)
  49. .Any(g => g.Count() >= 2);
  50. }
  51. bool CanActivateCondition(Hashtable hashtable)
  52. {
  53. return CardEffectCommons.IsExistOnBattleAreaDigimon(card);
  54. }
  55. bool PermanentCondition(Permanent permanent)
  56. {
  57. return CardEffectCommons.IsPermanentExistsOnOpponentBattleArea(permanent, card) &&
  58. (permanent.IsTamer || permanent.IsDigimon);
  59. }
  60. IEnumerator ActivateCoroutine(Hashtable hashtable)
  61. {
  62. if (card.Owner.LibraryCards.Count >= 1)
  63. yield return ContinuousController.instance.StartCoroutine(new DrawClass(card.Owner, 1, activateClass).Draw());
  64. if (card.Owner.HandCards.Count >= 1)
  65. {
  66. int discardCount = 1;
  67. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  68. selectHandEffect.SetUp(
  69. selectPlayer: card.Owner,
  70. canTargetCondition: (cardSource) => true,
  71. canTargetCondition_ByPreSelecetedList: null,
  72. canEndSelectCondition: null,
  73. maxCount: discardCount,
  74. canNoSelect: false,
  75. canEndNotMax: false,
  76. isShowOpponent: true,
  77. selectCardCoroutine: null,
  78. afterSelectCardCoroutine: null,
  79. mode: SelectHandEffect.Mode.Discard,
  80. cardEffect: activateClass);
  81. yield return StartCoroutine(selectHandEffect.Activate());
  82. }
  83. if (HasSameLevelDigivolutionCards(card.PermanentOfThisCard()))
  84. {
  85. if (card.Owner.Enemy.GetBattleAreaPermanents().Count(PermanentCondition) >= 1)
  86. {
  87. int maxCount = Math.Min(1, card.Owner.Enemy.GetBattleAreaPermanents().Count(PermanentCondition));
  88. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  89. selectPermanentEffect.SetUp(
  90. selectPlayer: card.Owner,
  91. canTargetCondition: PermanentCondition,
  92. canTargetCondition_ByPreSelecetedList: null,
  93. canEndSelectCondition: null,
  94. maxCount: maxCount,
  95. canNoSelect: false,
  96. canEndNotMax: false,
  97. selectPermanentCoroutine: SelectPermanentCoroutine,
  98. afterSelectPermanentCoroutine: null,
  99. mode: SelectPermanentEffect.Mode.Custom,
  100. cardEffect: activateClass);
  101. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon or Tamer that will get unable to suspend.", "The opponent is selecting 1 Digimon or Tamer that will get unable to suspend.");
  102. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  103. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  104. {
  105. Permanent selectedPermanent = permanent;
  106. if (selectedPermanent != null)
  107. {
  108. CanNotSuspendClass canNotSuspendClass = new CanNotSuspendClass();
  109. canNotSuspendClass.SetUpICardEffect("Can't Suspend", CanUseCondition1, card);
  110. canNotSuspendClass.SetUpCanNotSuspendClass(PermanentCondition: PermanentCondition);
  111. selectedPermanent.UntilOwnerTurnEndEffects.Add((_timing) => canNotSuspendClass);
  112. if (!selectedPermanent.TopCard.CanNotBeAffected(activateClass))
  113. {
  114. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(selectedPermanent));
  115. }
  116. bool CanUseCondition1(Hashtable hashtable)
  117. {
  118. if (selectedPermanent.TopCard != null)
  119. {
  120. if (!selectedPermanent.TopCard.CanNotBeAffected(activateClass))
  121. {
  122. return true;
  123. }
  124. }
  125. return false;
  126. }
  127. bool PermanentCondition(Permanent permanent)
  128. {
  129. if (permanent == selectedPermanent)
  130. {
  131. return true;
  132. }
  133. return false;
  134. }
  135. }
  136. }
  137. }
  138. }
  139. }
  140. }
  141. #endregion
  142. #region Inherit
  143. //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
  144. if (timing == EffectTiming.WhenPermanentWouldBeDeleted)
  145. {
  146. ActivateClass activateClass = new ActivateClass();
  147. activateClass.SetUpICardEffect("Prevent this Digimon from being deleted", CanUseCondition, card);
  148. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, true, EffectDiscription());
  149. activateClass.SetHashString("Inherit-BT22-073");
  150. activateClass.SetIsInheritedEffect(true);
  151. cardEffects.Add(activateClass);
  152. string EffectDiscription()
  153. {
  154. 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.";
  155. }
  156. bool CanSelectCardCondition(CardSource cardSource)
  157. {
  158. if (!cardSource.CanNotTrashFromDigivolutionCards(activateClass))
  159. {
  160. if (CardEffectCommons.IsExistOnBattleArea(card))
  161. {
  162. if (card.PermanentOfThisCard().DigivolutionCards.Contains(cardSource))
  163. {
  164. foreach (CardSource cardSource1 in card.PermanentOfThisCard().DigivolutionCards)
  165. {
  166. if (cardSource != cardSource1)
  167. {
  168. if (cardSource.Level == cardSource1.Level)
  169. {
  170. if (!cardSource1.CanNotTrashFromDigivolutionCards(activateClass))
  171. {
  172. if (cardSource.HasLevel && cardSource1.HasLevel)
  173. {
  174. return true;
  175. }
  176. }
  177. }
  178. }
  179. }
  180. }
  181. }
  182. }
  183. return false;
  184. }
  185. bool CanUseCondition(Hashtable hashtable)
  186. {
  187. return CardEffectCommons.IsExistOnBattleArea(card) &&
  188. CardEffectCommons.CanTriggerWhenRemoveField(hashtable, card) &&
  189. (card.PermanentOfThisCard().TopCard.EqualsTraits("Galaxy") || card.PermanentOfThisCard().TopCard.HasLightFangOrNightClawTraits);
  190. }
  191. bool CanActivateCondition(Hashtable hashtable)
  192. {
  193. if (CardEffectCommons.IsExistOnBattleArea(card))
  194. {
  195. if (card.PermanentOfThisCard().DigivolutionCards.Count(CanSelectCardCondition) >= 2)
  196. {
  197. List<CardSource> canSelectCards = new List<CardSource>();
  198. foreach (CardSource cardSource in card.PermanentOfThisCard().DigivolutionCards)
  199. {
  200. canSelectCards.Add(cardSource);
  201. }
  202. if (canSelectCards.Count >= 2)
  203. {
  204. List<CardSource[]> cardsList = ParameterComparer.Enumerate(canSelectCards, 2).ToList();
  205. foreach (CardSource[] cardSources in cardsList)
  206. {
  207. if (cardSources.Length == 2)
  208. {
  209. if (cardSources[0].Level == cardSources[1].Level)
  210. {
  211. if (cardSources[0].HasLevel && cardSources[1].HasLevel)
  212. {
  213. return true;
  214. }
  215. }
  216. }
  217. }
  218. }
  219. }
  220. }
  221. return false;
  222. }
  223. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  224. {
  225. if (CardEffectCommons.IsExistOnBattleArea(card))
  226. {
  227. Permanent selectedPermanent = card.PermanentOfThisCard();
  228. if (selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition) >= 2)
  229. {
  230. List<CardSource> selectedCards = new List<CardSource>();
  231. int maxCount = 2;
  232. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  233. selectCardEffect.SetUp(
  234. canTargetCondition: CanSelectCardCondition,
  235. canTargetCondition_ByPreSelecetedList: CanTargetCondition_ByPreSelecetedList,
  236. canEndSelectCondition: CanEndSelectCondition,
  237. canNoSelect: () => true,
  238. selectCardCoroutine: SelectCardCoroutine,
  239. afterSelectCardCoroutine: null,
  240. message: "Select cards to discard.",
  241. maxCount: maxCount,
  242. canEndNotMax: false,
  243. isShowOpponent: true,
  244. mode: SelectCardEffect.Mode.Custom,
  245. root: SelectCardEffect.Root.Custom,
  246. customRootCardList: selectedPermanent.DigivolutionCards,
  247. canLookReverseCard: true,
  248. selectPlayer: card.Owner,
  249. cardEffect: activateClass);
  250. selectCardEffect.SetNotShowCard();
  251. yield return StartCoroutine(selectCardEffect.Activate());
  252. bool CanEndSelectCondition(List<CardSource> cardSources)
  253. {
  254. if (CardEffectCommons.HasNoElement(cardSources))
  255. {
  256. return false;
  257. }
  258. List<int> levels = cardSources
  259. .Map(cardSource1 => cardSource1.Level)
  260. .Distinct()
  261. .ToList();
  262. if (levels.Count > 1)
  263. {
  264. return false;
  265. }
  266. return true;
  267. }
  268. bool CanTargetCondition_ByPreSelecetedList(List<CardSource> cardSources, CardSource cardSource)
  269. {
  270. List<int> levels = cardSources
  271. .Map(cardSource1 => cardSource1.Level)
  272. .Concat(new List<int>() { cardSource.Level })
  273. .Distinct()
  274. .ToList();
  275. if (levels.Count > 1)
  276. {
  277. return false;
  278. }
  279. return true;
  280. }
  281. IEnumerator SelectCardCoroutine(CardSource cardSource)
  282. {
  283. selectedCards.Add(cardSource);
  284. yield return null;
  285. }
  286. if (selectedCards.Count >= 1)
  287. {
  288. if (selectedCards.Count == 2)
  289. {
  290. selectedPermanent.willBeRemoveField = false;
  291. selectedPermanent.HideDeleteEffect();
  292. selectedPermanent.HideHandBounceEffect();
  293. selectedPermanent.HideDeckBounceEffect();
  294. }
  295. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(
  296. selectedPermanent,
  297. selectedCards,
  298. activateClass).TrashDigivolutionCards());
  299. }
  300. }
  301. }
  302. }
  303. }
  304. #endregion
  305. return cardEffects;
  306. }
  307. }
  308. }