2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * @addtogroup mailing The mail system
21 * The mailing system in MaNGOS consists of mostly two files:
28 * This file contains the the headers needed for MaNGOS to handle mails.
43 #define MAIL_BODY_ITEM_TEMPLATE 8383 ///< - plain letter, A Dusty Unsent Letter: 889
44 /// The maximal amount of items a mail can contain.
45 #define MAX_MAIL_ITEMS 12
47 * The type of the mail.
48 * A mail can have 5 Different Types.
54 MAIL_CREATURE
= 3, /// client send CMSG_CREATURE_QUERY on this mailmessagetype
55 MAIL_GAMEOBJECT
= 4, /// client send CMSG_GAMEOBJECT_QUERY on this mailmessagetype
56 MAIL_ITEM
= 5, /// client send CMSG_ITEM_QUERY on this mailmessagetype
59 * A Mask representing the status of the mail.
63 MAIL_CHECK_MASK_NONE
= 0x00,
64 MAIL_CHECK_MASK_READ
= 0x01, /// This mail was read.
65 MAIL_CHECK_MASK_AUCTION
= 0x04, /// This mail was from an auction.
66 MAIL_CHECK_MASK_COD_PAYMENT
= 0x08, /// This mail is payable on delivery.
67 MAIL_CHECK_MASK_RETURNED
= 0x10 /// This mail has been returned.
71 * The different types of Stationaries that exist for mails.
72 * They have been gathered from Stationery.dbc
76 MAIL_STATIONERY_UNKNOWN
= 1,
77 MAIL_STATIONERY_NORMAL
= 41,
78 MAIL_STATIONERY_GM
= 61,
79 MAIL_STATIONERY_AUCTION
= 62,
80 MAIL_STATIONERY_VAL
= 64,
81 MAIL_STATIONERY_CHR
= 65,
82 MAIL_STATIONERY_ORP
= 67, // new in 3.2.2
85 * Representation of the State of a mail.
89 MAIL_STATE_UNCHANGED
= 1,
90 MAIL_STATE_CHANGED
= 2,
91 MAIL_STATE_DELETED
= 3
94 * Answers contained in mails from auctionhouses.
96 enum MailAuctionAnswers
98 AUCTION_OUTBIDDED
= 0,
100 AUCTION_SUCCESSFUL
= 2,
102 AUCTION_CANCELLED_TO_BIDDER
= 4,
103 AUCTION_CANCELED
= 5,
104 AUCTION_SALE_PENDING
= 6
107 * A class to represent the sender of a mail.
111 public: // Constructors
113 * Creates a new MailSender object.
115 * @param messageType the type of the mail.
116 * @param sender_guidlow_or_entry The lower part of the GUID of the player sending
117 * this mail, or the Entry of the non-player object.
118 * @param stationery The stationary associated with this MailSender.
121 MailSender(MailMessageType messageType
, uint32 sender_guidlow_or_entry
, MailStationery stationery
= MAIL_STATIONERY_NORMAL
)
122 : m_messageType(messageType
), m_senderId(sender_guidlow_or_entry
), m_stationery(stationery
)
125 MailSender(Object
* sender
, MailStationery stationery
= MAIL_STATIONERY_NORMAL
);
126 MailSender(AuctionEntry
* sender
);
128 /// The Messagetype of this MailSender.
129 MailMessageType
GetMailMessageType() const { return m_messageType
; }
130 /// The GUID of the player represented by this MailSender, or the Entry of the non-player object.
131 uint32
GetSenderId() const { return m_senderId
; }
132 /// The stationary associated with this MailSender
133 MailStationery
GetStationery() const { return m_stationery
; }
135 MailMessageType m_messageType
;
136 uint32 m_senderId
; // player low guid or other object entry
137 MailStationery m_stationery
;
140 * A class to represent the receiver of a mail.
144 public: // Constructors
145 explicit MailReceiver(uint32 receiver_lowguid
) : m_receiver(NULL
), m_receiver_lowguid(receiver_lowguid
) {}
146 MailReceiver(Player
* receiver
);
147 MailReceiver(Player
* receiver
,uint32 receiver_lowguid
);
150 * Gets the player associated with this MailReciever
154 * @returns a pointer to the Player this mail is for.
157 Player
* GetPlayer() const { return m_receiver
; }
159 * Gets the low part of the recievers GUID.
161 * @returns the low part of the GUID of the player associated with this MailReciever
163 uint32
GetPlayerGUIDLow() const { return m_receiver_lowguid
; }
166 uint32 m_receiver_lowguid
;
169 * The class to represent the draft of a mail.
174 * Holds a Map of GUIDs of items and pointers to the items.
176 typedef std::map
<uint32
, Item
*> MailItemMap
;
178 public: // Constructors
180 * Creates a new MailDraft object.
182 * @param mailTemplateId The ID of the Template to be used.
183 * @param a boolean specifying whether the mail needs items or not.
186 explicit MailDraft(uint16 mailTemplateId
, bool need_items
= true)
187 : m_mailTemplateId(mailTemplateId
), m_mailTemplateItemsNeed(need_items
), m_bodyId(0), m_money(0), m_COD(0)
190 * Creates a new MailDraft object.
192 * @param subject The subject of the mail.
193 * @param itemTextId The id of the body of the mail.
195 MailDraft(std::string subject
, uint32 itemTextId
= 0)
196 : m_mailTemplateId(0), m_mailTemplateItemsNeed(false), m_subject(subject
), m_bodyId(itemTextId
), m_money(0), m_COD(0) {}
198 /// Returns the template ID used for this MailDraft.
199 uint16
GetMailTemplateId() const { return m_mailTemplateId
; }
200 /// Returns the subject of this MailDraft.
201 std::string
const& GetSubject() const { return m_subject
; }
202 /// Returns the ID of the text of this MailDraft.
203 uint32
GetBodyId() const { return m_bodyId
; }
204 /// Returns the ammount of money in this MailDraft.
205 uint32
GetMoney() const { return m_money
; }
206 /// Returns the Cost of delivery of this MailDraft.
207 uint32
GetCOD() const { return m_COD
; }
209 MailDraft
& AddItem(Item
* item
);
211 * Modifies the amount of money in a MailDraft.
213 * @param money The amount of money included in this MailDraft.
215 MailDraft
& AddMoney(uint32 money
) { m_money
= money
; return *this; }
217 * Modifies the cost of delivery of the MailDraft.
219 * @param COD the amount to which the cod should be set.
221 MailDraft
& AddCOD(uint32 COD
) { m_COD
= COD
; return *this; }
223 void SendReturnToSender(uint32 sender_acc
, uint32 sender_guid
, uint32 receiver_guid
);
224 void SendMailTo(MailReceiver
const& receiver
, MailSender
const& sender
, MailCheckMask checked
= MAIL_CHECK_MASK_NONE
, uint32 deliver_delay
= 0);
226 void deleteIncludedItems(bool inDB
= false);
227 void prepareItems(Player
* receiver
); ///< called from SendMailTo for generate mailTemplateBase items
229 /// The ID of the template associated with this MailDraft.
230 uint16 m_mailTemplateId
;
231 /// Boolean specifying whether items are required or not.
232 bool m_mailTemplateItemsNeed
;
233 /// The subject of the MailDraft.
234 std::string m_subject
;
235 /// The ID of the body of the MailDraft.
237 /// A map of items in this MailDraft.
238 MailItemMap m_items
; ///< Keep the items in a map to avoid duplicate guids (which can happen), store only low part of guid
240 /// The amount of money in this MailDraft.
242 /// The cod amount of this MailDraft.
246 * Structure holding information about an item in the mail.
250 uint32 item_guid
; ///< the GUID of the item.
251 uint32 item_template
; ///< the ID of the template of the item.
254 * Structure that holds an actual mail.
258 /// the ID of the message contained in the mail.
260 /// the type of the message
262 /// the stationary used in this mail.
264 /// the ID of the template this mail is based on.
265 uint16 mailTemplateId
;
266 /// the GUID of the player that sent this mail.
268 /// the GUID of the player that this mail is sent to.
270 /// the subject of the mail
272 /// The ID of the itemtext.
274 /// A vector containing Information about the items in this mail.
275 std::vector
<MailItemInfo
> items
;
276 /// A vector containing Information about the items that where already take from this mail.
277 std::vector
<uint32
> removedItems
;
278 /// The time at which this mail will expire
280 /// The time at which this mail (was/will be) delivered
282 /// The amount of money contained in this mail.
284 /// The amount of money the receiver has to pay to get this mail.
286 /// The time at which this mail was read.
288 /// The state of this mail.
292 * Adds an item to the mail.
293 * This method adds an item to mail represented by this structure.
294 * There is no checking done whether this is a legal action or not; it is up
295 * to the caller to make sure there is still room for more items in the mail.
297 * @param itemGuidLow the GUID(low) of the item added to the mail.
298 * @param item_template the ID of the template of the item.
301 void AddItem(uint32 itemGuidLow
, uint32 item_template
)
304 mii
.item_guid
= itemGuidLow
;
305 mii
.item_template
= item_template
;
306 items
.push_back(mii
);
310 * Removes an item from the mail.
311 * This method removes an item from the mail.
315 * @param item_guid The GUID of the item to be removed.
316 * @returns true if the item was removed, or false if no item with that GUID was found.
319 bool RemoveItem(uint32 item_guid
)
321 for(std::vector
<MailItemInfo
>::iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
323 if(itr
->item_guid
== item_guid
)
333 * Checks whether a mail contains items or not.
334 * HasItems() checks wether the mail contains items or not.
336 * @returns true if the mail contains items, false otherwise.
339 bool HasItems() const { return !items
.empty(); }