ItemType.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 AXE = 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 AXE_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. static const int SHOVEL = BlockTypeEnum::MAX_VALUE + 9;
  26. static const int SHOVEL_BROKEN = BlockTypeEnum::MAX_VALUE + 10;
  27. };
  28. class ItemType : public virtual Framework::ReferenceCounter
  29. {
  30. protected:
  31. const int id;
  32. const Framework::Text name;
  33. Framework::Text tooltipUIML;
  34. ItemSkillLevelUpRule* levelUpRule;
  35. int brokenTypeId;
  36. const ModelInfo model;
  37. ItemType(int id,
  38. const char* name,
  39. ItemSkillLevelUpRule* levelUpRule,
  40. int brokenTypeId,
  41. ModelInfo model);
  42. virtual void loadSuperItem(
  43. Item* zItem, Framework::StreamReader* zReader) const;
  44. virtual void saveSuperItem(
  45. const Item* zItem, Framework::StreamWriter* zWriter) const;
  46. virtual void loadSuperItemSkill(
  47. ItemSkill* zSkill, Framework::StreamReader* zReader) const;
  48. virtual void saveSuperItemSkill(
  49. const ItemSkill* zSkill, Framework::StreamWriter* zWriter) const;
  50. public:
  51. ~ItemType();
  52. int getId() const;
  53. const Framework::Text& getName() const;
  54. const Framework::Text& getTooltipUIML() const;
  55. const ItemType* zBrokenItemType() const;
  56. virtual Item* createItem() const = 0;
  57. virtual ItemStack* createItemStack(int size) const;
  58. virtual ItemSkill* createDefaultItemSkill() const;
  59. virtual void levelUpItemSkill(ItemSkill* zSkill) const;
  60. virtual Item* loadItem(Framework::StreamReader* zReader) const;
  61. virtual void saveItem(
  62. const Item* zItem, Framework::StreamWriter* zWriter) const;
  63. virtual ItemSkill* loadItemSkill(Framework::StreamReader* zReader) const;
  64. virtual void saveItemSkill(
  65. const ItemSkill* zSkill, Framework::StreamWriter* zWriter) const;
  66. virtual Item* cloneItem(const Item* zItem) const;
  67. virtual Item* breakItem(const Item* zItem) const;
  68. const ModelInfo& getModel() const;
  69. virtual void setItemAttribute(Item* zItem,
  70. Framework::Text name,
  71. Framework::JSON::JSONValue* zValue) const;
  72. virtual void addItemAttributes(Item* zItem,
  73. Framework::JSON::JSONObject* zItemObjet) const;
  74. static Item* createBasicItem(int id,
  75. const char* name,
  76. float hp,
  77. float maxHp,
  78. float durability,
  79. float maxDurability,
  80. bool eatable,
  81. bool placeable,
  82. bool equippable,
  83. bool solid,
  84. bool usable,
  85. int maxStackSize);
  86. static int getTypeId(const char* name);
  87. static const ItemType* zByName(const char* name);
  88. };