1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 05:53:50 +00:00

Skill progress refactoring

This commit is contained in:
scrawl 2015-02-04 23:15:12 +01:00
parent dd8aab2a7f
commit ae77eacd7e
4 changed files with 31 additions and 52 deletions

View file

@ -383,11 +383,15 @@ namespace MWGui
const MWMechanics::SkillValue &stat = mSkillValues.find(skillId)->second; const MWMechanics::SkillValue &stat = mSkillValues.find(skillId)->second;
int base = stat.getBase(); int base = stat.getBase();
int modified = stat.getModified(); int modified = stat.getModified();
int progressPercent = stat.getProgress() * 100;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
const MWWorld::ESMStore &esmStore = const MWWorld::ESMStore &esmStore =
MWBase::Environment::get().getWorld()->getStore(); MWBase::Environment::get().getWorld()->getStore();
int progressRequirement = player.getClass().getNpcStats(player).getSkillProgressRequirement(skillId,
*esmStore.get<ESM::Class>().find(player.get<ESM::NPC>()->mBase->mClass));
int progressPercent = int(int(stat.getProgress()) / float(progressRequirement) * 100.f);
const ESM::Skill* skill = esmStore.get<ESM::Skill>().find(skillId); const ESM::Skill* skill = esmStore.get<ESM::Skill>().find(skillId);
std::string icon = "icons\\k\\" + ESM::Skill::sIconNames[skillId]; std::string icon = "icons\\k\\" + ESM::Skill::sIconNames[skillId];

View file

@ -125,32 +125,9 @@ bool MWMechanics::NpcStats::isInFaction (const std::string& faction) const
return (mFactionRank.find(Misc::StringUtils::lowerCase(faction)) != mFactionRank.end()); return (mFactionRank.find(Misc::StringUtils::lowerCase(faction)) != mFactionRank.end());
} }
float MWMechanics::NpcStats::getSkillGain (int skillIndex, const ESM::Class& class_, int usageType, float MWMechanics::NpcStats::getSkillProgressRequirement (int skillIndex, const ESM::Class& class_) const
int level, float extraFactor) const
{ {
if (level<0) float progressRequirement = 1 + getSkill (skillIndex).getBase();
level = static_cast<int> (getSkill (skillIndex).getBase());
const ESM::Skill *skill =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Skill>().find (skillIndex);
float skillFactor = 1;
if (usageType>=4)
throw std::runtime_error ("skill usage type out of range");
if (usageType>=0)
{
skillFactor = skill->mData.mUseValue[usageType];
if (skillFactor<0)
throw std::runtime_error ("invalid skill gain factor");
if (skillFactor==0)
return 0;
}
skillFactor *= extraFactor;
const MWWorld::Store<ESM::GameSetting> &gmst = const MWWorld::Store<ESM::GameSetting> &gmst =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>(); MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
@ -173,11 +150,15 @@ float MWMechanics::NpcStats::getSkillGain (int skillIndex, const ESM::Class& cla
break; break;
} }
progressRequirement *= typeFactor;
if (typeFactor<=0) if (typeFactor<=0)
throw std::runtime_error ("invalid skill type factor"); throw std::runtime_error ("invalid skill type factor");
float specialisationFactor = 1; float specialisationFactor = 1;
const ESM::Skill *skill =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Skill>().find (skillIndex);
if (skill->mData.mSpecialization==class_.mData.mSpecialization) if (skill->mData.mSpecialization==class_.mData.mSpecialization)
{ {
specialisationFactor = gmst.find ("fSpecialSkillBonus")->getFloat(); specialisationFactor = gmst.find ("fSpecialSkillBonus")->getFloat();
@ -185,7 +166,9 @@ float MWMechanics::NpcStats::getSkillGain (int skillIndex, const ESM::Class& cla
if (specialisationFactor<=0) if (specialisationFactor<=0)
throw std::runtime_error ("invalid skill specialisation factor"); throw std::runtime_error ("invalid skill specialisation factor");
} }
return 1.0 / ((level+1) * (1.0/skillFactor) * typeFactor * specialisationFactor); progressRequirement *= specialisationFactor;
return progressRequirement;
} }
void MWMechanics::NpcStats::useSkill (int skillIndex, const ESM::Class& class_, int usageType, float extraFactor) void MWMechanics::NpcStats::useSkill (int skillIndex, const ESM::Class& class_, int usageType, float extraFactor)
@ -194,11 +177,24 @@ void MWMechanics::NpcStats::useSkill (int skillIndex, const ESM::Class& class_,
if(mIsWerewolf) if(mIsWerewolf)
return; return;
const ESM::Skill *skill =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Skill>().find (skillIndex);
float skillGain = 1;
if (usageType>=4)
throw std::runtime_error ("skill usage type out of range");
if (usageType>=0)
{
skillGain = skill->mData.mUseValue[usageType];
if (skillGain<0)
throw std::runtime_error ("invalid skill gain factor");
}
skillGain *= extraFactor;
MWMechanics::SkillValue& value = getSkill (skillIndex); MWMechanics::SkillValue& value = getSkill (skillIndex);
value.setProgress(value.getProgress() + getSkillGain (skillIndex, class_, usageType, -1, extraFactor)); value.setProgress(value.getProgress() + skillGain);
if (value.getProgress()>=1) if (int(value.getProgress())>=int(getSkillProgressRequirement(skillIndex, class_)))
{ {
// skill levelled up // skill levelled up
increaseSkill(skillIndex, class_, false); increaseSkill(skillIndex, class_, false);
@ -256,7 +252,7 @@ void MWMechanics::NpcStats::increaseSkill(int skillIndex, const ESM::Class &clas
MWBase::Environment::get().getWindowManager ()->messageBox ("#{sLevelUpMsg}", MWGui::ShowInDialogueMode_Never); MWBase::Environment::get().getWindowManager ()->messageBox ("#{sLevelUpMsg}", MWGui::ShowInDialogueMode_Never);
} }
getSkill (skillIndex).setBase (base); getSkill(skillIndex).setBase (base);
if (!preserveProgress) if (!preserveProgress)
getSkill(skillIndex).setProgress(0); getSkill(skillIndex).setProgress(0);
} }

