mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-23 06:41:08 +00:00
skill gain from books
This commit is contained in:
parent
234f8fa5d5
commit
f5237ff1a6
@ -145,6 +145,21 @@ 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
|
||||
@ -178,7 +193,6 @@ void MWMechanics::NpcStats::useSkill (int skillIndex, const ESM::Class& class_,
|
||||
// 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…
x
Reference in New Issue
Block a user