2012-05-03 03:26:05 +00:00
|
|
|
#include "actionread.hpp"
|
|
|
|
|
2017-06-27 05:27:14 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Include additional headers for multiplayer purposes
|
|
|
|
*/
|
|
|
|
#include "../mwmp/Main.hpp"
|
|
|
|
#include "../mwmp/LocalPlayer.hpp"
|
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
|
|
|
|
2012-05-03 03:26:05 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-08-12 16:11:09 +00:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-09-15 17:06:56 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
2014-04-25 02:47:45 +00:00
|
|
|
|
2012-09-15 17:06:56 +00:00
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
2015-09-10 06:48:34 +00:00
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
2012-08-12 16:11:09 +00:00
|
|
|
|
2012-10-01 15:17:04 +00:00
|
|
|
#include "player.hpp"
|
|
|
|
#include "class.hpp"
|
|
|
|
#include "esmstore.hpp"
|
2012-09-15 17:06:56 +00:00
|
|
|
|
2012-05-03 03:26:05 +00:00
|
|
|
namespace MWWorld
|
|
|
|
{
|
2012-09-04 13:24:55 +00:00
|
|
|
ActionRead::ActionRead (const MWWorld::Ptr& object) : Action (false, object)
|
2012-05-03 03:26:05 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-25 02:47:45 +00:00
|
|
|
void ActionRead::executeImp (const MWWorld::Ptr& actor) {
|
|
|
|
|
2015-09-10 06:48:34 +00:00
|
|
|
if (actor != MWMechanics::getPlayer())
|
2015-09-07 20:13:20 +00:00
|
|
|
return;
|
|
|
|
|
2014-04-27 07:12:49 +00:00
|
|
|
//Ensure we're not in combat
|
2015-09-10 06:48:34 +00:00
|
|
|
if(MWMechanics::isPlayerInCombat()
|
2014-04-27 07:12:49 +00: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-25 02:47:45 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sInventoryMessage4}");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-04 13:24:55 +00:00
|
|
|
LiveCellRef<ESM::Book> *ref = getTarget().get<ESM::Book>();
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
if (ref->mBase->mData.mIsScroll)
|
2017-09-22 19:26:41 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Scroll, getTarget());
|
2012-05-03 03:26:05 +00:00
|
|
|
else
|
2017-09-22 19:26:41 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Book, getTarget());
|
2012-09-15 17:06:56 +00:00
|
|
|
|
2015-03-11 19:33:55 +00:00
|
|
|
MWMechanics::NpcStats& npcStats = actor.getClass().getNpcStats (actor);
|
2012-09-25 16:59:24 +00:00
|
|
|
|
2012-09-15 18:03:53 +00:00
|
|
|
// Skill gain from books
|
2017-02-12 16:17:33 +00:00
|
|
|
if (ref->mBase->mData.mSkillId >= 0 && ref->mBase->mData.mSkillId < ESM::Skill::Length
|
2012-11-05 12:07:59 +00:00
|
|
|
&& !npcStats.hasBeenUsed (ref->mBase->mId))
|
2012-09-15 17:06:56 +00:00
|
|
|
{
|
2015-03-11 19:33:55 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::NPC> *playerRef = actor.get<ESM::NPC>();
|
2012-11-06 08:36:21 +00:00
|
|
|
|
|
|
|
const ESM::Class *class_ =
|
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>().find (
|
|
|
|
playerRef->mBase->mClass
|
|
|
|
);
|
2012-09-15 17:06:56 +00:00
|
|
|
|
2018-03-24 10:43:18 +00:00
|
|
|
npcStats.increaseSkill (ref->mBase->mData.mSkillId, *class_, true, true);
|
2012-09-15 17:06:56 +00:00
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
npcStats.flagAsUsed (ref->mBase->mId);
|
2017-06-27 05:27:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Send an ID_PLAYER_BOOK packet every time a player reads a skill book
|
|
|
|
*/
|
|
|
|
mwmp::Main::get().getLocalPlayer()->sendBook(ref->mBase->mId);
|
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
2012-09-15 17:06:56 +00:00
|
|
|
}
|
|
|
|
|
2012-05-03 03:26:05 +00:00
|
|
|
}
|
|
|
|
}
|