[Server] Make inventory script functions consistent with others

Functions that add elements to a vector should not change the action. This fixes the last remaining oddity in Koncord's original implementation of inventory sync.
pull/475/head
David Cernat 6 years ago
parent 8c7e06293f
commit c79660f721

@ -15,7 +15,6 @@ void ItemFunctions::InitializeInventoryChanges(unsigned short pid) noexcept
GET_PLAYER(pid, player, );
player->inventoryChanges.items.clear();
player->inventoryChanges.action = InventoryChanges::SET;
}
int ItemFunctions::GetEquipmentSize() noexcept
@ -39,6 +38,14 @@ unsigned int ItemFunctions::GetInventoryChangesAction(unsigned short pid) noexce
return player->inventoryChanges.action;
}
void ItemFunctions::SetInventoryChangesAction(unsigned short pid, unsigned char action) noexcept
{
Player *player;
GET_PLAYER(pid, player, );
player->inventoryChanges.action = action;
}
void ItemFunctions::EquipItem(unsigned short pid, unsigned short slot, const char *refId, unsigned int count,
int charge, double enchantmentCharge) noexcept
{
@ -62,7 +69,7 @@ void ItemFunctions::UnequipItem(unsigned short pid, unsigned short slot) noexcep
ItemFunctions::EquipItem(pid, slot, "", 0, -1, -1);
}
void ItemFunctions::AddItem(unsigned short pid, const char* refId, unsigned int count, int charge,
void ItemFunctions::AddItemChange(unsigned short pid, const char* refId, unsigned int count, int charge,
double enchantmentCharge, const char* soul) noexcept
{
Player *player;
@ -76,20 +83,6 @@ void ItemFunctions::AddItem(unsigned short pid, const char* refId, unsigned int
item.soul = soul;
player->inventoryChanges.items.push_back(item);
player->inventoryChanges.action = InventoryChanges::ADD;
}
void ItemFunctions::RemoveItem(unsigned short pid, const char* refId, unsigned short count) noexcept
{
Player *player;
GET_PLAYER(pid, player, );
Item item;
item.refId = refId;
item.count = count;
player->inventoryChanges.items.push_back(item);
player->inventoryChanges.action = InventoryChanges::REMOVE;
}
bool ItemFunctions::HasItemEquipped(unsigned short pid, const char* refId)
@ -259,3 +252,11 @@ void ItemFunctions::SendItemUse(unsigned short pid) noexcept
packet->Send(false);
}
// All methods below are deprecated versions of methods from above
void ItemFunctions::AddItem(unsigned short pid, const char* refId, unsigned int count, int charge,
double enchantmentCharge, const char* soul) noexcept
{
AddItemChange(pid, refId, count, charge, enchantmentCharge, soul);
}

@ -8,11 +8,12 @@
{"GetInventoryChangesSize", ItemFunctions::GetInventoryChangesSize},\
{"GetInventoryChangesAction", ItemFunctions::GetInventoryChangesAction},\
\
{"SetInventoryChangesAction", ItemFunctions::SetInventoryChangesAction},\
\
{"EquipItem", ItemFunctions::EquipItem},\
{"UnequipItem", ItemFunctions::UnequipItem},\
\
{"AddItem", ItemFunctions::AddItem},\
{"RemoveItem", ItemFunctions::RemoveItem},\
{"AddItemChange", ItemFunctions::AddItemChange},\
\
{"HasItemEquipped", ItemFunctions::HasItemEquipped},\
\
@ -35,7 +36,9 @@
\
{"SendEquipment", ItemFunctions::SendEquipment},\
{"SendInventoryChanges", ItemFunctions::SendInventoryChanges},\
{"SendItemUse", ItemFunctions::SendItemUse}
{"SendItemUse", ItemFunctions::SendItemUse},\
\
{"AddItem", ItemFunctions::AddItem}
class ItemFunctions
{
@ -76,6 +79,15 @@ public:
*/
static unsigned int GetInventoryChangesAction(unsigned short pid) noexcept;
/**
* \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;
/**
* \brief Equip an item in a certain slot of the equipment of a player.
*
@ -87,7 +99,8 @@ public:
* \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;
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.
@ -99,9 +112,7 @@ public:
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.
* \brief Add an item change to a player's inventory changes.
*
* \param pid The player ID.
* \param refId The refId of the item.
@ -111,21 +122,9 @@ public:
* \param soul The soul of the item.
* \return void
*/
static void AddItem(unsigned short pid, const char* refId, unsigned int count, int charge,
static void AddItemChange(unsigned short pid, const char* refId, unsigned int count, int charge,
double enchantmentCharge, const char* soul) 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.
*
@ -292,6 +291,11 @@ public:
*/
static void SendItemUse(unsigned short pid) noexcept;
// All methods below are deprecated versions of methods from above
static void AddItem(unsigned short pid, const char* refId, unsigned int count, int charge,
double enchantmentCharge, const char* soul) noexcept;
private:
};

Loading…
Cancel
Save