Apocalymon_BT15_102.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System;
  5. using System.Reflection;
  6. using UnityEngine;
  7. public class Apocalymon_BT15_102 : CEntity_Effect
  8. {
  9. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  10. {
  11. List<ICardEffect> cardEffects = new List<ICardEffect>();
  12. #region Before Pay Cost - Condition Effect
  13. if (timing == EffectTiming.BeforePayCost)
  14. {
  15. ActivateClass activateClass = new ActivateClass();
  16. activateClass.SetUpICardEffect("Placing 1 [Dark Masters] to get Play Cost -4", CanUseCondition, card);
  17. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDiscription());
  18. activateClass.SetHashString("PlayCost-12_BT15_102");
  19. cardEffects.Add(activateClass);
  20. string EffectDiscription()
  21. {
  22. return "When this card would be played, by placing up to 3 [Dark Masters] trait cards with different names from your battle area or trash under it, reduce the play cost by 4 for each one.";
  23. }
  24. bool CanSelectCardCondition(CardSource cardSource)
  25. {
  26. if (cardSource.IsDigimon)
  27. {
  28. if (cardSource.CardTraits.Contains("Dark Masters") || cardSource.CardTraits.Contains("DarkMasters"))
  29. {
  30. return true;
  31. }
  32. }
  33. return false;
  34. }
  35. bool CardCondition(CardSource cardSource)
  36. {
  37. if (cardSource == card)
  38. {
  39. if (CardEffectCommons.IsExistOnHand(cardSource))
  40. {
  41. return true;
  42. }
  43. }
  44. return false;
  45. }
  46. bool CanNoSelect(CardSource cardSource)
  47. {
  48. if (cardSource != null)
  49. {
  50. if (cardSource.PayingCost(SelectCardEffect.Root.Hand, null, checkAvailability: false) > cardSource.Owner.MaxMemoryCost)
  51. {
  52. return false;
  53. }
  54. }
  55. return true;
  56. }
  57. bool CanUseCondition(Hashtable hashtable)
  58. {
  59. if (CardEffectCommons.CanTriggerWhenPermanentWouldPlay(hashtable, CardCondition))
  60. {
  61. return true;
  62. }
  63. return false;
  64. }
  65. bool CanActivateCondition(Hashtable hashtable)
  66. {
  67. if (CardEffectCommons.IsExistOnHand(card))
  68. {
  69. if (CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, CanSelectCardCondition))
  70. {
  71. return true;
  72. }
  73. }
  74. return false;
  75. }
  76. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  77. {
  78. List<CardSource> digivolutionCards = new List<CardSource>();
  79. bool CanSelectTrashCardCondition(CardSource cardSource)
  80. {
  81. if (CanSelectCardCondition(cardSource))
  82. {
  83. if (digivolutionCards.Count((filteredCard) => filteredCard.CardID == cardSource.CardID) == 0)
  84. {
  85. return true;
  86. }
  87. }
  88. return false;
  89. }
  90. if (CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, (cardSource) => CanSelectTrashCardCondition(cardSource)))
  91. {
  92. bool noSelect = CanNoSelect(CardEffectCommons.GetCardFromHashtable(_hashtable));
  93. List<CardSource> selectedCards = new List<CardSource>();
  94. int maxCount = Math.Min(3 - digivolutionCards.Count, card.Owner.TrashCards.Count((cardSource) => CanSelectTrashCardCondition(cardSource)));
  95. if (maxCount >= 1)
  96. {
  97. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  98. selectCardEffect.SetUp(
  99. canTargetCondition: CanSelectTrashCardCondition,
  100. canTargetCondition_ByPreSelecetedList: CanTargetCondition_ByPreSelecetedList,
  101. canEndSelectCondition: CanEndSelectCondition,
  102. canNoSelect: () => noSelect,
  103. selectCardCoroutine: SelectCardCoroutine,
  104. afterSelectCardCoroutine: null,
  105. message: "Select cards to place in Digivolution cards.",
  106. maxCount: maxCount,
  107. canEndNotMax: true,
  108. isShowOpponent: true,
  109. mode: SelectCardEffect.Mode.Custom,
  110. root: SelectCardEffect.Root.Trash,
  111. customRootCardList: null,
  112. canLookReverseCard: true,
  113. selectPlayer: card.Owner,
  114. cardEffect: activateClass);
  115. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  116. bool CanTargetCondition_ByPreSelecetedList(List<CardSource> cardSources, CardSource cardSource)
  117. {
  118. List<string> cardIDs = new List<string>();
  119. foreach (CardSource cardSource1 in cardSources)
  120. {
  121. if (!cardIDs.Contains(cardSource1.CardID))
  122. {
  123. cardIDs.Add(cardSource1.CardID);
  124. }
  125. }
  126. foreach (CardSource cardSource1 in digivolutionCards)
  127. {
  128. if (!cardIDs.Contains(cardSource1.CardID))
  129. {
  130. cardIDs.Add(cardSource1.CardID);
  131. }
  132. }
  133. if (cardIDs.Contains(cardSource.CardID))
  134. {
  135. return false;
  136. }
  137. return true;
  138. }
  139. bool CanEndSelectCondition(List<CardSource> cardSources)
  140. {
  141. List<string> cardIDs = new List<string>();
  142. foreach (CardSource cardSource1 in cardSources)
  143. {
  144. if (!cardIDs.Contains(cardSource1.CardID))
  145. {
  146. cardIDs.Add(cardSource1.CardID);
  147. }
  148. }
  149. foreach (CardSource cardSource1 in digivolutionCards)
  150. {
  151. if (!cardIDs.Contains(cardSource1.CardID))
  152. {
  153. cardIDs.Add(cardSource1.CardID);
  154. }
  155. }
  156. if (cardIDs.Count != cardSources.Count + digivolutionCards.Count)
  157. {
  158. return false;
  159. }
  160. return true;
  161. }
  162. IEnumerator SelectCardCoroutine(CardSource cardSource)
  163. {
  164. selectedCards.Add(cardSource);
  165. digivolutionCards.Add(cardSource);
  166. yield return null;
  167. }
  168. if (selectedCards.Count >= 1)
  169. {
  170. GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutionCardInfos(new AddDigivolutionCardsInfo(activateClass, selectedCards));
  171. yield return StartCoroutine(AfterSelectCardCoroutine(selectedCards));
  172. }
  173. }
  174. }
  175. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  176. {
  177. if (card.Owner.CanReduceCost(null, card))
  178. {
  179. ContinuousController.instance.PlaySE(GManager.instance.GetComponent<Effects>().BuffSE);
  180. }
  181. ChangeCostClass changeCostClass = new ChangeCostClass();
  182. changeCostClass.SetUpICardEffect("Play Cost -4", CanUseCondition1, card);
  183. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardSourceCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  184. card.Owner.UntilCalculateFixedCostEffect.Add((_timing) => changeCostClass);
  185. bool CanUseCondition1(Hashtable hashtable)
  186. {
  187. return true;
  188. }
  189. int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  190. {
  191. if (CardSourceCondition(cardSource))
  192. {
  193. if (RootCondition(root))
  194. {
  195. if (PermanentsCondition(targetPermanents))
  196. {
  197. Cost -= cardSources.Count * 4;
  198. }
  199. }
  200. }
  201. return Cost;
  202. }
  203. bool PermanentsCondition(List<Permanent> targetPermanents)
  204. {
  205. if (targetPermanents == null)
  206. {
  207. return true;
  208. }
  209. else
  210. {
  211. if (targetPermanents.Count((targetPermanent) => targetPermanent != null) == 0)
  212. {
  213. return true;
  214. }
  215. }
  216. return false;
  217. }
  218. bool CardSourceCondition(CardSource cardSource)
  219. {
  220. return cardSource == card;
  221. }
  222. bool RootCondition(SelectCardEffect.Root root)
  223. {
  224. return true;
  225. }
  226. bool isUpDown()
  227. {
  228. return true;
  229. }
  230. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.ShowReducedCost(_hashtable));
  231. yield return null;
  232. }
  233. }
  234. }
  235. #endregion
  236. #region Reduce Play Cost - Not Shown
  237. if (timing == EffectTiming.None)
  238. {
  239. ChangeCostClass changeCostClass = new ChangeCostClass();
  240. changeCostClass.SetUpICardEffect("Play Cost -4", CanUseCondition, card);
  241. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardSourceCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => true, isChangePayingCost: () => true);
  242. changeCostClass.SetNotShowUI(true);
  243. cardEffects.Add(changeCostClass);
  244. bool CanSelectCardCondition(CardSource cardSource)
  245. {
  246. if (cardSource.IsDigimon)
  247. {
  248. if (cardSource.CardTraits.Contains("Dark Masters") || cardSource.CardTraits.Contains("DarkMasters"))
  249. {
  250. return true;
  251. }
  252. }
  253. return false;
  254. }
  255. bool CanUseCondition(Hashtable hashtable)
  256. {
  257. if (card.Owner.HandCards.Contains(card))
  258. {
  259. ICardEffect activateClass = card.EffectList(EffectTiming.BeforePayCost).Find(cardEffect => cardEffect.EffectName == "Placing 1 [Dark Masters] to get Play Cost -4");
  260. if (activateClass != null)
  261. {
  262. if (CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, CanSelectCardCondition))
  263. {
  264. return true;
  265. }
  266. }
  267. }
  268. return false;
  269. }
  270. int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  271. {
  272. if (CardSourceCondition(cardSource))
  273. {
  274. if (RootCondition(root))
  275. {
  276. if (PermanentsCondition(targetPermanents))
  277. {
  278. List<CardSource> trashSources = card.Owner.TrashCards.Filter(CanSelectCardCondition);
  279. int targetCount = (from trashCard in trashSources select trashCard.CardID).Distinct().Count();
  280. Cost -= targetCount * 4;
  281. }
  282. }
  283. }
  284. return Cost;
  285. }
  286. bool PermanentsCondition(List<Permanent> targetPermanents)
  287. {
  288. if (targetPermanents == null)
  289. {
  290. return true;
  291. }
  292. else
  293. {
  294. if (targetPermanents.Count((targetPermanent) => targetPermanent != null) == 0)
  295. {
  296. return true;
  297. }
  298. }
  299. return false;
  300. }
  301. bool CardSourceCondition(CardSource cardSource)
  302. {
  303. if (cardSource != null)
  304. {
  305. if (cardSource == card)
  306. {
  307. return true;
  308. }
  309. }
  310. return false;
  311. }
  312. bool RootCondition(SelectCardEffect.Root root)
  313. {
  314. return true;
  315. }
  316. bool isUpDown()
  317. {
  318. return true;
  319. }
  320. }
  321. #endregion
  322. #region End of Your Turn
  323. if (timing == EffectTiming.OnEndTurn)
  324. {
  325. ActivateClass activateClass = new ActivateClass();
  326. activateClass.SetUpICardEffect("Place 1 digimon from trash under this Digimon's digivolution cards", CanUseCondition, card);
  327. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDiscription());
  328. cardEffects.Add(activateClass);
  329. string EffectDiscription()
  330. {
  331. return "[End of Your Turn] [Once Per Turn] By placing 1 level 6 or lower card from your trash as this Digimon's bottom digivolution card, activate 1 [On Play] effect on that card as an effect. Then, trash the top 2 cards of your opponent's deck for each of this Digimon's level 6 digivolution cards.";
  332. }
  333. bool CanSelectCardCondition(CardSource cardSource)
  334. {
  335. if (cardSource.IsDigimon)
  336. {
  337. if (cardSource.HasLevel)
  338. {
  339. if(cardSource.Level <= 6)
  340. {
  341. return true;
  342. }
  343. }
  344. }
  345. return false;
  346. }
  347. bool CanUseCondition(Hashtable hashtable)
  348. {
  349. if (CardEffectCommons.IsExistOnBattleArea(card))
  350. {
  351. if (CardEffectCommons.IsOwnerTurn(card))
  352. {
  353. return true;
  354. }
  355. }
  356. return false;
  357. }
  358. bool CanActivateCondition(Hashtable hashtable)
  359. {
  360. if (CardEffectCommons.IsExistOnBattleArea(card))
  361. {
  362. if (CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, CanSelectCardCondition))
  363. {
  364. return true;
  365. }
  366. }
  367. return false;
  368. }
  369. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  370. {
  371. if (CardEffectCommons.IsExistOnBattleArea(card))
  372. {
  373. if (CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, CanSelectCardCondition))
  374. {
  375. int maxCount = Math.Min(1, card.Owner.TrashCards.Count((cardSource) => CanSelectCardCondition(cardSource)));
  376. List<CardSource> selectedCards = new List<CardSource>();
  377. IEnumerator SelectCardCoroutine(CardSource cardSource)
  378. {
  379. selectedCards.Add(cardSource);
  380. yield return null;
  381. }
  382. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  383. selectCardEffect.SetUp(
  384. canTargetCondition: CanSelectCardCondition,
  385. canTargetCondition_ByPreSelecetedList: null,
  386. canEndSelectCondition: null,
  387. canNoSelect: () => true,
  388. selectCardCoroutine: SelectCardCoroutine,
  389. afterSelectCardCoroutine: null,
  390. message: "Select 1 card to place on bottom of digivolution cards.",
  391. maxCount: maxCount,
  392. canEndNotMax: false,
  393. isShowOpponent: true,
  394. mode: SelectCardEffect.Mode.Custom,
  395. root: SelectCardEffect.Root.Trash,
  396. customRootCardList: null,
  397. canLookReverseCard: true,
  398. selectPlayer: card.Owner,
  399. cardEffect: activateClass);
  400. selectCardEffect.SetUpCustomMessage(
  401. "Select 1 card to place on bottom of digivolution cards.",
  402. "The opponent is selecting 1 card to place on bottom of digivolution cards.");
  403. selectCardEffect.SetUpCustomMessage_ShowCard("Digivolution Card");
  404. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  405. CardSource selectedCard = null;
  406. if (selectedCards.Count >= 1)
  407. {
  408. if (CardEffectCommons.IsExistOnBattleArea(card))
  409. {
  410. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(
  411. selectedCards,
  412. activateClass));
  413. selectedCard = selectedCards[0];
  414. }
  415. }
  416. if (selectedCard != null)
  417. {
  418. List<ICardEffect> candidateEffects = selectedCard.EffectList_ForCard(EffectTiming.OnEnterFieldAnyone, card)
  419. .Clone()
  420. .Filter(cardEffect => cardEffect != null && cardEffect is ActivateICardEffect && !cardEffect.IsSecurityEffect && cardEffect.IsOnPlay);
  421. if (candidateEffects.Count >= 1)
  422. {
  423. ICardEffect selectedEffect = null;
  424. if (candidateEffects.Count == 1)
  425. {
  426. selectedEffect = candidateEffects[0];
  427. }
  428. else
  429. {
  430. List<SkillInfo> skillInfos = candidateEffects
  431. .Map(cardEffect => new SkillInfo(cardEffect, null, EffectTiming.None));
  432. List<CardSource> cardSources = candidateEffects
  433. .Map(cardEffect => cardEffect.EffectSourceCard);
  434. SelectCardEffect selectSourceCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  435. selectSourceCardEffect.SetUp(
  436. canTargetCondition: (cardSource) => true,
  437. canTargetCondition_ByPreSelecetedList: null,
  438. canEndSelectCondition: null,
  439. canNoSelect: () => false,
  440. selectCardCoroutine: null,
  441. afterSelectCardCoroutine: null,
  442. message: "Select 1 effect to activate.",
  443. maxCount: 1,
  444. canEndNotMax: false,
  445. isShowOpponent: false,
  446. mode: SelectCardEffect.Mode.Custom,
  447. root: SelectCardEffect.Root.Custom,
  448. customRootCardList: cardSources,
  449. canLookReverseCard: true,
  450. selectPlayer: card.Owner,
  451. cardEffect: activateClass);
  452. selectSourceCardEffect.SetNotShowCard();
  453. selectSourceCardEffect.SetUpSkillInfos(skillInfos);
  454. selectSourceCardEffect.SetUpAfterSelectIndexCoroutine(AfterSelectIndexCoroutine);
  455. yield return ContinuousController.instance.StartCoroutine(selectSourceCardEffect.Activate());
  456. IEnumerator AfterSelectIndexCoroutine(List<int> selectedIndexes)
  457. {
  458. if (selectedIndexes.Count == 1)
  459. {
  460. selectedEffect = candidateEffects[selectedIndexes[0]];
  461. yield return null;
  462. }
  463. }
  464. }
  465. if (selectedEffect != null)
  466. {
  467. Hashtable effectHashtable = CardEffectCommons.OnPlayCheckHashtableOfCard(card);
  468. if (selectedEffect.CanUse(effectHashtable))
  469. {
  470. yield return ContinuousController.instance.StartCoroutine(
  471. ((ActivateICardEffect)selectedEffect).Activate_Optional_Effect_Execute(effectHashtable));
  472. }
  473. }
  474. }
  475. }
  476. }
  477. }
  478. int trashCount = 2 * card.PermanentOfThisCard().cardSources.Filter(cardSource => cardSource != card && cardSource.HasLevel && cardSource.Level == 6).Count;
  479. yield return ContinuousController.instance.StartCoroutine(new IAddTrashCardsFromLibraryTop(trashCount, card.Owner.Enemy, activateClass).AddTrashCardsFromLibraryTop());
  480. }
  481. }
  482. #endregion
  483. return cardEffects;
  484. }
  485. }