Partition.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. public partial class CardEffectCommons
  7. {
  8. #region Can trigger [Partition]
  9. public static bool CanTriggerPartition(Hashtable hashtable, CardSource card)
  10. {
  11. if (CanTriggerWhenPermanentRemoveField(hashtable, (permanent) => permanent.cardSources.Contains(card)))
  12. {
  13. if (!IsByBattle(hashtable))
  14. {
  15. if (!IsByEffect(hashtable, cardEffect => IsOwnerEffect(cardEffect, card)))
  16. {
  17. return true;
  18. }
  19. }
  20. }
  21. return false;
  22. }
  23. #endregion
  24. #region Can activate [Partition]
  25. public static bool CanActivatePartition(Permanent permanent)
  26. {
  27. if (IsPermanentExistsOnBattleArea(permanent))
  28. {
  29. if (permanent.DigivolutionCards.Count >= 2)
  30. {
  31. return true;
  32. }
  33. }
  34. return false;
  35. }
  36. #endregion
  37. #region Effect process of [Partition]
  38. public static IEnumerator PartitionProcess(ICardEffect activateClass, Permanent permanent, List<CardSource> firstSources, List<CardSource> secondSources)
  39. {
  40. yield return ContinuousController.instance.StartCoroutine(new PartitionClass(permanent).Partition(activateClass, firstSources, secondSources));
  41. }
  42. #endregion
  43. #region Partition class
  44. public class PartitionClass
  45. {
  46. public PartitionClass(Permanent permanent)
  47. {
  48. _permanent = permanent;
  49. }
  50. Permanent _permanent = null;
  51. public IEnumerator Partition(ICardEffect activateClass, List<CardSource> firstSources, List<CardSource> secondSources)
  52. {
  53. if (_permanent != null)
  54. {
  55. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  56. CardSource topCard = _permanent.TopCard;
  57. List<CardSource> selectedCards = new List<CardSource>();
  58. bool CanSelectCondition(CardSource source)
  59. {
  60. return true;
  61. }
  62. if (_permanent.TopCard != null)
  63. {
  64. if (firstSources.Count > 1)
  65. {
  66. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  67. selectCardEffect.SetUp(
  68. canTargetCondition: CanSelectCondition,
  69. canTargetCondition_ByPreSelecetedList: null,
  70. canEndSelectCondition: null,
  71. canNoSelect: () => false,
  72. selectCardCoroutine: SelectCardCoroutine,
  73. afterSelectCardCoroutine: null,
  74. message: "Select card to play",
  75. maxCount: 1,
  76. canEndNotMax: false,
  77. isShowOpponent: false,
  78. mode: SelectCardEffect.Mode.Custom,
  79. root: SelectCardEffect.Root.Custom,
  80. customRootCardList: firstSources,
  81. canLookReverseCard: true,
  82. selectPlayer: topCard.Owner,
  83. cardEffect: activateClass);
  84. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  85. }
  86. else
  87. selectedCards.AddRange(firstSources);
  88. if(secondSources.Count > 1)
  89. {
  90. SelectCardEffect selectSecondCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  91. selectSecondCardEffect.SetUp(
  92. canTargetCondition: CanSelectCondition,
  93. canTargetCondition_ByPreSelecetedList: null,
  94. canEndSelectCondition: null,
  95. canNoSelect: () => false,
  96. selectCardCoroutine: SelectCardCoroutine,
  97. afterSelectCardCoroutine: null,
  98. message: "Select card to play",
  99. maxCount: 1,
  100. canEndNotMax: false,
  101. isShowOpponent: false,
  102. mode: SelectCardEffect.Mode.Custom,
  103. root: SelectCardEffect.Root.Custom,
  104. customRootCardList: secondSources,
  105. canLookReverseCard: true,
  106. selectPlayer: topCard.Owner,
  107. cardEffect: activateClass);
  108. yield return ContinuousController.instance.StartCoroutine(selectSecondCardEffect.Activate());
  109. }
  110. else
  111. selectedCards.AddRange(secondSources);
  112. IEnumerator SelectCardCoroutine(CardSource cardSource)
  113. {
  114. selectedCards.Add(cardSource);
  115. secondSources = secondSources.Except(selectedCards).ToList();
  116. yield return null;
  117. }
  118. }
  119. if(selectedCards.Count == 2)
  120. {
  121. yield return ContinuousController.instance.StartCoroutine(PlayPermanentCards(
  122. cardSources: selectedCards,
  123. activateClass: activateClass,
  124. payCost: false,
  125. isTapped: false,
  126. root: SelectCardEffect.Root.DigivolutionCards,
  127. activateETB: true));
  128. }
  129. #region Play Log
  130. string log = "";
  131. log += $"\nPartition :";
  132. log += $"\n{topCard.BaseENGCardNameFromEntity}({topCard.CardID})";
  133. log += "\n";
  134. PlayLog.OnAddLog?.Invoke(log);
  135. #endregion
  136. }
  137. }
  138. }
  139. #endregion
  140. }