mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-22 05:06:24 +00:00
feat(Core/Player): add helper for send large count mail items (#8460)
This commit is contained in:
@@ -1580,6 +1580,8 @@ public:
|
||||
Mail* GetMail(uint32 id);
|
||||
|
||||
PlayerMails const& GetMails() const { return m_mail; }
|
||||
void SendItemRetrievalMail(uint32 itemEntry, uint32 count); // Item retrieval mails sent by The Postmaster (34337)
|
||||
void SendItemRetrievalMail(std::vector<std::pair<uint32, uint32>> mailItems); // Item retrieval mails sent by The Postmaster (34337)
|
||||
|
||||
/*********************************************************/
|
||||
/*** MAILED ITEMS SYSTEM ***/
|
||||
|
||||
@@ -416,3 +416,83 @@ void Player::UpdateDuelFlag(time_t currTime)
|
||||
}
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
void Player::SendItemRetrievalMail(uint32 itemEntry, uint32 count)
|
||||
{
|
||||
SendItemRetrievalMail({ { itemEntry, count } });
|
||||
}
|
||||
|
||||
void Player::SendItemRetrievalMail(std::vector<std::pair<uint32, uint32>> mailItems)
|
||||
{
|
||||
if (mailItems.empty())
|
||||
{
|
||||
// Skip send if empty items
|
||||
FMT_LOG_ERROR("entities.player.items", "> SendItemRetrievalMail: Attempt to send almost with items without items. Player {}", GetGUID().ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
using SendMailTempateVector = std::vector<std::pair<uint32, uint32>>;
|
||||
|
||||
std::vector<SendMailTempateVector> allItems;
|
||||
|
||||
auto AddMailItem = [&allItems](uint32 itemEntry, uint32 itemCount)
|
||||
{
|
||||
SendMailTempateVector toSendItems;
|
||||
|
||||
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemEntry);
|
||||
if (!itemTemplate)
|
||||
{
|
||||
FMT_LOG_ERROR("entities.player.items", "> SendItemRetrievalMail: Item id {} is invalid", itemEntry);
|
||||
return;
|
||||
}
|
||||
|
||||
if (itemCount < 1 || (itemTemplate->MaxCount > 0 && itemCount > static_cast<uint32>(itemTemplate->MaxCount)))
|
||||
{
|
||||
FMT_LOG_ERROR("entities.player.items", "> SendItemRetrievalMail: Incorrect item count ({}) for item id {}", itemEntry, itemCount);
|
||||
return;
|
||||
}
|
||||
|
||||
while (itemCount > itemTemplate->GetMaxStackSize())
|
||||
{
|
||||
if (toSendItems.size() <= MAX_MAIL_ITEMS)
|
||||
{
|
||||
toSendItems.emplace_back(itemEntry, itemTemplate->GetMaxStackSize());
|
||||
itemCount -= itemTemplate->GetMaxStackSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
allItems.emplace_back(toSendItems);
|
||||
toSendItems.clear();
|
||||
}
|
||||
}
|
||||
|
||||
toSendItems.emplace_back(itemEntry, itemCount);
|
||||
allItems.emplace_back(toSendItems);
|
||||
};
|
||||
|
||||
for (auto& [itemEntry, itemCount] : mailItems)
|
||||
{
|
||||
AddMailItem(itemEntry, itemCount);
|
||||
}
|
||||
|
||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
|
||||
for (auto const& items : allItems)
|
||||
{
|
||||
MailSender sender(MAIL_CREATURE, 34337 /* The Postmaster */);
|
||||
MailDraft draft("Recovered Item", "We recovered a lost item in the twisting nether and noted that it was yours.$B$BPlease find said object enclosed."); // This is the text used in Cataclysm, it probably wasn't changed.
|
||||
|
||||
for (auto const& [itemEntry, itemCount] : items)
|
||||
{
|
||||
if (Item* mailItem = Item::CreateItem(itemEntry, itemCount))
|
||||
{
|
||||
mailItem->SaveToDB(trans);
|
||||
draft.AddItem(mailItem);
|
||||
}
|
||||
}
|
||||
|
||||
draft.SendMailTo(trans, MailReceiver(this, GetGUID().GetCounter()), sender);
|
||||
}
|
||||
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
}
|
||||
|
||||
@@ -677,9 +677,9 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
|
||||
|
||||
RemoveTimedQuest(quest_id);
|
||||
|
||||
std::vector<std::pair<uint32, uint32> > problematicItems;
|
||||
std::vector<std::pair<uint32, uint32>> problematicItems;
|
||||
|
||||
if (quest->GetRewChoiceItemsCount() > 0)
|
||||
if (quest->GetRewChoiceItemsCount())
|
||||
{
|
||||
if (uint32 itemId = quest->RewardChoiceItemId[reward])
|
||||
{
|
||||
@@ -692,11 +692,13 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
|
||||
sScriptMgr->OnQuestRewardItem(this, item, quest->RewardChoiceItemCount[reward]);
|
||||
}
|
||||
else
|
||||
problematicItems.push_back(std::pair<uint32, uint32>(itemId, quest->RewardChoiceItemCount[reward]));
|
||||
{
|
||||
problematicItems.emplace_back(itemId, quest->RewardChoiceItemCount[reward]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (quest->GetRewItemsCount() > 0)
|
||||
if (quest->GetRewItemsCount())
|
||||
{
|
||||
for (uint32 i = 0; i < quest->GetRewItemsCount(); ++i)
|
||||
{
|
||||
@@ -711,7 +713,7 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
|
||||
sScriptMgr->OnQuestRewardItem(this, item, quest->RewardItemIdCount[i]);
|
||||
}
|
||||
else
|
||||
problematicItems.push_back(std::pair<uint32, uint32>(itemId, quest->RewardItemIdCount[i]));
|
||||
problematicItems.emplace_back(itemId, quest->RewardItemIdCount[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -719,21 +721,7 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
|
||||
// Xinef: send items that couldn't be added properly by mail
|
||||
if (!problematicItems.empty())
|
||||
{
|
||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
MailSender sender(MAIL_CREATURE, 34337 /* The Postmaster */ );
|
||||
MailDraft draft("Recovered Item", "We recovered a lost item in the twisting nether and noted that it was yours.$B$BPlease find said object enclosed."); // This is the text used in Cataclysm, it probably wasn't changed.
|
||||
|
||||
for (std::vector<std::pair<uint32, uint32> >::const_iterator itr = problematicItems.begin(); itr != problematicItems.end(); ++itr)
|
||||
{
|
||||
if(Item* item = Item::CreateItem(itr->first, itr->second))
|
||||
{
|
||||
item->SaveToDB(trans);
|
||||
draft.AddItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
draft.SendMailTo(trans, MailReceiver(this, GetGUID().GetCounter()), sender);
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
SendItemRetrievalMail(problematicItems);
|
||||
}
|
||||
|
||||
RewardReputation(quest);
|
||||
|
||||
Reference in New Issue
Block a user