ChangeLinkMaxClass.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. using Unity.Mathematics;
  6. public class ChangeLinkMaxClass : ICardEffect, IChangeLinkMaxEffect
  7. {
  8. public void SetUpChangeLinkMaxClass(Func<Permanent, int, int> changeLinkMaxFunc, Func<Permanent, bool> permanentCondition, Func<CalculateOrder> isUpDown)
  9. {
  10. _changeLinkMaxFunc = changeLinkMaxFunc;
  11. _permanentCondition = permanentCondition;
  12. _isUpDown = isUpDown;
  13. }
  14. Func<Permanent, int, int> _changeLinkMaxFunc = null;
  15. Func<Permanent, bool> _permanentCondition = null;
  16. Func<CalculateOrder> _isUpDown = null;
  17. public int GetLinkMax(int LinkMax, Permanent permanent, int invertValue)
  18. {
  19. int changedLinkMax = LinkMax;
  20. if (PermanentCondition(permanent))
  21. {
  22. changedLinkMax = _changeLinkMaxFunc(permanent, LinkMax);
  23. switch (invertValue)
  24. {
  25. case -1:
  26. if(changedLinkMax < LinkMax)
  27. changedLinkMax = LinkMax + Mathf.Abs(changedLinkMax - LinkMax);
  28. break;
  29. case 1:
  30. if (changedLinkMax > LinkMax)
  31. changedLinkMax = LinkMax - (changedLinkMax - LinkMax);
  32. break;
  33. }
  34. }
  35. return changedLinkMax;
  36. }
  37. public CalculateOrder isUpDown()
  38. {
  39. if (_isUpDown != null)
  40. {
  41. return _isUpDown();
  42. }
  43. return CalculateOrder.UpToConstant;
  44. }
  45. public bool PermanentCondition(Permanent permanent)
  46. {
  47. if (permanent != null)
  48. {
  49. if (permanent.TopCard != null)
  50. {
  51. if (_permanentCondition != null)
  52. {
  53. if (_permanentCondition(permanent))
  54. {
  55. return true;
  56. }
  57. }
  58. }
  59. }
  60. return false;
  61. }
  62. }