Partition.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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, List<PartitionCondition> partitionConditions)
  39. {
  40. yield return ContinuousController.instance.StartCoroutine(new PartitionClass(permanent, partitionConditions).Partition(activateClass, firstSources, secondSources));
  41. }
  42. #endregion
  43. #region Partition class
  44. public class PartitionClass
  45. {
  46. public PartitionClass(Permanent permanent, List<PartitionCondition> conditions)
  47. {
  48. _permanent = permanent;
  49. _conditions = conditions;
  50. }
  51. Permanent _permanent = null;
  52. List<PartitionCondition> _conditions = new List<PartitionCondition>();
  53. string GetConditionColors(PartitionCondition condition)
  54. {
  55. string str = condition.Color.ToString();
  56. if (condition.hasTwoColor)
  57. str += "/" + condition.Color2.ToString();
  58. return str;
  59. }
  60. public IEnumerator Partition(ICardEffect activateClass, List<CardSource> firstSources, List<CardSource> secondSources)
  61. {
  62. if (_permanent != null)
  63. {
  64. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  65. CardSource topCard = _permanent.TopCard;
  66. List<CardSource> selectedCards = new List<CardSource>();
  67. bool CanSelectCondition(CardSource source)
  68. {
  69. return true;
  70. }
  71. string colorsToGrab = "";
  72. if (_permanent.TopCard != null)
  73. {
  74. if (firstSources.Count > 1)
  75. {
  76. colorsToGrab = GetConditionColors(_conditions[0]);
  77. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  78. selectCardEffect.SetUp(
  79. canTargetCondition: CanSelectCondition,
  80. canTargetCondition_ByPreSelecetedList: null,
  81. canEndSelectCondition: null,
  82. canNoSelect: () => false,
  83. selectCardCoroutine: SelectCardCoroutine,
  84. afterSelectCardCoroutine: null,
  85. message: $"Select 1 {colorsToGrab} Digimon to play",
  86. maxCount: 1,
  87. canEndNotMax: false,
  88. isShowOpponent: false,
  89. mode: SelectCardEffect.Mode.Custom,
  90. root: SelectCardEffect.Root.Custom,
  91. customRootCardList: firstSources,
  92. canLookReverseCard: true,
  93. selectPlayer: topCard.Owner,
  94. cardEffect: activateClass);
  95. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  96. }
  97. else
  98. selectedCards.AddRange(firstSources);
  99. if(secondSources.Count > 1)
  100. {
  101. colorsToGrab = GetConditionColors(_conditions[1]);
  102. SelectCardEffect selectSecondCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  103. selectSecondCardEffect.SetUp(
  104. canTargetCondition: CanSelectCondition,
  105. canTargetCondition_ByPreSelecetedList: null,
  106. canEndSelectCondition: null,
  107. canNoSelect: () => false,
  108. selectCardCoroutine: SelectCardCoroutine,
  109. afterSelectCardCoroutine: null,
  110. message: $"Select 1 {colorsToGrab} Digimon to play",
  111. maxCount: 1,
  112. canEndNotMax: false,
  113. isShowOpponent: false,
  114. mode: SelectCardEffect.Mode.Custom,
  115. root: SelectCardEffect.Root.Custom,
  116. customRootCardList: secondSources,
  117. canLookReverseCard: true,
  118. selectPlayer: topCard.Owner,
  119. cardEffect: activateClass);
  120. yield return ContinuousController.instance.StartCoroutine(selectSecondCardEffect.Activate());
  121. }
  122. else
  123. selectedCards.AddRange(secondSources);
  124. IEnumerator SelectCardCoroutine(CardSource cardSource)
  125. {
  126. selectedCards.Add(cardSource);
  127. secondSources = secondSources.Except(selectedCards).ToList();
  128. yield return null;
  129. }
  130. }
  131. if(selectedCards.Count == 2)
  132. {
  133. yield return ContinuousController.instance.StartCoroutine(PlayPermanentCards(
  134. cardSources: selectedCards,
  135. activateClass: activateClass,
  136. payCost: false,
  137. isTapped: false,
  138. root: SelectCardEffect.Root.DigivolutionCards,
  139. activateETB: true));
  140. }
  141. #region Play Log
  142. string log = "";
  143. log += $"\nPartition :";
  144. log += $"\n{topCard.BaseENGCardNameFromEntity}({topCard.CardID})";
  145. log += "\n";
  146. PlayLog.OnAddLog?.Invoke(log);
  147. #endregion
  148. }
  149. }
  150. }
  151. #endregion
  152. }