Browse Source

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

Ivan Savenko 1 year ago
parent
commit
9e81c53547
2 changed files with 10 additions and 3 deletions
  1. 8 2
      lib/rewardable/Interface.cpp
  2. 2 1
      lib/rewardable/Reward.cpp

+ 8 - 2
lib/rewardable/Interface.cpp

@@ -161,8 +161,14 @@ void Rewardable::Interface::grantRewardAfterLevelup(IGameCallback * cb, const Re
 
 
 	if(!info.reward.spells.empty())
 	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())
 	if(!info.reward.creaturesChange.empty())

+ 2 - 1
lib/rewardable/Reward.cpp

@@ -102,7 +102,8 @@ void Rewardable::Reward::loadComponents(std::vector<Component> & comps, const CG
 		comps.emplace_back(ComponentType::ARTIFACT, entry);
 		comps.emplace_back(ComponentType::ARTIFACT, entry);
 
 
 	for(const auto & entry : spells)
 	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)
 	for(const auto & entry : creatures)
 		comps.emplace_back(ComponentType::CREATURE, entry.type->getId(), entry.count);
 		comps.emplace_back(ComponentType::CREATURE, entry.type->getId(), entry.count);