EX3_008.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. using Photon.Pun;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using UnityEngine;
  7. namespace DCGO.CardEffects.EX3
  8. {
  9. public class EX3_008 : CEntity_Effect
  10. {
  11. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  12. {
  13. List<ICardEffect> cardEffects = new List<ICardEffect>();
  14. if (timing == EffectTiming.OnEnterFieldAnyone)
  15. {
  16. ActivateClass activateClass = new ActivateClass();
  17. activateClass.SetUpICardEffect("Select Effects", CanUseCondition, card);
  18. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDiscription());
  19. cardEffects.Add(activateClass);
  20. string EffectDiscription()
  21. {
  22. return "[When Digivolving] Activate 1 of the effects below. - You may digivolve 1 of your other Digimon into a level 4 purple Digimon card with [Free] in its traits from your trash for the cost. - You may DNA digivolve this Digimon and one of your other Digimon in play into a Digimon card in your hand for the cost.";
  23. }
  24. bool CanSelectPermanentCondition(Permanent permanent)
  25. {
  26. if (CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card))
  27. {
  28. if (permanent != card.PermanentOfThisCard())
  29. {
  30. foreach (CardSource cardSource in permanent.TopCard.Owner.TrashCards)
  31. {
  32. if (CanSelectCardCondition(cardSource))
  33. {
  34. if (cardSource.CanPlayCardTargetFrame(permanent.PermanentFrame, false, activateClass, root: SelectCardEffect.Root.Trash))
  35. {
  36. return true;
  37. }
  38. }
  39. }
  40. }
  41. }
  42. return false;
  43. }
  44. bool CanSelectCardCondition(CardSource cardSource)
  45. {
  46. if (cardSource.IsDigimon)
  47. {
  48. if (cardSource.Level == 4)
  49. {
  50. if (cardSource.HasLevel)
  51. {
  52. if (cardSource.CardColors.Contains(CardColor.Purple))
  53. {
  54. if (cardSource.CardTraits.Contains("Free"))
  55. {
  56. return true;
  57. }
  58. }
  59. }
  60. }
  61. }
  62. return false;
  63. }
  64. bool CanSelectCardCondition1(CardSource cardSource)
  65. {
  66. if (cardSource != null)
  67. {
  68. if (cardSource.IsDigimon)
  69. {
  70. if (cardSource.Owner == card.Owner)
  71. {
  72. if (cardSource.CanPlayJogress(true))
  73. {
  74. if (isExistOnField(card))
  75. {
  76. if (cardSource.CanJogressFromTargetPermanent(card.PermanentOfThisCard(), true))
  77. {
  78. return true;
  79. }
  80. }
  81. }
  82. }
  83. }
  84. }
  85. return false;
  86. }
  87. bool CanUseCondition(Hashtable hashtable)
  88. {
  89. return CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  90. }
  91. bool CanActivateCondition(Hashtable hashtable)
  92. {
  93. if (CardEffectCommons.IsExistOnBattleArea(card))
  94. {
  95. return true;
  96. }
  97. return false;
  98. }
  99. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  100. {
  101. List<SelectionElement<bool>> selectionElements = new List<SelectionElement<bool>>()
  102. {
  103. new SelectionElement<bool>(message: $"Digivolve into trash Digimon", value : true, spriteIndex: 0),
  104. new SelectionElement<bool>(message: $"DNA Digivolve", value : false, spriteIndex: 1),
  105. };
  106. string selectPlayerMessage = "Which effect will you activate?";
  107. string notSelectPlayerMessage = "The opponent is choosing which effect to activate.";
  108. GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: selectionElements, selectPlayer: card.Owner, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  109. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  110. bool fromTrash = GManager.instance.userSelectionManager.SelectedBoolValue;
  111. if (fromTrash)
  112. {
  113. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  114. {
  115. Permanent selectedPermanent = null;
  116. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  117. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  118. selectPermanentEffect.SetUp(
  119. selectPlayer: card.Owner,
  120. canTargetCondition: CanSelectPermanentCondition,
  121. canTargetCondition_ByPreSelecetedList: null,
  122. canEndSelectCondition: null,
  123. maxCount: maxCount,
  124. canNoSelect: false,
  125. canEndNotMax: false,
  126. selectPermanentCoroutine: SelectPermanentCoroutine,
  127. afterSelectPermanentCoroutine: null,
  128. mode: SelectPermanentEffect.Mode.Custom,
  129. cardEffect: activateClass);
  130. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon that will digivolve.", "The opponent is selecting 1 Digimon that will digivolve.");
  131. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  132. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  133. {
  134. selectedPermanent = permanent;
  135. yield return null;
  136. }
  137. if (selectedPermanent != null)
  138. {
  139. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.DigivolveIntoHandOrTrashCard(
  140. targetPermanent: selectedPermanent,
  141. cardCondition: CanSelectCardCondition,
  142. payCost: true,
  143. reduceCostTuple: null,
  144. fixedCostTuple: null,
  145. ignoreDigivolutionRequirementFixedCost: -1,
  146. isHand: false,
  147. activateClass: activateClass,
  148. successProcess: null));
  149. }
  150. }
  151. }
  152. else
  153. {
  154. if (CardEffectCommons.HasMatchConditionOwnersPermanent(card, (permanent) => permanent.IsDigimon && permanent != card.PermanentOfThisCard()))
  155. {
  156. if (card.Owner.HandCards.Count(CanSelectCardCondition1) >= 1)
  157. {
  158. List<CardSource> selectedCards = new List<CardSource>();
  159. int maxCount = 1;
  160. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  161. selectHandEffect.SetUp(
  162. selectPlayer: card.Owner,
  163. canTargetCondition: CanSelectCardCondition1,
  164. canTargetCondition_ByPreSelecetedList: null,
  165. canEndSelectCondition: null,
  166. maxCount: maxCount,
  167. canNoSelect: true,
  168. canEndNotMax: false,
  169. isShowOpponent: true,
  170. selectCardCoroutine: SelectCardCoroutine,
  171. afterSelectCardCoroutine: null,
  172. mode: SelectHandEffect.Mode.Custom,
  173. cardEffect: activateClass);
  174. selectHandEffect.SetUpCustomMessage("Select 1 card to DNA digivolve.", "The opponent is selecting 1 card to DNA digivolve.");
  175. selectHandEffect.SetNotShowCard();
  176. yield return StartCoroutine(selectHandEffect.Activate());
  177. IEnumerator SelectCardCoroutine(CardSource cardSource)
  178. {
  179. selectedCards.Add(cardSource);
  180. yield return null;
  181. }
  182. if (selectedCards.Count >= 1)
  183. {
  184. foreach (CardSource selectedCard in selectedCards)
  185. {
  186. if (selectedCard.CanPlayJogress(true) && selectedCard.CanJogressFromTargetPermanent(card.PermanentOfThisCard(), true))
  187. {
  188. JogressEvoRootsFrameIDs = new int[0];
  189. yield return GManager.instance.photonWaitController.StartWait("Shadramon_EX3_058");
  190. if (card.Owner.isYou || GManager.instance.IsAI)
  191. {
  192. GManager.instance.selectJogressEffect.SetUp_SelectDigivolutionRoots
  193. (card: selectedCard,
  194. isLocal: true,
  195. isPayCost: true,
  196. canNoSelect: true,
  197. endSelectCoroutine_SelectDigivolutionRoots: EndSelectCoroutine_SelectDigivolutionRoots,
  198. noSelectCoroutine: null);
  199. GManager.instance.selectJogressEffect.SetUpCustomPermanentConditions(new Func<Permanent, bool>[] { (permanent) => permanent == card.PermanentOfThisCard() });
  200. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectJogressEffect.SelectDigivolutionRoots());
  201. IEnumerator EndSelectCoroutine_SelectDigivolutionRoots(List<Permanent> permanents)
  202. {
  203. permanents = permanents.Distinct().ToList();
  204. if (permanents.Count == 2)
  205. {
  206. JogressEvoRootsFrameIDs = new int[2];
  207. for (int i = 0; i < permanents.Count; i++)
  208. {
  209. if (i < JogressEvoRootsFrameIDs.Length)
  210. {
  211. JogressEvoRootsFrameIDs[i] = permanents[i].PermanentFrame.FrameID;
  212. }
  213. }
  214. }
  215. if (!permanents.Contains(card.PermanentOfThisCard()))
  216. {
  217. JogressEvoRootsFrameIDs = new int[0];
  218. }
  219. yield return null;
  220. }
  221. photonView.RPC("SetJogressEvoRootsFrameIDs", RpcTarget.All, JogressEvoRootsFrameIDs);
  222. }
  223. else
  224. {
  225. GManager.instance.commandText.OpenCommandText("The opponent is choosing a card to DNA digivolve.");
  226. }
  227. yield return new WaitWhile(() => !endSelect);
  228. endSelect = false;
  229. GManager.instance.commandText.CloseCommandText();
  230. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  231. if (JogressEvoRootsFrameIDs.Length == 2)
  232. {
  233. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { selectedCard }, "Played Card", true, true));
  234. PlayCardClass playCard = new PlayCardClass(
  235. cardSources: new List<CardSource>() { selectedCard },
  236. hashtable: CardEffectCommons.CardEffectHashtable(activateClass),
  237. payCost: true,
  238. targetPermanent: null,
  239. isTapped: false,
  240. root: SelectCardEffect.Root.Hand,
  241. activateETB: true);
  242. playCard.SetJogress(JogressEvoRootsFrameIDs);
  243. yield return ContinuousController.instance.StartCoroutine(playCard.PlayCard());
  244. }
  245. }
  246. }
  247. }
  248. }
  249. }
  250. }
  251. }
  252. }
  253. if (timing == EffectTiming.OnEndTurn)
  254. {
  255. ActivateClass activateClass = new ActivateClass();
  256. activateClass.SetUpICardEffect("DNA digivolve this Digimon", CanUseCondition, card);
  257. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  258. activateClass.SetIsInheritedEffect(true);
  259. cardEffects.Add(activateClass);
  260. string EffectDiscription()
  261. {
  262. return "[End of Your Turn] You may DNA digivolve this Digimon and one of your other Digimon in play into a Digimon card in your hand by paying its DNA digivolve cost.";
  263. }
  264. bool CanSelectCardCondition(CardSource cardSource)
  265. {
  266. if (cardSource != null)
  267. {
  268. if (cardSource.IsDigimon)
  269. {
  270. if (cardSource.Owner == card.Owner)
  271. {
  272. if (cardSource.CanPlayJogress(true))
  273. {
  274. if (isExistOnField(card))
  275. {
  276. if (cardSource.CanJogressFromTargetPermanent(card.PermanentOfThisCard(), true))
  277. {
  278. return true;
  279. }
  280. }
  281. }
  282. }
  283. }
  284. }
  285. return false;
  286. }
  287. bool CanUseCondition(Hashtable hashtable)
  288. {
  289. if (isExistOnField(card))
  290. {
  291. return true;
  292. }
  293. return false;
  294. }
  295. bool CanActivateCondition(Hashtable hashtable)
  296. {
  297. if (CardEffectCommons.IsExistOnBattleArea(card))
  298. {
  299. if (CardEffectCommons.IsOwnerTurn(card))
  300. {
  301. if (card.Owner.HandCards.Count >= 1)
  302. {
  303. if (CardEffectCommons.HasMatchConditionOwnersPermanent(card, (permanent) => permanent.IsDigimon && permanent != card.PermanentOfThisCard()))
  304. {
  305. return true;
  306. }
  307. }
  308. }
  309. }
  310. return false;
  311. }
  312. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  313. {
  314. if (isExistOnField(card))
  315. {
  316. if (card.Owner.GetBattleAreaDigimons().Contains(card.PermanentOfThisCard()))
  317. {
  318. if (card.Owner.HandCards.Count(CanSelectCardCondition) >= 1)
  319. {
  320. List<CardSource> selectedCards = new List<CardSource>();
  321. int maxCount = 1;
  322. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  323. selectHandEffect.SetUp(
  324. selectPlayer: card.Owner,
  325. canTargetCondition: CanSelectCardCondition,
  326. canTargetCondition_ByPreSelecetedList: null,
  327. canEndSelectCondition: null,
  328. maxCount: maxCount,
  329. canNoSelect: true,
  330. canEndNotMax: false,
  331. isShowOpponent: true,
  332. selectCardCoroutine: SelectCardCoroutine,
  333. afterSelectCardCoroutine: null,
  334. mode: SelectHandEffect.Mode.Custom,
  335. cardEffect: activateClass);
  336. selectHandEffect.SetUpCustomMessage("Select 1 card to DNA digivolve.", "The opponent is selecting 1 card to DNA digivolve.");
  337. selectHandEffect.SetNotShowCard();
  338. yield return StartCoroutine(selectHandEffect.Activate());
  339. IEnumerator SelectCardCoroutine(CardSource cardSource)
  340. {
  341. selectedCards.Add(cardSource);
  342. yield return null;
  343. }
  344. if (selectedCards.Count >= 1)
  345. {
  346. foreach (CardSource selectedCard in selectedCards)
  347. {
  348. if (selectedCard.CanPlayJogress(true) && selectedCard.CanJogressFromTargetPermanent(card.PermanentOfThisCard(), true))
  349. {
  350. JogressEvoRootsFrameIDs = new int[0];
  351. yield return GManager.instance.photonWaitController.StartWait("Flaedramon_EX3_008");
  352. if (card.Owner.isYou || GManager.instance.IsAI)
  353. {
  354. GManager.instance.selectJogressEffect.SetUp_SelectDigivolutionRoots
  355. (card: selectedCard,
  356. isLocal: true,
  357. isPayCost: true,
  358. canNoSelect: true,
  359. endSelectCoroutine_SelectDigivolutionRoots: EndSelectCoroutine_SelectDigivolutionRoots,
  360. noSelectCoroutine: null);
  361. GManager.instance.selectJogressEffect.SetUpCustomPermanentConditions(new Func<Permanent, bool>[] { (permanent) => permanent == card.PermanentOfThisCard() });
  362. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectJogressEffect.SelectDigivolutionRoots());
  363. IEnumerator EndSelectCoroutine_SelectDigivolutionRoots(List<Permanent> permanents)
  364. {
  365. permanents = permanents.Distinct().ToList();
  366. if (permanents.Count == 2)
  367. {
  368. JogressEvoRootsFrameIDs = new int[2];
  369. for (int i = 0; i < permanents.Count; i++)
  370. {
  371. if (i < JogressEvoRootsFrameIDs.Length)
  372. {
  373. JogressEvoRootsFrameIDs[i] = permanents[i].PermanentFrame.FrameID;
  374. }
  375. }
  376. }
  377. if (!permanents.Contains(card.PermanentOfThisCard()))
  378. {
  379. JogressEvoRootsFrameIDs = new int[0];
  380. }
  381. yield return null;
  382. }
  383. photonView.RPC("SetJogressEvoRootsFrameIDs", RpcTarget.All, JogressEvoRootsFrameIDs);
  384. }
  385. else
  386. {
  387. GManager.instance.commandText.OpenCommandText("The opponent is choosing a card to DNA digivolve.");
  388. }
  389. yield return new WaitWhile(() => !endSelect);
  390. endSelect = false;
  391. GManager.instance.commandText.CloseCommandText();
  392. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  393. if (JogressEvoRootsFrameIDs.Length == 2)
  394. {
  395. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { selectedCard }, "Played Card", true, true));
  396. PlayCardClass playCard = new PlayCardClass(
  397. cardSources: new List<CardSource>() { selectedCard },
  398. hashtable: CardEffectCommons.CardEffectHashtable(activateClass),
  399. payCost: true,
  400. targetPermanent: null,
  401. isTapped: false,
  402. root: SelectCardEffect.Root.Hand,
  403. activateETB: true);
  404. playCard.SetJogress(JogressEvoRootsFrameIDs);
  405. yield return ContinuousController.instance.StartCoroutine(playCard.PlayCard());
  406. }
  407. }
  408. }
  409. }
  410. }
  411. }
  412. }
  413. }
  414. }
  415. return cardEffects;
  416. }
  417. bool endSelect = false;
  418. int[] JogressEvoRootsFrameIDs = new int[0];
  419. [PunRPC]
  420. public void SetJogressEvoRootsFrameIDs(int[] JogressEvoRootsFrameIDs)
  421. {
  422. this.JogressEvoRootsFrameIDs = JogressEvoRootsFrameIDs;
  423. endSelect = true;
  424. }
  425. }
  426. }