CSkillHandler.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 DLL_LINKAGE CSkill // secondary skill
  15. {
  16. protected:
  17. struct LevelInfo
  18. {
  19. std::string description; //descriptions of spell for skill level
  20. std::vector<std::shared_ptr<Bonus>> effects;
  21. LevelInfo();
  22. ~LevelInfo();
  23. template <typename Handler> void serialize(Handler & h, const int version)
  24. {
  25. h & description;
  26. h & effects;
  27. }
  28. };
  29. std::vector<LevelInfo> levels; // bonuses provided by basic, advanced and expert level
  30. public:
  31. CSkill(SecondarySkill id = SecondarySkill::DEFAULT);
  32. ~CSkill();
  33. void addNewBonus(const std::shared_ptr<Bonus> & b, int level);
  34. void setDescription(const std::string & desc, int level);
  35. const std::vector<std::shared_ptr<Bonus>> & getBonus(int level) const;
  36. const std::string & getDescription(int level) const;
  37. std::string toString() const;
  38. SecondarySkill id;
  39. std::string identifier;
  40. template <typename Handler> void serialize(Handler & h, const int version)
  41. {
  42. h & id;
  43. h & identifier;
  44. h & levels;
  45. }
  46. friend class CSkillHandler;
  47. friend std::ostream & operator<<(std::ostream & out, const CSkill & skill);
  48. friend std::ostream & operator<<(std::ostream & out, const CSkill::LevelInfo & info);
  49. };
  50. class DLL_LINKAGE CSkillHandler: public CHandlerBase<SecondarySkill, CSkill>
  51. {
  52. public:
  53. CSkillHandler();
  54. virtual ~CSkillHandler();
  55. ///IHandler base
  56. std::vector<JsonNode> loadLegacyData(size_t dataSize) override;
  57. void afterLoadFinalization() override;
  58. void beforeValidate(JsonNode & object) override;
  59. std::vector<bool> getDefaultAllowed() const override;
  60. const std::string getTypeName() const override;
  61. void loadObject(std::string scope, std::string name, const JsonNode & data) override;
  62. void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
  63. template <typename Handler> void serialize(Handler & h, const int version)
  64. {
  65. h & objects;
  66. }
  67. protected:
  68. CSkill * loadFromJson(const JsonNode & json, const std::string & identifier) override;
  69. std::vector<std::shared_ptr<Bonus>> defaultBonus(SecondarySkill skill, int level) const;
  70. };