2017-08-20 09:18:07 +02:00
|
|
|
/*
|
|
|
|
* CSkillHandler.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../lib/HeroBonus.h"
|
|
|
|
#include "GameConstants.h"
|
|
|
|
#include "IHandlerBase.h"
|
|
|
|
|
|
|
|
class DLL_LINKAGE CSkill // secondary skill
|
|
|
|
{
|
|
|
|
protected:
|
2017-08-25 03:35:02 +02:00
|
|
|
struct LevelInfo
|
|
|
|
{
|
|
|
|
std::string description; //descriptions of spell for skill level
|
|
|
|
std::vector<std::shared_ptr<Bonus>> effects;
|
|
|
|
|
|
|
|
LevelInfo();
|
|
|
|
~LevelInfo();
|
|
|
|
|
2017-08-30 09:19:54 +02:00
|
|
|
template <typename Handler> void serialize(Handler & h, const int version)
|
2017-08-25 03:35:02 +02:00
|
|
|
{
|
2017-08-30 09:19:54 +02:00
|
|
|
h & description;
|
|
|
|
h & effects;
|
2017-08-25 03:35:02 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<LevelInfo> levels; // bonuses provided by basic, advanced and expert level
|
2017-08-20 09:18:07 +02:00
|
|
|
|
|
|
|
public:
|
2017-08-30 06:23:03 +02:00
|
|
|
CSkill(SecondarySkill id = SecondarySkill::DEFAULT);
|
|
|
|
~CSkill();
|
|
|
|
|
2017-08-30 09:19:54 +02:00
|
|
|
void addNewBonus(const std::shared_ptr<Bonus> & b, int level);
|
2017-08-30 06:23:03 +02:00
|
|
|
void setDescription(const std::string & desc, int level);
|
|
|
|
const std::vector<std::shared_ptr<Bonus>> & getBonus(int level) const;
|
|
|
|
const std::string & getDescription(int level) const;
|
|
|
|
std::string toString() const;
|
|
|
|
|
|
|
|
SecondarySkill id;
|
|
|
|
std::string identifier;
|
2017-08-30 12:35:23 +02:00
|
|
|
std::string name; //as displayed in GUI
|
2017-08-30 06:23:03 +02:00
|
|
|
|
2017-08-30 09:19:54 +02:00
|
|
|
template <typename Handler> void serialize(Handler & h, const int version)
|
2017-08-30 06:23:03 +02:00
|
|
|
{
|
2017-08-30 09:19:54 +02:00
|
|
|
h & id;
|
|
|
|
h & identifier;
|
2017-08-30 12:35:23 +02:00
|
|
|
h & name;
|
2017-08-30 06:23:03 +02:00
|
|
|
h & levels;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend class CSkillHandler;
|
2017-08-31 00:29:25 +02:00
|
|
|
friend DLL_LINKAGE std::ostream & operator<<(std::ostream & out, const CSkill & skill);
|
|
|
|
friend DLL_LINKAGE std::ostream & operator<<(std::ostream & out, const CSkill::LevelInfo & info);
|
2017-08-20 09:18:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CSkillHandler: public CHandlerBase<SecondarySkill, CSkill>
|
|
|
|
{
|
|
|
|
public:
|
2017-08-30 06:23:03 +02:00
|
|
|
CSkillHandler();
|
|
|
|
virtual ~CSkillHandler();
|
2017-08-20 09:18:07 +02:00
|
|
|
|
2017-08-30 06:23:03 +02:00
|
|
|
///IHandler base
|
|
|
|
std::vector<JsonNode> loadLegacyData(size_t dataSize) override;
|
|
|
|
void afterLoadFinalization() override;
|
|
|
|
void beforeValidate(JsonNode & object) override;
|
2017-08-20 09:18:07 +02:00
|
|
|
|
2017-08-30 06:23:03 +02:00
|
|
|
std::vector<bool> getDefaultAllowed() const override;
|
|
|
|
const std::string getTypeName() const override;
|
2017-08-20 09:18:07 +02:00
|
|
|
|
2017-08-30 12:35:23 +02:00
|
|
|
const std::string & skillInfo(int skill, int level) const;
|
|
|
|
const std::string & skillName(int skill) const;
|
|
|
|
|
2017-08-30 09:19:54 +02:00
|
|
|
template <typename Handler> void serialize(Handler & h, const int version)
|
2017-08-30 06:23:03 +02:00
|
|
|
{
|
2017-08-30 09:19:54 +02:00
|
|
|
h & objects;
|
2017-08-30 06:23:03 +02:00
|
|
|
}
|
2017-08-20 09:18:07 +02:00
|
|
|
|
|
|
|
protected:
|
2017-07-20 06:08:49 +02:00
|
|
|
CSkill * loadFromJson(const JsonNode & json, const std::string & identifier, size_t index) override;
|
2017-08-20 09:18:07 +02:00
|
|
|
};
|