TrinityCore
Loading...
Searching...
No Matches
Mail.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITY_MAIL_H
19#define TRINITY_MAIL_H
20
21#include "Common.h"
22#include "DatabaseEnvFwd.h"
23#include "ObjectGuid.h"
24#include <map>
25
26struct AuctionEntry;
27struct CalendarEvent;
28class Item;
29class Object;
30class Player;
31
32#define MAIL_BODY_ITEM_TEMPLATE 8383 // - plain letter, A Dusty Unsent Letter: 889
33#define MAX_MAIL_ITEMS 12
34
36{
39 MAIL_CREATURE = 3, // client send CMSG_CREATURE_QUERY on this mailmessagetype
40 MAIL_GAMEOBJECT = 4, // client send CMSG_GAMEOBJECT_QUERY on this mailmessagetype
42};
43
53
54// gathered from Stationery.dbc
65
72
74{
76 MAIL_SHOW_DELETE = 0x0002, // forced show delete button instead return button
77 MAIL_SHOW_AUCTION = 0x0004, // from old comment
78 MAIL_SHOW_UNK2 = 0x0008, // unknown, COD will be shown even without that flag
79 MAIL_SHOW_RETURN = 0x0010
80};
81
83{
84 public: // Constructors
85 MailSender(MailMessageType messageType, ObjectGuid::LowType sender_guidlow_or_entry, MailStationery stationery = MAIL_STATIONERY_DEFAULT)
86 : m_messageType(messageType), m_senderId(sender_guidlow_or_entry), m_stationery(stationery)
87 {
88 }
91 MailSender(AuctionEntry* sender);
92 MailSender(Player* sender);
93 MailSender(uint32 senderEntry);
94 public: // Accessors
95 MailMessageType GetMailMessageType() const { return m_messageType; }
96 ObjectGuid::LowType GetSenderId() const { return m_senderId; }
97 MailStationery GetStationery() const { return m_stationery; }
98 private:
100 ObjectGuid::LowType m_senderId; // player low guid or other object entry
102};
103
105{
106 public: // Constructors
107 explicit MailReceiver(ObjectGuid::LowType receiver_lowguid) : m_receiver(nullptr), m_receiver_lowguid(receiver_lowguid) { }
108 MailReceiver(Player* receiver);
109 MailReceiver(Player* receiver, ObjectGuid::LowType receiver_lowguid);
110 public: // Accessors
111 Player* GetPlayer() const { return m_receiver; }
112 ObjectGuid::LowType GetPlayerGUIDLow() const { return m_receiver_lowguid; }
113 private:
116};
117
119{
120 typedef std::map<ObjectGuid::LowType, Item*> MailItemMap;
121
122 public: // Constructors
123 explicit MailDraft(uint16 mailTemplateId, bool need_items = true)
124 : m_mailTemplateId(mailTemplateId), m_mailTemplateItemsNeed(need_items), m_money(0), m_COD(0)
125 { }
126 MailDraft(std::string const& subject, std::string const& body)
127 : m_mailTemplateId(0), m_mailTemplateItemsNeed(false), m_subject(subject), m_body(body), m_money(0), m_COD(0) { }
128 public: // Accessors
129 uint16 GetMailTemplateId() const { return m_mailTemplateId; }
130 std::string const& GetSubject() const { return m_subject; }
131 uint32 GetMoney() const { return m_money; }
132 uint32 GetCOD() const { return m_COD; }
133 std::string const& GetBody() const { return m_body; }
134
135 public: // modifiers
136 MailDraft& AddItem(Item* item);
137 MailDraft& AddMoney(uint32 money) { m_money = money; return *this; }
138 MailDraft& AddCOD(uint32 COD) { m_COD = COD; return *this; }
139
140 public: // finishers
141 void SendReturnToSender(uint32 sender_acc, ObjectGuid::LowType sender_guid, ObjectGuid::LowType receiver_guid, CharacterDatabaseTransaction trans);
142 void SendMailTo(CharacterDatabaseTransaction trans, MailReceiver const& receiver, MailSender const& sender, MailCheckMask checked = MAIL_CHECK_MASK_NONE, uint32 deliver_delay = 0);
143
144 private:
145 void deleteIncludedItems(CharacterDatabaseTransaction trans, bool inDB = false);
146 void prepareItems(Player* receiver, CharacterDatabaseTransaction trans); // called from SendMailTo for generate mailTemplateBase items
147
150 std::string m_subject;
151 std::string m_body;
152
153 MailItemMap m_items; // Keep the items in a map to avoid duplicate guids (which can happen), store only low part of guid
154
157};
158
164typedef std::vector<MailItemInfo> MailItemInfoVec;
165
167{
174 std::string subject;
175 std::string body;
176 std::vector<MailItemInfo> items;
177 std::vector<ObjectGuid::LowType> removedItems;
184
185 void AddItem(ObjectGuid::LowType itemGuidLow, uint32 item_template)
186 {
187 MailItemInfo mii;
188 mii.item_guid = itemGuidLow;
189 mii.item_template = item_template;
190 items.push_back(mii);
191 }
192
194 {
195 for (MailItemInfoVec::iterator itr = items.begin(); itr != items.end(); ++itr)
196 {
197 if (itr->item_guid == item_guid)
198 {
199 items.erase(itr);
200 return true;
201 }
202 }
203 return false;
204 }
205
206 bool HasItems() const { return !items.empty(); }
207};
208
209#endif
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
#define TC_GAME_API
Definition Define.h:114
uint8_t uint8
Definition Define.h:135
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
MailShowFlags
Definition Mail.h:74
@ MAIL_SHOW_UNK2
Definition Mail.h:78
@ MAIL_SHOW_UNK0
Definition Mail.h:75
@ MAIL_SHOW_DELETE
Definition Mail.h:76
@ MAIL_SHOW_RETURN
Definition Mail.h:79
@ MAIL_SHOW_AUCTION
Definition Mail.h:77
MailCheckMask
Definition Mail.h:45
@ MAIL_CHECK_MASK_HAS_BODY
Definition Mail.h:51
@ MAIL_CHECK_MASK_READ
Definition Mail.h:47
@ MAIL_CHECK_MASK_COD_PAYMENT
This mail was copied. Do not allow making a copy of items in mail.
Definition Mail.h:50
@ MAIL_CHECK_MASK_RETURNED
Definition Mail.h:48
@ MAIL_CHECK_MASK_NONE
Definition Mail.h:46
@ MAIL_CHECK_MASK_COPIED
This mail was returned. Do not allow returning mail back again.
Definition Mail.h:49
MailState
Definition Mail.h:67
@ MAIL_STATE_DELETED
Definition Mail.h:70
@ MAIL_STATE_CHANGED
Definition Mail.h:69
@ MAIL_STATE_UNCHANGED
Definition Mail.h:68
std::vector< MailItemInfo > MailItemInfoVec
Definition Mail.h:164
MailStationery
Definition Mail.h:56
@ MAIL_STATIONERY_TEST
Definition Mail.h:57
@ MAIL_STATIONERY_GM
Definition Mail.h:59
@ MAIL_STATIONERY_CHR
Definition Mail.h:62
@ MAIL_STATIONERY_ORP
Definition Mail.h:63
@ MAIL_STATIONERY_DEFAULT
Definition Mail.h:58
@ MAIL_STATIONERY_VAL
Definition Mail.h:61
@ MAIL_STATIONERY_AUCTION
Definition Mail.h:60
MailMessageType
Definition Mail.h:36
@ MAIL_AUCTION
Definition Mail.h:38
@ MAIL_GAMEOBJECT
Definition Mail.h:40
@ MAIL_CREATURE
Definition Mail.h:39
@ MAIL_CALENDAR
Definition Mail.h:41
@ MAIL_NORMAL
Definition Mail.h:37
Definition Item.h:62
uint32 GetCOD() const
Definition Mail.h:132
uint32 GetMoney() const
Definition Mail.h:131
MailDraft & AddMoney(uint32 money)
Definition Mail.h:137
MailItemMap m_items
Definition Mail.h:153
std::string const & GetSubject() const
Definition Mail.h:130
std::map< ObjectGuid::LowType, Item * > MailItemMap
Definition Mail.h:120
uint32 m_COD
Definition Mail.h:156
uint32 m_money
Definition Mail.h:155
uint16 m_mailTemplateId
Definition Mail.h:148
MailDraft(uint16 mailTemplateId, bool need_items=true)
Definition Mail.h:123
MailDraft & AddCOD(uint32 COD)
Definition Mail.h:138
MailDraft(std::string const &subject, std::string const &body)
Definition Mail.h:126
std::string m_subject
Definition Mail.h:150
bool m_mailTemplateItemsNeed
Definition Mail.h:149
uint16 GetMailTemplateId() const
Definition Mail.h:129
std::string const & GetBody() const
Definition Mail.h:133
std::string m_body
Definition Mail.h:151
Player * GetPlayer() const
Definition Mail.h:111
ObjectGuid::LowType GetPlayerGUIDLow() const
Definition Mail.h:112
Player * m_receiver
Definition Mail.h:114
ObjectGuid::LowType m_receiver_lowguid
Definition Mail.h:115
MailReceiver(ObjectGuid::LowType receiver_lowguid)
Definition Mail.h:107
MailStationery m_stationery
Definition Mail.h:101
ObjectGuid::LowType GetSenderId() const
Definition Mail.h:96
MailSender(MailMessageType messageType, ObjectGuid::LowType sender_guidlow_or_entry, MailStationery stationery=MAIL_STATIONERY_DEFAULT)
Definition Mail.h:85
MailMessageType m_messageType
Definition Mail.h:99
MailMessageType GetMailMessageType() const
Definition Mail.h:95
MailStationery GetStationery() const
Definition Mail.h:97
ObjectGuid::LowType m_senderId
Definition Mail.h:100
uint32 LowType
Definition ObjectGuid.h:142
ObjectGuid::LowType item_guid
Definition Mail.h:161
uint32 item_template
Definition Mail.h:162
Definition Mail.h:167
bool HasItems() const
Definition Mail.h:206
ObjectGuid::LowType receiver
Definition Mail.h:173
uint8 messageType
Definition Mail.h:169
uint32 messageID
Definition Mail.h:168
time_t expire_time
Definition Mail.h:178
uint8 stationery
Definition Mail.h:170
ObjectGuid::LowType sender
Definition Mail.h:172
std::string subject
Definition Mail.h:174
std::vector< ObjectGuid::LowType > removedItems
Definition Mail.h:177
std::string body
Definition Mail.h:175
std::vector< MailItemInfo > items
Definition Mail.h:176
void AddItem(ObjectGuid::LowType itemGuidLow, uint32 item_template)
Definition Mail.h:185
bool RemoveItem(ObjectGuid::LowType item_guid)
Definition Mail.h:193
time_t deliver_time
Definition Mail.h:179
uint32 COD
Definition Mail.h:181
uint32 checked
Definition Mail.h:182
MailState state
Definition Mail.h:183
uint32 money
Definition Mail.h:180
uint16 mailTemplateId
Definition Mail.h:171