BT25_089.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace DCGO.CardEffects.BT25
  6. {
  7. // Kazuki & Itsuki
  8. public class BT25_089 : CEntity_Effect
  9. {
  10. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  11. {
  12. List<ICardEffect> cardEffects = new List<ICardEffect>();
  13. #region Start of Your Main Phase
  14. if (timing == EffectTiming.OnStartMainPhase)
  15. {
  16. cardEffects.Add(CardEffectFactory.Gain1MemoryTamerOpponentDigimonEffect(card));
  17. }
  18. #endregion
  19. #region Main
  20. if (timing == EffectTiming.OnDeclaration)
  21. {
  22. ActivateClass activateClass = new ActivateClass();
  23. activateClass.SetUpICardEffect("Link for -2", CanUseCondition, card);
  24. activateClass.SetUpActivateClass(null, ActivateCoroutine, -1, false, EffectDescription());
  25. cardEffects.Add(activateClass);
  26. string EffectDescription()
  27. => "[Main] [Once Per Turn] You may link 1 [Appmon] trait Digimon card from your hand or your Digimon's digivolution cards to 1 of your Digimon with the cost reduced by 2.";
  28. bool CanUseCondition(Hashtable hashtable)
  29. {
  30. return CardEffectCommons.IsExistOnBattleArea(card)
  31. && CardEffectCommons.CanActivateSuspendCostEffect(card)
  32. && (CardEffectCommons.HasMatchConditionOwnersHand(card, CanLinkCardActivateCondition)
  33. || CardEffectCommons.HasMatchConditionPermanent(CanTakeFromDigivolutionCardsActivateCondition));
  34. }
  35. bool CanTakeFromDigivolutionCardsActivateCondition(Permanent permanent)
  36. {
  37. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card)
  38. && permanent.DigivolutionCards.Any(CanLinkCardActivateCondition);
  39. }
  40. bool CanLinkCardActivateCondition(CardSource cardSource) => CanLinkCardCondition(cardSource, false);
  41. bool CanLinkCardEffectCondition(CardSource cardSource) => CanLinkCardCondition(cardSource, true);
  42. bool CanLinkCardCondition(CardSource cardSource, bool payCost)
  43. {
  44. return cardSource.IsDigimon
  45. && cardSource.EqualsTraits("Appmon")
  46. && cardSource.CanLink(payCost);
  47. }
  48. bool CanTakeFromDigivolutionCardsEffectCondition(Permanent permanent)
  49. {
  50. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card)
  51. && permanent.DigivolutionCards.Any(CanLinkCardEffectCondition);
  52. }
  53. IEnumerator ActivateCoroutine(Hashtable hashtable)
  54. {
  55. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.SuspendPeremanentAndProcessAccordingToResult(
  56. new List<Permanent>() { card.PermanentOfThisCard() },
  57. activateClass,
  58. SuccessProcess,
  59. null));
  60. IEnumerator SuccessProcess(List<Permanent> suspendedPermaments)
  61. {
  62. #region Link Cost Reduction
  63. ICardEffect GetCardEffect(EffectTiming _timing)
  64. {
  65. if (_timing == EffectTiming.None)
  66. {
  67. return CardEffectFactory.GrantedReduceLinkCostClass(
  68. card: card,
  69. reducedCost: 2,
  70. cardSourceCondition: _ => true,
  71. permanentCondition: _ => true,
  72. rootCondition: _ => true
  73. );
  74. }
  75. return null;
  76. }
  77. card.Owner.UntilCalculateFixedCostEffect.Add(GetCardEffect);
  78. #endregion
  79. bool canSelectHand = CardEffectCommons.HasMatchConditionOwnersHand(card, CanLinkCardEffectCondition);
  80. bool canSelectSources = CardEffectCommons.HasMatchConditionPermanent(CanTakeFromDigivolutionCardsActivateCondition);
  81. List<SelectionElement<int>> selectionElements = new List<SelectionElement<int>>();
  82. if (canSelectHand)
  83. {
  84. selectionElements.Add(new SelectionElement<int>(message: $"From hand", value : 1, spriteIndex: 0));
  85. }
  86. if (canSelectSources)
  87. {
  88. selectionElements.Add(new SelectionElement<int>(message: $"From digivolution cards", value : 2, spriteIndex: 0));
  89. }
  90. selectionElements.Add(new SelectionElement<int>(message: $"Do not Link", value : 3, spriteIndex: 1));
  91. string selectPlayerMessage = "From which area will you link a card?";
  92. string notSelectPlayerMessage = "The opponent is choosing from which area to select a card.";
  93. GManager.instance.userSelectionManager.SetIntSelection(selectionElements: selectionElements, selectPlayer: card.Owner, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  94. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  95. bool doLink = GManager.instance.userSelectionManager.SelectedIntValue != 3;
  96. bool fromHand = GManager.instance.userSelectionManager.SelectedIntValue == 1;
  97. if (doLink)
  98. {
  99. if (fromHand)
  100. {
  101. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  102. selectHandEffect.SetUp(
  103. selectPlayer: card.Owner,
  104. canTargetCondition: CanLinkCardEffectCondition,
  105. canTargetCondition_ByPreSelecetedList: null,
  106. canEndSelectCondition: null,
  107. maxCount: 1,
  108. canNoSelect: true,
  109. canEndNotMax: false,
  110. isShowOpponent: true,
  111. selectCardCoroutine: SelectCardCoroutine,
  112. afterSelectCardCoroutine: null,
  113. mode: SelectHandEffect.Mode.Custom,
  114. cardEffect: activateClass);
  115. selectHandEffect.SetUpCustomMessage("Select 1 card to link.", "The opponent is selecting 1 card to link.");
  116. selectHandEffect.SetUpCustomMessage_ShowCard("Selected Card");
  117. yield return StartCoroutine(selectHandEffect.Activate());
  118. }
  119. else
  120. {
  121. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  122. selectPermanentEffect.SetUp(
  123. selectPlayer: card.Owner,
  124. canTargetCondition: CanTakeFromDigivolutionCardsEffectCondition,
  125. canTargetCondition_ByPreSelecetedList: null,
  126. canEndSelectCondition: null,
  127. maxCount: 1,
  128. canNoSelect: true,
  129. canEndNotMax: false,
  130. selectPermanentCoroutine: SelectPermanentCoroutine,
  131. afterSelectPermanentCoroutine: null,
  132. mode: SelectPermanentEffect.Mode.Custom,
  133. cardEffect: activateClass);
  134. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to select a digivolution card from", "The opponent is selecting 1 card to link.");
  135. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  136. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  137. {
  138. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  139. selectCardEffect.SetUp(
  140. canTargetCondition: CanLinkCardEffectCondition,
  141. canTargetCondition_ByPreSelecetedList: null,
  142. canEndSelectCondition: null,
  143. canNoSelect: () => true,
  144. selectCardCoroutine: SelectCardCoroutine,
  145. afterSelectCardCoroutine: null,
  146. message: "Select 1 card to add as source.",
  147. maxCount: 1,
  148. canEndNotMax: false,
  149. isShowOpponent: true,
  150. mode: SelectCardEffect.Mode.Custom,
  151. root: SelectCardEffect.Root.DigivolutionCards,
  152. customRootCardList: permanent.DigivolutionCards,
  153. canLookReverseCard: true,
  154. selectPlayer: card.Owner,
  155. cardEffect: activateClass);
  156. selectCardEffect.SetUpCustomMessage("Select 1 card to link.", "The opponent is selecting 1 card to link.");
  157. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Card");
  158. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  159. }
  160. }
  161. IEnumerator SelectCardCoroutine(CardSource cardSource)
  162. {
  163. bool CanLinkPermanentCondition(Permanent permanent)
  164. {
  165. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card)
  166. && cardSource.CanLinkToTargetPermanent(permanent, true);
  167. }
  168. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  169. selectPermanentEffect.SetUp(
  170. selectPlayer: card.Owner,
  171. canTargetCondition: CanLinkPermanentCondition,
  172. canTargetCondition_ByPreSelecetedList: null,
  173. canEndSelectCondition: null,
  174. maxCount: 1,
  175. canNoSelect: true,
  176. canEndNotMax: false,
  177. selectPermanentCoroutine: SelectPermanentCoroutine,
  178. afterSelectPermanentCoroutine: null,
  179. mode: SelectPermanentEffect.Mode.Custom,
  180. cardEffect: activateClass);
  181. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to link to.", "The opponent is selecting 1 digimon to link.");
  182. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  183. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  184. {
  185. yield return ContinuousController.instance.StartCoroutine(new ILinkCard(true, cardSource, permanent, activateClass).LinkCard());
  186. }
  187. }
  188. }
  189. #region Remove Link Cost Reduction
  190. card.Owner.UntilCalculateFixedCostEffect.Remove(GetCardEffect);
  191. #endregion
  192. }
  193. }
  194. }
  195. #endregion
  196. #region End of turn
  197. if (timing == EffectTiming.OnEndTurn)
  198. {
  199. ActivateClass activateClass = new ActivateClass();
  200. activateClass.SetUpICardEffect("App fuse 1 digimon into digimon in hand", CanUseCondition, card);
  201. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, false, EffectDescription());
  202. activateClass.SetHashString("BT25_089_AppFusion");
  203. activateClass.SetIsSkippable(true);
  204. cardEffects.Add(activateClass);
  205. string EffectDescription()
  206. {
  207. return "[End of Your Turn] [Once Per Turn] 1 of your Digimon may app fuse into a Digimon card in the hand.";
  208. }
  209. bool CanUseCondition(Hashtable hashtable)
  210. {
  211. return CardEffectCommons.IsExistOnBattleArea(card);
  212. }
  213. bool CanActivateCondition(Hashtable hashtable)
  214. {
  215. return CardEffectCommons.IsExistOnBattleArea(card)
  216. && CardEffectCommons.IsOwnerTurn(card);
  217. }
  218. bool CanSelectPermanent(Permanent permanent)
  219. {
  220. if (CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card))
  221. {
  222. foreach (CardSource hand in card.Owner.HandCards)
  223. {
  224. if (hand.appFusionCondition != null)
  225. {
  226. if (hand.CanAppFusionFromTargetPermanent(permanent, true))
  227. return true;
  228. }
  229. }
  230. }
  231. return false;
  232. }
  233. bool CanSelectCard(CardSource card, Permanent permanent)
  234. {
  235. if (CardEffectCommons.IsExistOnHand(card))
  236. {
  237. if (card.appFusionCondition != null)
  238. {
  239. if (card.CanAppFusionFromTargetPermanent(permanent, true))
  240. return true;
  241. }
  242. }
  243. return false;
  244. }
  245. IEnumerator ActivateCoroutine(Hashtable hashtable)
  246. {
  247. bool executed = false;
  248. if (CardEffectCommons.HasMatchConditionOwnersPermanent(card, CanSelectPermanent))
  249. {
  250. Permanent selectedPermanent = null;
  251. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionOwnersPermanentCount(card, CanSelectPermanent));
  252. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  253. selectPermanentEffect.SetUp(
  254. selectPlayer: card.Owner,
  255. canTargetCondition: CanSelectPermanent,
  256. canTargetCondition_ByPreSelecetedList: null,
  257. canEndSelectCondition: null,
  258. maxCount: maxCount,
  259. canNoSelect: true,
  260. canEndNotMax: false,
  261. selectPermanentCoroutine: SelectPermanentCoroutine,
  262. afterSelectPermanentCoroutine: null,
  263. mode: SelectPermanentEffect.Mode.Custom,
  264. cardEffect: activateClass);
  265. selectPermanentEffect.SetUpCustomMessage("Select 1 digimon to app fuse", "The opponent is selecting 1 digimon to app fuse");
  266. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  267. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  268. {
  269. selectedPermanent = permanent;
  270. yield return null;
  271. }
  272. if (selectedPermanent != null)
  273. {
  274. CardSource selectedCard = null;
  275. int maxCount1 = Math.Min(1, CardEffectCommons.MatchConditionOwnersCardCountInHand(card, handCard => CanSelectCard(handCard, selectedPermanent)));
  276. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  277. selectHandEffect.SetUp(
  278. selectPlayer: card.Owner,
  279. canTargetCondition: handCard => CanSelectCard(handCard, selectedPermanent),
  280. canTargetCondition_ByPreSelecetedList: null,
  281. canEndSelectCondition: null,
  282. maxCount: maxCount1,
  283. canNoSelect: true,
  284. canEndNotMax: false,
  285. isShowOpponent: true,
  286. selectCardCoroutine: SelectCardCoroutine,
  287. afterSelectCardCoroutine: null,
  288. mode: SelectHandEffect.Mode.Custom,
  289. cardEffect: activateClass);
  290. selectHandEffect.SetUpCustomMessage("Select digimon to app fuse into.", "The opponent is selecting digimon to app fuse into.");
  291. selectHandEffect.SetUpCustomMessage_ShowCard("Selected digimon");
  292. yield return StartCoroutine(selectHandEffect.Activate());
  293. IEnumerator SelectCardCoroutine(CardSource cardSource)
  294. {
  295. selectedCard = cardSource;
  296. yield return null;
  297. }
  298. if (selectedCard != null && selectedCard.CanAppFusionFromTargetPermanent(selectedPermanent, true))
  299. {
  300. CardSource linkCard = selectedPermanent.LinkedCards.Where(x => selectedCard.appFusionCondition.linkedCondition(selectedPermanent, x)).First();
  301. PlayCardClass playCardClass = new PlayCardClass(new List<CardSource> { selectedCard }, hashtable, true, selectedPermanent, false, SelectCardEffect.Root.Hand, true);
  302. playCardClass.SetAppFusion(new int[] { selectedPermanent.PermanentFrame.FrameID, selectedPermanent.LinkedCards.IndexOf(linkCard) });
  303. executed = true;
  304. yield return ContinuousController.instance.StartCoroutine(playCardClass.PlayCard());
  305. }
  306. }
  307. }
  308. if (!executed) activateClass.RemoveUse();
  309. }
  310. }
  311. #endregion
  312. #region Security Effect
  313. if (timing == EffectTiming.SecuritySkill)
  314. {
  315. cardEffects.Add(CardEffectFactory.PlaySelfTamerSecurityEffect(card));
  316. }
  317. #endregion
  318. return cardEffects;
  319. }
  320. }
  321. }