ItemType.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #pragma once
  2. #include <JSON.h>
  3. #include <Text.h>
  4. #include <Trie.h>
  5. #include <Writer.h>
  6. #include "BlockType.h"
  7. #include "Effect.h"
  8. #include "ModelInfo.h"
  9. #include "StaticRegistry.h"
  10. class Item;
  11. class ItemStack;
  12. class ItemSkill;
  13. class ItemSkillLevelUpRule;
  14. class ItemTypeEnum : public BlockTypeEnum
  15. {
  16. public:
  17. static const int WOOD_STICK = BlockTypeEnum::MAX_VALUE + 1;
  18. static const int STONE_TOOL = BlockTypeEnum::MAX_VALUE + 2;
  19. static const int RESIN = BlockTypeEnum::MAX_VALUE + 3;
  20. static const int PLAYER_HAND = BlockTypeEnum::MAX_VALUE + 4;
  21. static const int STONE_TOOL_BROKEN = BlockTypeEnum::MAX_VALUE + 5;
  22. };
  23. class ItemType : public virtual Framework::ReferenceCounter
  24. {
  25. protected:
  26. const int id;
  27. const Framework::Text name;
  28. ItemSkillLevelUpRule* levelUpRule;
  29. int brokenTypeId;
  30. const ModelInfo model;
  31. ItemType(int id,
  32. const char* name,
  33. ItemSkillLevelUpRule* levelUpRule,
  34. int brokenTypeId,
  35. ModelInfo model);
  36. virtual void loadSuperItem(
  37. Item* zItem, Framework::StreamReader* zReader) const;
  38. virtual void saveSuperItem(
  39. const Item* zItem, Framework::StreamWriter* zWriter) const;
  40. virtual void loadSuperItemSkill(
  41. ItemSkill* zSkill, Framework::StreamReader* zReader) const;
  42. virtual void saveSuperItemSkill(
  43. const ItemSkill* zSkill, Framework::StreamWriter* zWriter) const;
  44. public:
  45. ~ItemType();
  46. int getId() const;
  47. const Framework::Text& getName() const;
  48. const ItemType* zBrokenItemType() const;
  49. virtual Item* createItem() const = 0;
  50. virtual ItemStack* createItemStack(int size) const;
  51. virtual ItemSkill* createDefaultItemSkill() const;
  52. virtual void levelUpItemSkill(ItemSkill* zSkill) const;
  53. virtual Item* loadItem(Framework::StreamReader* zReader) const;
  54. virtual void saveItem(
  55. const Item* zItem, Framework::StreamWriter* zWriter) const;
  56. virtual ItemSkill* loadItemSkill(Framework::StreamReader* zReader) const;
  57. virtual void saveItemSkill(
  58. const ItemSkill* zSkill, Framework::StreamWriter* zWriter) const;
  59. virtual Item* cloneItem(const Item* zItem) const;
  60. virtual Item* breakItem(const Item* zItem) const;
  61. const ModelInfo& getModel() const;
  62. static Item* createBasicItem(int id,
  63. const char* name,
  64. float hp,
  65. float maxHp,
  66. float durability,
  67. float maxDurability,
  68. bool eatable,
  69. bool placeable,
  70. bool equippable,
  71. bool solid,
  72. bool usable,
  73. int maxStackSize);
  74. };