ChangeLinkCostClass.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections.Generic;
  2. using System;
  3. public class ChangeLinkCostClass : ICardEffect, IChangeLinkCostEffect
  4. {
  5. Func<CardSource, Permanent, int, SelectCardEffect.Root, int> _changeCostFunc { get; set; }
  6. Func<CardSource, bool> _cardSourceCondition { get; set; }
  7. Func<Permanent, bool> _permanentCondition { get; set; }
  8. Func<SelectCardEffect.Root, bool> _rootCondition { get; set; }
  9. Func<bool> _isUpDown { get; set; }
  10. public void SetUpChangeLinkCostClass(Func<CardSource, Permanent, int, SelectCardEffect.Root, int> changeCostFunc, Func<CardSource, bool> cardSourceCondition, Func<Permanent, bool> permanentCondition, Func<SelectCardEffect.Root, bool> rootCondition, Func<bool> isUpDown)
  11. {
  12. _changeCostFunc = changeCostFunc;
  13. _cardSourceCondition = cardSourceCondition;
  14. _permanentCondition = permanentCondition;
  15. _rootCondition = rootCondition;
  16. _isUpDown = isUpDown;
  17. }
  18. public int GetCost(int cost, CardSource cardSource, Permanent permanent, SelectCardEffect.Root root)
  19. {
  20. if (cardSource != null
  21. && CardCondition(cardSource)
  22. && PermanentCondition(permanent)
  23. && _changeCostFunc != null
  24. && _rootCondition != null
  25. && _rootCondition(root))
  26. {
  27. int newCost = _changeCostFunc(cardSource, permanent, cost, root);
  28. if (IsUpDown()
  29. && newCost < cost)
  30. {
  31. newCost = cost;
  32. }
  33. cost = newCost;
  34. }
  35. return cost;
  36. }
  37. public bool CardCondition(CardSource cardSource)
  38. {
  39. return _cardSourceCondition != null
  40. && _cardSourceCondition(cardSource);
  41. }
  42. public bool PermanentCondition(Permanent permanent)
  43. {
  44. return _permanentCondition != null
  45. && _permanentCondition(permanent);
  46. }
  47. public bool IsUpDown()
  48. {
  49. return _isUpDown != null
  50. && _isUpDown();
  51. }
  52. }