mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-22 05:06:24 +00:00
refactor(Core/ServerMail): Refactor to Dedicated Manager Class with Multi-Item & Condition Support (#21590)
1. Core Cleanup
- Move all ServerMail logic from `ObjectMgr` into a new dedicated `ServerMailMgr` class
- Move faction logic for money from SendServerMail into the script
2. Separation of items into a new table
- Create a new `mail_server_template_items` table
- Allows to send multiple items in one mail
- Separate items per faction Alliance/Horde
3. Separation of conditions into a new table
- Create a new `mail_server_template_conditions` table
- Allows to use multiple conditions for one mail
- Available condition types
- Minimum playtime (playerLevel >= condition)
- Minimum playtime (playerPlayTime >= condition)
- Rewarded quest
- Earned achievement
- Earned reputation (playerReputation >= conditionState)
- Faction
- Race
- Class
4. Updated ServerMail loading
- Move item and condition loading to their own functions
- LoadMailServerTemplateItems()
- LoadMailServerTemplateConditions()
5. Reworked eligibility check
- Player needs to pass all conditions to be eligible for the mail
- All players are automatically eligible if no conditions exist for a server mail template.
6. Updated foreign keys
- For table `mail_server_character`, `mail_server_template_conditions`, `mail_server_template_items` foreign key with on delete cascade is added for automatic removal of entries if mail_server_template.id is deleted.
7. Database changes
- See the PR
This commit is contained in:
@@ -38,6 +38,7 @@ EndScriptData */
|
||||
#include "MotdMgr.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "ServerMailMgr.h"
|
||||
#include "SkillDiscovery.h"
|
||||
#include "SkillExtraItems.h"
|
||||
#include "SmartAI.h"
|
||||
@@ -1196,7 +1197,7 @@ public:
|
||||
static bool HandleReloadMailServerTemplateCommand(ChatHandler* handler)
|
||||
{
|
||||
LOG_INFO("server.loading", "Reloading `server_mail_template` table");
|
||||
sObjectMgr->LoadMailServerTemplates();
|
||||
sServerMailMgr->LoadMailServerTemplates();
|
||||
handler->SendGlobalGMSysMessage("DB table `server_mail_template` reloaded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
#include "CreatureScript.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "Player.h"
|
||||
#include "PlayerScript.h"
|
||||
#include "QueryResult.h"
|
||||
#include "ServerMailMgr.h"
|
||||
|
||||
class ServerMailReward : public PlayerScript
|
||||
{
|
||||
@@ -30,13 +30,14 @@ public:
|
||||
void OnPlayerLogin(Player* player) override
|
||||
{
|
||||
// Retrieve all server mail records and session only once
|
||||
auto const& serverMailStore = sObjectMgr->GetAllServerMailStore();
|
||||
auto const& serverMailStore = sServerMailMgr->GetAllServerMailStore();
|
||||
WorldSession* session = player->GetSession();
|
||||
// We should always have a session, just incase
|
||||
if (!session)
|
||||
return;
|
||||
|
||||
uint32 playerGUID = player->GetGUID().GetCounter();
|
||||
bool isAlliance = player->GetTeamId() == TEAM_ALLIANCE;
|
||||
|
||||
for (auto const& [mailId, servMail] : serverMailStore)
|
||||
{
|
||||
@@ -45,26 +46,24 @@ public:
|
||||
stmt->SetData(1, mailId);
|
||||
|
||||
// Capture servMail by value
|
||||
auto callback = [session, servMailWrapper = std::reference_wrapper<ServerMail const>(servMail)](PreparedQueryResult result)
|
||||
auto callback = [session, servMailWrapper = std::reference_wrapper<ServerMail const>(servMail), isAlliance](PreparedQueryResult result)
|
||||
{
|
||||
ServerMail const& servMail = servMailWrapper.get(); // Dereference the wrapper to get the original object
|
||||
ServerMail const& servMail = servMailWrapper.get(); // Dereference the wrapper to get the original object
|
||||
|
||||
if (!result)
|
||||
{
|
||||
sObjectMgr->SendServerMail(
|
||||
uint32 money = isAlliance ? servMail.moneyA : servMail.moneyH;
|
||||
std::vector<ServerMailItems> const& items = isAlliance ? servMail.itemsA : servMail.itemsH;
|
||||
std::vector<ServerMailCondition> const& conditions = servMail.conditions;
|
||||
|
||||
sServerMailMgr->SendServerMail(
|
||||
session->GetPlayer(),
|
||||
servMail.id,
|
||||
servMail.reqLevel,
|
||||
servMail.reqPlayTime,
|
||||
servMail.moneyA,
|
||||
servMail.moneyH,
|
||||
servMail.itemA,
|
||||
servMail.itemCountA,
|
||||
servMail.itemH,
|
||||
servMail.itemCountH,
|
||||
money,
|
||||
items,
|
||||
conditions,
|
||||
servMail.subject,
|
||||
servMail.body,
|
||||
servMail.active
|
||||
servMail.body
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user