BT13_112.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace DCGO.CardEffects.BT13
  6. {
  7. public class BT13_112 : CEntity_Effect
  8. {
  9. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  10. {
  11. List<ICardEffect> cardEffects = new List<ICardEffect>();
  12. if (timing == EffectTiming.OnEnterFieldAnyone)
  13. {
  14. ActivateClass activateClass = new ActivateClass();
  15. activateClass.SetUpICardEffect("Delete 1 Digimon or play digivolution cards", CanUseCondition, card);
  16. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  17. cardEffects.Add(activateClass);
  18. string EffectDiscription()
  19. {
  20. return "[On Play] You may delete 1 of your opponent's Digimon, or play 1 of each Digimon with the [Royal Knight] trait and different names from the digivolution cards of your Digimon in the breeding area without paying the costs. When a Digimon is played by this effect, trash your Digimon in the breeding area, and all your Digimon gain <Rush> for the turn.";
  21. }
  22. bool CanSelectPermanentCondition(Permanent permanent)
  23. {
  24. return CardEffectCommons.IsPermanentExistsOnOpponentBattleAreaDigimon(permanent, card);
  25. }
  26. bool CanSelectPermanentCondition1(Permanent permanent)
  27. {
  28. if (CardEffectCommons.IsPermanentExistsOnOwnerBreedingArea(permanent, card))
  29. {
  30. if (permanent.IsDigimon)
  31. {
  32. if (permanent.DigivolutionCards.Count(CanSelectCardCondition) >= 1)
  33. {
  34. return true;
  35. }
  36. }
  37. }
  38. return false;
  39. }
  40. bool CanSelectCardCondition(CardSource cardSource)
  41. {
  42. if (cardSource.IsDigimon)
  43. {
  44. if (cardSource.HasRoyalKnightTraits)
  45. {
  46. if (CardEffectCommons.CanPlayAsNewPermanent(cardSource: cardSource, payCost: false, cardEffect: activateClass))
  47. {
  48. return true;
  49. }
  50. }
  51. }
  52. return false;
  53. }
  54. bool CanUseCondition(Hashtable hashtable)
  55. {
  56. return CardEffectCommons.CanTriggerOnPlay(hashtable, card);
  57. }
  58. bool CanActivateCondition(Hashtable hashtable)
  59. {
  60. if (CardEffectCommons.IsExistOnBattleArea(card))
  61. {
  62. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  63. {
  64. return true;
  65. }
  66. if (card.Owner.GetBreedingAreaPermanents().Some(CanSelectPermanentCondition1))
  67. {
  68. return true;
  69. }
  70. }
  71. return false;
  72. }
  73. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  74. {
  75. bool canSelectDelete = card.Owner.Enemy.GetBattleAreaDigimons().Some(CanSelectPermanentCondition);
  76. bool canSelectPlay = card.Owner.GetBreedingAreaPermanents().Some(CanSelectPermanentCondition1);
  77. if (canSelectDelete || canSelectPlay)
  78. {
  79. if (canSelectDelete && canSelectPlay)
  80. {
  81. List<SelectionElement<bool>> selectionElements = new List<SelectionElement<bool>>()
  82. {
  83. new SelectionElement<bool>(message: $"Delete Digimon", value : true, spriteIndex: 0),
  84. new SelectionElement<bool>(message: $"Play digivolution cards", value : false, spriteIndex: 1),
  85. };
  86. string selectPlayerMessage = "Which effect do you activate?";
  87. string notSelectPlayerMessage = "The opponent is choosing from which effect to activate.";
  88. GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: selectionElements, selectPlayer: card.Owner, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  89. }
  90. else
  91. {
  92. GManager.instance.userSelectionManager.SetBool(canSelectDelete);
  93. }
  94. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  95. bool isDelete = GManager.instance.userSelectionManager.SelectedBoolValue;
  96. if (isDelete)
  97. {
  98. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  99. {
  100. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  101. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  102. selectPermanentEffect.SetUp(
  103. selectPlayer: card.Owner,
  104. canTargetCondition: CanSelectPermanentCondition,
  105. canTargetCondition_ByPreSelecetedList: null,
  106. canEndSelectCondition: null,
  107. maxCount: maxCount,
  108. canNoSelect: false,
  109. canEndNotMax: false,
  110. selectPermanentCoroutine: null,
  111. afterSelectPermanentCoroutine: null,
  112. mode: SelectPermanentEffect.Mode.Destroy,
  113. cardEffect: activateClass);
  114. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  115. }
  116. }
  117. else
  118. {
  119. if (card.Owner.GetBreedingAreaPermanents().Count(CanSelectPermanentCondition1) >= 1)
  120. {
  121. Permanent selectedPermanent = card.Owner.GetBreedingAreaPermanents()[0];
  122. if (CanSelectPermanentCondition1(selectedPermanent))
  123. {
  124. bool played = false;
  125. List<CardSource> selectedCards = new List<CardSource>();
  126. int maxCount = selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition);
  127. List<string> royalKnightCardNames = selectedPermanent.DigivolutionCards
  128. .Filter(CanSelectCardCondition)
  129. .Map(digivolutionCard => digivolutionCard.CardNames)
  130. .Flat()
  131. .Distinct()
  132. .ToList();
  133. maxCount = Math.Min(maxCount, royalKnightCardNames.Count);
  134. maxCount = Math.Min(maxCount, card.Owner.fieldCardFrames.Count((frame) => frame.IsEmptyFrame() && frame.IsBattleAreaFrame()));
  135. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  136. selectCardEffect.SetUp(
  137. canTargetCondition: CanSelectCardCondition,
  138. canTargetCondition_ByPreSelecetedList: CanTargetCondition_ByPreSelecetedList,
  139. canEndSelectCondition: CanEndSelectCondition,
  140. canNoSelect: () => true,
  141. selectCardCoroutine: SelectCardCoroutine,
  142. afterSelectCardCoroutine: null,
  143. message: "Select cards to play.",
  144. maxCount: maxCount,
  145. canEndNotMax: false,
  146. isShowOpponent: true,
  147. mode: SelectCardEffect.Mode.Custom,
  148. root: SelectCardEffect.Root.Custom,
  149. customRootCardList: selectedPermanent.DigivolutionCards,
  150. canLookReverseCard: true,
  151. selectPlayer: card.Owner,
  152. cardEffect: activateClass);
  153. selectCardEffect.SetUpCustomMessage("Select cards to play.", "The opponent is selecting cards to play.");
  154. selectCardEffect.SetUpCustomMessage_ShowCard("Played Card");
  155. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  156. bool CanTargetCondition_ByPreSelecetedList(List<CardSource> cardSources, CardSource cardSource)
  157. {
  158. List<string> cardNames = cardSources
  159. .Map(cardSource1 => cardSource1.CardNames)
  160. .Flat()
  161. .Distinct()
  162. .ToList();
  163. if (cardSource.CardNames.Some((cardName) => cardNames.Contains(cardName)))
  164. {
  165. return false;
  166. }
  167. return true;
  168. }
  169. bool CanEndSelectCondition(List<CardSource> cardSources)
  170. {
  171. List<string> cardNames = cardSources
  172. .Map(cardSource1 => cardSource1.CardNames)
  173. .Flat()
  174. .Distinct()
  175. .ToList();
  176. if (cardNames.Some(cardName => cardSources.Count(cardSource => cardSource.CardNames.Contains(cardName)) >= 2))
  177. {
  178. return false;
  179. }
  180. return true;
  181. }
  182. IEnumerator SelectCardCoroutine(CardSource cardSource)
  183. {
  184. selectedCards.Add(cardSource);
  185. yield return null;
  186. }
  187. if (selectedCards.Count >= 1)
  188. {
  189. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(cardSources: selectedCards, activateClass: activateClass, payCost: false, isTapped: false, root: SelectCardEffect.Root.DigivolutionCards, activateETB: true));
  190. if (selectedCards.Some(CardEffectCommons.IsExistOnBattleArea))
  191. {
  192. played = true;
  193. }
  194. }
  195. if (played)
  196. {
  197. List<Permanent> DigitamaPermanents = card.Owner.GetBreedingAreaPermanents()
  198. .Filter(permanent => permanent.IsDigimon)
  199. .Filter(permanent => !permanent.TopCard.CanNotBeAffected(activateClass))
  200. .Clone();
  201. if (DigitamaPermanents.Count >= 1)
  202. {
  203. foreach (Permanent permanent in DigitamaPermanents)
  204. {
  205. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  206. CardSource cardSource = permanent.TopCard;
  207. ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { cardSource }, "Cards put to trash", true, true));
  208. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  209. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  210. }
  211. }
  212. bool PermanentCondition(Permanent permanent)
  213. {
  214. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card);
  215. }
  216. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.GainRushPlayerEffect(
  217. permanentCondition: PermanentCondition,
  218. effectDuration: EffectDuration.UntilEachTurnEnd,
  219. activateClass: activateClass));
  220. }
  221. }
  222. }
  223. }
  224. }
  225. }
  226. }
  227. if (timing == EffectTiming.OnEnterFieldAnyone)
  228. {
  229. ActivateClass activateClass = new ActivateClass();
  230. activateClass.SetUpICardEffect("Delete 1 Digimon or play digivolution cards", CanUseCondition, card);
  231. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  232. cardEffects.Add(activateClass);
  233. string EffectDiscription()
  234. {
  235. return "[When Digivolving] You may delete 1 of your opponent's Digimon, or play 1 of each Digimon with the [Royal Knight] trait and different names from the digivolution cards of your Digimon in the breeding area without paying the costs. When a Digimon is played by this effect, trash your Digimon in the breeding area, and all your Digimon gain <Rush> for the turn.";
  236. }
  237. bool CanSelectPermanentCondition(Permanent permanent)
  238. {
  239. return CardEffectCommons.IsPermanentExistsOnOpponentBattleAreaDigimon(permanent, card);
  240. }
  241. bool CanSelectPermanentCondition1(Permanent permanent)
  242. {
  243. if (CardEffectCommons.IsPermanentExistsOnOwnerBreedingArea(permanent, card))
  244. {
  245. if (permanent.IsDigimon)
  246. {
  247. if (permanent.DigivolutionCards.Count(CanSelectCardCondition) >= 1)
  248. {
  249. return true;
  250. }
  251. }
  252. }
  253. return false;
  254. }
  255. bool CanSelectCardCondition(CardSource cardSource)
  256. {
  257. if (cardSource.IsDigimon)
  258. {
  259. if (cardSource.HasRoyalKnightTraits)
  260. {
  261. if (CardEffectCommons.CanPlayAsNewPermanent(cardSource: cardSource, payCost: false, cardEffect: activateClass))
  262. {
  263. return true;
  264. }
  265. }
  266. }
  267. return false;
  268. }
  269. bool CanUseCondition(Hashtable hashtable)
  270. {
  271. return CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  272. }
  273. bool CanActivateCondition(Hashtable hashtable)
  274. {
  275. if (CardEffectCommons.IsExistOnBattleArea(card))
  276. {
  277. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  278. {
  279. return true;
  280. }
  281. if (card.Owner.GetBreedingAreaPermanents().Some(CanSelectPermanentCondition1))
  282. {
  283. return true;
  284. }
  285. }
  286. return false;
  287. }
  288. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  289. {
  290. bool canSelectDelete = card.Owner.Enemy.GetBattleAreaDigimons().Some(CanSelectPermanentCondition);
  291. bool canSelectPlay = card.Owner.GetBreedingAreaPermanents().Some(CanSelectPermanentCondition1);
  292. if (canSelectDelete || canSelectPlay)
  293. {
  294. if (canSelectDelete && canSelectPlay)
  295. {
  296. List<SelectionElement<bool>> selectionElements = new List<SelectionElement<bool>>()
  297. {
  298. new SelectionElement<bool>(message: $"Delete Digimon", value : true, spriteIndex: 0),
  299. new SelectionElement<bool>(message: $"Play digivolution cards", value : false, spriteIndex: 1),
  300. };
  301. string selectPlayerMessage = "Which effect do you activate?";
  302. string notSelectPlayerMessage = "The opponent is choosing from which effect to activate.";
  303. GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: selectionElements, selectPlayer: card.Owner, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  304. }
  305. else
  306. {
  307. GManager.instance.userSelectionManager.SetBool(canSelectDelete);
  308. }
  309. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  310. bool isDelete = GManager.instance.userSelectionManager.SelectedBoolValue;
  311. if (isDelete)
  312. {
  313. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  314. {
  315. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  316. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  317. selectPermanentEffect.SetUp(
  318. selectPlayer: card.Owner,
  319. canTargetCondition: CanSelectPermanentCondition,
  320. canTargetCondition_ByPreSelecetedList: null,
  321. canEndSelectCondition: null,
  322. maxCount: maxCount,
  323. canNoSelect: false,
  324. canEndNotMax: false,
  325. selectPermanentCoroutine: null,
  326. afterSelectPermanentCoroutine: null,
  327. mode: SelectPermanentEffect.Mode.Destroy,
  328. cardEffect: activateClass);
  329. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  330. }
  331. }
  332. else
  333. {
  334. if (card.Owner.GetBreedingAreaPermanents().Count(CanSelectPermanentCondition1) >= 1)
  335. {
  336. Permanent selectedPermanent = card.Owner.GetBreedingAreaPermanents()[0];
  337. if (CanSelectPermanentCondition1(selectedPermanent))
  338. {
  339. bool played = false;
  340. List<CardSource> selectedCards = new List<CardSource>();
  341. int maxCount = selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition);
  342. List<string> royalKnightCardNames = selectedPermanent.DigivolutionCards
  343. .Filter(CanSelectCardCondition)
  344. .Map(digivolutionCard => digivolutionCard.CardNames)
  345. .Flat()
  346. .Distinct()
  347. .ToList();
  348. maxCount = Math.Min(maxCount, royalKnightCardNames.Count);
  349. maxCount = Math.Min(maxCount, card.Owner.fieldCardFrames.Count((frame) => frame.IsEmptyFrame() && frame.IsBattleAreaFrame()));
  350. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  351. selectCardEffect.SetUp(
  352. canTargetCondition: CanSelectCardCondition,
  353. canTargetCondition_ByPreSelecetedList: CanTargetCondition_ByPreSelecetedList,
  354. canEndSelectCondition: CanEndSelectCondition,
  355. canNoSelect: () => true,
  356. selectCardCoroutine: SelectCardCoroutine,
  357. afterSelectCardCoroutine: null,
  358. message: "Select cards to play.",
  359. maxCount: maxCount,
  360. canEndNotMax: false,
  361. isShowOpponent: true,
  362. mode: SelectCardEffect.Mode.Custom,
  363. root: SelectCardEffect.Root.Custom,
  364. customRootCardList: selectedPermanent.DigivolutionCards,
  365. canLookReverseCard: true,
  366. selectPlayer: card.Owner,
  367. cardEffect: activateClass);
  368. selectCardEffect.SetUpCustomMessage("Select cards to play.", "The opponent is selecting cards to play.");
  369. selectCardEffect.SetUpCustomMessage_ShowCard("Played Card");
  370. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  371. bool CanTargetCondition_ByPreSelecetedList(List<CardSource> cardSources, CardSource cardSource)
  372. {
  373. List<string> cardNames = cardSources
  374. .Map(cardSource1 => cardSource1.CardNames)
  375. .Flat()
  376. .Distinct()
  377. .ToList();
  378. if (cardSource.CardNames.Some((cardName) => cardNames.Contains(cardName)))
  379. {
  380. return false;
  381. }
  382. return true;
  383. }
  384. bool CanEndSelectCondition(List<CardSource> cardSources)
  385. {
  386. List<string> cardNames = cardSources
  387. .Map(cardSource1 => cardSource1.CardNames)
  388. .Flat()
  389. .Distinct()
  390. .ToList();
  391. if (cardNames.Some(cardName => cardSources.Count(cardSource => cardSource.CardNames.Contains(cardName)) >= 2))
  392. {
  393. return false;
  394. }
  395. return true;
  396. }
  397. IEnumerator SelectCardCoroutine(CardSource cardSource)
  398. {
  399. selectedCards.Add(cardSource);
  400. yield return null;
  401. }
  402. if (selectedCards.Count >= 1)
  403. {
  404. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(cardSources: selectedCards, activateClass: activateClass, payCost: false, isTapped: false, root: SelectCardEffect.Root.DigivolutionCards, activateETB: true));
  405. if (selectedCards.Some(CardEffectCommons.IsExistOnBattleArea))
  406. {
  407. played = true;
  408. }
  409. }
  410. if (played)
  411. {
  412. List<Permanent> DigitamaPermanents = card.Owner.GetBreedingAreaPermanents()
  413. .Filter(permanent => permanent.IsDigimon)
  414. .Filter(permanent => !permanent.TopCard.CanNotBeAffected(activateClass))
  415. .Clone();
  416. if (DigitamaPermanents.Count >= 1)
  417. {
  418. foreach (Permanent permanent in DigitamaPermanents)
  419. {
  420. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  421. CardSource cardSource = permanent.TopCard;
  422. ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { cardSource }, "Cards put to trash", true, true));
  423. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  424. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  425. }
  426. }
  427. bool PermanentCondition(Permanent permanent)
  428. {
  429. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card);
  430. }
  431. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.GainRushPlayerEffect(
  432. permanentCondition: PermanentCondition,
  433. effectDuration: EffectDuration.UntilEachTurnEnd,
  434. activateClass: activateClass));
  435. }
  436. }
  437. }
  438. }
  439. }
  440. }
  441. }
  442. return cardEffects;
  443. }
  444. }
  445. }