CSkillHandler.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * CSkillHandler.cpp, 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. #include "StdInc.h"
  11. #include <cctype>
  12. #include "CSkillHandler.h"
  13. #include "CGeneralTextHandler.h"
  14. #include "filesystem/Filesystem.h"
  15. #include "JsonNode.h"
  16. #include "CModHandler.h"
  17. #include "StringConstants.h"
  18. #include "CStack.h"
  19. #include "battle/BattleInfo.h"
  20. #include "battle/CBattleInfoCallback.h"
  21. ///CSkill
  22. CSkill::CSkill()
  23. {
  24. BonusList emptyList;
  25. for(auto level : NSecondarySkill::levels)
  26. bonusByLevel.push_back(emptyList);
  27. }
  28. CSkill::~CSkill()
  29. {
  30. }
  31. void CSkill::addNewBonus(const std::shared_ptr<Bonus>& b, int level)
  32. {
  33. b->source = Bonus::SECONDARY_SKILL;
  34. b->duration = Bonus::PERMANENT;
  35. b->description = identifier;
  36. bonusByLevel[level].push_back(b);
  37. }
  38. BonusList CSkill::getBonus(int level)
  39. {
  40. return bonusByLevel[level];
  41. }
  42. ///CSkillHandler
  43. CSkillHandler::CSkillHandler()
  44. {
  45. }
  46. std::vector<JsonNode> CSkillHandler::loadLegacyData(size_t dataSize)
  47. {
  48. // not supported - no legacy data to load
  49. std::vector<JsonNode> legacyData;
  50. return legacyData;
  51. }
  52. const std::string CSkillHandler::getTypeName() const
  53. {
  54. return "secondarySkill";
  55. }
  56. CSkill * CSkillHandler::loadFromJson(const JsonNode & json, const std::string & identifier)
  57. {
  58. CSkill * skill = new CSkill();
  59. skill->identifier = identifier;
  60. skill->id = SecondarySkill::DEFAULT;
  61. for(int id = 0; id < GameConstants::SKILL_QUANTITY; id++)
  62. {
  63. if(NSecondarySkill::names[id].compare(identifier) == 0)
  64. {
  65. skill->id = SecondarySkill(id);
  66. break;
  67. }
  68. }
  69. for(int level = 1; level < NSecondarySkill::levels.size(); level++)
  70. {
  71. const std::string & levelName = NSecondarySkill::levels[level]; // basic, advanced, expert
  72. for(auto b : json[levelName].Vector())
  73. {
  74. auto bonus = JsonUtils::parseBonus(b);
  75. bonus->sid = skill->id;
  76. skill->addNewBonus(bonus, level);
  77. }
  78. }
  79. return skill;
  80. }
  81. void CSkillHandler::afterLoadFinalization()
  82. {
  83. }
  84. void CSkillHandler::beforeValidate(JsonNode & object)
  85. {
  86. }
  87. CSkillHandler::~CSkillHandler()
  88. {
  89. }
  90. std::vector<bool> CSkillHandler::getDefaultAllowed() const
  91. {
  92. std::vector<bool> allowedSkills(objects.size(), true);
  93. return allowedSkills;
  94. }