diff --git a/apps/openmw-mp/Script/Functions/Items.cpp b/apps/openmw-mp/Script/Functions/Items.cpp index aa3dc2eb0..a97106137 100644 --- a/apps/openmw-mp/Script/Functions/Items.cpp +++ b/apps/openmw-mp/Script/Functions/Items.cpp @@ -69,6 +69,15 @@ void ItemFunctions::RemoveItem(unsigned short pid, const char* itemName, unsigne player->inventorySendBuffer.action = Inventory::REMOVEITEM; } +void ItemFunctions::ClearInventory(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->inventorySendBuffer.items.clear(); + player->inventorySendBuffer.action = Inventory::UPDATE; +} + bool ItemFunctions::HasItemEquipped(unsigned short pid, const char* itemName) { Player *player; diff --git a/apps/openmw-mp/Script/Functions/Items.hpp b/apps/openmw-mp/Script/Functions/Items.hpp index eebe3b9a3..af1f4c1f5 100644 --- a/apps/openmw-mp/Script/Functions/Items.hpp +++ b/apps/openmw-mp/Script/Functions/Items.hpp @@ -12,8 +12,9 @@ {"EquipItem", ItemFunctions::EquipItem},\ {"UnequipItem", ItemFunctions::UnequipItem},\ \ - {"AddItem", ItemFunctions::AddItem}, \ - {"RemoveItem", ItemFunctions::RemoveItem}, \ + {"AddItem", ItemFunctions::AddItem},\ + {"RemoveItem", ItemFunctions::RemoveItem},\ + {"ClearInventory", ItemFunctions::ClearInventory},\ \ {"HasItemEquipped", ItemFunctions::HasItemEquipped},\ \ @@ -40,6 +41,7 @@ public: static void AddItem(unsigned short pid, const char* itemName, unsigned int count, int health) noexcept; static void RemoveItem(unsigned short pid, const char* itemName, unsigned short count) noexcept; + static void ClearInventory(unsigned short pid) noexcept; static bool HasItemEquipped(unsigned short pid, const char* itemName); diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index eb1bf53db..469214573 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -296,14 +296,15 @@ void Networking::processPlayerPacket(RakNet::Packet *packet) else { myPacket->Packet(&bsIn, getLocalPlayer(), false); - MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPlayerPtr(); - MWWorld::ContainerStore &conStore = ptr.getClass().getContainerStore(ptr); + MWWorld::Ptr ptrPlayer = MWBase::Environment::get().getWorld()->getPlayerPtr(); + MWWorld::ContainerStore &conStore = ptrPlayer.getClass().getContainerStore(ptrPlayer); + if (getLocalPlayer()->inventory.action == Inventory::ADDITEM) { for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++) { mwmp::Item item = getLocalPlayer()->inventory.items[i]; - MWWorld::Ptr itemPtr = *conStore.add(item.refid, item.count, ptr); + MWWorld::Ptr itemPtr = *conStore.add(item.refid, item.count, ptrPlayer); if (item.health != -1) itemPtr.getCellRef().setCharge(item.health); } @@ -313,21 +314,27 @@ void Networking::processPlayerPacket(RakNet::Packet *packet) for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++) { mwmp::Item item = getLocalPlayer()->inventory.items[i]; - conStore.remove(item.refid, item.count, ptr); + conStore.remove(item.refid, item.count, ptrPlayer); } } else // update { + // Clear items in inventory conStore.clear(); + for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++) { mwmp::Item item = getLocalPlayer()->inventory.items[i]; - MWWorld::Ptr itemPtr = *conStore.add(item.refid, item.count, ptr); + MWWorld::Ptr itemPtr = *conStore.add(item.refid, item.count, ptrPlayer); if (item.health != -1) itemPtr.getCellRef().setCharge(item.health); - printf("%s %d %d\n", item.refid.c_str(), item.count, item.health); } - getLocalPlayer()->setEquipment(); // restore equipped items + + // Don't automatically setEquipment() here, or the player could end + // up getting a new set of their starting clothes, or other items + // supposed to no longer exist + // + // Instead, expect server scripts to do that manually } } }