ChangeCardDP.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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)
  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. bool CanUseCondition(Hashtable hashtable)
  23. {
  24. if (condition == null || condition())
  25. {
  26. changeCardDPClass.SetEffectName(effectName);
  27. return true;
  28. }
  29. return false;
  30. }
  31. int ChangeDP(CardSource cardSource, int DP)
  32. {
  33. if (CardCondition(cardSource))
  34. {
  35. DP += _changeValue();
  36. }
  37. return DP;
  38. }
  39. bool CardCondition(CardSource cardSource)
  40. {
  41. if (cardSource != null)
  42. {
  43. if (GManager.instance.attackProcess.SecurityDigimon == cardSource)
  44. {
  45. if (cardCondition == null || cardCondition(cardSource))
  46. {
  47. return true;
  48. }
  49. }
  50. }
  51. return false;
  52. }
  53. bool _isUpDown()
  54. {
  55. return true;
  56. }
  57. return changeCardDPClass;
  58. }
  59. #endregion
  60. }