[7194] Reorganized order.
[getmangos.git] / src / game / Mail.h
blob9fcb8df4b9d595574b059f396c72897aa5b7be50
1 /*
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
18 #ifndef MANGOS_MAIL_H
19 #define MANGOS_MAIL_H
21 #include "Common.h"
22 #include <map>
24 class Item;
26 #define MAIL_BODY_ITEM_TEMPLATE 8383 // - plain letter, A Dusty Unsent Letter: 889
27 #define MAX_MAIL_ITEMS 12
29 enum MAIL_RESPONSE
31 MAIL_OK = 0,
32 MAIL_MONEY_TAKEN = 1,
33 MAIL_ITEM_TAKEN = 2,
34 MAIL_RETURNED_TO_SENDER = 3,
35 MAIL_DELETED = 4,
36 MAIL_MADE_PERMANENT = 5
39 enum MAIL_ERRORS
41 MAIL_ERR_BAG_FULL = 1,
42 MAIL_ERR_CANNOT_SEND_TO_SELF = 2,
43 MAIL_ERR_NOT_ENOUGH_MONEY = 3,
44 MAIL_ERR_RECIPIENT_NOT_FOUND = 4,
45 MAIL_ERR_NOT_YOUR_TEAM = 5,
46 MAIL_ERR_INTERNAL_ERROR = 6,
47 MAIL_ERR_DISABLED_FOR_TRIAL_ACC = 14,
48 MAIL_ERR_RECIPIENT_CAP_REACHED = 15,
49 MAIL_ERR_CANT_SEND_WRAPPED_COD = 16,
50 MAIL_ERR_MAIL_AND_CHAT_SUSPENDED = 17
53 enum MailCheckMask
55 MAIL_CHECK_MASK_NONE = 0,
56 MAIL_CHECK_MASK_READ = 1,
57 MAIL_CHECK_MASK_AUCTION = 4,
58 MAIL_CHECK_MASK_COD_PAYMENT = 8,
59 MAIL_CHECK_MASK_RETURNED = 16
62 enum MailMessageType
64 MAIL_NORMAL = 0,
65 MAIL_AUCTION = 2,
66 MAIL_CREATURE = 3, // client send CMSG_CREATURE_QUERY on this mailmessagetype
67 MAIL_GAMEOBJECT = 4, // client send CMSG_GAMEOBJECT_QUERY on this mailmessagetype
68 MAIL_ITEM = 5, // client send CMSG_ITEM_QUERY on this mailmessagetype
71 enum MailState
73 MAIL_STATE_UNCHANGED = 1,
74 MAIL_STATE_CHANGED = 2,
75 MAIL_STATE_DELETED = 3
78 enum MailAuctionAnswers
80 AUCTION_OUTBIDDED = 0,
81 AUCTION_WON = 1,
82 AUCTION_SUCCESSFUL = 2,
83 AUCTION_EXPIRED = 3,
84 AUCTION_CANCELLED_TO_BIDDER = 4,
85 AUCTION_CANCELED = 5,
86 AUCTION_SALE_PENDING = 6
89 // gathered from Stationery.dbc
90 enum MailStationery
92 MAIL_STATIONERY_UNKNOWN = 0x01,
93 MAIL_STATIONERY_NORMAL = 0x29,
94 MAIL_STATIONERY_GM = 0x3D,
95 MAIL_STATIONERY_AUCTION = 0x3E,
96 MAIL_STATIONERY_VAL = 0x40,
97 MAIL_STATIONERY_CHR = 0x41
100 struct MailItemInfo
102 uint32 item_guid;
103 uint32 item_template;
106 struct MailItem
108 MailItem() : item_slot(0), item_guidlow(0), item_template(0), item(NULL) {}
110 uint8 item_slot; // slot in mail
111 uint32 item_guidlow; // item guid (low part)
112 uint32 item_template; // item entry
113 Item *item; // item pointer
115 void deleteItem(bool inDB = false);
118 typedef std::map<uint32, MailItem> MailItemMap;
120 class MailItemsInfo
122 public:
123 MailItemMap::const_iterator begin() const { return i_MailItemMap.begin(); }
124 MailItemMap::const_iterator end() const { return i_MailItemMap.end(); }
125 MailItemMap::iterator begin() { return i_MailItemMap.begin(); }
126 MailItemMap::iterator end() { return i_MailItemMap.end(); }
128 void AddItem(uint32 guidlow, uint32 _template, Item *item, uint8 slot = 0)
130 MailItem mailItem;
131 mailItem.item_slot = slot;
132 mailItem.item_guidlow = guidlow;
133 mailItem.item_template = _template;
134 mailItem.item = item;
135 i_MailItemMap[guidlow] = mailItem;
138 void AddItem(uint32 guidlow, uint8 slot = 0)
140 MailItem mailItem;
141 mailItem.item_guidlow = guidlow;
142 mailItem.item_slot = slot;
143 i_MailItemMap[guidlow] = mailItem;
146 uint8 size() const { return i_MailItemMap.size(); }
147 bool empty() const { return i_MailItemMap.empty(); }
149 void deleteIncludedItems(bool inDB = false)
151 for(MailItemMap::iterator mailItemIter = begin(); mailItemIter != end(); ++mailItemIter)
153 MailItem& mailItem = mailItemIter->second;
154 mailItem.deleteItem(inDB);
157 private:
158 MailItemMap i_MailItemMap; // Keep the items in a map to avoid duplicate guids (which can happen), store only low part of guid
161 struct Mail
163 uint32 messageID;
164 uint8 messageType;
165 uint8 stationery;
166 uint16 mailTemplateId;
167 uint32 sender;
168 uint32 receiver;
169 std::string subject;
170 uint32 itemTextId;
171 std::vector<MailItemInfo> items;
172 std::vector<uint32> removedItems;
173 time_t expire_time;
174 time_t deliver_time;
175 uint32 money;
176 uint32 COD;
177 uint32 checked;
178 MailState state;
180 void AddItem(uint32 itemGuidLow, uint32 item_template)
182 MailItemInfo mii;
183 mii.item_guid = itemGuidLow;
184 mii.item_template = item_template;
185 items.push_back(mii);
188 void AddAllItems(MailItemsInfo& pMailItemsInfo)
190 for(MailItemMap::iterator mailItemIter = pMailItemsInfo.begin(); mailItemIter != pMailItemsInfo.end(); ++mailItemIter)
192 MailItem& mailItem = mailItemIter->second;
193 AddItem(mailItem.item_guidlow, mailItem.item_template);
197 bool RemoveItem(uint32 itemId)
199 for(std::vector<MailItemInfo>::iterator itr = items.begin(); itr != items.end(); ++itr)
201 if(itr->item_guid == itemId)
203 items.erase(itr);
204 return true;
207 return false;
210 bool HasItems() const { return !items.empty(); }
212 #endif