ItemFilter.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include "ItemFilter.h"
  2. #include "ItemType.h"
  3. #include "Item.h"
  4. #include "ItemSlot.h"
  5. ItemFilter::ItemFilter()
  6. : ReferenceCounter()
  7. {}
  8. bool ItemFilter::matchItem(const Item* zItem) const
  9. {
  10. return 1;
  11. }
  12. bool ItemFilter::matchSourceSlot(ItemSlot* zSlot) const
  13. {
  14. return zSlot->zStack() ? matchItem(zSlot->zStack()->zItem()) : 0;
  15. }
  16. bool ItemFilter::matchTargetSlot(ItemSlot* zSlot) const
  17. {
  18. return 1;
  19. }
  20. CombinedItemFilter::CombinedItemFilter(ItemFilter* filterA, ItemFilter* filterB, std::function<bool(bool, bool)> op)
  21. : ItemFilter(),
  22. filterA(filterA),
  23. filterB(filterB),
  24. op(op)
  25. {}
  26. CombinedItemFilter::~CombinedItemFilter()
  27. {
  28. filterA->release();
  29. filterB->release();
  30. }
  31. bool CombinedItemFilter::matchItem(const Item* zItem) const
  32. {
  33. return op(filterA->matchItem(zItem), filterB->matchItem(zItem));
  34. }
  35. AnyItemFilter::AnyItemFilter()
  36. : ItemFilter()
  37. {}
  38. bool AnyItemFilter::matchItem(const Item* zItem) const
  39. {
  40. return true;
  41. }
  42. TypeItemFilter::TypeItemFilter(const ItemType* zType)
  43. : ItemFilter(),
  44. zType(zType)
  45. {}
  46. bool TypeItemFilter::matchItem(const Item* zItem) const
  47. {
  48. return zItem->zItemType() == zType;
  49. }
  50. SpecificSlotFilter::SpecificSlotFilter(int sourceSlotId, int targetSlotId)
  51. : ItemFilter(),
  52. sourceSlotId(sourceSlotId),
  53. targetSlotId(targetSlotId)
  54. {}
  55. bool SpecificSlotFilter::matchSourceSlot(ItemSlot* zSlot) const
  56. {
  57. return sourceSlotId == zSlot->getId();
  58. }
  59. bool SpecificSlotFilter::matchTargetSlot(ItemSlot* zSlot) const
  60. {
  61. return targetSlotId == zSlot->getId();
  62. }
  63. SourceSlotBlacklistFilter::SourceSlotBlacklistFilter()
  64. : ItemFilter()
  65. {}
  66. void SourceSlotBlacklistFilter::addBlackListSlotId(int id)
  67. {
  68. blackList.add(id);
  69. }
  70. bool SourceSlotBlacklistFilter::matchSourceSlot(ItemSlot* zSlot) const
  71. {
  72. for (int black : blackList)
  73. {
  74. if (black == zSlot->getId())
  75. return 0;
  76. }
  77. return 1;
  78. }
  79. bool SourceSlotBlacklistFilter::matchTargetSlot(ItemSlot* zSlot) const
  80. {
  81. return 1;
  82. }