Item.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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<bool(Item*, Entity*)> foodEffect;
  26. std::function<bool(const Item*, Entity*)> foodEffectDestroysItemTest;
  27. Item(int itemTypeId, const char* 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. 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. float getMaxDurability() const;
  45. int getMaxStackSize() const;
  46. float getMaxHp() const;
  47. const Framework::Text& getName() const;
  48. virtual bool canBeStackedWith(const Item* zItem) const;
  49. virtual bool canBePlacedAt(
  50. int dimensionId, Framework::Vec3<int> worldPos) const;
  51. virtual void onPlaced();
  52. virtual Framework::Text getTooltipUIML() const;
  53. virtual void applyInventoryEffects(Entity* zTarget);
  54. virtual void removeInventoryEffects(Entity* zTarget);
  55. virtual void applyEquippedEffects(Entity* zTarget);
  56. virtual void removeEquippedEffects(Entity* zTarget);
  57. virtual bool applyFoodEffects(Entity* zTarget);
  58. virtual bool canApplyFoodEffectsFully(Entity* zTarget) const;
  59. friend ItemType;
  60. };
  61. class ItomJsonType : public TypeFactory<Item>
  62. {
  63. public:
  64. ItomJsonType();
  65. Item* fromJson(Framework::JSON::JSONValue* zJson) const override;
  66. Framework::JSON::JSONValue* toJson(Item* zObject) const override;
  67. Framework::JSON::Validator::JSONValidator*
  68. getValidator() const override;
  69. };