P_156.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. namespace DCGO.CardEffects.P
  6. {
  7. public class P_156 : CEntity_Effect
  8. {
  9. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  10. {
  11. List<ICardEffect> cardEffects = new List<ICardEffect>();
  12. #region Ignore Color Requirements
  13. if (timing == EffectTiming.None)
  14. {
  15. IgnoreColorConditionClass ignoreColorConditionClass = new IgnoreColorConditionClass();
  16. ignoreColorConditionClass.SetUpICardEffect("Ignore color requirements", CanUseCondition, card);
  17. ignoreColorConditionClass.SetUpIgnoreColorConditionClass(cardCondition: CardCondition);
  18. cardEffects.Add(ignoreColorConditionClass);
  19. bool CanUseCondition(Hashtable hashtable)
  20. {
  21. return CardEffectCommons.HasMatchConditionOwnersPermanent(card, (permanent) => permanent.IsTamer);
  22. }
  23. bool CardCondition(CardSource cardSource)
  24. {
  25. return (cardSource == card);
  26. }
  27. }
  28. #endregion
  29. #region Main
  30. if (timing == EffectTiming.OptionSkill)
  31. {
  32. List<CardColor> tamerColors = new List<CardColor>();
  33. ActivateClass activateClass = new ActivateClass();
  34. activateClass.SetUpICardEffect("Play 1 Digimon, 3 cost or less", CanUseCondition, card);
  35. activateClass.SetUpActivateClass(null, ActivateCoroutine, -1, false, EffectDiscription());
  36. cardEffects.Add(activateClass);
  37. string EffectDiscription()
  38. {
  39. return "[Main] Choose 1 Tamer. You may play 1 Digimon card with the same color as that Tamer and with a play cost of 3 or less from your hand or trash without paying the cost.";
  40. }
  41. bool HasTamer(Permanent permanent)
  42. {
  43. if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
  44. return permanent.IsTamer;
  45. return false;
  46. }
  47. bool SelectDigimonCondition(CardSource source)
  48. {
  49. if (source.IsDigimon)
  50. {
  51. if (CardEffectCommons.CanPlayAsNewPermanent(source, false, activateClass))
  52. {
  53. if(source.GetCostItself <= 3)
  54. {
  55. foreach (CardColor color in source.CardColors)
  56. {
  57. if (tamerColors.Contains(color))
  58. return true;
  59. }
  60. }
  61. }
  62. }
  63. return false;
  64. }
  65. bool CanUseCondition(Hashtable hashtable)
  66. {
  67. if (CardEffectCommons.CanTriggerOptionMainEffect(hashtable, card))
  68. return CardEffectCommons.HasMatchConditionPermanent(HasTamer);
  69. return false;
  70. }
  71. IEnumerator ActivateCoroutine(Hashtable hashtable)
  72. {
  73. Permanent selectedPermanent = null;
  74. if (CardEffectCommons.HasMatchConditionPermanent(HasTamer))
  75. {
  76. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(HasTamer));
  77. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  78. selectPermanentEffect.SetUp(
  79. selectPlayer: card.Owner,
  80. canTargetCondition: HasTamer,
  81. canTargetCondition_ByPreSelecetedList: null,
  82. canEndSelectCondition: null,
  83. maxCount: maxCount,
  84. canNoSelect: false,
  85. canEndNotMax: false,
  86. selectPermanentCoroutine: TamerSelected,
  87. afterSelectPermanentCoroutine: null,
  88. mode: SelectPermanentEffect.Mode.Custom,
  89. cardEffect: activateClass);
  90. selectPermanentEffect.SetUpCustomMessage("Select 1 Tamer.", "The opponent is selecting 1 Tamer.");
  91. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  92. }
  93. IEnumerator TamerSelected(Permanent permanent)
  94. {
  95. selectedPermanent = permanent;
  96. yield return null;
  97. }
  98. if(selectedPermanent != null)
  99. {
  100. tamerColors = selectedPermanent.TopCard.CardColors;
  101. bool canSelectHand = CardEffectCommons.HasMatchConditionOwnersHand(card, SelectDigimonCondition);
  102. bool canSelectTrash = CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, SelectDigimonCondition);
  103. if (canSelectHand || canSelectTrash)
  104. {
  105. if (canSelectHand && canSelectTrash)
  106. {
  107. List<SelectionElement<bool>> selectionElements = new List<SelectionElement<bool>>
  108. {
  109. new(message: "From hand", value: true, spriteIndex: 0),
  110. new(message: "From trash", value: false, spriteIndex: 1),
  111. };
  112. string selectPlayerMessage = "From which area do you play a card?";
  113. string notSelectPlayerMessage = "The opponent is choosing from which area to play a card.";
  114. GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: selectionElements,
  115. selectPlayer: card.Owner, selectPlayerMessage: selectPlayerMessage,
  116. notSelectPlayerMessage: notSelectPlayerMessage);
  117. }
  118. else
  119. {
  120. GManager.instance.userSelectionManager.SetBool(canSelectHand);
  121. }
  122. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager
  123. .WaitForEndSelect());
  124. bool fromHand = GManager.instance.userSelectionManager.SelectedBoolValue;
  125. if (fromHand)
  126. {
  127. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  128. selectHandEffect.SetUp(
  129. selectPlayer: card.Owner,
  130. canTargetCondition: SelectDigimonCondition,
  131. canTargetCondition_ByPreSelecetedList: null,
  132. canEndSelectCondition: null,
  133. maxCount: 1,
  134. canNoSelect: true,
  135. canEndNotMax: false,
  136. isShowOpponent: true,
  137. selectCardCoroutine: null,
  138. afterSelectCardCoroutine: DigimonSelected,
  139. mode: SelectHandEffect.Mode.Custom,
  140. cardEffect: activateClass);
  141. selectHandEffect.SetUpCustomMessage("Select 1 Digimon to play.",
  142. "The opponent is selecting 1 Digimon to play.");
  143. selectHandEffect.SetUpCustomMessage_ShowCard("Played card");
  144. yield return StartCoroutine(selectHandEffect.Activate());
  145. }
  146. else
  147. {
  148. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  149. selectCardEffect.SetUp(
  150. canTargetCondition: SelectDigimonCondition,
  151. canTargetCondition_ByPreSelecetedList: null,
  152. canEndSelectCondition: null,
  153. canNoSelect: () => false,
  154. selectCardCoroutine: null,
  155. afterSelectCardCoroutine: DigimonSelected,
  156. message: "Select Digimon to play.",
  157. maxCount: 1,
  158. canEndNotMax: true,
  159. isShowOpponent: true,
  160. mode: SelectCardEffect.Mode.Custom,
  161. root: SelectCardEffect.Root.Trash,
  162. customRootCardList: null,
  163. canLookReverseCard: true,
  164. selectPlayer: card.Owner,
  165. cardEffect: activateClass);
  166. selectCardEffect.SetUpCustomMessage("Select 1 Digimon to play.",
  167. "The opponent is selecting 1 Digimon to play.");
  168. yield return StartCoroutine(selectCardEffect.Activate());
  169. }
  170. }
  171. }
  172. IEnumerator DigimonSelected(List<CardSource> selectedCards)
  173. {
  174. SelectCardEffect.Root root = SelectCardEffect.Root.Hand;
  175. if (card.Owner.TrashCards.Contains(selectedCards[0]))
  176. root = SelectCardEffect.Root.Trash;
  177. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(
  178. cardSources: selectedCards,
  179. activateClass: activateClass,
  180. payCost: false,
  181. isTapped: false,
  182. root: root,
  183. activateETB: true));
  184. }
  185. }
  186. }
  187. #endregion
  188. #region Security
  189. if (timing == EffectTiming.SecuritySkill)
  190. {
  191. ActivateClass activateClass = new ActivateClass();
  192. activateClass.SetUpICardEffect("Play 1 tamer, then add this card to hand", CanUseCondition, card);
  193. activateClass.SetUpActivateClass(null, ActivateCoroutine, -1, false, EffectDiscription());
  194. activateClass.SetIsSecurityEffect(true);
  195. cardEffects.Add(activateClass);
  196. string EffectDiscription()
  197. {
  198. return "[Security] You may play 1 tamer card from your hand without paying the cost. Then, add this card to the hand.";
  199. }
  200. bool HasTamer(CardSource source)
  201. {
  202. if (CardEffectCommons.CanPlayAsNewPermanent(source, false,activateClass))
  203. return source.IsTamer;
  204. return false;
  205. }
  206. bool CanUseCondition(Hashtable hashtable)
  207. {
  208. return CardEffectCommons.CanTriggerSecurityEffect(hashtable, card);
  209. }
  210. IEnumerator ActivateCoroutine(Hashtable hashtable)
  211. {
  212. if (CardEffectCommons.HasMatchConditionOwnersHand(card, HasTamer))
  213. {
  214. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  215. selectHandEffect.SetUp(
  216. selectPlayer: card.Owner,
  217. canTargetCondition: HasTamer,
  218. canTargetCondition_ByPreSelecetedList: null,
  219. canEndSelectCondition: null,
  220. maxCount: 1,
  221. canNoSelect: true,
  222. canEndNotMax: false,
  223. isShowOpponent: true,
  224. selectCardCoroutine: null,
  225. afterSelectCardCoroutine: SelectCardCoroutine,
  226. mode: SelectHandEffect.Mode.Custom,
  227. cardEffect: activateClass);
  228. selectHandEffect.SetUpCustomMessage(
  229. "Select 1 tamer to play.",
  230. "The opponent is selecting 1 tamer to play.");
  231. yield return StartCoroutine(selectHandEffect.Activate());
  232. IEnumerator SelectCardCoroutine(List<CardSource> cardSources)
  233. {
  234. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.PlayPermanentCards(
  235. cardSources: cardSources,
  236. activateClass: activateClass,
  237. payCost: false,
  238. isTapped: false,
  239. root: SelectCardEffect.Root.Hand,
  240. activateETB: true));
  241. }
  242. }
  243. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.AddThisCardToHand(card, activateClass));
  244. }
  245. }
  246. #endregion
  247. return cardEffects;
  248. }
  249. }
  250. }