forked from mirror/openmw-tes3mp
6a3fbf4e98
Previously, there was a confusing separation between script functions that had a "broadcast" argument and script functions that had a "toOthers" argument. Those with broadcast sent the packet to all players on the server when broadcast was true. Those with toOthers sent the packet to all players other than the packet's attached player. The former was based on the pattern of the original SendMessage() script function. The latter more closely resembled RakNet's own broadcast argument as seen here: https://github.com/TES3MP/CrabNet/blob/master/include/raknet/RakPeer.h#L219 This commit makes it so all sending functions have a sendToOtherPlayers argument that is false by default and a sendToAttachedPlayer that is true by default. This should simultaneously allow sending to be more intuitive, while not breaking previous existing scripts to a significant degree. Additionally, this commit also reduces some code repetition for all instances of packet-fetching in script functions.
225 lines
8.2 KiB
C++
225 lines
8.2 KiB
C++
//
|
|
// Created by koncord on 30.08.16.
|
|
//
|
|
|
|
#ifndef OPENMW_ITEMAPI_HPP
|
|
#define OPENMW_ITEMAPI_HPP
|
|
|
|
#define ITEMAPI \
|
|
{"InitializeInventoryChanges", ItemFunctions::InitializeInventoryChanges},\
|
|
\
|
|
{"GetEquipmentSize", ItemFunctions::GetEquipmentSize},\
|
|
{"GetInventoryChangesSize", ItemFunctions::GetInventoryChangesSize},\
|
|
\
|
|
{"EquipItem", ItemFunctions::EquipItem},\
|
|
{"UnequipItem", ItemFunctions::UnequipItem},\
|
|
\
|
|
{"AddItem", ItemFunctions::AddItem},\
|
|
{"RemoveItem", ItemFunctions::RemoveItem},\
|
|
\
|
|
{"HasItemEquipped", ItemFunctions::HasItemEquipped},\
|
|
\
|
|
{"GetEquipmentItemRefId", ItemFunctions::GetEquipmentItemRefId},\
|
|
{"GetEquipmentItemCount", ItemFunctions::GetEquipmentItemCount},\
|
|
{"GetEquipmentItemCharge", ItemFunctions::GetEquipmentItemCharge},\
|
|
{"GetEquipmentItemEnchantmentCharge", ItemFunctions::GetEquipmentItemEnchantmentCharge},\
|
|
\
|
|
{"GetInventoryItemRefId", ItemFunctions::GetInventoryItemRefId},\
|
|
{"GetInventoryItemCount", ItemFunctions::GetInventoryItemCount},\
|
|
{"GetInventoryItemCharge", ItemFunctions::GetInventoryItemCharge},\
|
|
{"GetInventoryItemEnchantmentCharge", ItemFunctions::GetInventoryItemEnchantmentCharge},\
|
|
\
|
|
{"SendEquipment", ItemFunctions::SendEquipment},\
|
|
{"SendInventoryChanges", ItemFunctions::SendInventoryChanges}
|
|
|
|
class ItemFunctions
|
|
{
|
|
public:
|
|
|
|
/**
|
|
* \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
|
|
*/
|
|
static void InitializeInventoryChanges(unsigned short pid) noexcept;
|
|
|
|
/**
|
|
* \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.
|
|
*/
|
|
static int GetEquipmentSize() noexcept;
|
|
|
|
/**
|
|
* \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.
|
|
*/
|
|
static unsigned int GetInventoryChangesSize(unsigned short pid) noexcept;
|
|
|
|
/**
|
|
* \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
|
|
*/
|
|
static void EquipItem(unsigned short pid, unsigned short slot, const char* refId, unsigned int count, int charge, double enchantmentCharge = -1) noexcept;
|
|
|
|
/**
|
|
* \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
|
|
*/
|
|
static void UnequipItem(unsigned short pid, unsigned short slot) noexcept;
|
|
|
|
/**
|
|
* \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
|
|
*/
|
|
static void AddItem(unsigned short pid, const char* refId, unsigned int count, int charge, double enchantmentCharge = -1) noexcept;
|
|
|
|
/**
|
|
* \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
|
|
*/
|
|
static void RemoveItem(unsigned short pid, const char* refId, unsigned short count) noexcept;
|
|
|
|
/**
|
|
* \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.
|
|
*/
|
|
static bool HasItemEquipped(unsigned short pid, const char* refId);
|
|
|
|
/**
|
|
* \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.
|
|
*/
|
|
static const char *GetEquipmentItemRefId(unsigned short pid, unsigned short slot) noexcept;
|
|
|
|
/**
|
|
* \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.
|
|
*/
|
|
static int GetEquipmentItemCount(unsigned short pid, unsigned short slot) noexcept;
|
|
|
|
/**
|
|
* \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.
|
|
*/
|
|
static int GetEquipmentItemCharge(unsigned short pid, unsigned short slot) noexcept;
|
|
|
|
/**
|
|
* \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.
|
|
*/
|
|
static double GetEquipmentItemEnchantmentCharge(unsigned short pid, unsigned short slot) noexcept;
|
|
|
|
/**
|
|
* \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.
|
|
*/
|
|
static const char *GetInventoryItemRefId(unsigned short pid, unsigned int i) noexcept;
|
|
|
|
/**
|
|
* \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.
|
|
*/
|
|
static int GetInventoryItemCount(unsigned short pid, unsigned int i) noexcept;
|
|
|
|
/**
|
|
* \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.
|
|
*/
|
|
static int GetInventoryItemCharge(unsigned short pid, unsigned int i) noexcept;
|
|
|
|
/**
|
|
* \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.
|
|
*/
|
|
static double GetInventoryItemEnchantmentCharge(unsigned short pid, unsigned int i) noexcept;
|
|
|
|
/**
|
|
* \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
|
|
*/
|
|
static void SendEquipment(unsigned short pid) noexcept;
|
|
|
|
/**
|
|
* \brief Send a PlayerInventory packet with a player's recorded inventory changes.
|
|
*
|
|
* \param pid The player ID whose inventory changes should be used.
|
|
* \param sendToOtherPlayers Whether this packet should be sent to players other than the
|
|
* player attached to the packet (false by default).
|
|
* \param sendToAttachedPlayer Whether the packet should be sent to the player attached
|
|
* to the packet (true by default).
|
|
* \return void
|
|
*/
|
|
static void SendInventoryChanges(unsigned short pid, bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept;
|
|
private:
|
|
|
|
};
|
|
|
|
#endif //OPENMW_ITEMAPI_HPP
|