root/trunk/src/game/Mail.h @ 40

Revision 2, 6.3 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18#ifndef MANGOS_MAIL_H
19#define MANGOS_MAIL_H
20
21#include "Common.h"
22#include <map>
23
24class Item;
25
26#define MAIL_BODY_ITEM_TEMPLATE 8383                        // - plain letter, A Dusty Unsent Letter: 889
27#define MAX_MAIL_ITEMS 12
28
29enum MAIL_RESPONSE
30{
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
37};
38
39enum MAIL_ERRORS
40{
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
51};
52
53enum MailCheckMask
54{
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
60};
61
62enum MailMessageType
63{
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
69};
70
71enum MailState
72{
73    MAIL_STATE_UNCHANGED = 1,
74    MAIL_STATE_CHANGED   = 2,
75    MAIL_STATE_DELETED   = 3
76};
77
78enum MailAuctionAnswers
79{
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
87};
88
89// gathered from Stationery.dbc
90enum MailStationery
91{
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
98};
99
100struct MailItemInfo
101{
102    uint32 item_guid;
103    uint32 item_template;
104};
105
106struct MailItem
107{
108    MailItem() : item_slot(0), item_guidlow(0), item_template(0), item(NULL) {}
109
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
114
115    void deleteItem(bool inDB = false);
116};
117
118typedef std::map<uint32, MailItem> MailItemMap;
119
120class MailItemsInfo
121{
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(); }
127
128        void AddItem(uint32 guidlow, uint32 _template, Item *item, uint8 slot = 0)
129        {
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;
136        }
137
138        void AddItem(uint32 guidlow, uint8 slot = 0)
139        {
140            MailItem mailItem;
141            mailItem.item_guidlow = guidlow;
142            mailItem.item_slot = slot;
143            i_MailItemMap[guidlow] = mailItem;
144        }
145
146        uint8 size() const { return i_MailItemMap.size(); }
147        bool empty() const { return i_MailItemMap.empty(); }
148
149        void deleteIncludedItems(bool inDB = false)
150        {
151            for(MailItemMap::iterator mailItemIter = begin(); mailItemIter != end(); ++mailItemIter)
152            {
153                MailItem& mailItem = mailItemIter->second;
154                mailItem.deleteItem(inDB);
155            }
156        }
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
159};
160
161struct Mail
162{
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;
179
180    void AddItem(uint32 itemGuidLow, uint32 item_template)
181    {
182        MailItemInfo mii;
183        mii.item_guid = itemGuidLow;
184        mii.item_template = item_template;
185        items.push_back(mii);
186    }
187
188    void AddAllItems(MailItemsInfo& pMailItemsInfo)
189    {
190        for(MailItemMap::iterator mailItemIter = pMailItemsInfo.begin(); mailItemIter != pMailItemsInfo.end(); ++mailItemIter)
191        {
192            MailItem& mailItem = mailItemIter->second;
193            AddItem(mailItem.item_guidlow, mailItem.item_template);
194        }
195    }
196
197    bool RemoveItem(uint32 itemId)
198    {
199        for(std::vector<MailItemInfo>::iterator itr = items.begin(); itr != items.end(); ++itr)
200        {
201            if(itr->item_guid == itemId)
202            {
203                items.erase(itr);
204                return true;
205            }
206        }
207        return false;
208    }
209
210    bool HasItems() const { return !items.empty(); }
211};
212#endif
Note: See TracBrowser for help on using the browser.