CSkillHandler.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. SecondarySkill id;
  41. std::string identifier;
  42. template <typename Handler> void serialize(Handler &h, const int version)
  43. {
  44. h & id & identifier;
  45. h & levels;
  46. }
  47. friend class CSkillHandler;
  48. friend std::ostream & operator<<(std::ostream &out, const CSkill &skill);
  49. friend std::ostream & operator<<(std::ostream &out, const CSkill::LevelInfo &info);
  50. };
  51. class DLL_LINKAGE CSkillHandler: public CHandlerBase<SecondarySkill, CSkill>
  52. {
  53. public:
  54. CSkillHandler();
  55. virtual ~CSkillHandler();
  56. ///IHandler base
  57. std::vector<JsonNode> loadLegacyData(size_t dataSize) override;
  58. void afterLoadFinalization() override;
  59. void beforeValidate(JsonNode & object) override;
  60. std::vector<bool> getDefaultAllowed() const override;
  61. const std::string getTypeName() const override;
  62. void loadObject(std::string scope, std::string name, const JsonNode & data) override;
  63. void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
  64. template <typename Handler> void serialize(Handler &h, const int version)
  65. {
  66. h & objects ;
  67. }
  68. protected:
  69. CSkill * loadFromJson(const JsonNode & json, const std::string & identifier) override;
  70. const std::shared_ptr<Bonus> defaultBonus(SecondarySkill skill, int level) const;
  71. };