1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-20 18:39:39 +00:00

[Client] Send Container & ObjectState packets when harvesting objects

This commit is contained in:
David Cernat 2021-03-31 08:13:59 +02:00
parent 17ee3d54e4
commit 860be0a4e7

View file

@ -4,6 +4,19 @@
#include <MyGUI_LanguageManager.h>
/*
Start of tes3mp addition
Include additional headers for multiplayer purposes
*/
#include "../mwmp/Main.hpp"
#include "../mwmp/Networking.hpp"
#include "../mwmp/LocalPlayer.hpp"
#include "../mwmp/ObjectList.hpp"
/*
End of tes3mp addition
*/
#include <components/misc/stringops.hpp>
#include "../mwbase/environment.hpp"
@ -28,6 +41,25 @@ namespace MWWorld
return;
MWWorld::Ptr target = getTarget();
/*
Start of tes3mp addition
Prepare an ID_CONTAINER packet that will let the server know about the
items removed from the harvested objects
*/
mwmp::ObjectList* objectList = mwmp::Main::get().getNetworking()->getObjectList();
objectList->reset();
objectList->packetOrigin = mwmp::CLIENT_GAMEPLAY;
objectList->cell = *target.getCell()->getCell();
objectList->action = mwmp::BaseObjectList::REMOVE;
objectList->containerSubAction = mwmp::BaseObjectList::NONE;
mwmp::BaseObject baseObject = objectList->getBaseObjectFromPtr(target);
/*
End of tes3mp addition
*/
MWWorld::ContainerStore& store = target.getClass().getContainerStore (target);
store.resolve();
MWWorld::ContainerStore& actorStore = actor.getClass().getContainerStore(actor);
@ -42,10 +74,35 @@ namespace MWWorld
// for a last item in the container - empty harvested containers are considered as "allowed to use".
MWBase::Environment::get().getMechanicsManager()->itemTaken(actor, *it, target, itemCount);
actorStore.add(*it, itemCount, actor);
/*
Start of tes3mp addition
Track this item removal in the ID_CONTAINER packet being prepared
*/
objectList->addContainerItem(baseObject, *it, 0, itemCount);
/*
End of tes3mp addition
*/
store.remove(*it, itemCount, getTarget());
takenMap[it->getClass().getName(*it)]+=itemCount;
}
/*
Start of tes3mp addition
Send an ID_CONTAINER packet if the local player is logged in
*/
if (mwmp::Main::get().getLocalPlayer()->isLoggedIn())
{
objectList->addBaseObject(baseObject);
objectList->sendContainer();
}
/*
End of tes3mp addition
*/
// Spawn a messagebox (only for items added to player's inventory)
if (actor == MWBase::Environment::get().getWorld()->getPlayerPtr())
{
@ -89,5 +146,28 @@ namespace MWWorld
// Update animation object
MWBase::Environment::get().getWorld()->disable(target);
MWBase::Environment::get().getWorld()->enable(target);
/*
Start of tes3mp addition
Send ID_OBJECT_STATE packets whenever an object is harvested, as long as
the player is logged in on the server
*/
if (mwmp::Main::get().getLocalPlayer()->isLoggedIn())
{
mwmp::ObjectList* objectList = mwmp::Main::get().getNetworking()->getObjectList();
objectList->reset();
objectList->packetOrigin = mwmp::CLIENT_GAMEPLAY;
objectList->addObjectState(target, false);
objectList->sendObjectState();
objectList->reset();
objectList->packetOrigin = mwmp::CLIENT_GAMEPLAY;
objectList->addObjectState(target, true);
objectList->sendObjectState();
}
/*
End of tes3mp addition
*/
}
}