EX9_005.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. //Negamon
  7. namespace DCGO.CardEffects.EX9
  8. {
  9. public class EX9_005 : CEntity_Effect
  10. {
  11. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  12. {
  13. List<ICardEffect> cardEffects = new List<ICardEffect>();
  14. #region Breeding - Main
  15. if(timing == EffectTiming.OnDeclaration)
  16. {
  17. ActivateClass activateClass = new ActivateClass();
  18. activateClass.SetUpICardEffect("Reduce play cost", CanUseCondition, card);
  19. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, false, EffectDiscription());
  20. activateClass.SetHashString("Reduce_EX9_005");
  21. cardEffects.Add(activateClass);
  22. string EffectDiscription()
  23. {
  24. return "[Breeding] [Main] [Once Per Turn] You may play 1 Digimon card with [Negamon] in its text from your hand with the play cost reduced by 2. For each [Negamon] in your trash or your Digimon's digivolution cards, further reduce it by 1. Then, place this Digimon as the played Digimon's bottom digivolution card.";
  25. }
  26. int ReductionAmount()
  27. {
  28. int value = 2;
  29. value += CardEffectCommons.MatchConditionOwnersCardCountInTrash(card, IsNegamon);
  30. foreach (Permanent perm in card.Owner.GetBattleAreaDigimons())
  31. {
  32. value += perm.DigivolutionCards.Count(IsNegamon);
  33. }
  34. return value;
  35. }
  36. bool IsNegamon(CardSource source)
  37. {
  38. return source.EqualsCardName("Negamon");
  39. }
  40. bool CardCondition(CardSource cardSource)
  41. {
  42. if (cardSource.Owner == card.Owner)
  43. {
  44. if (cardSource.IsDigimon)
  45. {
  46. if (cardSource.HasText("Negamon"))
  47. {
  48. return true;
  49. }
  50. }
  51. }
  52. return false;
  53. }
  54. bool CanUseCondition(Hashtable hashtable)
  55. {
  56. if (CardEffectCommons.IsExistOnBreedingArea(card))
  57. {
  58. if (CardEffectCommons.IsOwnerTurn(card))
  59. {
  60. return true;
  61. }
  62. }
  63. return false;
  64. }
  65. bool CanActivateCondition(Hashtable hashtable)
  66. {
  67. return CardEffectCommons.IsExistOnBreedingArea(card);
  68. }
  69. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  70. {
  71. int reduceCount = ReductionAmount();
  72. #region Reduce Play Cost
  73. ChangeCostClass changeCostClass = new ChangeCostClass();
  74. changeCostClass.SetUpICardEffect($"Play Cost -{reduceCount}", _ => true, card);
  75. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardCondition,
  76. rootCondition: RootCondition, isUpDown: () => true, isCheckAvailability: () => false,
  77. isChangePayingCost: () => true);
  78. Func<EffectTiming, ICardEffect> getCardEffect = GetCardEffect;
  79. card.Owner.UntilCalculateFixedCostEffect.Add(getCardEffect);
  80. ICardEffect GetCardEffect(EffectTiming rcTiming)
  81. {
  82. if (rcTiming == EffectTiming.None)
  83. {
  84. return changeCostClass;
  85. }
  86. return null;
  87. }
  88. int ChangeCost(CardSource cardSource, int cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  89. {
  90. if (CardCondition(cardSource))
  91. {
  92. if (RootCondition(root))
  93. {
  94. if (PermanentsCondition(targetPermanents))
  95. {
  96. cost -= reduceCount;
  97. }
  98. }
  99. }
  100. return cost;
  101. }
  102. bool PermanentsCondition(List<Permanent> targetPermanents)
  103. {
  104. if (targetPermanents == null)
  105. {
  106. return true;
  107. }
  108. return targetPermanents.Count((targetPermanent) => targetPermanent != null) == 0;
  109. }
  110. bool RootCondition(SelectCardEffect.Root root)
  111. {
  112. return true;
  113. }
  114. #endregion
  115. List<CardSource> selectedCards = new List<CardSource>();
  116. if (card.Owner.HandCards.Count(CardCondition) >= 1)
  117. {
  118. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  119. selectHandEffect.SetUp(
  120. selectPlayer: card.Owner,
  121. canTargetCondition: CardCondition,
  122. canTargetCondition_ByPreSelecetedList: null,
  123. canEndSelectCondition: null,
  124. maxCount: 1,
  125. canNoSelect: false,
  126. canEndNotMax: false,
  127. isShowOpponent: true,
  128. selectCardCoroutine: SelectCardCoroutine,
  129. afterSelectCardCoroutine: null,
  130. mode: SelectHandEffect.Mode.Custom,
  131. cardEffect: activateClass);
  132. selectHandEffect.SetUpCustomMessage("Select 1 Digimon to play.",
  133. "The opponent is selecting 1 Digimon to play.");
  134. selectHandEffect.SetUpCustomMessage_ShowCard("Played Card");
  135. yield return StartCoroutine(selectHandEffect.Activate());
  136. IEnumerator SelectCardCoroutine(CardSource cardSource)
  137. {
  138. selectedCards.Add(cardSource);
  139. yield return null;
  140. }
  141. yield return ContinuousController.instance.StartCoroutine(
  142. CardEffectCommons.PlayPermanentCards(cardSources: selectedCards, activateClass: activateClass,
  143. payCost: true, isTapped: false, root: SelectCardEffect.Root.Hand, activateETB: true));
  144. }
  145. #region Remove Reduce Cost effect
  146. card.Owner.UntilCalculateFixedCostEffect.Remove(getCardEffect);
  147. #endregion
  148. if(selectedCards.Count > 0 && CardEffectCommons.IsExistOnBattleAreaDigimon(selectedCards[0]))
  149. {
  150. Permanent targetPermanent = selectedCards[0].PermanentOfThisCard();
  151. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
  152. yield return ContinuousController.instance.StartCoroutine(targetPermanent.AddDigivolutionCardsBottom(new List<CardSource>() { card }, activateClass));
  153. }
  154. }
  155. }
  156. #endregion
  157. #region Breeding - All Turns
  158. if (timing == EffectTiming.None)
  159. {
  160. bool Condition()
  161. {
  162. return CardEffectCommons.IsExistOnBreedingArea(card);
  163. }
  164. bool PermanentCondition(Permanent permanent)
  165. {
  166. return permanent == card.PermanentOfThisCard();
  167. }
  168. bool CardEffectCondition(ICardEffect cardEffect)
  169. {
  170. return cardEffect != null;
  171. }
  172. cardEffects.Add(CardEffectFactory.CanNotDigivolveStaticSelfEffect(
  173. cardCondition: null,
  174. isInheritedEffect: false,
  175. card: card,
  176. condition: Condition,
  177. effectName: "Can't digivolve"
  178. ));
  179. cardEffects.Add(CardEffectFactory.CanNotBeDestroyedBySkillStaticEffect(
  180. permanentCondition: PermanentCondition,
  181. cardEffectCondition: CardEffectCondition,
  182. isInheritedEffect: false,
  183. card: card,
  184. condition: Condition,
  185. effectName: "Can't be deleted by effects"
  186. ));
  187. cardEffects.Add(CardEffectFactory.CanNotBeTrashedBySkillStaticEffect(
  188. permanentCondition: PermanentCondition,
  189. cardEffectCondition: CardEffectCondition,
  190. isInheritedEffect: false,
  191. card: card,
  192. condition: Condition,
  193. effectName: "Can't be trashed by effects")
  194. );
  195. }
  196. if (timing == EffectTiming.None)
  197. {
  198. }
  199. #endregion
  200. #region Opponents Turn - ESS
  201. if (timing == EffectTiming.OnAllyAttack)
  202. {
  203. ActivateClass activateClass = new ActivateClass();
  204. activateClass.SetUpICardEffect("Switch attack target", CanUseCondition, card);
  205. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, true, EffectDiscription());
  206. activateClass.SetHashString("SwitchTarget_EX9-005");
  207. activateClass.SetIsInheritedEffect(true);
  208. cardEffects.Add(activateClass);
  209. string EffectDiscription()
  210. {
  211. return "[Opponent's Turn] [Once Per Turn] When one of your opponent's Digimon attacks, you may change the attack target to 1 of your Digimon with [Negamon] in its text.";
  212. }
  213. bool CanSelectPermanentCondition(Permanent permanent)
  214. {
  215. return CardEffectCommons.IsPermanentExistsOnOwnerBattleAreaDigimon(permanent, card) &&
  216. permanent.TopCard.HasText("Negamon");
  217. }
  218. bool PermanentCondition(Permanent permanent)
  219. {
  220. return CardEffectCommons.IsOpponentPermanent(permanent, card);
  221. }
  222. bool CanUseCondition(Hashtable hashtable)
  223. {
  224. if (CardEffectCommons.IsExistOnBattleAreaDigimon(card))
  225. {
  226. if (CardEffectCommons.IsOpponentTurn(card))
  227. {
  228. if (CardEffectCommons.CanTriggerOnPermanentAttack(hashtable, PermanentCondition))
  229. {
  230. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  231. {
  232. return true;
  233. }
  234. }
  235. }
  236. }
  237. return false;
  238. }
  239. bool CanActivateCondition(Hashtable hashtable)
  240. {
  241. if (CardEffectCommons.IsExistOnBattleArea(card))
  242. {
  243. if (GManager.instance.attackProcess.IsAttacking)
  244. {
  245. if (GManager.instance.attackProcess.AttackingPermanent.CanSwitchAttackTarget)
  246. {
  247. return true;
  248. }
  249. }
  250. }
  251. return false;
  252. }
  253. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  254. {
  255. if (CardEffectCommons.IsExistOnBattleArea(card))
  256. {
  257. if (CardEffectCommons.IsPermanentExistsOnOpponentBattleArea(GManager.instance.attackProcess.AttackingPermanent, card))
  258. {
  259. if (GManager.instance.attackProcess.IsAttacking)
  260. {
  261. if (GManager.instance.attackProcess.AttackingPermanent.CanSwitchAttackTarget)
  262. {
  263. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  264. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  265. selectPermanentEffect.SetUp(
  266. selectPlayer: card.Owner,
  267. canTargetCondition: CanSelectPermanentCondition,
  268. canTargetCondition_ByPreSelecetedList: null,
  269. canEndSelectCondition: null,
  270. maxCount: maxCount,
  271. canNoSelect: false,
  272. canEndNotMax: false,
  273. selectPermanentCoroutine: SelectPermanentCoroutine,
  274. afterSelectPermanentCoroutine: null,
  275. mode: SelectPermanentEffect.Mode.Custom,
  276. cardEffect: activateClass);
  277. selectPermanentEffect.SetUpCustomMessage(
  278. "Select 1 Digimon to switch the attack to.",
  279. "The opponent is selecting 1 Digimon to switch the attack to.");
  280. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  281. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  282. {
  283. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SwitchDefender(
  284. activateClass,
  285. false,
  286. permanent));
  287. }
  288. }
  289. }
  290. }
  291. }
  292. }
  293. }
  294. #endregion
  295. return cardEffects;
  296. }
  297. }
  298. }