[6844] Daily quest fixes.
[getmangos.git] / src / game / Guild.h
blob31da4438a07e333b7ec1794f7a90c3067b990022
1 /*
2 * Copyright (C) 2005-2008 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
19 #ifndef MANGOSSERVER_GUILD_H
20 #define MANGOSSERVER_GUILD_H
22 #define WITHDRAW_MONEY_UNLIMITED 0xFFFFFFFF
23 #define WITHDRAW_SLOT_UNLIMITED 0xFFFFFFFF
25 #include "Item.h"
27 class Item;
29 enum GuildDefaultRanks
31 GR_GUILDMASTER = 0,
32 GR_OFFICER = 1,
33 //GR_VETERAN = 2, -- not used anywhere and possible incorrect in modified rank list
34 //GR_MEMBER = 3,
35 //GR_INITIATE = 4, -- use Guild::GetLowestRank() instead for lowest rank
38 enum GuildRankRights
40 GR_RIGHT_EMPTY = 0x00000040,
41 GR_RIGHT_GCHATLISTEN = 0x00000041,
42 GR_RIGHT_GCHATSPEAK = 0x00000042,
43 GR_RIGHT_OFFCHATLISTEN = 0x00000044,
44 GR_RIGHT_OFFCHATSPEAK = 0x00000048,
45 GR_RIGHT_PROMOTE = 0x000000C0,
46 GR_RIGHT_DEMOTE = 0x00000140,
47 GR_RIGHT_INVITE = 0x00000050,
48 GR_RIGHT_REMOVE = 0x00000060,
49 GR_RIGHT_SETMOTD = 0x00001040,
50 GR_RIGHT_EPNOTE = 0x00002040,
51 GR_RIGHT_VIEWOFFNOTE = 0x00004040,
52 GR_RIGHT_EOFFNOTE = 0x00008040,
53 GR_RIGHT_MODIFY_GUILD_INFO = 0x00010040,
54 GR_RIGHT_REPAIR_FROM_GUILD = 0x00020000, // unused in 2.4.x?, Remove money withdraw capacity
55 GR_RIGHT_WITHDRAW_REPAIR = 0x00040000, // withdraw for repair
56 GR_RIGHT_WITHDRAW_GOLD = 0x00080000, // withdraw gold
57 GR_RIGHT_ALL = 0x000FF1FF
60 enum Typecommand
62 GUILD_CREATE_S = 0x00,
63 GUILD_INVITE_S = 0x01,
64 GUILD_QUIT_S = 0x03,
65 GUILD_FOUNDER_S = 0x0E,
66 GUILD_UNK1 = 0x10,
67 GUILD_BANK_S = 0x15,
68 GUILD_UNK3 = 0x16
71 enum CommandErrors
73 GUILD_PLAYER_NO_MORE_IN_GUILD = 0x00,
74 GUILD_INTERNAL = 0x01,
75 GUILD_ALREADY_IN_GUILD = 0x02,
76 ALREADY_IN_GUILD = 0x03,
77 INVITED_TO_GUILD = 0x04,
78 ALREADY_INVITED_TO_GUILD = 0x05,
79 GUILD_NAME_INVALID = 0x06,
80 GUILD_NAME_EXISTS = 0x07,
81 GUILD_LEADER_LEAVE = 0x08,
82 GUILD_PERMISSIONS = 0x08,
83 GUILD_PLAYER_NOT_IN_GUILD = 0x09,
84 GUILD_PLAYER_NOT_IN_GUILD_S = 0x0A,
85 GUILD_PLAYER_NOT_FOUND = 0x0B,
86 GUILD_NOT_ALLIED = 0x0C,
87 GUILD_RANK_TOO_HIGH_S = 0x0D,
88 GUILD_ALREADY_LOWEST_RANK_S = 0x0E,
89 GUILD_TEMP_ERROR = 0x11,
90 GUILD_RANK_IN_USE = 0x12,
91 GUILD_IGNORE = 0x13,
92 GUILD_ERR_UNK1 = 0x17,
93 GUILD_WITHDRAW_TOO_MUCH = 0x18,
94 GUILD_BANK_NO_MONEY = 0x19,
95 GUILD_BANK_TAB_IS_FULL = 0x1B,
96 GUILD_BANK_ITEM_NOT_FOUND = 0x1C
99 enum GuildEvents
101 GE_PROMOTION = 0x00,
102 GE_DEMOTION = 0x01,
103 GE_MOTD = 0x02,
104 GE_JOINED = 0x03,
105 GE_LEFT = 0x04,
106 GE_REMOVED = 0x05,
107 GE_LEADER_IS = 0x06,
108 GE_LEADER_CHANGED = 0x07,
109 GE_DISBANDED = 0x08,
110 GE_TABARDCHANGE = 0x09,
111 GE_UNK1 = 0x0A, // string, string
112 GE_UNK2 = 0x0B,
113 GE_SIGNED_ON = 0x0C,
114 GE_SIGNED_OFF = 0x0D,
115 GE_UNK3 = 0x0E,
116 GE_BANKTAB_PURCHASED= 0x0F,
117 GE_UNK5 = 0x10,
118 GE_UNK6 = 0x11, // string 0000000000002710 is 1 gold
119 GE_UNK7 = 0x12
122 enum PetitionTurns
124 PETITION_TURN_OK = 0,
125 PETITION_TURN_ALREADY_IN_GUILD = 2,
126 PETITION_TURN_NEED_MORE_SIGNATURES = 4,
129 enum PetitionSigns
131 PETITION_SIGN_OK = 0,
132 PETITION_SIGN_ALREADY_SIGNED = 1,
133 PETITION_SIGN_ALREADY_IN_GUILD = 2,
134 PETITION_SIGN_CANT_SIGN_OWN = 3,
135 PETITION_SIGN_NOT_SERVER = 4,
138 enum GuildBankRights
140 GUILD_BANK_RIGHT_VIEW_TAB = 0x01,
141 GUILD_BANK_RIGHT_PUT_ITEM = 0x02,
142 GUILD_BANK_RIGHT_UPDATE_TEXT = 0x04,
144 GUILD_BANK_RIGHT_DEPOSIT_ITEM = GUILD_BANK_RIGHT_VIEW_TAB | GUILD_BANK_RIGHT_PUT_ITEM,
145 GUILD_BANK_RIGHT_FULL = 0xFF,
148 enum GuildBankLogEntries
150 GUILD_BANK_LOG_DEPOSIT_ITEM = 1,
151 GUILD_BANK_LOG_WITHDRAW_ITEM = 2,
152 GUILD_BANK_LOG_MOVE_ITEM = 3,
153 GUILD_BANK_LOG_DEPOSIT_MONEY = 4,
154 GUILD_BANK_LOG_WITHDRAW_MONEY = 5,
155 GUILD_BANK_LOG_REPAIR_MONEY = 6,
156 GUILD_BANK_LOG_MOVE_ITEM2 = 7,
159 enum GuildEventLogEntryTypes
161 GUILD_EVENT_LOG_INVITE_PLAYER = 1,
162 GUILD_EVENT_LOG_JOIN_GUILD = 2,
163 GUILD_EVENT_LOG_PROMOTE_PLAYER = 3,
164 GUILD_EVENT_LOG_DEMOTE_PLAYER = 4,
165 GUILD_EVENT_LOG_UNINVITE_PLAYER = 5,
166 GUILD_EVENT_LOG_LEAVE_GUILD = 6,
169 struct GuildEventlogEntry
171 uint32 LogGuid;
172 uint8 EventType;
173 uint32 PlayerGuid1;
174 uint32 PlayerGuid2;
175 uint8 NewRank;
176 uint64 TimeStamp;
179 enum GuildEmblem
181 ERR_GUILDEMBLEM_SUCCESS = 0,
182 ERR_GUILDEMBLEM_INVALID_TABARD_COLORS = 1,
183 ERR_GUILDEMBLEM_NOGUILD = 2,
184 ERR_GUILDEMBLEM_NOTGUILDMASTER = 3,
185 ERR_GUILDEMBLEM_NOTENOUGHMONEY = 4,
186 ERR_GUILDEMBLEM_INVALIDVENDOR = 5
189 struct GuildBankEvent
191 uint32 LogGuid;
192 uint8 LogEntry;
193 uint8 TabId;
194 uint32 PlayerGuid;
195 uint32 ItemOrMoney;
196 uint8 ItemStackCount;
197 uint8 DestTabId;
198 uint64 TimeStamp;
200 bool isMoneyEvent() const
202 return LogEntry == GUILD_BANK_LOG_DEPOSIT_MONEY ||
203 LogEntry == GUILD_BANK_LOG_WITHDRAW_MONEY ||
204 LogEntry == GUILD_BANK_LOG_REPAIR_MONEY;
208 struct GuildBankTab
210 Item* Slots[GUILD_BANK_MAX_SLOTS];
211 std::string Name;
212 std::string Icon;
213 std::string Text;
216 struct GuildItemPosCount
218 GuildItemPosCount(uint8 _slot, uint8 _count) : slot(_slot), count(_count) {}
220 bool isContainedIn(std::vector<GuildItemPosCount> const& vec) const;
222 uint8 slot;
223 uint8 count;
225 typedef std::vector<GuildItemPosCount> GuildItemPosCountVec;
227 struct MemberSlot
229 uint64 logout_time;
230 std::string name;
231 std::string Pnote;
232 std::string OFFnote;
233 uint32 RankId;
234 uint32 zoneId;
235 uint8 level;
236 uint8 Class;
237 uint32 BankResetTimeMoney;
238 uint32 BankRemMoney;
239 uint32 BankResetTimeTab[GUILD_BANK_MAX_TABS];
240 uint32 BankRemSlotsTab[GUILD_BANK_MAX_TABS];
243 struct RankInfo
245 RankInfo(std::string _name, uint32 _rights, uint32 _money) : name(_name), rights(_rights), BankMoneyPerDay(_money)
247 for(uint8 i = 0; i < GUILD_BANK_MAX_TABS; ++i)
249 TabRight[i] = 0;
250 TabSlotPerDay[i] = 0;
254 std::string name;
255 uint32 rights;
256 uint32 BankMoneyPerDay;
257 uint32 TabRight[GUILD_BANK_MAX_TABS];
258 uint32 TabSlotPerDay[GUILD_BANK_MAX_TABS];
261 class Guild
263 public:
264 Guild();
265 ~Guild();
267 bool create(uint64 lGuid, std::string gname);
268 void Disband();
270 typedef std::map<uint32, MemberSlot> MemberList;
271 typedef std::vector<RankInfo> RankList;
273 uint32 GetId(){ return Id; }
274 const uint64& GetLeader(){ return leaderGuid; }
275 std::string GetName(){ return name; }
276 std::string GetMOTD(){ return MOTD; }
277 std::string GetGINFO(){ return GINFO; }
279 uint32 GetCreatedYear(){ return CreatedYear; }
280 uint32 GetCreatedMonth(){ return CreatedMonth; }
281 uint32 GetCreatedDay(){ return CreatedDay; }
283 uint32 GetEmblemStyle(){ return EmblemStyle; }
284 uint32 GetEmblemColor(){ return EmblemColor; }
285 uint32 GetBorderStyle(){ return BorderStyle; }
286 uint32 GetBorderColor(){ return BorderColor; }
287 uint32 GetBackgroundColor(){ return BackgroundColor; }
289 void SetLeader(uint64 guid);
290 bool AddMember(uint64 plGuid, uint32 plRank);
291 void ChangeRank(uint64 guid, uint32 newRank);
292 void DelMember(uint64 guid, bool isDisbanding=false);
293 uint32 GetLowestRank() const { return GetNrRanks()-1; }
295 void SetMOTD(std::string motd);
296 void SetGINFO(std::string ginfo);
297 void SetPNOTE(uint64 guid,std::string pnote);
298 void SetOFFNOTE(uint64 guid,std::string offnote);
299 void SetEmblem(uint32 emblemStyle, uint32 emblemColor, uint32 borderStyle, uint32 borderColor, uint32 backgroundColor);
301 uint32 GetMemberSize() const { return members.size(); }
303 bool LoadGuildFromDB(uint32 GuildId);
304 bool LoadRanksFromDB(uint32 GuildId);
305 bool LoadMembersFromDB(uint32 GuildId);
307 bool FillPlayerData(uint64 guid, MemberSlot* memslot);
308 void LoadPlayerStatsByGuid(uint64 guid);
310 void BroadcastToGuild(WorldSession *session, std::string msg, uint32 language = LANG_UNIVERSAL);
311 void BroadcastToOfficers(WorldSession *session, std::string msg, uint32 language = LANG_UNIVERSAL);
312 void BroadcastPacketToRank(WorldPacket *packet, uint32 rankId);
313 void BroadcastPacket(WorldPacket *packet);
315 void CreateRank(std::string name,uint32 rights);
316 void DelRank();
317 std::string GetRankName(uint32 rankId);
318 uint32 GetRankRights(uint32 rankId);
319 uint32 GetNrRanks() const { return m_ranks.size(); }
321 void SetRankName(uint32 rankId, std::string name);
322 void SetRankRights(uint32 rankId, uint32 rights);
323 bool HasRankRight(uint32 rankId, uint32 right)
325 return ((GetRankRights(rankId) & right) != GR_RIGHT_EMPTY) ? true : false;
327 int32 GetRank(uint32 LowGuid);
328 bool IsMember(uint32 LowGuid)
330 return (members.find(LowGuid) != members.end());
332 MemberSlot* GetMemberSlot(std::string const& name, uint64& guid)
334 for(MemberList::iterator itr = members.begin(); itr != members.end(); ++itr)
336 if(itr->second.name == name)
338 guid = itr->first;
339 return &itr->second;
342 return NULL;
345 void Roster(WorldSession *session);
346 void Query(WorldSession *session);
348 void UpdateLogoutTime(uint64 guid);
349 // Guild eventlog
350 void LoadGuildEventLogFromDB();
351 void UnloadGuildEventlog();
352 void DisplayGuildEventlog(WorldSession *session);
353 void LogGuildEvent(uint8 EventType, uint32 PlayerGuid1, uint32 PlayerGuid2, uint8 NewRank);
354 void RenumGuildEventlog();
356 // ** Guild bank **
357 // Content & item deposit/withdraw
358 void DisplayGuildBankContent(WorldSession *session, uint8 TabId);
359 void DisplayGuildBankContentUpdate(uint8 TabId, int32 slot1, int32 slot2 = -1);
360 void DisplayGuildBankContentUpdate(uint8 TabId, GuildItemPosCountVec const& slots);
361 void DisplayGuildBankMoneyUpdate();
363 Item* GetItem(uint8 TabId, uint8 SlotId);
364 uint8 CanStoreItem( uint8 tab, uint8 slot, GuildItemPosCountVec& dest, uint32 count, Item *pItem, bool swap = false) const;
365 Item* StoreItem( uint8 tab, GuildItemPosCountVec const& pos, Item *pItem );
366 void RemoveItem(uint8 tab, uint8 slot );
368 // Tabs
369 void DisplayGuildBankTabsInfo(WorldSession *session);
370 void CreateNewBankTab();
371 void SetGuildBankTabText(uint8 TabId, std::string text);
372 void SendGuildBankTabText(WorldSession *session, uint8 TabId);
373 void SetGuildBankTabInfo(uint8 TabId, std::string name, std::string icon);
374 void CreateBankRightForTab(uint32 rankid, uint8 TabId);
375 const GuildBankTab *GetBankTab(uint8 index) { if(index >= m_TabListMap.size()) return NULL; return m_TabListMap[index]; }
376 uint8 GetPurchasedTabs() const { return purchased_tabs; }
377 uint32 GetBankRights(uint32 rankId, uint8 TabId) const;
378 bool IsMemberHaveRights(uint32 LowGuid, uint8 TabId,uint32 rights) const;
379 bool CanMemberViewTab(uint32 LowGuid, uint8 TabId) const;
380 // Load/unload
381 void LoadGuildBankFromDB();
382 void UnloadGuildBank();
383 void IncOnlineMemberCount() { ++m_onlinemembers; }
384 // Money deposit/withdraw
385 void SendMoneyInfo(WorldSession *session, uint32 LowGuid);
386 bool MemberMoneyWithdraw(uint32 amount, uint32 LowGuid);
387 uint64 GetGuildBankMoney() { return guildbank_money; }
388 void SetBankMoney(int64 money);
389 // per days
390 bool MemberItemWithdraw(uint8 TabId, uint32 LowGuid);
391 uint32 GetMemberSlotWithdrawRem(uint32 LowGuid, uint8 TabId);
392 uint32 GetMemberMoneyWithdrawRem(uint32 LowGuid);
393 void SetBankMoneyPerDay(uint32 rankId, uint32 money);
394 void SetBankRightsAndSlots(uint32 rankId, uint8 TabId, uint32 right, uint32 SlotPerDay, bool db);
395 uint32 GetBankMoneyPerDay(uint32 rankId);
396 uint32 GetBankSlotPerDay(uint32 rankId, uint8 TabId);
397 // rights per day
398 void LoadBankRightsFromDB(uint32 GuildId);
399 // logs
400 void LoadGuildBankEventLogFromDB();
401 void UnloadGuildBankEventLog();
402 void DisplayGuildBankLogs(WorldSession *session, uint8 TabId);
403 void LogBankEvent(uint8 LogEntry, uint8 TabId, uint32 PlayerGuidLow, uint32 ItemOrMoney, uint8 ItemStackCount=0, uint8 DestTabId=0);
404 void RenumBankLogs();
405 bool AddGBankItemToDB(uint32 GuildId, uint32 BankTab , uint32 BankTabSlot , uint32 GUIDLow, uint32 Entry );
407 protected:
408 void AddRank(std::string name,uint32 rights,uint32 money);
410 uint32 Id;
411 std::string name;
412 uint64 leaderGuid;
413 std::string MOTD;
414 std::string GINFO;
415 uint32 CreatedYear;
416 uint32 CreatedMonth;
417 uint32 CreatedDay;
419 uint32 EmblemStyle;
420 uint32 EmblemColor;
421 uint32 BorderStyle;
422 uint32 BorderColor;
423 uint32 BackgroundColor;
425 RankList m_ranks;
427 MemberList members;
429 typedef std::vector<GuildBankTab*> TabListMap;
430 TabListMap m_TabListMap;
432 /** These are actually ordered lists. The first element is the oldest entry.*/
433 typedef std::list<GuildEventlogEntry*> GuildEventlog;
434 typedef std::list<GuildBankEvent*> GuildBankEventLog;
435 GuildEventlog m_GuildEventlog;
436 GuildBankEventLog m_GuildBankEventLog_Money;
437 GuildBankEventLog m_GuildBankEventLog_Item[GUILD_BANK_MAX_TABS];
439 bool m_bankloaded;
440 bool m_eventlogloaded;
441 uint32 m_onlinemembers;
442 uint64 guildbank_money;
443 uint8 purchased_tabs;
445 uint32 LogMaxGuid;
446 uint32 GuildEventlogMaxGuid;
447 private:
448 // internal common parts for CanStore/StoreItem functions
449 void AppendDisplayGuildBankSlot( WorldPacket& data, GuildBankTab const *tab, int32 slot );
450 uint8 _CanStoreItem_InSpecificSlot( uint8 tab, uint8 slot, GuildItemPosCountVec& dest, uint32& count, bool swap, Item *pSrcItem ) const;
451 uint8 _CanStoreItem_InTab( uint8 tab, GuildItemPosCountVec& dest, uint32& count, bool merge, Item *pSrcItem, uint8 skip_slot ) const;
452 Item* _StoreItem( uint8 tab, uint8 slot, Item *pItem, uint32 count, bool clone );
454 #endif