ChangeCostClass.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System.Collections.Generic;
  2. using System;
  3. public class ChangeCostClass : ICardEffect, IChangeCostEffect
  4. {
  5. Func<CardSource, int, SelectCardEffect.Root, List<Permanent>, int> _changeCostFunc { get; set; }
  6. Func<CardSource, bool> _cardSourceCondition { get; set; }
  7. Func<SelectCardEffect.Root, bool> _rootCondition { get; set; }
  8. Func<bool> _isUpDown { get; set; }
  9. Func<bool> _isCheckAvailability { get; set; }
  10. Func<bool> _isChangePayingCost { get; set; }
  11. public void SetUpChangeCostClass(Func<CardSource, int, SelectCardEffect.Root, List<Permanent>, int> changeCostFunc, Func<CardSource, bool> cardSourceCondition, Func<SelectCardEffect.Root, bool> rootCondition, Func<bool> isUpDown, Func<bool> isCheckAvailability, Func<bool> isChangePayingCost)
  12. {
  13. _changeCostFunc = changeCostFunc;
  14. _cardSourceCondition = cardSourceCondition;
  15. _rootCondition = rootCondition;
  16. _isUpDown = isUpDown;
  17. _isCheckAvailability = isCheckAvailability;
  18. _isChangePayingCost = isChangePayingCost;
  19. }
  20. public int GetCost(int cost, CardSource cardSource, SelectCardEffect.Root root, List<Permanent> targetPermanents)
  21. {
  22. if (cardSource != null)
  23. {
  24. if (CardCondition(cardSource))
  25. {
  26. if (_changeCostFunc != null)
  27. {
  28. if (_rootCondition != null)
  29. {
  30. if (_rootCondition(root))
  31. {
  32. int newCost = _changeCostFunc(cardSource, cost, root, targetPermanents);
  33. if (IsUpDown())
  34. {
  35. if (newCost < cost)
  36. {
  37. if (!cardSource.Owner.CanReduceCost(targetPermanents, cardSource))
  38. {
  39. newCost = cost;
  40. }
  41. }
  42. }
  43. cost = newCost;
  44. }
  45. }
  46. }
  47. }
  48. }
  49. return cost;
  50. }
  51. public bool CardCondition(CardSource cardSource)
  52. {
  53. if (_cardSourceCondition != null)
  54. {
  55. if (_cardSourceCondition(cardSource))
  56. {
  57. return true;
  58. }
  59. }
  60. return false;
  61. }
  62. public bool IsUpDown()
  63. {
  64. if (_isUpDown != null)
  65. {
  66. return _isUpDown();
  67. }
  68. return false;
  69. }
  70. public bool IsCheckAvailability()
  71. {
  72. if (_isCheckAvailability != null)
  73. {
  74. return _isCheckAvailability();
  75. }
  76. return false;
  77. }
  78. public bool IsChangePayingCost()
  79. {
  80. if (_isChangePayingCost != null)
  81. {
  82. return _isChangePayingCost();
  83. }
  84. return true;
  85. }
  86. }