CSkillHandler.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 <vcmi/Skill.h>
  12. #include <vcmi/SkillService.h>
  13. #include "../lib/bonuses/Bonus.h"
  14. #include "GameConstants.h"
  15. #include "IHandlerBase.h"
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. class JsonSerializeFormat;
  18. class DLL_LINKAGE CSkill : public Skill
  19. {
  20. public:
  21. struct LevelInfo
  22. {
  23. std::string iconSmall;
  24. std::string iconMedium;
  25. std::string iconLarge;
  26. std::string scenarioBonus;
  27. std::vector<std::shared_ptr<Bonus>> effects;
  28. };
  29. private:
  30. std::vector<LevelInfo> levels; // bonuses provided by basic, advanced and expert level
  31. void addNewBonus(const std::shared_ptr<Bonus> & b, int level);
  32. int32_t getIconIndex() const override;
  33. SecondarySkill id;
  34. std::string modScope;
  35. std::string identifier;
  36. public:
  37. CSkill(const SecondarySkill & id = SecondarySkill::NONE, std::string identifier = "default", bool obligatoryMajor = false, bool obligatoryMinor = false);
  38. ~CSkill() = default;
  39. enum class Obligatory : ui8
  40. {
  41. MAJOR = 0,
  42. MINOR = 1,
  43. };
  44. int32_t getIndex() const override;
  45. int32_t getIconIndex(uint8_t skillMasterLevel) const;
  46. std::string getJsonKey() const override;
  47. std::string getModScope() const override;
  48. void registerIcons(const IconRegistar & cb) const override;
  49. SecondarySkill getId() const override;
  50. std::string getNameTextID() const override;
  51. std::string getNameTranslated() const override;
  52. std::string getDescriptionTextID(int level) const override;
  53. std::string getDescriptionTranslated(int level) const override;
  54. const LevelInfo & at(int level) const;
  55. LevelInfo & at(int level);
  56. std::string toString() const;
  57. bool obligatory(Obligatory val) const { return val == Obligatory::MAJOR ? obligatoryMajor : obligatoryMinor; };
  58. std::array<si32, 2> gainChance; // gainChance[0/1] = default gain chance on level-up for might/magic heroes
  59. /// Bonuses that should be given to hero that specializes in this skill
  60. std::vector<std::shared_ptr<const Bonus>> specialtyTargetBonuses;
  61. void updateFrom(const JsonNode & data);
  62. void serializeJson(JsonSerializeFormat & handler);
  63. bool onlyOnWaterMap;
  64. bool special;
  65. friend class CSkillHandler;
  66. friend DLL_LINKAGE std::ostream & operator<<(std::ostream & out, const CSkill & skill);
  67. friend DLL_LINKAGE std::ostream & operator<<(std::ostream & out, const CSkill::LevelInfo & info);
  68. private:
  69. bool obligatoryMajor;
  70. bool obligatoryMinor;
  71. };
  72. class DLL_LINKAGE CSkillHandler: public CHandlerBase<SecondarySkill, Skill, CSkill, SkillService>
  73. {
  74. public:
  75. ///IHandler base
  76. std::vector<JsonNode> loadLegacyData() override;
  77. void afterLoadFinalization() override;
  78. void beforeValidate(JsonNode & object) override;
  79. std::set<SecondarySkill> getDefaultAllowed() const;
  80. protected:
  81. const std::vector<std::string> & getTypeNames() const override;
  82. std::shared_ptr<CSkill> loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index) override;
  83. };
  84. VCMI_LIB_NAMESPACE_END