forked from teamnwah/openmw-tes3coop
[General] Implement PlayerItemUse packet
Players can no longer unilaterally use items on themselves in their inventory. When they try to use an item, they send a PlayerItemUse packet to the server with the item's details. A serverside script can then check the item and either send the packet back to make the item use go through or drop it.fix/skillcap
parent
888e1dfff8
commit
8df08c7d10
@ -0,0 +1,25 @@
|
||||
#ifndef OPENMW_PROCESSORPLAYERITEMUSE_HPP
|
||||
#define OPENMW_PROCESSORPLAYERITEMUSE_HPP
|
||||
|
||||
#include "../PlayerProcessor.hpp"
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
class ProcessorPlayerItemUse : public PlayerProcessor
|
||||
{
|
||||
public:
|
||||
ProcessorPlayerItemUse()
|
||||
{
|
||||
BPP_INIT(ID_PLAYER_ITEM_USE)
|
||||
}
|
||||
|
||||
void Do(PlayerPacket &packet, Player &player) override
|
||||
{
|
||||
DEBUG_PRINTF(strPacketID.c_str());
|
||||
|
||||
Script::Call<Script::CallbackIdentity("OnPlayerItemUse")>(player.getId());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //OPENMW_PROCESSORPLAYERITEMUSE_HPP
|
@ -0,0 +1,44 @@
|
||||
#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"
|
||||
|
||||
#include "../MechanicsHelper.hpp"
|
||||
#include "../PlayerProcessor.hpp"
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
class ProcessorPlayerItemUse : public PlayerProcessor
|
||||
{
|
||||
public:
|
||||
ProcessorPlayerItemUse()
|
||||
{
|
||||
BPP_INIT(ID_PLAYER_ITEM_USE)
|
||||
}
|
||||
|
||||
virtual void Do(PlayerPacket &packet, BasePlayer *player)
|
||||
{
|
||||
if (!isLocal()) return;
|
||||
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_ITEM_USE about LocalPlayer from server");
|
||||
|
||||
if (!isRequest())
|
||||
{
|
||||
LOG_APPEND(Log::LOG_INFO, "- refId: %s, count: %i, charge: %f, enchantmentCharge: %f, soul: %s",
|
||||
player->usedItem.refId.c_str(), player->usedItem.count, player->usedItem.charge,
|
||||
player->usedItem.enchantmentCharge, player->usedItem.soul.c_str());
|
||||
|
||||
MWWorld::Ptr &playerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||
MWWorld::InventoryStore &inventoryStore = playerPtr.getClass().getInventoryStore(playerPtr);
|
||||
|
||||
MWWorld::Ptr &itemPtr = MechanicsHelper::getItemPtrFromStore(player->usedItem, inventoryStore);
|
||||
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->useItem(itemPtr);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //OPENMW_PROCESSORPLAYERITEMUSE_HPP
|
@ -0,0 +1,21 @@
|
||||
#include "PacketPlayerItemUse.hpp"
|
||||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
|
||||
using namespace mwmp;
|
||||
|
||||
PacketPlayerItemUse::PacketPlayerItemUse(RakNet::RakPeerInterface *peer) : PlayerPacket(peer)
|
||||
{
|
||||
packetID = ID_PLAYER_ITEM_USE;
|
||||
}
|
||||
|
||||
void PacketPlayerItemUse::Packet(RakNet::BitStream *bs, bool send)
|
||||
{
|
||||
PlayerPacket::Packet(bs, send);
|
||||
|
||||
|
||||
RW(player->usedItem.refId, send, true);
|
||||
RW(player->usedItem.count, send);
|
||||
RW(player->usedItem.charge, send);
|
||||
RW(player->usedItem.enchantmentCharge, send);
|
||||
RW(player->usedItem.soul, send, true);
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
#ifndef OPENMW_PACKETPLAYERITEMUSE_HPP
|
||||
#define OPENMW_PACKETPLAYERITEMUSE_HPP
|
||||
|
||||
#include <components/openmw-mp/Packets/Player/PlayerPacket.hpp>
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
class PacketPlayerItemUse : public PlayerPacket
|
||||
{
|
||||
public:
|
||||
PacketPlayerItemUse(RakNet::RakPeerInterface *peer);
|
||||
|
||||
virtual void Packet(RakNet::BitStream *bs, bool send);
|
||||
};
|
||||
}
|
||||
|
||||
#endif //OPENMW_PACKETPLAYERITEMUSE_HPP
|
Loading…
Reference in New Issue