mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-19 21:10:12 +02:00
Implemented "changeCreatures" option for Stables
This commit is contained in:
parent
ecbcafefbc
commit
c9dcb921ab
@ -313,16 +313,26 @@
|
||||
"rarity" : 40
|
||||
},
|
||||
|
||||
"onVisitedMessage" : 136,
|
||||
"onVisitedMessage" : 136, // TODO: alternative message with Cavalier -> Champions upgrade & text ID 139
|
||||
"visitMode" : "bonus",
|
||||
"selectMode" : "selectFirst",
|
||||
"rewards" : [
|
||||
{
|
||||
"limiter" : {
|
||||
"creatures" : [ { "type" : "cavalier", "amount" : 1 } ],
|
||||
},
|
||||
"message" : 138,
|
||||
"movePoints" : 400,
|
||||
"bonuses" : [ { "type" : "LAND_MOVEMENT", "val" : 400, "duration" : "ONE_WEEK"} ],
|
||||
"changeCreatures" : {
|
||||
"cavalier" : "champion"
|
||||
}
|
||||
},
|
||||
{
|
||||
"message" : 137,
|
||||
"movePoints" : 400,
|
||||
"bonuses" : [ { "type" : "LAND_MOVEMENT", "val" : 400, "duration" : "ONE_WEEK"} ]
|
||||
}
|
||||
// TODO: 2nd reward with Cavalier -> Champions upgrade & text ID 138
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "../CRandomGenerator.h"
|
||||
#include "../StringConstants.h"
|
||||
#include "../CCreatureHandler.h"
|
||||
#include "../CModHandler.h"
|
||||
#include "JsonRandom.h"
|
||||
#include "../IGameCallback.h"
|
||||
|
||||
@ -117,6 +118,16 @@ void CRandomRewardObjectInfo::configureReward(CRewardableObject * object, CRando
|
||||
reward.artifacts = JsonRandom::loadArtifacts(source["artifacts"], rng);
|
||||
reward.spells = JsonRandom::loadSpells(source["spells"], rng, spells);
|
||||
reward.creatures = JsonRandom::loadCreatures(source["creatures"], rng);
|
||||
|
||||
for ( auto node : source["changeCreatures"].Struct() )
|
||||
{
|
||||
CreatureID from (VLC->modh->identifiers.getIdentifier (node.second.meta, "creature", node.first) .get());
|
||||
CreatureID dest (VLC->modh->identifiers.getIdentifier (node.second.meta, "creature", node.second.String()).get());
|
||||
|
||||
reward.extraComponents.push_back(Component(Component::CREATURE, dest.getNum(), 0, 0));
|
||||
|
||||
reward.creaturesChange[from] = dest;
|
||||
}
|
||||
}
|
||||
|
||||
void CRandomRewardObjectInfo::configureResetInfo(CRewardableObject * object, CRandomGenerator & rng, CRewardResetInfo & resetParameters, const JsonNode & source) const
|
||||
|
@ -337,6 +337,24 @@ void CRewardableObject::grantRewardAfterLevelup(const CRewardVisitInfo & info, c
|
||||
cb->changeSpells(hero, true, spellsToGive);
|
||||
}
|
||||
|
||||
if(!info.reward.creaturesChange.empty())
|
||||
{
|
||||
for (auto slot : hero->Slots())
|
||||
{
|
||||
const CStackInstance * heroStack = slot.second;
|
||||
|
||||
for (auto & change : info.reward.creaturesChange)
|
||||
{
|
||||
if (heroStack->type->getId() == change.first)
|
||||
{
|
||||
StackLocation location(hero, slot.first);
|
||||
cb->changeStackType(location, change.second.toCreature());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!info.reward.creatures.empty())
|
||||
{
|
||||
CCreatureSet creatures;
|
||||
|
@ -153,6 +153,9 @@ public:
|
||||
std::vector<si32> primary;
|
||||
std::map<SecondarySkill, si32> secondary;
|
||||
|
||||
/// creatures that will be changed in hero's army
|
||||
std::map<CreatureID, CreatureID> creaturesChange;
|
||||
|
||||
/// objects that hero may receive
|
||||
std::vector<ArtifactID> artifacts;
|
||||
std::vector<SpellID> spells;
|
||||
@ -198,6 +201,7 @@ public:
|
||||
h & artifacts;
|
||||
h & spells;
|
||||
h & creatures;
|
||||
h & creaturesChange;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -32,7 +32,7 @@ namespace JsonRandom
|
||||
if (value.isNumber())
|
||||
return static_cast<si32>(value.Float());
|
||||
if (!value["amount"].isNull())
|
||||
return static_cast<si32>(loadValue(value, rng, defaultValue));
|
||||
return static_cast<si32>(loadValue(value["amount"], rng, defaultValue));
|
||||
si32 min = static_cast<si32>(value["min"].Float());
|
||||
si32 max = static_cast<si32>(value["max"].Float());
|
||||
return rng.getIntRange(min, max)();
|
||||
|
Loading…
x
Reference in New Issue
Block a user