Partition.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 PartitionCondition(int level, CardColor color)
  11. {
  12. Level = level;
  13. Color = color;
  14. }
  15. }
  16. public partial class CardEffectFactory
  17. {
  18. #region Trigger effect of [Partition] on oneself
  19. public static ActivateClass PartitionSelfEffect(bool isInheritedEffect, CardSource card, Func<bool> condition, List<PartitionCondition> cardSourceConditions)
  20. {
  21. Permanent targetPermanent = card.PermanentOfThisCard();
  22. List<CardSource> sourceOneCard = targetPermanent.cardSources
  23. .Clone()
  24. .Filter(source =>
  25. source.CardColors.Contains(cardSourceConditions[0].Color)
  26. && (source.HasLevel && source.Level == cardSourceConditions[0].Level));
  27. List<CardSource> sourceTwoCard = targetPermanent.cardSources
  28. .Clone()
  29. .Filter(source =>
  30. source.CardColors.Contains(cardSourceConditions[1].Color)
  31. && (source.HasLevel && source.Level == cardSourceConditions[1].Level));
  32. Debug.Log(sourceOneCard.Count + " ++ " + sourceTwoCard.Count);
  33. foreach (CardSource cardSource in sourceOneCard)
  34. Debug.Log($"First Source Options: {cardSource.BaseENGCardNameFromEntity}");
  35. foreach (CardSource cardSource in sourceTwoCard)
  36. Debug.Log($"Second Source Options: {cardSource.BaseENGCardNameFromEntity}");
  37. if (sourceOneCard.Count == 1)
  38. sourceTwoCard = sourceTwoCard.Except(sourceOneCard).ToList();
  39. if (sourceTwoCard.Count == 1)
  40. sourceOneCard = sourceOneCard.Except(sourceTwoCard).ToList();
  41. Debug.Log(sourceOneCard.Count + " ++ " + sourceTwoCard.Count);
  42. foreach (CardSource cardSource in sourceOneCard)
  43. Debug.Log($"First Source Options: {cardSource.BaseENGCardNameFromEntity}");
  44. foreach (CardSource cardSource in sourceTwoCard)
  45. Debug.Log($"Second Source Options: {cardSource.BaseENGCardNameFromEntity}");
  46. bool CanUseCondition()
  47. {
  48. if (condition == null || condition())
  49. {
  50. return true;
  51. }
  52. return false;
  53. }
  54. return PartitionEffect(targetPermanent: targetPermanent, isInheritedEffect: isInheritedEffect, condition: CanUseCondition, firstSourceCards: sourceOneCard, secondSourceCards: sourceTwoCard, card);
  55. }
  56. #endregion
  57. #region Trigger effect of [Partition]
  58. public static ActivateClass PartitionEffect(Permanent targetPermanent, bool isInheritedEffect, Func<bool> condition, List<CardSource> firstSourceCards, List<CardSource> secondSourceCards, CardSource card)
  59. {
  60. if (targetPermanent == null) return null;
  61. if (targetPermanent.TopCard == null) return null;
  62. if (card == null) return null;
  63. ActivateClass activateClass = new ActivateClass();
  64. activateClass.SetUpICardEffect("Partition", CanUseCondition, card);
  65. activateClass.SetUpActivateClass(CanActivateCondition, ActivateCoroutine, -1, true, EffectDiscription());
  66. activateClass.SetHashString($"Partition_{card.CardID}" + (isInheritedEffect ? "_inherited" : ""));
  67. activateClass.SetIsInheritedEffect(isInheritedEffect);
  68. string EffectDiscription()
  69. {
  70. return DataBase.PartitionEffectDiscription();
  71. }
  72. bool CanUseCondition(Hashtable hashtable)
  73. {
  74. if (CardEffectCommons.CanTriggerPartition(hashtable, card))
  75. {
  76. if (condition == null || condition())
  77. {
  78. return true;
  79. }
  80. }
  81. return false;
  82. }
  83. bool CanActivateCondition(Hashtable hashtable)
  84. {
  85. if (CardEffectCommons.CanActivatePartition(targetPermanent))
  86. {
  87. if (firstSourceCards == null || firstSourceCards.Count > 0)
  88. {
  89. if (secondSourceCards == null || secondSourceCards.Count > 0)
  90. {
  91. return true;
  92. }
  93. }
  94. }
  95. return false;
  96. }
  97. IEnumerator ActivateCoroutine(Hashtable _hashtable)
  98. {
  99. return CardEffectCommons.PartitionProcess(activateClass, targetPermanent, firstSourceCards, secondSourceCards);
  100. }
  101. return activateClass;
  102. }
  103. #endregion
  104. }