CSkillHandler.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. std::string name; //as displayed in GUI
  41. template <typename Handler> void serialize(Handler & h, const int version)
  42. {
  43. h & id;
  44. h & identifier;
  45. h & name;
  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. const std::string & skillInfo(int skill, int level) const;
  66. const std::string & skillName(int skill) const;
  67. template <typename Handler> void serialize(Handler & h, const int version)
  68. {
  69. h & objects;
  70. }
  71. protected:
  72. CSkill * loadFromJson(const JsonNode & json, const std::string & identifier) override;
  73. std::vector<std::shared_ptr<Bonus>> defaultBonus(SecondarySkill skill, int level) const;
  74. };