TrashDigivolutionCards.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 partial class CardEffectCommons
  9. {
  10. public static IEnumerator SelectTrashDigivolutionCards(Func<Permanent, bool> permanentCondition, Func<CardSource, bool> cardCondition, int maxCount, bool canNoTrash, bool isFromOnly1Permanent, ICardEffect activateClass, string selectString = "Digimon")
  11. {
  12. if (maxCount <= 0) yield break;
  13. if (activateClass == null) yield break;
  14. CardSource card = activateClass.EffectSourceCard;
  15. if (card == null) yield break;
  16. bool CanSelectPermanentCondition(Permanent permanent)
  17. {
  18. if (IsPermanentExistsOnOpponentBattleArea(permanent, card))
  19. {
  20. if (permanentCondition == null || permanentCondition(permanent))
  21. {
  22. if (permanent.DigivolutionCards.Some(CanSelectCardCondition))
  23. {
  24. if (!permanent.TopCard.CanNotBeAffected(activateClass))
  25. {
  26. return true;
  27. }
  28. }
  29. }
  30. }
  31. return false;
  32. }
  33. bool CanSelectCardCondition(CardSource cardSource)
  34. {
  35. if (!cardSource.CanNotTrashFromDigivolutionCards(activateClass))
  36. {
  37. if (cardCondition == null || cardCondition(cardSource))
  38. {
  39. return true;
  40. }
  41. }
  42. return false;
  43. }
  44. int digivolutionCardsSum =
  45. card.Owner.Enemy.GetBattleAreaPermanents()
  46. .Filter(CanSelectPermanentCondition)
  47. .Map(permanent => permanent.DigivolutionCards.Count(CanSelectCardCondition))
  48. .Sum();
  49. int maxDigivolutionDiscardCount = Math.Min(digivolutionCardsSum, maxCount);
  50. int digivolutionDiscardedCount = 0;
  51. void EndSelection() => digivolutionDiscardedCount = maxDigivolutionDiscardCount;
  52. bool NotSelectYet() => digivolutionDiscardedCount == 0;
  53. int permanentSelectedCount = 0;
  54. while (true)
  55. {
  56. if (isFromOnly1Permanent)
  57. {
  58. if (permanentSelectedCount >= 1)
  59. {
  60. break;
  61. }
  62. }
  63. if (digivolutionDiscardedCount >= maxDigivolutionDiscardCount)
  64. {
  65. break;
  66. }
  67. if (!card.Owner.Enemy.GetBattleAreaPermanents().Some(CanSelectPermanentCondition))
  68. {
  69. break;
  70. }
  71. else
  72. {
  73. permanentSelectedCount++;
  74. maxCount = Math.Min(1, card.Owner.Enemy.GetBattleAreaPermanents().Count(CanSelectPermanentCondition));
  75. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  76. selectPermanentEffect.SetUp(
  77. selectPlayer: card.Owner,
  78. canTargetCondition: CanSelectPermanentCondition,
  79. canTargetCondition_ByPreSelecetedList: null,
  80. canEndSelectCondition: null,
  81. maxCount: maxCount,
  82. canNoSelect: canNoTrash && NotSelectYet(),
  83. canEndNotMax: false,
  84. selectPermanentCoroutine: SelectPermanentCoroutine,
  85. afterSelectPermanentCoroutine: AfterSelectPermanentCoroutine,
  86. mode: SelectPermanentEffect.Mode.Custom,
  87. cardEffect: activateClass);
  88. selectPermanentEffect.SetUpCustomMessage($"Select 1 {selectString} that will trash digivolution cards.", $"The opponent is selecting 1 {selectString} that will trash digivolution cards.");
  89. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  90. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  91. {
  92. Permanent selectedPermanent = permanent;
  93. if (selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition) >= 1)
  94. {
  95. int trashMaxCountOfTargetPermanent = Math.Min(
  96. maxDigivolutionDiscardCount - digivolutionDiscardedCount,
  97. selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition));
  98. List<CardSource> selectedCards = new List<CardSource>();
  99. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  100. selectCardEffect.SetUp(
  101. canTargetCondition: CanSelectCardCondition,
  102. canTargetCondition_ByPreSelecetedList: null,
  103. canEndSelectCondition: null,
  104. canNoSelect: () => canNoTrash && NotSelectYet(),
  105. selectCardCoroutine: SelectCardCoroutine,
  106. afterSelectCardCoroutine: null,
  107. message: "Select digivolution cards to trash.",
  108. maxCount: trashMaxCountOfTargetPermanent,
  109. canEndNotMax: trashMaxCountOfTargetPermanent >= 2 && !isFromOnly1Permanent,
  110. isShowOpponent: true,
  111. mode: SelectCardEffect.Mode.Custom,
  112. root: SelectCardEffect.Root.Custom,
  113. customRootCardList: selectedPermanent.DigivolutionCards,
  114. canLookReverseCard: true,
  115. selectPlayer: card.Owner,
  116. cardEffect: activateClass);
  117. selectCardEffect.SetUpCustomMessage("Select digivolution cards to trash.", "The opponent is selecting digivolution cards to trash.");
  118. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  119. IEnumerator SelectCardCoroutine(CardSource cardSource)
  120. {
  121. selectedCards.Add(cardSource);
  122. yield return null;
  123. }
  124. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(
  125. selectedPermanent,
  126. selectedCards,
  127. activateClass).TrashDigivolutionCards());
  128. digivolutionDiscardedCount += selectedCards.Count;
  129. if (canNoTrash && NotSelectYet())
  130. {
  131. EndSelection();
  132. }
  133. }
  134. }
  135. IEnumerator AfterSelectPermanentCoroutine(List<Permanent> permanents)
  136. {
  137. if (permanents.Count == 0)
  138. {
  139. if (canNoTrash && NotSelectYet())
  140. {
  141. EndSelection();
  142. }
  143. }
  144. yield return null;
  145. }
  146. }
  147. }
  148. }
  149. }