Przeglądaj źródła

small refactor secskill limit check.

alexvins 13 lat temu
rodzic
commit
66d9edf76e

+ 1 - 1
client/GUIClasses.cpp

@@ -5320,7 +5320,7 @@ int CUniversityWindow::CItem::state()
 {
 	if (parent->hero->getSecSkillLevel(static_cast<CGHeroInstance::SecondarySkill>(ID)))//hero know this skill
 		return 1;
-	if (parent->hero->secSkills.size() >= GameConstants::SKILL_PER_HERO)//can't learn more skills
+	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)
 		return 0;

+ 8 - 4
lib/CObjectHandler.cpp

@@ -642,6 +642,11 @@ void CGHeroInstance::setSecSkillLevel(SecondarySkill which, int val, bool abs)
 	}
 }
 
+bool CGHeroInstance::canLearnSkill() const
+{
+	return secSkills.size() < GameConstants::SKILL_PER_HERO;
+}
+
 int CGHeroInstance::maxMovePoints(bool onLand) const
 {
 	int base;
@@ -4764,7 +4769,7 @@ void CGWitchHut::onHeroVisit( const CGHeroInstance * h ) const
 		iw.text << std::pair<ui8,ui32>(11,172);
 		iw.text.addReplacement(MetaString::SEC_SKILL_NAME, ability);
 	}
-	else if(h->secSkills.size() >= GameConstants::SKILL_PER_HERO) //already all skills slots used
+	else if(!h->canLearnSkill()) //already all skills slots used
 	{
 		iw.text << std::pair<ui8,ui32>(11,173);
 		iw.text.addReplacement(MetaString::SEC_SKILL_NAME, ability);
@@ -5169,8 +5174,7 @@ void CGPandoraBox::giveContents( const CGHeroInstance *h, bool afterBattle ) con
 		{
 			int curLev = h->getSecSkillLevel(static_cast<CGHeroInstance::SecondarySkill>(abilities[i]));
 
-			if( (curLev  &&  curLev < abilityLevels[i])
-				|| (h->secSkills.size() < GameConstants::SKILL_PER_HERO) )
+			if( (curLev  &&  curLev < abilityLevels[i])	|| (h->canLearnSkill() ))
 			{
 				cb->changeSecSkill(h->id,abilities[i],abilityLevels[i],true);
 			}
@@ -5525,7 +5529,7 @@ void CGScholar::onHeroVisit( const CGHeroInstance * h ) const
 	//check if the bonus if applicable, if not - give primary skill (always possible)
 	int ssl = h->getSecSkillLevel(static_cast<CGHeroInstance::SecondarySkill>(bid)); //current sec skill level, used if bonusType == 1
 	if((type == 1
-			&& ((ssl == 3)  ||  (!ssl  &&  h->secSkills.size() == GameConstants::SKILL_PER_HERO))) ////hero already has expert level in the skill or (don't know skill and doesn't have free slot)
+			&& ((ssl == 3)  ||  (!ssl  &&  !h->canLearnSkill()))) ////hero already has expert level in the skill or (don't know skill and doesn't have free slot)
 		|| (type == 2  &&  (!h->getArt(17) || vstd::contains(h->spells, (ui32) bid)
 		|| (VLC->spellh->spells[bid]->level > h->getSecSkillLevel(CGHeroInstance::WISDOM) + 2)
 		))) //hero doesn't have a spellbook or already knows the spell or doesn't have Wisdom

+ 2 - 1
lib/CObjectHandler.h

@@ -377,7 +377,8 @@ public:
 
 	ui8 getSecSkillLevel(SecondarySkill skill) const; //0 - no skill
 	void setSecSkillLevel(SecondarySkill which, int val, bool abs);// abs == 0 - changes by value; 1 - sets to value
-
+	bool canLearnSkill() const; ///true if hero has free secondary skill slot
+	
 	int maxMovePoints(bool onLand) const;
 	int movementPointsAfterEmbark(int MPsBefore, int basicCost, bool disembark = false) const; 
 

+ 3 - 3
server/CGameHandler.cpp

@@ -259,14 +259,14 @@ void CGameHandler::levelUpHero(int ID)
 		hlu.skills.push_back(s);
 		basicAndAdv.erase(s);
 	}
-	else if(none.size() && hero->secSkills.size() < GameConstants::SKILL_PER_HERO)
+	else if(none.size() && hero->canLearnSkill())
 	{
 		hlu.skills.push_back(hero->type->heroClass->chooseSecSkill(none)); //give new skill
 		none.erase(hlu.skills.back());
 	}
 
 	//second offered skill
-	if(none.size() && hero->secSkills.size() < GameConstants::SKILL_PER_HERO) //hero have free skill slot
+	if(none.size() && hero->canLearnSkill()) //hero have free skill slot
 	{
 		hlu.skills.push_back(hero->type->heroClass->chooseSecSkill(none)); //new skill
 	}
@@ -3005,7 +3005,7 @@ bool CGameHandler::buySecSkill( const IMarket *m, const CGHeroInstance *h, int s
 	if (h->getSecSkillLevel(static_cast<CGHeroInstance::SecondarySkill>(skill)))
 		COMPLAIN_RET("Hero already know this skill");
 
-	if (h->secSkills.size() >= GameConstants::SKILL_PER_HERO)//can't learn more skills
+	if (!h->canLearnSkill())
 		COMPLAIN_RET("Hero can't learn any more skills");
 
 	if (h->type->heroClass->secSkillProbability[skill]==0)//can't learn this skill (like necromancy for most of non-necros)