ChangeDigivolutionCost.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 digivolution cost
  9. public static ChangeCostClass ChangeDigivolutionCostStaticEffect<T>(
  10. T changeValue,
  11. Func<Permanent, bool> permanentCondition,
  12. Func<CardSource, bool> cardCondition,
  13. Func<SelectCardEffect.Root, bool> rootCondition,
  14. bool isInheritedEffect,
  15. CardSource card,
  16. Func<bool> condition,
  17. bool setFixedCost)
  18. {
  19. bool isInt = typeof(T) == typeof(int);
  20. bool isIntFunc = typeof(T) == typeof(Func<int>);
  21. if (!isInt && !isIntFunc) return null;
  22. if (isInt && (int)(object)changeValue == 0) return null;
  23. if (isIntFunc && changeValue as Func<int> == null) return null;
  24. int _changeValue() => isInt ? (int)(object)changeValue : (changeValue as Func<int>)();
  25. bool isUpValue() => !setFixedCost && _changeValue() > 0;
  26. string effectName()
  27. {
  28. if (!setFixedCost)
  29. {
  30. return isUpValue() ? $"Digivolution Cost +{_changeValue()}" : $"Digivolution Cost {_changeValue()}";
  31. }
  32. return $"Digivolution Cost is {_changeValue()}";
  33. };
  34. ChangeCostClass changeCostClass = new ChangeCostClass();
  35. changeCostClass.SetUpICardEffect("", CanUseCondition, card);
  36. changeCostClass.SetUpChangeCostClass(
  37. changeCostFunc: ChangeCost,
  38. cardSourceCondition: CardCondition,
  39. rootCondition: RootCondition,
  40. isUpDown: isUpDown,
  41. isCheckAvailability: () => false,
  42. isChangePayingCost: () => true);
  43. if (isInheritedEffect)
  44. {
  45. changeCostClass.SetIsInheritedEffect(true);
  46. }
  47. bool CanUseCondition(Hashtable hashtable)
  48. {
  49. if (condition == null || condition())
  50. {
  51. changeCostClass.SetEffectName(effectName());
  52. return true;
  53. }
  54. return false;
  55. }
  56. int ChangeCost(CardSource cardSource, int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  57. {
  58. if (CardCondition(cardSource))
  59. {
  60. if (RootCondition(root))
  61. {
  62. if (PermanentsCondition(targetPermanents))
  63. {
  64. if (!setFixedCost)
  65. {
  66. Cost += _changeValue();
  67. }
  68. else
  69. {
  70. Cost = _changeValue();
  71. }
  72. }
  73. }
  74. }
  75. return Cost;
  76. }
  77. bool PermanentsCondition(List<Permanent> targetPermanents)
  78. {
  79. if (targetPermanents != null)
  80. {
  81. if (targetPermanents.Count(PermanentCondition) >= 1)
  82. {
  83. return true;
  84. }
  85. }
  86. return false;
  87. }
  88. bool PermanentCondition(Permanent targetPermanent)
  89. {
  90. if (CardEffectCommons.IsPermanentExistsOnField(targetPermanent))
  91. {
  92. return permanentCondition == null || permanentCondition(targetPermanent);
  93. }
  94. return false;
  95. }
  96. bool CardCondition(CardSource cardSource)
  97. {
  98. if (cardSource != null)
  99. {
  100. return cardCondition == null || cardCondition(cardSource);
  101. }
  102. return false;
  103. }
  104. bool RootCondition(SelectCardEffect.Root root)
  105. {
  106. return rootCondition == null || rootCondition(root);
  107. }
  108. bool isUpDown()
  109. {
  110. return !setFixedCost;
  111. }
  112. return changeCostClass;
  113. }
  114. #endregion
  115. }