BT18_097.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace DCGO.CardEffects.BT18
  6. {
  7. public class BT18_097 : CEntity_Effect
  8. {
  9. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  10. {
  11. List<ICardEffect> cardEffects = new List<ICardEffect>();
  12. #region Main Effect
  13. if (timing == EffectTiming.OptionSkill)
  14. {
  15. List<string> selectedNames = new List<string>();
  16. ActivateClass activateClass = new ActivateClass();
  17. activateClass.SetUpICardEffect(card.BaseENGCardNameFromEntity, CanUseCondition, card);
  18. activateClass.SetUpActivateClass(null, ActivateCoroutine, -1, false, EffectDescription());
  19. cardEffects.Add(activateClass);
  20. string EffectDescription()
  21. {
  22. return
  23. "[Main] You may place up to 5 [Hybrid] trait cards with different names from your hand or trash under 1 of your Tamers. Then, 1 of your Tamers with 5 or more cards under it may digivolve into [MagnaGarurumon] in the hand or trash, ignoring digivolution requirements and without paying the cost.";
  24. }
  25. bool CanTargetCondition_ByPreSelecetedList(List<CardSource> cardSources, CardSource cardSource)
  26. {
  27. List<string> cardNames = GetNamesList(cardSources);
  28. foreach (string name in cardNames)
  29. {
  30. if (cardSource.CardNames.Contains(name))
  31. return false;
  32. }
  33. return true;
  34. }
  35. List<string> GetNamesList(List<CardSource> cardSources)
  36. {
  37. foreach (CardSource cardName in cardSources)
  38. {
  39. foreach (string name in cardName.CardNames)
  40. {
  41. if (!selectedNames.Contains(name))
  42. {
  43. selectedNames.Add(name);
  44. }
  45. }
  46. }
  47. return selectedNames;
  48. }
  49. bool CanUseCondition(Hashtable hashtable)
  50. {
  51. return CardEffectCommons.CanTriggerOptionMainEffect(hashtable, card);
  52. }
  53. bool CanSelectOwnTamerPermanentCondition(Permanent permanent)
  54. {
  55. return CardEffectCommons.IsPermanentExistsOnOwnerBattleArea(permanent, card) && permanent.IsTamer;
  56. }
  57. bool SelectHybridCardCondition(CardSource cardSource)
  58. {
  59. return cardSource.ContainsTraits("Hybrid");
  60. }
  61. bool DigivolveFromPermanentCondition(Permanent permanent)
  62. {
  63. return CardEffectCommons.IsPermanentExistsOnOwnerBattleArea(permanent, card) &&
  64. permanent.IsTamer && permanent.DigivolutionCards.Count >= 5 &&
  65. (card.Owner.HandCards.Where(DigivolveToCardCondition).Any(cardSource =>
  66. cardSource.CanPlayCardTargetFrame(permanent.PermanentFrame, false, activateClass, ignore: CardEffectCommons.IgnoreRequirement.All)) ||
  67. card.Owner.TrashCards.Where(DigivolveToCardCondition).Any(cardSource =>
  68. cardSource.CanPlayCardTargetFrame(permanent.PermanentFrame, false, activateClass, SelectCardEffect.Root.Trash, ignore: CardEffectCommons.IgnoreRequirement.All)));
  69. }
  70. bool DigivolveToCardCondition(CardSource cardSource)
  71. {
  72. return cardSource.EqualsCardName("MagnaGarurumon");
  73. }
  74. IEnumerator ActivateCoroutine(Hashtable hashtable)
  75. {
  76. // Place Hybrid cards under Tamer
  77. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectOwnTamerPermanentCondition))
  78. {
  79. Permanent tamerPermanent = null;
  80. SelectPermanentEffect selectPermanentEffect =
  81. GManager.instance.GetComponent<SelectPermanentEffect>();
  82. selectPermanentEffect.SetUp(
  83. selectPlayer: card.Owner,
  84. canTargetCondition: CanSelectOwnTamerPermanentCondition,
  85. canTargetCondition_ByPreSelecetedList: null,
  86. canEndSelectCondition: null,
  87. maxCount: 1,
  88. canNoSelect: true,
  89. canEndNotMax: false,
  90. selectPermanentCoroutine: SelectPermanentCoroutine1,
  91. afterSelectPermanentCoroutine: null,
  92. mode: SelectPermanentEffect.Mode.Custom,
  93. cardEffect: activateClass);
  94. selectPermanentEffect.SetUpCustomMessage(
  95. "Select 1 of your Tamers that will add digivolution cards.",
  96. "The opponent is selecting 1 of their Tamers that will add digivolution cards.");
  97. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  98. IEnumerator SelectPermanentCoroutine1(Permanent selectedPermanent)
  99. {
  100. tamerPermanent = selectedPermanent;
  101. yield return null;
  102. }
  103. if (tamerPermanent != null)
  104. {
  105. List<CardSource> digivolutionCards = new List<CardSource>();
  106. if (CardEffectCommons.HasMatchConditionOwnersHand(card, SelectHybridCardCondition))
  107. {
  108. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  109. selectHandEffect.SetUp(
  110. selectPlayer: card.Owner,
  111. canTargetCondition: SelectHybridCardCondition,
  112. canTargetCondition_ByPreSelecetedList: CanTargetCondition_ByPreSelecetedList,
  113. canEndSelectCondition: null,
  114. maxCount: Math.Min(5,
  115. CardEffectCommons.MatchConditionOwnersCardCountInHand(card, SelectHybridCardCondition)),
  116. canNoSelect: true,
  117. canEndNotMax: true,
  118. isShowOpponent: true,
  119. selectCardCoroutine: null,
  120. afterSelectCardCoroutine: SelectCardCoroutine,
  121. mode: SelectHandEffect.Mode.Custom,
  122. cardEffect: activateClass);
  123. selectHandEffect.SetUpCustomMessage("Select cards in hand to place in digivolution cards.",
  124. "The opponent is selecting cards in hand to place in digivolution cards.");
  125. yield return StartCoroutine(selectHandEffect.Activate());
  126. }
  127. if (CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, SelectHybridCardCondition))
  128. {
  129. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  130. selectCardEffect.SetUp(
  131. canTargetCondition: SelectHybridCardCondition,
  132. canTargetCondition_ByPreSelecetedList: CanTargetCondition_ByPreSelecetedList,
  133. canEndSelectCondition: null,
  134. canNoSelect: () => true,
  135. selectCardCoroutine: null,
  136. afterSelectCardCoroutine: SelectCardCoroutine,
  137. message: "Select cards in trash to place in digivolution cards.",
  138. maxCount: Math.Min(5 - digivolutionCards.Count,
  139. CardEffectCommons.MatchConditionOwnersCardCountInTrash(card, SelectHybridCardCondition)),
  140. canEndNotMax: true,
  141. isShowOpponent: true,
  142. mode: SelectCardEffect.Mode.Custom,
  143. root: SelectCardEffect.Root.Trash,
  144. customRootCardList: null,
  145. canLookReverseCard: true,
  146. selectPlayer: card.Owner,
  147. cardEffect: activateClass);
  148. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  149. }
  150. IEnumerator SelectCardCoroutine(List<CardSource> cardSources)
  151. {
  152. digivolutionCards.AddRange(cardSources);
  153. yield return null;
  154. }
  155. if (digivolutionCards.Count >= 1)
  156. {
  157. List<CardSource> digivolutionCardsFixed = new List<CardSource>();
  158. if (digivolutionCards.Count == 1)
  159. {
  160. digivolutionCardsFixed.AddRange(digivolutionCards);
  161. }
  162. else
  163. {
  164. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  165. selectCardEffect.SetUp(
  166. canTargetCondition: _ => true,
  167. canTargetCondition_ByPreSelecetedList: null,
  168. canEndSelectCondition: null,
  169. canNoSelect: () => false,
  170. selectCardCoroutine: null,
  171. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  172. message:
  173. "Specify the order to place the cards on the bottom of the digivolution cards\n(cards will be placed so that cards with lower numbers are on top).",
  174. maxCount: digivolutionCards.Count,
  175. canEndNotMax: false,
  176. isShowOpponent: false,
  177. mode: SelectCardEffect.Mode.Custom,
  178. root: SelectCardEffect.Root.Custom,
  179. customRootCardList: digivolutionCards,
  180. canLookReverseCard: true,
  181. selectPlayer: card.Owner,
  182. cardEffect: activateClass);
  183. selectCardEffect.SetUpCustomMessage_ShowCard("Digivolution Cards");
  184. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  185. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  186. {
  187. digivolutionCardsFixed.AddRange(cardSources);
  188. yield return null;
  189. }
  190. }
  191. if (CardEffectCommons.IsPermanentExistsOnBattleArea(tamerPermanent))
  192. {
  193. yield return ContinuousController.instance.StartCoroutine(tamerPermanent
  194. .AddDigivolutionCardsBottom(digivolutionCardsFixed, activateClass));
  195. }
  196. }
  197. }
  198. }
  199. // Digivolve
  200. if (CardEffectCommons.HasMatchConditionPermanent(DigivolveFromPermanentCondition))
  201. {
  202. Permanent selectedPermanent = null;
  203. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  204. selectPermanentEffect.SetUp(
  205. selectPlayer: card.Owner,
  206. canTargetCondition: DigivolveFromPermanentCondition,
  207. canTargetCondition_ByPreSelecetedList: null,
  208. canEndSelectCondition: null,
  209. maxCount: 1,
  210. canNoSelect: false,
  211. canEndNotMax: false,
  212. selectPermanentCoroutine: SelectPermanentCoroutine,
  213. afterSelectPermanentCoroutine: null,
  214. mode: SelectPermanentEffect.Mode.Custom,
  215. cardEffect: activateClass);
  216. selectPermanentEffect.SetUpCustomMessage("Select 1 Tamer that will digivolve.",
  217. "The opponent is selecting 1 Tamer that will digivolve.");
  218. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  219. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  220. {
  221. selectedPermanent = permanent;
  222. yield return null;
  223. }
  224. if (selectedPermanent != null)
  225. {
  226. bool canSelectHand = CardEffectCommons.HasMatchConditionOwnersHand(card, DigivolveToCardCondition);
  227. bool canSelectTrash = CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, DigivolveToCardCondition);
  228. if (canSelectHand || canSelectTrash)
  229. {
  230. if (canSelectHand && canSelectTrash)
  231. {
  232. List<SelectionElement<bool>> selectionElements = new List<SelectionElement<bool>>
  233. {
  234. new(message: "From hand", value: true, spriteIndex: 0),
  235. new(message: "From trash", value: false, spriteIndex: 1),
  236. };
  237. string selectPlayerMessage = "From which area do you digivolve?";
  238. string notSelectPlayerMessage = "The opponent is choosing from which area to digivolve.";
  239. GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: selectionElements,
  240. selectPlayer: card.Owner, selectPlayerMessage: selectPlayerMessage,
  241. notSelectPlayerMessage: notSelectPlayerMessage);
  242. }
  243. else
  244. {
  245. GManager.instance.userSelectionManager.SetBool(canSelectHand);
  246. }
  247. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager
  248. .WaitForEndSelect());
  249. bool fromHand = GManager.instance.userSelectionManager.SelectedBoolValue;
  250. yield return ContinuousController.instance.StartCoroutine(
  251. CardEffectCommons.DigivolveIntoHandOrTrashCard(
  252. targetPermanent: selectedPermanent,
  253. cardCondition: DigivolveToCardCondition,
  254. payCost: false,
  255. reduceCostTuple: null,
  256. fixedCostTuple: null,
  257. ignoreDigivolutionRequirementFixedCost: 0,
  258. isHand: fromHand,
  259. activateClass: activateClass,
  260. successProcess: null));
  261. }
  262. }
  263. }
  264. }
  265. }
  266. #endregion
  267. #region Security Effect
  268. if (timing == EffectTiming.SecuritySkill)
  269. {
  270. ActivateClass activateClass = new ActivateClass();
  271. activateClass.SetUpICardEffect($"Play 1 Tamer card with an inherited effect from hand or trash and add this card to hand",
  272. CanUseCondition, card);
  273. activateClass.SetUpActivateClass(null, ActivateCoroutine, -1, false, EffectDescription());
  274. activateClass.SetIsSecurityEffect(true);
  275. cardEffects.Add(activateClass);
  276. string EffectDescription()
  277. {
  278. return
  279. "[Security] You may play 1 Tamer card with an inherited effect from your hand or trash without paying the cost. Then, add this card to the hand.";
  280. }
  281. bool CanUseCondition(Hashtable hashtable)
  282. {
  283. return CardEffectCommons.CanTriggerSecurityEffect(hashtable, card);
  284. }
  285. bool CanSelectCardCondition(CardSource cardSource)
  286. {
  287. if (CardEffectCommons.CanPlayAsNewPermanent(cardSource: cardSource, payCost: false, cardEffect: activateClass))
  288. {
  289. return cardSource.IsTamer && cardSource.HasInheritedEffect;
  290. }
  291. return false;
  292. }
  293. IEnumerator ActivateCoroutine(Hashtable hashtable)
  294. {
  295. bool canSelectHand = CardEffectCommons.HasMatchConditionOwnersHand(card, CanSelectCardCondition);
  296. bool canSelectTrash = CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, CanSelectCardCondition);
  297. if (canSelectHand || canSelectTrash)
  298. {
  299. if (canSelectHand && canSelectTrash)
  300. {
  301. List<SelectionElement<bool>> selectionElements = new List<SelectionElement<bool>>
  302. {
  303. new(message: "From hand", value: true, spriteIndex: 0),
  304. new(message: "From trash", value: false, spriteIndex: 1),
  305. };
  306. string selectPlayerMessage = "From which area do you play a card?";
  307. string notSelectPlayerMessage = "The opponent is choosing from which area to play a card.";
  308. GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: selectionElements,
  309. selectPlayer: card.Owner, selectPlayerMessage: selectPlayerMessage,
  310. notSelectPlayerMessage: notSelectPlayerMessage);
  311. }
  312. else
  313. {
  314. GManager.instance.userSelectionManager.SetBool(canSelectHand);
  315. }
  316. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager
  317. .WaitForEndSelect());
  318. bool fromHand = GManager.instance.userSelectionManager.SelectedBoolValue;
  319. List<CardSource> selectedCards = new List<CardSource>();
  320. IEnumerator SelectCardCoroutine(CardSource cardSource)
  321. {
  322. selectedCards.Add(cardSource);
  323. yield return null;
  324. }
  325. if (fromHand)
  326. {
  327. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  328. selectHandEffect.SetUp(
  329. selectPlayer: card.Owner,
  330. canTargetCondition: CanSelectCardCondition,
  331. canTargetCondition_ByPreSelecetedList: null,
  332. canEndSelectCondition: null,
  333. maxCount: 1,
  334. canNoSelect: true,
  335. canEndNotMax: false,
  336. isShowOpponent: true,
  337. selectCardCoroutine: SelectCardCoroutine,
  338. afterSelectCardCoroutine: null,
  339. mode: SelectHandEffect.Mode.Custom,
  340. cardEffect: activateClass);
  341. selectHandEffect.SetUpCustomMessage("Select 1 card to play.", "The opponent is selecting 1 card to play.");
  342. selectHandEffect.SetUpCustomMessage_ShowCard("Played Card");
  343. yield return StartCoroutine(selectHandEffect.Activate());
  344. }
  345. else
  346. {
  347. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  348. selectCardEffect.SetUp(
  349. canTargetCondition: CanSelectCardCondition,
  350. canTargetCondition_ByPreSelecetedList: null,
  351. canEndSelectCondition: null,
  352. canNoSelect: () => true,
  353. selectCardCoroutine: SelectCardCoroutine,
  354. afterSelectCardCoroutine: null,
  355. message: "Select 1 card to play.",
  356. maxCount: 1,
  357. canEndNotMax: false,
  358. isShowOpponent: true,
  359. mode: SelectCardEffect.Mode.Custom,
  360. root: SelectCardEffect.Root.Trash,
  361. customRootCardList: null,
  362. canLookReverseCard: true,
  363. selectPlayer: card.Owner,
  364. cardEffect: activateClass);
  365. selectCardEffect.SetUpCustomMessage("Select 1 card to play.", "The opponent is selecting 1 card to play.");
  366. selectCardEffect.SetUpCustomMessage_ShowCard("Played Card");
  367. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  368. }
  369. SelectCardEffect.Root root = SelectCardEffect.Root.Hand;
  370. if (!fromHand)
  371. {
  372. root = SelectCardEffect.Root.Trash;
  373. }
  374. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(
  375. cardSources: selectedCards, activateClass: activateClass, payCost: false, isTapped: false, root: root,
  376. activateETB: true));
  377. }
  378. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.AddThisCardToHand(card, activateClass));
  379. }
  380. }
  381. #endregion
  382. return cardEffects;
  383. }
  384. }
  385. }