feat(Core/ServerMail): Allow mail sender to be a creature (#26302)
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE `mail_server_template`
|
||||||
|
ADD COLUMN `senderEntry` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Entry from creature_template. 0 for default "Customer Support" sender.' AFTER `id`;
|
||||||
@@ -41,8 +41,8 @@ void ServerMailMgr::LoadMailServerTemplates()
|
|||||||
|
|
||||||
_serverMailStore.clear(); // for reload case
|
_serverMailStore.clear(); // for reload case
|
||||||
|
|
||||||
// 0 1 2 3 4 5
|
// 0 1 2 3 4 5 6
|
||||||
QueryResult result = CharacterDatabase.Query("SELECT `id`, `moneyA`, `moneyH`, `subject`, `body`, `active` FROM `mail_server_template`");
|
QueryResult result = CharacterDatabase.Query("SELECT `id`, `senderEntry`, `moneyA`, `moneyH`, `subject`, `body`, `active` FROM `mail_server_template`");
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
LOG_INFO("server.loading", ">> Loaded 0 server mail rewards. DB table `mail_server_template` is empty.");
|
LOG_INFO("server.loading", ">> Loaded 0 server mail rewards. DB table `mail_server_template` is empty.");
|
||||||
@@ -60,11 +60,12 @@ void ServerMailMgr::LoadMailServerTemplates()
|
|||||||
|
|
||||||
ServerMail& servMail = _serverMailStore[id];
|
ServerMail& servMail = _serverMailStore[id];
|
||||||
servMail.id = id;
|
servMail.id = id;
|
||||||
servMail.moneyA = fields[1].Get<uint32>();
|
servMail.senderEntry = fields[1].Get<uint32>();
|
||||||
servMail.moneyH = fields[2].Get<uint32>();
|
servMail.moneyA = fields[2].Get<uint32>();
|
||||||
servMail.subject = fields[3].Get<std::string>();
|
servMail.moneyH = fields[3].Get<uint32>();
|
||||||
servMail.body = fields[4].Get<std::string>();
|
servMail.subject = fields[4].Get<std::string>();
|
||||||
servMail.active = fields[5].Get<uint8>();
|
servMail.body = fields[5].Get<std::string>();
|
||||||
|
servMail.active = fields[6].Get<uint8>();
|
||||||
|
|
||||||
// Skip non-activated entries
|
// Skip non-activated entries
|
||||||
if (!servMail.active)
|
if (!servMail.active)
|
||||||
@@ -75,6 +76,12 @@ void ServerMailMgr::LoadMailServerTemplates()
|
|||||||
LOG_ERROR("sql.sql", "Table `mail_server_template` has moneyA {} or moneyH {} larger than MAX_MONEY_AMOUNT {} for id {}, skipped.", servMail.moneyA, servMail.moneyH, MAX_MONEY_AMOUNT, servMail.id);
|
LOG_ERROR("sql.sql", "Table `mail_server_template` has moneyA {} or moneyH {} larger than MAX_MONEY_AMOUNT {} for id {}, skipped.", servMail.moneyA, servMail.moneyH, MAX_MONEY_AMOUNT, servMail.id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (servMail.senderEntry && !sObjectMgr->GetCreatureTemplate(servMail.senderEntry))
|
||||||
|
{
|
||||||
|
LOG_ERROR("sql.sql", "Table `mail_server_template` has invalid senderEntry {} (no matching creature_template) for id {}, falling back to default sender.", servMail.senderEntry, servMail.id);
|
||||||
|
servMail.senderEntry = 0;
|
||||||
|
}
|
||||||
} while (result->NextRow());
|
} while (result->NextRow());
|
||||||
|
|
||||||
LoadMailServerTemplatesItems();
|
LoadMailServerTemplatesItems();
|
||||||
@@ -281,7 +288,7 @@ void ServerMailMgr::LoadMailServerTemplatesConditions()
|
|||||||
} while (result->NextRow());
|
} while (result->NextRow());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerMailMgr::SendServerMail(Player* player, uint32 id, uint32 money,
|
void ServerMailMgr::SendServerMail(Player* player, uint32 id, uint32 senderEntry, uint32 money,
|
||||||
std::vector<ServerMailItems> const& items,
|
std::vector<ServerMailItems> const& items,
|
||||||
std::vector<ServerMailCondition> const& conditions,
|
std::vector<ServerMailCondition> const& conditions,
|
||||||
std::string const& subject, std::string const& body) const
|
std::string const& subject, std::string const& body) const
|
||||||
@@ -292,7 +299,9 @@ void ServerMailMgr::SendServerMail(Player* player, uint32 id, uint32 money,
|
|||||||
|
|
||||||
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
||||||
|
|
||||||
MailSender sender(MAIL_NORMAL, player->GetGUID().GetCounter(), MAIL_STATIONERY_GM);
|
MailSender sender = senderEntry
|
||||||
|
? MailSender(MAIL_CREATURE, senderEntry, MAIL_STATIONERY_DEFAULT)
|
||||||
|
: MailSender(MAIL_NORMAL, player->GetGUID().GetCounter(), MAIL_STATIONERY_GM);
|
||||||
MailDraft draft(subject, body);
|
MailDraft draft(subject, body);
|
||||||
|
|
||||||
draft.AddMoney(money);
|
draft.AddMoney(money);
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ struct ServerMail
|
|||||||
{
|
{
|
||||||
ServerMail() = default;
|
ServerMail() = default;
|
||||||
uint32 id{ 0 };
|
uint32 id{ 0 };
|
||||||
|
uint32 senderEntry{ 0 }; ///< Entry from creature_template. 0 for default "Customer Support" sender.
|
||||||
uint32 moneyA{ 0 };
|
uint32 moneyA{ 0 };
|
||||||
uint32 moneyH{ 0 };
|
uint32 moneyH{ 0 };
|
||||||
std::string subject;
|
std::string subject;
|
||||||
@@ -205,6 +206,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param player The recipient player.
|
* @param player The recipient player.
|
||||||
* @param id The template ID.
|
* @param id The template ID.
|
||||||
|
* @param senderEntry Entry from creature_template. 0 for default "Customer Support" sender.
|
||||||
* @param money Money reward.
|
* @param money Money reward.
|
||||||
* @param items List of items to include in the mail.
|
* @param items List of items to include in the mail.
|
||||||
* @param conditions List of the conditions for the mail.
|
* @param conditions List of the conditions for the mail.
|
||||||
@@ -212,7 +214,7 @@ public:
|
|||||||
* @param body Mail body.
|
* @param body Mail body.
|
||||||
* @param active Whether the mail template is active.
|
* @param active Whether the mail template is active.
|
||||||
*/
|
*/
|
||||||
void SendServerMail(Player* player, uint32 id, uint32 money, std::vector<ServerMailItems> const& items, std::vector<ServerMailCondition> const& conditions, std::string const& subject, std::string const& body) const;
|
void SendServerMail(Player* player, uint32 id, uint32 senderEntry, uint32 money, std::vector<ServerMailItems> const& items, std::vector<ServerMailCondition> const& conditions, std::string const& subject, std::string const& body) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Retrieves the entire server mail store.
|
* @brief Retrieves the entire server mail store.
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ public:
|
|||||||
sServerMailMgr->SendServerMail(
|
sServerMailMgr->SendServerMail(
|
||||||
session->GetPlayer(),
|
session->GetPlayer(),
|
||||||
servMail.id,
|
servMail.id,
|
||||||
|
servMail.senderEntry,
|
||||||
money,
|
money,
|
||||||
items,
|
items,
|
||||||
conditions,
|
conditions,
|
||||||
|
|||||||
Reference in New Issue
Block a user