Item.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. #include "ItemType.h"
  3. #include "Reader.h"
  4. class ItemType;
  5. class BlockType;
  6. class StoneToolItemType;
  7. class Item : public virtual Framework::ReferenceCounter
  8. {
  9. protected:
  10. int itemTypeId;
  11. int blockTypeId;
  12. float hp; // an item will be removed once its hp reaches 0
  13. float maxHp;
  14. float durability; // an item will break into another item once its
  15. // durability reaches 0
  16. float maxDurability;
  17. bool eatable;
  18. bool placeable;
  19. bool equippable;
  20. bool solid;
  21. bool usable;
  22. int maxStackSize;
  23. Framework::Text name;
  24. std::function<void(Entity*)> foodEffect;
  25. Item(int itemTypeId, const char* name);
  26. public:
  27. void setHp(float hp);
  28. void setDurability(float durability);
  29. virtual void tick();
  30. void setFoodEffect(std::function<void(Entity*)> foodEffect);
  31. const ItemType* zItemType() const;
  32. int getTypeId() const;
  33. const BlockType* zPlacedBlockType() const;
  34. float getHp() const;
  35. float getDurability() const;
  36. bool isUsable() const;
  37. bool isEatable() const;
  38. bool isPlaceable() const;
  39. bool isEquippable() const;
  40. bool isSolid() const;
  41. float getMaxDurability() const;
  42. int getMaxStackSize() const;
  43. float getMaxHp() const;
  44. const Framework::Text& getName() const;
  45. virtual bool canBeStackedWith(const Item* zItem) const;
  46. virtual bool canBePlacedAt(int dimensionId, Framework::Vec3<int> worldPos) const;
  47. virtual void onPlaced();
  48. virtual Framework::Text getTooltipUIML() const;
  49. virtual void applyInventoryEffects(Entity* zTarget);
  50. virtual void removeInventoryEffects(Entity* zTarget);
  51. virtual void applyEquippedEffects(Entity* zTarget);
  52. virtual void removeEquippedEffects(Entity* zTarget);
  53. virtual void applyFoodEffects(Entity* zTarget);
  54. friend ItemType;
  55. };