2017-04-09 09:28:38 +00:00
|
|
|
#ifndef OPENMW_ITEMAPI_HPP
|
|
|
|
#define OPENMW_ITEMAPI_HPP
|
2016-08-30 04:19:49 +00:00
|
|
|
|
|
|
|
#define ITEMAPI \
|
2018-10-02 23:26:47 +00:00
|
|
|
{"ClearInventoryChanges", ItemFunctions::ClearInventoryChanges},\
|
2016-09-30 09:30:05 +00:00
|
|
|
\
|
2017-12-23 11:16:38 +00:00
|
|
|
{"GetEquipmentSize", ItemFunctions::GetEquipmentSize},\
|
|
|
|
{"GetInventoryChangesSize", ItemFunctions::GetInventoryChangesSize},\
|
2018-08-21 07:06:40 +00:00
|
|
|
{"GetInventoryChangesAction", ItemFunctions::GetInventoryChangesAction},\
|
2016-11-17 21:07:29 +00:00
|
|
|
\
|
2018-10-01 15:29:50 +00:00
|
|
|
{"SetInventoryChangesAction", ItemFunctions::SetInventoryChangesAction},\
|
|
|
|
\
|
2017-12-23 11:16:38 +00:00
|
|
|
{"EquipItem", ItemFunctions::EquipItem},\
|
|
|
|
{"UnequipItem", ItemFunctions::UnequipItem},\
|
2016-11-17 21:07:29 +00:00
|
|
|
\
|
2018-10-01 15:29:50 +00:00
|
|
|
{"AddItemChange", ItemFunctions::AddItemChange},\
|
2016-11-17 22:52:17 +00:00
|
|
|
\
|
2017-12-23 11:16:38 +00:00
|
|
|
{"HasItemEquipped", ItemFunctions::HasItemEquipped},\
|
2016-11-17 22:52:17 +00:00
|
|
|
\
|
2017-12-23 11:16:38 +00:00
|
|
|
{"GetEquipmentItemRefId", ItemFunctions::GetEquipmentItemRefId},\
|
|
|
|
{"GetEquipmentItemCount", ItemFunctions::GetEquipmentItemCount},\
|
|
|
|
{"GetEquipmentItemCharge", ItemFunctions::GetEquipmentItemCharge},\
|
|
|
|
{"GetEquipmentItemEnchantmentCharge", ItemFunctions::GetEquipmentItemEnchantmentCharge},\
|
2016-11-17 22:52:17 +00:00
|
|
|
\
|
2017-12-23 11:16:38 +00:00
|
|
|
{"GetInventoryItemRefId", ItemFunctions::GetInventoryItemRefId},\
|
|
|
|
{"GetInventoryItemCount", ItemFunctions::GetInventoryItemCount},\
|
|
|
|
{"GetInventoryItemCharge", ItemFunctions::GetInventoryItemCharge},\
|
|
|
|
{"GetInventoryItemEnchantmentCharge", ItemFunctions::GetInventoryItemEnchantmentCharge},\
|
2018-07-26 19:37:04 +00:00
|
|
|
{"GetInventoryItemSoul", ItemFunctions::GetInventoryItemSoul},\
|
2017-07-07 06:25:48 +00:00
|
|
|
\
|
2018-08-09 15:25:20 +00:00
|
|
|
{"GetUsedItemRefId", ItemFunctions::GetUsedItemRefId},\
|
|
|
|
{"GetUsedItemCount", ItemFunctions::GetUsedItemCount},\
|
|
|
|
{"GetUsedItemCharge", ItemFunctions::GetUsedItemCharge},\
|
|
|
|
{"GetUsedItemEnchantmentCharge", ItemFunctions::GetUsedItemEnchantmentCharge},\
|
|
|
|
{"GetUsedItemSoul", ItemFunctions::GetUsedItemSoul},\
|
|
|
|
\
|
2017-12-23 11:16:38 +00:00
|
|
|
{"SendEquipment", ItemFunctions::SendEquipment},\
|
2018-08-09 15:25:20 +00:00
|
|
|
{"SendInventoryChanges", ItemFunctions::SendInventoryChanges},\
|
2018-10-01 15:29:50 +00:00
|
|
|
{"SendItemUse", ItemFunctions::SendItemUse},\
|
|
|
|
\
|
2018-10-02 23:26:47 +00:00
|
|
|
{"InitializeInventoryChanges", ItemFunctions::InitializeInventoryChanges},\
|
2018-10-01 15:29:50 +00:00
|
|
|
{"AddItem", ItemFunctions::AddItem}
|
2016-08-30 04:19:49 +00:00
|
|
|
|
|
|
|
class ItemFunctions
|
|
|
|
{
|
|
|
|
public:
|
2016-11-17 22:52:17 +00:00
|
|
|
|
2018-04-18 08:02:18 +00:00
|
|
|
/**
|
|
|
|
* \brief Clear the last recorded inventory changes for a player.
|
|
|
|
*
|
|
|
|
* This is used to initialize the sending of new PlayerInventory packets.
|
|
|
|
*
|
|
|
|
* \param pid The player ID whose inventory changes should be used.
|
|
|
|
* \return void
|
|
|
|
*/
|
2018-10-02 23:26:47 +00:00
|
|
|
static void ClearInventoryChanges(unsigned short pid) noexcept;
|
2017-07-07 06:25:48 +00:00
|
|
|
|
2018-04-18 08:02:18 +00:00
|
|
|
/**
|
|
|
|
* \brief Get the number of slots used for equipment.
|
|
|
|
*
|
|
|
|
* The number is 19 before any dehardcoding is done in OpenMW.
|
|
|
|
*
|
|
|
|
* \return The number of slots.
|
|
|
|
*/
|
2016-11-17 22:52:17 +00:00
|
|
|
static int GetEquipmentSize() noexcept;
|
2018-04-18 08:02:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get the number of indexes in a player's latest inventory changes.
|
|
|
|
*
|
|
|
|
* \param pid The player ID whose inventory changes should be used.
|
|
|
|
* \return The number of indexes.
|
|
|
|
*/
|
2017-01-20 10:43:05 +00:00
|
|
|
static unsigned int GetInventoryChangesSize(unsigned short pid) noexcept;
|
2016-11-17 21:07:29 +00:00
|
|
|
|
2018-08-21 07:06:40 +00:00
|
|
|
/**
|
|
|
|
* \brief Get the action type used in a player's latest inventory changes.
|
|
|
|
*
|
|
|
|
* \param pid The player ID whose inventory changes should be used.
|
|
|
|
* \return The action type (0 for SET, 1 for ADD, 2 for REMOVE).
|
|
|
|
*/
|
|
|
|
static unsigned int GetInventoryChangesAction(unsigned short pid) noexcept;
|
|
|
|
|
2018-10-01 15:29:50 +00:00
|
|
|
/**
|
|
|
|
* \brief Set the action type in a player's inventory changes.
|
|
|
|
*
|
|
|
|
* \param pid The player ID whose inventory changes should be used.
|
|
|
|
* \param action The action (0 for SET, 1 for ADD, 2 for REMOVE).
|
|
|
|
* \return void
|
|
|
|
*/
|
|
|
|
static void SetInventoryChangesAction(unsigned short pid, unsigned char action) noexcept;
|
|
|
|
|
2018-04-18 08:02:18 +00:00
|
|
|
/**
|
|
|
|
* \brief Equip an item in a certain slot of the equipment of a player.
|
|
|
|
*
|
|
|
|
* \param pid The player ID.
|
|
|
|
* \param slot The equipment slot.
|
|
|
|
* \param refId The refId of the item.
|
|
|
|
* \param count The count of the item.
|
|
|
|
* \param charge The charge of the item.
|
|
|
|
* \param enchantmentCharge The enchantment charge of the item.
|
|
|
|
* \return void
|
|
|
|
*/
|
2018-10-01 15:29:50 +00:00
|
|
|
static void EquipItem(unsigned short pid, unsigned short slot, const char* refId, unsigned int count, int charge,
|
|
|
|
double enchantmentCharge = -1) noexcept;
|
2018-04-18 08:02:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Unequip the item in a certain slot of the equipment of a player.
|
|
|
|
*
|
|
|
|
* \param pid The player ID.
|
|
|
|
* \param slot The equipment slot.
|
|
|
|
* \return void
|
|
|
|
*/
|
2016-11-16 17:28:22 +00:00
|
|
|
static void UnequipItem(unsigned short pid, unsigned short slot) noexcept;
|
2016-11-17 22:52:17 +00:00
|
|
|
|
2018-04-18 08:02:18 +00:00
|
|
|
/**
|
2018-10-01 15:29:50 +00:00
|
|
|
* \brief Add an item change to a player's inventory changes.
|
2018-04-18 08:02:18 +00:00
|
|
|
*
|
|
|
|
* \param pid The player ID.
|
|
|
|
* \param refId The refId of the item.
|
|
|
|
* \param count The count of the item.
|
|
|
|
* \param charge The charge of the item.
|
|
|
|
* \param enchantmentCharge The enchantment charge of the item.
|
2018-07-26 19:37:04 +00:00
|
|
|
* \param soul The soul of the item.
|
2018-04-18 08:02:18 +00:00
|
|
|
* \return void
|
|
|
|
*/
|
2018-10-01 15:29:50 +00:00
|
|
|
static void AddItemChange(unsigned short pid, const char* refId, unsigned int count, int charge,
|
2018-07-26 19:37:04 +00:00
|
|
|
double enchantmentCharge, const char* soul) noexcept;
|
2018-04-18 08:02:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Check whether a player has equipped an item with a certain refId in any slot.
|
|
|
|
*
|
|
|
|
* \param pid The player ID.
|
|
|
|
* \param refId The refId of the item.
|
|
|
|
* \return Whether the player has the item equipped.
|
|
|
|
*/
|
2017-02-07 11:50:28 +00:00
|
|
|
static bool HasItemEquipped(unsigned short pid, const char* refId);
|
2016-09-30 09:30:05 +00:00
|
|
|
|
2018-04-18 08:02:18 +00:00
|
|
|
/**
|
|
|
|
* \brief Get the refId of the item in a certain slot of the equipment of a player.
|
|
|
|
*
|
|
|
|
* \param pid The player ID.
|
|
|
|
* \param slot The slot of the equipment item.
|
|
|
|
* \return The refId.
|
|
|
|
*/
|
2017-02-07 11:50:28 +00:00
|
|
|
static const char *GetEquipmentItemRefId(unsigned short pid, unsigned short slot) noexcept;
|
2018-04-18 08:02:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get the count of the item in a certain slot of the equipment of a player.
|
|
|
|
*
|
|
|
|
* \param pid The player ID.
|
|
|
|
* \param slot The slot of the equipment item.
|
|
|
|
* \return The item count.
|
|
|
|
*/
|
2016-11-17 22:52:17 +00:00
|
|
|
static int GetEquipmentItemCount(unsigned short pid, unsigned short slot) noexcept;
|
2018-04-18 08:02:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get the charge of the item in a certain slot of the equipment of a player.
|
|
|
|
*
|
|
|
|
* \param pid The player ID.
|
|
|
|
* \param slot The slot of the equipment item.
|
|
|
|
* \return The charge.
|
|
|
|
*/
|
2017-02-05 12:56:27 +00:00
|
|
|
static int GetEquipmentItemCharge(unsigned short pid, unsigned short slot) noexcept;
|
2018-04-18 08:02:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get the enchantment charge of the item in a certain slot of the equipment of
|
|
|
|
* a player.
|
|
|
|
*
|
|
|
|
* \param pid The player ID.
|
|
|
|
* \param slot The slot of the equipment item.
|
|
|
|
* \return The enchantment charge.
|
|
|
|
*/
|
2018-01-17 06:09:57 +00:00
|
|
|
static double GetEquipmentItemEnchantmentCharge(unsigned short pid, unsigned short slot) noexcept;
|
2016-11-17 22:52:17 +00:00
|
|
|
|
2018-04-18 08:02:18 +00:00
|
|
|
/**
|
|
|
|
* \brief Get the refId of the item at a certain index in a player's latest inventory
|
|
|
|
* changes.
|
|
|
|
*
|
|
|
|
* \param pid The player ID whose inventory changes should be used.
|
2018-07-24 17:14:51 +00:00
|
|
|
* \param index The index of the inventory item.
|
2018-04-18 08:02:18 +00:00
|
|
|
* \return The refId.
|
|
|
|
*/
|
2018-07-24 17:14:51 +00:00
|
|
|
static const char *GetInventoryItemRefId(unsigned short pid, unsigned int index) noexcept;
|
2018-04-18 08:02:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get the count of the item at a certain index in a player's latest inventory
|
|
|
|
* changes.
|
|
|
|
*
|
|
|
|
* \param pid The player ID whose inventory changes should be used.
|
2018-07-24 17:14:51 +00:00
|
|
|
* \param index The index of the inventory item.
|
2018-04-18 08:02:18 +00:00
|
|
|
* \return The item count.
|
|
|
|
*/
|
2018-07-24 17:14:51 +00:00
|
|
|
static int GetInventoryItemCount(unsigned short pid, unsigned int index) noexcept;
|
2018-04-18 08:02:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get the charge of the item at a certain index in a player's latest inventory
|
|
|
|
* changes.
|
|
|
|
*
|
|
|
|
* \param pid The player ID whose inventory changes should be used.
|
2018-07-24 17:14:51 +00:00
|
|
|
* \param index The index of the inventory item.
|
2018-04-18 08:02:18 +00:00
|
|
|
* \return The charge.
|
|
|
|
*/
|
2018-07-24 17:14:51 +00:00
|
|
|
static int GetInventoryItemCharge(unsigned short pid, unsigned int index) noexcept;
|
2018-04-18 08:02:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get the enchantment charge of the item at a certain index in a player's
|
|
|
|
* latest inventory changes.
|
|
|
|
*
|
|
|
|
* \param pid The player ID whose inventory changes should be used.
|
2018-07-24 17:14:51 +00:00
|
|
|
* \param index The index of the inventory item.
|
2018-04-18 08:02:18 +00:00
|
|
|
* \return The enchantment charge.
|
|
|
|
*/
|
2018-07-24 17:14:51 +00:00
|
|
|
static double GetInventoryItemEnchantmentCharge(unsigned short pid, unsigned int index) noexcept;
|
2018-07-26 19:37:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get the soul of the item at a certain index in a player's latest inventory
|
|
|
|
* changes.
|
|
|
|
*
|
|
|
|
* \param pid The player ID whose inventory changes should be used.
|
|
|
|
* \param index The index of the inventory item.
|
|
|
|
* \return The soul.
|
|
|
|
*/
|
|
|
|
static const char *GetInventoryItemSoul(unsigned short pid, unsigned int index) 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
|
|
|
|
2018-08-09 15:25:20 +00:00
|
|
|
/**
|
|
|
|
* \brief Get the refId of the item last used by a player.
|
|
|
|
*
|
|
|
|
* \param pid The player ID.
|
|
|
|
* \return The refId.
|
|
|
|
*/
|
|
|
|
static const char *GetUsedItemRefId(unsigned short pid) noexcept;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get the count of the item last used by a player.
|
|
|
|
*
|
|
|
|
* \param pid The player ID.
|
|
|
|
* \return The item count.
|
|
|
|
*/
|
|
|
|
static int GetUsedItemCount(unsigned short pid) noexcept;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get the charge of the item last used by a player.
|
|
|
|
*
|
|
|
|
* \param pid The player ID.
|
|
|
|
* \return The charge.
|
|
|
|
*/
|
|
|
|
static int GetUsedItemCharge(unsigned short pid) noexcept;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get the enchantment charge of the item last used by a player.
|
|
|
|
*
|
|
|
|
* \param pid The player ID.
|
|
|
|
* \return The enchantment charge.
|
|
|
|
*/
|
|
|
|
static double GetUsedItemEnchantmentCharge(unsigned short pid) noexcept;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get the soul of the item last used by a player.
|
|
|
|
*
|
|
|
|
* \param pid The player ID.
|
|
|
|
* \return The soul.
|
|
|
|
*/
|
|
|
|
static const char *GetUsedItemSoul(unsigned short pid) noexcept;
|
|
|
|
|
2018-04-18 08:02:18 +00:00
|
|
|
/**
|
|
|
|
* \brief Send a PlayerEquipment packet with a player's equipment.
|
|
|
|
*
|
|
|
|
* It is always sent to all players.
|
|
|
|
*
|
|
|
|
* \param pid The player ID whose equipment should be sent.
|
|
|
|
* \return void
|
|
|
|
*/
|
2016-11-16 17:28:22 +00:00
|
|
|
static void SendEquipment(unsigned short pid) noexcept;
|
2018-04-18 08:02:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Send a PlayerInventory packet with a player's recorded inventory changes.
|
|
|
|
*
|
|
|
|
* \param pid The player ID whose inventory changes should be used.
|
2018-07-07 15:29:31 +00:00
|
|
|
* \param sendToOtherPlayers Whether this packet should be sent to players other than the
|
|
|
|
* player attached to the packet (false by default).
|
2018-07-07 17:16:36 +00:00
|
|
|
* \param skipAttachedPlayer Whether the packet should skip being sent to the player attached
|
|
|
|
* to the packet (false by default).
|
2018-04-18 08:02:18 +00:00
|
|
|
* \return void
|
|
|
|
*/
|
2018-07-07 17:08:59 +00:00
|
|
|
static void SendInventoryChanges(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept;
|
2018-08-09 15:25:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Send a PlayerItemUse causing a player to use their recorded usedItem.
|
|
|
|
*
|
|
|
|
* \param pid The player ID affected.
|
|
|
|
* \return void
|
|
|
|
*/
|
|
|
|
static void SendItemUse(unsigned short pid) noexcept;
|
|
|
|
|
2018-10-01 15:29:50 +00:00
|
|
|
// All methods below are deprecated versions of methods from above
|
|
|
|
|
2018-10-02 23:26:47 +00:00
|
|
|
static void InitializeInventoryChanges(unsigned short pid) noexcept;
|
|
|
|
|
2018-10-01 15:29:50 +00:00
|
|
|
static void AddItem(unsigned short pid, const char* refId, unsigned int count, int charge,
|
|
|
|
double enchantmentCharge, const char* soul) 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
|
|
|
private:
|
|
|
|
|
2016-08-30 04:19:49 +00:00
|
|
|
};
|
|
|
|
|
2017-04-09 09:28:38 +00:00
|
|
|
#endif //OPENMW_ITEMAPI_HPP
|