2012-05-03 05:26:05 +02:00
|
|
|
#include "actionread.hpp"
|
|
|
|
|
|
|
|
#include "../mwbase/environment.hpp"
|
2012-08-12 18:11:09 +02:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-09-15 19:06:56 +02:00
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
2012-08-12 18:11:09 +02:00
|
|
|
|
2012-05-03 05:26:05 +02:00
|
|
|
#include "../mwgui/bookwindow.hpp"
|
|
|
|
#include "../mwgui/scrollwindow.hpp"
|
|
|
|
|
2012-10-01 19:17:04 +04:00
|
|
|
#include "player.hpp"
|
|
|
|
#include "class.hpp"
|
|
|
|
#include "esmstore.hpp"
|
2012-09-15 19:06:56 +02:00
|
|
|
|
2012-05-03 05:26:05 +02:00
|
|
|
namespace MWWorld
|
|
|
|
{
|
2012-09-04 15:24:55 +02:00
|
|
|
ActionRead::ActionRead (const MWWorld::Ptr& object) : Action (false, object)
|
2012-05-03 05:26:05 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-27 12:00:10 +02:00
|
|
|
void ActionRead::executeImp (const MWWorld::Ptr& actor)
|
2012-05-03 05:26:05 +02:00
|
|
|
{
|
2012-09-04 15:24:55 +02:00
|
|
|
LiveCellRef<ESM::Book> *ref = getTarget().get<ESM::Book>();
|
2012-05-03 05:26:05 +02:00
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
if (ref->mBase->mData.mIsScroll)
|
2012-05-03 05:26:05 +02:00
|
|
|
{
|
2012-05-23 12:23:35 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Scroll);
|
2012-09-04 15:24:55 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->getScrollWindow()->open(getTarget());
|
2012-05-03 05:26:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-23 12:23:35 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Book);
|
2012-09-04 15:24:55 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->getBookWindow()->open(getTarget());
|
2012-05-03 05:26:05 +02:00
|
|
|
}
|
2012-09-15 19:06:56 +02:00
|
|
|
|
2014-01-08 18:39:44 +01:00
|
|
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
|
2012-09-25 18:59:24 +02:00
|
|
|
MWMechanics::NpcStats& npcStats = MWWorld::Class::get(player).getNpcStats (player);
|
|
|
|
|
2012-09-15 20:03:53 +02:00
|
|
|
// Skill gain from books
|
2012-11-05 16:07:59 +04:00
|
|
|
if (ref->mBase->mData.mSkillID >= 0 && ref->mBase->mData.mSkillID < ESM::Skill::Length
|
|
|
|
&& !npcStats.hasBeenUsed (ref->mBase->mId))
|
2012-09-15 19:06:56 +02:00
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *playerRef = player.get<ESM::NPC>();
|
2012-11-06 12:36:21 +04:00
|
|
|
|
|
|
|
const ESM::Class *class_ =
|
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>().find (
|
|
|
|
playerRef->mBase->mClass
|
|
|
|
);
|
2012-09-15 19:06:56 +02:00
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
npcStats.increaseSkill (ref->mBase->mData.mSkillID, *class_, true);
|
2012-09-15 19:06:56 +02:00
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
npcStats.flagAsUsed (ref->mBase->mId);
|
2012-09-15 19:06:56 +02:00
|
|
|
}
|
|
|
|
|
2012-05-03 05:26:05 +02:00
|
|
|
}
|
|
|
|
}
|