mirror of
https://github.com/vcmi/vcmi.git
synced 2025-05-27 22:47:48 +02:00
added basic handler for loading secondary skill bonuses
This commit is contained in:
parent
8180e4d5c5
commit
fbab52eb18
@ -115,6 +115,7 @@ set(lib_SRCS
|
|||||||
CModHandler.cpp
|
CModHandler.cpp
|
||||||
CPathfinder.cpp
|
CPathfinder.cpp
|
||||||
CRandomGenerator.cpp
|
CRandomGenerator.cpp
|
||||||
|
CSkillHandler.cpp
|
||||||
CStack.cpp
|
CStack.cpp
|
||||||
CThreadHelper.cpp
|
CThreadHelper.cpp
|
||||||
CTownHandler.cpp
|
CTownHandler.cpp
|
||||||
|
117
lib/CSkillHandler.cpp
Normal file
117
lib/CSkillHandler.cpp
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* CSkillHandler.cpp, 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "StdInc.h"
|
||||||
|
|
||||||
|
#include <cctype>
|
||||||
|
|
||||||
|
#include "CSkillHandler.h"
|
||||||
|
|
||||||
|
#include "CGeneralTextHandler.h"
|
||||||
|
#include "filesystem/Filesystem.h"
|
||||||
|
|
||||||
|
#include "JsonNode.h"
|
||||||
|
|
||||||
|
#include "CModHandler.h"
|
||||||
|
#include "StringConstants.h"
|
||||||
|
|
||||||
|
#include "CStack.h"
|
||||||
|
#include "battle/BattleInfo.h"
|
||||||
|
#include "battle/CBattleInfoCallback.h"
|
||||||
|
|
||||||
|
///CSkill
|
||||||
|
CSkill::CSkill()
|
||||||
|
{
|
||||||
|
for(auto level : NSecondarySkill::levels)
|
||||||
|
bonusByLevel.push_back(new CBonusSystemNode());
|
||||||
|
}
|
||||||
|
|
||||||
|
CSkill::~CSkill()
|
||||||
|
{
|
||||||
|
for(auto bonus : bonusByLevel)
|
||||||
|
delete bonus;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSkill::addNewBonus(const std::shared_ptr<Bonus>& b, int level)
|
||||||
|
{
|
||||||
|
b->source = Bonus::SECONDARY_SKILL;
|
||||||
|
b->duration = Bonus::PERMANENT;
|
||||||
|
b->description = identifier;
|
||||||
|
bonusByLevel[level]->addNewBonus(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
CBonusSystemNode * CSkill::getBonus(int level)
|
||||||
|
{
|
||||||
|
return bonusByLevel[level];
|
||||||
|
}
|
||||||
|
|
||||||
|
///CSkillHandler
|
||||||
|
CSkillHandler::CSkillHandler()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<JsonNode> CSkillHandler::loadLegacyData(size_t dataSize)
|
||||||
|
{
|
||||||
|
// not supported - no legacy data to load
|
||||||
|
std::vector<JsonNode> legacyData;
|
||||||
|
return legacyData;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string CSkillHandler::getTypeName() const
|
||||||
|
{
|
||||||
|
return "secondarySkill";
|
||||||
|
}
|
||||||
|
|
||||||
|
CSkill * CSkillHandler::loadFromJson(const JsonNode & json, const std::string & identifier)
|
||||||
|
{
|
||||||
|
CSkill * skill = new CSkill();
|
||||||
|
skill->identifier = identifier;
|
||||||
|
|
||||||
|
skill->id = SecondarySkill::DEFAULT;
|
||||||
|
for(int id = 0; id < GameConstants::SKILL_QUANTITY; id++)
|
||||||
|
{
|
||||||
|
if(NSecondarySkill::names[id].compare(identifier) == 0)
|
||||||
|
{
|
||||||
|
skill->id = SecondarySkill(id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int level = 1; level < NSecondarySkill::levels.size(); level++)
|
||||||
|
{
|
||||||
|
const std::string & levelName = NSecondarySkill::levels[level]; // basic, advanced, expert
|
||||||
|
for(auto b : json[levelName].Vector())
|
||||||
|
{
|
||||||
|
auto bonus = JsonUtils::parseBonus(b);
|
||||||
|
bonus->sid = skill->id;
|
||||||
|
skill->addNewBonus(bonus, level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return skill;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSkillHandler::afterLoadFinalization()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSkillHandler::beforeValidate(JsonNode & object)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CSkillHandler::~CSkillHandler()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<bool> CSkillHandler::getDefaultAllowed() const
|
||||||
|
{
|
||||||
|
std::vector<bool> allowedSkills(objects.size(), true);
|
||||||
|
return allowedSkills;
|
||||||
|
}
|
66
lib/CSkillHandler.h
Normal file
66
lib/CSkillHandler.h
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* 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 CSkillHandler;
|
||||||
|
class CGHeroInstance;
|
||||||
|
class CMap;
|
||||||
|
class JsonSerializeFormat;
|
||||||
|
|
||||||
|
class DLL_LINKAGE CSkill // secondary skill
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
std::vector<CBonusSystemNode *> bonusByLevel; // bonuses provided by none, basic, advanced and expert level
|
||||||
|
|
||||||
|
public:
|
||||||
|
CSkill();
|
||||||
|
~CSkill();
|
||||||
|
|
||||||
|
void addNewBonus(const std::shared_ptr<Bonus>& b, int level);
|
||||||
|
CBonusSystemNode * getBonus(int level);
|
||||||
|
|
||||||
|
SecondarySkill id;
|
||||||
|
std::string identifier;
|
||||||
|
|
||||||
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
|
{
|
||||||
|
h & id & identifier;
|
||||||
|
h & bonusByLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend class CSkillHandler;
|
||||||
|
};
|
||||||
|
|
||||||
|
class DLL_LINKAGE CSkillHandler: public CHandlerBase<SecondarySkill, CSkill>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CSkillHandler();
|
||||||
|
virtual ~CSkillHandler();
|
||||||
|
|
||||||
|
///IHandler base
|
||||||
|
std::vector<JsonNode> loadLegacyData(size_t dataSize) override;
|
||||||
|
void afterLoadFinalization() override;
|
||||||
|
void beforeValidate(JsonNode & object) override;
|
||||||
|
|
||||||
|
std::vector<bool> getDefaultAllowed() const override;
|
||||||
|
const std::string getTypeName() const override;
|
||||||
|
|
||||||
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
|
{
|
||||||
|
h & objects ;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CSkill * loadFromJson(const JsonNode & json, const std::string & identifier) override;
|
||||||
|
};
|
@ -21,6 +21,7 @@
|
|||||||
#include "CArtHandler.h"
|
#include "CArtHandler.h"
|
||||||
#include "CCreatureHandler.h"
|
#include "CCreatureHandler.h"
|
||||||
#include "spells/CSpellHandler.h"
|
#include "spells/CSpellHandler.h"
|
||||||
|
#include "CSkillHandler.h"
|
||||||
#include "StringConstants.h"
|
#include "StringConstants.h"
|
||||||
#include "CGeneralTextHandler.h"
|
#include "CGeneralTextHandler.h"
|
||||||
|
|
||||||
@ -65,6 +66,11 @@ const CSpell * SpellID::toSpell() const
|
|||||||
return VLC->spellh->objects[*this];
|
return VLC->spellh->objects[*this];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CSkill * SecondarySkill::toSkill() const
|
||||||
|
{
|
||||||
|
return VLC->skillh->objects.at(*this);
|
||||||
|
}
|
||||||
|
|
||||||
//template std::ostream & operator << <ArtifactInstanceID>(std::ostream & os, BaseForID<ArtifactInstanceID> id);
|
//template std::ostream & operator << <ArtifactInstanceID>(std::ostream & os, BaseForID<ArtifactInstanceID> id);
|
||||||
//template std::ostream & operator << <ObjectInstanceID>(std::ostream & os, BaseForID<ObjectInstanceID> id);
|
//template std::ostream & operator << <ObjectInstanceID>(std::ostream & os, BaseForID<ObjectInstanceID> id);
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@ class CArtifactInstance;
|
|||||||
class CCreature;
|
class CCreature;
|
||||||
class CHero;
|
class CHero;
|
||||||
class CSpell;
|
class CSpell;
|
||||||
|
class CSkill;
|
||||||
class CGameInfoCallback;
|
class CGameInfoCallback;
|
||||||
class CNonConstInfoCallback;
|
class CNonConstInfoCallback;
|
||||||
|
|
||||||
@ -320,6 +321,8 @@ public:
|
|||||||
SecondarySkill(ESecondarySkill _num = WRONG) : num(_num)
|
SecondarySkill(ESecondarySkill _num = WRONG) : num(_num)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
DLL_LINKAGE const CSkill * toSkill() const;
|
||||||
|
|
||||||
ID_LIKE_CLASS_COMMON(SecondarySkill, ESecondarySkill)
|
ID_LIKE_CLASS_COMMON(SecondarySkill, ESecondarySkill)
|
||||||
|
|
||||||
ESecondarySkill num;
|
ESecondarySkill num;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "CHeroHandler.h" // for CHeroHandler
|
#include "CHeroHandler.h" // for CHeroHandler
|
||||||
#include "spells/CSpellHandler.h"// for CSpell
|
#include "spells/CSpellHandler.h"// for CSpell
|
||||||
|
#include "CSkillHandler.h"// for CSkill
|
||||||
#include "NetPacks.h"
|
#include "NetPacks.h"
|
||||||
#include "CBonusTypeHandler.h"
|
#include "CBonusTypeHandler.h"
|
||||||
#include "CModHandler.h"
|
#include "CModHandler.h"
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "CTownHandler.h"
|
#include "CTownHandler.h"
|
||||||
#include "CBuildingHandler.h"
|
#include "CBuildingHandler.h"
|
||||||
#include "spells/CSpellHandler.h"
|
#include "spells/CSpellHandler.h"
|
||||||
|
#include "CSkillHandler.h"
|
||||||
#include "CGeneralTextHandler.h"
|
#include "CGeneralTextHandler.h"
|
||||||
#include "CModHandler.h"
|
#include "CModHandler.h"
|
||||||
#include "IGameEventsReceiver.h"
|
#include "IGameEventsReceiver.h"
|
||||||
@ -113,6 +114,8 @@ void LibClasses::init()
|
|||||||
|
|
||||||
createHandler(spellh, "Spell", pomtime);
|
createHandler(spellh, "Spell", pomtime);
|
||||||
|
|
||||||
|
createHandler(skillh, "Skill", pomtime);
|
||||||
|
|
||||||
createHandler(terviewh, "Terrain view pattern", pomtime);
|
createHandler(terviewh, "Terrain view pattern", pomtime);
|
||||||
|
|
||||||
createHandler(tplh, "Template", pomtime); //templates need already resolved identifiers (refactor?)
|
createHandler(tplh, "Template", pomtime); //templates need already resolved identifiers (refactor?)
|
||||||
@ -137,6 +140,7 @@ void LibClasses::clear()
|
|||||||
delete objh;
|
delete objh;
|
||||||
delete objtypeh;
|
delete objtypeh;
|
||||||
delete spellh;
|
delete spellh;
|
||||||
|
delete skillh;
|
||||||
delete modh;
|
delete modh;
|
||||||
delete bth;
|
delete bth;
|
||||||
delete tplh;
|
delete tplh;
|
||||||
@ -154,6 +158,7 @@ void LibClasses::makeNull()
|
|||||||
objh = nullptr;
|
objh = nullptr;
|
||||||
objtypeh = nullptr;
|
objtypeh = nullptr;
|
||||||
spellh = nullptr;
|
spellh = nullptr;
|
||||||
|
skillh = nullptr;
|
||||||
modh = nullptr;
|
modh = nullptr;
|
||||||
bth = nullptr;
|
bth = nullptr;
|
||||||
tplh = nullptr;
|
tplh = nullptr;
|
||||||
|
@ -14,6 +14,7 @@ class CArtHandler;
|
|||||||
class CHeroHandler;
|
class CHeroHandler;
|
||||||
class CCreatureHandler;
|
class CCreatureHandler;
|
||||||
class CSpellHandler;
|
class CSpellHandler;
|
||||||
|
class CSkillHandler;
|
||||||
class CBuildingHandler;
|
class CBuildingHandler;
|
||||||
class CObjectHandler;
|
class CObjectHandler;
|
||||||
class CObjectClassesHandler;
|
class CObjectClassesHandler;
|
||||||
@ -41,6 +42,7 @@ public:
|
|||||||
CHeroHandler * heroh;
|
CHeroHandler * heroh;
|
||||||
CCreatureHandler * creh;
|
CCreatureHandler * creh;
|
||||||
CSpellHandler * spellh;
|
CSpellHandler * spellh;
|
||||||
|
CSkillHandler * skillh;
|
||||||
CObjectHandler * objh;
|
CObjectHandler * objh;
|
||||||
CObjectClassesHandler * objtypeh;
|
CObjectClassesHandler * objtypeh;
|
||||||
CTownHandler * townh;
|
CTownHandler * townh;
|
||||||
@ -67,6 +69,7 @@ public:
|
|||||||
h & objh;
|
h & objh;
|
||||||
h & objtypeh;
|
h & objtypeh;
|
||||||
h & spellh;
|
h & spellh;
|
||||||
|
h & skillh;
|
||||||
h & modh;
|
h & modh;
|
||||||
h & IS_AI_ENABLED;
|
h & IS_AI_ENABLED;
|
||||||
h & bth;
|
h & bth;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user