[Client] See when other players remove items from containers

pull/163/head
David Cernat 8 years ago
parent 25d79dbcfe
commit 60d6a6d463

@ -1,6 +1,8 @@
#include "LocalEvent.hpp"
#include "Networking.hpp"
#include "Main.hpp"
#include "Networking.hpp"
#include "LocalPlayer.hpp"
#include "DedicatedPlayer.hpp"
#include <components/openmw-mp/Log.hpp>
@ -11,6 +13,7 @@
#include "../mwbase/windowmanager.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/containerstore.hpp"
#include "../mwworld/esmstore.hpp"
#include "../mwworld/manualref.hpp"
@ -42,6 +45,55 @@ void LocalEvent::addContainerItem(ContainerItem containerItem)
containerChanges.items.push_back(containerItem);
}
void LocalEvent::editContainer(MWWorld::CellStore* cellStore)
{
WorldObject worldObject;
for (unsigned int i = 0; i < objectChanges.count; i++)
{
worldObject = objectChanges.objects[i];
LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s",
worldObject.refId.c_str(),
worldObject.refNumIndex,
cell.getDescription().c_str());
MWWorld::Ptr ptrFound = cellStore->searchExact(worldObject.refId, worldObject.refNumIndex);
if (ptrFound)
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i",
ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum());
MWWorld::ContainerStore& containerStore = ptrFound.getClass().getContainerStore(ptrFound);
for (unsigned int i = 0; i < containerChanges.count; i++)
{
ContainerItem item = containerChanges.items.at(i);
if (containerChanges.action == ContainerChanges::REMOVE)
{
containerStore.remove(item.refId, item.count, mwmp::Players::getPlayer(guid)->getPtr());
}
}
// If we are in a container, and it happens to be this container, update its view
if (MWBase::Environment::get().getWindowManager()->containsMode(MWGui::GM_Container))
{
CurrentContainer *currentContainer = &mwmp::Main::get().getLocalPlayer()->currentContainer;
if (currentContainer->refNumIndex == ptrFound.getCellRef().getRefNum().mIndex &&
Misc::StringUtils::ciEqual(currentContainer->refId, ptrFound.getCellRef().getRefId()))
{
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Container);
MWBase::Environment::get().getWindowManager()->openContainer(ptrFound, currentContainer->loot);
}
}
}
}
}
void LocalEvent::placeObjects(MWWorld::CellStore* cellStore)
{
WorldObject worldObject;

@ -18,6 +18,7 @@ namespace mwmp
void addObject(WorldObject worldObject);
void addContainerItem(ContainerItem containerItem);
void editContainer(MWWorld::CellStore* cellStore);
void placeObjects(MWWorld::CellStore* cellStore);
void deleteObjects(MWWorld::CellStore* cellStore);
void lockObjects(MWWorld::CellStore* cellStore);

@ -1096,6 +1096,12 @@ void LocalPlayer::clearCellStates()
cellStateChanges.cellStates.clear();
}
void LocalPlayer::clearCurrentContainer()
{
currentContainer.refId = "";
currentContainer.refNumIndex = 0;
}
void LocalPlayer::storeCellState(ESM::Cell cell, int stateType)
{
std::vector<CellState>::iterator iter;
@ -1119,6 +1125,13 @@ void LocalPlayer::storeCellState(ESM::Cell cell, int stateType)
cellStateChanges.cellStates.push_back(cellState);
}
void LocalPlayer::storeCurrentContainer(const MWWorld::Ptr &container, bool loot)
{
currentContainer.refId = container.getCellRef().getRefId();
currentContainer.refNumIndex = container.getCellRef().getRefNum().mIndex;
currentContainer.loot = loot;
}
void LocalPlayer::prepareAttack(Attack::TYPE type, bool state)
{
if (attack.pressed == state && type != Attack::MAGIC)

@ -68,8 +68,10 @@ namespace mwmp
void sendAttack(Attack::TYPE type);
void clearCellStates();
void clearCurrentContainer();
void storeCellState(ESM::Cell cell, int stateType);
void storeCurrentContainer(const MWWorld::Ptr& container, bool loot);
void prepareAttack(Attack::TYPE type, bool state);

@ -739,6 +739,17 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
switch (packet->data[0])
{
case ID_CONTAINER:
{
MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(event->cell);
if (!ptrCellStore) return;
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_CONTAINER");
event->editContainer(ptrCellStore);
break;
}
case ID_OBJECT_PLACE:
{
MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(event->cell);

@ -44,6 +44,9 @@ MWWorld::CellStore *mwmp::WorldController::getCell(const ESM::Cell& cell)
void mwmp::WorldController::openContainer(const MWWorld::Ptr &container, bool loot)
{
// Record this as the player's current open container
mwmp::Main::get().getLocalPlayer()->storeCurrentContainer(container, loot);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Container \"%s\" (%d) is opened. Loot: %s",
container.getCellRef().getRefId().c_str(),
container.getCellRef().getRefNum().mIndex,
@ -65,6 +68,8 @@ void mwmp::WorldController::openContainer(const MWWorld::Ptr &container, bool lo
void mwmp::WorldController::closeContainer(const MWWorld::Ptr &container)
{
mwmp::Main::get().getLocalPlayer()->clearCurrentContainer();
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Container \"%s\" (%d) is closed.",
container.getCellRef().getRefId().c_str(),
container.getCellRef().getRefNum().mIndex);

@ -35,6 +35,13 @@ namespace mwmp
char knockdown;
};
struct CurrentContainer
{
std::string refId;
int refNumIndex;
bool loot;
};
struct Item
{
std::string refId;
@ -160,13 +167,16 @@ namespace mwmp
int month;
int day;
double hour;
InventoryChanges inventoryChanges;
SpellbookChanges spellbookChanges;
JournalChanges journalChanges;
CellStateChanges cellStateChanges;
ESM::ActiveSpells activeSpells;
CurrentContainer currentContainer;
bool consoleAllowed;
bool ignorePosPacket;
ESM::ActiveSpells activeSpells;
ESM::Position position;
ESM::Position direction;

Loading…
Cancel
Save