1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Do not give spells as reward if hero can't learn them

This commit is contained in:
Ivan Savenko 2024-04-12 00:25:02 +03:00
parent 53fcd3ad26
commit 9e81c53547
2 changed files with 10 additions and 3 deletions

View File

@ -161,8 +161,14 @@ void Rewardable::Interface::grantRewardAfterLevelup(IGameCallback * cb, const Re
if(!info.reward.spells.empty())
{
std::set<SpellID> spellsToGive(info.reward.spells.begin(), info.reward.spells.end());
cb->changeSpells(hero, true, spellsToGive);
std::set<SpellID> spellsToGive;
for (auto const & spell : info.reward.spells)
if (hero->canLearnSpell(spell.toEntity(VLC), true))
spellsToGive.insert(spell);
if (!spellsToGive.empty())
cb->changeSpells(hero, true, spellsToGive);
}
if(!info.reward.creaturesChange.empty())

View File

@ -102,7 +102,8 @@ void Rewardable::Reward::loadComponents(std::vector<Component> & comps, const CG
comps.emplace_back(ComponentType::ARTIFACT, entry);
for(const auto & entry : spells)
comps.emplace_back(ComponentType::SPELL, entry);
if (!h || h->canLearnSpell(entry.toEntity(VLC), true))
comps.emplace_back(ComponentType::SPELL, entry);
for(const auto & entry : creatures)
comps.emplace_back(ComponentType::CREATURE, entry.type->getId(), entry.count);