EX10_052.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. // Lucemon: Chaos Mode
  6. namespace DCGO.CardEffects.EX10
  7. {
  8. public class EX10_052 : CEntity_Effect
  9. {
  10. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  11. {
  12. List<ICardEffect> cardEffects = new List<ICardEffect>();
  13. #region Shared Methods
  14. bool CanSelectPermanentConditionShared(Permanent permanent)
  15. {
  16. if (CardEffectCommons.IsPermanentExistsOnOpponentBattleArea(permanent, card))
  17. {
  18. if (permanent.IsDigimon || permanent.IsTamer)
  19. {
  20. return true;
  21. }
  22. }
  23. return false;
  24. }
  25. IEnumerator SharedActivateCoroutine(Hashtable hashtable, ActivateClass activateClass)
  26. {
  27. #region Discard 1 hand card
  28. int discardCount = Math.Min(1, card.Owner.HandCards.Count);
  29. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  30. selectHandEffect.SetUp(
  31. selectPlayer: card.Owner,
  32. canTargetCondition: _ => true,
  33. canTargetCondition_ByPreSelecetedList: null,
  34. canEndSelectCondition: null,
  35. maxCount: discardCount,
  36. canNoSelect: false,
  37. canEndNotMax: false,
  38. isShowOpponent: true,
  39. selectCardCoroutine: null,
  40. afterSelectCardCoroutine: null,
  41. mode: SelectHandEffect.Mode.Discard,
  42. cardEffect: activateClass);
  43. yield return ContinuousController.instance.StartCoroutine(selectHandEffect.Activate());
  44. #endregion
  45. List<Permanent> deleteTargetPermanents = new List<Permanent>();
  46. bool attemptedToDelete = false;
  47. bool failedToDelete = false;
  48. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentConditionShared))
  49. {
  50. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentConditionShared));
  51. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  52. selectPermanentEffect.SetUp(
  53. selectPlayer: card.Owner.Enemy,
  54. canTargetCondition: CanSelectPermanentConditionShared,
  55. canTargetCondition_ByPreSelecetedList: null,
  56. canEndSelectCondition: null,
  57. maxCount: maxCount,
  58. canNoSelect: true,
  59. canEndNotMax: false,
  60. selectPermanentCoroutine: null,
  61. afterSelectPermanentCoroutine: AfterSelectPermanentCoroutine,
  62. mode: SelectPermanentEffect.Mode.Custom,
  63. cardEffect: activateClass);
  64. selectPermanentEffect.SetUpCustomMessage("Select 1 Digimon or Tamer to delete.", "The opponent is selecting 1 Digimon or Tamer to delete.");
  65. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  66. IEnumerator AfterSelectPermanentCoroutine(List<Permanent> permanents)
  67. {
  68. deleteTargetPermanents = permanents.Clone();
  69. attemptedToDelete = true;
  70. yield return null;
  71. }
  72. }
  73. if (attemptedToDelete)
  74. {
  75. yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.DeletePeremanentAndProcessAccordingToResult(
  76. targetPermanents: deleteTargetPermanents,
  77. activateClass: activateClass,
  78. successProcess: null,
  79. failureProcess: FailureProcess));
  80. IEnumerator FailureProcess()
  81. {
  82. failedToDelete = true;
  83. yield return null;
  84. }
  85. }
  86. if (!attemptedToDelete || failedToDelete)
  87. {
  88. yield return ContinuousController.instance.StartCoroutine(new IRecovery(
  89. player: card.Owner,
  90. AddLifeCount: 1,
  91. cardEffect: activateClass).Recovery()
  92. );
  93. }
  94. }
  95. #endregion
  96. #region Alternate Digivolution Requirement
  97. if (timing == EffectTiming.None)
  98. {
  99. static bool PermanentCondition(Permanent targetPermanent)
  100. {
  101. return targetPermanent.TopCard.EqualsCardName("Lucemon");
  102. }
  103. cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(permanentCondition: PermanentCondition, digivolutionCost: 5, ignoreDigivolutionRequirement: false, card: card, condition: null));
  104. }
  105. #endregion
  106. #region When Digivolving
  107. if (timing == EffectTiming.OnEnterFieldAnyone)
  108. {
  109. ActivateClass activateClass = new ActivateClass();
  110. activateClass.SetUpICardEffect("By trashing 1 card in hand, your opponent may delete a digimon or tamer. if they didn't Recover +1", CanUseCondition, card);
  111. activateClass.SetUpActivateClass(CanActivateCondition, hashtable => SharedActivateCoroutine(hashtable, activateClass), -1, true, EffectDiscription());
  112. cardEffects.Add(activateClass);
  113. string EffectDiscription()
  114. {
  115. return "[When Digivolving] By trashing 1 card in your hand, your opponent may delete 1 of their Digimon or Tamers. If this effect didn't delete, <Recovery +1 (Deck)> (Place the top card of your deck on top of your security stack.)";
  116. }
  117. bool CanUseCondition(Hashtable hashtable)
  118. {
  119. return CardEffectCommons.IsExistOnBattleAreaDigimon(card)
  120. && CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  121. }
  122. bool CanActivateCondition(Hashtable hashtable)
  123. {
  124. return CardEffectCommons.IsExistOnBattleAreaDigimon(card)
  125. && card.Owner.HandCards.Any();
  126. }
  127. }
  128. #endregion
  129. #region When Attacking
  130. if (timing == EffectTiming.OnAllyAttack)
  131. {
  132. ActivateClass activateClass = new ActivateClass();
  133. activateClass.SetUpICardEffect("By trashing 1 card in hand, your opponent may delete a digimon or tamer. if they didn't Recover +1", CanUseCondition, card);
  134. activateClass.SetUpActivateClass(CanActivateCondition, hashtable => SharedActivateCoroutine(hashtable, activateClass), -1, true, EffectDiscription());
  135. cardEffects.Add(activateClass);
  136. string EffectDiscription()
  137. {
  138. return "[When Attacking] By trashing 1 card in your hand, your opponent may delete 1 of their Digimon or Tamers. If this effect didn't delete, <Recovery +1 (Deck)> (Place the top card of your deck on top of your security stack.)";
  139. }
  140. bool CanUseCondition(Hashtable hashtable)
  141. {
  142. return CardEffectCommons.IsExistOnBattleAreaDigimon(card)
  143. && CardEffectCommons.CanTriggerOnAttack(hashtable, card);
  144. }
  145. bool CanActivateCondition(Hashtable hashtable)
  146. {
  147. return CardEffectCommons.IsExistOnBattleAreaDigimon(card)
  148. && card.Owner.HandCards.Any();
  149. }
  150. }
  151. #endregion
  152. #region All Turns - Once Per Turn
  153. if (timing == EffectTiming.WhenRemoveField)
  154. {
  155. ActivateClass activateClass = new ActivateClass();
  156. activateClass.SetUpICardEffect("Your opponent may delete a digimon or tamer, if they don't this cards doesn't leave", CanUseCondition, card);
  157. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, 1, false, EffectDiscription());
  158. activateClass.SetHashString("EX10_052_RemoveField");
  159. cardEffects.Add(activateClass);
  160. string EffectDiscription()
  161. {
  162. return "[All Turns] [Once Per Turn] When this Digimon would leave the battle area, your opponent may delete 1 of their Digimon or Tamers. If this effect didn't delete, it doesn't leave.";
  163. }
  164. bool CanUseCondition(Hashtable hashtable)
  165. {
  166. return CardEffectCommons.IsExistOnBattleAreaDigimon(card)
  167. && CardEffectCommons.CanTriggerWhenRemoveField(hashtable, card);
  168. }
  169. bool CanActivateCondition(Hashtable hashtable)
  170. {
  171. return CardEffectCommons.IsExistOnBattleAreaDigimon(card);
  172. }
  173. IEnumerator ActivateCoroutine(Hashtable hashtable)
  174. {
  175. bool hasOpponentDeleted = false;
  176. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentConditionShared))
  177. {
  178. Permanent selectedPermanent = null;
  179. #region Opponent Selects 1 Digimon or Tamer
  180. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentConditionShared));
  181. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  182. selectPermanentEffect.SetUp(
  183. selectPlayer: card.Owner.Enemy,
  184. canTargetCondition: CanSelectPermanentConditionShared,
  185. canTargetCondition_ByPreSelecetedList: null,
  186. canEndSelectCondition: null,
  187. maxCount: maxCount,
  188. canNoSelect: true,
  189. canEndNotMax: false,
  190. selectPermanentCoroutine: SelectPermanentCoroutine,
  191. afterSelectPermanentCoroutine: null,
  192. mode: SelectPermanentEffect.Mode.Custom,
  193. cardEffect: activateClass);
  194. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  195. IEnumerator SelectPermanentCoroutine (Permanent permanent)
  196. {
  197. selectedPermanent = permanent;
  198. yield return null;
  199. }
  200. #endregion
  201. #region Attempt to delete selected permanent
  202. IEnumerator SuccessProcess(List<Permanent> deletedPermanents)
  203. {
  204. hasOpponentDeleted = true;
  205. UnityEngine.Debug.Log($"DELETED SUCCESSFULLY: {hasOpponentDeleted}");
  206. yield return null;
  207. }
  208. if (selectedPermanent != null) yield return ContinuousController.instance.StartCoroutine(CardEffectCommons.DeletePeremanentAndProcessAccordingToResult(
  209. targetPermanents: new List<Permanent> { selectedPermanent },
  210. activateClass: activateClass,
  211. successProcess: SuccessProcess,
  212. failureProcess: null));
  213. #endregion
  214. }
  215. UnityEngine.Debug.Log($"FINAL CHECK: {hasOpponentDeleted}");
  216. if (!hasOpponentDeleted)
  217. {
  218. Permanent thisPermament = card.PermanentOfThisCard();
  219. #region Remove Events from Permanent
  220. thisPermament.HideDeleteEffect();
  221. thisPermament.HideHandBounceEffect();
  222. thisPermament.HideDeckBounceEffect();
  223. thisPermament.HideWillRemoveFieldEffect();
  224. thisPermament.DestroyingEffect = null;
  225. thisPermament.IsDestroyedByBattle = false;
  226. thisPermament.HandBounceEffect = null;
  227. thisPermament.LibraryBounceEffect = null;
  228. thisPermament.willBeRemoveField = false;
  229. #endregion
  230. }
  231. }
  232. }
  233. #endregion
  234. return cardEffects;
  235. }
  236. }
  237. }