P_072.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.Linq;
  5. using Photon;
  6. using System;
  7. using Photon.Pun;
  8. public class P_072 : CEntity_Effect
  9. {
  10. public override List<ICardEffect> CardEffects(EffectTiming timing, CardSource card)
  11. {
  12. List<ICardEffect> cardEffects = new List<ICardEffect>();
  13. if (timing == EffectTiming.None)
  14. {
  15. bool PermanentCondition(Permanent targetPermanent)
  16. {
  17. return targetPermanent.TopCard.CardNames.Contains("MetalGreymon");
  18. }
  19. cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(
  20. permanentCondition: PermanentCondition,
  21. digivolutionCost: 0,
  22. ignoreDigivolutionRequirement: false,
  23. card: card,
  24. condition: null));
  25. }
  26. if (timing == EffectTiming.None)
  27. {
  28. ChangeCardNamesClass changeCardNamesClass = new ChangeCardNamesClass();
  29. changeCardNamesClass.SetUpICardEffect("Also treated as [MetalGreymon]", CanUseCondition, card);
  30. changeCardNamesClass.SetUpChangeCardNamesClass(changeCardNames: changeCardNames);
  31. cardEffects.Add(changeCardNamesClass);
  32. bool CanUseCondition(Hashtable hashtable)
  33. {
  34. return true;
  35. }
  36. List<string> changeCardNames(CardSource cardSource, List<string> CardNames)
  37. {
  38. if (cardSource == card)
  39. {
  40. CardNames.Add("MetalGreymon");
  41. }
  42. return CardNames;
  43. }
  44. }
  45. if (timing == EffectTiming.OnEnterFieldAnyone)
  46. {
  47. ActivateClass activateClass = new ActivateClass();
  48. activateClass.SetUpICardEffect("Delete 1 Digimon with 5000 DP or less", CanUseCondition, card);
  49. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDiscription());
  50. cardEffects.Add(activateClass);
  51. string EffectDiscription()
  52. {
  53. return "[When Digivolving] If you have a Tamer in play, delete 1 of your opponent's Digimon with 5000 DP or less.";
  54. }
  55. bool CanSelectPermanentCondition(Permanent permanent)
  56. {
  57. if (CardEffectCommons.IsPermanentExistsOnOpponentBattleAreaDigimon(permanent, card))
  58. {
  59. if (permanent.DP <= card.Owner.MaxDP_DeleteEffect(5000, activateClass))
  60. {
  61. return true;
  62. }
  63. }
  64. return false;
  65. }
  66. bool CanUseCondition(Hashtable hashtable)
  67. {
  68. return CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  69. }
  70. bool CanActivateCondition(Hashtable hashtable)
  71. {
  72. if (CardEffectCommons.IsExistOnBattleArea(card))
  73. {
  74. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  75. {
  76. if (CardEffectCommons.HasMatchConditionOwnersPermanent(card, (permanent) => permanent.IsTamer))
  77. {
  78. return true;
  79. }
  80. }
  81. }
  82. return false;
  83. }
  84. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  85. {
  86. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  87. {
  88. int maxCount = Math.Min(1, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  89. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  90. selectPermanentEffect.SetUp(
  91. selectPlayer: card.Owner,
  92. canTargetCondition: CanSelectPermanentCondition,
  93. canTargetCondition_ByPreSelecetedList: null,
  94. canEndSelectCondition: null,
  95. maxCount: maxCount,
  96. canNoSelect: false,
  97. canEndNotMax: false,
  98. selectPermanentCoroutine: null,
  99. afterSelectPermanentCoroutine: null,
  100. mode: SelectPermanentEffect.Mode.Destroy,
  101. cardEffect: activateClass);
  102. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  103. }
  104. }
  105. }
  106. if (timing == EffectTiming.WhenPermanentWouldBeDeleted || timing == EffectTiming.WhenReturntoHandAnyone || timing == EffectTiming.WhenReturntoLibraryAnyone)
  107. {
  108. ActivateClass activateClass = new ActivateClass();
  109. activateClass.SetUpICardEffect("Prevent this Digimon from being deleted or returned to hand or deck", CanUseCondition, card);
  110. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  111. activateClass.SetIsInheritedEffect(true);
  112. activateClass.SetHashString("Substitute_P_072");
  113. cardEffects.Add(activateClass);
  114. string EffectDiscription()
  115. {
  116. return "[All Turns] When this Digimon has [Greymon] or [Omnimon] in its name and an effect would delete it or return it to your hand or deck, you may trash 2 cards of the same level in this Digimon's digivolution cards to prevent it from leaving play.";
  117. }
  118. bool CanSelectCardCondition(CardSource cardSource)
  119. {
  120. if (!cardSource.CanNotTrashFromDigivolutionCards(activateClass))
  121. {
  122. if (CardEffectCommons.IsExistOnBattleArea(card))
  123. {
  124. if (card.PermanentOfThisCard().DigivolutionCards.Contains(card))
  125. {
  126. foreach (CardSource cardSource1 in card.PermanentOfThisCard().DigivolutionCards)
  127. {
  128. if (cardSource != cardSource1)
  129. {
  130. if (cardSource.Level == cardSource1.Level)
  131. {
  132. if (!cardSource1.CanNotTrashFromDigivolutionCards(activateClass))
  133. {
  134. if (cardSource.HasLevel && cardSource1.HasLevel)
  135. {
  136. return true;
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }
  143. }
  144. }
  145. return false;
  146. }
  147. bool CanUseCondition(Hashtable hashtable)
  148. {
  149. if (CardEffectCommons.IsExistOnBattleArea(card))
  150. {
  151. if (CardEffectCommons.CanTriggerWhenRemoveField(hashtable, card))
  152. {
  153. if (CardEffectCommons.IsByEffect(hashtable, null))
  154. {
  155. return true;
  156. }
  157. }
  158. }
  159. return false;
  160. }
  161. bool CanActivateCondition(Hashtable hashtable)
  162. {
  163. if (CardEffectCommons.IsExistOnBattleArea(card))
  164. {
  165. if (card.PermanentOfThisCard().TopCard.HasGreymonName || card.PermanentOfThisCard().TopCard.ContainsCardName("Omnimon"))
  166. {
  167. if (card.PermanentOfThisCard().DigivolutionCards.Count(CanSelectCardCondition) >= 2)
  168. {
  169. List<CardSource> canSelectCards = new List<CardSource>();
  170. foreach (CardSource cardSource in card.PermanentOfThisCard().DigivolutionCards)
  171. {
  172. canSelectCards.Add(cardSource);
  173. }
  174. if (canSelectCards.Count >= 2)
  175. {
  176. List<CardSource[]> cardsList = ParameterComparer.Enumerate(canSelectCards, 2).ToList();
  177. foreach (CardSource[] cardSources in cardsList)
  178. {
  179. if (cardSources.Length == 2)
  180. {
  181. if (cardSources[0].Level == cardSources[1].Level)
  182. {
  183. if (cardSources[0].HasLevel && cardSources[1].HasLevel)
  184. {
  185. return true;
  186. }
  187. }
  188. }
  189. }
  190. }
  191. }
  192. }
  193. }
  194. return false;
  195. }
  196. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  197. {
  198. if (CardEffectCommons.IsExistOnBattleArea(card))
  199. {
  200. Permanent selectedPermanent = card.PermanentOfThisCard();
  201. if (selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition) >= 2)
  202. {
  203. List<CardSource> selectedCards = new List<CardSource>();
  204. int maxCount = 2;
  205. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  206. selectCardEffect.SetUp(
  207. canTargetCondition: CanSelectCardCondition,
  208. canTargetCondition_ByPreSelecetedList: CanTargetCondition_ByPreSelecetedList,
  209. canEndSelectCondition: CanEndSelectCondition,
  210. canNoSelect: () => true,
  211. selectCardCoroutine: SelectCardCoroutine,
  212. afterSelectCardCoroutine: null,
  213. message: "Select cards to discard.",
  214. maxCount: maxCount,
  215. canEndNotMax: false,
  216. isShowOpponent: true,
  217. mode: SelectCardEffect.Mode.Custom,
  218. root: SelectCardEffect.Root.Custom,
  219. customRootCardList: selectedPermanent.DigivolutionCards,
  220. canLookReverseCard: true,
  221. selectPlayer: card.Owner,
  222. cardEffect: activateClass);
  223. selectCardEffect.SetNotShowCard();
  224. yield return StartCoroutine(selectCardEffect.Activate());
  225. bool CanEndSelectCondition(List<CardSource> cardSources)
  226. {
  227. if (CardEffectCommons.HasNoElement(cardSources))
  228. {
  229. return false;
  230. }
  231. List<int> levels = cardSources
  232. .Map(cardSource1 => cardSource1.Level)
  233. .Distinct()
  234. .ToList();
  235. if (levels.Count > 1)
  236. {
  237. return false;
  238. }
  239. return true;
  240. }
  241. bool CanTargetCondition_ByPreSelecetedList(List<CardSource> cardSources, CardSource cardSource)
  242. {
  243. List<int> levels = cardSources
  244. .Map(cardSource1 => cardSource1.Level)
  245. .Concat(new List<int>() { cardSource.Level })
  246. .Distinct()
  247. .ToList();
  248. if (levels.Count > 1)
  249. {
  250. return false;
  251. }
  252. return true;
  253. }
  254. IEnumerator SelectCardCoroutine(CardSource cardSource)
  255. {
  256. selectedCards.Add(cardSource);
  257. yield return null;
  258. }
  259. if (selectedCards.Count >= 1)
  260. {
  261. if (selectedCards.Count == 2)
  262. {
  263. selectedPermanent.willBeRemoveField = false;
  264. selectedPermanent.HideDeleteEffect();
  265. selectedPermanent.HideHandBounceEffect();
  266. selectedPermanent.HideDeckBounceEffect();
  267. }
  268. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(
  269. selectedPermanent,
  270. selectedCards,
  271. activateClass).TrashDigivolutionCards());
  272. }
  273. }
  274. }
  275. }
  276. }
  277. return cardEffects;
  278. }
  279. }