mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 10:37:02 +00:00
[8768] Rewrite code for prepare and send mails.
* Move send functions to new MailDraft class from WorldSession * Simplify use different args combinations used in SendMailTo by groupping its by functionality in Helper classes. This also will prevent wrong way use args combinations.
This commit is contained in:
parent
50e80d67f9
commit
d009994f59
12 changed files with 381 additions and 317 deletions
|
|
@ -3914,8 +3914,8 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
|
|||
// remove signs from petitions (also remove petitions if owner);
|
||||
RemovePetitionsAndSigns(playerguid, 10);
|
||||
|
||||
// return back all mails with COD and Item 0 1 2 3 4 5 6
|
||||
QueryResult *resultMail = CharacterDatabase.PQuery("SELECT id,mailTemplateId,sender,subject,itemTextId,money,has_items FROM mail WHERE receiver='%u' AND has_items<>0 AND cod<>0", guid);
|
||||
// return back all mails with COD and Item 0 1 2 3 4 5 6 7
|
||||
QueryResult *resultMail = CharacterDatabase.PQuery("SELECT id,messageType,mailTemplateId,sender,subject,itemTextId,money,has_items FROM mail WHERE receiver='%u' AND has_items<>0 AND cod<>0", guid);
|
||||
if(resultMail)
|
||||
{
|
||||
do
|
||||
|
|
@ -3923,18 +3923,30 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
|
|||
Field *fields = resultMail->Fetch();
|
||||
|
||||
uint32 mail_id = fields[0].GetUInt32();
|
||||
uint16 mailTemplateId= fields[1].GetUInt16();
|
||||
uint32 sender = fields[2].GetUInt32();
|
||||
std::string subject = fields[3].GetCppString();
|
||||
uint32 itemTextId = fields[4].GetUInt32();
|
||||
uint32 money = fields[5].GetUInt32();
|
||||
bool has_items = fields[6].GetBool();
|
||||
uint16 mailType = fields[1].GetUInt16();
|
||||
uint16 mailTemplateId= fields[2].GetUInt16();
|
||||
uint32 sender = fields[3].GetUInt32();
|
||||
std::string subject = fields[4].GetCppString();
|
||||
uint32 itemTextId = fields[5].GetUInt32();
|
||||
uint32 money = fields[6].GetUInt32();
|
||||
bool has_items = fields[7].GetBool();
|
||||
|
||||
//we can return mail now
|
||||
//so firstly delete the old one
|
||||
CharacterDatabase.PExecute("DELETE FROM mail WHERE id = '%u'", mail_id);
|
||||
|
||||
MailItemsInfo mi;
|
||||
// mail not from player
|
||||
if (mailType != MAIL_NORMAL)
|
||||
{
|
||||
if(has_items)
|
||||
CharacterDatabase.PExecute("DELETE FROM mail_items WHERE mail_id = '%u'", mail_id);
|
||||
continue;
|
||||
}
|
||||
|
||||
MailDraft draft(subject, itemTextId);
|
||||
if (mailTemplateId)
|
||||
draft = MailDraft(mailTemplateId,false); // itesm already included
|
||||
|
||||
if(has_items)
|
||||
{
|
||||
// data needs to be at first place for Item::LoadFromDB
|
||||
|
|
@ -3963,7 +3975,7 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
|
|||
continue;
|
||||
}
|
||||
|
||||
mi.AddItem(pItem);
|
||||
draft.AddItem(pItem);
|
||||
}
|
||||
while (resultItems->NextRow());
|
||||
|
||||
|
|
@ -3975,7 +3987,7 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
|
|||
|
||||
uint32 pl_account = objmgr.GetPlayerAccountIdByGUID(MAKE_NEW_GUID(guid, 0, HIGHGUID_PLAYER));
|
||||
|
||||
WorldSession::SendReturnToSender(MAIL_NORMAL, pl_account, guid, sender, subject, itemTextId, &mi, money, mailTemplateId);
|
||||
draft.AddMoney(money).SendReturnToSender(pl_account, guid, sender);
|
||||
}
|
||||
while (resultMail->NextRow());
|
||||
|
||||
|
|
@ -12715,7 +12727,7 @@ void Player::RewardQuest( Quest const *pQuest, uint32 reward, Object* questGiver
|
|||
|
||||
// Send reward mail
|
||||
if (uint32 mail_template_id = pQuest->GetRewMailTemplateId())
|
||||
WorldSession::SendMailTemplateTo(this, questGiver, MAIL_STATIONERY_NORMAL, mail_template_id, 0, 0, MAIL_CHECK_MASK_NONE, pQuest->GetRewMailDelaySecs());
|
||||
MailDraft(mail_template_id).SendMailTo(this, questGiver, MAIL_CHECK_MASK_NONE, pQuest->GetRewMailDelaySecs());
|
||||
|
||||
if (pQuest->IsDaily())
|
||||
{
|
||||
|
|
@ -14941,20 +14953,20 @@ void Player::_LoadInventory(QueryResult *result, uint32 timediff)
|
|||
// send by mail problematic items
|
||||
while(!problematicItems.empty())
|
||||
{
|
||||
std::string subject = GetSession()->GetMangosString(LANG_NOT_EQUIPPED_ITEM);
|
||||
|
||||
// fill mail
|
||||
MailItemsInfo mi; // item list preparing
|
||||
MailDraft draft(subject);
|
||||
|
||||
for(int i = 0; !problematicItems.empty() && i < MAX_MAIL_ITEMS; ++i)
|
||||
{
|
||||
Item* item = problematicItems.front();
|
||||
problematicItems.pop_front();
|
||||
|
||||
mi.AddItem(item);
|
||||
draft.AddItem(item);
|
||||
}
|
||||
|
||||
std::string subject = GetSession()->GetMangosString(LANG_NOT_EQUIPPED_ITEM);
|
||||
|
||||
WorldSession::SendMailTo(this, MAIL_NORMAL, MAIL_STATIONERY_GM, GetGUIDLow(), GetGUIDLow(), subject, 0, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
|
||||
draft.SendMailTo(this, MailSender(this, MAIL_STATIONERY_GM));
|
||||
}
|
||||
}
|
||||
//if(isAlive())
|
||||
|
|
@ -18822,8 +18834,6 @@ void Player::AutoUnequipOffhandIfNeed()
|
|||
}
|
||||
else
|
||||
{
|
||||
MailItemsInfo mi;
|
||||
mi.AddItem(offItem);
|
||||
MoveItemFromInventory(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND, true);
|
||||
CharacterDatabase.BeginTransaction();
|
||||
offItem->DeleteFromInventoryDB(); // deletes item from character's inventory
|
||||
|
|
@ -18831,7 +18841,7 @@ void Player::AutoUnequipOffhandIfNeed()
|
|||
CharacterDatabase.CommitTransaction();
|
||||
|
||||
std::string subject = GetSession()->GetMangosString(LANG_NOT_EQUIPPED_ITEM);
|
||||
WorldSession::SendMailTo(this, MAIL_NORMAL, MAIL_STATIONERY_GM, GetGUIDLow(), GetGUIDLow(), subject, 0, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
|
||||
MailDraft(subject).AddItem(offItem).SendMailTo(this, MailSender(this, MAIL_STATIONERY_GM));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -20707,4 +20717,4 @@ void Player::SendDuelCountdown(uint32 counter)
|
|||
WorldPacket data(SMSG_DUEL_COUNTDOWN, 4);
|
||||
data << uint32(counter); // seconds
|
||||
GetSession()->SendPacket(&data);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue