CHeroHandler.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * CHeroHandler.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 <vcmi/HeroTypeService.h>
  12. #include "CHero.h" // convenience include - users of handler generally also use its entity
  13. #include "../../GameConstants.h"
  14. #include "../../IHandlerBase.h"
  15. VCMI_LIB_NAMESPACE_BEGIN
  16. class DLL_LINKAGE CHeroHandler : public CHandlerBase<HeroTypeID, HeroType, CHero, HeroTypeService>
  17. {
  18. /// expPerLEvel[i] is amount of exp needed to reach level i;
  19. /// consists of 196 values. Any higher levels require experience larger that TExpType can hold
  20. std::vector<TExpType> expPerLevel;
  21. /// helpers for loading to avoid huge load functions
  22. void loadHeroArmy(CHero * hero, const JsonNode & node) const;
  23. void loadHeroSkills(CHero * hero, const JsonNode & node) const;
  24. void loadHeroSpecialty(CHero * hero, const JsonNode & node);
  25. void loadExperience();
  26. std::vector<std::function<void()>> callAfterLoadFinalization;
  27. public:
  28. ui32 level(TExpType experience) const; //calculates level corresponding to given experience amount
  29. TExpType reqExp(ui32 level) const; //calculates experience required for given level
  30. ui32 maxSupportedLevel() const;
  31. std::vector<JsonNode> loadLegacyData() override;
  32. void beforeValidate(JsonNode & object) override;
  33. void loadObject(std::string scope, std::string name, const JsonNode & data) override;
  34. void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
  35. void afterLoadFinalization() override;
  36. CHeroHandler();
  37. ~CHeroHandler();
  38. std::set<HeroTypeID> getDefaultAllowed() const;
  39. protected:
  40. const std::vector<std::string> & getTypeNames() const override;
  41. std::shared_ptr<CHero> loadFromJson(const std::string & scope, const JsonNode & node, const std::string & identifier, size_t index) override;
  42. };
  43. VCMI_LIB_NAMESPACE_END