EX2_044.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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.EX2
  8. {
  9. public class EX2_044 : 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.OnDiscardLibrary)
  15. {
  16. ActivateClass activateClass = new ActivateClass();
  17. activateClass.SetUpICardEffect("Play 1 [Impmon] from trash", CanUseCondition, card);
  18. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  19. cardEffects.Add(activateClass);
  20. string EffectDiscription()
  21. {
  22. return "When this card is trashed from your deck, you may play 1 [Impmon] from your trash without paying its memory cost.";
  23. }
  24. bool CanSelectCardCondition(CardSource cardSource)
  25. {
  26. if (CardEffectCommons.CanPlayAsNewPermanent(cardSource: cardSource, payCost: false, cardEffect: activateClass))
  27. {
  28. if (cardSource.CardNames.Contains("Impmon"))
  29. {
  30. return true;
  31. }
  32. }
  33. return false;
  34. }
  35. bool CanUseCondition(Hashtable hashtable)
  36. {
  37. return CardEffectCommons.CanTriggerWhenSelfDiscardLibrary(hashtable, card);
  38. }
  39. bool CanActivateCondition(Hashtable hashtable)
  40. {
  41. if (CardEffectCommons.IsExistOnTrash(card))
  42. {
  43. if (CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, (cardSource) => CanSelectCardCondition(cardSource)))
  44. {
  45. return true;
  46. }
  47. }
  48. return false;
  49. }
  50. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  51. {
  52. if (CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, (cardSource) => CanSelectCardCondition(cardSource)))
  53. {
  54. int maxCount = Math.Min(1, card.Owner.TrashCards.Count((cardSource) => CanSelectCardCondition(cardSource)));
  55. List<CardSource> selectedCards = new List<CardSource>();
  56. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  57. selectCardEffect.SetUp(
  58. canTargetCondition: CanSelectCardCondition,
  59. canTargetCondition_ByPreSelecetedList: null,
  60. canEndSelectCondition: null,
  61. canNoSelect: () => true,
  62. selectCardCoroutine: SelectCardCoroutine,
  63. afterSelectCardCoroutine: null,
  64. message: "Select 1 card to play.",
  65. maxCount: maxCount,
  66. canEndNotMax: false,
  67. isShowOpponent: true,
  68. mode: SelectCardEffect.Mode.Custom,
  69. root: SelectCardEffect.Root.Trash,
  70. customRootCardList: null,
  71. canLookReverseCard: true,
  72. selectPlayer: card.Owner,
  73. cardEffect: activateClass);
  74. selectCardEffect.SetUpCustomMessage("Select 1 card to play.", "The opponent is selecting 1 card to play.");
  75. selectCardEffect.SetUpCustomMessage_ShowCard("Played Card");
  76. yield return StartCoroutine(selectCardEffect.Activate());
  77. IEnumerator SelectCardCoroutine(CardSource cardSource)
  78. {
  79. selectedCards.Add(cardSource);
  80. yield return null;
  81. }
  82. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(cardSources: selectedCards, activateClass: activateClass, payCost: false, isTapped: false, root: SelectCardEffect.Root.Trash, activateETB: true));
  83. }
  84. }
  85. }
  86. if (timing == EffectTiming.OnEnterFieldAnyone)
  87. {
  88. ActivateClass activateClass = new ActivateClass();
  89. activateClass.SetUpICardEffect("Trash 2 cards from deck top and delete 1 Digimon", CanUseCondition, card);
  90. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDiscription());
  91. cardEffects.Add(activateClass);
  92. string EffectDiscription()
  93. {
  94. return "[When Digivolving] You may trash the top 2 cards of your deck. Then, delete 1 of your opponent's level 3 or lower Digimon. For every 10 cards in your trash, add 1 to the maximum level of the Digimon you can choose with this effect.";
  95. }
  96. bool CanSelectPermanentCondition(Permanent permanent)
  97. {
  98. if (permanent != null)
  99. {
  100. if (permanent.TopCard != null)
  101. {
  102. if (permanent.IsDigimon)
  103. {
  104. if (permanent.TopCard.Owner == card.Owner.Enemy)
  105. {
  106. if (permanent.TopCard.Owner.GetBattleAreaPermanents().Contains(permanent))
  107. {
  108. int maxLevel = 3 + card.Owner.TrashCards.Count / 10;
  109. if (permanent.Level <= maxLevel)
  110. {
  111. if (permanent.TopCard.HasLevel)
  112. {
  113. return true;
  114. }
  115. }
  116. }
  117. }
  118. }
  119. }
  120. }
  121. return false;
  122. }
  123. bool CanUseCondition(Hashtable hashtable)
  124. {
  125. return CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  126. }
  127. bool CanActivateCondition(Hashtable hashtable)
  128. {
  129. if (CardEffectCommons.IsExistOnBattleArea(card))
  130. {
  131. return true;
  132. }
  133. return false;
  134. }
  135. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  136. {
  137. if (isExistOnField(card))
  138. {
  139. if (card.Owner.GetBattleAreaDigimons().Contains(card.PermanentOfThisCard()))
  140. {
  141. if (card.Owner.LibraryCards.Count >= 1)
  142. {
  143. if (card.Owner.isYou)
  144. {
  145. GManager.instance.commandText.OpenCommandText("Will you trash the top cards of your deck?");
  146. List<Command_SelectCommand> command_SelectCommands = new List<Command_SelectCommand>()
  147. {
  148. new Command_SelectCommand($"Trash", () => photonView.RPC("SetDoTrash", RpcTarget.All, true), 0),
  149. new Command_SelectCommand($"Not trash", () => photonView.RPC("SetDoTrash", RpcTarget.All, false), 1),
  150. };
  151. GManager.instance.selectCommandPanel.SetUpCommandButton(command_SelectCommands);
  152. }
  153. else
  154. {
  155. GManager.instance.commandText.OpenCommandText("The opponent is choosing whether to trash the top cards of deck.");
  156. #region AI���[�h
  157. if (GManager.instance.IsAI)
  158. {
  159. SetDoTrash(RandomUtility.IsSucceedProbability(0.5f));
  160. }
  161. #endregion
  162. }
  163. yield return new WaitWhile(() => !endSelect);
  164. endSelect = false;
  165. GManager.instance.commandText.CloseCommandText();
  166. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  167. if (doTrash)
  168. {
  169. yield return ContinuousController.instance.StartCoroutine(new IAddTrashCardsFromLibraryTop(2, card.Owner, activateClass).AddTrashCardsFromLibraryTop());
  170. }
  171. }
  172. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  173. {
  174. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  175. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  176. selectPermanentEffect.SetUp(
  177. selectPlayer: card.Owner,
  178. canTargetCondition: CanSelectPermanentCondition,
  179. canTargetCondition_ByPreSelecetedList: null,
  180. canEndSelectCondition: null,
  181. maxCount: maxCount,
  182. canNoSelect: false,
  183. canEndNotMax: false,
  184. selectPermanentCoroutine: null,
  185. afterSelectPermanentCoroutine: null,
  186. mode: SelectPermanentEffect.Mode.Destroy,
  187. cardEffect: activateClass);
  188. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  189. }
  190. }
  191. }
  192. }
  193. }
  194. if (timing == EffectTiming.OnAllyAttack)
  195. {
  196. ActivateClass activateClass = new ActivateClass();
  197. activateClass.SetUpICardEffect("Trash 2 cards from deck top and delete 1 Digimon", CanUseCondition, card);
  198. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDiscription());
  199. cardEffects.Add(activateClass);
  200. string EffectDiscription()
  201. {
  202. return "[When Attacking] You may trash the top 2 cards of your deck. Then, delete 1 of your opponent's level 3 or lower Digimon. For every 10 cards in your trash, add 1 to the maximum level of the Digimon you can choose with this effect.";
  203. }
  204. bool CanSelectPermanentCondition(Permanent permanent)
  205. {
  206. if (permanent != null)
  207. {
  208. if (permanent.TopCard != null)
  209. {
  210. if (permanent.IsDigimon)
  211. {
  212. if (permanent.TopCard.Owner == card.Owner.Enemy)
  213. {
  214. if (permanent.TopCard.Owner.GetBattleAreaPermanents().Contains(permanent))
  215. {
  216. int maxLevel = 3 + card.Owner.TrashCards.Count / 10;
  217. if (permanent.Level <= maxLevel)
  218. {
  219. if (permanent.TopCard.HasLevel)
  220. {
  221. return true;
  222. }
  223. }
  224. }
  225. }
  226. }
  227. }
  228. }
  229. return false;
  230. }
  231. bool CanUseCondition(Hashtable hashtable)
  232. {
  233. return CardEffectCommons.CanTriggerOnAttack(hashtable, card);
  234. }
  235. bool CanActivateCondition(Hashtable hashtable)
  236. {
  237. if (CardEffectCommons.IsExistOnBattleArea(card))
  238. {
  239. return true;
  240. }
  241. return false;
  242. }
  243. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  244. {
  245. if (isExistOnField(card))
  246. {
  247. if (card.Owner.GetBattleAreaDigimons().Contains(card.PermanentOfThisCard()))
  248. {
  249. if (card.Owner.LibraryCards.Count >= 1)
  250. {
  251. if (card.Owner.isYou)
  252. {
  253. GManager.instance.commandText.OpenCommandText("Will you trash the top cards of your deck?");
  254. List<Command_SelectCommand> command_SelectCommands = new List<Command_SelectCommand>()
  255. {
  256. new Command_SelectCommand($"Trash", () => photonView.RPC("SetDoTrash", RpcTarget.All, true), 0),
  257. new Command_SelectCommand($"Not trash", () => photonView.RPC("SetDoTrash", RpcTarget.All, false), 1),
  258. };
  259. GManager.instance.selectCommandPanel.SetUpCommandButton(command_SelectCommands);
  260. }
  261. else
  262. {
  263. GManager.instance.commandText.OpenCommandText("The opponent is choosing whether to trash the top cards of deck.");
  264. #region AI���[�h
  265. if (GManager.instance.IsAI)
  266. {
  267. SetDoTrash(RandomUtility.IsSucceedProbability(0.5f));
  268. }
  269. #endregion
  270. }
  271. yield return new WaitWhile(() => !endSelect);
  272. endSelect = false;
  273. GManager.instance.commandText.CloseCommandText();
  274. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  275. if (doTrash)
  276. {
  277. yield return ContinuousController.instance.StartCoroutine(new IAddTrashCardsFromLibraryTop(2, card.Owner, activateClass).AddTrashCardsFromLibraryTop());
  278. }
  279. }
  280. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  281. {
  282. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  283. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  284. selectPermanentEffect.SetUp(
  285. selectPlayer: card.Owner,
  286. canTargetCondition: CanSelectPermanentCondition,
  287. canTargetCondition_ByPreSelecetedList: null,
  288. canEndSelectCondition: null,
  289. maxCount: maxCount,
  290. canNoSelect: false,
  291. canEndNotMax: false,
  292. selectPermanentCoroutine: null,
  293. afterSelectPermanentCoroutine: null,
  294. mode: SelectPermanentEffect.Mode.Destroy,
  295. cardEffect: activateClass);
  296. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  297. }
  298. }
  299. }
  300. }
  301. }
  302. return cardEffects;
  303. }
  304. bool endSelect = false;
  305. bool doTrash = false;
  306. [PunRPC]
  307. public void SetDoTrash(bool doTrash)
  308. {
  309. this.doTrash = doTrash;
  310. endSelect = true;
  311. }
  312. }
  313. }