forked from teamnwah/openmw-tes3coop
skill gain from books
This commit is contained in:
parent
234f8fa5d5
commit
f5237ff1a6
3 changed files with 70 additions and 30 deletions
|
@ -145,40 +145,54 @@ void MWMechanics::NpcStats::useSkill (int skillIndex, const ESM::Class& class_,
|
|||
if (static_cast<int> (base)!=level)
|
||||
{
|
||||
// skill leveled up
|
||||
increaseSkill(skillIndex, class_, false);
|
||||
}
|
||||
else
|
||||
getSkill (skillIndex).setBase (base);
|
||||
}
|
||||
|
||||
void MWMechanics::NpcStats::increaseSkill(int skillIndex, const ESM::Class &class_, bool preserveProgress)
|
||||
{
|
||||
float base = getSkill (skillIndex).getBase();
|
||||
|
||||
int level = static_cast<int> (base);
|
||||
|
||||
if (preserveProgress)
|
||||
base += 1;
|
||||
else
|
||||
base = level+1;
|
||||
|
||||
// if this is a major or minor skill of the class, increase level progress
|
||||
bool levelProgress = false;
|
||||
for (int i=0; i<2; ++i)
|
||||
for (int j=0; j<5; ++j)
|
||||
{
|
||||
int skill = class_.data.skills[j][i];
|
||||
if (skill == skillIndex)
|
||||
levelProgress = true;
|
||||
}
|
||||
|
||||
mLevelProgress += levelProgress;
|
||||
|
||||
// check the attribute this skill belongs to
|
||||
const ESM::Skill* skill = MWBase::Environment::get().getWorld ()->getStore ().skills.find(skillIndex);
|
||||
++mSkillIncreases[skill->data.attribute];
|
||||
|
||||
// Play sound & skill progress notification
|
||||
/// \todo check if character is the player, if levelling is ever implemented for NPCs
|
||||
MWBase::Environment::get().getSoundManager ()->playSound ("skillraise", 1, 1);
|
||||
|
||||
std::stringstream message;
|
||||
message << boost::format(MWBase::Environment::get().getWindowManager ()->getGameSettingString ("sNotifyMessage39", ""))
|
||||
% std::string("#{" + ESM::Skill::sSkillNameIds[skillIndex] + "}")
|
||||
% base;
|
||||
MWBase::Environment::get().getWindowManager ()->messageBox(message.str(), std::vector<std::string>());
|
||||
|
||||
if (mLevelProgress >= 10)
|
||||
// if this is a major or minor skill of the class, increase level progress
|
||||
bool levelProgress = false;
|
||||
for (int i=0; i<2; ++i)
|
||||
for (int j=0; j<5; ++j)
|
||||
{
|
||||
// levelup is possible now
|
||||
MWBase::Environment::get().getWindowManager ()->messageBox ("#{sLevelUpMsg}", std::vector<std::string>());
|
||||
int skill = class_.data.skills[j][i];
|
||||
if (skill == skillIndex)
|
||||
levelProgress = true;
|
||||
}
|
||||
}
|
||||
|
||||
mLevelProgress += levelProgress;
|
||||
|
||||
// check the attribute this skill belongs to
|
||||
const ESM::Skill* skill = MWBase::Environment::get().getWorld ()->getStore ().skills.find(skillIndex);
|
||||
++mSkillIncreases[skill->data.attribute];
|
||||
|
||||
// Play sound & skill progress notification
|
||||
/// \todo check if character is the player, if levelling is ever implemented for NPCs
|
||||
MWBase::Environment::get().getSoundManager ()->playSound ("skillraise", 1, 1);
|
||||
|
||||
std::stringstream message;
|
||||
message << boost::format(MWBase::Environment::get().getWindowManager ()->getGameSettingString ("sNotifyMessage39", ""))
|
||||
% std::string("#{" + ESM::Skill::sSkillNameIds[skillIndex] + "}")
|
||||
% base;
|
||||
MWBase::Environment::get().getWindowManager ()->messageBox(message.str(), std::vector<std::string>());
|
||||
|
||||
if (mLevelProgress >= 10)
|
||||
{
|
||||
// levelup is possible now
|
||||
MWBase::Environment::get().getWindowManager ()->messageBox ("#{sLevelUpMsg}", std::vector<std::string>());
|
||||
}
|
||||
|
||||
getSkill (skillIndex).setBase (base);
|
||||
}
|
||||
|
|
|
@ -79,6 +79,8 @@ namespace MWMechanics
|
|||
void useSkill (int skillIndex, const ESM::Class& class_, int usageType = -1);
|
||||
///< Increase skill by usage.
|
||||
|
||||
void increaseSkill (int skillIndex, const ESM::Class& class_, bool preserveProgress);
|
||||
|
||||
int getLevelProgress() const;
|
||||
|
||||
int getLevelupAttributeMultiplier(int attribute) const;
|
||||
|
|
|
@ -2,10 +2,18 @@
|
|||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
|
||||
#include "../mwworld/player.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
|
||||
#include "../mwmechanics/npcstats.hpp"
|
||||
|
||||
#include "../mwgui/bookwindow.hpp"
|
||||
#include "../mwgui/scrollwindow.hpp"
|
||||
|
||||
#include <components/esm_store/store.hpp>
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
ActionRead::ActionRead (const MWWorld::Ptr& object) : Action (false, object)
|
||||
|
@ -26,5 +34,21 @@ namespace MWWorld
|
|||
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Book);
|
||||
MWBase::Environment::get().getWindowManager()->getBookWindow()->open(getTarget());
|
||||
}
|
||||
|
||||
if (ref->base->data.skillID >= 0 && ref->base->data.skillID < ESM::Skill::Length)
|
||||
{
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayer().getPlayer();
|
||||
MWMechanics::NpcStats& npcStats = MWWorld::Class::get(player).getNpcStats (player);
|
||||
MWWorld::LiveCellRef<ESM::NPC> *playerRef = player.get<ESM::NPC>();
|
||||
const ESM::Class *class_ = MWBase::Environment::get().getWorld()->getStore().classes.find (
|
||||
playerRef->base->cls);
|
||||
|
||||
npcStats.increaseSkill (ref->base->data.skillID, *class_, true);
|
||||
|
||||
// Remove skill from the book
|
||||
/// \todo This will have to be changed later
|
||||
const_cast<ESM::Book*>(ref->base)->data.skillID = -1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue