2010-08-03 15:24:44 +02:00
|
|
|
|
|
|
|
#include "lockpick.hpp"
|
|
|
|
|
2013-03-22 05:50:54 +01:00
|
|
|
#include <components/esm/loadlock.hpp>
|
2010-08-03 15:24:44 +02:00
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwbase/world.hpp"
|
2012-08-12 18:11:09 +02:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-04-23 15:27:03 +02:00
|
|
|
|
2010-08-03 17:11:41 +02:00
|
|
|
#include "../mwworld/ptr.hpp"
|
2010-08-07 20:25:17 +02:00
|
|
|
#include "../mwworld/actiontake.hpp"
|
2012-06-04 21:48:20 +02:00
|
|
|
#include "../mwworld/actionequip.hpp"
|
2012-03-13 15:35:06 +01:00
|
|
|
#include "../mwworld/inventorystore.hpp"
|
2012-06-29 16:48:50 +02:00
|
|
|
#include "../mwworld/cellstore.hpp"
|
2012-07-03 13:15:20 +02:00
|
|
|
#include "../mwworld/physicssystem.hpp"
|
2013-02-17 15:56:22 +01:00
|
|
|
#include "../mwworld/nullaction.hpp"
|
2012-06-29 16:48:50 +02:00
|
|
|
|
2012-04-16 22:58:16 +02:00
|
|
|
#include "../mwgui/tooltips.hpp"
|
2010-08-03 17:11:41 +02:00
|
|
|
|
2012-01-27 15:11:02 +01:00
|
|
|
#include "../mwrender/objects.hpp"
|
2012-07-03 13:15:20 +02:00
|
|
|
#include "../mwrender/renderinginterface.hpp"
|
2012-01-27 15:11:02 +01:00
|
|
|
|
2010-08-03 15:24:44 +02:00
|
|
|
namespace MWClass
|
|
|
|
{
|
2011-11-09 15:47:06 -05:00
|
|
|
void Lockpick::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
|
2010-08-14 10:02:54 +02:00
|
|
|
{
|
2012-07-24 20:22:11 +04:00
|
|
|
const std::string model = getModel(ptr);
|
|
|
|
if (!model.empty()) {
|
2013-08-07 03:51:57 -07:00
|
|
|
renderingInterface.getObjects().insertModel(ptr, model);
|
2010-08-14 10:02:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
void Lockpick::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
|
2012-07-24 20:22:11 +04:00
|
|
|
{
|
|
|
|
const std::string model = getModel(ptr);
|
2012-11-05 18:40:02 +00:00
|
|
|
if(!model.empty())
|
2013-03-14 03:04:02 +01:00
|
|
|
physics.addObject(ptr,true);
|
2012-07-24 20:22:11 +04:00
|
|
|
}
|
2012-08-09 14:33:21 +02:00
|
|
|
|
2012-07-24 20:22:11 +04:00
|
|
|
std::string Lockpick::getModel(const MWWorld::Ptr &ptr) const
|
2011-11-09 18:06:55 -05:00
|
|
|
{
|
2013-03-22 05:50:54 +01:00
|
|
|
MWWorld::LiveCellRef<ESM::Lockpick> *ref =
|
|
|
|
ptr.get<ESM::Lockpick>();
|
2012-11-05 16:07:59 +04:00
|
|
|
assert(ref->mBase != NULL);
|
2011-11-11 14:37:42 -05:00
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
const std::string &model = ref->mBase->mModel;
|
2012-07-24 20:22:11 +04:00
|
|
|
if (!model.empty()) {
|
|
|
|
return "meshes\\" + model;
|
2011-11-09 18:06:55 -05:00
|
|
|
}
|
2012-07-24 20:22:11 +04:00
|
|
|
return "";
|
2011-11-09 18:06:55 -05:00
|
|
|
}
|
|
|
|
|
2010-08-03 17:11:41 +02:00
|
|
|
std::string Lockpick::getName (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2013-03-22 05:50:54 +01:00
|
|
|
MWWorld::LiveCellRef<ESM::Lockpick> *ref =
|
|
|
|
ptr.get<ESM::Lockpick>();
|
2010-08-03 17:11:41 +02:00
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return ref->mBase->mName;
|
2010-08-03 17:11:41 +02:00
|
|
|
}
|
|
|
|
|
2010-08-07 20:25:17 +02:00
|
|
|
boost::shared_ptr<MWWorld::Action> Lockpick::activate (const MWWorld::Ptr& ptr,
|
2012-04-23 15:27:03 +02:00
|
|
|
const MWWorld::Ptr& actor) const
|
2010-08-07 20:25:17 +02:00
|
|
|
{
|
2013-08-08 22:34:53 -07:00
|
|
|
return defaultItemActivate(ptr, actor);
|
2010-08-07 20:25:17 +02:00
|
|
|
}
|
|
|
|
|
2010-08-05 15:40:03 +02:00
|
|
|
std::string Lockpick::getScript (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2013-03-22 05:50:54 +01:00
|
|
|
MWWorld::LiveCellRef<ESM::Lockpick> *ref =
|
|
|
|
ptr.get<ESM::Lockpick>();
|
2010-08-05 15:40:03 +02:00
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return ref->mBase->mScript;
|
2010-08-05 15:40:03 +02:00
|
|
|
}
|
|
|
|
|
2012-03-13 15:35:06 +01:00
|
|
|
std::pair<std::vector<int>, bool> Lockpick::getEquipmentSlots (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2013-11-12 23:23:19 +01:00
|
|
|
std::vector<int> slots_;
|
2012-03-13 15:35:06 +01:00
|
|
|
|
2013-11-12 23:23:19 +01:00
|
|
|
slots_.push_back (int (MWWorld::InventoryStore::Slot_CarriedRight));
|
2012-03-13 15:35:06 +01:00
|
|
|
|
2013-11-12 23:23:19 +01:00
|
|
|
return std::make_pair (slots_, false);
|
2012-03-13 15:35:06 +01:00
|
|
|
}
|
|
|
|
|
2012-04-07 19:53:49 +02:00
|
|
|
int Lockpick::getValue (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2013-03-22 05:50:54 +01:00
|
|
|
MWWorld::LiveCellRef<ESM::Lockpick> *ref =
|
|
|
|
ptr.get<ESM::Lockpick>();
|
2012-04-07 19:53:49 +02:00
|
|
|
|
2013-11-21 04:45:40 +01:00
|
|
|
if (ptr.getCellRef().mCharge == -1)
|
|
|
|
return ref->mBase->mData.mValue;
|
|
|
|
else
|
2013-12-16 13:22:27 +01:00
|
|
|
return ref->mBase->mData.mValue * (static_cast<float>(ptr.getCellRef().mCharge) / getItemMaxHealth(ptr));
|
2012-04-07 19:53:49 +02:00
|
|
|
}
|
|
|
|
|
2010-08-03 15:24:44 +02:00
|
|
|
void Lockpick::registerSelf()
|
|
|
|
{
|
|
|
|
boost::shared_ptr<Class> instance (new Lockpick);
|
|
|
|
|
2013-03-22 05:50:54 +01:00
|
|
|
registerClass (typeid (ESM::Lockpick).name(), instance);
|
2010-08-03 15:24:44 +02:00
|
|
|
}
|
2012-03-13 18:50:32 +02:00
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
std::string Lockpick::getUpSoundId (const MWWorld::Ptr& ptr) const
|
2012-03-13 18:50:32 +02:00
|
|
|
{
|
|
|
|
return std::string("Item Lockpick Up");
|
|
|
|
}
|
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
std::string Lockpick::getDownSoundId (const MWWorld::Ptr& ptr) const
|
2012-03-13 18:50:32 +02:00
|
|
|
{
|
|
|
|
return std::string("Item Lockpick Down");
|
|
|
|
}
|
2012-04-15 17:52:39 +02:00
|
|
|
|
|
|
|
std::string Lockpick::getInventoryIcon (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2013-03-22 05:50:54 +01:00
|
|
|
MWWorld::LiveCellRef<ESM::Lockpick> *ref =
|
|
|
|
ptr.get<ESM::Lockpick>();
|
2012-04-15 17:52:39 +02:00
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return ref->mBase->mIcon;
|
2012-04-15 17:52:39 +02:00
|
|
|
}
|
2012-05-11 10:40:40 +02:00
|
|
|
|
2012-04-16 22:58:16 +02:00
|
|
|
bool Lockpick::hasToolTip (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2013-03-22 05:50:54 +01:00
|
|
|
MWWorld::LiveCellRef<ESM::Lockpick> *ref =
|
|
|
|
ptr.get<ESM::Lockpick>();
|
2012-04-16 22:58:16 +02:00
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return (ref->mBase->mName != "");
|
2012-04-16 22:58:16 +02:00
|
|
|
}
|
|
|
|
|
2012-04-24 02:02:03 +02:00
|
|
|
MWGui::ToolTipInfo Lockpick::getToolTipInfo (const MWWorld::Ptr& ptr) const
|
2012-04-16 22:58:16 +02:00
|
|
|
{
|
2013-03-22 05:50:54 +01:00
|
|
|
MWWorld::LiveCellRef<ESM::Lockpick> *ref =
|
|
|
|
ptr.get<ESM::Lockpick>();
|
2012-04-16 22:58:16 +02:00
|
|
|
|
|
|
|
MWGui::ToolTipInfo info;
|
2012-11-05 16:07:59 +04:00
|
|
|
info.caption = ref->mBase->mName + MWGui::ToolTips::getCountString(ptr.getRefData().getCount());
|
|
|
|
info.icon = ref->mBase->mIcon;
|
2012-04-16 22:58:16 +02:00
|
|
|
|
|
|
|
std::string text;
|
|
|
|
|
2013-03-22 12:24:09 +01:00
|
|
|
int remainingUses = (ptr.getCellRef().mCharge != -1) ? ptr.getCellRef().mCharge : ref->mBase->mData.mUses;
|
2012-04-16 22:58:16 +02:00
|
|
|
|
2013-03-22 12:24:09 +01:00
|
|
|
text += "\n#{sUses}: " + MWGui::ToolTips::toString(remainingUses);
|
2012-11-05 16:07:59 +04:00
|
|
|
text += "\n#{sQuality}: " + MWGui::ToolTips::toString(ref->mBase->mData.mQuality);
|
|
|
|
text += "\n#{sWeight}: " + MWGui::ToolTips::toString(ref->mBase->mData.mWeight);
|
2013-12-16 13:22:27 +01:00
|
|
|
text += MWGui::ToolTips::getValueString(getValue(ptr), "#{sValue}");
|
2012-04-16 22:58:16 +02:00
|
|
|
|
2012-04-24 02:02:03 +02:00
|
|
|
if (MWBase::Environment::get().getWindowManager()->getFullHelp()) {
|
2012-11-05 16:07:59 +04:00
|
|
|
text += MWGui::ToolTips::getMiscString(ref->mRef.mOwner, "Owner");
|
|
|
|
text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script");
|
2012-04-16 22:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
info.text = text;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
2012-06-04 21:48:20 +02:00
|
|
|
|
|
|
|
boost::shared_ptr<MWWorld::Action> Lockpick::use (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-08-19 20:11:50 -03:00
|
|
|
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionEquip(ptr));
|
|
|
|
|
|
|
|
action->setSound(getUpSoundId(ptr));
|
2012-06-04 21:48:20 +02:00
|
|
|
|
2012-08-19 20:11:50 -03:00
|
|
|
return action;
|
2012-06-04 21:48:20 +02:00
|
|
|
}
|
2012-07-25 17:18:17 +04:00
|
|
|
|
|
|
|
MWWorld::Ptr
|
2012-07-26 16:14:11 +04:00
|
|
|
Lockpick::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
|
2012-07-25 17:18:17 +04:00
|
|
|
{
|
2013-03-22 05:50:54 +01:00
|
|
|
MWWorld::LiveCellRef<ESM::Lockpick> *ref =
|
|
|
|
ptr.get<ESM::Lockpick>();
|
2012-07-25 17:18:17 +04:00
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return MWWorld::Ptr(&cell.mLockpicks.insert(*ref), &cell);
|
2012-07-25 17:18:17 +04:00
|
|
|
}
|
2013-04-07 21:38:53 +02:00
|
|
|
|
|
|
|
bool Lockpick::canSell (const MWWorld::Ptr& item, int npcServices) const
|
|
|
|
{
|
|
|
|
return npcServices & ESM::NPC::Picks;
|
|
|
|
}
|
2013-04-29 12:05:10 +02:00
|
|
|
|
|
|
|
int Lockpick::getItemMaxHealth (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::Lockpick> *ref =
|
|
|
|
ptr.get<ESM::Lockpick>();
|
|
|
|
|
|
|
|
return ref->mBase->mData.mUses;
|
|
|
|
}
|
2013-05-11 18:38:27 +02:00
|
|
|
|
|
|
|
float Lockpick::getWeight(const MWWorld::Ptr &ptr) const
|
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::Lockpick> *ref =
|
|
|
|
ptr.get<ESM::Lockpick>();
|
|
|
|
return ref->mBase->mData.mWeight;
|
|
|
|
}
|
2010-08-03 15:24:44 +02:00
|
|
|
}
|