2012-05-03 05:26:05 +02:00
|
|
|
#include "actionread.hpp"
|
2022-09-05 19:35:15 +02:00
|
|
|
|
|
|
|
#include <components/esm3/loadbook.hpp>
|
|
|
|
#include <components/esm3/loadclas.hpp>
|
2023-06-06 17:02:10 +02:00
|
|
|
#include <components/esm3/loadskil.hpp>
|
2012-05-03 05:26:05 +02:00
|
|
|
|
|
|
|
#include "../mwbase/environment.hpp"
|
2012-08-12 18:11:09 +02:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2014-04-24 22:47:45 -04:00
|
|
|
|
2015-09-10 18:48:34 +12:00
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
2012-09-15 19:06:56 +02:00
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
2012-08-12 18:11:09 +02:00
|
|
|
|
2012-10-01 19:17:04 +04:00
|
|
|
#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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-24 22:47:45 -04:00
|
|
|
void ActionRead::executeImp(const MWWorld::Ptr& actor)
|
|
|
|
{
|
|
|
|
|
2015-09-10 18:48:34 +12:00
|
|
|
if (actor != MWMechanics::getPlayer())
|
2015-09-07 22:13:20 +02:00
|
|
|
return;
|
|
|
|
|
2014-04-27 09:12:49 +02:00
|
|
|
// Ensure we're not in combat
|
2015-09-10 18:48:34 +12:00
|
|
|
if (MWMechanics::isPlayerInCombat()
|
2014-04-27 09:12:49 +02:00
|
|
|
// Reading in combat is still allowed if the scroll/book is not in the player inventory yet
|
|
|
|
// (since otherwise, there would be no way to pick it up)
|
|
|
|
&& getTarget().getContainerStore() == &actor.getClass().getContainerStore(actor))
|
|
|
|
{
|
2014-04-24 22:47:45 -04:00
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sInventoryMessage4}");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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)
|
2017-09-22 21:26:41 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Scroll, getTarget());
|
2012-05-03 05:26:05 +02:00
|
|
|
else
|
2017-09-22 21:26:41 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Book, getTarget());
|
2012-09-15 19:06:56 +02:00
|
|
|
|
2015-03-11 20:33:55 +01:00
|
|
|
MWMechanics::NpcStats& npcStats = actor.getClass().getNpcStats(actor);
|
2012-09-25 18:59:24 +02:00
|
|
|
|
2012-09-15 20:03:53 +02:00
|
|
|
// Skill gain from books
|
2023-06-06 17:02:10 +02:00
|
|
|
ESM::RefId skill = ESM::Skill::indexToRefId(ref->mBase->mData.mSkillId);
|
|
|
|
if (!skill.empty() && !npcStats.hasBeenUsed(ref->mBase->mId))
|
2012-09-15 19:06:56 +02:00
|
|
|
{
|
2015-03-11 20:33:55 +01:00
|
|
|
MWWorld::LiveCellRef<ESM::NPC>* playerRef = actor.get<ESM::NPC>();
|
2012-11-06 12:36:21 +04:00
|
|
|
|
|
|
|
const ESM::Class* class_
|
2023-04-20 21:07:53 +02:00
|
|
|
= MWBase::Environment::get().getESMStore()->get<ESM::Class>().find(playerRef->mBase->mClass);
|
2012-09-15 19:06:56 +02:00
|
|
|
|
2023-06-06 17:02:10 +02:00
|
|
|
npcStats.increaseSkill(skill, *class_, true, 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
|
|
|
}
|
|
|
|
}
|