BT12_081.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace DCGO.CardEffects.BT12
  6. {
  7. public class BT12_081 : 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.None)
  13. {
  14. bool PermanentCondition(Permanent targetPermanent)
  15. {
  16. return targetPermanent.TopCard.CardNames.Contains("Psychemon");
  17. }
  18. cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(permanentCondition: PermanentCondition, digivolutionCost: 5, ignoreDigivolutionRequirement: false, card: card, condition: null));
  19. }
  20. if (timing == EffectTiming.None)
  21. {
  22. bool PermanentCondition(Permanent targetPermanent)
  23. {
  24. return targetPermanent.TopCard.HasSaveText && (targetPermanent.TopCard.CardColors.Contains(CardColor.Yellow) || targetPermanent.TopCard.CardColors.Contains(CardColor.Green) || targetPermanent.TopCard.CardColors.Contains(CardColor.Purple)) && targetPermanent.TopCard.HasLevel && targetPermanent.TopCard.Level == 4;
  25. }
  26. cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(permanentCondition: PermanentCondition, digivolutionCost: 3, ignoreDigivolutionRequirement: false, card: card, condition: null));
  27. }
  28. if (timing == EffectTiming.OnEnterFieldAnyone)
  29. {
  30. ActivateClass activateClass = new ActivateClass();
  31. activateClass.SetUpICardEffect("Play 1 digivolution card or this Digimon digivolves to [Quartzmon]", CanUseCondition, card);
  32. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  33. cardEffects.Add(activateClass);
  34. string EffectDiscription()
  35. {
  36. return "[When Digivolving] You may play 1 level 4 or lower Digimon card with <Save> from under one of your Tamers without paying its cost. If there are 4 or more digivolution cards under this Digimon, it can be digivolved into a [Quartzmon] in your hand or under one of your Tamers with the digivolution cost reduced by 3 instead.";
  37. }
  38. bool CanSelectPermanentCondition(Permanent permanent)
  39. {
  40. if (CardEffectCommons.IsPermanentExistsOnOwnerBattleArea(permanent, card))
  41. {
  42. if (permanent.IsTamer)
  43. {
  44. if (permanent.DigivolutionCards.Count(CanSelectCardCondition) >= 1)
  45. {
  46. return true;
  47. }
  48. }
  49. }
  50. return false;
  51. }
  52. bool CanSelectCardCondition(CardSource cardSource)
  53. {
  54. if (cardSource.IsDigimon)
  55. {
  56. if (cardSource.Level <= 4)
  57. {
  58. if (CardEffectCommons.CanPlayAsNewPermanent(cardSource: cardSource, payCost: false, cardEffect: activateClass))
  59. {
  60. if (cardSource.HasLevel)
  61. {
  62. if (cardSource.HasSaveText)
  63. {
  64. return true;
  65. }
  66. }
  67. }
  68. }
  69. }
  70. return false;
  71. }
  72. bool CanUseCondition(Hashtable hashtable)
  73. {
  74. return CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  75. }
  76. bool CanActivateCondition(Hashtable hashtable)
  77. {
  78. if (CardEffectCommons.IsExistOnBattleArea(card))
  79. {
  80. if (card.PermanentOfThisCard().DigivolutionCards.Count >= 4)
  81. {
  82. bool CanSelectQuartzmonCardCondition(CardSource cardSource)
  83. {
  84. if (cardSource.CardNames.Contains("Quartzmon"))
  85. {
  86. if (cardSource.CanPlayCardTargetFrame(card.PermanentOfThisCard().PermanentFrame, PayCost: true, cardEffect: activateClass))
  87. {
  88. return true;
  89. }
  90. }
  91. return false;
  92. }
  93. bool CanSelectQuartzmonTamerCondition(Permanent permanent)
  94. {
  95. if (CardEffectCommons.IsPermanentExistsOnOwnerBattleArea(permanent, card))
  96. {
  97. if (permanent.IsTamer)
  98. {
  99. if (permanent.DigivolutionCards.Some(CanSelectQuartzmonCardCondition))
  100. {
  101. return true;
  102. }
  103. }
  104. }
  105. return false;
  106. }
  107. if (card.Owner.HandCards.Count >= 1)
  108. {
  109. return true;
  110. }
  111. if (card.Owner.GetBattleAreaPermanents().Some(CanSelectQuartzmonTamerCondition))
  112. {
  113. return true;
  114. }
  115. }
  116. else
  117. {
  118. if (card.Owner.GetBattleAreaPermanents().Some(CanSelectPermanentCondition))
  119. {
  120. return true;
  121. }
  122. }
  123. }
  124. return false;
  125. }
  126. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  127. {
  128. if (CardEffectCommons.IsExistOnBattleArea(card))
  129. {
  130. bool canEvo = card.PermanentOfThisCard().DigivolutionCards.Count >= 4;
  131. if (canEvo)
  132. {
  133. List<SelectionElement<int>> selectionElements = new List<SelectionElement<int>>()
  134. {
  135. new SelectionElement<int>(message: $"Play From Sources", value : 1, spriteIndex: 0),
  136. new SelectionElement<int>(message: $"Digivolve to [Quartzmon]", value : 0, spriteIndex: 1),
  137. };
  138. string selectPlayerMessage = "Which effect would you like to do?";
  139. string notSelectPlayerMessage = "The opponent is choosing effect to do.";
  140. GManager.instance.userSelectionManager.SetIntSelection(selectionElements: selectionElements, selectPlayer: card.Owner, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  141. }
  142. else
  143. {
  144. GManager.instance.userSelectionManager.SetInt(1);
  145. }
  146. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  147. if (GManager.instance.userSelectionManager.SelectedIntValue == 0)
  148. {
  149. #region Reduce Cost
  150. ChangeCostClass changeCostClass = new ChangeCostClass();
  151. changeCostClass.SetUpICardEffect("Digivolution Cost -3", CanUseCondition1, card);
  152. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardSourceCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  153. Func<EffectTiming, ICardEffect> getCardEffect = GetCardEffect;
  154. card.Owner.UntilCalculateFixedCostEffect.Add(getCardEffect);
  155. ICardEffect GetCardEffect(EffectTiming _timing)
  156. {
  157. if (_timing == EffectTiming.None)
  158. {
  159. return changeCostClass;
  160. }
  161. return null;
  162. }
  163. bool CanUseCondition1(Hashtable hashtable)
  164. {
  165. return true;
  166. }
  167. int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  168. {
  169. if (CardSourceCondition(cardSource))
  170. {
  171. if (RootCondition(root))
  172. {
  173. if (PermanentsCondition(targetPermanents))
  174. {
  175. Cost -= 3;
  176. }
  177. }
  178. }
  179. return Cost;
  180. }
  181. bool PermanentsCondition(List<Permanent> targetPermanents)
  182. {
  183. if (targetPermanents != null)
  184. {
  185. if (targetPermanents.Count(PermanentCondition) >= 1)
  186. {
  187. return true;
  188. }
  189. }
  190. return false;
  191. }
  192. bool PermanentCondition(Permanent targetPermanent)
  193. {
  194. return targetPermanent == card.PermanentOfThisCard();
  195. }
  196. bool CardSourceCondition(CardSource cardSource)
  197. {
  198. return cardSource.Owner == card.Owner;
  199. }
  200. bool RootCondition(SelectCardEffect.Root root)
  201. {
  202. return true;
  203. }
  204. bool isUpDown()
  205. {
  206. return true;
  207. }
  208. #endregion
  209. bool CanSelectQuartzmonCardCondition(CardSource cardSource)
  210. {
  211. if (cardSource.CardNames.Contains("Quartzmon"))
  212. {
  213. SelectCardEffect.Root root = CardEffectCommons.HasMatchConditionOwnersPermanent(
  214. card, (permanent) => permanent.DigivolutionCards.Contains(cardSource))
  215. ? SelectCardEffect.Root.DigivolutionCards
  216. : SelectCardEffect.Root.Hand;
  217. if (cardSource.CanPlayCardTargetFrame(
  218. card.PermanentOfThisCard().PermanentFrame,
  219. PayCost: true,
  220. cardEffect: activateClass,
  221. root: root))
  222. {
  223. return true;
  224. }
  225. }
  226. return false;
  227. }
  228. bool CanSelectQuartzmonTamerCondition(Permanent permanent)
  229. {
  230. if (CardEffectCommons.IsPermanentExistsOnOwnerBattleArea(permanent, card))
  231. {
  232. if (permanent.IsTamer)
  233. {
  234. if (permanent.DigivolutionCards.Some(CanSelectQuartzmonCardCondition))
  235. {
  236. return true;
  237. }
  238. }
  239. }
  240. return false;
  241. }
  242. bool canSelectHand = card.Owner.HandCards.Some(CanSelectQuartzmonCardCondition);
  243. bool canSelectTamer = CardEffectCommons.HasMatchConditionPermanent(CanSelectQuartzmonTamerCondition);
  244. if (canSelectHand || canSelectTamer)
  245. {
  246. if (canSelectHand && canSelectTamer)
  247. {
  248. List<SelectionElement<bool>> selectionElements = new List<SelectionElement<bool>>()
  249. {
  250. new SelectionElement<bool>(message: $"From hand", value : true, spriteIndex: 0),
  251. new SelectionElement<bool>(message: $"Under Tamer", value : false, spriteIndex: 1),
  252. };
  253. string selectPlayerMessage = "From which area do you select 1 [Quartzmon]?";
  254. string notSelectPlayerMessage = "The opponent is selecting from which area to select 1 [Quartzmon].";
  255. GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: selectionElements, selectPlayer: card.Owner, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  256. }
  257. else
  258. {
  259. GManager.instance.userSelectionManager.SetBool(canSelectHand);
  260. }
  261. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  262. bool fromHand = GManager.instance.userSelectionManager.SelectedBoolValue;
  263. if (fromHand)
  264. {
  265. if (card.Owner.HandCards.Count(CanSelectQuartzmonCardCondition) >= 1)
  266. {
  267. List<CardSource> selectedCards = new List<CardSource>();
  268. int maxCount = 1;
  269. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  270. selectHandEffect.SetUp(
  271. selectPlayer: card.Owner,
  272. canTargetCondition: CanSelectQuartzmonCardCondition,
  273. canTargetCondition_ByPreSelecetedList: null,
  274. canEndSelectCondition: null,
  275. maxCount: maxCount,
  276. canNoSelect: true,
  277. canEndNotMax: false,
  278. isShowOpponent: true,
  279. selectCardCoroutine: SelectCardCoroutine,
  280. afterSelectCardCoroutine: null,
  281. mode: SelectHandEffect.Mode.Custom,
  282. cardEffect: activateClass);
  283. selectHandEffect.SetUpCustomMessage("Select 1 [Quartzmon] to digivolve.", "The opponent is selecting 1 [Quartzmon] to digivolve.");
  284. selectHandEffect.SetUpCustomMessage_ShowCard("Played Card");
  285. yield return StartCoroutine(selectHandEffect.Activate());
  286. IEnumerator SelectCardCoroutine(CardSource cardSource)
  287. {
  288. selectedCards.Add(cardSource);
  289. yield return null;
  290. }
  291. yield return ContinuousController.instance.StartCoroutine(new PlayCardClass(
  292. cardSources: selectedCards,
  293. hashtable: CardEffectCommons.CardEffectHashtable(activateClass),
  294. payCost: true,
  295. targetPermanent: card.PermanentOfThisCard(),
  296. isTapped: false,
  297. root: SelectCardEffect.Root.Hand,
  298. activateETB: true).PlayCard());
  299. }
  300. }
  301. else
  302. {
  303. if (card.Owner.GetBattleAreaPermanents().Some(CanSelectQuartzmonTamerCondition))
  304. {
  305. Permanent selectedPermanent = null;
  306. int maxCount = Math.Min(1, card.Owner.GetBattleAreaPermanents().Count(CanSelectQuartzmonTamerCondition));
  307. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  308. selectPermanentEffect.SetUp(
  309. selectPlayer: card.Owner,
  310. canTargetCondition: CanSelectQuartzmonTamerCondition,
  311. canTargetCondition_ByPreSelecetedList: null,
  312. canEndSelectCondition: null,
  313. maxCount: maxCount,
  314. canNoSelect: true,
  315. canEndNotMax: false,
  316. selectPermanentCoroutine: SelectPermanentCoroutine,
  317. afterSelectPermanentCoroutine: null,
  318. mode: SelectPermanentEffect.Mode.Custom,
  319. cardEffect: activateClass);
  320. selectPermanentEffect.SetUpCustomMessage("Select 1 Tamer.", "The opponent is selecting 1 Tamer.");
  321. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  322. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  323. {
  324. selectedPermanent = permanent;
  325. yield return null;
  326. }
  327. if (selectedPermanent != null)
  328. {
  329. if (selectedPermanent.DigivolutionCards.Some((cardSource) => CanSelectQuartzmonCardCondition(cardSource)))
  330. {
  331. maxCount = Math.Min(1, selectedPermanent.DigivolutionCards.Count((cardSource) => CanSelectQuartzmonCardCondition(cardSource)));
  332. List<CardSource> selectedCards = new List<CardSource>();
  333. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  334. selectCardEffect.SetUp(
  335. canTargetCondition: CanSelectQuartzmonCardCondition,
  336. canTargetCondition_ByPreSelecetedList: null,
  337. canEndSelectCondition: null,
  338. canNoSelect: () => false,
  339. selectCardCoroutine: SelectCardCoroutine,
  340. afterSelectCardCoroutine: null,
  341. message: "Select 1 [Quartzmon] to digivolve from digivolution cards.",
  342. maxCount: maxCount,
  343. canEndNotMax: false,
  344. isShowOpponent: true,
  345. mode: SelectCardEffect.Mode.Custom,
  346. root: SelectCardEffect.Root.Custom,
  347. customRootCardList: selectedPermanent.DigivolutionCards,
  348. canLookReverseCard: true,
  349. selectPlayer: card.Owner,
  350. cardEffect: activateClass);
  351. selectCardEffect.SetUpCustomMessage(
  352. "Select 1 [Quartzmon] to digivolve from digivolution cards.",
  353. "The opponent is selecting 1 [Quartzmon] to digivolve from digivolution cards.");
  354. selectCardEffect.SetUpCustomMessage_ShowCard("Played Card");
  355. yield return StartCoroutine(selectCardEffect.Activate());
  356. IEnumerator SelectCardCoroutine(CardSource cardSource)
  357. {
  358. selectedCards.Add(cardSource);
  359. cardSource.willBeRemoveSources = true;
  360. yield return null;
  361. }
  362. yield return ContinuousController.instance.StartCoroutine(new PlayCardClass(
  363. cardSources: selectedCards,
  364. hashtable: CardEffectCommons.CardEffectHashtable(activateClass),
  365. payCost: true,
  366. targetPermanent: card.PermanentOfThisCard(),
  367. isTapped: false,
  368. root: SelectCardEffect.Root.DigivolutionCards,
  369. activateETB: true).PlayCard());
  370. }
  371. }
  372. }
  373. }
  374. }
  375. #region End Cost Reduction
  376. card.Owner.UntilCalculateFixedCostEffect.Remove(getCardEffect);
  377. #endregion
  378. }
  379. else
  380. {
  381. if (card.Owner.GetBattleAreaPermanents().Count(CanSelectPermanentCondition) >= 1)
  382. {
  383. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  384. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  385. selectPermanentEffect.SetUp(
  386. selectPlayer: card.Owner,
  387. canTargetCondition: CanSelectPermanentCondition,
  388. canTargetCondition_ByPreSelecetedList: null,
  389. canEndSelectCondition: null,
  390. maxCount: maxCount,
  391. canNoSelect: true,
  392. canEndNotMax: false,
  393. selectPermanentCoroutine: SelectPermanentCoroutine,
  394. afterSelectPermanentCoroutine: null,
  395. mode: SelectPermanentEffect.Mode.Custom,
  396. cardEffect: activateClass);
  397. selectPermanentEffect.SetUpCustomMessage("Select 1 Tamer which has digivolution cards.", "The opponent is selecting 1 Tamer which has digivolution cards.");
  398. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  399. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  400. {
  401. Permanent selectedPermanent = permanent;
  402. if (selectedPermanent != null)
  403. {
  404. if (selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition) >= 1)
  405. {
  406. maxCount = Math.Min(1, selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition));
  407. List<CardSource> selectedCards = new List<CardSource>();
  408. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  409. selectCardEffect.SetUp(
  410. canTargetCondition: CanSelectCardCondition,
  411. canTargetCondition_ByPreSelecetedList: null,
  412. canEndSelectCondition: null,
  413. canNoSelect: () => true,
  414. selectCardCoroutine: SelectCardCoroutine,
  415. afterSelectCardCoroutine: null,
  416. message: "Select 1 digivolution card to play.",
  417. maxCount: maxCount,
  418. canEndNotMax: false,
  419. isShowOpponent: true,
  420. mode: SelectCardEffect.Mode.Custom,
  421. root: SelectCardEffect.Root.Custom,
  422. customRootCardList: selectedPermanent.DigivolutionCards,
  423. canLookReverseCard: true,
  424. selectPlayer: card.Owner,
  425. cardEffect: activateClass);
  426. selectCardEffect.SetUpCustomMessage("Select 1 digivolution card to play.", "The opponent is selecting 1 digivolution card to play.");
  427. selectCardEffect.SetUpCustomMessage_ShowCard("Played Card");
  428. yield return StartCoroutine(selectCardEffect.Activate());
  429. IEnumerator SelectCardCoroutine(CardSource cardSource)
  430. {
  431. selectedCards.Add(cardSource);
  432. yield return null;
  433. }
  434. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(
  435. cardSources: selectedCards,
  436. activateClass: activateClass,
  437. payCost: false,
  438. isTapped: false,
  439. root: SelectCardEffect.Root.DigivolutionCards,
  440. activateETB: true));
  441. }
  442. }
  443. }
  444. }
  445. }
  446. }
  447. }
  448. }
  449. if (timing == EffectTiming.OnAllyAttack)
  450. {
  451. ActivateClass activateClass = new ActivateClass();
  452. activateClass.SetUpICardEffect("Draw 1", CanUseCondition, card);
  453. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, false, EffectDiscription());
  454. activateClass.SetIsInheritedEffect(true);
  455. activateClass.SetHashString("Draw1_BT12_081");
  456. cardEffects.Add(activateClass);
  457. string EffectDiscription()
  458. {
  459. return "[When Attacking][Once Per Turn] If this Digimon has <Save> in its text, <Draw 1>. (Draw 1 card from your deck.)";
  460. }
  461. bool CanUseCondition(Hashtable hashtable)
  462. {
  463. return CardEffectCommons.CanTriggerOnAttack(hashtable, card);
  464. }
  465. bool CanActivateCondition(Hashtable hashtable)
  466. {
  467. if (CardEffectCommons.IsExistOnBattleArea(card))
  468. {
  469. if (card.PermanentOfThisCard().TopCard.HasSaveText)
  470. {
  471. return true;
  472. }
  473. }
  474. return false;
  475. }
  476. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  477. {
  478. yield return ContinuousController.instance.StartCoroutine(new DrawClass(card.Owner, 1, activateClass).Draw());
  479. }
  480. }
  481. return cardEffects;
  482. }
  483. }
  484. }