2016-01-12 03:41:44 +00:00
|
|
|
//
|
|
|
|
// Created by koncord on 02.03.16.
|
|
|
|
//
|
|
|
|
|
2016-08-30 04:19:49 +00:00
|
|
|
#include "Items.hpp"
|
2016-01-12 03:41:44 +00:00
|
|
|
#include <apps/openmw-mp/Script/ScriptFunctions.hpp>
|
|
|
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
|
|
|
#include <apps/openmw-mp/Networking.hpp>
|
2016-11-17 21:07:29 +00:00
|
|
|
#include <apps/openmw/mwworld/inventorystore.hpp>
|
2016-01-12 03:41:44 +00:00
|
|
|
#include <components/misc/stringops.hpp>
|
|
|
|
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
using namespace mwmp;
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-11-17 22:52:17 +00:00
|
|
|
int ItemFunctions::GetEquipmentSize() noexcept
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-11-17 22:52:17 +00:00
|
|
|
return MWWorld::InventoryStore::Slots;
|
|
|
|
}
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-11-17 22:52:17 +00:00
|
|
|
unsigned int ItemFunctions::GetInventorySize(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0);
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
|
2017-01-19 16:06:59 +00:00
|
|
|
return player->packetItems.count;
|
2016-08-30 04:19:49 +00:00
|
|
|
}
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-11-21 18:37:04 +00:00
|
|
|
void ItemFunctions::EquipItem(unsigned short pid, unsigned short slot, const char *itemId, unsigned int count, int health) noexcept
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player,);
|
|
|
|
|
2016-11-21 18:37:04 +00:00
|
|
|
player->EquipedItem(slot)->refid = itemId;
|
2016-01-12 03:41:44 +00:00
|
|
|
player->EquipedItem(slot)->count = count;
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
player->EquipedItem(slot)->health = health;
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 17:28:22 +00:00
|
|
|
void ItemFunctions::UnequipItem(unsigned short pid, unsigned short slot) noexcept
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-11-17 23:50:55 +00:00
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
|
|
|
ItemFunctions::EquipItem(pid, slot, "", 0, -1);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 18:37:04 +00:00
|
|
|
void ItemFunctions::AddItem(unsigned short pid, const char* itemId, unsigned int count, int health) noexcept
|
2016-11-17 21:07:29 +00:00
|
|
|
{
|
2016-11-17 22:52:17 +00:00
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
|
|
|
Item item;
|
2016-11-21 18:37:04 +00:00
|
|
|
item.refid = itemId;
|
2016-11-17 22:52:17 +00:00
|
|
|
item.count = count;
|
|
|
|
item.health = health;
|
|
|
|
|
2017-01-19 16:06:59 +00:00
|
|
|
player->packetItemsBuffer.items.push_back(item);
|
|
|
|
player->packetItemsBuffer.action = PacketItems::ADD;
|
2016-11-17 21:07:29 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 18:37:04 +00:00
|
|
|
void ItemFunctions::RemoveItem(unsigned short pid, const char* itemId, unsigned short count) noexcept
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-09-30 09:30:05 +00:00
|
|
|
Player *player;
|
2016-11-17 22:52:17 +00:00
|
|
|
GET_PLAYER(pid, player, );
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-11-17 22:52:17 +00:00
|
|
|
Item item;
|
2016-11-21 18:37:04 +00:00
|
|
|
item.refid = itemId;
|
2016-11-17 22:52:17 +00:00
|
|
|
item.count = count;
|
|
|
|
|
2017-01-19 16:06:59 +00:00
|
|
|
player->packetItemsBuffer.items.push_back(item);
|
|
|
|
player->packetItemsBuffer.action = PacketItems::REMOVE;
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-20 02:06:33 +00:00
|
|
|
void ItemFunctions::ClearInventory(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
2017-01-19 16:06:59 +00:00
|
|
|
player->packetItemsBuffer.items.clear();
|
|
|
|
player->packetItemsBuffer.action = PacketItems::UPDATE;
|
2016-11-20 02:06:33 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 18:37:04 +00:00
|
|
|
bool ItemFunctions::HasItemEquipped(unsigned short pid, const char* itemId)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, false);
|
|
|
|
|
2016-11-17 22:52:17 +00:00
|
|
|
for (int slot = 0; slot < MWWorld::InventoryStore::Slots; slot++)
|
2016-11-21 18:37:04 +00:00
|
|
|
if (Misc::StringUtils::ciEqual(player->EquipedItem(slot)->refid, itemId))
|
2016-01-12 03:41:44 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
2016-08-30 04:19:49 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 22:52:17 +00:00
|
|
|
const char *ItemFunctions::GetEquipmentItemId(unsigned short pid, unsigned short slot) noexcept
|
2016-08-30 04:19:49 +00:00
|
|
|
{
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
Player *player;
|
2016-11-17 22:52:17 +00:00
|
|
|
GET_PLAYER(pid, player, 0);
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
|
2016-11-17 22:52:17 +00:00
|
|
|
return player->EquipedItem(slot)->refid.c_str();
|
2016-08-30 04:19:49 +00:00
|
|
|
}
|
2016-11-17 22:52:17 +00:00
|
|
|
|
|
|
|
int ItemFunctions::GetEquipmentItemCount(unsigned short pid, unsigned short slot) noexcept
|
2016-08-30 04:19:49 +00:00
|
|
|
{
|
2016-11-17 22:52:17 +00:00
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0);
|
|
|
|
|
|
|
|
return player->EquipedItem(slot)->count;
|
2016-09-30 09:30:05 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 22:52:17 +00:00
|
|
|
int ItemFunctions::GetEquipmentItemHealth(unsigned short pid, unsigned short slot) noexcept
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
2016-11-17 22:52:17 +00:00
|
|
|
GET_PLAYER(pid, player, 0);
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
|
2016-11-17 22:52:17 +00:00
|
|
|
return player->EquipedItem(slot)->health;
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 22:52:17 +00:00
|
|
|
const char *ItemFunctions::GetInventoryItemId(unsigned short pid, unsigned int i) noexcept
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
2016-11-17 22:52:17 +00:00
|
|
|
GET_PLAYER(pid, player, "");
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
|
2017-01-19 16:06:59 +00:00
|
|
|
if (i >= player->packetItems.count)
|
2016-11-17 22:52:17 +00:00
|
|
|
return "invalid";
|
|
|
|
|
2017-01-19 16:06:59 +00:00
|
|
|
return player->packetItems.items.at(i).refid.c_str();
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 22:52:17 +00:00
|
|
|
int ItemFunctions::GetInventoryItemCount(unsigned short pid, unsigned int i) noexcept
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0);
|
|
|
|
|
2017-01-19 16:06:59 +00:00
|
|
|
return player->packetItems.items.at(i).count;
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 22:52:17 +00:00
|
|
|
int ItemFunctions::GetInventoryItemHealth(unsigned short pid, unsigned int i) noexcept
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0);
|
|
|
|
|
2017-01-19 16:06:59 +00:00
|
|
|
return player->packetItems.items.at(i).health;
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 17:28:22 +00:00
|
|
|
void ItemFunctions::SendEquipment(unsigned short pid) noexcept
|
2016-09-30 09:30:05 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
2016-11-16 00:05:14 +00:00
|
|
|
mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_EQUIPMENT)->Send(player, false);
|
|
|
|
mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_EQUIPMENT)->Send(player, true);
|
2016-09-30 09:30:05 +00:00
|
|
|
}
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
|
2017-01-19 16:06:59 +00:00
|
|
|
void ItemFunctions::SendItems(unsigned short pid) noexcept
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
2017-01-19 16:06:59 +00:00
|
|
|
std::swap(player->packetItems, player->packetItemsBuffer);
|
2016-11-16 00:05:14 +00:00
|
|
|
mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_INVENTORY)->Send(player, false);
|
2017-01-19 16:06:59 +00:00
|
|
|
player->packetItems = std::move(player->packetItemsBuffer);
|
|
|
|
player->packetItemsBuffer.items.clear();
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
}
|