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

Revision 102, 6.4 kB (checked in by yumileroy, 17 years ago)

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#ifndef TRINITY_MAIL_H
21#define TRINITY_MAIL_H
22
23#include "Common.h"
24#include <map>
25
26class Item;
27
28#define MAIL_BODY_ITEM_TEMPLATE 8383                        // - plain letter, A Dusty Unsent Letter: 889
29#define MAX_MAIL_ITEMS 12
30
31enum MAIL_RESPONSE
32{
33    MAIL_OK                 = 0,
34    MAIL_MONEY_TAKEN        = 1,
35    MAIL_ITEM_TAKEN         = 2,
36    MAIL_RETURNED_TO_SENDER = 3,
37    MAIL_DELETED            = 4,
38    MAIL_MADE_PERMANENT     = 5
39};
40
41enum MAIL_ERRORS
42{
43    MAIL_ERR_BAG_FULL                  = 1,
44    MAIL_ERR_CANNOT_SEND_TO_SELF       = 2,
45    MAIL_ERR_NOT_ENOUGH_MONEY          = 3,
46    MAIL_ERR_RECIPIENT_NOT_FOUND       = 4,
47    MAIL_ERR_NOT_YOUR_TEAM             = 5,
48    MAIL_ERR_INTERNAL_ERROR            = 6,
49    MAIL_ERR_DISABLED_FOR_TRIAL_ACC    = 14,
50    MAIL_ERR_RECIPIENT_CAP_REACHED     = 15,
51    MAIL_ERR_CANT_SEND_WRAPPED_COD     = 16,
52    MAIL_ERR_MAIL_AND_CHAT_SUSPENDED   = 17
53};
54
55enum MailCheckMask
56{
57    MAIL_CHECK_MASK_NONE        = 0,
58    MAIL_CHECK_MASK_READ        = 1,
59    MAIL_CHECK_MASK_AUCTION     = 4,
60    MAIL_CHECK_MASK_COD_PAYMENT = 8,
61    MAIL_CHECK_MASK_RETURNED    = 16
62};
63
64enum MailMessageType
65{
66    MAIL_NORMAL         = 0,
67    MAIL_AUCTION        = 2,
68    MAIL_CREATURE       = 3,                                // client send CMSG_CREATURE_QUERY on this mailmessagetype
69    MAIL_GAMEOBJECT     = 4,                                // client send CMSG_GAMEOBJECT_QUERY on this mailmessagetype
70    MAIL_ITEM           = 5,                                // client send CMSG_ITEM_QUERY on this mailmessagetype
71};
72
73enum MailState
74{
75    MAIL_STATE_UNCHANGED = 1,
76    MAIL_STATE_CHANGED   = 2,
77    MAIL_STATE_DELETED   = 3
78};
79
80enum MailAuctionAnswers
81{
82    AUCTION_OUTBIDDED           = 0,
83    AUCTION_WON                 = 1,
84    AUCTION_SUCCESSFUL          = 2,
85    AUCTION_EXPIRED             = 3,
86    AUCTION_CANCELLED_TO_BIDDER = 4,
87    AUCTION_CANCELED            = 5,
88    AUCTION_SALE_PENDING        = 6
89};
90
91// gathered from Stationery.dbc
92enum MailStationery
93{
94    MAIL_STATIONERY_UNKNOWN = 0x01,
95    MAIL_STATIONERY_NORMAL  = 0x29,
96    MAIL_STATIONERY_GM      = 0x3D,
97    MAIL_STATIONERY_AUCTION = 0x3E,
98    MAIL_STATIONERY_VAL     = 0x40,
99    MAIL_STATIONERY_CHR     = 0x41
100};
101
102struct MailItemInfo
103{
104    uint32 item_guid;
105    uint32 item_template;
106};
107
108struct MailItem
109{
110    MailItem() : item_slot(0), item_guidlow(0), item_template(0), item(NULL) {}
111
112    uint8 item_slot;                                        // slot in mail
113    uint32 item_guidlow;                                    // item guid (low part)
114    uint32 item_template;                                   // item entry
115    Item *item;                                             // item pointer
116
117    void deleteItem(bool inDB = false);
118};
119
120typedef std::map<uint32, MailItem> MailItemMap;
121
122class MailItemsInfo
123{
124    public:
125        MailItemMap::const_iterator begin() const { return i_MailItemMap.begin(); }
126        MailItemMap::const_iterator end() const { return i_MailItemMap.end(); }
127        MailItemMap::iterator begin() { return i_MailItemMap.begin(); }
128        MailItemMap::iterator end() { return i_MailItemMap.end(); }
129
130        void AddItem(uint32 guidlow, uint32 _template, Item *item, uint8 slot = 0)
131        {
132            MailItem mailItem;
133            mailItem.item_slot = slot;
134            mailItem.item_guidlow = guidlow;
135            mailItem.item_template = _template;
136            mailItem.item = item;
137            i_MailItemMap[guidlow] = mailItem;
138        }
139
140        void AddItem(uint32 guidlow, uint8 slot = 0)
141        {
142            MailItem mailItem;
143            mailItem.item_guidlow = guidlow;
144            mailItem.item_slot = slot;
145            i_MailItemMap[guidlow] = mailItem;
146        }
147
148        uint8 size() const { return i_MailItemMap.size(); }
149        bool empty() const { return i_MailItemMap.empty(); }
150
151        void deleteIncludedItems(bool inDB = false)
152        {
153            for(MailItemMap::iterator mailItemIter = begin(); mailItemIter != end(); ++mailItemIter)
154            {
155                MailItem& mailItem = mailItemIter->second;
156                mailItem.deleteItem(inDB);
157            }
158        }
159    private:
160        MailItemMap i_MailItemMap;                          // Keep the items in a map to avoid duplicate guids (which can happen), store only low part of guid
161};
162
163struct Mail
164{
165    uint32 messageID;
166    uint8 messageType;
167    uint8 stationery;
168    uint16 mailTemplateId;
169    uint32 sender;
170    uint32 receiver;
171    std::string subject;
172    uint32 itemTextId;
173    std::vector<MailItemInfo> items;
174    std::vector<uint32> removedItems;
175    time_t expire_time;
176    time_t deliver_time;
177    uint32 money;
178    uint32 COD;
179    uint32 checked;
180    MailState state;
181
182    void AddItem(uint32 itemGuidLow, uint32 item_template)
183    {
184        MailItemInfo mii;
185        mii.item_guid = itemGuidLow;
186        mii.item_template = item_template;
187        items.push_back(mii);
188    }
189
190    void AddAllItems(MailItemsInfo& pMailItemsInfo)
191    {
192        for(MailItemMap::iterator mailItemIter = pMailItemsInfo.begin(); mailItemIter != pMailItemsInfo.end(); ++mailItemIter)
193        {
194            MailItem& mailItem = mailItemIter->second;
195            AddItem(mailItem.item_guidlow, mailItem.item_template);
196        }
197    }
198
199    bool RemoveItem(uint32 itemId)
200    {
201        for(std::vector<MailItemInfo>::iterator itr = items.begin(); itr != items.end(); ++itr)
202        {
203            if(itr->item_guid == itemId)
204            {
205                items.erase(itr);
206                return true;
207            }
208        }
209        return false;
210    }
211
212    bool HasItems() const { return !items.empty(); }
213};
214#endif
Note: See TracBrowser for help on using the browser.