mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +02:00
Add limiter serialization
This commit is contained in:
@ -45,7 +45,6 @@ void CGPandoraBox::onHeroVisit(const CGHeroInstance * h) const
|
|||||||
{
|
{
|
||||||
auto setText = [](MetaString & text, int tId, const CGHeroInstance * h)
|
auto setText = [](MetaString & text, int tId, const CGHeroInstance * h)
|
||||||
{
|
{
|
||||||
text.clear();
|
|
||||||
text.appendLocalString(EMetaText::ADVOB_TXT, tId);
|
text.appendLocalString(EMetaText::ADVOB_TXT, tId);
|
||||||
text.replaceRawString(h->getNameTranslated());
|
text.replaceRawString(h->getNameTranslated());
|
||||||
};
|
};
|
||||||
@ -124,6 +123,7 @@ void CGPandoraBox::onHeroVisit(const CGHeroInstance * h) const
|
|||||||
txt.replaceRawString(h->getNameTranslated());
|
txt.replaceRawString(h->getNameTranslated());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(r.message.empty())
|
||||||
const_cast<MetaString&>(r.message) = txt;
|
const_cast<MetaString&>(r.message) = txt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,6 +111,7 @@ void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const
|
|||||||
case Rewardable::SELECT_ALL: // give all rewards
|
case Rewardable::SELECT_ALL: // give all rewards
|
||||||
for(auto i : rewards)
|
for(auto i : rewards)
|
||||||
grantRewardWithMessage(i, i == rewards.size() - 1);
|
grantRewardWithMessage(i, i == rewards.size() - 1);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
#include "../CPlayerState.h"
|
#include "../CPlayerState.h"
|
||||||
#include "../mapObjects/CGHeroInstance.h"
|
#include "../mapObjects/CGHeroInstance.h"
|
||||||
#include "../serializer/JsonSerializeFormat.h"
|
#include "../serializer/JsonSerializeFormat.h"
|
||||||
|
#include "../constants/StringConstants.h"
|
||||||
|
#include "../CSkillHandler.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@ -122,7 +124,81 @@ bool Rewardable::Limiter::heroAllowed(const CGHeroInstance * hero) const
|
|||||||
|
|
||||||
void Rewardable::Limiter::serializeJson(JsonSerializeFormat & handler)
|
void Rewardable::Limiter::serializeJson(JsonSerializeFormat & handler)
|
||||||
{
|
{
|
||||||
|
handler.serializeInt("dayOfWeek", dayOfWeek);
|
||||||
|
handler.serializeInt("daysPassed", daysPassed);
|
||||||
|
resources.serializeJson(handler, "resources");
|
||||||
|
handler.serializeInt("manaPercentage", manaPercentage);
|
||||||
|
handler.serializeInt("heroExperience", heroExperience);
|
||||||
|
handler.serializeInt("heroLevel", heroLevel);
|
||||||
|
handler.serializeInt("manaPoints", manaPoints);
|
||||||
|
handler.serializeIdArray("artifacts", artifacts);
|
||||||
|
handler.enterArray("creatures").serializeStruct(creatures);
|
||||||
|
{
|
||||||
|
auto a = handler.enterArray("primary");
|
||||||
|
a.syncSize(primary);
|
||||||
|
for(int i = 0; i < primary.size(); ++i)
|
||||||
|
a.serializeInt(i, primary[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto a = handler.enterArray("secondary");
|
||||||
|
std::vector<std::pair<std::string, std::string>> fieldValue;
|
||||||
|
if(handler.saving)
|
||||||
|
{
|
||||||
|
for(auto & i : secondary)
|
||||||
|
{
|
||||||
|
auto key = VLC->skillh->encodeSkill(i.first);
|
||||||
|
auto value = NSecondarySkill::levels.at(i.second);
|
||||||
|
fieldValue.emplace_back(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
a.syncSize(fieldValue);
|
||||||
|
for(int i = 0; i < fieldValue.size(); ++i)
|
||||||
|
{
|
||||||
|
auto e = a.enterStruct(i);
|
||||||
|
e->serializeString("skill", fieldValue[i].first);
|
||||||
|
e->serializeString("level", fieldValue[i].second);
|
||||||
|
}
|
||||||
|
if(!handler.saving)
|
||||||
|
{
|
||||||
|
for(auto & i : fieldValue)
|
||||||
|
{
|
||||||
|
const int skillId = VLC->skillh->decodeSkill(i.first);
|
||||||
|
if(skillId < 0)
|
||||||
|
{
|
||||||
|
logGlobal->error("Invalid secondary skill %s", i.first);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int level = vstd::find_pos(NSecondarySkill::levels, i.second);
|
||||||
|
if(level < 0)
|
||||||
|
{
|
||||||
|
logGlobal->error("Invalid secondary skill level%s", i.second);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
secondary[SecondarySkill(skillId)] = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//sublimiters
|
||||||
|
auto serializeSublimitersList = [&handler](const std::string & field, LimitersList & container)
|
||||||
|
{
|
||||||
|
auto a = handler.enterArray(field);
|
||||||
|
a.syncSize(container);
|
||||||
|
for(int i = 0; i < container.size(); ++i)
|
||||||
|
{
|
||||||
|
if(!handler.saving)
|
||||||
|
container[i] = std::make_shared<Rewardable::Limiter>();
|
||||||
|
auto e = a.enterStruct(i);
|
||||||
|
container[i]->serializeJson(handler);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
serializeSublimitersList("allOf", allOf);
|
||||||
|
serializeSublimitersList("anyOf", anyOf);
|
||||||
|
serializeSublimitersList("noneOf", noneOf);
|
||||||
}
|
}
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
Reference in New Issue
Block a user