fix(Scripts/Command): Allow player name/guid in additem (#17915)

* fix(Scripts/Command): Allow player name/guid in additem

* build?

* Revert "build?"

This reverts commit 3f37456f1d41a0db0bae45801c6f90e72ce19292.

* Update cs_misc.cpp

* console isnt a player
This commit is contained in:
Kitzunu
2023-12-02 19:59:09 +01:00
committed by GitHub
parent db4b0b0d3d
commit eb663a436a
2 changed files with 18 additions and 20 deletions
@@ -0,0 +1,2 @@
--
UPDATE `command` SET `help`='Syntax: .additem Optional(playerName/playerGUID) #itemID/[#itemName]/#itemLink #itemCount\r\nAdds the specified item to you, the selected character or the specifed character name/GUID.\r\nIf #itemCount is negative, you will remove #itemID.' WHERE `name`='additem';
+16 -20
View File
@@ -113,7 +113,7 @@ public:
{ "neargrave", HandleNearGraveCommand, SEC_GAMEMASTER, Console::No }, { "neargrave", HandleNearGraveCommand, SEC_GAMEMASTER, Console::No },
{ "showarea", HandleShowAreaCommand, SEC_GAMEMASTER, Console::No }, { "showarea", HandleShowAreaCommand, SEC_GAMEMASTER, Console::No },
{ "hidearea", HandleHideAreaCommand, SEC_ADMINISTRATOR, Console::No }, { "hidearea", HandleHideAreaCommand, SEC_ADMINISTRATOR, Console::No },
{ "additem", HandleAddItemCommand, SEC_GAMEMASTER, Console::No }, { "additem", HandleAddItemCommand, SEC_GAMEMASTER, Console::Yes },
{ "additem set", HandleAddItemSetCommand, SEC_GAMEMASTER, Console::No }, { "additem set", HandleAddItemSetCommand, SEC_GAMEMASTER, Console::No },
{ "wchange", HandleChangeWeather, SEC_ADMINISTRATOR, Console::No }, { "wchange", HandleChangeWeather, SEC_ADMINISTRATOR, Console::No },
{ "maxskill", HandleMaxSkillCommand, SEC_GAMEMASTER, Console::No }, { "maxskill", HandleMaxSkillCommand, SEC_GAMEMASTER, Console::No },
@@ -1617,7 +1617,7 @@ public:
return true; return true;
} }
static bool HandleAddItemCommand(ChatHandler* handler, ItemTemplate const* itemTemplate, Optional<int32> _count) static bool HandleAddItemCommand(ChatHandler* handler, Optional<PlayerIdentifier> player, ItemTemplate const* itemTemplate, Optional<int32> _count)
{ {
if (!sObjectMgr->GetItemTemplate(itemTemplate->ItemId)) if (!sObjectMgr->GetItemTemplate(itemTemplate->ItemId))
{ {
@@ -1629,22 +1629,21 @@ public:
int32 count = 1; int32 count = 1;
if (_count) if (_count)
{
count = *_count; count = *_count;
}
if (!count) if (!count)
{
count = 1; count = 1;
}
Player* player = handler->GetSession()->GetPlayer(); if (!player)
Player* playerTarget = handler->getSelectedPlayer(); player = PlayerIdentifier::FromTargetOrSelf(handler);
if (!player)
return false;
Player* playerTarget = player->GetConnectedPlayer();
if (!playerTarget) if (!playerTarget)
{ return false;
playerTarget = player;
}
// Subtract // Subtract
if (count < 0) if (count < 0)
@@ -1681,9 +1680,7 @@ public:
InventoryResult msg = playerTarget->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount); InventoryResult msg = playerTarget->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount);
if (msg != EQUIP_ERR_OK) // convert to possible store amount if (msg != EQUIP_ERR_OK) // convert to possible store amount
{
count -= noSpaceForCount; count -= noSpaceForCount;
}
if (!count || dest.empty()) // can't add any if (!count || dest.empty()) // can't add any
{ {
@@ -1693,32 +1690,31 @@ public:
Item* item = playerTarget->StoreNewItem(dest, itemId, true); Item* item = playerTarget->StoreNewItem(dest, itemId, true);
Player* p = handler->GetSession()->GetPlayer();
// remove binding (let GM give it to another player later) // remove binding (let GM give it to another player later)
if (player == playerTarget) if (p && p == playerTarget)
{ {
for (auto const& itemPos : dest) for (auto const& itemPos : dest)
{ {
if (Item* item1 = player->GetItemByPos(itemPos.pos)) if (Item* item1 = p->GetItemByPos(itemPos.pos))
{ {
item1->SetBinding(false); item1->SetBinding(false);
} }
} }
} }
if (count && item) if (p && count && item)
{ {
player->SendNewItem(item, count, false, true); p->SendNewItem(item, count, false, true);
if (player != playerTarget) if (p != playerTarget)
{ {
playerTarget->SendNewItem(item, count, true, false); playerTarget->SendNewItem(item, count, true, false);
} }
} }
if (noSpaceForCount) if (noSpaceForCount)
{
handler->PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount); handler->PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
}
return true; return true;
} }