diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/Player/Player.h | 2 | ||||
-rw-r--r-- | src/server/game/Entities/Player/PlayerMisc.cpp | 80 | ||||
-rw-r--r-- | src/server/game/Entities/Player/PlayerQuest.cpp | 28 |
3 files changed, 90 insertions, 20 deletions
diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index 87d0a8359b..aeedb4f504 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -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 ***/ diff --git a/src/server/game/Entities/Player/PlayerMisc.cpp b/src/server/game/Entities/Player/PlayerMisc.cpp index 2670fba1fd..c14ff97fc2 100644 --- a/src/server/game/Entities/Player/PlayerMisc.cpp +++ b/src/server/game/Entities/Player/PlayerMisc.cpp @@ -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); +} diff --git a/src/server/game/Entities/Player/PlayerQuest.cpp b/src/server/game/Entities/Player/PlayerQuest.cpp index 2ba20af37e..1b086e07e8 100644 --- a/src/server/game/Entities/Player/PlayerQuest.cpp +++ b/src/server/game/Entities/Player/PlayerQuest.cpp @@ -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); |