openmw-tes3coop/apps/openmw/mwmp/processors/player/ProcessorPlayerInventory.hpp

47 lines
1.5 KiB
C++
Raw Normal View History

2017-04-16 07:00:25 +00:00
#ifndef OPENMW_PROCESSORPLAYERUPDATEINVENTORY_HPP
#define OPENMW_PROCESSORPLAYERUPDATEINVENTORY_HPP
2017-06-06 16:06:10 +00:00
#include "../PlayerProcessor.hpp"
2017-04-16 07:00:25 +00:00
namespace mwmp
{
class ProcessorPlayerInventory : public PlayerProcessor
{
public:
ProcessorPlayerInventory()
{
BPP_INIT(ID_PLAYER_INVENTORY)
}
virtual void Do(PlayerPacket &packet, BasePlayer *player)
{
if (!isLocal()) return;
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_INVENTORY about LocalPlayer from server");
2017-04-16 07:00:25 +00:00
if (isRequest())
static_cast<LocalPlayer*>(player)->updateInventory(true);
else
{
LocalPlayer &localPlayer = static_cast<LocalPlayer&>(*player);
int inventoryAction = localPlayer.inventoryChanges.action;
// Because we send PlayerInventory packets from the same OpenMW methods that we use to set the
// items received, we need to set a boolean to prevent resending the items set here
localPlayer.isReceivingInventory = true;
2017-04-16 07:00:25 +00:00
if (inventoryAction == InventoryChanges::ADD)
localPlayer.addItems();
else if (inventoryAction == InventoryChanges::REMOVE)
localPlayer.removeItems();
else // InventoryChanges::SET
localPlayer.setInventory();
localPlayer.isReceivingInventory = false;
2017-04-16 07:00:25 +00:00
}
}
};
}
#endif //OPENMW_PROCESSORPLAYERUPDATEINVENTORY_HPP