ChangePlayCost.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. }