Several fixes for additem command (#168)

* FIX : HandleAdditemCommand (delete items in bank)

The .additem command was not deleting items in the bank

* FIX : HandleAdditemCommand (delete items in buyback tab)

The .additem command was not deleting items in the buyback vendor tab for npc vendors

* Enchance LANG_REMOVEITEM text

* Fix Tabs / spaces in Language.h

* Fix Language.h file generator
This commit is contained in:
Elmsroth 2021-12-29 00:15:18 +01:00 committed by GitHub
parent 43d5069dfe
commit 39381b1552
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 138 additions and 24 deletions

View File

@ -1100,8 +1100,8 @@ bool ChatHandler::HandleAddItemCommand(char* args)
// Subtract
if (count < 0)
{
plTarget->DestroyItemCount(itemId, -count, true, false);
PSendSysMessage(LANG_REMOVEITEM, itemId, -count, GetNameLink(plTarget).c_str());
uint32 deletedCount = plTarget->DestroyItemCount(itemId, -count, true, false, /* delete_from_bank */ true, /* delete_from_buyback*/ true);
PSendSysMessage(LANG_REMOVEITEM, itemId, -count , deletedCount, GetNameLink(plTarget).c_str());
return true;
}

View File

@ -12175,12 +12175,12 @@ void Player::DestroyItem(uint8 bag, uint8 slot, bool update)
}
}
void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequip_check)
uint32 Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequip_check, bool delete_from_bank,bool delete_from_buyback)
{
DEBUG_LOG("STORAGE: DestroyItemCount item = %u, count = %u", item, count);
uint32 remcount = 0;
// in inventory
// Search in default bagpack
for (int i = INVENTORY_SLOT_ITEM_START; i < INVENTORY_SLOT_ITEM_END; ++i)
{
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
@ -12195,7 +12195,7 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
if (remcount >= count)
{
return;
return remcount;
}
}
else
@ -12207,12 +12207,13 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
pItem->SendCreateUpdateToPlayer(this);
}
pItem->SetState(ITEM_CHANGED, this);
return;
return remcount;
}
}
}
}
// Search in keyring slots
for (int i = KEYRING_SLOT_START; i < KEYRING_SLOT_END; ++i)
{
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
@ -12227,7 +12228,7 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
if (remcount >= count)
{
return;
return remcount;
}
}
else
@ -12239,13 +12240,13 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
pItem->SendCreateUpdateToPlayer(this);
}
pItem->SetState(ITEM_CHANGED, this);
return;
return remcount;
}
}
}
}
// in inventory bags
// Search in inventory bags
for (int i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; ++i)
{
if (Bag* pBag = (Bag*)GetItemByPos(INVENTORY_SLOT_BAG_0, i))
@ -12264,7 +12265,7 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
if (remcount >= count)
{
return;
return remcount;
}
}
else
@ -12276,7 +12277,7 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
pItem->SendCreateUpdateToPlayer(this);
}
pItem->SetState(ITEM_CHANGED, this);
return;
return remcount;
}
}
}
@ -12284,8 +12285,8 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
}
}
// in equipment and bag list
for (int i = EQUIPMENT_SLOT_START; i < INVENTORY_SLOT_BAG_END; ++i)
// Search in Equiped items
for (int i = EQUIPMENT_SLOT_START; i < EQUIPMENT_SLOT_END; ++i)
{
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
{
@ -12297,10 +12298,9 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
{
remcount += pItem->GetCount();
DestroyItem(INVENTORY_SLOT_BAG_0, i, update);
if (remcount >= count)
{
return;
return remcount;
}
}
}
@ -12313,11 +12313,125 @@ void Player::DestroyItemCount(uint32 item, uint32 count, bool update, bool unequ
pItem->SendCreateUpdateToPlayer(this);
}
pItem->SetState(ITEM_CHANGED, this);
return;
return remcount;
}
}
}
}
// Search in bank items
if (delete_from_bank)
{
// Normal bank slots
for (int i = BANK_SLOT_ITEM_START; i < BANK_SLOT_ITEM_END; ++i)
{
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
{
if (pItem->GetEntry() == item && !pItem->IsInTrade())
{
if (pItem->GetCount() + remcount <= count)
{
// all items in inventory can unequipped
remcount += pItem->GetCount();
DestroyItem(INVENTORY_SLOT_BAG_0, i, update);
if (remcount >= count)
{
return remcount;
}
}
else
{
ItemRemovedQuestCheck(pItem->GetEntry(), count - remcount);
pItem->SetCount(pItem->GetCount() - count + remcount);
if (IsInWorld() && update)
{
pItem->SendCreateUpdateToPlayer(this);
}
pItem->SetState(ITEM_CHANGED, this);
return remcount;
}
}
}
}
// Bank bagslots
for (int i = BANK_SLOT_BAG_START; i < BANK_SLOT_BAG_END; ++i)
{
if (Bag* pBag = (Bag*)GetItemByPos(INVENTORY_SLOT_BAG_0, i))
{
for (uint32 j = 0; j < pBag->GetBagSize(); ++j)
{
if (Item* pItem = pBag->GetItemByPos(j))
{
if (pItem->GetEntry() == item && !pItem->IsInTrade())
{
// all items in bags can be unequipped
if (pItem->GetCount() + remcount <= count)
{
remcount += pItem->GetCount();
DestroyItem(i, j, update);
if (remcount >= count)
{
return remcount;
}
}
else
{
ItemRemovedQuestCheck(pItem->GetEntry(), count - remcount);
pItem->SetCount(pItem->GetCount() - count + remcount);
if (IsInWorld() && update)
{
pItem->SendCreateUpdateToPlayer(this);
}
pItem->SetState(ITEM_CHANGED, this);
return remcount;
}
}
}
}
}
}
}
// Search in buyback npcs vendor tab
if (delete_from_buyback)
{
for (int i = BUYBACK_SLOT_START; i < BUYBACK_SLOT_END; ++i)
{
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
{
if (pItem->GetEntry() == item && !pItem->IsInTrade())
{
if (pItem->GetCount() + remcount <= count)
{
// all keys can be unequipped
remcount += pItem->GetCount();
DestroyItem(INVENTORY_SLOT_BAG_0, i, update);
if (remcount >= count)
{
return remcount;
}
}
else
{
ItemRemovedQuestCheck(pItem->GetEntry(), count - remcount);
pItem->SetCount(pItem->GetCount() - count + remcount);
if (IsInWorld() && update)
{
pItem->SendCreateUpdateToPlayer(this);
}
pItem->SetState(ITEM_CHANGED, this);
return remcount;
}
}
}
}
}
return remcount;
}
void Player::DestroyZoneLimitedItem(bool update, uint32 new_zone)

