mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
added basics for specialty format updating
This commit is contained in:
parent
5d3f6c3b91
commit
89b1ba7538
@ -542,18 +542,28 @@ void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node)
|
||||
return bonus;
|
||||
};
|
||||
|
||||
//deprecated, used only for original spciealties
|
||||
for(const JsonNode &specialty : node["specialties"].Vector())
|
||||
//deprecated, used only for original specialties
|
||||
const JsonNode & specialties = node["specialties"];
|
||||
if (!specialties.isNull())
|
||||
{
|
||||
SSpecialtyInfo spec;
|
||||
logMod->warn("Hero %s has deprecated specialties format. New format:", hero->identifier);
|
||||
JsonNode specVec(JsonNode::DATA_VECTOR);
|
||||
for(const JsonNode &specialty : node["specialties"].Vector())
|
||||
{
|
||||
SSpecialtyInfo spec;
|
||||
|
||||
spec.type = specialty["type"].Float();
|
||||
spec.val = specialty["val"].Float();
|
||||
spec.subtype = specialty["subtype"].Float();
|
||||
spec.additionalinfo = specialty["info"].Float();
|
||||
spec.type = specialty["type"].Float();
|
||||
spec.val = specialty["val"].Float();
|
||||
spec.subtype = specialty["subtype"].Float();
|
||||
spec.additionalinfo = specialty["info"].Float();
|
||||
|
||||
for(std::shared_ptr<Bonus> bonus : SpecialtyInfoToBonuses(spec, sid))
|
||||
hero->specialty.push_back(bonus);
|
||||
for(std::shared_ptr<Bonus> bonus : SpecialtyInfoToBonuses(spec, sid))
|
||||
{
|
||||
hero->specialty.push_back(bonus);
|
||||
specVec.Vector().push_back(bonus->toJsonNode());
|
||||
}
|
||||
}
|
||||
logMod->info("\"specialty\" = %s", specVec.toJson());
|
||||
}
|
||||
//new format, using bonus system
|
||||
for(const JsonNode & specialty : node["specialty"].Vector())
|
||||
|
@ -1163,6 +1163,22 @@ std::string Bonus::Description() const
|
||||
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)
|
||||
: 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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
updater = Updater;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "GameConstants.h"
|
||||
#include "JsonNode.h"
|
||||
|
||||
class CCreature;
|
||||
struct Bonus;
|
||||
@ -424,6 +425,7 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>
|
||||
}
|
||||
|
||||
std::string Description() const;
|
||||
JsonNode toJsonNode() const;
|
||||
|
||||
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
|
||||
@ -1025,6 +1027,7 @@ public:
|
||||
|
||||
virtual bool update(Bonus & b, const CBonusSystemNode & context) const = 0;
|
||||
virtual std::string toString() const;
|
||||
virtual JsonNode toJsonNode() const = 0;
|
||||
|
||||
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;
|
||||
virtual std::string toString() const override;
|
||||
virtual JsonNode toJsonNode() const override;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user