ItemType.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. static const int HOE = BlockTypeEnum::MAX_VALUE + 6;
  23. static const int BROKEN_HOE = BlockTypeEnum::MAX_VALUE + 7;
  24. static const int FLINT = BlockTypeEnum::MAX_VALUE + 8;
  25. };
  26. class ItemType : public virtual Framework::ReferenceCounter
  27. {
  28. protected:
  29. const int id;
  30. const Framework::Text name;
  31. ItemSkillLevelUpRule* levelUpRule;
  32. int brokenTypeId;
  33. const ModelInfo model;
  34. ItemType(int id,
  35. const char* name,
  36. ItemSkillLevelUpRule* levelUpRule,
  37. int brokenTypeId,
  38. ModelInfo model);
  39. virtual void loadSuperItem(
  40. Item* zItem, Framework::StreamReader* zReader) const;
  41. virtual void saveSuperItem(
  42. const Item* zItem, Framework::StreamWriter* zWriter) const;
  43. virtual void loadSuperItemSkill(
  44. ItemSkill* zSkill, Framework::StreamReader* zReader) const;
  45. virtual void saveSuperItemSkill(
  46. const ItemSkill* zSkill, Framework::StreamWriter* zWriter) const;
  47. public:
  48. ~ItemType();
  49. int getId() const;
  50. const Framework::Text& getName() const;
  51. const ItemType* zBrokenItemType() const;
  52. virtual Item* createItem() const = 0;
  53. virtual ItemStack* createItemStack(int size) const;
  54. virtual ItemSkill* createDefaultItemSkill() const;
  55. virtual void levelUpItemSkill(ItemSkill* zSkill) const;
  56. virtual Item* loadItem(Framework::StreamReader* zReader) const;
  57. virtual void saveItem(
  58. const Item* zItem, Framework::StreamWriter* zWriter) const;
  59. virtual ItemSkill* loadItemSkill(Framework::StreamReader* zReader) const;
  60. virtual void saveItemSkill(
  61. const ItemSkill* zSkill, Framework::StreamWriter* zWriter) const;
  62. virtual Item* cloneItem(const Item* zItem) const;
  63. virtual Item* breakItem(const Item* zItem) const;
  64. const ModelInfo& getModel() const;
  65. static Item* createBasicItem(int id,
  66. const char* name,
  67. float hp,
  68. float maxHp,
  69. float durability,
  70. float maxDurability,
  71. bool eatable,
  72. bool placeable,
  73. bool equippable,
  74. bool solid,
  75. bool usable,
  76. int maxStackSize);
  77. };