TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Mail.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef TRINITY_MAIL_H
20 #define TRINITY_MAIL_H
21 
22 #include "Common.h"
23 #include "ObjectGuid.h"
24 #include "Transaction.h"
25 #include <map>
26 
27 struct AuctionEntry;
28 struct CalendarEvent;
29 class Item;
30 class Object;
31 class Player;
32 
33 #define MAIL_BODY_ITEM_TEMPLATE 8383 // - plain letter, A Dusty Unsent Letter: 889
34 #define MAX_MAIL_ITEMS 12
35 
37 {
40  MAIL_CREATURE = 3, // client send CMSG_CREATURE_QUERY on this mailmessagetype
41  MAIL_GAMEOBJECT = 4, // client send CMSG_GAMEOBJECT_QUERY on this mailmessagetype
43 };
44 
46 {
53 };
54 
55 // gathered from Stationery.dbc
57 {
62  MAIL_STATIONERY_VAL = 64, // Valentine
63  MAIL_STATIONERY_CHR = 65, // Christmas
64  MAIL_STATIONERY_ORP = 67 // Orphan
65 };
66 
68 {
72 };
73 
75 {
76  MAIL_SHOW_UNK0 = 0x0001,
77  MAIL_SHOW_DELETE = 0x0002, // forced show delete button instead return button
78  MAIL_SHOW_AUCTION = 0x0004, // from old comment
79  MAIL_SHOW_UNK2 = 0x0008, // unknown, COD will be shown even without that flag
81 };
82 
84 {
85  public: // Constructors
86  MailSender(MailMessageType messageType, ObjectGuid::LowType sender_guidlow_or_entry, MailStationery stationery = MAIL_STATIONERY_DEFAULT)
87  : m_messageType(messageType), m_senderId(sender_guidlow_or_entry), m_stationery(stationery)
88  {
89  }
91  MailSender(CalendarEvent* sender);
92  MailSender(AuctionEntry* sender);
93  MailSender(Player* sender);
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(NULL), 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  uint64 GetMoney() const { return m_money; }
132  uint64 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(uint64 money) { m_money = money; return *this; }
138  MailDraft& AddCOD(uint64 COD) { m_COD = COD; return *this; }
139 
140  public: // finishers
141  void SendReturnToSender(uint32 sender_acc, ObjectGuid::LowType sender_guid, ObjectGuid::LowType receiver_guid, SQLTransaction& trans);
142  void SendMailTo(SQLTransaction& trans, MailReceiver const& receiver, MailSender const& sender, MailCheckMask checked = MAIL_CHECK_MASK_NONE, uint32 deliver_delay = 0);
143 
144  private:
145  void deleteIncludedItems(SQLTransaction& trans, bool inDB = false);
146  void prepareItems(Player* receiver, SQLTransaction& 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 
160 {
163 };
164 typedef std::vector<MailItemInfo> MailItemInfoVec;
165 
167 {
172  ObjectGuid::LowType sender; // TODO: change to uint64 and store full guids
174  std::string subject;
175  std::string body;
176  std::vector<MailItemInfo> items;
177  std::vector<ObjectGuid::LowType> removedItems;
178  time_t expire_time;
179  time_t deliver_time;
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
Definition: Object.h:95
std::vector< MailItemInfo > items
Definition: Mail.h:176
std::vector< MailItemInfo > MailItemInfoVec
Definition: Mail.h:164
MailItemMap m_items
Definition: Mail.h:153
uint16 mailTemplateId
Definition: Mail.h:171
This mail was copied. Do not allow making a copy of items in mail.
Definition: Mail.h:51
bool m_mailTemplateItemsNeed
Definition: Mail.h:149
MailSender(MailMessageType messageType, ObjectGuid::LowType sender_guidlow_or_entry, MailStationery stationery=MAIL_STATIONERY_DEFAULT)
Definition: Mail.h:86
ObjectGuid::LowType GetPlayerGUIDLow() const
Definition: Mail.h:112
Definition: Mail.h:61
uint16 GetMailTemplateId() const
Definition: Mail.h:129
Definition: Mail.h:58
Definition: Mail.h:39
MailDraft(std::string const &subject, std::string const &body)
Definition: Mail.h:126
ObjectGuid::LowType m_senderId
Definition: Mail.h:100
uint8 messageType
Definition: Mail.h:169
MailDraft & AddCOD(uint64 COD)
Definition: Mail.h:138
MailState state
Definition: Mail.h:183
MailMessageType GetMailMessageType() const
Definition: Mail.h:95
Definition: Mail.h:60
uint32 checked
Definition: Mail.h:182
Definition: Mail.h:70
Definition: AuctionHouseMgr.h:67
uint8 stationery
Definition: Mail.h:170
arena_t NULL
Definition: jemalloc_internal.h:624
uint64 COD
Definition: Mail.h:181
Definition: Mail.h:78
#define false
Definition: CascPort.h:18
uint32 item_template
Definition: Mail.h:162
Definition: Mail.h:38
ObjectGuid::LowType receiver
Definition: Mail.h:173
std::string m_body
Definition: Mail.h:151
std::map< ObjectGuid::LowType, Item * > MailItemMap
Definition: Mail.h:120
Definition: Mail.h:63
uint64 m_COD
Definition: Mail.h:156
uint64 LowType
Definition: ObjectGuid.h:199
MailMessageType
Definition: Mail.h:36
This mail was returned. Do not allow returning mail back again.
Definition: Mail.h:50
MailState
Definition: Mail.h:67
Definition: Mail.h:52
uint64 m_money
Definition: Mail.h:155
uint64 money
Definition: Mail.h:180
Definition: Mail.h:159
MailCheckMask
Definition: Mail.h:45
std::string body
Definition: Mail.h:175
Definition: Mail.h:47
Definition: Mail.h:166
Definition: Mail.h:118
Definition: Mail.h:77
uint64 GetMoney() const
Definition: Mail.h:131
Definition: Mail.h:42
bool HasItems() const
Definition: Mail.h:206
Player * m_receiver
Definition: Mail.h:114
MailDraft(uint16 mailTemplateId, bool need_items=true)
Definition: Mail.h:123
Definition: CalendarMgr.h:191
Definition: Mail.h:41
Definition: Mail.h:64
ObjectGuid::LowType item_guid
Definition: Mail.h:161
ObjectGuid::LowType m_receiver_lowguid
Definition: Mail.h:115
Definition: Item.h:259
Definition: Mail.h:59
std::string const & GetBody() const
Definition: Mail.h:133
uint32_t uint32
Definition: Define.h:150
time_t deliver_time
Definition: Mail.h:179
uint64_t uint64
Definition: Define.h:149
uint16_t uint16
Definition: Define.h:151
MailShowFlags
Definition: Mail.h:74
uint16 m_mailTemplateId
Definition: Mail.h:148
Definition: Mail.h:71
std::string const & GetSubject() const
Definition: Mail.h:130
Definition: Mail.h:79
MailStationery
Definition: Mail.h:56
Definition: Mail.h:80
Definition: Mail.h:48
MailStationery GetStationery() const
Definition: Mail.h:97
Definition: Mail.h:76
time_t expire_time
Definition: Mail.h:178
ObjectGuid::LowType GetSenderId() const
Definition: Mail.h:96
Player * GetPlayer() const
Definition: Mail.h:111
#define TC_GAME_API
Definition: Define.h:134
std::string subject
Definition: Mail.h:174
void AddItem(ObjectGuid::LowType itemGuidLow, uint32 item_template)
Definition: Mail.h:185
std::string m_subject
Definition: Mail.h:150
MailReceiver(ObjectGuid::LowType receiver_lowguid)
Definition: Mail.h:107
MailDraft & AddMoney(uint64 money)
Definition: Mail.h:137
uint8_t uint8
Definition: Define.h:152
MailMessageType m_messageType
Definition: Mail.h:99
Definition: Mail.h:49
uint32 messageID
Definition: Mail.h:168
Definition: Mail.h:40
Definition: Mail.h:62
Definition: Mail.h:104
uint64 GetCOD() const
Definition: Mail.h:132
bool RemoveItem(ObjectGuid::LowType item_guid)
Definition: Mail.h:193
MailStationery m_stationery
Definition: Mail.h:101
std::vector< ObjectGuid::LowType > removedItems
Definition: Mail.h:177
Definition: Mail.h:83
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58
Definition: Mail.h:69
ObjectGuid::LowType sender
Definition: Mail.h:172