diff --git a/apps/openmw-mp/Script/Functions/Items.cpp b/apps/openmw-mp/Script/Functions/Items.cpp index dd3d7be2d..5d987cee3 100644 --- a/apps/openmw-mp/Script/Functions/Items.cpp +++ b/apps/openmw-mp/Script/Functions/Items.cpp @@ -11,18 +11,17 @@ 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; - GET_PLAYER(pid, player,); + GET_PLAYER(pid, player, 0); - Item item; - item.refid = itemName; - item.count = count; - item.health = health; - - player->inventorySendBuffer.items.push_back(item); - player->inventorySendBuffer.action = Inventory::ADDITEM; + return player->inventory.count; } 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); } -int ItemFunctions::GetEquipmentSize() noexcept -{ - return MWWorld::InventoryStore::Slots; -} - -const char *ItemFunctions::GetItemSlot(unsigned short pid, unsigned short slot) noexcept +void ItemFunctions::AddItem(unsigned short pid, const char* itemName, unsigned int count, int health) noexcept { 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 *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; + player->inventorySendBuffer.items.push_back(item); + player->inventorySendBuffer.action = Inventory::ADDITEM; } void ItemFunctions::RemoveItem(unsigned short pid, const char* itemName, unsigned short count) noexcept { Player *player; - GET_PLAYER(pid, player,); + GET_PLAYER(pid, player, ); Item item; 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.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; GET_PLAYER(pid, player, ""); + if (i >= player->inventory.count) + return "invalid"; + 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; 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; } -int ItemFunctions::GetItemHealth(unsigned short pid, unsigned int i) noexcept +int ItemFunctions::GetInventoryItemHealth(unsigned short pid, unsigned int i) noexcept { Player *player; 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; } -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 { Player *player; diff --git a/apps/openmw-mp/Script/Functions/Items.hpp b/apps/openmw-mp/Script/Functions/Items.hpp index 97d48b972..eebe3b9a3 100644 --- a/apps/openmw-mp/Script/Functions/Items.hpp +++ b/apps/openmw-mp/Script/Functions/Items.hpp @@ -6,40 +6,50 @@ #define OPENMW_ITEMS_HPP #define ITEMAPI \ - {"AddItem", ItemFunctions::AddItem},\ - {"RemoveItem", ItemFunctions::RemoveItem},\ - {"GetItemCount", ItemFunctions::GetItemCount2},\ + {"GetEquipmentSize", ItemFunctions::GetEquipmentSize},\ + {"GetInventorySize", ItemFunctions::GetInventorySize},\ \ - {"EquipItem", ItemFunctions::EquipItem},\ - {"UnequipItem", ItemFunctions::UnequipItem},\ - {"GetEquipmentSize", ItemFunctions::GetEquipmentSize},\ - {"HasItemEquipped", ItemFunctions::HasItemEquipped},\ + {"EquipItem", ItemFunctions::EquipItem},\ + {"UnequipItem", ItemFunctions::UnequipItem},\ \ - {"GetItemSlot", ItemFunctions::GetItemSlot},\ - {"GetItemName", ItemFunctions::GetItemName},\ - {"GetItemHealth", ItemFunctions::GetItemHealth},\ - {"GetInventorySize", ItemFunctions::GetInventorySize},\ + {"AddItem", ItemFunctions::AddItem}, \ + {"RemoveItem", ItemFunctions::RemoveItem}, \ \ - {"SendEquipment", ItemFunctions::SendEquipment},\ - {"SendInventory", ItemFunctions::SendInventory} + {"HasItemEquipped", ItemFunctions::HasItemEquipped},\ + \ + {"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 { 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 void GetItemCount(unsigned short pid, const char* itemName) noexcept; + + static int GetEquipmentSize() 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 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 const char *GetItemSlot(unsigned short pid, unsigned short slot) noexcept; - static const char *GetItemName(unsigned short pid, unsigned int i) noexcept; - static int GetItemCount2(unsigned short pid, unsigned int i) noexcept; - static int GetItemHealth(unsigned short pid, unsigned int i) noexcept; - static unsigned int GetInventorySize(unsigned short pid) noexcept; + static const char *GetEquipmentItemId(unsigned short pid, unsigned short slot) noexcept; + static int GetEquipmentItemCount(unsigned short pid, unsigned short slot) noexcept; + static int GetEquipmentItemHealth(unsigned short pid, unsigned short slot) 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 SendInventory(unsigned short pid) noexcept;