Myotismon_EX8_060.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using Photon.Pun;
  6. using UnityEngine;
  7. namespace DCGO.CardEffects.EX8
  8. {
  9. public class Myotismon_EX8_060 : CEntity_Effect
  10. {
  11. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  12. {
  13. List<ICardEffect> cardEffects = new List<ICardEffect>();
  14. #region Alternate Digivolution
  15. if (timing == EffectTiming.None)
  16. {
  17. bool PermanentCondition(Permanent targetPermanent)
  18. {
  19. return targetPermanent.TopCard.IsLevel4 && targetPermanent.TopCard.EqualsTraits("NSo");
  20. }
  21. cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(
  22. permanentCondition: PermanentCondition,
  23. digivolutionCost: 3,
  24. ignoreDigivolutionRequirement: false,
  25. card: card,
  26. condition: null)
  27. );
  28. }
  29. #endregion
  30. #region When Attacking
  31. if (timing == EffectTiming.OnAllyAttack)
  32. {
  33. ActivateClass activateClass = new ActivateClass();
  34. activateClass.SetUpICardEffect("You may play 1 3 cost or less NSo Digimon", CanUseCondition, card);
  35. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDescription());
  36. cardEffects.Add(activateClass);
  37. string EffectDescription()
  38. {
  39. return "[When Attacking] You may play 1 [NSo] trait Digimon card with a play cost of 3 or less from your trash without paying the cost.";
  40. }
  41. bool DigimonToPlay(CardSource cardSource)
  42. {
  43. return CardEffectCommons.CanPlayAsNewPermanent(cardSource, false, activateClass, SelectCardEffect.Root.Trash) &&
  44. cardSource.IsDigimon &&
  45. cardSource.HasPlayCost &&
  46. cardSource.GetCostItself <= 3 &&
  47. cardSource.EqualsTraits("NSo");
  48. }
  49. bool CanUseCondition(Hashtable hashtable)
  50. {
  51. if(CardEffectCommons.IsExistOnBattleAreaDigimon(card))
  52. return CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  53. return false;
  54. }
  55. bool CanActivateCondition(Hashtable hashtable)
  56. {
  57. return CardEffectCommons.IsExistOnBattleAreaDigimon(card) &&
  58. CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, DigimonToPlay) &&
  59. card.Owner.MemoryForPlayer >= 1;
  60. }
  61. IEnumerator ActivateCoroutine(Hashtable hashtable)
  62. {
  63. List<CardSource> selectedCards = new List<CardSource>();
  64. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  65. selectCardEffect.SetUp(
  66. canTargetCondition: DigimonToPlay,
  67. canTargetCondition_ByPreSelecetedList: null,
  68. canEndSelectCondition: null,
  69. canNoSelect: () => true,
  70. selectCardCoroutine: null,
  71. afterSelectCardCoroutine: SelectCardCoroutine,
  72. message: "Select 1 level 4 or lower Digimon card to play.",
  73. maxCount: 1,
  74. canEndNotMax: false,
  75. isShowOpponent: true,
  76. mode: SelectCardEffect.Mode.Custom,
  77. root: SelectCardEffect.Root.Trash,
  78. customRootCardList: null,
  79. canLookReverseCard: true,
  80. selectPlayer: card.Owner,
  81. cardEffect: activateClass);
  82. selectCardEffect.SetUpCustomMessage(
  83. "Select 1 level 4 or lower Digimon card to play.",
  84. "The opponent is selecting 1 level 4 or lower Digimon card to play.");
  85. selectCardEffect.SetUpCustomMessage_ShowCard("Play Card");
  86. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  87. IEnumerator SelectCardCoroutine(List<CardSource> sources)
  88. {
  89. selectedCards = sources;
  90. yield return null;
  91. }
  92. if (selectedCards.Count > 0)
  93. {
  94. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(
  95. cardSources: selectedCards,
  96. activateClass: activateClass,
  97. payCost: false,
  98. isTapped: false,
  99. root: SelectCardEffect.Root.Trash,
  100. activateETB: true));
  101. }
  102. }
  103. }
  104. #endregion
  105. #region Your Turn
  106. if (timing == EffectTiming.OnEnterFieldAnyone)
  107. {
  108. ActivateClass activateClass = new ActivateClass();
  109. activateClass.SetUpICardEffect("DNA Digivolve.", CanUseCondition, card);
  110. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, true, EffectDescription());
  111. activateClass.SetHashString("DNADigivolve_EX8_060");
  112. cardEffects.Add(activateClass);
  113. string EffectDescription()
  114. {
  115. return "[Your Turn] [Once Per Turn] When your Digimon are played or digivolve, if any of them have the [NSo] trait, 2 of your Digimon may DNA digivolve into a Digimon card with the [NSo] trait in the hand. Then, that DNA digivolved Digimon may attack.";
  116. }
  117. bool PermanentConditionNSoEnterField(Permanent permanent)
  118. {
  119. if (CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card))
  120. {
  121. if (permanent.TopCard.CardTraits.Contains("NSo"))
  122. {
  123. return true;
  124. }
  125. }
  126. return false;
  127. }
  128. bool CanUseCondition(Hashtable hashtable)
  129. {
  130. if (CardEffectCommons.IsExistOnBattleArea(card))
  131. {
  132. if (CardEffectCommons.IsOwnerTurn(card))
  133. {
  134. if (CardEffectCommons.CanTriggerOnPermanentPlay(hashtable, PermanentConditionNSoEnterField))
  135. {
  136. return true;
  137. }
  138. if (CardEffectCommons.CanTriggerWhenPermanentDigivolving(hashtable, PermanentConditionNSoEnterField))
  139. {
  140. return true;
  141. }
  142. }
  143. }
  144. return false;
  145. }
  146. bool CanActivateCondition(Hashtable hashtable)
  147. {
  148. if (CardEffectCommons.IsExistOnBattleArea(card))
  149. {
  150. return true;
  151. }
  152. return false;
  153. }
  154. bool CanSelectDNACardCondition(CardSource cardSource)
  155. {
  156. return cardSource.IsDigimon &&
  157. cardSource.CanPlayJogress(true) &&
  158. cardSource.ContainsTraits("NSo");
  159. }
  160. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  161. {
  162. List<CardSource> selectedCards = new List<CardSource>();
  163. bool DNADigivolved = false;
  164. int maxCount = 1;
  165. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  166. selectHandEffect.SetUp(
  167. selectPlayer: card.Owner,
  168. canTargetCondition: CanSelectDNACardCondition,
  169. canTargetCondition_ByPreSelecetedList: null,
  170. canEndSelectCondition: null,
  171. maxCount: maxCount,
  172. canNoSelect: true,
  173. canEndNotMax: false,
  174. isShowOpponent: true,
  175. selectCardCoroutine: SelectCardCoroutine,
  176. afterSelectCardCoroutine: null,
  177. mode: SelectHandEffect.Mode.Custom,
  178. cardEffect: activateClass);
  179. selectHandEffect.SetUpCustomMessage("Select 1 card to DNA digivolve.",
  180. "The opponent is selecting 1 card to DNA digivolve.");
  181. selectHandEffect.SetNotShowCard();
  182. yield return StartCoroutine(selectHandEffect.Activate());
  183. IEnumerator SelectCardCoroutine(CardSource cardSource)
  184. {
  185. selectedCards.Add(cardSource);
  186. yield return null;
  187. }
  188. if (selectedCards.Count >= 1)
  189. {
  190. foreach (CardSource selectedCard in selectedCards)
  191. {
  192. if (selectedCard.CanPlayJogress(true))
  193. {
  194. _jogressEvoRootsFrameIDs = Array.Empty<int>();
  195. yield return GManager.instance.photonWaitController.StartWait("Myotismon_EX8_060");
  196. if (card.Owner.isYou || GManager.instance.IsAI)
  197. {
  198. GManager.instance.selectJogressEffect.SetUp_SelectDigivolutionRoots
  199. (card: selectedCard,
  200. isLocal: true,
  201. isPayCost: true,
  202. canNoSelect: true,
  203. endSelectCoroutine_SelectDigivolutionRoots: EndSelectCoroutineSelectDigivolutionRoots,
  204. noSelectCoroutine: null);
  205. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectJogressEffect
  206. .SelectDigivolutionRoots());
  207. IEnumerator EndSelectCoroutineSelectDigivolutionRoots(List<Permanent> permanents)
  208. {
  209. if (permanents.Count == 2)
  210. {
  211. _jogressEvoRootsFrameIDs = permanents.Distinct().ToArray()
  212. .Map(permanent => permanent.PermanentFrame.FrameID);
  213. }
  214. yield return null;
  215. }
  216. photonView.RPC("SetJogressEvoRootsFrameIDs", RpcTarget.All, _jogressEvoRootsFrameIDs);
  217. }
  218. else
  219. {
  220. GManager.instance.commandText.OpenCommandText("The opponent is choosing a card to DNA digivolve.");
  221. }
  222. yield return new WaitWhile(() => !_endSelect);
  223. _endSelect = false;
  224. GManager.instance.commandText.CloseCommandText();
  225. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  226. if (_jogressEvoRootsFrameIDs.Length == 2)
  227. {
  228. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>()
  229. .ShowCardEffect(new List<CardSource>() { selectedCard }, "Played Card", true, true));
  230. PlayCardClass playCard = new PlayCardClass(
  231. cardSources: new List<CardSource>() { selectedCard },
  232. hashtable: CardEffectCommons.CardEffectHashtable(activateClass),
  233. payCost: true,
  234. targetPermanent: null,
  235. isTapped: false,
  236. root: SelectCardEffect.Root.Hand,
  237. activateETB: true);
  238. playCard.SetJogress(_jogressEvoRootsFrameIDs);
  239. DNADigivolved = true;
  240. yield return ContinuousController.instance.StartCoroutine(playCard.PlayCard());
  241. }
  242. if (DNADigivolved)
  243. {
  244. List<SelectionElement<bool>> selectionElements = new List<SelectionElement<bool>>()
  245. {
  246. new SelectionElement<bool>(message: $"Yes", value: true, spriteIndex: 0),
  247. new SelectionElement<bool>(message: $"No", value: false, spriteIndex: 1),
  248. };
  249. string selectPlayerMessage = "Attack?";
  250. string notSelectPlayerMessage = "The opponent is choosing effects.";
  251. GManager.instance.userSelectionManager.SetBoolSelection(
  252. selectionElements: selectionElements, selectPlayer: card.Owner,
  253. selectPlayerMessage: selectPlayerMessage,
  254. notSelectPlayerMessage: notSelectPlayerMessage);
  255. yield return ContinuousController.instance.StartCoroutine(GManager.instance
  256. .userSelectionManager.WaitForEndSelect());
  257. bool willAttack = GManager.instance.userSelectionManager.SelectedBoolValue;
  258. if (willAttack)
  259. {
  260. yield return ContinuousController.instance.StartCoroutine(
  261. CardEffectCommons.ChangeDigimonSAttack(selectedCard.PermanentOfThisCard(), 1,
  262. EffectDuration.UntilEachTurnEnd, activateClass));
  263. if (selectedCard.PermanentOfThisCard() != null)
  264. {
  265. if (selectedCard.PermanentOfThisCard().CanAttack(activateClass))
  266. {
  267. SelectAttackEffect selectAttackEffect =
  268. GManager.instance.GetComponent<SelectAttackEffect>();
  269. selectAttackEffect.SetUp(
  270. attacker: selectedCard.PermanentOfThisCard(),
  271. canAttackPlayerCondition: () => true,
  272. defenderCondition: (permanent) => true,
  273. cardEffect: activateClass);
  274. selectAttackEffect.SetCanNotSelectNotAttack();
  275. yield return ContinuousController.instance.StartCoroutine(selectAttackEffect
  276. .Activate());
  277. }
  278. }
  279. }
  280. }
  281. }
  282. }
  283. }
  284. }
  285. }
  286. #endregion
  287. #region Inherited Effect
  288. if (timing == EffectTiming.OnAllyAttack)
  289. {
  290. ActivateClass activateClass = new ActivateClass();
  291. activateClass.SetUpICardEffect("Delete your another Digimon to unsuspend this Digimon", CanUseCondition, card);
  292. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, true, EffectDescription());
  293. activateClass.SetIsInheritedEffect(true);
  294. activateClass.SetHashString("Unsuspend_EX8_060");
  295. cardEffects.Add(activateClass);
  296. string EffectDescription()
  297. {
  298. return "[When Attacking] [Once Per Turn] By deleting 1 of your other Digimon, this Digimon unsuspends.";
  299. }
  300. bool CanSelectPermanentCondition(Permanent permanent)
  301. {
  302. if (CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card))
  303. {
  304. if (permanent != card.PermanentOfThisCard())
  305. {
  306. return true;
  307. }
  308. }
  309. return false;
  310. }
  311. bool CanUseCondition(Hashtable hashtable)
  312. {
  313. return CardEffectCommons.CanTriggerOnAttack(hashtable, card);
  314. }
  315. bool CanActivateCondition(Hashtable hashtable)
  316. {
  317. if (CardEffectCommons.IsExistOnBattleArea(card))
  318. {
  319. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  320. {
  321. return true;
  322. }
  323. }
  324. return false;
  325. }
  326. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  327. {
  328. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  329. {
  330. int maxCount = Math.Min(1, card.Owner.GetBattleAreaDigimons().Count(CanSelectPermanentCondition));
  331. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  332. selectPermanentEffect.SetUp(
  333. selectPlayer: card.Owner,
  334. canTargetCondition: CanSelectPermanentCondition,
  335. canTargetCondition_ByPreSelecetedList: null,
  336. canEndSelectCondition: null,
  337. maxCount: maxCount,
  338. canNoSelect: true,
  339. canEndNotMax: false,
  340. selectPermanentCoroutine: SelectPermanentCoroutine,
  341. afterSelectPermanentCoroutine: null,
  342. mode: SelectPermanentEffect.Mode.Custom,
  343. cardEffect: activateClass);
  344. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon to delete.", "The opponent is selecting 1 Digimon to delete.");
  345. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  346. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  347. {
  348. Permanent thisCardPermanent = card.PermanentOfThisCard();
  349. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.DeletePeremanentAndProcessAccordingToResult(targetPermanents: new List<Permanent>() { permanent },
  350. activateClass: activateClass,
  351. successProcess: permanents => SuccessProcess(),
  352. failureProcess: null));
  353. IEnumerator SuccessProcess()
  354. {
  355. if (thisCardPermanent.TopCard != null)
  356. {
  357. yield return ContinuousController.instance.StartCoroutine(new IUnsuspendPermanents(new List<Permanent>() { thisCardPermanent }, activateClass).Unsuspend());
  358. }
  359. }
  360. }
  361. }
  362. }
  363. }
  364. #endregion
  365. return cardEffects;
  366. }
  367. #region Photon DNA
  368. bool _endSelect;
  369. int[] _jogressEvoRootsFrameIDs = Array.Empty<int>();
  370. [PunRPC]
  371. public void SetJogressEvoRootsFrameIDs(int[] jogressEvoRootsFrameIDs)
  372. {
  373. this._jogressEvoRootsFrameIDs = jogressEvoRootsFrameIDs;
  374. _endSelect = true;
  375. }
  376. #endregion
  377. }
  378. }