[9290] Some cleanups in realmd, no functional changes
[getmangos.git] / src / game / Mail.h
blob3922723034d15c6f11457d52173d42844b908629
1 /*
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
18 #ifndef MANGOS_MAIL_H
19 #define MANGOS_MAIL_H
21 #include "Common.h"
22 #include <map>
24 struct AuctionEntry;
25 class Item;
26 class Object;
27 class Player;
29 #define MAIL_BODY_ITEM_TEMPLATE 8383 // - plain letter, A Dusty Unsent Letter: 889
30 #define MAX_MAIL_ITEMS 12
32 enum MailMessageType
34 MAIL_NORMAL = 0,
35 MAIL_AUCTION = 2,
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
41 enum MailCheckMask
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
51 enum MailStationery
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
62 enum MailState
64 MAIL_STATE_UNCHANGED = 1,
65 MAIL_STATE_CHANGED = 2,
66 MAIL_STATE_DELETED = 3
69 enum MailAuctionAnswers
71 AUCTION_OUTBIDDED = 0,
72 AUCTION_WON = 1,
73 AUCTION_SUCCESSFUL = 2,
74 AUCTION_EXPIRED = 3,
75 AUCTION_CANCELLED_TO_BIDDER = 4,
76 AUCTION_CANCELED = 5,
77 AUCTION_SALE_PENDING = 6
80 class MailSender
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);
89 public: // Accessors
90 MailMessageType GetMailMessageType() const { return m_messageType; }
91 uint32 GetSenderId() const { return m_senderId; }
92 MailStationery GetStationery() const { return m_stationery; }
93 private:
94 MailMessageType m_messageType;
95 uint32 m_senderId; // player low guid or other object entry
96 MailStationery m_stationery;
99 class MailReceiver
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);
105 public: // Accessors
106 Player* GetPlayer() const { return m_receiver; }
107 uint32 GetPlayerGUIDLow() const { return m_receiver_lowguid; }
108 private:
109 Player* m_receiver;
110 uint32 m_receiver_lowguid;
113 class MailDraft
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) {}
123 public: // Accessors
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; }
129 public: // modifiers
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; }
133 public: // finishers
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);
136 private:
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;
143 uint32 m_bodyId;
145 MailItemMap m_items; // Keep the items in a map to avoid duplicate guids (which can happen), store only low part of guid
147 uint32 m_money;
148 uint32 m_COD;
151 struct MailItemInfo
153 uint32 item_guid;
154 uint32 item_template;
157 struct Mail
159 uint32 messageID;
160 uint8 messageType;
161 uint8 stationery;
162 uint16 mailTemplateId;
163 uint32 sender;
164 uint32 receiver;
165 std::string subject;
166 uint32 itemTextId;
167 std::vector<MailItemInfo> items;
168 std::vector<uint32> removedItems;
169 time_t expire_time;
170 time_t deliver_time;
171 uint32 money;
172 uint32 COD;
173 uint32 checked;
174 MailState state;
176 void AddItem(uint32 itemGuidLow, uint32 item_template)
178 MailItemInfo mii;
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)
190 items.erase(itr);
191 return true;
194 return false;
197 bool HasItems() const { return !items.empty(); }
200 #endif