ChangeCardDP.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 security Digimon card DP
  9. public static ChangeCardDPClass ChangeSecurityDigimonCardDPStaticEffect<T>(Func<CardSource, bool> cardCondition, T changeValue, bool isInheritedEffect, CardSource card, Func<bool> condition, string effectName, bool islinkedEffect = false)
  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. bool isUpValue() => _changeValue() > 0;
  18. ChangeCardDPClass changeCardDPClass = new ChangeCardDPClass();
  19. changeCardDPClass.SetUpICardEffect("", CanUseCondition, card);
  20. changeCardDPClass.SetUpChangeCardDPClass(changeDPFunc: ChangeDP, cardSourceCondition: CardCondition, isUpDown: _isUpDown, isMinusDP: () => !isUpValue());
  21. changeCardDPClass.SetIsInheritedEffect(isInheritedEffect);
  22. changeCardDPClass.SetIsLinkedEffect(islinkedEffect);
  23. bool CanUseCondition(Hashtable hashtable)
  24. {
  25. if (condition == null || condition())
  26. {
  27. changeCardDPClass.SetEffectName(effectName);
  28. return true;
  29. }
  30. return false;
  31. }
  32. int ChangeDP(CardSource cardSource, int DP)
  33. {
  34. if (CardCondition(cardSource))
  35. {
  36. DP += _changeValue();
  37. }
  38. return DP;
  39. }
  40. bool CardCondition(CardSource cardSource)
  41. {
  42. if (cardSource != null)
  43. {
  44. if (GManager.instance.attackProcess.SecurityDigimon == cardSource)
  45. {
  46. if (cardCondition == null || cardCondition(cardSource))
  47. {
  48. return true;
  49. }
  50. }
  51. }
  52. return false;
  53. }
  54. bool _isUpDown()
  55. {
  56. return true;
  57. }
  58. return changeCardDPClass;
  59. }
  60. #endregion
  61. }