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

View File

@ -92,15 +92,14 @@ void CRandomRewardObjectInfo::configureObject(CRewardableObject * object, CRando
info.reward.gainedLevels = JsonRandom::loadValue(reward["gainedLevels"], rng); info.reward.gainedLevels = JsonRandom::loadValue(reward["gainedLevels"], rng);
info.reward.manaDiff = JsonRandom::loadValue(reward["manaPoints"], 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.manaPercentage = JsonRandom::loadValue(reward["manaPercentage"], rng, -1);
info.reward.movePoints = JsonRandom::loadValue(reward["movePoints"], rng); info.reward.movePoints = JsonRandom::loadValue(reward["movePoints"], rng);
info.reward.movePercentage = JsonRandom::loadValue(reward["movePercentage"], rng, -1); info.reward.movePercentage = JsonRandom::loadValue(reward["movePercentage"], rng, -1);
info.reward.removeObject = reward["removeObject"].Bool(); info.reward.removeObject = reward["removeObject"].Bool();
info.reward.bonuses = JsonRandom::loadBonuses(reward["bonuses"]);
//FIXME: compile this line on Visual
//info.reward.bonuses = JsonRandom::loadBonuses(reward["bonuses"]);
info.reward.primary = JsonRandom::loadPrimary(reward["primary"], rng); info.reward.primary = JsonRandom::loadPrimary(reward["primary"], rng);
info.reward.secondary = JsonRandom::loadSecondary(reward["secondary"], 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.spells = JsonRandom::loadSpells(reward["spells"], rng, spells);
info.reward.creatures = JsonRandom::loadCreatures(reward["creatures"], rng); info.reward.creatures = JsonRandom::loadCreatures(reward["creatures"], rng);
info.reward.removeObject = reward["removeObject"].Bool();
info.message = loadMessage(reward["message"]); info.message = loadMessage(reward["message"]);
info.selectChance = JsonRandom::loadValue(reward["selectChance"], rng); 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) if(info.reward.manaDiff || info.reward.manaPercentage >= 0)
{ {
si32 mana = hero->mana; si32 manaScaled = hero->mana;
if (info.reward.manaPercentage >= 0) 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) if(info.reward.movePoints || info.reward.movePercentage >= 0)

View File

@ -85,6 +85,10 @@ public:
/// mana given to/taken from hero, fixed value /// mana given to/taken from hero, fixed value
si32 manaDiff; 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 /// fixed value, in form of percentage from max
si32 manaPercentage; si32 manaPercentage;
@ -137,6 +141,7 @@ public:
h & gainedExp; h & gainedExp;
h & gainedLevels; h & gainedLevels;
h & manaDiff; h & manaDiff;
h & manaOverflowFactor;
h & movePoints; h & movePoints;
h & primary; h & primary;
h & secondary; h & secondary;

View File

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