Item.h 2.4 KB

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