ChangeSAttackClass.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 ChangeSAttackClass : ICardEffect, IChangeSAttackEffect
  7. {
  8. public void SetUpChangeSAttackClass(Func<Permanent, int, int> changeSAttackFunc, Func<Permanent, bool> permanentCondition, Func<CalculateOrder> isUpDown)
  9. {
  10. _changeSAttackFunc = changeSAttackFunc;
  11. _permanentCondition = permanentCondition;
  12. _isUpDown = isUpDown;
  13. }
  14. Func<Permanent, int, int> _changeSAttackFunc = null;
  15. Func<Permanent, bool> _permanentCondition = null;
  16. Func<CalculateOrder> _isUpDown = null;
  17. public int GetSAttack(int SAttack, Permanent permanent, int invertValue)
  18. {
  19. int changedSAttack = SAttack;
  20. if (PermanentCondition(permanent))
  21. {
  22. changedSAttack = _changeSAttackFunc(permanent, SAttack);
  23. switch (invertValue)
  24. {
  25. case -1:
  26. if(changedSAttack < SAttack)
  27. changedSAttack = SAttack + Mathf.Abs(changedSAttack - SAttack);
  28. break;
  29. case 1:
  30. if (changedSAttack > SAttack)
  31. changedSAttack = SAttack - (changedSAttack - SAttack);
  32. break;
  33. }
  34. }
  35. return changedSAttack;
  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. }