CSkillHandler.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * CSkillHandler.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../lib/HeroBonus.h"
  12. #include "GameConstants.h"
  13. #include "IHandlerBase.h"
  14. class CSkillHandler;
  15. class CGHeroInstance;
  16. class CMap;
  17. class JsonSerializeFormat;
  18. class DLL_LINKAGE CSkill // secondary skill
  19. {
  20. protected:
  21. struct LevelInfo
  22. {
  23. std::string description; //descriptions of spell for skill level
  24. std::vector<std::shared_ptr<Bonus>> effects;
  25. LevelInfo();
  26. ~LevelInfo();
  27. template <typename Handler> void serialize(Handler &h, const int version)
  28. {
  29. h & description & effects;
  30. }
  31. };
  32. std::vector<LevelInfo> levels; // bonuses provided by basic, advanced and expert level
  33. public:
  34. CSkill(SecondarySkill id = SecondarySkill::DEFAULT);
  35. ~CSkill();
  36. void addNewBonus(const std::shared_ptr<Bonus>& b, int level);
  37. void setDescription(const std::string & desc, int level);
  38. const std::vector<std::shared_ptr<Bonus>> & getBonus(int level) const;
  39. const std::string & getDescription(int level) const;
  40. std::string toString() const;
  41. SecondarySkill id;
  42. std::string identifier;
  43. template <typename Handler> void serialize(Handler &h, const int version)
  44. {
  45. h & id & identifier;
  46. h & levels;
  47. }
  48. friend class CSkillHandler;
  49. friend std::ostream & operator<<(std::ostream &out, const CSkill &skill);
  50. friend std::ostream & operator<<(std::ostream &out, const CSkill::LevelInfo &info);
  51. };
  52. class DLL_LINKAGE CSkillHandler: public CHandlerBase<SecondarySkill, CSkill>
  53. {
  54. public:
  55. CSkillHandler();
  56. virtual ~CSkillHandler();
  57. ///IHandler base
  58. std::vector<JsonNode> loadLegacyData(size_t dataSize) override;
  59. void afterLoadFinalization() override;
  60. void beforeValidate(JsonNode & object) override;
  61. std::vector<bool> getDefaultAllowed() const override;
  62. const std::string getTypeName() const override;
  63. void loadObject(std::string scope, std::string name, const JsonNode & data) override;
  64. void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
  65. template <typename Handler> void serialize(Handler &h, const int version)
  66. {
  67. h & objects ;
  68. }
  69. protected:
  70. CSkill * loadFromJson(const JsonNode & json, const std::string & identifier) override;
  71. const std::shared_ptr<Bonus> defaultBonus(SecondarySkill skill, int level) const;
  72. };