BT24_079.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System;
  5. // Hadesmon
  6. namespace DCGO.CardEffects.BT24
  7. {
  8. public class BT24_079 : CEntity_Effect
  9. {
  10. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  11. {
  12. List<ICardEffect> cardEffects = new List<ICardEffect>();
  13. #region Alternative Digivolution Condition - Ult.
  14. if (timing == EffectTiming.None)
  15. {
  16. bool PermanentCondition(Permanent targetPermanent)
  17. {
  18. return targetPermanent.TopCard.HasUltimateAppTraits;
  19. }
  20. cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(permanentCondition: PermanentCondition, digivolutionCost: 4, ignoreDigivolutionRequirement: false, card: card, condition: null));
  21. }
  22. #endregion
  23. #region App Fusion (Revivemon, Biomon)
  24. if (timing == EffectTiming.None)
  25. {
  26. cardEffects.Add(CardEffectFactory.AddAppfuseMethodByName(new List<string>() { "Revivemon", "Biomon" }, card));
  27. }
  28. #endregion
  29. #region Overclock
  30. if (timing == EffectTiming.OnEndTurn)
  31. {
  32. cardEffects.Add(CardEffectFactory.OverclockSelfEffect(trait: "Appmon", isInheritedEffect: false, card: card, condition: null));
  33. }
  34. #endregion
  35. #region Link +1
  36. if (timing == EffectTiming.None) cardEffects.Add(CardEffectFactory.ChangeSelfLinkMaxStaticEffect(1, false, card, null));
  37. #endregion
  38. #region When Digivolving
  39. if (timing == EffectTiming.OnEnterFieldAnyone)
  40. {
  41. ActivateClass activateClass = new ActivateClass();
  42. activateClass.SetUpICardEffect("Play a lvl 4- from trash. Add new link to a digimon", CanUseCondition, card);
  43. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDiscription());
  44. cardEffects.Add(activateClass);
  45. string EffectDiscription()
  46. => "[When Digivolving] You may play 1 level 4 or lower [System] or [Life] trait Digimon card from your trash without paying the cost. Then, you may link 1 [Appmon] trait Digimon card from your hand or this Digimon's digivolution cards to 1 of your Digimon without paying the cost.";
  47. bool CanUseCondition(Hashtable hashtable)
  48. {
  49. return CardEffectCommons.IsExistOnBattleAreaDigimon(card)
  50. && CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  51. }
  52. bool CanActivateCondition(Hashtable hashtable)
  53. {
  54. return CardEffectCommons.IsExistOnBattleAreaDigimon(card);
  55. }
  56. bool CanPlayCardCondition(CardSource cardSource)
  57. {
  58. return cardSource.IsDigimon
  59. && cardSource.HasLevel
  60. && cardSource.Level <= 4
  61. && (cardSource.EqualsTraits("System")
  62. || cardSource.EqualsTraits("Life"))
  63. && CardEffectCommons.CanPlayAsNewPermanent(cardSource, false, activateClass);
  64. }
  65. bool CanSelectLinkCard(CardSource cardSource)
  66. {
  67. return cardSource.IsDigimon
  68. && cardSource.HasAppmonTraits
  69. && cardSource.CanLink(false);
  70. }
  71. IEnumerator ActivateCoroutine(Hashtable hashtable)
  72. {
  73. #region Play 4- from trash
  74. {
  75. int maxCount = Math.Min(1, card.Owner.TrashCards.Count((cardSource) => CanPlayCardCondition(cardSource)));
  76. List<CardSource> selectedCards = new List<CardSource>();
  77. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  78. selectCardEffect.SetUp(
  79. canTargetCondition: CanPlayCardCondition,
  80. canTargetCondition_ByPreSelecetedList: null,
  81. canEndSelectCondition: null,
  82. canNoSelect: () => true,
  83. selectCardCoroutine: SelectCardPlayCoroutine,
  84. afterSelectCardCoroutine: null,
  85. message: "Select 1 card to play.",
  86. maxCount: maxCount,
  87. canEndNotMax: false,
  88. isShowOpponent: true,
  89. mode: SelectCardEffect.Mode.Custom,
  90. root: SelectCardEffect.Root.Trash,
  91. customRootCardList: null,
  92. canLookReverseCard: true,
  93. selectPlayer: card.Owner,
  94. cardEffect: activateClass);
  95. selectCardEffect.SetUpCustomMessage("Select 1 card to play.", "The opponent is selecting 1 card to play.");
  96. selectCardEffect.SetUpCustomMessage_ShowCard("Played Card");
  97. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  98. IEnumerator SelectCardPlayCoroutine(CardSource cardSource)
  99. {
  100. selectedCards.Add(cardSource);
  101. yield return null;
  102. }
  103. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(cardSources: selectedCards, activateClass: activateClass, payCost: false, isTapped: false, root: SelectCardEffect.Root.Trash, activateETB: true));
  104. }
  105. #endregion
  106. #region Link a card
  107. bool hasInHand = CardEffectCommons.HasMatchConditionOwnersHand(card, CanSelectLinkCard);
  108. bool hasInSources = card.PermanentOfThisCard().DigivolutionCards.Count(CanSelectLinkCard) > 0;
  109. bool selectedRoot = false;
  110. CardSource selectedCard = null;
  111. if (hasInHand || hasInSources)
  112. {
  113. if (hasInHand && hasInSources)
  114. {
  115. List<SelectionElement<bool>> selectionElements = new List<SelectionElement<bool>>()
  116. {
  117. new SelectionElement<bool>(message: $"From This Digimon", value: true, spriteIndex: 0),
  118. new SelectionElement<bool>(message: $"From Hand", value: false, spriteIndex: 0),
  119. };
  120. string selectPlayerMessage = "Choose where to get the digimon from";
  121. string notSelectPlayerMessage = "The opponent is choosing effects.";
  122. GManager.instance.userSelectionManager.SetBoolSelection(
  123. selectionElements: selectionElements, selectPlayer: card.Owner,
  124. selectPlayerMessage: selectPlayerMessage,
  125. notSelectPlayerMessage: notSelectPlayerMessage);
  126. yield return ContinuousController.instance.StartCoroutine(GManager.instance
  127. .userSelectionManager.WaitForEndSelect());
  128. selectedRoot = GManager.instance.userSelectionManager.SelectedBoolValue;
  129. }
  130. else if (hasInSources)
  131. {
  132. selectedRoot = true;
  133. }
  134. if (selectedRoot)
  135. {
  136. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  137. selectCardEffect.SetUp(
  138. canTargetCondition: CanSelectLinkCard,
  139. canTargetCondition_ByPreSelecetedList: null,
  140. canEndSelectCondition: null,
  141. canNoSelect: () => true,
  142. selectCardCoroutine: SelectCardCoroutine,
  143. afterSelectCardCoroutine: null,
  144. message: "Select 1 card to link.",
  145. maxCount: 1,
  146. canEndNotMax: false,
  147. isShowOpponent: true,
  148. mode: SelectCardEffect.Mode.Custom,
  149. root: SelectCardEffect.Root.DigivolutionCards,
  150. customRootCardList: card.PermanentOfThisCard().DigivolutionCards,
  151. canLookReverseCard: true,
  152. selectPlayer: card.Owner,
  153. cardEffect: activateClass);
  154. selectCardEffect.SetUpCustomMessage("Select 1 card to link", "The opponent is selecting 1 card to link");
  155. yield return StartCoroutine(selectCardEffect.Activate());
  156. }
  157. else
  158. {
  159. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  160. selectHandEffect.SetUp(
  161. selectPlayer: card.Owner,
  162. canTargetCondition: CanSelectLinkCard,
  163. canTargetCondition_ByPreSelecetedList: null,
  164. canEndSelectCondition: null,
  165. maxCount: 1,
  166. canNoSelect: true,
  167. canEndNotMax: false,
  168. isShowOpponent: true,
  169. selectCardCoroutine: SelectCardCoroutine,
  170. afterSelectCardCoroutine: null,
  171. mode: SelectHandEffect.Mode.Custom,
  172. cardEffect: activateClass);
  173. selectHandEffect.SetUpCustomMessage("Select 1 card to link", "The opponent is selecting 1 card to link");
  174. yield return StartCoroutine(selectHandEffect.Activate());
  175. }
  176. }
  177. IEnumerator SelectCardCoroutine(CardSource cardSource)
  178. {
  179. selectedCard = cardSource;
  180. yield return null;
  181. }
  182. if (selectedCard != null)
  183. {
  184. bool CanSelectDigimon(Permanent permanent)
  185. {
  186. if (CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card))
  187. return selectedCard.CanLinkToTargetPermanent(permanent, false);
  188. return false;
  189. }
  190. if (CardEffectCommons.HasMatchConditionOwnersPermanent(card, CanSelectDigimon))
  191. {
  192. Permanent selectedPermanent = null;
  193. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectDigimon));
  194. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  195. selectPermanentEffect.SetUp(
  196. selectPlayer: card.Owner,
  197. canTargetCondition: CanSelectDigimon,
  198. canTargetCondition_ByPreSelecetedList: null,
  199. canEndSelectCondition: null,
  200. maxCount: maxCount,
  201. canNoSelect: true,
  202. canEndNotMax: false,
  203. selectPermanentCoroutine: SelectPermanentCoroutine,
  204. afterSelectPermanentCoroutine: null,
  205. mode: SelectPermanentEffect.Mode.Custom,
  206. cardEffect: activateClass);
  207. selectPermanentEffect.SetUpCustomMessage("Select 1 digimon to add link", "The opponent is selecting 1 digimon to add link");
  208. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  209. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  210. {
  211. selectedPermanent = permanent;
  212. yield return null;
  213. }
  214. if (selectedPermanent != null)
  215. {
  216. yield return ContinuousController.instance.StartCoroutine(selectedPermanent.AddLinkCard(selectedCard, activateClass));
  217. }
  218. }
  219. }
  220. #endregion
  221. }
  222. }
  223. #endregion
  224. #region All Turns OPT
  225. if (timing == EffectTiming.OnDestroyedAnyone)
  226. {
  227. ActivateClass activateClass = new ActivateClass();
  228. activateClass.SetUpICardEffect("Activate [When Digivolving]", CanUseCondition, card);
  229. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, true, EffectDescription());
  230. activateClass.SetHashString("BT24_079_AT_Activate_WD");
  231. cardEffects.Add(activateClass);
  232. string EffectDescription()
  233. {
  234. return "[All Turns] [Once Per Turn] When other Digimon are deleted, you may activate 1 of this Digimon's [When Digivolving] effects.";
  235. }
  236. bool PermanentCondition(Permanent permanent)
  237. {
  238. return CardEffectCommons.IsPermanentExistsOnBattleAreaDigimon(permanent)
  239. && permanent != card.PermanentOfThisCard();
  240. }
  241. bool CanUseCondition(Hashtable hashtable)
  242. {
  243. return CardEffectCommons.IsExistOnBattleAreaDigimon(card)
  244. && CardEffectCommons.CanTriggerOnPermanentDeleted(hashtable, PermanentCondition, activateClass);
  245. }
  246. bool CanActivateCondition(Hashtable hashtable)
  247. {
  248. return CardEffectCommons.IsExistOnBattleAreaDigimon(card)
  249. && card.PermanentOfThisCard().EffectList(EffectTiming.OnEnterFieldAnyone).Any(CanBeEffectCandidate);
  250. }
  251. bool CanBeEffectCandidate(ICardEffect cardEffect)
  252. {
  253. if (cardEffect != null &&
  254. cardEffect is ActivateICardEffect &&
  255. !cardEffect.IsSecurityEffect &&
  256. cardEffect.IsWhenDigivolving)
  257. {
  258. Hashtable digivolvingHashtable = CardEffectCommons.WhenDigivolvingCheckHashtableOfCard(cardEffect.EffectSourceCard);
  259. return cardEffect.CanUse(digivolvingHashtable);
  260. }
  261. return false;
  262. }
  263. IEnumerator ActivateCoroutine(Hashtable hashtable)
  264. {
  265. List<ICardEffect> candidateEffects = card.PermanentOfThisCard().EffectList(EffectTiming.OnEnterFieldAnyone)
  266. .Clone()
  267. .Filter(CanBeEffectCandidate);
  268. if (candidateEffects.Count >= 1)
  269. {
  270. ICardEffect selectedEffect = null;
  271. if (candidateEffects.Count == 1)
  272. {
  273. selectedEffect = candidateEffects[0];
  274. }
  275. else
  276. {
  277. List<SkillInfo> skillInfos = candidateEffects
  278. .Map(cardEffect => new SkillInfo(cardEffect, null, EffectTiming.None));
  279. List<CardSource> cardSources = candidateEffects
  280. .Map(cardEffect => cardEffect.EffectSourceCard);
  281. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  282. selectCardEffect.SetUp(
  283. canTargetCondition: (cardSource) => true,
  284. canTargetCondition_ByPreSelecetedList: null,
  285. canEndSelectCondition: null,
  286. canNoSelect: () => false,
  287. selectCardCoroutine: null,
  288. afterSelectCardCoroutine: null,
  289. message: "Select 1 effect to activate.",
  290. maxCount: 1,
  291. canEndNotMax: false,
  292. isShowOpponent: false,
  293. mode: SelectCardEffect.Mode.Custom,
  294. root: SelectCardEffect.Root.Custom,
  295. customRootCardList: cardSources,
  296. canLookReverseCard: true,
  297. selectPlayer: card.Owner,
  298. cardEffect: activateClass);
  299. selectCardEffect.SetNotShowCard();
  300. selectCardEffect.SetUpSkillInfos(skillInfos);
  301. selectCardEffect.SetUpAfterSelectIndexCoroutine(AfterSelectIndexCoroutine);
  302. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  303. IEnumerator AfterSelectIndexCoroutine(List<int> selectedIndexes)
  304. {
  305. if (selectedIndexes.Count == 1)
  306. {
  307. selectedEffect = candidateEffects[selectedIndexes[0]];
  308. yield return null;
  309. }
  310. }
  311. }
  312. if (selectedEffect != null)
  313. {
  314. if (selectedEffect.EffectSourceCard != null)
  315. {
  316. if (selectedEffect.EffectSourceCard.PermanentOfThisCard() != null)
  317. {
  318. Hashtable digivolvingHashtable = CardEffectCommons.WhenDigivolvingCheckHashtableOfCard(selectedEffect.EffectSourceCard);
  319. if (selectedEffect.CanUse(digivolvingHashtable))
  320. {
  321. yield return ContinuousController.instance.StartCoroutine(((ActivateICardEffect)selectedEffect).Activate_Optional_Effect_Execute(digivolvingHashtable));
  322. }
  323. }
  324. }
  325. }
  326. }
  327. }
  328. }
  329. #endregion
  330. return cardEffects;
  331. }
  332. }
  333. }