forked from teamnwah/openmw-tes3coop
Skill progress refactoring
This commit is contained in:
parent
dd8aab2a7f
commit
ae77eacd7e
4 changed files with 31 additions and 52 deletions
|
@ -383,11 +383,15 @@ namespace MWGui
|
|||
const MWMechanics::SkillValue &stat = mSkillValues.find(skillId)->second;
|
||||
int base = stat.getBase();
|
||||
int modified = stat.getModified();
|
||||
int progressPercent = stat.getProgress() * 100;
|
||||
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||
const MWWorld::ESMStore &esmStore =
|
||||
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);
|
||||
|
||||
std::string icon = "icons\\k\\" + ESM::Skill::sIconNames[skillId];
|
||||
|
|
|
@ -125,32 +125,9 @@ bool MWMechanics::NpcStats::isInFaction (const std::string& faction) const
|
|||
return (mFactionRank.find(Misc::StringUtils::lowerCase(faction)) != mFactionRank.end());
|
||||
}
|
||||
|
||||
float MWMechanics::NpcStats::getSkillGain (int skillIndex, const ESM::Class& class_, int usageType,
|
||||
int level, float extraFactor) const
|
||||
float MWMechanics::NpcStats::getSkillProgressRequirement (int skillIndex, const ESM::Class& class_) const
|
||||
{
|
||||
if (level<0)
|
||||
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;
|
||||
float progressRequirement = 1 + getSkill (skillIndex).getBase();
|
||||
|
||||
const MWWorld::Store<ESM::GameSetting> &gmst =
|
||||
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
|
||||
|
@ -173,11 +150,15 @@ float MWMechanics::NpcStats::getSkillGain (int skillIndex, const ESM::Class& cla
|
|||
break;
|
||||
}
|
||||
|
||||
progressRequirement *= typeFactor;
|
||||
|
||||
if (typeFactor<=0)
|
||||
throw std::runtime_error ("invalid skill type factor");
|
||||
|
||||
float specialisationFactor = 1;
|
||||
|
||||
const ESM::Skill *skill =
|
||||
MWBase::Environment::get().getWorld()->getStore().get<ESM::Skill>().find (skillIndex);
|
||||
if (skill->mData.mSpecialization==class_.mData.mSpecialization)
|
||||
{
|
||||
specialisationFactor = gmst.find ("fSpecialSkillBonus")->getFloat();
|
||||
|
@ -185,7 +166,9 @@ float MWMechanics::NpcStats::getSkillGain (int skillIndex, const ESM::Class& cla
|
|||
if (specialisationFactor<=0)
|
||||
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)
|
||||
|
@ -194,11 +177,24 @@ void MWMechanics::NpcStats::useSkill (int skillIndex, const ESM::Class& class_,
|
|||
if(mIsWerewolf)
|
||||
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);
|
||||
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
getSkill (skillIndex).setBase (base);
|
||||
getSkill(skillIndex).setBase (base);
|
||||
if (!preserveProgress)
|
||||
getSkill(skillIndex).setProgress(0);
|
||||
}
|
||||
|
|
|
@ -74,11 +74,7 @@ namespace MWMechanics
|
|||
|
||||
bool isInFaction (const std::string& faction) const;
|
||||
|
||||
float getSkillGain (int skillIndex, const ESM::Class& class_, int usageType = -1,
|
||||
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.
|
||||
float getSkillProgressRequirement (int skillIndex, const ESM::Class& class_) const;
|
||||
|
||||
void useSkill (int skillIndex, const ESM::Class& class_, int usageType = -1, float extraFactor=1.f);
|
||||
///< Increase skill by usage.
|
||||
|
|
|
@ -348,29 +348,12 @@ namespace MWScript
|
|||
|
||||
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());
|
||||
|
||||
if (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).setProgress(progress);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue