ChangePlayCost.cs 5.3 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 CardEffectFactory
  7. {
  8. #region Static effect that reduces play cost
  9. public static ChangeCostClass ChangePlayCostStaticEffect<T>(
  10. T changeValue,
  11. Func<Permanent, bool> permanentCondition,
  12. bool isInheritedEffect,
  13. CardSource card,
  14. Func<bool> condition,
  15. bool setFixedCost)
  16. {
  17. bool isInt = typeof(T) == typeof(int);
  18. bool isIntFunc = typeof(T) == typeof(Func<int>);
  19. if (!isInt && !isIntFunc) return null;
  20. if (isInt && (int)(object)changeValue == 0) return null;
  21. if (isIntFunc && changeValue as Func<int> == null) return null;
  22. int _changeValue() => isInt ? (int)(object)changeValue : (changeValue as Func<int>)();
  23. bool isUpValue() => !setFixedCost && _changeValue() > 0;
  24. string effectName()
  25. {
  26. if (!setFixedCost)
  27. {
  28. return isUpValue() ? $"Play Cost +{_changeValue()}" : $"Play Cost {_changeValue()}";
  29. }
  30. return $"Play Cost is {_changeValue()}";
  31. };
  32. ChangeCostClass changeCostClass = new ChangeCostClass();
  33. changeCostClass.SetUpICardEffect(effectName(), CanUseCondition, card);
  34. changeCostClass.SetUpChangeCostClass(
  35. changeCostFunc: ChangeCost,
  36. cardSourceCondition: (card) => true,
  37. rootCondition: (card) => true,
  38. isUpDown: isUpDown,
  39. isCheckAvailability: () => false,
  40. isChangePayingCost: () => false);
  41. if (isInheritedEffect)
  42. {
  43. changeCostClass.SetIsInheritedEffect(true);
  44. }
  45. bool CanUseCondition(Hashtable hashtable)
  46. {
  47. if (condition == null || condition())
  48. {
  49. changeCostClass.SetEffectName(effectName());
  50. return true;
  51. }
  52. return false;
  53. }
  54. int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  55. {
  56. if (PermanentsCondition(targetPermanents))
  57. {
  58. if (!setFixedCost)
  59. {
  60. Cost += _changeValue();
  61. }
  62. else
  63. {
  64. Cost = _changeValue();
  65. }
  66. }
  67. return Cost;
  68. }
  69. bool PermanentsCondition(List<Permanent> targetPermanents)
  70. {
  71. if (targetPermanents != null)
  72. {
  73. if (targetPermanents.Count(PermanentCondition) >= 1)
  74. {
  75. return true;
  76. }
  77. }
  78. return false;
  79. }
  80. bool PermanentCondition(Permanent targetPermanent)
  81. {
  82. if (CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent))
  83. {
  84. return permanentCondition == null || permanentCondition(targetPermanent);
  85. }
  86. return false;
  87. }
  88. bool isUpDown()
  89. {
  90. return !setFixedCost;
  91. }
  92. return changeCostClass;
  93. }
  94. #endregion
  95. #region Mandatory Self Cost Reduction
  96. public static ChangeCostClass MandatorySelfPlayCostReduction<T>(
  97. T changeValue,
  98. CardSource card,
  99. Func<bool> condition = null,
  100. Func<SelectCardEffect.Root, bool> rootCondition = null
  101. )
  102. {
  103. bool isInt = typeof(T) == typeof(int);
  104. bool isIntFunc = typeof(T) == typeof(Func<int>);
  105. if (!isInt && !isIntFunc) return null;
  106. if (isInt && (int)(object)changeValue == 0) return null;
  107. if (isIntFunc && changeValue as Func<int> == null) return null;
  108. int _changeValue() => isInt ? (int)(object)changeValue : (changeValue as Func<int>)();
  109. ChangeCostClass changeCostClass = new ChangeCostClass();
  110. changeCostClass.SetUpICardEffect($"Play Cost -{_changeValue()}", CanUseCondition, card);
  111. changeCostClass.SetUpChangeCostClass(changeCostFunc: ChangeCost, cardSourceCondition: CardSourceCondition, rootCondition: RootCondition, isUpDown: isUpDown, isCheckAvailability: () => false, isChangePayingCost: () => true);
  112. changeCostClass.SetNotShowUI(true);
  113. return changeCostClass;
  114. bool CanUseCondition(Hashtable hashtable)
  115. {
  116. return condition == null || condition();
  117. }
  118. int ChangeCost(CardSource cardSource, int cost, SelectCardEffect.Root root,
  119. List<Permanent> targetPermanents)
  120. {
  121. if (CardSourceCondition(cardSource) &&
  122. RootCondition(root) &&
  123. PermanentsCondition(targetPermanents))
  124. {
  125. cost -= _changeValue();
  126. }
  127. return cost;
  128. }
  129. bool PermanentsCondition(List<Permanent> targetPermanents)
  130. {
  131. return targetPermanents == null || targetPermanents.Count(targetPermanent => targetPermanent != null) == 0;
  132. }
  133. bool CardSourceCondition(CardSource cardSource)
  134. {
  135. return cardSource == card;
  136. }
  137. bool RootCondition(SelectCardEffect.Root root)
  138. {
  139. return rootCondition == null || rootCondition(root);
  140. }
  141. bool isUpDown()
  142. {
  143. return true;
  144. }
  145. }
  146. #endregion
  147. }