ItemFilter.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. bool CombinedItemFilter::matchItem(const Item* zItem) const
  27. {
  28. return op(filterA->matchItem(zItem), filterB->matchItem(zItem));
  29. }
  30. AnyItemFilter::AnyItemFilter()
  31. : ItemFilter()
  32. {}
  33. bool AnyItemFilter::matchItem(const Item* zItem) const
  34. {
  35. return true;
  36. }
  37. TypeItemFilter::TypeItemFilter(const ItemType* zType)
  38. : ItemFilter(),
  39. zType(zType)
  40. {}
  41. bool TypeItemFilter::matchItem(const Item* zItem) const
  42. {
  43. return zItem->zItemType() == zType;
  44. }
  45. SpecificSlotFilter::SpecificSlotFilter(int sourceSlotId, int targetSlotId)
  46. : ItemFilter(),
  47. sourceSlotId(sourceSlotId),
  48. targetSlotId(targetSlotId)
  49. {}
  50. bool SpecificSlotFilter::matchSourceSlot(ItemSlot* zSlot) const
  51. {
  52. return sourceSlotId == zSlot->getId();
  53. }
  54. bool SpecificSlotFilter::matchTargetSlot(ItemSlot* zSlot) const
  55. {
  56. return targetSlotId == zSlot->getId();
  57. }