forked from mirror/openmw-tes3mp
Add and implement ClearInventory() script function
This commit is contained in:
parent
80b40bfb70
commit
456aee65d9
3 changed files with 27 additions and 9 deletions
|
@ -69,6 +69,15 @@ void ItemFunctions::RemoveItem(unsigned short pid, const char* itemName, unsigne
|
||||||
player->inventorySendBuffer.action = Inventory::REMOVEITEM;
|
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)
|
bool ItemFunctions::HasItemEquipped(unsigned short pid, const char* itemName)
|
||||||
{
|
{
|
||||||
Player *player;
|
Player *player;
|
||||||
|
|
|
@ -12,8 +12,9 @@
|
||||||
{"EquipItem", ItemFunctions::EquipItem},\
|
{"EquipItem", ItemFunctions::EquipItem},\
|
||||||
{"UnequipItem", ItemFunctions::UnequipItem},\
|
{"UnequipItem", ItemFunctions::UnequipItem},\
|
||||||
\
|
\
|
||||||
{"AddItem", ItemFunctions::AddItem}, \
|
{"AddItem", ItemFunctions::AddItem},\
|
||||||
{"RemoveItem", ItemFunctions::RemoveItem}, \
|
{"RemoveItem", ItemFunctions::RemoveItem},\
|
||||||
|
{"ClearInventory", ItemFunctions::ClearInventory},\
|
||||||
\
|
\
|
||||||
{"HasItemEquipped", ItemFunctions::HasItemEquipped},\
|
{"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 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 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);
|
static bool HasItemEquipped(unsigned short pid, const char* itemName);
|
||||||
|
|
||||||
|
|
|
@ -296,14 +296,15 @@ void Networking::processPlayerPacket(RakNet::Packet *packet)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
myPacket->Packet(&bsIn, getLocalPlayer(), false);
|
myPacket->Packet(&bsIn, getLocalPlayer(), false);
|
||||||
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
MWWorld::Ptr ptrPlayer = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||||
MWWorld::ContainerStore &conStore = ptr.getClass().getContainerStore(ptr);
|
MWWorld::ContainerStore &conStore = ptrPlayer.getClass().getContainerStore(ptrPlayer);
|
||||||
|
|
||||||
if (getLocalPlayer()->inventory.action == Inventory::ADDITEM)
|
if (getLocalPlayer()->inventory.action == Inventory::ADDITEM)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++)
|
for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++)
|
||||||
{
|
{
|
||||||
mwmp::Item item = getLocalPlayer()->inventory.items[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)
|
if (item.health != -1)
|
||||||
itemPtr.getCellRef().setCharge(item.health);
|
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++)
|
for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++)
|
||||||
{
|
{
|
||||||
mwmp::Item item = getLocalPlayer()->inventory.items[i];
|
mwmp::Item item = getLocalPlayer()->inventory.items[i];
|
||||||
conStore.remove(item.refid, item.count, ptr);
|
conStore.remove(item.refid, item.count, ptrPlayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // update
|
else // update
|
||||||
{
|
{
|
||||||
|
// Clear items in inventory
|
||||||
conStore.clear();
|
conStore.clear();
|
||||||
|
|
||||||
for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++)
|
for (unsigned int i = 0; i < getLocalPlayer()->inventory.count; i++)
|
||||||
{
|
{
|
||||||
mwmp::Item item = getLocalPlayer()->inventory.items[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)
|
if (item.health != -1)
|
||||||
itemPtr.getCellRef().setCharge(item.health);
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue