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