TrinityCore
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 CalendarEvent;
29class Item;
30class Object;
31class Player;
32
33#define MAIL_BODY_ITEM_TEMPLATE 8383 // - plain letter, A Dusty Unsent Letter: 889
34#define MAX_CLIENT_MAIL_ITEMS 12 // max number of items a player is allowed to attach
35#define MAX_MAIL_ITEMS 16
36
38{
41 MAIL_CREATURE = 3, // client send CMSG_CREATURE_QUERY on this mailmessagetype
42 MAIL_GAMEOBJECT = 4, // client send CMSG_GAMEOBJECT_QUERY on this mailmessagetype
45 MAIL_COMMERCE_AUCTION = 7, // wow token auction
47 MAIL_ARTISANS_CONSORTIUM = 9 // crafting orders
48};
49
51{
58};
59
60// gathered from Stationery.dbc
62{
67 MAIL_STATIONERY_VAL = 64, // Valentine
68 MAIL_STATIONERY_CHR = 65, // Christmas
69 MAIL_STATIONERY_ORP = 67 // Orphan
70};
71
73{
77};
78
80{
82 MAIL_SHOW_DELETE = 0x0002, // forced show delete button instead return button
83 MAIL_SHOW_AUCTION = 0x0004, // from old comment
84 MAIL_SHOW_UNK2 = 0x0008, // unknown, COD will be shown even without that flag
85 MAIL_SHOW_RETURN = 0x0010
86};
87
89{
90 public: // Constructors
91 MailSender(MailMessageType messageType, ObjectGuid::LowType sender_guidlow_or_entry, MailStationery stationery = MAIL_STATIONERY_DEFAULT)
92 : m_messageType(messageType), m_senderId(sender_guidlow_or_entry), m_stationery(stationery)
93 {
94 }
97 MailSender(AuctionHouseObject const* sender);
99 MailSender(Player* sender);
100 MailSender(uint32 senderEntry);
101 public: // Accessors
102 MailMessageType GetMailMessageType() const { return m_messageType; }
103 ObjectGuid::LowType GetSenderId() const { return m_senderId; }
104 MailStationery GetStationery() const { return m_stationery; }
105 private:
107 ObjectGuid::LowType m_senderId; // player low guid or other object entry
109};
110
112{
113 public: // Constructors
114 explicit MailReceiver(ObjectGuid::LowType receiver_lowguid) : m_receiver(nullptr), m_receiver_lowguid(receiver_lowguid) { }
115 MailReceiver(Player* receiver);
116 MailReceiver(Player* receiver, ObjectGuid::LowType receiver_lowguid);
117 MailReceiver(Player* receiver, ObjectGuid receiverGuid);
118 public: // Accessors
119 Player* GetPlayer() const { return m_receiver; }
120 ObjectGuid::LowType GetPlayerGUIDLow() const { return m_receiver_lowguid; }
121 private:
124};
125
127{
128 typedef std::map<ObjectGuid::LowType, Item*> MailItemMap;
129
130 public: // Constructors
131 explicit MailDraft(uint16 mailTemplateId, bool need_items = true)
132 : m_mailTemplateId(mailTemplateId), m_mailTemplateItemsNeed(need_items), m_money(0), m_COD(0)
133 { }
134 MailDraft(std::string const& subject, std::string const& body)
135 : m_mailTemplateId(0), m_mailTemplateItemsNeed(false), m_subject(subject), m_body(body), m_money(0), m_COD(0) { }
136 public: // Accessors
137 uint16 GetMailTemplateId() const { return m_mailTemplateId; }
138 std::string const& GetSubject() const { return m_subject; }
139 uint64 GetMoney() const { return m_money; }
140 uint64 GetCOD() const { return m_COD; }
141 std::string const& GetBody() const { return m_body; }
142
143 public: // modifiers
144 MailDraft& AddItem(Item* item);
145 MailDraft& AddMoney(uint64 money) { m_money = money; return *this; }
146 MailDraft& AddCOD(uint64 COD) { m_COD = COD; return *this; }
147
148 public: // finishers
149 void SendReturnToSender(uint32 sender_acc, ObjectGuid::LowType sender_guid, ObjectGuid::LowType receiver_guid, CharacterDatabaseTransaction trans);
150 void SendMailTo(CharacterDatabaseTransaction trans, MailReceiver const& receiver, MailSender const& sender, MailCheckMask checked = MAIL_CHECK_MASK_NONE, uint32 deliver_delay = 0);
151
152 private:
153 void deleteIncludedItems(CharacterDatabaseTransaction trans, bool inDB = false);
154 void prepareItems(Player* receiver, CharacterDatabaseTransaction trans); // called from SendMailTo for generate mailTemplateBase items
155
158 std::string m_subject;
159 std::string m_body;
160
161 MailItemMap m_items; // Keep the items in a map to avoid duplicate guids (which can happen), store only low part of guid
162
165};
166
168{
171};
172typedef std::vector<MailItemInfo> MailItemInfoVec;
173
175{
180 ObjectGuid::LowType sender; // TODO: change to uint64 and store full guids
182 std::string subject;
183 std::string body;
184 std::vector<MailItemInfo> items;
185 std::vector<ObjectGuid::LowType> removedItems;
192
193 void AddItem(ObjectGuid::LowType itemGuidLow, uint32 item_template)
194 {
195 MailItemInfo mii;
196 mii.item_guid = itemGuidLow;
197 mii.item_template = item_template;
198 items.push_back(mii);
199 }
200
202 {
203 for (MailItemInfoVec::iterator itr = items.begin(); itr != items.end(); ++itr)
204 {
205 if (itr->item_guid == item_guid)
206 {
207 items.erase(itr);
208 return true;
209 }
210 }
211 return false;
212 }
213
214 bool HasItems() const { return !items.empty(); }
215};
216
217#endif
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
#define TC_GAME_API
Definition: Define.h:123
uint8_t uint8
Definition: Define.h:144
uint64_t uint64
Definition: Define.h:141
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
MailShowFlags
Definition: Mail.h:80
@ MAIL_SHOW_UNK2
Definition: Mail.h:84
@ MAIL_SHOW_UNK0
Definition: Mail.h:81
@ MAIL_SHOW_DELETE
Definition: Mail.h:82
@ MAIL_SHOW_RETURN
Definition: Mail.h:85
@ MAIL_SHOW_AUCTION
Definition: Mail.h:83
MailCheckMask
Definition: Mail.h:51
@ MAIL_CHECK_MASK_HAS_BODY
Definition: Mail.h:57
@ MAIL_CHECK_MASK_READ
Definition: Mail.h:53
@ MAIL_CHECK_MASK_COD_PAYMENT
This mail was copied. Do not allow making a copy of items in mail.
Definition: Mail.h:56
@ MAIL_CHECK_MASK_RETURNED
Definition: Mail.h:54
@ MAIL_CHECK_MASK_NONE
Definition: Mail.h:52
@ MAIL_CHECK_MASK_COPIED
This mail was returned. Do not allow returning mail back again.
Definition: Mail.h:55
MailState
Definition: Mail.h:73
@ MAIL_STATE_DELETED
Definition: Mail.h:76
@ MAIL_STATE_CHANGED
Definition: Mail.h:75
@ MAIL_STATE_UNCHANGED
Definition: Mail.h:74
std::vector< MailItemInfo > MailItemInfoVec
Definition: Mail.h:172
MailStationery
Definition: Mail.h:62
@ MAIL_STATIONERY_TEST
Definition: Mail.h:63
@ MAIL_STATIONERY_GM
Definition: Mail.h:65
@ MAIL_STATIONERY_CHR
Definition: Mail.h:68
@ MAIL_STATIONERY_ORP
Definition: Mail.h:69
@ MAIL_STATIONERY_DEFAULT
Definition: Mail.h:64
@ MAIL_STATIONERY_VAL
Definition: Mail.h:67
@ MAIL_STATIONERY_AUCTION
Definition: Mail.h:66
MailMessageType
Definition: Mail.h:38
@ MAIL_AUCTION
Definition: Mail.h:40
@ MAIL_BLACKMARKET
Definition: Mail.h:44
@ MAIL_GAMEOBJECT
Definition: Mail.h:42
@ MAIL_CREATURE
Definition: Mail.h:41
@ MAIL_COMMERCE_AUCTION
Definition: Mail.h:45
@ MAIL_AUCTION_2
Definition: Mail.h:46
@ MAIL_CALENDAR
Definition: Mail.h:43
@ MAIL_NORMAL
Definition: Mail.h:39
@ MAIL_ARTISANS_CONSORTIUM
Definition: Mail.h:47
Definition: Item.h:170
uint64 GetCOD() const
Definition: Mail.h:140
uint64 m_money
Definition: Mail.h:163
MailItemMap m_items
Definition: Mail.h:161
std::string const & GetSubject() const
Definition: Mail.h:138
std::map< ObjectGuid::LowType, Item * > MailItemMap
Definition: Mail.h:128
MailDraft & AddCOD(uint64 COD)
Definition: Mail.h:146
uint16 m_mailTemplateId
Definition: Mail.h:156
MailDraft(uint16 mailTemplateId, bool need_items=true)
Definition: Mail.h:131
MailDraft(std::string const &subject, std::string const &body)
Definition: Mail.h:134
std::string m_subject
Definition: Mail.h:158
bool m_mailTemplateItemsNeed
Definition: Mail.h:157
uint16 GetMailTemplateId() const
Definition: Mail.h:137
uint64 m_COD
Definition: Mail.h:164
std::string const & GetBody() const
Definition: Mail.h:141
std::string m_body
Definition: Mail.h:159
MailDraft & AddMoney(uint64 money)
Definition: Mail.h:145
uint64 GetMoney() const
Definition: Mail.h:139
Player * GetPlayer() const
Definition: Mail.h:119
ObjectGuid::LowType GetPlayerGUIDLow() const
Definition: Mail.h:120
Player * m_receiver
Definition: Mail.h:122
ObjectGuid::LowType m_receiver_lowguid
Definition: Mail.h:123
MailReceiver(ObjectGuid::LowType receiver_lowguid)
Definition: Mail.h:114
MailStationery m_stationery
Definition: Mail.h:108
ObjectGuid::LowType GetSenderId() const
Definition: Mail.h:103
MailSender(MailMessageType messageType, ObjectGuid::LowType sender_guidlow_or_entry, MailStationery stationery=MAIL_STATIONERY_DEFAULT)
Definition: Mail.h:91
MailMessageType m_messageType
Definition: Mail.h:106
MailMessageType GetMailMessageType() const
Definition: Mail.h:102
MailStationery GetStationery() const
Definition: Mail.h:104
ObjectGuid::LowType m_senderId
Definition: Mail.h:107
uint64 LowType
Definition: ObjectGuid.h:278
Definition: Object.h:150
ObjectGuid::LowType item_guid
Definition: Mail.h:169
uint32 item_template
Definition: Mail.h:170
Definition: Mail.h:175
uint64 messageID
Definition: Mail.h:176
bool HasItems() const
Definition: Mail.h:214
ObjectGuid::LowType receiver
Definition: Mail.h:181
uint8 messageType
Definition: Mail.h:177
uint64 money
Definition: Mail.h:188
uint64 COD
Definition: Mail.h:189
time_t expire_time
Definition: Mail.h:186
uint8 stationery
Definition: Mail.h:178
ObjectGuid::LowType sender
Definition: Mail.h:180
std::string subject
Definition: Mail.h:182
std::vector< ObjectGuid::LowType > removedItems
Definition: Mail.h:185
std::string body
Definition: Mail.h:183
std::vector< MailItemInfo > items
Definition: Mail.h:184
void AddItem(ObjectGuid::LowType itemGuidLow, uint32 item_template)
Definition: Mail.h:193
bool RemoveItem(ObjectGuid::LowType item_guid)
Definition: Mail.h:201
time_t deliver_time
Definition: Mail.h:187
uint32 checked
Definition: Mail.h:190
MailState state
Definition: Mail.h:191
uint16 mailTemplateId
Definition: Mail.h:179