forked from mirror/openmw-tes3mp
[Client] See when other players remove items from containers
This commit is contained in:
parent
25d79dbcfe
commit
60d6a6d463
7 changed files with 96 additions and 2 deletions
|
@ -1,6 +1,8 @@
|
||||||
#include "LocalEvent.hpp"
|
#include "LocalEvent.hpp"
|
||||||
#include "Networking.hpp"
|
|
||||||
#include "Main.hpp"
|
#include "Main.hpp"
|
||||||
|
#include "Networking.hpp"
|
||||||
|
#include "LocalPlayer.hpp"
|
||||||
|
#include "DedicatedPlayer.hpp"
|
||||||
|
|
||||||
#include <components/openmw-mp/Log.hpp>
|
#include <components/openmw-mp/Log.hpp>
|
||||||
|
|
||||||
|
@ -11,6 +13,7 @@
|
||||||
#include "../mwbase/windowmanager.hpp"
|
#include "../mwbase/windowmanager.hpp"
|
||||||
|
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
|
#include "../mwworld/containerstore.hpp"
|
||||||
#include "../mwworld/esmstore.hpp"
|
#include "../mwworld/esmstore.hpp"
|
||||||
#include "../mwworld/manualref.hpp"
|
#include "../mwworld/manualref.hpp"
|
||||||
|
|
||||||
|
@ -42,6 +45,55 @@ void LocalEvent::addContainerItem(ContainerItem containerItem)
|
||||||
containerChanges.items.push_back(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)
|
void LocalEvent::placeObjects(MWWorld::CellStore* cellStore)
|
||||||
{
|
{
|
||||||
WorldObject worldObject;
|
WorldObject worldObject;
|
||||||
|
|
|
@ -18,6 +18,7 @@ namespace mwmp
|
||||||
void addObject(WorldObject worldObject);
|
void addObject(WorldObject worldObject);
|
||||||
void addContainerItem(ContainerItem containerItem);
|
void addContainerItem(ContainerItem containerItem);
|
||||||
|
|
||||||
|
void editContainer(MWWorld::CellStore* cellStore);
|
||||||
void placeObjects(MWWorld::CellStore* cellStore);
|
void placeObjects(MWWorld::CellStore* cellStore);
|
||||||
void deleteObjects(MWWorld::CellStore* cellStore);
|
void deleteObjects(MWWorld::CellStore* cellStore);
|
||||||
void lockObjects(MWWorld::CellStore* cellStore);
|
void lockObjects(MWWorld::CellStore* cellStore);
|
||||||
|
|
|
@ -1096,6 +1096,12 @@ void LocalPlayer::clearCellStates()
|
||||||
cellStateChanges.cellStates.clear();
|
cellStateChanges.cellStates.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LocalPlayer::clearCurrentContainer()
|
||||||
|
{
|
||||||
|
currentContainer.refId = "";
|
||||||
|
currentContainer.refNumIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void LocalPlayer::storeCellState(ESM::Cell cell, int stateType)
|
void LocalPlayer::storeCellState(ESM::Cell cell, int stateType)
|
||||||
{
|
{
|
||||||
std::vector<CellState>::iterator iter;
|
std::vector<CellState>::iterator iter;
|
||||||
|
@ -1119,6 +1125,13 @@ void LocalPlayer::storeCellState(ESM::Cell cell, int stateType)
|
||||||
cellStateChanges.cellStates.push_back(cellState);
|
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)
|
void LocalPlayer::prepareAttack(Attack::TYPE type, bool state)
|
||||||
{
|
{
|
||||||
if (attack.pressed == state && type != Attack::MAGIC)
|
if (attack.pressed == state && type != Attack::MAGIC)
|
||||||
|
|
|
@ -68,8 +68,10 @@ namespace mwmp
|
||||||
void sendAttack(Attack::TYPE type);
|
void sendAttack(Attack::TYPE type);
|
||||||
|
|
||||||
void clearCellStates();
|
void clearCellStates();
|
||||||
|
void clearCurrentContainer();
|
||||||
|
|
||||||
void storeCellState(ESM::Cell cell, int stateType);
|
void storeCellState(ESM::Cell cell, int stateType);
|
||||||
|
void storeCurrentContainer(const MWWorld::Ptr& container, bool loot);
|
||||||
|
|
||||||
void prepareAttack(Attack::TYPE type, bool state);
|
void prepareAttack(Attack::TYPE type, bool state);
|
||||||
|
|
||||||
|
|
|
@ -739,6 +739,17 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
|
||||||
|
|
||||||
switch (packet->data[0])
|
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:
|
case ID_OBJECT_PLACE:
|
||||||
{
|
{
|
||||||
MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(event->cell);
|
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)
|
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",
|
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Container \"%s\" (%d) is opened. Loot: %s",
|
||||||
container.getCellRef().getRefId().c_str(),
|
container.getCellRef().getRefId().c_str(),
|
||||||
container.getCellRef().getRefNum().mIndex,
|
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)
|
void mwmp::WorldController::closeContainer(const MWWorld::Ptr &container)
|
||||||
{
|
{
|
||||||
|
mwmp::Main::get().getLocalPlayer()->clearCurrentContainer();
|
||||||
|
|
||||||
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Container \"%s\" (%d) is closed.",
|
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Container \"%s\" (%d) is closed.",
|
||||||
container.getCellRef().getRefId().c_str(),
|
container.getCellRef().getRefId().c_str(),
|
||||||
container.getCellRef().getRefNum().mIndex);
|
container.getCellRef().getRefNum().mIndex);
|
||||||
|
|
|
@ -35,6 +35,13 @@ namespace mwmp
|
||||||
char knockdown;
|
char knockdown;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CurrentContainer
|
||||||
|
{
|
||||||
|
std::string refId;
|
||||||
|
int refNumIndex;
|
||||||
|
bool loot;
|
||||||
|
};
|
||||||
|
|
||||||
struct Item
|
struct Item
|
||||||
{
|
{
|
||||||
std::string refId;
|
std::string refId;
|
||||||
|
@ -160,13 +167,16 @@ namespace mwmp
|
||||||
int month;
|
int month;
|
||||||
int day;
|
int day;
|
||||||
double hour;
|
double hour;
|
||||||
|
|
||||||
InventoryChanges inventoryChanges;
|
InventoryChanges inventoryChanges;
|
||||||
SpellbookChanges spellbookChanges;
|
SpellbookChanges spellbookChanges;
|
||||||
JournalChanges journalChanges;
|
JournalChanges journalChanges;
|
||||||
CellStateChanges cellStateChanges;
|
CellStateChanges cellStateChanges;
|
||||||
|
ESM::ActiveSpells activeSpells;
|
||||||
|
CurrentContainer currentContainer;
|
||||||
|
|
||||||
bool consoleAllowed;
|
bool consoleAllowed;
|
||||||
bool ignorePosPacket;
|
bool ignorePosPacket;
|
||||||
ESM::ActiveSpells activeSpells;
|
|
||||||
|
|
||||||
ESM::Position position;
|
ESM::Position position;
|
||||||
ESM::Position direction;
|
ESM::Position direction;
|
||||||
|
|
Loading…
Reference in a new issue