View file

@ -74,11 +74,7 @@ namespace MWMechanics
bool isInFaction (const std::string& faction) const; bool isInFaction (const std::string& faction) const;
float getSkillGain (int skillIndex, const ESM::Class& class_, int usageType = -1, float getSkillProgressRequirement (int skillIndex, const ESM::Class& class_) const;
int level = -1, float extraFactor=1.f) const;
///< \param usageType: Usage specific factor, specified in the respective skill record;
/// -1: use a factor of 1.0 instead.
/// \param level Level to base calculation on; -1: use current level.
void useSkill (int skillIndex, const ESM::Class& class_, int usageType = -1, float extraFactor=1.f); void useSkill (int skillIndex, const ESM::Class& class_, int usageType = -1, float extraFactor=1.f);
///< Increase skill by usage. ///< Increase skill by usage.

View file

@ -348,29 +348,12 @@ namespace MWScript
MWMechanics::NpcStats& stats = ptr.getClass().getNpcStats (ptr); MWMechanics::NpcStats& stats = ptr.getClass().getNpcStats (ptr);
MWWorld::LiveCellRef<ESM::NPC> *ref = ptr.get<ESM::NPC>();
assert (ref);
const ESM::Class& class_ =
*MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>().find (ref->mBase->mClass);
float level = stats.getSkill(mIndex).getBase();
float progress = stats.getSkill(mIndex).getProgress();
int newLevel = value - (stats.getSkill(mIndex).getModified() - stats.getSkill(mIndex).getBase()); int newLevel = value - (stats.getSkill(mIndex).getModified() - stats.getSkill(mIndex).getBase());
if (newLevel<0) if (newLevel<0)
newLevel = 0; newLevel = 0;
progress = (progress / stats.getSkillGain (mIndex, class_, -1, level))
* stats.getSkillGain (mIndex, class_, -1, newLevel);
if (progress>=1)
progress = 0.999999999;
stats.getSkill (mIndex).setBase (newLevel); stats.getSkill (mIndex).setBase (newLevel);
stats.getSkill (mIndex).setProgress(progress);
} }
}; };