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
|
|
|
|
2016-11-17 22:52:17 +00:00
|
|
|
return player->inventory.count;
|
2016-08-30 04:19:49 +00:00
|
|
|
}
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-11-16 17:28:22 +00:00
|
|
|
void ItemFunctions::EquipItem(unsigned short pid, unsigned short slot, const char *itemName, unsigned int count, int health) noexcept
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player,);
|
|
|
|
|
|
|
|
player->EquipedItem(slot)->refid = itemName;
|
|
|
|
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 04:39:35 +00:00
|
|
|
LOG_MESSAGE(Log::LOG_WARN, "stub");
|
2016-11-16 17:28:22 +00:00
|
|
|
//ItemFunctions::EquipItem(pid, slot, "", 0);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 22:52:17 +00:00
|
|
|
void ItemFunctions::AddItem(unsigned short pid, const char* itemName, 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;
|
|
|
|
item.refid = itemName;
|
|
|
|
item.count = count;
|
|
|
|
item.health = health;
|
|
|
|
|
|
|
|
player->inventorySendBuffer.items.push_back(item);
|
|
|
|
player->inventorySendBuffer.action = Inventory::ADDITEM;
|
2016-11-17 21:07:29 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 22:52:17 +00:00
|
|
|
void ItemFunctions::RemoveItem(unsigned short pid, const char* itemName, 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;
|
|
|
|
item.refid = itemName;
|
|
|
|
item.count = count;
|
|
|
|
|
|
|
|
player->inventorySendBuffer.items.clear();
|
|
|
|
player->inventorySendBuffer.items.push_back(item);
|
|
|
|
player->inventorySendBuffer.action = Inventory::REMOVEITEM;
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 17:28:22 +00:00
|
|
|
bool ItemFunctions::HasItemEquipped(unsigned short pid, const char* itemName)
|
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-08-17 15:04:35 +00:00
|
|
|
if (Misc::StringUtils::ciEqual(player->EquipedItem(slot)->refid, itemName))
|
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
|
|
|
|
2016-11-17 22:52:17 +00:00
|
|
|
if (i >= player->inventory.count)
|
|
|
|
return "invalid";
|
|
|
|
|
|
|
|
return player->inventory.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);
|
|
|
|
|
2016-11-17 22:52:17 +00:00
|
|
|
return player->inventory.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);
|
|
|
|
|
2016-11-17 22:52:17 +00:00
|
|
|
return player->inventory.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
|
|
|
|
2016-11-16 17:28:22 +00:00
|
|
|
void ItemFunctions::SendInventory(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, );
|
|
|
|
std::swap(player->inventory, player->inventorySendBuffer);
|
2016-11-16 00:05:14 +00:00
|
|
|
mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_INVENTORY)->Send(player, false);
|
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->inventory = std::move(player->inventorySendBuffer);
|
|
|
|
player->inventorySendBuffer.items.clear();
|
|
|
|
}
|