Partition.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. public class PartitionCondition
  7. {
  8. public int Level;
  9. public CardColor Color;
  10. public CardColor Color2;
  11. public bool hasTwoColor = false;
  12. public PartitionCondition(int level, CardColor color)
  13. {
  14. Level = level;
  15. Color = color;
  16. }
  17. public PartitionCondition(int level, CardColor color, CardColor color2)
  18. {
  19. Level = level;
  20. Color = color;
  21. Color2 = color2;
  22. hasTwoColor = true;
  23. }
  24. /*
  25. public bool ContainsAll(List<CardColor> sourceColors)
  26. {
  27. foreach(CardColor cardColor in Color)
  28. {
  29. if(!sourceColors.Contains(cardColor))
  30. return false;
  31. }
  32. return false;
  33. }
  34. */
  35. }
  36. public partial class CardEffectFactory
  37. {
  38. #region Trigger effect of [Partition] on oneself
  39. public static ActivateClass PartitionSelfEffect(bool isInheritedEffect, CardSource card, Func<bool> condition, List<PartitionCondition> cardSourceConditions)
  40. {
  41. Permanent targetPermanent = card.PermanentOfThisCard();
  42. bool CanUseCondition()
  43. {
  44. if (condition == null || condition())
  45. {
  46. return true;
  47. }
  48. return false;
  49. }
  50. return PartitionEffect(targetPermanent: targetPermanent, isInheritedEffect: isInheritedEffect, condition: CanUseCondition, partitionConditions: cardSourceConditions, card);
  51. }
  52. #endregion
  53. #region Trigger effect of [Partition]
  54. public static ActivateClass PartitionEffect(Permanent targetPermanent, bool isInheritedEffect, Func<bool> condition, List<PartitionCondition> partitionConditions, CardSource card)
  55. {
  56. if (targetPermanent == null) return null;
  57. if (targetPermanent.TopCard == null) return null;
  58. if (card == null) return null;
  59. if (partitionConditions[0].hasTwoColor == false || partitionConditions[1].hasTwoColor == false)
  60. {
  61. List<CardSource> sourceOneCard = targetPermanent.cardSources
  62. .Clone()
  63. .Filter(source =>
  64. source.CardColors.Contains(partitionConditions[0].Color)
  65. && (source.HasLevel && source.Level == partitionConditions[0].Level));
  66. List<CardSource> sourceTwoCard = targetPermanent.cardSources
  67. .Clone()
  68. .Filter(source =>
  69. source.CardColors.Contains(partitionConditions[1].Color)
  70. && (source.HasLevel && source.Level == partitionConditions[1].Level));
  71. ActivateClass activateClass = new ActivateClass();
  72. activateClass.SetUpICardEffect("Partition", CanUseCondition, card);
  73. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  74. activateClass.SetHashString($"Partition_{card.CardID}" + (isInheritedEffect ? "_inherited" : ""));
  75. activateClass.SetIsInheritedEffect(isInheritedEffect);
  76. string EffectDiscription()
  77. {
  78. return DataBase.PartitionEffectDiscription();
  79. }
  80. bool CanUseCondition(Hashtable hashtable)
  81. {
  82. if (CardEffectCommons.CanTriggerPartition(hashtable, card))
  83. {
  84. if (condition == null || condition())
  85. {
  86. return true;
  87. }
  88. }
  89. return false;
  90. }
  91. bool CanActivateCondition(Hashtable hashtable)
  92. {
  93. if (CardEffectCommons.CanActivatePartition(targetPermanent))
  94. {
  95. if (sourceOneCard == null || sourceOneCard.Count > 0)
  96. {
  97. if (sourceTwoCard == null || sourceTwoCard.Count > 0)
  98. {
  99. return true;
  100. }
  101. }
  102. }
  103. return false;
  104. }
  105. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  106. {
  107. if (sourceOneCard.Count == 1)
  108. sourceTwoCard = sourceTwoCard.Except(sourceOneCard).ToList();
  109. if (sourceTwoCard.Count == 1)
  110. sourceOneCard = sourceOneCard.Except(sourceTwoCard).ToList();
  111. return CardEffectCommons.PartitionProcess(activateClass, targetPermanent, sourceOneCard, sourceTwoCard);
  112. }
  113. return activateClass;
  114. }
  115. else
  116. {
  117. List<CardSource> sourceOneCard = targetPermanent.cardSources
  118. .Clone()
  119. .Filter(source =>
  120. source.CardColors.Contains(partitionConditions[0].Color) || source.CardColors.Contains(partitionConditions[0].Color2)
  121. && (source.HasLevel && source.Level == partitionConditions[0].Level));
  122. List<CardSource> sourceTwoCard = targetPermanent.cardSources
  123. .Clone()
  124. .Filter(source =>
  125. source.CardColors.Contains(partitionConditions[1].Color) || source.CardColors.Contains(partitionConditions[1].Color2)
  126. && (source.HasLevel && source.Level == partitionConditions[1].Level));
  127. ActivateClass activateClass = new ActivateClass();
  128. activateClass.SetUpICardEffect("Partition", CanUseCondition, card);
  129. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  130. activateClass.SetHashString($"Partition_{card.CardID}" + (isInheritedEffect ? "_inherited" : ""));
  131. activateClass.SetIsInheritedEffect(isInheritedEffect);
  132. string EffectDiscription()
  133. {
  134. return DataBase.PartitionEffectDiscription();
  135. }
  136. bool CanUseCondition(Hashtable hashtable)
  137. {
  138. if (CardEffectCommons.CanTriggerPartition(hashtable, card))
  139. {
  140. if (condition == null || condition())
  141. {
  142. return true;
  143. }
  144. }
  145. return false;
  146. }
  147. bool CanActivateCondition(Hashtable hashtable)
  148. {
  149. if (CardEffectCommons.CanActivatePartition(targetPermanent))
  150. {
  151. if (sourceOneCard == null || sourceOneCard.Count > 0)
  152. {
  153. if (sourceTwoCard == null || sourceTwoCard.Count > 0)
  154. {
  155. return true;
  156. }
  157. }
  158. }
  159. return false;
  160. }
  161. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  162. {
  163. if (sourceOneCard.Count == 1)
  164. sourceTwoCard = sourceTwoCard.Except(sourceOneCard).ToList();
  165. if (sourceTwoCard.Count == 1)
  166. sourceOneCard = sourceOneCard.Except(sourceTwoCard).ToList();
  167. return CardEffectCommons.PartitionProcess(activateClass, targetPermanent, sourceOneCard, sourceTwoCard);
  168. }
  169. return activateClass;
  170. }
  171. }
  172. #endregion
  173. }