ChangeDP.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 changes one's own DP
  9. public static ChangeDPClass ChangeSelfDPStaticEffect<T>(
  10. T changeValue,
  11. bool isInheritedEffect,
  12. CardSource card,
  13. Func<bool> condition,
  14. bool isLinkedEffect = false)
  15. {
  16. bool CanUseCondition()
  17. {
  18. if (CardEffectCommons.IsExistOnBattleAreaDigimon(card))
  19. {
  20. if (condition == null || condition())
  21. {
  22. return true;
  23. }
  24. }
  25. return false;
  26. }
  27. return ChangeTargetDPStaticEffect(
  28. targetPermanent: card.PermanentOfThisCard(),
  29. changeValue: changeValue,
  30. isInheritedEffect: isInheritedEffect,
  31. card: card,
  32. condition: CanUseCondition,
  33. isLinkedEffect: isLinkedEffect);
  34. }
  35. #endregion
  36. #region Static effect that changes DP
  37. public static ChangeDPClass ChangeTargetDPStaticEffect<T>(
  38. Permanent targetPermanent,
  39. T changeValue,
  40. bool isInheritedEffect,
  41. CardSource card,
  42. Func<bool> condition,
  43. bool isLinkedEffect = false)
  44. {
  45. bool PermanentCondition(Permanent permanent)
  46. {
  47. return permanent == targetPermanent;
  48. }
  49. return ChangeDPStaticEffect(
  50. permanentCondition: PermanentCondition,
  51. changeValue: changeValue,
  52. isInheritedEffect: isInheritedEffect,
  53. card: card,
  54. condition: condition,
  55. effectName: null,
  56. isLinkedEffect: isLinkedEffect
  57. );
  58. }
  59. public static ChangeDPClass ChangeDPStaticEffect<T>(
  60. Func<Permanent, bool> permanentCondition,
  61. T changeValue,
  62. bool isInheritedEffect,
  63. CardSource card,
  64. Func<bool> condition,
  65. Func<string> effectName,
  66. bool isLinkedEffect = false)
  67. {
  68. bool isInt = typeof(T) == typeof(int);
  69. bool isIntFunc = typeof(T) == typeof(Func<int>);
  70. if (!isInt && !isIntFunc) return null;
  71. if (isInt && (int)(object)changeValue == 0) return null;
  72. if (isIntFunc && changeValue as Func<int> == null) return null;
  73. int _changeValue() => isInt ? (int)(object)changeValue : (changeValue as Func<int>)();
  74. bool isUpValue() => _changeValue() > 0;
  75. string EffectName()
  76. {
  77. if (effectName != null)
  78. {
  79. return effectName();
  80. }
  81. return isUpValue() ? $"DP +{_changeValue()}" : $"DP {_changeValue()}";
  82. }
  83. ChangeDPClass changeDPClass = new ChangeDPClass();
  84. changeDPClass.SetUpICardEffect("", CanUseCondition, card);
  85. changeDPClass.SetUpChangeDPClass(ChangeDP: ChangeDP, permanentCondition: PermanentCondition, isUpDown: _isUpDown, isMinusDP: () => !isUpValue());
  86. changeDPClass.SetIsInheritedEffect(isInheritedEffect);
  87. changeDPClass.SetIsLinkedEffect(isLinkedEffect);
  88. bool CanUseCondition(Hashtable hashtable)
  89. {
  90. if (condition == null || condition())
  91. {
  92. changeDPClass.SetEffectName(EffectName());
  93. return true;
  94. }
  95. return false;
  96. }
  97. int ChangeDP(Permanent permanent, int DP)
  98. {
  99. if (PermanentCondition(permanent))
  100. {
  101. DP += _changeValue();
  102. }
  103. return DP;
  104. }
  105. bool PermanentCondition(Permanent permanent)
  106. {
  107. if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
  108. {
  109. if (!permanent.TopCard.CanNotBeAffected(changeDPClass))
  110. {
  111. if (permanentCondition == null || permanentCondition(permanent))
  112. {
  113. return true;
  114. }
  115. }
  116. }
  117. return false;
  118. }
  119. bool _isUpDown()
  120. {
  121. return true;
  122. }
  123. return changeDPClass;
  124. }
  125. #endregion
  126. }