Item.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. virtual bool canBeStackedWith(const Item* zItem) const;
  45. virtual bool canBePlacedAt(int dimensionId, Framework::Vec3<int> worldPos) const;
  46. virtual void onPlaced();
  47. virtual Framework::Text getTooltipUIML() const;
  48. virtual void applyInventoryEffects(Entity* zTarget);
  49. virtual void removeInventoryEffects(Entity* zTarget);
  50. virtual void applyEquippedEffects(Entity* zTarget);
  51. virtual void removeEquippedEffects(Entity* zTarget);
  52. virtual void applyFoodEffects(Entity* zTarget);
  53. friend ItemType;
  54. };