1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 12:49:56 +00:00
openmw-tes3mp/apps/openmw/mwworld/actionread.cpp

60 lines
2 KiB
C++
Raw Normal View History

#include "actionread.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
2012-09-15 17:06:56 +00:00
#include "../mwbase/world.hpp"
2012-09-15 17:06:56 +00:00
#include "../mwmechanics/npcstats.hpp"
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
namespace MWWorld
{
ActionRead::ActionRead (const MWWorld::Ptr& object) : Action (false, object)
{
}
void ActionRead::executeImp (const MWWorld::Ptr& actor) {
//Ensure we're not in combat
if(MWBase::Environment::get().getWorld()->getPlayer().isInCombat()
// 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)
) {
MWBase::Environment::get().getWindowManager()->messageBox("#{sInventoryMessage4}");
return;
}
2015-03-11 19:33:55 +00:00
bool showTakeButton = (getTarget().getContainerStore() != &actor.getClass().getContainerStore(actor));
LiveCellRef<ESM::Book> *ref = getTarget().get<ESM::Book>();
2012-11-05 12:07:59 +00:00
if (ref->mBase->mData.mIsScroll)
2015-03-11 19:33:55 +00:00
MWBase::Environment::get().getWindowManager()->showScroll(getTarget(), showTakeButton);
else
2015-03-11 19:33:55 +00:00
MWBase::Environment::get().getWindowManager()->showBook(getTarget(), showTakeButton);
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
2012-11-05 12:07:59 +00:00
if (ref->mBase->mData.mSkillID >= 0 && ref->mBase->mData.mSkillID < ESM::Skill::Length
&& !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>();
const ESM::Class *class_ =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>().find (
playerRef->mBase->mClass
);
2012-09-15 17:06:56 +00:00
2012-11-05 12:07:59 +00:00
npcStats.increaseSkill (ref->mBase->mData.mSkillID, *class_, true);
2012-09-15 17:06:56 +00:00
2012-11-05 12:07:59 +00:00
npcStats.flagAsUsed (ref->mBase->mId);
2012-09-15 17:06:56 +00:00
}
}
}