|
|
|
@ -22,12 +22,10 @@
|
|
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
|
|
|
#include "../mwbase/dialoguemanager.hpp"
|
|
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
|
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
|
|
|
|
|
|
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
|
#include "../mwworld/inventorystore.hpp"
|
|
|
|
|
|
|
|
|
|
#include "../mwmechanics/pickpocket.hpp"
|
|
|
|
|
#include "../mwmechanics/creaturestats.hpp"
|
|
|
|
|
|
|
|
|
|
#include "countdialog.hpp"
|
|
|
|
@ -47,7 +45,6 @@ namespace MWGui
|
|
|
|
|
ContainerWindow::ContainerWindow(DragAndDrop* dragAndDrop)
|
|
|
|
|
: WindowBase("openmw_container_window.layout")
|
|
|
|
|
, mDragAndDrop(dragAndDrop)
|
|
|
|
|
, mPickpocketDetected(false)
|
|
|
|
|
, mSortModel(NULL)
|
|
|
|
|
, mModel(NULL)
|
|
|
|
|
, mSelectedItem(-1)
|
|
|
|
@ -69,10 +66,9 @@ namespace MWGui
|
|
|
|
|
|
|
|
|
|
void ContainerWindow::onItemSelected(int index)
|
|
|
|
|
{
|
|
|
|
|
if (mDragAndDrop->mIsOnDragAndDrop)
|
|
|
|
|
if (mDragAndDrop->mIsOnDragAndDrop && mModel)
|
|
|
|
|
{
|
|
|
|
|
if (mModel && mModel->allowedToInsertItems())
|
|
|
|
|
dropItem();
|
|
|
|
|
dropItem();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -151,71 +147,56 @@ namespace MWGui
|
|
|
|
|
|
|
|
|
|
void ContainerWindow::dropItem()
|
|
|
|
|
{
|
|
|
|
|
if (mPtr.getTypeName() == typeid(ESM::Container).name())
|
|
|
|
|
{
|
|
|
|
|
// check container organic flag
|
|
|
|
|
MWWorld::LiveCellRef<ESM::Container>* ref = mPtr.get<ESM::Container>();
|
|
|
|
|
if (ref->mBase->mFlags & ESM::Container::Organic)
|
|
|
|
|
{
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->
|
|
|
|
|
messageBox("#{sContentsMessage2}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check that we don't exceed container capacity
|
|
|
|
|
MWWorld::Ptr item = mDragAndDrop->mItem.mBase;
|
|
|
|
|
float weight = item.getClass().getWeight(item) * mDragAndDrop->mDraggedCount;
|
|
|
|
|
if (mPtr.getClass().getCapacity(mPtr) < mPtr.getClass().getEncumbrance(mPtr) + weight)
|
|
|
|
|
{
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sContentsMessage3}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bool success = mModel->onDropItem(mDragAndDrop->mItem.mBase, mDragAndDrop->mDraggedCount);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
|
|
Send an ID_CONTAINER packet every time an item is dropped in a container
|
|
|
|
|
*/
|
|
|
|
|
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
|
|
|
|
|
worldEvent->reset();
|
|
|
|
|
worldEvent->cell = *mPtr.getCell()->getCell();
|
|
|
|
|
worldEvent->action = mwmp::BaseEvent::ADD;
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
|
|
|
|
|
worldEvent->reset();
|
|
|
|
|
worldEvent->cell = *mPtr.getCell()->getCell();
|
|
|
|
|
worldEvent->action = mwmp::BaseEvent::ADD;
|
|
|
|
|
|
|
|
|
|
mwmp::WorldObject worldObject;
|
|
|
|
|
worldObject.refId = mPtr.getCellRef().getRefId();
|
|
|
|
|
worldObject.refNumIndex = mPtr.getCellRef().getRefNum().mIndex;
|
|
|
|
|
worldObject.mpNum = mPtr.getCellRef().getMpNum();
|
|
|
|
|
mwmp::WorldObject worldObject;
|
|
|
|
|
worldObject.refId = mPtr.getCellRef().getRefId();
|
|
|
|
|
worldObject.refNumIndex = mPtr.getCellRef().getRefNum().mIndex;
|
|
|
|
|
worldObject.mpNum = mPtr.getCellRef().getMpNum();
|
|
|
|
|
|
|
|
|
|
MWWorld::Ptr itemPtr = mDragAndDrop->mItem.mBase;
|
|
|
|
|
MWWorld::Ptr itemPtr = mDragAndDrop->mItem.mBase;
|
|
|
|
|
|
|
|
|
|
mwmp::ContainerItem containerItem;
|
|
|
|
|
containerItem.refId = itemPtr.getCellRef().getRefId();
|
|
|
|
|
|
|
|
|
|
// Make sure we get the drag and drop count, not the count of the original item
|
|
|
|
|
containerItem.count = mDragAndDrop->mDraggedCount;
|
|
|
|
|
mwmp::ContainerItem containerItem;
|
|
|
|
|
containerItem.refId = itemPtr.getCellRef().getRefId();
|
|
|
|
|
|
|
|
|
|
// Make sure we get the drag and drop count, not the count of the original item
|
|
|
|
|
containerItem.count = mDragAndDrop->mDraggedCount;
|
|
|
|
|
|
|
|
|
|
containerItem.charge = itemPtr.getCellRef().getCharge();
|
|
|
|
|
containerItem.charge = itemPtr.getCellRef().getCharge();
|
|
|
|
|
|
|
|
|
|
worldObject.containerItems.push_back(containerItem);
|
|
|
|
|
worldEvent->addObject(worldObject);
|
|
|
|
|
worldObject.containerItems.push_back(containerItem);
|
|
|
|
|
worldEvent->addObject(worldObject);
|
|
|
|
|
|
|
|
|
|
mwmp::Main::get().getNetworking()->getWorldPacket(ID_CONTAINER)->setEvent(worldEvent);
|
|
|
|
|
mwmp::Main::get().getNetworking()->getWorldPacket(ID_CONTAINER)->Send();
|
|
|
|
|
mwmp::Main::get().getNetworking()->getWorldPacket(ID_CONTAINER)->setEvent(worldEvent);
|
|
|
|
|
mwmp::Main::get().getNetworking()->getWorldPacket(ID_CONTAINER)->Send();
|
|
|
|
|
|
|
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_CONTAINER about\n- Ptr cellRef: %s, %i\n- cell: %s\n- item: %s, %i",
|
|
|
|
|
worldObject.refId.c_str(), worldObject.refNumIndex, worldEvent->cell.getDescription().c_str(),
|
|
|
|
|
containerItem.refId.c_str(), containerItem.count);
|
|
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_CONTAINER about\n- Ptr cellRef: %s, %i\n- cell: %s\n- item: %s, %i",
|
|
|
|
|
worldObject.refId.c_str(), worldObject.refNumIndex, worldEvent->cell.getDescription().c_str(),
|
|
|
|
|
containerItem.refId.c_str(), containerItem.count);
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
End of tes3mp addition
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
mDragAndDrop->drop(mModel, mItemView);
|
|
|
|
|
if (success)
|
|
|
|
|
mDragAndDrop->drop(mModel, mItemView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContainerWindow::onBackgroundSelected()
|
|
|
|
|
{
|
|
|
|
|
if (mDragAndDrop->mIsOnDragAndDrop && mModel && mModel->allowedToInsertItems())
|
|
|
|
|
if (mDragAndDrop->mIsOnDragAndDrop && mModel)
|
|
|
|
|
dropItem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -231,7 +212,6 @@ namespace MWGui
|
|
|
|
|
End of tes3mp addition
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
mPickpocketDetected = false;
|
|
|
|
|
mPtr = container;
|
|
|
|
|
|
|
|
|
|
bool loot = mPtr.getClass().isActor() && mPtr.getClass().getCreatureStats(mPtr).isDead();
|
|
|
|
@ -241,8 +221,7 @@ namespace MWGui
|
|
|
|
|
if (mPtr.getClass().isNpc() && !loot)
|
|
|
|
|
{
|
|
|
|
|
// we are stealing stuff
|
|
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
|
|
|
|
mModel = new PickpocketItemModel(player, new InventoryItemModel(container),
|
|
|
|
|
mModel = new PickpocketItemModel(mPtr, new InventoryItemModel(container),
|
|
|
|
|
!mPtr.getClass().getCreatureStats(mPtr).getKnockedDown());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -287,24 +266,7 @@ namespace MWGui
|
|
|
|
|
|
|
|
|
|
WindowBase::onClose();
|
|
|
|
|
|
|
|
|
|
if (dynamic_cast<PickpocketItemModel*>(mModel)
|
|
|
|
|
// Make sure we were actually closed, rather than just temporarily hidden (e.g. console or main menu opened)
|
|
|
|
|
&& !MWBase::Environment::get().getWindowManager()->containsMode(GM_Container)
|
|
|
|
|
// If it was already detected while taking an item, no need to check now
|
|
|
|
|
&& !mPickpocketDetected
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
|
|
|
|
MWMechanics::Pickpocket pickpocket(player, mPtr);
|
|
|
|
|
if (pickpocket.finish())
|
|
|
|
|
{
|
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->commitCrime(
|
|
|
|
|
player, mPtr, MWBase::MechanicsManager::OT_Pickpocket, 0, true);
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Container);
|
|
|
|
|
mPickpocketDetected = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mModel->onClose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender)
|
|
|
|
@ -422,32 +384,7 @@ namespace MWGui
|
|
|
|
|
|
|
|
|
|
bool ContainerWindow::onTakeItem(const ItemStack &item, int count)
|
|
|
|
|
{
|
|
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
|
|
|
|
// TODO: move to ItemModels
|
|
|
|
|
if (dynamic_cast<PickpocketItemModel*>(mModel)
|
|
|
|
|
&& !mPtr.getClass().getCreatureStats(mPtr).getKnockedDown())
|
|
|
|
|
{
|
|
|
|
|
MWMechanics::Pickpocket pickpocket(player, mPtr);
|
|
|
|
|
if (pickpocket.pick(item.mBase, count))
|
|
|
|
|
{
|
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->commitCrime(
|
|
|
|
|
player, mPtr, MWBase::MechanicsManager::OT_Pickpocket, 0, true);
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Container);
|
|
|
|
|
mPickpocketDetected = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
player.getClass().skillUsageSucceeded(player, ESM::Skill::Sneak, 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Looting a dead corpse is considered OK
|
|
|
|
|
if (mPtr.getClass().isActor() && mPtr.getClass().getCreatureStats(mPtr).isDead())
|
|
|
|
|
return true;
|
|
|
|
|
else
|
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->itemTaken(player, item.mBase, mPtr, count);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
return mModel->onTakeItem(item.mBase, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|