Skip to content

Commit

Permalink
Core/Commands: Extract bonus lists and item context from provided ite…
Browse files Browse the repository at this point in the history
…m link for .additem commands

Closes TrinityCore#30209
  • Loading branch information
Shauren committed Jan 7, 2025
1 parent 039acb2 commit f647ff6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/server/scripts/Commands/cs_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,8 +1158,14 @@ class misc_commandscript : public CommandScript
Optional<std::string_view> const& bonusListIdString, Optional<uint8> itemContextArg)
{
uint32 itemId = 0;
std::vector<int32> bonusListIDs;
ItemContext itemContext = ItemContext::NONE;
if (Hyperlink<::item> const* itemLinkData = std::get_if<Hyperlink<::item>>(&itemArg))
{
itemId = (*itemLinkData)->Item->GetId();
bonusListIDs = (*itemLinkData)->ItemBonusListIDs;
itemContext = static_cast<ItemContext>((*itemLinkData)->Context);
}
else if (uint32 const* itemIdPtr = std::get_if<uint32>(&itemArg))
itemId = *itemIdPtr;
else if (std::string_view const* itemNameText = std::get_if<std::string_view>(&itemArg))
Expand Down Expand Up @@ -1192,22 +1198,22 @@ class misc_commandscript : public CommandScript
if (count == 0)
count = 1;

std::vector<int32> bonusListIDs;

// semicolon separated bonuslist ids (parse them after all arguments are extracted by strtok!)
if (bonusListIdString)
for (std::string_view token : Trinity::Tokenize(*bonusListIdString, ';', false))
if (Optional<int32> bonusListId = Trinity::StringTo<int32>(token); bonusListId && *bonusListId)
bonusListIDs.push_back(*bonusListId);

ItemContext itemContext = ItemContext::NONE;
if (itemContextArg)
{
itemContext = ItemContext(*itemContextArg);
if (itemContext < ItemContext::Max)
{
std::vector<int32> contextBonuses = ItemBonusMgr::GetBonusListsForItem(itemId, itemContext);
bonusListIDs.insert(bonusListIDs.begin(), contextBonuses.begin(), contextBonuses.end());
std::ranges::sort(bonusListIDs);
std::ranges::borrowed_subrange_t<std::vector<int>&> removed = std::ranges::unique(bonusListIDs);
bonusListIDs.erase(removed.begin(), removed.end());
}
}

Expand Down

0 comments on commit f647ff6

Please sign in to comment.