BT25_041.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. // Murasamemon
  6. namespace DCGO.CardEffects.BT25
  7. {
  8. public class BT25_041 : CEntity_Effect
  9. {
  10. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  11. {
  12. List<ICardEffect> cardEffects = new List<ICardEffect>();
  13. #region Alt Digivolution
  14. if (timing == EffectTiming.None)
  15. {
  16. bool PermanentCondition(Permanent permanent)
  17. {
  18. return permanent.TopCard.HasGlowingDawnTraits;
  19. }
  20. cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(PermanentCondition, 3, false, card, null, level: 4));
  21. }
  22. #endregion
  23. #region Alliance
  24. if (timing == EffectTiming.OnAllyAttack)
  25. {
  26. cardEffects.Add(CardEffectFactory.AllianceSelfEffect(isInheritedEffect: false, card: card, condition: null));
  27. }
  28. #endregion
  29. #region Shared WD / WA
  30. string SharedHashString = "BT25_041_WD_WA";
  31. string SharedEffectName = "By adding top security to hand or trashing bottom face down of a tamer, play or use 1 [Glowing Dawn] trait card from hand for 3 reduced cost";
  32. string SharedEffectDescription(string tag)
  33. => $"[{tag}] [Once Per Turn] If it's your turn, by adding your top security card to the hand or trashing the bottom face-down card under any of your Tamers, you may play or use 1 card with the [Glowing Dawn] trait from your hand with the cost reduced by 3.";
  34. bool AdditionalActivateCondition(Hashtable hashtable, ActivateClass activateClass) => CardEffectCommons.IsOwnerTurn(card);
  35. IEnumerator SharedActivateCoroutine(Hashtable hashtable, ActivateClass activateClass)
  36. {
  37. #region Conditions
  38. bool IsTamerWithFaceDownCard(Permanent permanent) =>
  39. CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaTamer(permanent, card) &&
  40. permanent.HasFaceDownDigivolutionCards &&
  41. !permanent.ImmuneFromStackTrashing(activateClass);
  42. bool isGlowingDawnCard(CardSource cardSource) =>
  43. cardSource.HasGlowingDawnTraits;
  44. bool FaceDownCards(CardSource cardSource) => cardSource.IsFaceDown;
  45. #endregion
  46. bool isUsed = false;
  47. bool hasPaidCost = false;
  48. bool canAddSecurityToHand = card.Owner.SecurityCards.Any();
  49. bool canTrashBottomFaceDownCard = CardEffectCommons.HasMatchConditionPermanent(IsTamerWithFaceDownCard);
  50. #region Select to pay Cost
  51. List<SelectionElement<int>> selectionElements = new List<SelectionElement<int>>();
  52. if (canAddSecurityToHand) selectionElements.Add(new SelectionElement<int>(message: $"Add top security card to hand", value: 1, spriteIndex: 0));
  53. if (canTrashBottomFaceDownCard) selectionElements.Add(new SelectionElement<int>(message: $"Trash bottom face down card from 1 tamer", value: 2, spriteIndex: 0));
  54. selectionElements.Add(new SelectionElement<int>(message: $"Dont pay the cost", value: 3, spriteIndex: 1));
  55. string selectPlayerMessage = "Will you pay the cost?";
  56. string notSelectPlayerMessage = "The opponent is choosing to pay the cost.";
  57. GManager.instance.userSelectionManager.SetIntSelection(selectionElements: selectionElements, selectPlayer: card.Owner, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  58. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  59. bool payCost = GManager.instance.userSelectionManager.SelectedIntValue != 3;
  60. bool isSecurity = GManager.instance.userSelectionManager.SelectedIntValue == 1;
  61. #endregion
  62. #region Pay Cost
  63. if (payCost)
  64. {
  65. if (isSecurity)
  66. {
  67. CardSource topCard = card.Owner.SecurityCards[0];
  68. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(new List<CardSource>() { topCard }, false, activateClass));
  69. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(player: card.Owner, refSkillInfos: ref ContinuousController.instance.nullSkillInfos, activateClass).ReduceSecurity());
  70. if (card.Owner.HandCards.Contains(topCard))
  71. {
  72. hasPaidCost = true;
  73. isUsed = true;
  74. }
  75. }
  76. else
  77. {
  78. bool trash = false;
  79. SelectPermanentEffect selectPermanentEffect1 = GManager.instance.GetComponent<SelectPermanentEffect>();
  80. selectPermanentEffect1.SetUp(
  81. selectPlayer: card.Owner,
  82. canTargetCondition: IsTamerWithFaceDownCard,
  83. canTargetCondition_ByPreSelecetedList: null,
  84. canEndSelectCondition: null,
  85. maxCount: 1,
  86. canNoSelect: true,
  87. canEndNotMax: false,
  88. selectPermanentCoroutine: null,
  89. afterSelectPermanentCoroutine: AfterSelectPermanentCoroutine,
  90. mode: SelectPermanentEffect.Mode.Custom,
  91. cardEffect: activateClass);
  92. IEnumerator AfterSelectPermanentCoroutine(List<Permanent> permanents)
  93. {
  94. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.TrashDigivolutionCardsFromTopOrBottom(targetPermanent: permanents[0], trashCount: 1, isFromTop: false, activateClass: activateClass, FaceDownCards));
  95. trash = true;
  96. }
  97. selectPermanentEffect1.SetUpCustomMessage("Select 1 Tamer to trash 1 bottom face-down card from", "The opponent is selecting 1 Tamer to trash 1 bottom face-down card from");
  98. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect1.Activate());
  99. if (trash)
  100. {
  101. hasPaidCost = true;
  102. isUsed = true;
  103. }
  104. }
  105. }
  106. #endregion
  107. if (hasPaidCost && CardEffectCommons.HasMatchConditionOwnersHand(card, isGlowingDawnCard))
  108. {
  109. CardSource selectedCard = null;
  110. #region Selected Glowing Dawn Card in Hand to play or use
  111. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  112. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionOwnersCardCountInHand(card, isGlowingDawnCard));
  113. selectHandEffect.SetUp(
  114. selectPlayer: card.Owner,
  115. canTargetCondition: isGlowingDawnCard,
  116. canTargetCondition_ByPreSelecetedList: null,
  117. canEndSelectCondition: null,
  118. maxCount: maxCount,
  119. canNoSelect: true,
  120. canEndNotMax: false,
  121. isShowOpponent: true,
  122. selectCardCoroutine: SelectCardCoroutine,
  123. afterSelectCardCoroutine: null,
  124. mode: SelectHandEffect.Mode.Custom,
  125. cardEffect: activateClass);
  126. IEnumerator SelectCardCoroutine(CardSource cardSource)
  127. {
  128. selectedCard = cardSource;
  129. yield return null;
  130. }
  131. selectHandEffect.SetUpCustomMessage("Select 1 [Glowing Dawn] card to play/use.", "The opponent is selecting 1 [Glowing Dawn] card to play/use.");
  132. selectHandEffect.SetUpCustomMessage_ShowCard("Selected Card");
  133. yield return ContinuousController.instance.StartCoroutine(selectHandEffect.Activate());
  134. #endregion
  135. if (selectedCard != null)
  136. {
  137. #region Reduce Cost
  138. IEnumerator ReduceCost(string type)
  139. {
  140. if (card.Owner.CanReduceCost(null, card))
  141. {
  142. ContinuousController.instance.PlaySE(GManager.instance.GetComponent<Effects>().BuffSE);
  143. }
  144. Hashtable hashtable = new Hashtable
  145. {
  146. { "CardEffect", activateClass }
  147. };
  148. ChangeCostClass changeCostClass = new ChangeCostClass();
  149. changeCostClass.SetUpICardEffect($"{type} cost: -3", CanUseCondition1, card);
  150. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardSourceCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  151. card.Owner.UntilCalculateFixedCostEffect.Add(_ => changeCostClass);
  152. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.ShowReducedCost(hashtable));
  153. bool CanUseCondition1(Hashtable hashtable)
  154. {
  155. return true;
  156. }
  157. int ChangeCost(CardSource cardSource, int cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  158. {
  159. if (CardSourceCondition(cardSource) &&
  160. RootCondition(root) &&
  161. PermanentsCondition(targetPermanents))
  162. {
  163. cost -= 3;
  164. }
  165. return cost;
  166. }
  167. bool PermanentsCondition(List<Permanent> targetPermanents)
  168. {
  169. return targetPermanents == null || targetPermanents.Count(targetPermanent => targetPermanent != null) == 0;
  170. }
  171. bool CardSourceCondition(CardSource cardSource)
  172. {
  173. return cardSource != null
  174. && cardSource.Owner == card.Owner
  175. && cardSource.EqualsTraits("Glowing Dawn");
  176. }
  177. bool RootCondition(SelectCardEffect.Root root)
  178. {
  179. return true;
  180. }
  181. bool isUpDown()
  182. {
  183. return true;
  184. }
  185. }
  186. #endregion
  187. if (selectedCard.IsOption)
  188. {
  189. yield return ContinuousController.instance.StartCoroutine(ReduceCost("Use"));
  190. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayOptionCards(
  191. cardSources: new List<CardSource>() { selectedCard },
  192. activateClass: activateClass,
  193. payCost: true,
  194. root: SelectCardEffect.Root.Hand));
  195. }
  196. else
  197. {
  198. yield return ContinuousController.instance.StartCoroutine(ReduceCost("Play"));
  199. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(
  200. cardSources: new List<CardSource>() { selectedCard },
  201. activateClass: activateClass,
  202. payCost: true,
  203. isTapped: false,
  204. root: SelectCardEffect.Root.Hand,
  205. activateETB: true));
  206. }
  207. }
  208. }
  209. if (!isUsed) activateClass.RemoveUse();
  210. }
  211. CardEffectFactory.ActivateClassesForSharedEffects
  212. (ref cardEffects, timing, card,
  213. SharedEffectName,
  214. SharedActivateCoroutine,
  215. SharedEffectDescription,
  216. optional: false,
  217. isSkippable: true,
  218. maxCountPerTurn: 1,
  219. hashValue: SharedHashString,
  220. whenDigivolving: true,
  221. whenAttacking: true,
  222. additionalActivateCondition: AdditionalActivateCondition);
  223. #endregion
  224. #region Inherit End of Attack OPT
  225. if (timing == EffectTiming.OnEndAttack)
  226. {
  227. ActivateClass activateClass = new ActivateClass();
  228. activateClass.SetUpICardEffect("By trashing bottom face down of a tamer, this digimon with [Glowing Dawn] trait unsuspends", CanUseCondition, card);
  229. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, false, EffectDescription());
  230. activateClass.SetHashString("BT25_041_EndAttack");
  231. activateClass.SetIsInheritedEffect(true);
  232. cardEffects.Add(activateClass);
  233. string EffectDescription() => "[End of Attack] [Once Per Turn] By trashing the bottom face-down card from under any of your Tamers, this Digimon with the [Glowing Dawn] trait unsuspends.";
  234. bool CanUseCondition(Hashtable hashtable)
  235. {
  236. return CardEffectCommons.IsExistOnBattleAreaDigimon(card)
  237. && CardEffectCommons.CanTriggerOnEndAttack(hashtable, card);
  238. }
  239. bool CanActivateCondition(Hashtable hashtable)
  240. {
  241. return CardEffectCommons.IsExistOnBattleAreaDigimon(card)
  242. && CardEffectCommons.HasMatchConditionOwnersPermanent(card, IsTamerWithFaceDownCard);
  243. }
  244. bool IsTamerWithFaceDownCard(Permanent permanent) =>
  245. CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaTamer(permanent, card) &&
  246. permanent.HasFaceDownDigivolutionCards &&
  247. !permanent.ImmuneFromStackTrashing(activateClass);
  248. bool FaceDownCards(CardSource cardSource) => cardSource.IsFaceDown;
  249. bool IsGlowingDawnDigimon(Permanent permanent) => permanent.TopCard.HasGlowingDawnTraits;
  250. IEnumerator ActivateCoroutine(Hashtable hashtable)
  251. {
  252. bool isUsed = false;
  253. bool hasPaidCost = false;
  254. if (CardEffectCommons.HasMatchConditionPermanent(IsTamerWithFaceDownCard))
  255. {
  256. bool trash = false;
  257. SelectPermanentEffect selectPermanentEffect1 = GManager.instance.GetComponent<SelectPermanentEffect>();
  258. selectPermanentEffect1.SetUp(
  259. selectPlayer: card.Owner,
  260. canTargetCondition: IsTamerWithFaceDownCard,
  261. canTargetCondition_ByPreSelecetedList: null,
  262. canEndSelectCondition: null,
  263. maxCount: 1,
  264. canNoSelect: true,
  265. canEndNotMax: false,
  266. selectPermanentCoroutine: null,
  267. afterSelectPermanentCoroutine: AfterSelectPermanentCoroutine,
  268. mode: SelectPermanentEffect.Mode.Custom,
  269. cardEffect: activateClass);
  270. selectPermanentEffect1.SetUpCustomMessage("Select 1 Tamer to trash 1 bottom face-down card from", "The opponent is selecting 1 Tamer to trash 1 bottom face-down card from");
  271. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect1.Activate());
  272. IEnumerator AfterSelectPermanentCoroutine(List<Permanent> permanents)
  273. {
  274. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.TrashDigivolutionCardsFromTopOrBottom(targetPermanent: permanents[0], trashCount: 1, isFromTop: false, activateClass: activateClass, FaceDownCards));
  275. trash = true;
  276. }
  277. if (trash) hasPaidCost = true;
  278. }
  279. if (hasPaidCost) isUsed = true;
  280. if (hasPaidCost && IsGlowingDawnDigimon(card.PermanentOfThisCard())) yield return ContinuousController.instance.StartCoroutine(new IUnsuspendPermanents(new List<Permanent>() { card.PermanentOfThisCard() }, activateClass).Unsuspend());
  281. if (!isUsed) activateClass.RemoveUse();
  282. }
  283. }
  284. #endregion
  285. return cardEffects;
  286. }
  287. }
  288. }