TrashDigivolutionCards.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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", Func<Permanent, List<CardSource>, IEnumerator> afterSelectionCoroutine = null, bool canEndNotMax = false)
  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. return true;
  23. }
  24. }
  25. return false;
  26. }
  27. bool CanSelectCardCondition(CardSource cardSource)
  28. {
  29. if (!cardSource.CanNotTrashFromDigivolutionCards(activateClass))
  30. {
  31. if (cardCondition == null || cardCondition(cardSource))
  32. {
  33. return true;
  34. }
  35. }
  36. return false;
  37. }
  38. int permanentSum =
  39. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  40. .Map(player => player.GetBattleAreaPermanents().Filter(CanSelectPermanentCondition))
  41. .Flat().Count();
  42. int digivolutionCardsSum =
  43. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  44. .Map(player => player.GetBattleAreaPermanents().Filter(CanSelectPermanentCondition))
  45. .Flat()
  46. .Map(permanent => permanent.DigivolutionCards.Count(CanSelectCardCondition))
  47. .Sum();
  48. int maxDigivolutionDiscardCount = Math.Min(digivolutionCardsSum, maxCount);
  49. int digivolutionDiscardedCount = 0;
  50. void EndSelection() => digivolutionDiscardedCount = maxDigivolutionDiscardCount;
  51. bool NotSelectYet() => digivolutionDiscardedCount == 0;
  52. int permanentSelectedCount = 0;
  53. List<CardSource> selectedCards = new List<CardSource>();
  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 (permanentSum < 1)
  68. {
  69. break;
  70. }
  71. else
  72. {
  73. Permanent selectedPermanent = null;
  74. permanentSelectedCount++;
  75. maxCount = Math.Min(1, permanentSum);
  76. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  77. selectPermanentEffect.SetUp(
  78. selectPlayer: card.Owner,
  79. canTargetCondition: CanSelectPermanentCondition,
  80. canTargetCondition_ByPreSelecetedList: null,
  81. canEndSelectCondition: null,
  82. maxCount: maxCount,
  83. canNoSelect: canNoTrash && NotSelectYet(),
  84. canEndNotMax: canEndNotMax,
  85. selectPermanentCoroutine: SelectPermanentCoroutine,
  86. afterSelectPermanentCoroutine: AfterSelectPermanentCoroutine,
  87. mode: SelectPermanentEffect.Mode.Custom,
  88. cardEffect: activateClass);
  89. selectPermanentEffect.SetUpCustomMessage($"Select 1 {selectString} that will trash digivolution cards.", $"The opponent is selecting 1 {selectString} that will trash digivolution cards.");
  90. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  91. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  92. {
  93. selectedPermanent = permanent;
  94. if (selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition) >= 1)
  95. {
  96. int trashMaxCountOfTargetPermanent = Math.Min(
  97. maxDigivolutionDiscardCount - digivolutionDiscardedCount,
  98. selectedPermanent.DigivolutionCards.Count(CanSelectCardCondition));
  99. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  100. selectCardEffect.SetUp(
  101. canTargetCondition: CanSelectCardCondition,
  102. canTargetCondition_ByPreSelecetedList: CanTargetCondition_ByPreSelecetedList,
  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: false,
  115. selectPlayer: card.Owner,
  116. cardEffect: activateClass);
  117. selectCardEffect.SetUseFaceDown();
  118. selectCardEffect.SetUpCustomMessage("Select digivolution cards to trash.", "The opponent is selecting digivolution cards to trash.");
  119. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  120. bool CanTargetCondition_ByPreSelecetedList(List<CardSource> sources, CardSource source)
  121. {
  122. return !selectedCards.Contains(source);
  123. }
  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. if (afterSelectionCoroutine != null)
  139. yield return ContinuousController.instance.StartCoroutine(afterSelectionCoroutine(selectedPermanent, selectedCards));
  140. }
  141. }
  142. IEnumerator AfterSelectPermanentCoroutine(List<Permanent> permanents)
  143. {
  144. if (permanents.Count == 0)
  145. {
  146. if ((canNoTrash && NotSelectYet()) || canEndNotMax)
  147. {
  148. EndSelection();
  149. }
  150. }
  151. yield return null;
  152. }
  153. }
  154. }
  155. }
  156. }