Item.h 2.1 KB

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