BT23_102.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. // Mastemon
  6. namespace DCGO.CardEffects.BT23
  7. {
  8. public class BT23_102 : CEntity_Effect
  9. {
  10. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  11. {
  12. List<ICardEffect> cardEffects = new List<ICardEffect>();
  13. #region Static Effects
  14. #region Alt Digivolve Cost
  15. if (timing == EffectTiming.None)
  16. {
  17. bool PermanentCondition(Permanent targetPermanent)
  18. {
  19. return targetPermanent.TopCard.IsLevel5
  20. && targetPermanent.TopCard.HasCSTraits;
  21. }
  22. cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(
  23. permanentCondition: PermanentCondition,
  24. digivolutionCost: 5,
  25. ignoreDigivolutionRequirement: false,
  26. card: card, condition: null)
  27. );
  28. }
  29. #endregion
  30. #region DNA Digivolution
  31. if (timing == EffectTiming.None)
  32. {
  33. AddJogressConditionClass addJogressConditionClass = new AddJogressConditionClass();
  34. addJogressConditionClass.SetUpICardEffect($"DNA Digivolution", CanUseCondition, card);
  35. addJogressConditionClass.SetUpAddJogressConditionClass(getJogressCondition: GetJogress);
  36. addJogressConditionClass.SetNotShowUI(true);
  37. cardEffects.Add(addJogressConditionClass);
  38. bool CanUseCondition(Hashtable hashtable)
  39. {
  40. return true;
  41. }
  42. JogressCondition GetJogress(CardSource cardSource)
  43. {
  44. if (cardSource == card)
  45. {
  46. bool PermanentCondition1(Permanent permanent)
  47. {
  48. if (permanent != null)
  49. {
  50. if (permanent.TopCard != null)
  51. {
  52. if (permanent.TopCard.Owner == card.Owner)
  53. {
  54. if (permanent.IsDigimon)
  55. {
  56. if (CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card))
  57. {
  58. if (permanent.TopCard.CardColors.Contains(CardColor.Yellow))
  59. {
  60. if (permanent.Levels_ForJogress(card).Contains(5))
  61. {
  62. return true;
  63. }
  64. }
  65. }
  66. }
  67. }
  68. }
  69. }
  70. return false;
  71. }
  72. bool PermanentCondition2(Permanent permanent)
  73. {
  74. if (permanent != null)
  75. {
  76. if (permanent.TopCard != null)
  77. {
  78. if (permanent.TopCard.Owner == card.Owner)
  79. {
  80. if (permanent.IsDigimon)
  81. {
  82. if (CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card))
  83. {
  84. if (permanent.TopCard.CardColors.Contains(CardColor.Purple))
  85. {
  86. if (permanent.Levels_ForJogress(card).Contains(5))
  87. {
  88. return true;
  89. }
  90. }
  91. }
  92. }
  93. }
  94. }
  95. }
  96. return false;
  97. }
  98. JogressConditionElement[] elements =
  99. {
  100. new(PermanentCondition1, "a level Yellow Digimon"),
  101. new(PermanentCondition2, "a level Purple Digimon")
  102. };
  103. JogressCondition jogressCondition = new JogressCondition(elements, 0);
  104. return jogressCondition;
  105. }
  106. return null;
  107. }
  108. }
  109. #endregion
  110. #region Barrier
  111. if (timing == EffectTiming.WhenPermanentWouldBeDeleted)
  112. {
  113. cardEffects.Add(CardEffectFactory.BarrierSelfEffect(isInheritedEffect: false, card: card, condition: null));
  114. }
  115. #endregion
  116. //TODO: Named Partition effect
  117. #endregion
  118. #region When Digivolving
  119. if (timing == EffectTiming.OnEnterFieldAnyone)
  120. {
  121. ActivateClass activateClass = new ActivateClass();
  122. activateClass.SetUpICardEffect("Play 1 level 5 or lower yellow/purple card from hand or trash. then if digimon has 2+ same level cards in stack, trash both security till 3", CanUseCondition, card);
  123. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  124. cardEffects.Add(activateClass);
  125. string EffectDiscription()
  126. {
  127. return "[When Digivolving] You may play 1 level 5 or lower yellow or purple card from your hand or trash without paying the cost. Then, if this Digimon's stack has 2 or more same-level cards, trash the top cards of both players' security stacks so that they have 3 cards left.";
  128. }
  129. bool CanUseCondition(Hashtable hashtable)
  130. {
  131. return CardEffectCommons.IsExistOnBattleAreaDigimon(card)
  132. && CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  133. }
  134. bool CanActivateCondition(Hashtable hashtable)
  135. {
  136. return CardEffectCommons.IsExistOnBattleAreaDigimon(card);
  137. }
  138. bool CanSelectCard(CardSource cardSource)
  139. {
  140. return cardSource.IsDigimon
  141. && cardSource.HasLevel && cardSource.Level <= 5
  142. && cardSource.CardColors.Contains(CardColor.Yellow) || cardSource.CardColors.Contains(CardColor.Purple)
  143. && CardEffectCommons.CanPlayAsNewPermanent(cardSource, false, activateClass);
  144. }
  145. IEnumerator ActivateCoroutine(Hashtable hashtable)
  146. {
  147. bool canSelectHand = CardEffectCommons.HasMatchConditionOwnersHand(card, CanSelectCard);
  148. bool canSelectTrash = CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, CanSelectCard);
  149. if (canSelectHand || canSelectTrash)
  150. {
  151. #region Setup user Selection
  152. if (canSelectHand && canSelectTrash)
  153. {
  154. List<SelectionElement<bool>> selectionElements = new List<SelectionElement<bool>>()
  155. {
  156. new SelectionElement<bool>(message: $"From hand", value : true, spriteIndex: 0),
  157. new SelectionElement<bool>(message: $"From trash", value : false, spriteIndex: 1),
  158. };
  159. string selectPlayerMessage = "From which area do you select a card?";
  160. string notSelectPlayerMessage = "The opponent is choosing from which area to select a card.";
  161. GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: selectionElements, selectPlayer: card.Owner, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  162. }
  163. else
  164. {
  165. GManager.instance.userSelectionManager.SetBool(canSelectHand);
  166. }
  167. #endregion
  168. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  169. bool fromHand = GManager.instance.userSelectionManager.SelectedBoolValue;
  170. CardSource selectedCard = null;
  171. IEnumerator SelectCardCoroutine(CardSource cardSource)
  172. {
  173. selectedCard = cardSource;
  174. yield return null;
  175. }
  176. if (fromHand)
  177. {
  178. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  179. selectHandEffect.SetUp(
  180. selectPlayer: card.Owner,
  181. canTargetCondition: CanSelectCard,
  182. canTargetCondition_ByPreSelecetedList: null,
  183. canEndSelectCondition: null,
  184. maxCount: 1,
  185. canNoSelect: true,
  186. canEndNotMax: false,
  187. isShowOpponent: true,
  188. selectCardCoroutine: SelectCardCoroutine,
  189. afterSelectCardCoroutine: null,
  190. mode: SelectHandEffect.Mode.Custom,
  191. cardEffect: activateClass);
  192. selectHandEffect.SetUpCustomMessage("Select 1 card to play", "The opponent is selecting 1 card to play.");
  193. selectHandEffect.SetUpCustomMessage_ShowCard("Selected card");
  194. yield return ContinuousController.instance.StartCoroutine(selectHandEffect.Activate());
  195. if (selectedCard != null) yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(
  196. new List<CardSource>() { selectedCard },
  197. activateClass: activateClass,
  198. payCost: false,
  199. isTapped: false,
  200. root: SelectCardEffect.Root.Hand,
  201. activateETB: transform)
  202. );
  203. }
  204. else
  205. {
  206. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  207. selectCardEffect.SetUp(
  208. canTargetCondition: CanSelectCard,
  209. canTargetCondition_ByPreSelecetedList: null,
  210. canEndSelectCondition: null,
  211. canNoSelect: () => true,
  212. selectCardCoroutine: SelectCardCoroutine,
  213. afterSelectCardCoroutine: null,
  214. message: "Select 1 card to play.",
  215. maxCount: 1,
  216. canEndNotMax: false,
  217. isShowOpponent: true,
  218. mode: SelectCardEffect.Mode.Custom,
  219. root: SelectCardEffect.Root.Trash,
  220. customRootCardList: null,
  221. canLookReverseCard: true,
  222. selectPlayer: card.Owner,
  223. cardEffect: activateClass);
  224. selectCardEffect.SetUpCustomMessage("Select 1 card to play", "The opponent is selecting 1 card to play.");
  225. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Card");
  226. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  227. if (selectedCard != null) yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(
  228. new List<CardSource>() { selectedCard },
  229. activateClass: activateClass,
  230. payCost: false,
  231. isTapped: false,
  232. root: SelectCardEffect.Root.Trash,
  233. activateETB: transform)
  234. );
  235. }
  236. }
  237. if (card.PermanentOfThisCard().StackCards.Filter(x => !x.IsFlipped).GroupBy(x => x.Level).Any(g => g.Count() >= 2))
  238. {
  239. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  240. {
  241. if (player.SecurityCards.Count <= 3) continue;
  242. var trashAmount = player.SecurityCards.Count - 3;
  243. yield return ContinuousController.instance.StartCoroutine(new IDestroySecurity(
  244. player: player,
  245. destroySecurityCount: trashAmount,
  246. cardEffect: activateClass,
  247. fromTop: true).DestroySecurity()
  248. );
  249. }
  250. }
  251. }
  252. }
  253. #endregion
  254. #region All Turns - OPT
  255. if (timing == EffectTiming.OnLoseSecurity)
  256. {
  257. ActivateClass activateClass = new ActivateClass();
  258. activateClass.SetUpICardEffect("Place 1 digimon as bottom security", CanUseCondition, card);
  259. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, true, EffectDiscription());
  260. activateClass.SetHashString("BT23_102_AT");
  261. cardEffects.Add(activateClass);
  262. string EffectDiscription()
  263. {
  264. return "[All Turns] [Once Per Turn] When security stacks are removed from, you may place 1 Digimon as the bottom security card.";
  265. }
  266. bool CanUseCondition(Hashtable hashtable)
  267. {
  268. return CardEffectCommons.IsExistOnBattleAreaDigimon(card)
  269. && CardEffectCommons.CanTriggerWhenLoseSecurity(hashtable, null);
  270. }
  271. bool CanActivateCondition(Hashtable hashtable)
  272. {
  273. return CardEffectCommons.IsExistOnBattleAreaDigimon(card);
  274. }
  275. bool CanSelectPermanentCondition(Permanent permanent)
  276. {
  277. return CardEffectCommons.IsPermanentExistsOnBattleArea(permanent)
  278. && permanent.IsDigimon;
  279. }
  280. IEnumerator ActivateCoroutine(Hashtable hashtable)
  281. {
  282. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  283. {
  284. Permanent selectedPermament = null;
  285. #region Select Opponent Permament
  286. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  287. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  288. selectPermanentEffect.SetUp(
  289. selectPlayer: card.Owner,
  290. canTargetCondition: CanSelectPermanentCondition,
  291. canTargetCondition_ByPreSelecetedList: null,
  292. canEndSelectCondition: null,
  293. maxCount: maxCount,
  294. canNoSelect: false,
  295. canEndNotMax: false,
  296. selectPermanentCoroutine: SelectPermanentCoroutine,
  297. afterSelectPermanentCoroutine: null,
  298. mode: SelectPermanentEffect.Mode.Custom,
  299. cardEffect: activateClass);
  300. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  301. {
  302. selectedPermament = permanent;
  303. yield return null;
  304. }
  305. selectPermanentEffect.SetUpCustomMessage("Select 1 digimon to send to bottom of security.", "Your opponent is selecting 1 digimon to send to bottom of security.");
  306. #endregion
  307. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  308. if (selectedPermament != null) yield return ContinuousController.instance.StartCoroutine(new IPutSecurityPermanent(
  309. permanent: selectedPermament,
  310. hashtable: hashtable,
  311. toTop: false).PutSecurity()
  312. );
  313. }
  314. }
  315. }
  316. #endregion
  317. return cardEffects;
  318. }
  319. }
  320. }