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
27 #define MAIL_BODY_ITEM_TEMPLATE 8383 // - plain letter, A Dusty Unsent Letter: 889
28 #define MAX_MAIL_ITEMS 12
34 MAIL_CREATURE
= 3, // client send CMSG_CREATURE_QUERY on this mailmessagetype
35 MAIL_GAMEOBJECT
= 4, // client send CMSG_GAMEOBJECT_QUERY on this mailmessagetype
36 MAIL_ITEM
= 5, // client send CMSG_ITEM_QUERY on this mailmessagetype
41 MAIL_STATE_UNCHANGED
= 1,
42 MAIL_STATE_CHANGED
= 2,
43 MAIL_STATE_DELETED
= 3
46 enum MailAuctionAnswers
48 AUCTION_OUTBIDDED
= 0,
50 AUCTION_SUCCESSFUL
= 2,
52 AUCTION_CANCELLED_TO_BIDDER
= 4,
54 AUCTION_SALE_PENDING
= 6
59 public: // Constructors
60 MailSender(MailMessageType messageType
, uint32 sender_guidlow_or_entry
, MailStationery stationery
= MAIL_STATIONERY_NORMAL
)
61 : m_messageType(messageType
), m_senderId(sender_guidlow_or_entry
), m_stationery(stationery
)
64 MailSender(Object
* sender
, MailStationery stationery
= MAIL_STATIONERY_NORMAL
);
65 MailSender(AuctionEntry
* sender
);
67 MailMessageType
GetMailMessageType() const { return m_messageType
; }
68 uint32
GetSenderId() const { return m_senderId
; }
69 MailStationery
GetStationery() const { return m_stationery
; }
71 MailMessageType m_messageType
;
72 uint32 m_senderId
; // player low guid or other object entry
73 MailStationery m_stationery
;
78 public: // Constructors
79 explicit MailReceiver(uint32 receiver_lowguid
) : m_receiver(NULL
), m_receiver_lowguid(receiver_lowguid
) {}
80 MailReceiver(Player
* receiver
);
81 MailReceiver(Player
* receiver
,uint32 receiver_lowguid
);
83 Player
* GetPlayer() const { return m_receiver
; }
84 uint32
GetPlayerGUIDLow() const { return m_receiver_lowguid
; }
87 uint32 m_receiver_lowguid
;
92 typedef std::map
<uint32
, Item
*> MailItemMap
;
94 public: // Constructors
95 explicit MailDraft(uint16 mailTemplateId
, bool need_items
= true)
96 : m_mailTemplateId(mailTemplateId
), m_mailTemplateItemsNeed(need_items
), m_bodyId(0), m_money(0), m_COD(0)
98 MailDraft(std::string subject
, uint32 itemTextId
= 0)
99 : m_mailTemplateId(0), m_mailTemplateItemsNeed(false), m_subject(subject
), m_bodyId(itemTextId
), m_money(0), m_COD(0) {}
101 uint16
GetMailTemplateId() const { return m_mailTemplateId
; }
102 std::string
const& GetSubject() const { return m_subject
; }
103 uint32
GetBodyId() const { return m_bodyId
; }
104 uint32
GetMoney() const { return m_money
; }
105 uint32
GetCOD() const { return m_COD
; }
107 MailDraft
& AddItem(Item
* item
);
108 MailDraft
& AddMoney(uint32 money
) { m_money
= money
; return *this; }
109 MailDraft
& AddCOD(uint32 COD
) { m_COD
= COD
; return *this; }
111 void SendReturnToSender(uint32 sender_acc
, uint32 sender_guid
, uint32 receiver_guid
);
112 void SendMailTo(MailReceiver
const& receiver
, MailSender
const& sender
, MailCheckMask checked
= MAIL_CHECK_MASK_NONE
, uint32 deliver_delay
= 0);
114 void deleteIncludedItems(bool inDB
= false);
115 void prepareItems(Player
* receiver
); // called from SendMailTo for generate mailTemplateBase items
117 uint16 m_mailTemplateId
;
118 bool m_mailTemplateItemsNeed
;
119 std::string m_subject
;
122 MailItemMap m_items
; // Keep the items in a map to avoid duplicate guids (which can happen), store only low part of guid
131 uint32 item_template
;
139 uint16 mailTemplateId
;
144 std::vector
<MailItemInfo
> items
;
145 std::vector
<uint32
> removedItems
;
153 void AddItem(uint32 itemGuidLow
, uint32 item_template
)
156 mii
.item_guid
= itemGuidLow
;
157 mii
.item_template
= item_template
;
158 items
.push_back(mii
);
161 bool RemoveItem(uint32 item_guid
)
163 for(std::vector
<MailItemInfo
>::iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
165 if(itr
->item_guid
== item_guid
)
174 bool HasItems() const { return !items
.empty(); }