BT19_099.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. using Photon.Pun;
  7. namespace DCGO.CardEffects.BT19
  8. {
  9. public class BT19_099 : CEntity_Effect
  10. {
  11. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  12. {
  13. List<ICardEffect> cardEffects = new List<ICardEffect>();
  14. #region Main
  15. if (timing == EffectTiming.OptionSkill)
  16. {
  17. ActivateClass activateClass = new ActivateClass();
  18. activateClass.SetUpICardEffect("Play 1 [Composite] trait Digimon card from your trash with the play cost reduced by 4.", CanUseCondition, card);
  19. activateClass.SetUpActivateClass(null, ActivateCoroutine, -1, false, EffectDiscription());
  20. cardEffects.Add(activateClass);
  21. string EffectDiscription()
  22. {
  23. return "[Main] You may play 1 [Composite] trait Digimon card from your trash with the play cost reduced by 4. Then, place this card in the battle area.";
  24. }
  25. bool HasCompositeTrait(CardSource cardSource)
  26. {
  27. if (cardSource.IsDigimon)
  28. return cardSource.ContainsTraits("Composite");
  29. return false;
  30. }
  31. bool CanUseCondition(Hashtable hashtable)
  32. {
  33. return CardEffectCommons.CanTriggerOptionMainEffect(hashtable, card);
  34. }
  35. IEnumerator ActivateCoroutine(Hashtable hashtable)
  36. {
  37. if(CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, HasCompositeTrait))
  38. {
  39. #region reduce play cost
  40. ChangeCostClass changeCostClass = new ChangeCostClass();
  41. changeCostClass.SetUpICardEffect($"Play Cost -4", CanUseCondition1, card);
  42. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardSourceCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  43. Func<EffectTiming, ICardEffect> getCardEffect = GetCardEffect;
  44. card.Owner.UntilCalculateFixedCostEffect.Add(getCardEffect);
  45. ICardEffect GetCardEffect(EffectTiming _timing)
  46. {
  47. if (_timing == EffectTiming.None)
  48. {
  49. return changeCostClass;
  50. }
  51. return null;
  52. }
  53. bool CanUseCondition1(Hashtable hashtable)
  54. {
  55. return true;
  56. }
  57. int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  58. {
  59. if (CardSourceCondition(cardSource))
  60. {
  61. if (RootCondition(root))
  62. {
  63. if (PermanentsCondition(targetPermanents))
  64. {
  65. Cost -= 4;
  66. }
  67. }
  68. }
  69. return Cost;
  70. }
  71. bool PermanentsCondition(List<Permanent> targetPermanents)
  72. {
  73. if (targetPermanents == null)
  74. {
  75. return true;
  76. }
  77. else
  78. {
  79. if (targetPermanents.Count((targetPermanent) => targetPermanent != null) == 0)
  80. {
  81. return true;
  82. }
  83. }
  84. return false;
  85. }
  86. bool CardSourceCondition(CardSource cardSource)
  87. {
  88. if (cardSource.HasPlayCost)
  89. {
  90. if (cardSource.IsDigimon)
  91. return cardSource.ContainsTraits("Composite");
  92. }
  93. return false;
  94. }
  95. bool RootCondition(SelectCardEffect.Root root)
  96. {
  97. return true;
  98. }
  99. bool isUpDown()
  100. {
  101. return true;
  102. }
  103. #endregion
  104. List<CardSource> selectedCards = new List<CardSource>();
  105. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  106. selectCardEffect.SetUp(
  107. canTargetCondition: HasCompositeTrait,
  108. canTargetCondition_ByPreSelecetedList: null,
  109. canEndSelectCondition: null,
  110. canNoSelect: () => true,
  111. selectCardCoroutine: null,
  112. afterSelectCardCoroutine: SelectCardCoroutine,
  113. message: "Select 1 [Composite] trait Digimon card to play.",
  114. maxCount: 1,
  115. canEndNotMax: false,
  116. isShowOpponent: true,
  117. mode: SelectCardEffect.Mode.Custom,
  118. root: SelectCardEffect.Root.Trash,
  119. customRootCardList: null,
  120. canLookReverseCard: true,
  121. selectPlayer: card.Owner,
  122. cardEffect: activateClass);
  123. selectCardEffect.SetUpCustomMessage(
  124. "Select 1 [Composite] trait Digimon card to play.",
  125. "The opponent is selecting 1 [Composite] trait Digimon card to play.");
  126. selectCardEffect.SetUpCustomMessage_ShowCard("Play Card");
  127. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  128. IEnumerator SelectCardCoroutine(List<CardSource> sources)
  129. {
  130. selectedCards = sources;
  131. yield return null;
  132. }
  133. #region Place As Source
  134. if (selectedCards.Count > 0)
  135. {
  136. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(
  137. cardSources: selectedCards,
  138. activateClass: activateClass,
  139. payCost: true,
  140. isTapped: false,
  141. root: SelectCardEffect.Root.Trash,
  142. activateETB: true));
  143. }
  144. #endregion
  145. #region Remove Cost effect after use
  146. card.Owner.UntilCalculateFixedCostEffect.Remove(getCardEffect);
  147. #endregion
  148. }
  149. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlaceDelayOptionCards(card: card, cardEffect: activateClass));
  150. }
  151. }
  152. #endregion
  153. #region All Turns - Delay
  154. if (timing == EffectTiming.WhenRemoveField)
  155. {
  156. ActivateClass activateClass = new ActivateClass();
  157. activateClass.SetUpICardEffect("Play 1 [Wicked God] trait Digimon card from hand or trash", CanUseCondition, card);
  158. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  159. cardEffects.Add(activateClass);
  160. string EffectDiscription()
  161. {
  162. return "[All Turns] When any of your Digimon with [Millenniummon] in its name would leave the battle area, <Delay>.\r\n• You may play 1 [Wicked God] trait Digimon card with a play cost 1 greater than that Digimon from your hand or trash without paying the cost.";
  163. }
  164. bool PermanentCondition(Permanent permanent)
  165. {
  166. if (CardEffectCommons.IsOwnerPermanent(permanent, card))
  167. {
  168. return permanent.TopCard.ContainsCardName("Millenniummon");
  169. }
  170. return false;
  171. }
  172. bool CanUseCondition(Hashtable hashtable)
  173. {
  174. if (CardEffectCommons.IsExistOnBattleArea(card))
  175. {
  176. if (CardEffectCommons.CanTriggerWhenPermanentRemoveField(hashtable, PermanentCondition))
  177. {
  178. if (CardEffectCommons.CanDeclareOptionDelayEffect(card))
  179. {
  180. return true;
  181. }
  182. }
  183. }
  184. return false;
  185. }
  186. bool CanActivateCondition(Hashtable hashtable)
  187. {
  188. if (CardEffectCommons.IsExistOnBattleArea(card))
  189. {
  190. if (card.PermanentOfThisCard().CanBeDestroyedBySkill(activateClass))
  191. {
  192. return true;
  193. }
  194. }
  195. return false;
  196. }
  197. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  198. {
  199. bool deleted = false;
  200. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.DeletePeremanentAndProcessAccordingToResult(
  201. targetPermanents: new List<Permanent>() { card.PermanentOfThisCard() },
  202. activateClass: activateClass,
  203. successProcess: permanents => SuccessProcess(),
  204. failureProcess: null));
  205. IEnumerator SuccessProcess()
  206. {
  207. deleted = true;
  208. yield return null;
  209. }
  210. if (deleted)
  211. {
  212. List<Permanent> selectedPermanents = CardEffectCommons.GetPermanentsFromHashtable(_hashtable);
  213. bool CanPlayWickedGodCondition(CardSource cardSource)
  214. {
  215. foreach (Permanent permanent in selectedPermanents)
  216. {
  217. if (PermanentCondition(permanent))
  218. {
  219. if(permanent.TopCard.GetCostItself + 1 == cardSource.GetCostItself)
  220. {
  221. if (CardEffectCommons.CanPlayAsNewPermanent(cardSource: cardSource, payCost: false, cardEffect: activateClass))
  222. {
  223. return cardSource.IsDigimon &&
  224. cardSource.ContainsTraits("Wicked God");
  225. }
  226. }
  227. }
  228. }
  229. return false;
  230. }
  231. if (selectedPermanents.Count > 0)
  232. {
  233. if (card.Owner.HandCards.Count(CanPlayWickedGodCondition) >= 1 || CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, CanPlayWickedGodCondition))
  234. {
  235. if (card.Owner.HandCards.Count(CanPlayWickedGodCondition) >= 1 && CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, CanPlayWickedGodCondition))
  236. {
  237. List<SelectionElement<bool>> selectionElements = new List<SelectionElement<bool>>()
  238. {
  239. new SelectionElement<bool>(message: $"From hand", value : true, spriteIndex: 0),
  240. new SelectionElement<bool>(message: $"From trash", value : false, spriteIndex: 1),
  241. };
  242. string selectPlayerMessage = "From which area do you play a card?";
  243. string notSelectPlayerMessage = "The opponent is choosing from which area to play a card.";
  244. GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: selectionElements, selectPlayer: card.Owner, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  245. }
  246. else if (card.Owner.HandCards.Count(CanPlayWickedGodCondition) == 0 && CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, CanPlayWickedGodCondition))
  247. {
  248. GManager.instance.userSelectionManager.SetBool(false);
  249. }
  250. else if (card.Owner.HandCards.Count(CanPlayWickedGodCondition) >= 1 && card.Owner.TrashCards.Count(CanPlayWickedGodCondition) == 0)
  251. {
  252. GManager.instance.userSelectionManager.SetBool(true);
  253. }
  254. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  255. bool fromHand = GManager.instance.userSelectionManager.SelectedBoolValue;
  256. List <CardSource> selectedCards = new List<CardSource>();
  257. IEnumerator SelectCardCoroutine(CardSource cardSource)
  258. {
  259. selectedCards.Add(cardSource);
  260. yield return null;
  261. }
  262. if (fromHand)
  263. {
  264. int maxCount = 1;
  265. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  266. selectHandEffect.SetUp(
  267. selectPlayer: card.Owner,
  268. canTargetCondition: CanPlayWickedGodCondition,
  269. canTargetCondition_ByPreSelecetedList: null,
  270. canEndSelectCondition: null,
  271. maxCount: maxCount,
  272. canNoSelect: true,
  273. canEndNotMax: false,
  274. isShowOpponent: true,
  275. selectCardCoroutine: SelectCardCoroutine,
  276. afterSelectCardCoroutine: null,
  277. mode: SelectHandEffect.Mode.Custom,
  278. cardEffect: activateClass);
  279. selectHandEffect.SetUpCustomMessage(
  280. "Select 1 [Wicked God] trait Digimon card to play.",
  281. "The opponent is selecting 1 [Wicked God] trait Digimon card to play.");
  282. selectHandEffect.SetUpCustomMessage_ShowCard("Played Card");
  283. yield return StartCoroutine(selectHandEffect.Activate());
  284. }
  285. else
  286. {
  287. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  288. selectCardEffect.SetUp(
  289. canTargetCondition: CanPlayWickedGodCondition,
  290. canTargetCondition_ByPreSelecetedList: null,
  291. canEndSelectCondition: null,
  292. canNoSelect: () => false,
  293. selectCardCoroutine: SelectCardCoroutine,
  294. afterSelectCardCoroutine: null,
  295. message: "Select 1 [Wicked God] trait Digimon card to play.",
  296. maxCount: 1,
  297. canEndNotMax: false,
  298. isShowOpponent: true,
  299. mode: SelectCardEffect.Mode.Custom,
  300. root: SelectCardEffect.Root.Trash,
  301. customRootCardList: null,
  302. canLookReverseCard: true,
  303. selectPlayer: card.Owner,
  304. cardEffect: activateClass);
  305. selectCardEffect.SetUpCustomMessage(
  306. "Select 1 [Wicked God] trait Digimon card to play.",
  307. "The opponent is selecting 1 [Wicked God] trait Digimon card to play.");
  308. selectCardEffect.SetUpCustomMessage_ShowCard("Played Card");
  309. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  310. }
  311. SelectCardEffect.Root root = SelectCardEffect.Root.Hand;
  312. if (!fromHand)
  313. {
  314. root = SelectCardEffect.Root.Trash;
  315. }
  316. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(
  317. cardSources: selectedCards,
  318. activateClass: activateClass,
  319. payCost: false,
  320. isTapped: false,
  321. root: root,
  322. activateETB: true));
  323. }
  324. }
  325. }
  326. }
  327. }
  328. #endregion
  329. #region Security
  330. if (timing == EffectTiming.SecuritySkill)
  331. {
  332. cardEffects.Add(CardEffectFactory.PlaceSelfDelayOptionSecurityEffect(card));
  333. }
  334. #endregion
  335. return cardEffects;
  336. }
  337. }
  338. }