2023-04-30 02:39:31 +02:00
|
|
|
/*
|
2023-04-30 15:13:07 +02:00
|
|
|
* Info.cpp, part of VCMI engine
|
2023-04-30 02:39:31 +02:00
|
|
|
*
|
|
|
|
* 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"
|
2023-04-30 15:13:07 +02:00
|
|
|
#include "Info.h"
|
2023-07-19 21:25:52 +02:00
|
|
|
|
|
|
|
#include "Configuration.h"
|
2023-04-30 15:13:07 +02:00
|
|
|
#include "Limiter.h"
|
|
|
|
#include "Reward.h"
|
2023-04-30 02:39:31 +02:00
|
|
|
|
|
|
|
#include "../CGeneralTextHandler.h"
|
2023-04-30 15:13:07 +02:00
|
|
|
#include "../IGameCallback.h"
|
2023-07-19 21:25:52 +02:00
|
|
|
#include "../JsonRandom.h"
|
2023-06-02 20:47:37 +02:00
|
|
|
#include "../mapObjects/IObjectInterface.h"
|
2023-07-30 19:12:25 +02:00
|
|
|
#include "../modding/IdentifierStorage.h"
|
2024-01-31 00:17:40 +02:00
|
|
|
#include "../CRandomGenerator.h"
|
2023-04-30 02:39:31 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
namespace {
|
2023-10-16 16:55:31 +02:00
|
|
|
MetaString loadMessage(const JsonNode & value, const TextIdentifier & textIdentifier, EMetaText textSource = EMetaText::ADVOB_TXT )
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
|
|
|
MetaString ret;
|
2023-10-16 16:55:31 +02:00
|
|
|
|
|
|
|
if (value.isVector())
|
|
|
|
{
|
|
|
|
for(const auto & entry : value.Vector())
|
|
|
|
{
|
|
|
|
if (entry.isNumber())
|
|
|
|
ret.appendLocalString(textSource, static_cast<ui32>(entry.Float()));
|
|
|
|
if (entry.isString())
|
|
|
|
ret.appendRawString(entry.String());
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-04-30 02:39:31 +02:00
|
|
|
if (value.isNumber())
|
2023-07-19 21:25:52 +02:00
|
|
|
{
|
2023-10-16 16:55:31 +02:00
|
|
|
ret.appendLocalString(textSource, static_cast<ui32>(value.Float()));
|
2023-07-19 21:25:52 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value.String().empty())
|
|
|
|
return ret;
|
|
|
|
|
2023-10-19 12:34:15 +02:00
|
|
|
if (value.String()[0] == '@')
|
|
|
|
ret.appendTextID(value.String().substr(1));
|
|
|
|
else
|
|
|
|
ret.appendTextID(textIdentifier.get());
|
|
|
|
|
2023-04-30 02:39:31 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool testForKey(const JsonNode & value, const std::string & key)
|
|
|
|
{
|
|
|
|
for(const auto & reward : value["rewards"].Vector())
|
|
|
|
{
|
|
|
|
if (!reward[key].isNull())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-19 21:25:52 +02:00
|
|
|
void Rewardable::Info::init(const JsonNode & objectConfig, const std::string & objectName)
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
2023-07-19 21:25:52 +02:00
|
|
|
objectTextID = objectName;
|
|
|
|
|
|
|
|
auto loadString = [&](const JsonNode & entry, const TextIdentifier & textID){
|
2023-10-19 12:34:15 +02:00
|
|
|
if (entry.isString() && !entry.String().empty() && entry.String()[0] != '@')
|
2023-07-19 21:25:52 +02:00
|
|
|
VLC->generaltexth->registerString(entry.meta, textID, entry.String());
|
|
|
|
};
|
|
|
|
|
2023-04-30 02:39:31 +02:00
|
|
|
parameters = objectConfig;
|
2023-07-19 21:25:52 +02:00
|
|
|
|
|
|
|
for(size_t i = 0; i < parameters["rewards"].Vector().size(); ++i)
|
|
|
|
{
|
|
|
|
const JsonNode message = parameters["rewards"][i]["message"];
|
|
|
|
loadString(message, TextIdentifier(objectName, "rewards", i));
|
|
|
|
}
|
|
|
|
|
|
|
|
for(size_t i = 0; i < parameters["onVisited"].Vector().size(); ++i)
|
|
|
|
{
|
|
|
|
const JsonNode message = parameters["onVisited"][i]["message"];
|
|
|
|
loadString(message, TextIdentifier(objectName, "onVisited", i));
|
|
|
|
}
|
|
|
|
|
|
|
|
for(size_t i = 0; i < parameters["onEmpty"].Vector().size(); ++i)
|
|
|
|
{
|
|
|
|
const JsonNode message = parameters["onEmpty"][i]["message"];
|
|
|
|
loadString(message, TextIdentifier(objectName, "onEmpty", i));
|
|
|
|
}
|
|
|
|
|
|
|
|
loadString(parameters["onSelectMessage"], TextIdentifier(objectName, "onSelect"));
|
2023-10-16 16:55:31 +02:00
|
|
|
loadString(parameters["description"], TextIdentifier(objectName, "description"));
|
|
|
|
loadString(parameters["notVisitedTooltip"], TextIdentifier(objectName, "notVisitedText"));
|
|
|
|
loadString(parameters["visitedTooltip"], TextIdentifier(objectName, "visitedTooltip"));
|
2023-07-19 21:25:52 +02:00
|
|
|
loadString(parameters["onVisitedMessage"], TextIdentifier(objectName, "onVisited"));
|
|
|
|
loadString(parameters["onEmptyMessage"], TextIdentifier(objectName, "onEmpty"));
|
2023-04-30 02:39:31 +02:00
|
|
|
}
|
|
|
|
|
2024-01-09 19:08:22 +02:00
|
|
|
Rewardable::LimitersList Rewardable::Info::configureSublimiters(Rewardable::Configuration & object, CRandomGenerator & rng, IGameCallback * cb, const JsonNode & source) const
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
2023-04-30 15:13:07 +02:00
|
|
|
Rewardable::LimitersList result;
|
2023-04-30 02:39:31 +02:00
|
|
|
for (const auto & input : source.Vector())
|
|
|
|
{
|
2023-04-30 15:13:07 +02:00
|
|
|
auto newLimiter = std::make_shared<Rewardable::Limiter>();
|
2023-04-30 02:39:31 +02:00
|
|
|
|
2024-01-09 19:08:22 +02:00
|
|
|
configureLimiter(object, rng, cb, *newLimiter, input);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
|
|
|
result.push_back(newLimiter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-01-09 19:08:22 +02:00
|
|
|
void Rewardable::Info::configureLimiter(Rewardable::Configuration & object, CRandomGenerator & rng, IGameCallback * cb, Rewardable::Limiter & limiter, const JsonNode & source) const
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
2023-09-30 17:47:47 +02:00
|
|
|
auto const & variables = object.variables.values;
|
2024-01-09 19:08:22 +02:00
|
|
|
JsonRandom randomizer(cb);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
2024-01-01 16:37:48 +02:00
|
|
|
limiter.dayOfWeek = randomizer.loadValue(source["dayOfWeek"], rng, variables);
|
|
|
|
limiter.daysPassed = randomizer.loadValue(source["daysPassed"], rng, variables);
|
|
|
|
limiter.heroExperience = randomizer.loadValue(source["heroExperience"], rng, variables);
|
|
|
|
limiter.heroLevel = randomizer.loadValue(source["heroLevel"], rng, variables);
|
2023-09-30 20:22:31 +02:00
|
|
|
limiter.canLearnSkills = source["canLearnSkills"].Bool();
|
2023-04-30 02:39:31 +02:00
|
|
|
|
2024-01-01 16:37:48 +02:00
|
|
|
limiter.manaPercentage = randomizer.loadValue(source["manaPercentage"], rng, variables);
|
|
|
|
limiter.manaPoints = randomizer.loadValue(source["manaPoints"], rng, variables);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
2024-01-01 16:37:48 +02:00
|
|
|
limiter.resources = randomizer.loadResources(source["resources"], rng, variables);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
2024-01-01 16:37:48 +02:00
|
|
|
limiter.primary = randomizer.loadPrimaries(source["primary"], rng, variables);
|
|
|
|
limiter.secondary = randomizer.loadSecondaries(source["secondary"], rng, variables);
|
|
|
|
limiter.artifacts = randomizer.loadArtifacts(source["artifacts"], rng, variables);
|
|
|
|
limiter.spells = randomizer.loadSpells(source["spells"], rng, variables);
|
|
|
|
limiter.canLearnSpells = randomizer.loadSpells(source["canLearnSpells"], rng, variables);
|
|
|
|
limiter.creatures = randomizer.loadCreatures(source["creatures"], rng, variables);
|
2023-10-09 04:19:12 +02:00
|
|
|
|
2024-01-01 16:37:48 +02:00
|
|
|
limiter.players = randomizer.loadColors(source["colors"], rng, variables);
|
|
|
|
limiter.heroes = randomizer.loadHeroes(source["heroes"], rng);
|
|
|
|
limiter.heroClasses = randomizer.loadHeroClasses(source["heroClasses"], rng);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
2024-01-09 19:08:22 +02:00
|
|
|
limiter.allOf = configureSublimiters(object, rng, cb, source["allOf"] );
|
|
|
|
limiter.anyOf = configureSublimiters(object, rng, cb, source["anyOf"] );
|
|
|
|
limiter.noneOf = configureSublimiters(object, rng, cb, source["noneOf"] );
|
2023-04-30 02:39:31 +02:00
|
|
|
}
|
|
|
|
|
2024-01-09 19:08:22 +02:00
|
|
|
void Rewardable::Info::configureReward(Rewardable::Configuration & object, CRandomGenerator & rng, IGameCallback * cb, Rewardable::Reward & reward, const JsonNode & source) const
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
2023-09-30 17:47:47 +02:00
|
|
|
auto const & variables = object.variables.values;
|
2024-01-09 19:08:22 +02:00
|
|
|
JsonRandom randomizer(cb);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
2024-01-01 16:37:48 +02:00
|
|
|
reward.resources = randomizer.loadResources(source["resources"], rng, variables);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
2024-01-01 16:37:48 +02:00
|
|
|
reward.heroExperience = randomizer.loadValue(source["heroExperience"], rng, variables);
|
|
|
|
reward.heroLevel = randomizer.loadValue(source["heroLevel"], rng, variables);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
2024-01-01 16:37:48 +02:00
|
|
|
reward.manaDiff = randomizer.loadValue(source["manaPoints"], rng, variables);
|
|
|
|
reward.manaOverflowFactor = randomizer.loadValue(source["manaOverflowFactor"], rng, variables);
|
|
|
|
reward.manaPercentage = randomizer.loadValue(source["manaPercentage"], rng, variables, -1);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
2024-01-01 16:37:48 +02:00
|
|
|
reward.movePoints = randomizer.loadValue(source["movePoints"], rng, variables);
|
|
|
|
reward.movePercentage = randomizer.loadValue(source["movePercentage"], rng, variables, -1);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
|
|
|
reward.removeObject = source["removeObject"].Bool();
|
2024-01-01 16:37:48 +02:00
|
|
|
reward.bonuses = randomizer.loadBonuses(source["bonuses"]);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
2024-01-01 16:37:48 +02:00
|
|
|
reward.primary = randomizer.loadPrimaries(source["primary"], rng, variables);
|
|
|
|
reward.secondary = randomizer.loadSecondaries(source["secondary"], rng, variables);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
2024-01-01 16:37:48 +02:00
|
|
|
reward.artifacts = randomizer.loadArtifacts(source["artifacts"], rng, variables);
|
|
|
|
reward.spells = randomizer.loadSpells(source["spells"], rng, variables);
|
|
|
|
reward.creatures = randomizer.loadCreatures(source["creatures"], rng, variables);
|
2023-04-30 02:39:31 +02:00
|
|
|
if(!source["spellCast"].isNull() && source["spellCast"].isStruct())
|
|
|
|
{
|
2024-01-01 16:37:48 +02:00
|
|
|
reward.spellCast.first = randomizer.loadSpell(source["spellCast"]["spell"], rng, variables);
|
2023-04-30 02:39:31 +02:00
|
|
|
reward.spellCast.second = source["spellCast"]["schoolLevel"].Integer();
|
|
|
|
}
|
|
|
|
|
2023-10-04 13:11:13 +02:00
|
|
|
if (!source["revealTiles"].isNull())
|
|
|
|
{
|
|
|
|
auto const & entry = source["revealTiles"];
|
|
|
|
|
|
|
|
reward.revealTiles = RewardRevealTiles();
|
2024-01-01 16:37:48 +02:00
|
|
|
reward.revealTiles->radius = randomizer.loadValue(entry["radius"], rng, variables);
|
2023-10-04 13:11:13 +02:00
|
|
|
reward.revealTiles->hide = entry["hide"].Bool();
|
|
|
|
|
2024-01-01 16:37:48 +02:00
|
|
|
reward.revealTiles->scoreSurface = randomizer.loadValue(entry["surface"], rng, variables);
|
|
|
|
reward.revealTiles->scoreSubterra = randomizer.loadValue(entry["subterra"], rng, variables);
|
|
|
|
reward.revealTiles->scoreWater = randomizer.loadValue(entry["water"], rng, variables);
|
|
|
|
reward.revealTiles->scoreRock = randomizer.loadValue(entry["rock"], rng, variables);
|
2023-10-04 13:11:13 +02:00
|
|
|
}
|
|
|
|
|
2023-04-30 02:39:31 +02:00
|
|
|
for ( auto node : source["changeCreatures"].Struct() )
|
|
|
|
{
|
2023-07-30 19:12:25 +02:00
|
|
|
CreatureID from(VLC->identifiers()->getIdentifier(node.second.meta, "creature", node.first).value());
|
|
|
|
CreatureID dest(VLC->identifiers()->getIdentifier(node.second.meta, "creature", node.second.String()).value());
|
2023-04-30 02:39:31 +02:00
|
|
|
|
2023-11-02 13:18:40 +02:00
|
|
|
reward.extraComponents.emplace_back(ComponentType::CREATURE, dest);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
|
|
|
reward.creaturesChange[from] = dest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-30 15:13:07 +02:00
|
|
|
void Rewardable::Info::configureResetInfo(Rewardable::Configuration & object, CRandomGenerator & rng, Rewardable::ResetInfo & resetParameters, const JsonNode & source) const
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
|
|
|
resetParameters.period = static_cast<ui32>(source["period"].Float());
|
|
|
|
resetParameters.visitors = source["visitors"].Bool();
|
|
|
|
resetParameters.rewards = source["rewards"].Bool();
|
|
|
|
}
|
|
|
|
|
2024-01-09 19:08:22 +02:00
|
|
|
void Rewardable::Info::configureVariables(Rewardable::Configuration & object, CRandomGenerator & rng, IGameCallback * cb, const JsonNode & source) const
|
2023-09-30 17:47:47 +02:00
|
|
|
{
|
2024-01-09 19:08:22 +02:00
|
|
|
JsonRandom randomizer(cb);
|
2024-01-01 16:37:48 +02:00
|
|
|
|
2023-09-30 17:47:47 +02:00
|
|
|
for(const auto & category : source.Struct())
|
|
|
|
{
|
|
|
|
for(const auto & entry : category.second.Struct())
|
|
|
|
{
|
|
|
|
JsonNode preset = object.getPresetVariable(category.first, entry.first);
|
2023-09-30 20:22:31 +02:00
|
|
|
const JsonNode & input = preset.isNull() ? entry.second : preset;
|
2023-09-30 17:47:47 +02:00
|
|
|
int32_t value = -1;
|
|
|
|
|
|
|
|
if (category.first == "number")
|
2024-01-01 16:37:48 +02:00
|
|
|
value = randomizer.loadValue(input, rng, object.variables.values);
|
2023-09-30 17:47:47 +02:00
|
|
|
|
|
|
|
if (category.first == "artifact")
|
2024-01-01 16:37:48 +02:00
|
|
|
value = randomizer.loadArtifact(input, rng, object.variables.values).getNum();
|
2023-09-30 17:47:47 +02:00
|
|
|
|
|
|
|
if (category.first == "spell")
|
2024-01-01 16:37:48 +02:00
|
|
|
value = randomizer.loadSpell(input, rng, object.variables.values).getNum();
|
2023-09-30 17:47:47 +02:00
|
|
|
|
2023-10-04 18:32:16 +02:00
|
|
|
if (category.first == "primarySkill")
|
2024-01-01 16:37:48 +02:00
|
|
|
value = randomizer.loadPrimary(input, rng, object.variables.values).getNum();
|
2023-09-30 17:47:47 +02:00
|
|
|
|
|
|
|
if (category.first == "secondarySkill")
|
2024-01-01 16:37:48 +02:00
|
|
|
value = randomizer.loadSecondary(input, rng, object.variables.values).getNum();
|
2023-09-30 17:47:47 +02:00
|
|
|
|
|
|
|
object.initVariable(category.first, entry.first, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-20 23:44:57 +02:00
|
|
|
void Rewardable::Info::replaceTextPlaceholders(MetaString & target, const Variables & variables) const
|
|
|
|
{
|
|
|
|
for (const auto & variable : variables.values )
|
|
|
|
{
|
|
|
|
if( boost::algorithm::starts_with(variable.first, "spell"))
|
2023-11-02 22:01:49 +02:00
|
|
|
target.replaceName(SpellID(variable.second));
|
2023-10-20 23:44:57 +02:00
|
|
|
|
|
|
|
if( boost::algorithm::starts_with(variable.first, "secondarySkill"))
|
2023-11-02 22:01:49 +02:00
|
|
|
target.replaceName(SecondarySkill(variable.second));
|
2023-10-20 23:44:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Rewardable::Info::replaceTextPlaceholders(MetaString & target, const Variables & variables, const VisitInfo & info) const
|
|
|
|
{
|
|
|
|
for (const auto & artifact : info.reward.artifacts )
|
2023-11-02 22:01:49 +02:00
|
|
|
target.replaceName(artifact);
|
2023-10-20 23:44:57 +02:00
|
|
|
|
2023-11-02 22:01:49 +02:00
|
|
|
for (const auto & spell : info.reward.spells )
|
|
|
|
target.replaceName(spell);
|
2023-10-20 23:44:57 +02:00
|
|
|
|
|
|
|
for (const auto & secondary : info.reward.secondary )
|
2023-11-02 22:01:49 +02:00
|
|
|
target.replaceName(secondary.first);
|
2023-10-20 23:44:57 +02:00
|
|
|
|
|
|
|
replaceTextPlaceholders(target, variables);
|
|
|
|
}
|
|
|
|
|
2023-04-30 15:13:07 +02:00
|
|
|
void Rewardable::Info::configureRewards(
|
2023-04-30 02:39:31 +02:00
|
|
|
Rewardable::Configuration & object,
|
2023-12-21 22:33:33 +02:00
|
|
|
CRandomGenerator & rng,
|
2024-01-09 19:08:22 +02:00
|
|
|
IGameCallback * cb,
|
2023-12-21 22:33:33 +02:00
|
|
|
const JsonNode & source,
|
2023-07-19 21:25:52 +02:00
|
|
|
Rewardable::EEventType event,
|
|
|
|
const std::string & modeName) const
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
2023-07-19 21:25:52 +02:00
|
|
|
for(size_t i = 0; i < source.Vector().size(); ++i)
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
2023-12-21 22:33:33 +02:00
|
|
|
const JsonNode & reward = source.Vector().at(i);
|
2023-07-19 21:25:52 +02:00
|
|
|
|
2023-04-30 02:39:31 +02:00
|
|
|
if (!reward["appearChance"].isNull())
|
|
|
|
{
|
2023-12-21 22:33:33 +02:00
|
|
|
const JsonNode & chance = reward["appearChance"];
|
2023-09-30 17:47:47 +02:00
|
|
|
std::string diceID = std::to_string(chance["dice"].Integer());
|
|
|
|
|
|
|
|
auto diceValue = object.getVariable("dice", diceID);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
2023-09-30 17:47:47 +02:00
|
|
|
if (!diceValue.has_value())
|
|
|
|
{
|
2023-10-18 16:14:22 +02:00
|
|
|
const JsonNode & preset = object.getPresetVariable("dice", diceID);
|
|
|
|
if (preset.isNull())
|
|
|
|
object.initVariable("dice", diceID, rng.getIntRange(0, 99)());
|
|
|
|
else
|
|
|
|
object.initVariable("dice", diceID, preset.Integer());
|
|
|
|
|
2023-09-30 17:47:47 +02:00
|
|
|
diceValue = object.getVariable("dice", diceID);
|
|
|
|
}
|
|
|
|
assert(diceValue.has_value());
|
2023-04-30 02:39:31 +02:00
|
|
|
|
|
|
|
if (!chance["min"].isNull())
|
|
|
|
{
|
|
|
|
int min = static_cast<int>(chance["min"].Float());
|
2023-09-30 17:47:47 +02:00
|
|
|
if (min > *diceValue)
|
2023-04-30 02:39:31 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!chance["max"].isNull())
|
|
|
|
{
|
|
|
|
int max = static_cast<int>(chance["max"].Float());
|
2023-09-30 17:47:47 +02:00
|
|
|
if (max <= *diceValue)
|
2023-04-30 02:39:31 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-30 15:13:07 +02:00
|
|
|
Rewardable::VisitInfo info;
|
2024-01-09 19:08:22 +02:00
|
|
|
configureLimiter(object, rng, cb, info.limiter, reward["limiter"]);
|
|
|
|
configureReward(object, rng, cb, info.reward, reward);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
|
|
|
info.visitType = event;
|
2023-07-19 21:25:52 +02:00
|
|
|
info.message = loadMessage(reward["message"], TextIdentifier(objectTextID, modeName, i));
|
2023-10-17 15:35:34 +02:00
|
|
|
info.description = loadMessage(reward["description"], TextIdentifier(objectTextID, "description", modeName, i), EMetaText::GENERAL_TXT);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
2023-10-20 23:44:57 +02:00
|
|
|
replaceTextPlaceholders(info.message, object.variables, info);
|
|
|
|
replaceTextPlaceholders(info.description, object.variables, info);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
|
|
|
object.info.push_back(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-09 19:08:22 +02:00
|
|
|
void Rewardable::Info::configureObject(Rewardable::Configuration & object, CRandomGenerator & rng, IGameCallback * cb) const
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
|
|
|
object.info.clear();
|
|
|
|
|
2024-01-09 19:08:22 +02:00
|
|
|
configureVariables(object, rng, cb, parameters["variables"]);
|
2023-04-30 02:39:31 +02:00
|
|
|
|
2024-01-09 19:08:22 +02:00
|
|
|
configureRewards(object, rng, cb, parameters["rewards"], Rewardable::EEventType::EVENT_FIRST_VISIT, "rewards");
|
|
|
|
configureRewards(object, rng, cb, parameters["onVisited"], Rewardable::EEventType::EVENT_ALREADY_VISITED, "onVisited");
|
|
|
|
configureRewards(object, rng, cb, parameters["onEmpty"], Rewardable::EEventType::EVENT_NOT_AVAILABLE, "onEmpty");
|
2023-04-30 02:39:31 +02:00
|
|
|
|
2023-10-16 16:55:31 +02:00
|
|
|
object.onSelect = loadMessage(parameters["onSelectMessage"], TextIdentifier(objectTextID, "onSelect"));
|
|
|
|
object.description = loadMessage(parameters["description"], TextIdentifier(objectTextID, "description"));
|
|
|
|
object.notVisitedTooltip = loadMessage(parameters["notVisitedTooltip"], TextIdentifier(objectTextID, "notVisitedTooltip"), EMetaText::GENERAL_TXT);
|
|
|
|
object.visitedTooltip = loadMessage(parameters["visitedTooltip"], TextIdentifier(objectTextID, "visitedTooltip"), EMetaText::GENERAL_TXT);
|
|
|
|
|
|
|
|
if (object.notVisitedTooltip.empty())
|
|
|
|
object.notVisitedTooltip.appendTextID("core.genrltxt.353");
|
|
|
|
|
|
|
|
if (object.visitedTooltip.empty())
|
|
|
|
object.visitedTooltip.appendTextID("core.genrltxt.352");
|
2023-04-30 02:39:31 +02:00
|
|
|
|
|
|
|
if (!parameters["onVisitedMessage"].isNull())
|
|
|
|
{
|
2023-04-30 15:13:07 +02:00
|
|
|
Rewardable::VisitInfo onVisited;
|
|
|
|
onVisited.visitType = Rewardable::EEventType::EVENT_ALREADY_VISITED;
|
2023-07-19 21:25:52 +02:00
|
|
|
onVisited.message = loadMessage(parameters["onVisitedMessage"], TextIdentifier(objectTextID, "onVisited"));
|
2023-10-20 23:44:57 +02:00
|
|
|
replaceTextPlaceholders(onVisited.message, object.variables);
|
2023-10-17 15:35:34 +02:00
|
|
|
|
2023-04-30 02:39:31 +02:00
|
|
|
object.info.push_back(onVisited);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parameters["onEmptyMessage"].isNull())
|
|
|
|
{
|
2023-04-30 15:13:07 +02:00
|
|
|
Rewardable::VisitInfo onEmpty;
|
|
|
|
onEmpty.visitType = Rewardable::EEventType::EVENT_NOT_AVAILABLE;
|
2023-07-19 21:25:52 +02:00
|
|
|
onEmpty.message = loadMessage(parameters["onEmptyMessage"], TextIdentifier(objectTextID, "onEmpty"));
|
2023-10-20 23:44:57 +02:00
|
|
|
replaceTextPlaceholders(onEmpty.message, object.variables);
|
2023-10-17 15:35:34 +02:00
|
|
|
|
2023-04-30 02:39:31 +02:00
|
|
|
object.info.push_back(onEmpty);
|
|
|
|
}
|
|
|
|
|
|
|
|
configureResetInfo(object, rng, object.resetParameters, parameters["resetParameters"]);
|
|
|
|
|
|
|
|
object.canRefuse = parameters["canRefuse"].Bool();
|
2023-10-19 14:17:58 +02:00
|
|
|
object.showScoutedPreview = parameters["showScoutedPreview"].Bool();
|
2023-04-30 02:39:31 +02:00
|
|
|
|
|
|
|
if(parameters["showInInfobox"].isNull())
|
|
|
|
object.infoWindowType = EInfoWindowMode::AUTO;
|
|
|
|
else
|
|
|
|
object.infoWindowType = parameters["showInInfobox"].Bool() ? EInfoWindowMode::INFO : EInfoWindowMode::MODAL;
|
|
|
|
|
|
|
|
auto visitMode = parameters["visitMode"].String();
|
|
|
|
for(int i = 0; i < Rewardable::VisitModeString.size(); ++i)
|
|
|
|
{
|
|
|
|
if(Rewardable::VisitModeString[i] == visitMode)
|
|
|
|
{
|
|
|
|
object.visitMode = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto selectMode = parameters["selectMode"].String();
|
|
|
|
for(int i = 0; i < Rewardable::SelectModeString.size(); ++i)
|
|
|
|
{
|
|
|
|
if(Rewardable::SelectModeString[i] == selectMode)
|
|
|
|
{
|
|
|
|
object.selectMode = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-09-30 20:22:31 +02:00
|
|
|
|
2023-10-17 15:35:34 +02:00
|
|
|
if (object.visitMode == Rewardable::VISIT_LIMITER)
|
2024-01-09 19:08:22 +02:00
|
|
|
configureLimiter(object, rng, cb, object.visitLimiter, parameters["visitLimiter"]);
|
2023-09-30 20:22:31 +02:00
|
|
|
|
2023-04-30 02:39:31 +02:00
|
|
|
}
|
|
|
|
|
2023-04-30 15:13:07 +02:00
|
|
|
bool Rewardable::Info::givesResources() const
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
|
|
|
return testForKey(parameters, "resources");
|
|
|
|
}
|
|
|
|
|
2023-04-30 15:13:07 +02:00
|
|
|
bool Rewardable::Info::givesExperience() const
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
|
|
|
return testForKey(parameters, "gainedExp") || testForKey(parameters, "gainedLevels");
|
|
|
|
}
|
|
|
|
|
2023-04-30 15:13:07 +02:00
|
|
|
bool Rewardable::Info::givesMana() const
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
|
|
|
return testForKey(parameters, "manaPoints") || testForKey(parameters, "manaPercentage");
|
|
|
|
}
|
|
|
|
|
2023-04-30 15:13:07 +02:00
|
|
|
bool Rewardable::Info::givesMovement() const
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
|
|
|
return testForKey(parameters, "movePoints") || testForKey(parameters, "movePercentage");
|
|
|
|
}
|
|
|
|
|
2023-04-30 15:13:07 +02:00
|
|
|
bool Rewardable::Info::givesPrimarySkills() const
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
|
|
|
return testForKey(parameters, "primary");
|
|
|
|
}
|
|
|
|
|
2023-04-30 15:13:07 +02:00
|
|
|
bool Rewardable::Info::givesSecondarySkills() const
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
|
|
|
return testForKey(parameters, "secondary");
|
|
|
|
}
|
|
|
|
|
2023-04-30 15:13:07 +02:00
|
|
|
bool Rewardable::Info::givesArtifacts() const
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
|
|
|
return testForKey(parameters, "artifacts");
|
|
|
|
}
|
|
|
|
|
2023-04-30 15:13:07 +02:00
|
|
|
bool Rewardable::Info::givesCreatures() const
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
|
|
|
return testForKey(parameters, "spells");
|
|
|
|
}
|
|
|
|
|
2023-04-30 15:13:07 +02:00
|
|
|
bool Rewardable::Info::givesSpells() const
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
|
|
|
return testForKey(parameters, "creatures");
|
|
|
|
}
|
|
|
|
|
2023-04-30 15:13:07 +02:00
|
|
|
bool Rewardable::Info::givesBonuses() const
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
|
|
|
return testForKey(parameters, "bonuses");
|
|
|
|
}
|
|
|
|
|
2023-04-30 15:13:07 +02:00
|
|
|
const JsonNode & Rewardable::Info::getParameters() const
|
2023-04-30 02:39:31 +02:00
|
|
|
{
|
|
|
|
return parameters;
|
|
|
|
}
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|