2016-08-30 04:19:49 +00:00
|
|
|
//
|
|
|
|
// Created by koncord on 30.08.16.
|
|
|
|
//
|
|
|
|
|
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 \
|
2017-12-23 11:16:38 +00:00
|
|
|
{"InitializeInventoryChanges", ItemFunctions::InitializeInventoryChanges},\
|
2016-09-30 09:30:05 +00:00
|
|
|
\
|
2017-12-23 11:16:38 +00:00
|
|
|
{"GetEquipmentSize", ItemFunctions::GetEquipmentSize},\
|
|
|
|
{"GetInventoryChangesSize", ItemFunctions::GetInventoryChangesSize},\
|
2016-11-17 21:07:29 +00:00
|
|
|
\
|
2017-12-23 11:16:38 +00:00
|
|
|
{"EquipItem", ItemFunctions::EquipItem},\
|
|
|
|
{"UnequipItem", ItemFunctions::UnequipItem},\
|
2016-11-17 21:07:29 +00:00
|
|
|
\
|
2017-12-23 11:16:38 +00:00
|
|
|
{"AddItem", ItemFunctions::AddItem},\
|
|
|
|
{"RemoveItem", ItemFunctions::RemoveItem},\
|
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},\
|
2017-07-07 06:25:48 +00:00
|
|
|
\
|
2017-12-23 11:16:38 +00:00
|
|
|
{"SendEquipment", ItemFunctions::SendEquipment},\
|
|
|
|
{"SendInventoryChanges", ItemFunctions::SendInventoryChanges}
|
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
|
|
|
|
*/
|
2017-07-07 06:25:48 +00:00
|
|
|
static void InitializeInventoryChanges(unsigned short pid) noexcept;
|
|
|
|
|
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-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-01-17 06:09:57 +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
|
|
|
/**
|
|
|
|
* \brief Add an item to a player's inventory.
|
|
|
|
*
|
|
|
|
* Note: This will set the ADD action for all of the player's current inventory changes.
|
|
|
|
*
|
|
|
|
* \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.
|
|
|
|
* \return void
|
|
|
|
*/
|
2018-01-17 06:09:57 +00:00
|
|
|
static void AddItem(unsigned short pid, const char* refId, unsigned int count, int charge, double enchantmentCharge = -1) noexcept;
|
2018-04-18 08:02:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Remove an item from a player's inventory.
|
|
|
|
*
|
|
|
|
* Note: This will set the REMOVE action for all of the player's current inventory changes.
|
|
|
|
*
|
|
|
|
* \param pid The player ID.
|
|
|
|
* \param refId The refId of the item.
|
|
|
|
* \param count The count of the item.
|
|
|
|
* \return void
|
|
|
|
*/
|
2017-02-07 11:50:28 +00:00
|
|
|
static void RemoveItem(unsigned short pid, const char* refId, unsigned short count) noexcept;
|
2016-11-17 22:52:17 +00:00
|
|
|
|
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.
|
|
|
|
* \param i The index of the inventory item.
|
|
|
|
* \return The refId.
|
|
|
|
*/
|
2017-02-07 11:50:28 +00:00
|
|
|
static const char *GetInventoryItemRefId(unsigned short pid, unsigned int i) 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.
|
|
|
|
* \param i The index of the inventory item.
|
|
|
|
* \return The item count.
|
|
|
|
*/
|
2016-11-17 22:52:17 +00:00
|
|
|
static int GetInventoryItemCount(unsigned short pid, unsigned int i) 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.
|
|
|
|
* \param i The index of the inventory item.
|
|
|
|
* \return The charge.
|
|
|
|
*/
|
2017-02-05 12:56:27 +00:00
|
|
|
static int GetInventoryItemCharge(unsigned short pid, unsigned int i) 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.
|
|
|
|
* \param i The index of the inventory item.
|
|
|
|
* \return The enchantment charge.
|
|
|
|
*/
|
2018-01-17 06:09:57 +00:00
|
|
|
static double GetInventoryItemEnchantmentCharge(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
|
|
|
|
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;
|
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
|