forked from mirror/openmw-tes3mp
Clean up inventory script functions so they are usable for equipment too
This commit is contained in:
parent
356143faed
commit
56928bdc4c
2 changed files with 88 additions and 63 deletions
|
@ -11,18 +11,17 @@
|
||||||
|
|
||||||
using namespace mwmp;
|
using namespace mwmp;
|
||||||
|
|
||||||
void ItemFunctions::AddItem(unsigned short pid, const char* itemName, unsigned int count, int health) noexcept
|
int ItemFunctions::GetEquipmentSize() noexcept
|
||||||
|
{
|
||||||
|
return MWWorld::InventoryStore::Slots;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int ItemFunctions::GetInventorySize(unsigned short pid) noexcept
|
||||||
{
|
{
|
||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player,);
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
Item item;
|
return player->inventory.count;
|
||||||
item.refid = itemName;
|
|
||||||
item.count = count;
|
|
||||||
item.health = health;
|
|
||||||
|
|
||||||
player->inventorySendBuffer.items.push_back(item);
|
|
||||||
player->inventorySendBuffer.action = Inventory::ADDITEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemFunctions::EquipItem(unsigned short pid, unsigned short slot, const char *itemName, unsigned int count, int health) noexcept
|
void ItemFunctions::EquipItem(unsigned short pid, unsigned short slot, const char *itemName, unsigned int count, int health) noexcept
|
||||||
|
@ -41,34 +40,24 @@ void ItemFunctions::UnequipItem(unsigned short pid, unsigned short slot) noexcep
|
||||||
//ItemFunctions::EquipItem(pid, slot, "", 0);
|
//ItemFunctions::EquipItem(pid, slot, "", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ItemFunctions::GetEquipmentSize() noexcept
|
void ItemFunctions::AddItem(unsigned short pid, const char* itemName, unsigned int count, int health) noexcept
|
||||||
{
|
|
||||||
return MWWorld::InventoryStore::Slots;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *ItemFunctions::GetItemSlot(unsigned short pid, unsigned short slot) noexcept
|
|
||||||
{
|
{
|
||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, 0);
|
GET_PLAYER(pid, player, );
|
||||||
|
|
||||||
return player->EquipedItem(slot)->refid.c_str();
|
Item item;
|
||||||
}
|
item.refid = itemName;
|
||||||
|
item.count = count;
|
||||||
|
item.health = health;
|
||||||
|
|
||||||
bool ItemFunctions::HasItemEquipped(unsigned short pid, const char* itemName)
|
player->inventorySendBuffer.items.push_back(item);
|
||||||
{
|
player->inventorySendBuffer.action = Inventory::ADDITEM;
|
||||||
Player *player;
|
|
||||||
GET_PLAYER(pid, player, false);
|
|
||||||
|
|
||||||
for (int slot = 0; slot < 27; slot ++)
|
|
||||||
if (Misc::StringUtils::ciEqual(player->EquipedItem(slot)->refid, itemName))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemFunctions::RemoveItem(unsigned short pid, const char* itemName, unsigned short count) noexcept
|
void ItemFunctions::RemoveItem(unsigned short pid, const char* itemName, unsigned short count) noexcept
|
||||||
{
|
{
|
||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player,);
|
GET_PLAYER(pid, player, );
|
||||||
|
|
||||||
Item item;
|
Item item;
|
||||||
item.refid = itemName;
|
item.refid = itemName;
|
||||||
|
@ -78,20 +67,54 @@ void ItemFunctions::RemoveItem(unsigned short pid, const char* itemName, unsigne
|
||||||
player->inventorySendBuffer.items.push_back(item);
|
player->inventorySendBuffer.items.push_back(item);
|
||||||
player->inventorySendBuffer.action = Inventory::REMOVEITEM;
|
player->inventorySendBuffer.action = Inventory::REMOVEITEM;
|
||||||
}
|
}
|
||||||
void ItemFunctions::GetItemCount(unsigned short pid, const char* itemName) noexcept
|
|
||||||
|
bool ItemFunctions::HasItemEquipped(unsigned short pid, const char* itemName)
|
||||||
{
|
{
|
||||||
LOG_MESSAGE(Log::LOG_WARN, "stub");
|
Player *player;
|
||||||
|
GET_PLAYER(pid, player, false);
|
||||||
|
|
||||||
|
for (int slot = 0; slot < MWWorld::InventoryStore::Slots; slot++)
|
||||||
|
if (Misc::StringUtils::ciEqual(player->EquipedItem(slot)->refid, itemName))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *ItemFunctions::GetItemName(unsigned short pid, unsigned int i) noexcept
|
const char *ItemFunctions::GetEquipmentItemId(unsigned short pid, unsigned short slot) noexcept
|
||||||
|
{
|
||||||
|
Player *player;
|
||||||
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
|
return player->EquipedItem(slot)->refid.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ItemFunctions::GetEquipmentItemCount(unsigned short pid, unsigned short slot) noexcept
|
||||||
|
{
|
||||||
|
Player *player;
|
||||||
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
|
return player->EquipedItem(slot)->count;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ItemFunctions::GetEquipmentItemHealth(unsigned short pid, unsigned short slot) noexcept
|
||||||
|
{
|
||||||
|
Player *player;
|
||||||
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
|
return player->EquipedItem(slot)->health;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *ItemFunctions::GetInventoryItemId(unsigned short pid, unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, "");
|
GET_PLAYER(pid, player, "");
|
||||||
|
|
||||||
|
if (i >= player->inventory.count)
|
||||||
|
return "invalid";
|
||||||
|
|
||||||
return player->inventory.items.at(i).refid.c_str();
|
return player->inventory.items.at(i).refid.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ItemFunctions::GetItemCount2(unsigned short pid, unsigned int i) noexcept
|
int ItemFunctions::GetInventoryItemCount(unsigned short pid, unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, 0);
|
GET_PLAYER(pid, player, 0);
|
||||||
|
@ -99,7 +122,7 @@ int ItemFunctions::GetItemCount2(unsigned short pid, unsigned int i) noexcept
|
||||||
return player->inventory.items.at(i).count;
|
return player->inventory.items.at(i).count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ItemFunctions::GetItemHealth(unsigned short pid, unsigned int i) noexcept
|
int ItemFunctions::GetInventoryItemHealth(unsigned short pid, unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, 0);
|
GET_PLAYER(pid, player, 0);
|
||||||
|
@ -107,14 +130,6 @@ int ItemFunctions::GetItemHealth(unsigned short pid, unsigned int i) noexcept
|
||||||
return player->inventory.items.at(i).health;
|
return player->inventory.items.at(i).health;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ItemFunctions::GetInventorySize(unsigned short pid) noexcept
|
|
||||||
{
|
|
||||||
Player *player;
|
|
||||||
GET_PLAYER(pid, player, 0);
|
|
||||||
|
|
||||||
return player->inventory.count;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ItemFunctions::SendEquipment(unsigned short pid) noexcept
|
void ItemFunctions::SendEquipment(unsigned short pid) noexcept
|
||||||
{
|
{
|
||||||
Player *player;
|
Player *player;
|
||||||
|
|
|
@ -6,40 +6,50 @@
|
||||||
#define OPENMW_ITEMS_HPP
|
#define OPENMW_ITEMS_HPP
|
||||||
|
|
||||||
#define ITEMAPI \
|
#define ITEMAPI \
|
||||||
{"AddItem", ItemFunctions::AddItem},\
|
{"GetEquipmentSize", ItemFunctions::GetEquipmentSize},\
|
||||||
{"RemoveItem", ItemFunctions::RemoveItem},\
|
{"GetInventorySize", ItemFunctions::GetInventorySize},\
|
||||||
{"GetItemCount", ItemFunctions::GetItemCount2},\
|
|
||||||
\
|
\
|
||||||
{"EquipItem", ItemFunctions::EquipItem},\
|
{"EquipItem", ItemFunctions::EquipItem},\
|
||||||
{"UnequipItem", ItemFunctions::UnequipItem},\
|
{"UnequipItem", ItemFunctions::UnequipItem},\
|
||||||
{"GetEquipmentSize", ItemFunctions::GetEquipmentSize},\
|
|
||||||
{"HasItemEquipped", ItemFunctions::HasItemEquipped},\
|
|
||||||
\
|
\
|
||||||
{"GetItemSlot", ItemFunctions::GetItemSlot},\
|
{"AddItem", ItemFunctions::AddItem}, \
|
||||||
{"GetItemName", ItemFunctions::GetItemName},\
|
{"RemoveItem", ItemFunctions::RemoveItem}, \
|
||||||
{"GetItemHealth", ItemFunctions::GetItemHealth},\
|
|
||||||
{"GetInventorySize", ItemFunctions::GetInventorySize},\
|
|
||||||
\
|
\
|
||||||
{"SendEquipment", ItemFunctions::SendEquipment},\
|
{"HasItemEquipped", ItemFunctions::HasItemEquipped},\
|
||||||
{"SendInventory", ItemFunctions::SendInventory}
|
\
|
||||||
|
{"GetEquipmentItemId", ItemFunctions::GetEquipmentItemId},\
|
||||||
|
{"GetEquipmentItemCount", ItemFunctions::GetEquipmentItemCount},\
|
||||||
|
{"GetEquipmentItemHealth", ItemFunctions::GetEquipmentItemHealth},\
|
||||||
|
\
|
||||||
|
{"GetInventoryItemId", ItemFunctions::GetInventoryItemId},\
|
||||||
|
{"GetInventoryItemCount", ItemFunctions::GetInventoryItemCount},\
|
||||||
|
{"GetInventoryItemHealth", ItemFunctions::GetInventoryItemHealth},\
|
||||||
|
\
|
||||||
|
{"SendEquipment", ItemFunctions::SendEquipment},\
|
||||||
|
{"SendInventory", ItemFunctions::SendInventory}
|
||||||
|
|
||||||
class ItemFunctions
|
class ItemFunctions
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
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 int GetEquipmentSize() noexcept;
|
||||||
static void GetItemCount(unsigned short pid, const char* itemName) noexcept;
|
static unsigned int GetInventorySize(unsigned short pid) noexcept;
|
||||||
|
|
||||||
static void EquipItem(unsigned short pid, unsigned short slot, const char* itemName, unsigned int count, int health) noexcept;
|
static void EquipItem(unsigned short pid, unsigned short slot, const char* itemName, unsigned int count, int health) noexcept;
|
||||||
static void UnequipItem(unsigned short pid, unsigned short slot) noexcept;
|
static void UnequipItem(unsigned short pid, unsigned short slot) noexcept;
|
||||||
static int GetEquipmentSize() 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 bool HasItemEquipped(unsigned short pid, const char* itemName);
|
static bool HasItemEquipped(unsigned short pid, const char* itemName);
|
||||||
|
|
||||||
static const char *GetItemSlot(unsigned short pid, unsigned short slot) noexcept;
|
static const char *GetEquipmentItemId(unsigned short pid, unsigned short slot) noexcept;
|
||||||
static const char *GetItemName(unsigned short pid, unsigned int i) noexcept;
|
static int GetEquipmentItemCount(unsigned short pid, unsigned short slot) noexcept;
|
||||||
static int GetItemCount2(unsigned short pid, unsigned int i) noexcept;
|
static int GetEquipmentItemHealth(unsigned short pid, unsigned short slot) noexcept;
|
||||||
static int GetItemHealth(unsigned short pid, unsigned int i) noexcept;
|
|
||||||
static unsigned int GetInventorySize(unsigned short pid) noexcept;
|
static const char *GetInventoryItemId(unsigned short pid, unsigned int i) noexcept;
|
||||||
|
static int GetInventoryItemCount(unsigned short pid, unsigned int i) noexcept;
|
||||||
|
static int GetInventoryItemHealth(unsigned short pid, unsigned int i) noexcept;
|
||||||
|
|
||||||
static void SendEquipment(unsigned short pid) noexcept;
|
static void SendEquipment(unsigned short pid) noexcept;
|
||||||
static void SendInventory(unsigned short pid) noexcept;
|
static void SendInventory(unsigned short pid) noexcept;
|
||||||
|
|
Loading…
Reference in a new issue