1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

Added some missing functionality for configurable object

This commit is contained in:
Ivan Savenko 2023-01-22 02:08:58 +02:00
parent 83bb70cd8a
commit 9f3f9cc563
5 changed files with 35 additions and 22 deletions

View File

@ -174,7 +174,6 @@
},
"types" : {
"campfire" : {
//EXPERNCE.WAV
"index" : 0,
"aiValue" : 2000,
"rmg" : {
@ -215,7 +214,6 @@
},
"types" : {
"flotsam" : {
//GENIE.WAV
"index" : 0,
"aiValue" : 2000,
"rmg" : {
@ -227,10 +225,20 @@
"rewards" : [
{
"message" : 51,
"appearChance" : { "max" : 25 },
"removeObject" : true,
},
{
"message" : 52,
"appearChance" : { "min" : 25, "max" : 50 },
"removeObject" : true,
"resources" : {
"wood" : 5
}
},
{
"message" : 53,
"appearChance" : { "min" : 50, "max" : 75 },
"removeObject" : true,
"resources" : {
"wood" : 5,
@ -238,7 +246,8 @@
}
},
{
"message" : 53,
"message" : 54,
"appearChance" : { "min" : 75 },
"removeObject" : true,
"resources" : {
"wood" : 10,
@ -260,7 +269,6 @@
},
"types" : {
"seaChest" : {
//CHEST.WAV
"index" : 0,
"aiValue" : 1500,
"rmg" : {
@ -365,38 +373,37 @@
"value" : 1500,
"rarity" : 1000
},
//CHEST.WAV
"visitMode" : "unlimited",
"selectMode" : "player",
"rewards" : [
{
"appearChance" : { "max" : 33 },
"resources" : { "gold" : 2000 }
"resources" : { "gold" : 2000 },
"removeObject" : true,
},
{
"appearChance" : { "max" : 33 },
"experience" : 1500
"experience" : 1500,
"removeObject" : true,
},
{
"appearChance" : { "min" : 33, "max" : 65 },
"resources" : { "gold" : 1500 }
"resources" : { "gold" : 1500 },
"removeObject" : true,
},
{
"appearChance" : { "min" : 33, "max" : 65 },
"experience" : 1000
"experience" : 1000,
"removeObject" : true,
},
{
"appearChance" : { "min" : 65, "max" : 95 },
"resources" : { "gold" : 1000 }
"resources" : { "gold" : 1000 },
"removeObject" : true,
},
{
"appearChance" : { "min" : 65, "max" : 95 },
"experience" : 500
"experience" : 500,
"removeObject" : true,
},
{

View File

@ -92,15 +92,14 @@ void CRandomRewardObjectInfo::configureObject(CRewardableObject * object, CRando
info.reward.gainedLevels = JsonRandom::loadValue(reward["gainedLevels"], rng);
info.reward.manaDiff = JsonRandom::loadValue(reward["manaPoints"], rng);
info.reward.manaOverflowFactor = JsonRandom::loadValue(reward["manaOverflowFactor"], rng);
info.reward.manaPercentage = JsonRandom::loadValue(reward["manaPercentage"], rng, -1);
info.reward.movePoints = JsonRandom::loadValue(reward["movePoints"], rng);
info.reward.movePercentage = JsonRandom::loadValue(reward["movePercentage"], rng, -1);
info.reward.removeObject = reward["removeObject"].Bool();
//FIXME: compile this line on Visual
//info.reward.bonuses = JsonRandom::loadBonuses(reward["bonuses"]);
info.reward.bonuses = JsonRandom::loadBonuses(reward["bonuses"]);
info.reward.primary = JsonRandom::loadPrimary(reward["primary"], rng);
info.reward.secondary = JsonRandom::loadSecondary(reward["secondary"], rng);
@ -113,8 +112,6 @@ void CRandomRewardObjectInfo::configureObject(CRewardableObject * object, CRando
info.reward.spells = JsonRandom::loadSpells(reward["spells"], rng, spells);
info.reward.creatures = JsonRandom::loadCreatures(reward["creatures"], rng);
info.reward.removeObject = reward["removeObject"].Bool();
info.message = loadMessage(reward["message"]);
info.selectChance = JsonRandom::loadValue(reward["selectChance"], rng);

View File

@ -265,11 +265,17 @@ void CRewardableObject::grantRewardAfterLevelup(const CVisitInfo & info, const C
{
if(info.reward.manaDiff || info.reward.manaPercentage >= 0)
{
si32 mana = hero->mana;
si32 manaScaled = hero->mana;
if (info.reward.manaPercentage >= 0)
mana = hero->manaLimit() * info.reward.manaPercentage / 100;
manaScaled = hero->manaLimit() * info.reward.manaPercentage / 100;
cb->setManaPoints(hero->id, mana + info.reward.manaDiff);
si32 manaMissing = hero->manaLimit() - manaScaled;
si32 manaGranted = std::min(manaMissing, info.reward.manaDiff);
si32 manaOverflow = info.reward.manaDiff - manaGranted;
si32 manaOverLimit = manaOverflow * info.reward.manaOverflowFactor / 100;
si32 manaOutput = manaScaled + manaGranted + manaOverLimit;
cb->setManaPoints(hero->id, manaOutput);
}
if(info.reward.movePoints || info.reward.movePercentage >= 0)

View File

@ -85,6 +85,10 @@ public:
/// mana given to/taken from hero, fixed value
si32 manaDiff;
/// if giving mana points puts hero above mana pool, any overflow will be multiplied by specified percentage
si32 manaOverflowFactor;
/// fixed value, in form of percentage from max
si32 manaPercentage;
@ -137,6 +141,7 @@ public:
h & gainedExp;
h & gainedLevels;
h & manaDiff;
h & manaOverflowFactor;
h & movePoints;
h & primary;
h & secondary;

View File

@ -32,7 +32,7 @@ namespace JsonRandom
if (value.isNumber())
return static_cast<si32>(value.Float());
if (!value["amount"].isNull())
return static_cast<si32>(value["amount"].Float());
return static_cast<si32>(loadValue(value, rng, defaultValue));
si32 min = static_cast<si32>(value["min"].Float());
si32 max = static_cast<si32>(value["max"].Float());
return rng.getIntRange(min, max)();
@ -131,8 +131,6 @@ namespace JsonRandom
{
if (value.getType() == JsonNode::JsonType::DATA_STRING)
return SpellID(VLC->modh->identifiers.getIdentifier("spell", value).get());
if (value["type"].getType() == JsonNode::JsonType::DATA_STRING)
return SpellID(VLC->modh->identifiers.getIdentifier("spell", value["type"]).get());
vstd::erase_if(spells, [=](SpellID spell)
{