2018-08-09 15:25:20 +00:00
|
|
|
#ifndef OPENMW_PROCESSORPLAYERITEMUSE_HPP
|
|
|
|
#define OPENMW_PROCESSORPLAYERITEMUSE_HPP
|
|
|
|
|
|
|
|
#include "apps/openmw/mwbase/environment.hpp"
|
|
|
|
#include "apps/openmw/mwgui/inventorywindow.hpp"
|
|
|
|
#include "apps/openmw/mwgui/windowmanagerimp.hpp"
|
|
|
|
#include "apps/openmw/mwworld/inventorystore.hpp"
|
|
|
|
|
2018-08-09 19:33:22 +00:00
|
|
|
#include "apps/openmw/mwmp/MechanicsHelper.hpp"
|
|
|
|
|
2018-08-09 15:25:20 +00:00
|
|
|
#include "../PlayerProcessor.hpp"
|
|
|
|
|
|
|
|
namespace mwmp
|
|
|
|
{
|
2019-10-24 19:16:17 +00:00
|
|
|
class ProcessorPlayerItemUse final: public PlayerProcessor
|
2018-08-09 15:25:20 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ProcessorPlayerItemUse()
|
|
|
|
{
|
|
|
|
BPP_INIT(ID_PLAYER_ITEM_USE)
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Do(PlayerPacket &packet, BasePlayer *player)
|
|
|
|
{
|
|
|
|
if (!isLocal()) return;
|
|
|
|
|
2019-08-19 18:39:33 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received ID_PLAYER_ITEM_USE about LocalPlayer from server");
|
2018-08-09 15:25:20 +00:00
|
|
|
|
|
|
|
if (!isRequest())
|
|
|
|
{
|
2019-08-19 18:39:33 +00:00
|
|
|
LOG_APPEND(TimedLog::LOG_INFO, "- refId: %s, count: %i, charge: %i, enchantmentCharge: %f, soul: %s",
|
2018-08-09 15:25:20 +00:00
|
|
|
player->usedItem.refId.c_str(), player->usedItem.count, player->usedItem.charge,
|
2018-10-11 20:49:24 +00:00
|
|
|
player->usedItem.enchantmentCharge, player->usedItem.soul.c_str());
|
2018-08-09 15:25:20 +00:00
|
|
|
|
2018-08-20 07:15:30 +00:00
|
|
|
MWWorld::Ptr playerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
2018-08-09 15:25:20 +00:00
|
|
|
MWWorld::InventoryStore &inventoryStore = playerPtr.getClass().getInventoryStore(playerPtr);
|
|
|
|
|
2018-08-11 16:00:02 +00:00
|
|
|
MWWorld::Ptr itemPtr = MechanicsHelper::getItemPtrFromStore(player->usedItem, inventoryStore);
|
2018-11-13 18:36:31 +00:00
|
|
|
|
|
|
|
if (itemPtr)
|
2019-08-16 02:50:07 +00:00
|
|
|
{
|
2018-11-13 18:36:31 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->useItem(itemPtr);
|
2019-08-16 02:50:07 +00:00
|
|
|
|
|
|
|
if (player->usingItemMagic)
|
|
|
|
{
|
|
|
|
MWWorld::ContainerStoreIterator storeIterator = inventoryStore.begin();
|
|
|
|
for (; storeIterator != inventoryStore.end(); ++storeIterator)
|
|
|
|
{
|
|
|
|
if (*storeIterator == itemPtr)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
inventoryStore.setSelectedEnchantItem(storeIterator);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (player->itemUseDrawState != MWMechanics::DrawState_Nothing)
|
|
|
|
playerPtr.getClass().getNpcStats(playerPtr).setDrawState(static_cast<MWMechanics::DrawState_>(player->itemUseDrawState));
|
|
|
|
}
|
2018-11-13 18:36:31 +00:00
|
|
|
else
|
2019-08-19 18:39:33 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(TimedLog::LOG_ERROR, "Cannot use non-existent item %s", player->usedItem.refId.c_str());
|
2018-08-09 15:25:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //OPENMW_PROCESSORPLAYERITEMUSE_HPP
|