2 * Copyright (C) 2005-2009 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
29 #define MAIL_BODY_ITEM_TEMPLATE 8383 // - plain letter, A Dusty Unsent Letter: 889
30 #define MAX_MAIL_ITEMS 12
36 MAIL_CREATURE
= 3, // client send CMSG_CREATURE_QUERY on this mailmessagetype
37 MAIL_GAMEOBJECT
= 4, // client send CMSG_GAMEOBJECT_QUERY on this mailmessagetype
38 MAIL_ITEM
= 5, // client send CMSG_ITEM_QUERY on this mailmessagetype
43 MAIL_CHECK_MASK_NONE
= 0x00,
44 MAIL_CHECK_MASK_READ
= 0x01,
45 MAIL_CHECK_MASK_AUCTION
= 0x04,
46 MAIL_CHECK_MASK_COD_PAYMENT
= 0x08,
47 MAIL_CHECK_MASK_RETURNED
= 0x10
50 // gathered from Stationery.dbc
53 MAIL_STATIONERY_UNKNOWN
= 1,
54 MAIL_STATIONERY_NORMAL
= 41,
55 MAIL_STATIONERY_GM
= 61,
56 MAIL_STATIONERY_AUCTION
= 62,
57 MAIL_STATIONERY_VAL
= 64,
58 MAIL_STATIONERY_CHR
= 65,
59 MAIL_STATIONERY_ORP
= 67, // new in 3.2.2
64 MAIL_STATE_UNCHANGED
= 1,
65 MAIL_STATE_CHANGED
= 2,
66 MAIL_STATE_DELETED
= 3
69 enum MailAuctionAnswers
71 AUCTION_OUTBIDDED
= 0,
73 AUCTION_SUCCESSFUL
= 2,
75 AUCTION_CANCELLED_TO_BIDDER
= 4,
77 AUCTION_SALE_PENDING
= 6
82 public: // Constructors
83 MailSender(MailMessageType messageType
, uint32 sender_guidlow_or_entry
, MailStationery stationery
= MAIL_STATIONERY_NORMAL
)
84 : m_messageType(messageType
), m_senderId(sender_guidlow_or_entry
), m_stationery(stationery
)
87 MailSender(Object
* sender
, MailStationery stationery
= MAIL_STATIONERY_NORMAL
);
88 MailSender(AuctionEntry
* sender
);
90 MailMessageType
GetMailMessageType() const { return m_messageType
; }
91 uint32
GetSenderId() const { return m_senderId
; }
92 MailStationery
GetStationery() const { return m_stationery
; }
94 MailMessageType m_messageType
;
95 uint32 m_senderId
; // player low guid or other object entry
96 MailStationery m_stationery
;
101 public: // Constructors
102 explicit MailReceiver(uint32 receiver_lowguid
) : m_receiver(NULL
), m_receiver_lowguid(receiver_lowguid
) {}
103 MailReceiver(Player
* receiver
);
104 MailReceiver(Player
* receiver
,uint32 receiver_lowguid
);
106 Player
* GetPlayer() const { return m_receiver
; }
107 uint32
GetPlayerGUIDLow() const { return m_receiver_lowguid
; }
110 uint32 m_receiver_lowguid
;
115 typedef std::map
<uint32
, Item
*> MailItemMap
;
117 public: // Constructors
118 explicit MailDraft(uint16 mailTemplateId
, bool need_items
= true)
119 : m_mailTemplateId(mailTemplateId
), m_mailTemplateItemsNeed(need_items
), m_bodyId(0), m_money(0), m_COD(0)
121 MailDraft(std::string subject
, uint32 itemTextId
= 0)
122 : m_mailTemplateId(0), m_mailTemplateItemsNeed(false), m_subject(subject
), m_bodyId(itemTextId
), m_money(0), m_COD(0) {}
124 uint16
GetMailTemplateId() const { return m_mailTemplateId
; }
125 std::string
const& GetSubject() const { return m_subject
; }
126 uint32
GetBodyId() const { return m_bodyId
; }
127 uint32
GetMoney() const { return m_money
; }
128 uint32
GetCOD() const { return m_COD
; }
130 MailDraft
& AddItem(Item
* item
);
131 MailDraft
& AddMoney(uint32 money
) { m_money
= money
; return *this; }
132 MailDraft
& AddCOD(uint32 COD
) { m_COD
= COD
; return *this; }
134 void SendReturnToSender(uint32 sender_acc
, uint32 sender_guid
, uint32 receiver_guid
);
135 void SendMailTo(MailReceiver
const& receiver
, MailSender
const& sender
, MailCheckMask checked
= MAIL_CHECK_MASK_NONE
, uint32 deliver_delay
= 0);
137 void deleteIncludedItems(bool inDB
= false);
138 void prepareItems(Player
* receiver
); // called from SendMailTo for generate mailTemplateBase items
140 uint16 m_mailTemplateId
;
141 bool m_mailTemplateItemsNeed
;
142 std::string m_subject
;
145 MailItemMap m_items
; // Keep the items in a map to avoid duplicate guids (which can happen), store only low part of guid
154 uint32 item_template
;
162 uint16 mailTemplateId
;
167 std::vector
<MailItemInfo
> items
;
168 std::vector
<uint32
> removedItems
;
176 void AddItem(uint32 itemGuidLow
, uint32 item_template
)
179 mii
.item_guid
= itemGuidLow
;
180 mii
.item_template
= item_template
;
181 items
.push_back(mii
);
184 bool RemoveItem(uint32 item_guid
)
186 for(std::vector
<MailItemInfo
>::iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
188 if(itr
->item_guid
== item_guid
)
197 bool HasItems() const { return !items
.empty(); }