Partition.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. List<CardSource> sourceOneCard = new List<CardSource>();
  60. List<CardSource> sourceTwoCard = new List<CardSource>();
  61. if (partitionConditions[0].hasTwoColor)
  62. {
  63. sourceOneCard = targetPermanent.cardSources
  64. .Clone()
  65. .Filter(source =>
  66. source.CardColors.Contains(partitionConditions[0].Color) || source.CardColors.Contains(partitionConditions[0].Color2)
  67. && (source.HasLevel && source.Level == partitionConditions[0].Level));
  68. }
  69. else
  70. {
  71. sourceOneCard = targetPermanent.cardSources
  72. .Clone()
  73. .Filter(source =>
  74. source.CardColors.Contains(partitionConditions[0].Color)
  75. && (source.HasLevel && source.Level == partitionConditions[0].Level));
  76. }
  77. if (partitionConditions[1].hasTwoColor)
  78. {
  79. sourceTwoCard = targetPermanent.cardSources
  80. .Clone()
  81. .Filter(source =>
  82. source.CardColors.Contains(partitionConditions[1].Color) || source.CardColors.Contains(partitionConditions[1].Color2)
  83. && (source.HasLevel && source.Level == partitionConditions[1].Level));
  84. }
  85. else
  86. {
  87. sourceTwoCard = targetPermanent.cardSources
  88. .Clone()
  89. .Filter(source =>
  90. source.CardColors.Contains(partitionConditions[1].Color)
  91. && (source.HasLevel && source.Level == partitionConditions[1].Level));
  92. }
  93. ActivateClass activateClass = new ActivateClass();
  94. activateClass.SetUpICardEffect("Partition", CanUseCondition, card);
  95. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  96. activateClass.SetHashString($"Partition_{card.CardID}" + (isInheritedEffect ? "_inherited" : ""));
  97. activateClass.SetIsInheritedEffect(isInheritedEffect);
  98. string EffectDiscription()
  99. {
  100. return DataBase.PartitionEffectDiscription();
  101. }
  102. bool CanUseCondition(Hashtable hashtable)
  103. {
  104. if (CardEffectCommons.CanTriggerPartition(hashtable, card))
  105. {
  106. if (condition == null || condition())
  107. {
  108. return true;
  109. }
  110. }
  111. return false;
  112. }
  113. bool CanActivateCondition(Hashtable hashtable)
  114. {
  115. if (CardEffectCommons.CanActivatePartition(targetPermanent))
  116. {
  117. if (sourceOneCard == null || sourceOneCard.Count > 0)
  118. {
  119. if (sourceTwoCard == null || sourceTwoCard.Count > 0)
  120. {
  121. return true;
  122. }
  123. }
  124. }
  125. return false;
  126. }
  127. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  128. {
  129. if (sourceOneCard.Count == 1)
  130. sourceTwoCard = sourceTwoCard.Except(sourceOneCard).ToList();
  131. if (sourceTwoCard.Count == 1)
  132. sourceOneCard = sourceOneCard.Except(sourceTwoCard).ToList();
  133. return CardEffectCommons.PartitionProcess(activateClass, targetPermanent, sourceOneCard, sourceTwoCard);
  134. }
  135. return activateClass;
  136. }
  137. #endregion
  138. }