TrashDigivolutionCards.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 (IsPermanentExistsOnBattleArea(permanent))
  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 permanentSum =
  45. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  46. .Map(player => player.GetBattleAreaPermanents().Filter(CanSelectPermanentCondition))
  47. .Flat().Count();
  48. int digivolutionCardsSum =
  49. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  50. .Map(player => player.GetBattleAreaPermanents().Filter(CanSelectPermanentCondition))
  51. .Flat()
  52. .Map(permanent => permanent.DigivolutionCards.Count(CanSelectCardCondition))
  53. .Sum();
  54. int maxDigivolutionDiscardCount = Math.Min(digivolutionCardsSum, maxCount);
  55. int digivolutionDiscardedCount = 0;
  56. void EndSelection() => digivolutionDiscardedCount = maxDigivolutionDiscardCount;
  57. bool NotSelectYet() => digivolutionDiscardedCount == 0;
  58. int permanentSelectedCount = 0;
  59. while (true)
  60. {
  61. if (isFromOnly1Permanent)
  62. {
  63. if (permanentSelectedCount >= 1)
  64. {
  65. break;
  66. }
  67. }
  68. if (digivolutionDiscardedCount >= maxDigivolutionDiscardCount)
  69. {
  70. break;
  71. }
  72. if (permanentSum < 1)
  73. {
  74. break;
  75. }
  76. else
  77. {
  78. permanentSelectedCount++;
  79. maxCount = Math.Min(1, permanentSum);
  80. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  81. selectPermanentEffect.SetUp(
  82. selectPlayer: card.Owner,
  83. canTargetCondition: CanSelectPermanentCondition,
  84. canTargetCondition_ByPreSelecetedList: null,
  85. canEndSelectCondition: null,
  86. maxCount: maxCount,
  87. canNoSelect: canNoTrash && NotSelectYet(),
  88. canEndNotMax: false,
  89. selectPermanentCoroutine: SelectPermanentCoroutine,
  90. afterSelectPermanentCoroutine: AfterSelectPermanentCoroutine,
  91. mode: SelectPermanentEffect.Mode.Custom,
  92. cardEffect: activateClass);
  93. selectPermanentEffect.SetUpCustomMessage($"Select 1 {selectString} that will trash digivolution cards.", $"The opponent is selecting 1 {selectString} that will trash digivolution cards.");
  94. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  95. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  96. {
  97. Permanent selectedPermanent = permanent;
  98. if (selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition) >= 1)
  99. {
  100. int trashMaxCountOfTargetPermanent = Math.Min(
  101. maxDigivolutionDiscardCount - digivolutionDiscardedCount,
  102. selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition));
  103. List<CardSource> selectedCards = new List<CardSource>();
  104. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  105. selectCardEffect.SetUp(
  106. canTargetCondition: CanSelectCardCondition,
  107. canTargetCondition_ByPreSelecetedList: null,
  108. canEndSelectCondition: null,
  109. canNoSelect: () => canNoTrash && NotSelectYet(),
  110. selectCardCoroutine: SelectCardCoroutine,
  111. afterSelectCardCoroutine: null,
  112. message: "Select digivolution cards to trash.",
  113. maxCount: trashMaxCountOfTargetPermanent,
  114. canEndNotMax: trashMaxCountOfTargetPermanent >= 2 && !isFromOnly1Permanent,
  115. isShowOpponent: true,
  116. mode: SelectCardEffect.Mode.Custom,
  117. root: SelectCardEffect.Root.Custom,
  118. customRootCardList: selectedPermanent.DigivolutionCards,
  119. canLookReverseCard: true,
  120. selectPlayer: card.Owner,
  121. cardEffect: activateClass);
  122. selectCardEffect.SetUpCustomMessage("Select digivolution cards to trash.", "The opponent is selecting digivolution cards to trash.");
  123. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  124. IEnumerator SelectCardCoroutine(CardSource cardSource)
  125. {
  126. selectedCards.Add(cardSource);
  127. yield return null;
  128. }
  129. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(
  130. selectedPermanent,
  131. selectedCards,
  132. activateClass).TrashDigivolutionCards());
  133. digivolutionDiscardedCount += selectedCards.Count;
  134. if (canNoTrash && NotSelectYet())
  135. {
  136. EndSelection();
  137. }
  138. }
  139. }
  140. IEnumerator AfterSelectPermanentCoroutine(List<Permanent> permanents)
  141. {
  142. if (permanents.Count == 0)
  143. {
  144. if (canNoTrash && NotSelectYet())
  145. {
  146. EndSelection();
  147. }
  148. }
  149. yield return null;
  150. }
  151. }
  152. }
  153. }
  154. }