mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-04 22:14:25 +02:00
added basics for specialty format updating
This commit is contained in:
parent
5d3f6c3b91
commit
89b1ba7538
@ -542,7 +542,12 @@ void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node)
|
|||||||
return bonus;
|
return bonus;
|
||||||
};
|
};
|
||||||
|
|
||||||
//deprecated, used only for original spciealties
|
//deprecated, used only for original specialties
|
||||||
|
const JsonNode & specialties = node["specialties"];
|
||||||
|
if (!specialties.isNull())
|
||||||
|
{
|
||||||
|
logMod->warn("Hero %s has deprecated specialties format. New format:", hero->identifier);
|
||||||
|
JsonNode specVec(JsonNode::DATA_VECTOR);
|
||||||
for(const JsonNode &specialty : node["specialties"].Vector())
|
for(const JsonNode &specialty : node["specialties"].Vector())
|
||||||
{
|
{
|
||||||
SSpecialtyInfo spec;
|
SSpecialtyInfo spec;
|
||||||
@ -553,7 +558,12 @@ void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node)
|
|||||||
spec.additionalinfo = specialty["info"].Float();
|
spec.additionalinfo = specialty["info"].Float();
|
||||||
|
|
||||||
for(std::shared_ptr<Bonus> bonus : SpecialtyInfoToBonuses(spec, sid))
|
for(std::shared_ptr<Bonus> bonus : SpecialtyInfoToBonuses(spec, sid))
|
||||||
|
{
|
||||||
hero->specialty.push_back(bonus);
|
hero->specialty.push_back(bonus);
|
||||||
|
specVec.Vector().push_back(bonus->toJsonNode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logMod->info("\"specialty\" = %s", specVec.toJson());
|
||||||
}
|
}
|
||||||
//new format, using bonus system
|
//new format, using bonus system
|
||||||
for(const JsonNode & specialty : node["specialty"].Vector())
|
for(const JsonNode & specialty : node["specialty"].Vector())
|
||||||
|
@ -1163,6 +1163,22 @@ std::string Bonus::Description() const
|
|||||||
return str.str();
|
return str.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonNode Bonus::toJsonNode() const
|
||||||
|
{
|
||||||
|
JsonNode root(JsonNode::DATA_STRUCT);
|
||||||
|
|
||||||
|
root["type"].Float() = type;
|
||||||
|
if(subtype != -1)
|
||||||
|
root["subtype"].Float() = subtype;
|
||||||
|
if(val != 0)
|
||||||
|
root["val"].Float() = val;
|
||||||
|
if(valType != ADDITIVE_VALUE)
|
||||||
|
root["valType"].Float() = valType;
|
||||||
|
if(updater)
|
||||||
|
root["updater"] = updater->toJsonNode();
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
Bonus::Bonus(ui16 Dur, BonusType Type, BonusSource Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype)
|
Bonus::Bonus(ui16 Dur, BonusType Type, BonusSource Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype)
|
||||||
: duration(Dur), type(Type), subtype(Subtype), source(Src), val(Val), sid(ID), description(Desc)
|
: duration(Dur), type(Type), subtype(Subtype), source(Src), val(Val), sid(ID), description(Desc)
|
||||||
{
|
{
|
||||||
@ -1611,6 +1627,24 @@ std::string ScalingUpdater::toString() const
|
|||||||
return std::string(buf);
|
return std::string(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonNode ScalingUpdater::toJsonNode() const
|
||||||
|
{
|
||||||
|
JsonNode root(JsonNode::DATA_STRUCT);
|
||||||
|
auto addParam = [&](int param)
|
||||||
|
{
|
||||||
|
JsonNode paramNode(JsonNode::DATA_INTEGER);
|
||||||
|
paramNode.Integer() = param;
|
||||||
|
root["parameters"].Vector().push_back(paramNode);
|
||||||
|
};
|
||||||
|
|
||||||
|
root["type"].String() = "GROWS_WITH_LEVEL";
|
||||||
|
addParam(valPer20);
|
||||||
|
if(stepSize > 1)
|
||||||
|
addParam(stepSize);
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<Bonus> Bonus::addUpdater(TUpdaterPtr Updater)
|
std::shared_ptr<Bonus> Bonus::addUpdater(TUpdaterPtr Updater)
|
||||||
{
|
{
|
||||||
updater = Updater;
|
updater = Updater;
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "GameConstants.h"
|
#include "GameConstants.h"
|
||||||
|
#include "JsonNode.h"
|
||||||
|
|
||||||
class CCreature;
|
class CCreature;
|
||||||
struct Bonus;
|
struct Bonus;
|
||||||
@ -424,6 +425,7 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string Description() const;
|
std::string Description() const;
|
||||||
|
JsonNode toJsonNode() const;
|
||||||
|
|
||||||
std::shared_ptr<Bonus> addLimiter(TLimiterPtr Limiter); //returns this for convenient chain-calls
|
std::shared_ptr<Bonus> addLimiter(TLimiterPtr Limiter); //returns this for convenient chain-calls
|
||||||
std::shared_ptr<Bonus> addPropagator(TPropagatorPtr Propagator); //returns this for convenient chain-calls
|
std::shared_ptr<Bonus> addPropagator(TPropagatorPtr Propagator); //returns this for convenient chain-calls
|
||||||
@ -1025,6 +1027,7 @@ public:
|
|||||||
|
|
||||||
virtual bool update(Bonus & b, const CBonusSystemNode & context) const = 0;
|
virtual bool update(Bonus & b, const CBonusSystemNode & context) const = 0;
|
||||||
virtual std::string toString() const;
|
virtual std::string toString() const;
|
||||||
|
virtual JsonNode toJsonNode() const = 0;
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
{
|
{
|
||||||
@ -1048,4 +1051,5 @@ struct DLL_LINKAGE ScalingUpdater : public IUpdater
|
|||||||
|
|
||||||
bool update(Bonus & b, const CBonusSystemNode & context) const override;
|
bool update(Bonus & b, const CBonusSystemNode & context) const override;
|
||||||
virtual std::string toString() const override;
|
virtual std::string toString() const override;
|
||||||
|
virtual JsonNode toJsonNode() const override;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user