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
|
|
|
|
{
|
2018-03-31 07:56:40 +02:00
|
|
|
public:
|
2017-08-25 03:35:02 +02:00
|
|
|
struct LevelInfo
|
|
|
|
{
|
|
|
|
std::string description; //descriptions of spell for skill level
|
2018-03-31 07:56:40 +02:00
|
|
|
std::string iconSmall;
|
|
|
|
std::string iconMedium;
|
|
|
|
std::string iconLarge;
|
2017-08-25 03:35:02 +02:00
|
|
|
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;
|
2018-03-31 07:56:40 +02:00
|
|
|
if(version >= 785)
|
|
|
|
{
|
|
|
|
h & iconSmall;
|
|
|
|
h & iconMedium;
|
|
|
|
h & iconLarge;
|
|
|
|
}
|
2017-08-30 09:19:54 +02:00
|
|
|
h & effects;
|
2017-08-25 03:35:02 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-31 07:56:40 +02:00
|
|
|
private:
|
2017-08-25 03:35:02 +02:00
|
|
|
std::vector<LevelInfo> levels; // bonuses provided by basic, advanced and expert level
|
2018-03-31 07:56:40 +02:00
|
|
|
void addNewBonus(const std::shared_ptr<Bonus> & b, int level);
|
2017-08-20 09:18:07 +02:00
|
|
|
|
|
|
|
public:
|
2018-03-31 07:56:40 +02:00
|
|
|
CSkill(SecondarySkill id = SecondarySkill::DEFAULT, std::string identifier = "default");
|
2017-08-30 06:23:03 +02:00
|
|
|
~CSkill();
|
|
|
|
|
2018-03-31 07:56:40 +02:00
|
|
|
const LevelInfo & at(int level) const;
|
|
|
|
LevelInfo & at(int level);
|
|
|
|
|
2017-08-30 06:23:03 +02:00
|
|
|
std::string toString() const;
|
|
|
|
|
|
|
|
SecondarySkill id;
|
|
|
|
std::string identifier;
|
2017-08-30 12:35:23 +02:00
|
|
|
std::string name; //as displayed in GUI
|
2018-03-31 07:56:40 +02:00
|
|
|
std::array<si32, 2> gainChance; // gainChance[0/1] = default gain chance on level-up for might/magic heroes
|
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;
|
2018-03-31 07:56:40 +02:00
|
|
|
if(version >= 785)
|
|
|
|
{
|
|
|
|
h & gainChance;
|
|
|
|
}
|
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;
|
2018-03-31 07:56:40 +02:00
|
|
|
const std::vector<std::string> & getTypeNames() 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;
|
|
|
|
|
2018-03-31 07:56:40 +02:00
|
|
|
///json serialization helpers
|
|
|
|
static si32 decodeSkill(const std::string & identifier);
|
|
|
|
static std::string encodeSkill(const si32 index);
|
|
|
|
static std::string encodeSkillWithType(const si32 index);
|
|
|
|
|
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
|
|
|
};
|