ChangeDP.cs 3.9 KB

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