ChangeOriginDP.cs 2.9 KB

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