P_073.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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_073 : 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("WereGarurumon");
  18. }
  19. cardEffects.Add(CardEffectFactory.AddSelfDigivolutionRequirementStaticEffect(permanentCondition: PermanentCondition, digivolutionCost: 0, ignoreDigivolutionRequirement: false, card: card, condition: null));
  20. }
  21. if (timing == EffectTiming.None)
  22. {
  23. ChangeCardNamesClass changeCardNamesClass = new ChangeCardNamesClass();
  24. changeCardNamesClass.SetUpICardEffect("Also treated as [WereGarurumon]", CanUseCondition, card);
  25. changeCardNamesClass.SetUpChangeCardNamesClass(changeCardNames: changeCardNames);
  26. cardEffects.Add(changeCardNamesClass);
  27. bool CanUseCondition(Hashtable hashtable)
  28. {
  29. return true;
  30. }
  31. List<string> changeCardNames(CardSource cardSource, List<string> CardNames)
  32. {
  33. if (cardSource == card)
  34. {
  35. CardNames.Add("WereGarurumon");
  36. }
  37. return CardNames;
  38. }
  39. }
  40. if (timing == EffectTiming.OnEnterFieldAnyone)
  41. {
  42. ActivateClass activateClass = new ActivateClass();
  43. activateClass.SetUpICardEffect("Return level 3 Digimon to hand", CanUseCondition, card);
  44. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, false, EffectDiscription());
  45. cardEffects.Add(activateClass);
  46. string EffectDiscription()
  47. {
  48. return "[When Digivolving] If you have a Tamer in play, return 2 of your opponent's level 3 Digimon to their owners' hands.";
  49. }
  50. bool CanSelectPermanentCondition(Permanent permanent)
  51. {
  52. if (CardEffectCommons.IsPermanentExistsOnOpponentBattleAreaDigimon(permanent, card))
  53. {
  54. if (permanent.TopCard.HasLevel)
  55. {
  56. if (permanent.Level == 3)
  57. {
  58. return true;
  59. }
  60. }
  61. }
  62. return false;
  63. }
  64. bool CanUseCondition(Hashtable hashtable)
  65. {
  66. return CardEffectCommons.CanTriggerWhenDigivolving(hashtable, card);
  67. }
  68. bool CanActivateCondition(Hashtable hashtable)
  69. {
  70. if (CardEffectCommons.IsExistOnBattleArea(card))
  71. {
  72. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  73. {
  74. if (CardEffectCommons.HasMatchConditionOwnersPermanent(card, (permanent) => permanent.IsTamer))
  75. {
  76. return true;
  77. }
  78. }
  79. }
  80. return false;
  81. }
  82. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  83. {
  84. if (isExistOnField(card))
  85. {
  86. if (card.Owner.GetBattleAreaDigimons().Contains(card.PermanentOfThisCard()))
  87. {
  88. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  89. {
  90. int maxCount = Math.Min(2, CardEffectCommons.MatchConditionPermanentCount(CanSelectPermanentCondition));
  91. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  92. selectPermanentEffect.SetUp(
  93. selectPlayer: card.Owner,
  94. canTargetCondition: CanSelectPermanentCondition,
  95. canTargetCondition_ByPreSelecetedList: null,
  96. canEndSelectCondition: null,
  97. maxCount: maxCount,
  98. canNoSelect: false,
  99. canEndNotMax: false,
  100. selectPermanentCoroutine: null,
  101. afterSelectPermanentCoroutine: null,
  102. mode: SelectPermanentEffect.Mode.Bounce,
  103. cardEffect: activateClass);
  104. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  105. }
  106. }
  107. }
  108. }
  109. }
  110. if (timing == EffectTiming.WhenPermanentWouldBeDeleted)
  111. {
  112. ActivateClass activateClass = new ActivateClass();
  113. activateClass.SetUpICardEffect("Prevent this Digimon from being deleted", CanUseCondition, card);
  114. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  115. activateClass.SetIsInheritedEffect(true);
  116. activateClass.SetHashString("Substitute_P_073");
  117. cardEffects.Add(activateClass);
  118. string EffectDiscription()
  119. {
  120. return "[All Turns] If this Digimon has [Garurumon] or [Omnimon] in its name and would be deleted in battle, you may trash 2 cards of the same level from this Digimon's digivolution cards to prevent the deletion.";
  121. }
  122. bool CanSelectCardCondition(CardSource cardSource)
  123. {
  124. if (cardSource != null)
  125. {
  126. if (cardSource.Owner == card.Owner)
  127. {
  128. if (!cardSource.CanNotTrashFromDigivolutionCards(activateClass))
  129. {
  130. if (isExistOnField(card))
  131. {
  132. if (card.PermanentOfThisCard().DigivolutionCards.Contains(card))
  133. {
  134. foreach (CardSource cardSource1 in card.PermanentOfThisCard().DigivolutionCards)
  135. {
  136. if (cardSource != cardSource1)
  137. {
  138. if (cardSource.Level == cardSource1.Level)
  139. {
  140. if (!cardSource1.CanNotTrashFromDigivolutionCards(activateClass))
  141. {
  142. if (cardSource.HasLevel && cardSource1.HasLevel)
  143. {
  144. return true;
  145. }
  146. }
  147. }
  148. }
  149. }
  150. }
  151. }
  152. }
  153. }
  154. }
  155. return false;
  156. }
  157. bool CanUseCondition(Hashtable hashtable)
  158. {
  159. if (isExistOnField(card))
  160. {
  161. if (card.Owner.GetBattleAreaDigimons().Contains(card.PermanentOfThisCard()))
  162. {
  163. if (hashtable != null)
  164. {
  165. if (hashtable.ContainsKey("Permanents"))
  166. {
  167. if (hashtable["Permanents"] is List<Permanent>)
  168. {
  169. List<Permanent> permanents = (List<Permanent>)hashtable["Permanents"];
  170. if (permanents != null)
  171. {
  172. if (permanents.Count((permanent) => permanent == card.PermanentOfThisCard()) >= 1)
  173. {
  174. if (hashtable.ContainsKey("battle"))
  175. {
  176. if (hashtable["battle"] is IBattle)
  177. {
  178. IBattle battle = (IBattle)hashtable["battle"];
  179. if (battle != null)
  180. {
  181. return true;
  182. }
  183. }
  184. }
  185. }
  186. }
  187. }
  188. }
  189. }
  190. }
  191. }
  192. return false;
  193. }
  194. bool CanActivateCondition(Hashtable hashtable)
  195. {
  196. if (isExistOnField(card))
  197. {
  198. if (card.Owner.GetBattleAreaDigimons().Contains(card.PermanentOfThisCard()))
  199. {
  200. if (card.PermanentOfThisCard().TopCard.HasGarurumonName || card.PermanentOfThisCard().TopCard.ContainsCardName("Omnimon"))
  201. {
  202. if (card.PermanentOfThisCard().DigivolutionCards.Count(CanSelectCardCondition) >= 2)
  203. {
  204. List<CardSource> canSelectCards = new List<CardSource>();
  205. foreach (CardSource cardSource in card.PermanentOfThisCard().DigivolutionCards)
  206. {
  207. canSelectCards.Add(cardSource);
  208. }
  209. if (canSelectCards.Count >= 2)
  210. {
  211. List<CardSource[]> cardsList = ParameterComparer.Enumerate(canSelectCards, 2).ToList();
  212. foreach (CardSource[] cardSources in cardsList)
  213. {
  214. if (cardSources.Length == 2)
  215. {
  216. if (cardSources[0].Level == cardSources[1].Level)
  217. {
  218. if (cardSources[0].HasLevel && cardSources[1].HasLevel)
  219. {
  220. return true;
  221. }
  222. }
  223. }
  224. }
  225. }
  226. }
  227. }
  228. }
  229. }
  230. return false;
  231. }
  232. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  233. {
  234. if (isExistOnField(card))
  235. {
  236. if (card.Owner.GetBattleAreaDigimons().Contains(card.PermanentOfThisCard()))
  237. {
  238. Permanent selectedPermanent = card.PermanentOfThisCard();
  239. if (selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition) >= 2)
  240. {
  241. List<CardSource> selectedCards = new List<CardSource>();
  242. int maxCount = 2;
  243. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  244. selectCardEffect.SetUp(
  245. canTargetCondition: CanSelectCardCondition,
  246. canTargetCondition_ByPreSelecetedList: CanTargetCondition_ByPreSelecetedList,
  247. canEndSelectCondition: CanEndSelectCondition,
  248. canNoSelect: () => true,
  249. selectCardCoroutine: SelectCardCoroutine,
  250. afterSelectCardCoroutine: null,
  251. message: "Select cards to discard.",
  252. maxCount: maxCount,
  253. canEndNotMax: false,
  254. isShowOpponent: true,
  255. mode: SelectCardEffect.Mode.Custom,
  256. root: SelectCardEffect.Root.Custom,
  257. customRootCardList: selectedPermanent.DigivolutionCards,
  258. canLookReverseCard: true,
  259. selectPlayer: card.Owner,
  260. cardEffect: activateClass);
  261. selectCardEffect.SetNotShowCard();
  262. yield return StartCoroutine(selectCardEffect.Activate());
  263. bool CanEndSelectCondition(List<CardSource> cardSources)
  264. {
  265. if (maxCount >= 1)
  266. {
  267. if (cardSources.Count <= 0)
  268. {
  269. return false;
  270. }
  271. }
  272. List<int> levels = new List<int>();
  273. foreach (CardSource cardSource1 in cardSources)
  274. {
  275. if (!levels.Contains(cardSource1.Level))
  276. {
  277. levels.Add(cardSource1.Level);
  278. }
  279. }
  280. levels = levels.Distinct().ToList();
  281. if (levels.Count > 1)
  282. {
  283. return false;
  284. }
  285. return true;
  286. }
  287. bool CanTargetCondition_ByPreSelecetedList(List<CardSource> cardSources, CardSource cardSource)
  288. {
  289. List<int> levels = new List<int>();
  290. foreach (CardSource cardSource1 in cardSources)
  291. {
  292. if (!levels.Contains(cardSource1.Level))
  293. {
  294. levels.Add(cardSource1.Level);
  295. }
  296. }
  297. if (!levels.Contains(cardSource.Level))
  298. {
  299. levels.Add(cardSource.Level);
  300. }
  301. levels = levels.Distinct().ToList();
  302. if (levels.Count > 1)
  303. {
  304. return false;
  305. }
  306. return true;
  307. }
  308. IEnumerator SelectCardCoroutine(CardSource cardSource)
  309. {
  310. selectedCards.Add(cardSource);
  311. yield return null;
  312. }
  313. if (selectedCards.Count >= 1)
  314. {
  315. if (selectedCards.Count == 2)
  316. {
  317. selectedPermanent.willBeRemoveField = false;
  318. }
  319. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(selectedPermanent, selectedCards, activateClass).TrashDigivolutionCards());
  320. }
  321. }
  322. }
  323. }
  324. }
  325. }
  326. return cardEffects;
  327. }
  328. }