ChangeOriginDP.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 origin DP
  9. public static ChangeBaseDPClass ChangeBaseDPStaticEffect<T>(Permanent targetPermanent, T changeValue, bool isInheritedEffect, CardSource card, Func<bool> condition)
  10. {
  11. bool isInt = typeof(T) == typeof(int);
  12. bool isIntFunc = typeof(T) == typeof(Func<int>);
  13. if (!isInt && !isIntFunc) return null;
  14. if (isInt && (int)(object)changeValue == 0) return null;
  15. if (isIntFunc && changeValue as Func<int> == null) return null;
  16. int _changeValue() => isInt ? (int)(object)changeValue : (changeValue as Func<int>)();
  17. string effectName() => $"Origin DP is {_changeValue()}";
  18. ChangeBaseDPClass changeBaseDPClass = new ChangeBaseDPClass();
  19. changeBaseDPClass.SetUpICardEffect("", CanUseCondition, card);
  20. changeBaseDPClass.SetUpChangeBaseDPClass(changeDPFunc: ChangeDP, permanentCondition: PermanentCondition, isUpDownFunc: _isUpDown, isMinusDPFunc: () => false);
  21. changeBaseDPClass.SetIsInheritedEffect(isInheritedEffect);
  22. bool CanUseCondition(Hashtable hashtable)
  23. {
  24. if (CardEffectCommons.IsPermanentExistsOnBattleArea(targetPermanent))
  25. {
  26. if (condition == null || condition())
  27. {
  28. changeBaseDPClass.SetEffectName(effectName());
  29. return true;
  30. }
  31. }
  32. return false;
  33. }
  34. int ChangeDP(Permanent permanent, int DP)
  35. {
  36. if (PermanentCondition(permanent))
  37. {
  38. DP = _changeValue();
  39. }
  40. return DP;
  41. }
  42. bool PermanentCondition(Permanent permanent)
  43. {
  44. if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
  45. {
  46. if (!permanent.TopCard.CanNotBeAffected(changeBaseDPClass))
  47. {
  48. if (permanent == targetPermanent)
  49. {
  50. return true;
  51. }
  52. }
  53. }
  54. return false;
  55. }
  56. bool _isUpDown()
  57. {
  58. return false;
  59. }
  60. return changeBaseDPClass;
  61. }
  62. #endregion
  63. }