View File

@ -1255,7 +1255,7 @@ class Player : public Unit
// in trade, guild bank, mail....
void RemoveItemDependentAurasAndCasts(Item* pItem);
void DestroyItem(uint8 bag, uint8 slot, bool update);
void DestroyItemCount(uint32 item, uint32 count, bool update, bool unequip_check = false);
uint32 DestroyItemCount(uint32 item, uint32 count, bool update, bool unequip_check = false, bool delete_from_bank = false, bool delete_from_buyback = false);
void DestroyItemCount(Item* item, uint32& count, bool update);
void DestroyConjuredItems(bool update);
void DestroyZoneLimitedItem(bool update, uint32 new_zone);

View File

@ -443,7 +443,7 @@ enum MangosStrings
LANG_REMOVE_COOLDOWN = 493, /* Spell %u cooldown removed for %s. */
LANG_ADDITEM = 494, /* Command : Additem, itemId = %i, amount = %i */
LANG_ADDITEMSET = 495, /* Command : Additemset, itemsetId = %i */
LANG_REMOVEITEM = 496, /* Removed itemID = %i, amount = %i from %s */
LANG_REMOVEITEM = 496, /* Removed itemID = |cffffffff%i|r : Try to remove count = |cff00a1ff%i|r, Effective deleted count = |cffff0000%i|r from |cffffffff%s|r */
LANG_ITEM_CANNOT_CREATE = 497, /* Cannot create item '%i' (amount: %i) */
LANG_INSERT_GUILD_NAME = 498, /* You need to provide a guild name! */
LANG_PLAYER_NOT_FOUND = 499, /* Player not found! */
@ -869,8 +869,8 @@ Faction Template: %u. */
LANG_COMMAND_AURAGROUP_ALL_AURA_REMOVED = 1704, /* All auras have been removed from %s. */
LANG_COMMAND_AURAGROUP_AURA_REMOVED_FOR_SPELL = 1705, /* Aura from spell %u has been removedfrom %s */
LANG_COMMAND_EXECUTE_GOCRE_ANOTHER_TIME = 1706, /* You will have to execute your command another time to get to the real moving npc position (.go creature %u) */
LANG_COMMAND_FREEZE_PLAYER = 1707, /* %s has been freezed ! Be careful : Effect will persist after logout or ban if not manually removed ! (use ".unfreezeplayer" command to allow the player to move again) */
LANG_COMMAND_UNFREEZE_PLAYER = 1708, /* %s has been unfreezed. */
LANG_COMMAND_FREEZE_PLAYER = 1707, /* %s has been frozen ! Be careful : Effect will persist after logout or ban if not manually removed ! (use ".unfreezeplayer" command to allow the player to move again) */
LANG_COMMAND_UNFREEZE_PLAYER = 1708, /* %s has been unfrozen. */
LANG_COMMAND_FREEZE_PLAYER_CANNOT_FREEZE_HIGHER_SECLEVEL = 1709, /* You cannot freeze %s since his security level is higher than yours. */
LANG_COMMAND_FREEZE_PLAYER_CANNOT_FREEZE_YOURSELF = 1710, /* You cannot freeze yourself ! (What a strange idea by the way...) */
LANG_COMMAND_FREEZE_PLAYER_YOU_HAVE_BEEN_FROZEN = 1711, /* A GM has frozen your character. From now, you cannot move, use spells or logout. */

View File

@ -37,7 +37,7 @@
#define CHAR_DB_UPDATE_DESCRIPTION "add_character_createdDate_col"
#define WORLD_DB_VERSION_NR 22
#define WORLD_DB_STRUCTURE_NR 1
#define WORLD_DB_CONTENT_NR 011
#define WORLD_DB_UPDATE_DESCRIPTION "update_additem_command_syntax"
#define WORLD_DB_STRUCTURE_NR 2
#define WORLD_DB_CONTENT_NR 001
#define WORLD_DB_UPDATE_DESCRIPTION "Fix_Additem_LANG_REMOVEITEM"
#endif // __REVISION_H__

View File

@ -75,7 +75,7 @@
foreach($rows as $row)
{
$tagLen = strlen($row["source_enum_tag"]);
$line = TAB . $row["source_enum_tag"] . spaces($maxTagLength - $tagLen + 2) . "= " .$row["entry"] ."," . spaces(4) . "/* " .$row["content_default"] ." */" . NEWLINE;
$line = spaces(4) . $row["source_enum_tag"] . spaces($maxTagLength - $tagLen + 2) . "= " .$row["entry"] ."," . spaces(4) . "/* " .$row["content_default"] ." */" . NEWLINE;
$fileContent .= $line;
}