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

Merge pull request #1130 from IvanSavenko/banned_skills_fix

Fixes #1096 - do not propose banned skills on levelup
This commit is contained in:
Andrii Danylchenko 2022-11-15 09:32:12 +02:00 committed by GitHub
commit 6974d4ea53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 7 deletions

View File

@ -1559,9 +1559,7 @@ int CUniversityWindow::CItem::state()
{
if(parent->hero->getSecSkillLevel(SecondarySkill(ID)))//hero know this skill
return 1;
if(!parent->hero->canLearnSkill())//can't learn more skills
return 0;
if(parent->hero->type->heroClass->secSkillProbability[ID]==0)//can't learn this skill (like necromancy for most of non-necros)
if(!parent->hero->canLearnSkill(SecondarySkill(ID)))//can't learn more skills
return 0;
return 2;
}

View File

@ -195,6 +195,23 @@ bool CGHeroInstance::canLearnSkill() const
return secSkills.size() < GameConstants::SKILL_PER_HERO;
}
bool CGHeroInstance::canLearnSkill(SecondarySkill which) const
{
if ( !canLearnSkill())
return false;
if (!cb->isAllowed(2, which))
return false;
if (getSecSkillLevel(which) > 0)
return false;
if (type->heroClass->secSkillProbability[which] == 0)
return false;
return true;
}
int CGHeroInstance::maxMovePoints(bool onLand) const
{
TurnInfo ti(this);
@ -1117,7 +1134,7 @@ std::vector<SecondarySkill> CGHeroInstance::getLevelUpProposedSecondarySkills()
std::vector<SecondarySkill> obligatorySkills; //hero is offered magic school or wisdom if possible
if (!skillsInfo.wisdomCounter)
{
if (cb->isAllowed(2, SecondarySkill::WISDOM) && !getSecSkillLevel(SecondarySkill::WISDOM))
if (canLearnSkill(SecondarySkill::WISDOM))
obligatorySkills.push_back(SecondarySkill::WISDOM);
}
if (!skillsInfo.magicSchoolCounter)
@ -1131,7 +1148,7 @@ std::vector<SecondarySkill> CGHeroInstance::getLevelUpProposedSecondarySkills()
for (auto skill : ss)
{
if (cb->isAllowed(2, skill) && !getSecSkillLevel(skill)) //only schools hero doesn't know yet
if (canLearnSkill(skill)) //only schools hero doesn't know yet
{
obligatorySkills.push_back(skill);
break; //only one
@ -1143,7 +1160,7 @@ std::vector<SecondarySkill> CGHeroInstance::getLevelUpProposedSecondarySkills()
//picking sec. skills for choice
std::set<SecondarySkill> basicAndAdv, expert, none;
for(int i = 0; i < VLC->skillh->size(); i++)
if (cb->isAllowed(2,i))
if (canLearnSkill(SecondarySkill(i)))
none.insert(SecondarySkill(i));
for(auto & elem : secSkills)

View File

@ -187,6 +187,7 @@ public:
/// Returns true if hero has free secondary skill slot.
bool canLearnSkill() const;
bool canLearnSkill(SecondarySkill which) const;
void setPrimarySkill(PrimarySkill::PrimarySkill primarySkill, si64 value, ui8 abs);
void setSecSkillLevel(SecondarySkill which, int val, bool abs);// abs == 0 - changes by value; 1 - sets to value

View File

@ -4177,7 +4177,7 @@ bool CGameHandler::buySecSkill(const IMarket *m, const CGHeroInstance *h, Second
if (!h->canLearnSkill())
COMPLAIN_RET("Hero can't learn any more skills");
if (h->type->heroClass->secSkillProbability.at(skill)==0)//can't learn this skill (like necromancy for most of non-necros)
if (!h->canLearnSkill(skill))
COMPLAIN_RET("The hero can't learn this skill!");
if (!vstd::contains(m->availableItemsIds(EMarketMode::RESOURCE_SKILL), skill))