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
29 enum GuildDefaultRanks
33 //GR_VETERAN = 2, -- not used anywhere and possible incorrect in modified rank list
35 //GR_INITIATE = 4, -- use Guild::GetLowestRank() instead for lowest rank
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
62 GUILD_CREATE_S
= 0x00,
63 GUILD_INVITE_S
= 0x01,
65 GUILD_FOUNDER_S
= 0x0E,
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,
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
108 GE_LEADER_CHANGED
= 0x07,
110 GE_TABARDCHANGE
= 0x09,
111 GE_UNK1
= 0x0A, // string, string
114 GE_SIGNED_OFF
= 0x0D,
116 GE_BANKTAB_PURCHASED
= 0x0F,
118 GE_UNK6
= 0x11, // string 0000000000002710 is 1 gold
124 PETITION_TURN_OK
= 0,
125 PETITION_TURN_ALREADY_IN_GUILD
= 2,
126 PETITION_TURN_NEED_MORE_SIGNATURES
= 4,
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,
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
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
196 uint8 ItemStackCount
;
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
;
210 Item
* Slots
[GUILD_BANK_MAX_SLOTS
];
216 struct GuildItemPosCount
218 GuildItemPosCount(uint8 _slot
, uint8 _count
) : slot(_slot
), count(_count
) {}
220 bool isContainedIn(std::vector
<GuildItemPosCount
> const& vec
) const;
225 typedef std::vector
<GuildItemPosCount
> GuildItemPosCountVec
;
237 uint32 BankResetTimeMoney
;
239 uint32 BankResetTimeTab
[GUILD_BANK_MAX_TABS
];
240 uint32 BankRemSlotsTab
[GUILD_BANK_MAX_TABS
];
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
)
250 TabSlotPerDay
[i
] = 0;
256 uint32 BankMoneyPerDay
;
257 uint32 TabRight
[GUILD_BANK_MAX_TABS
];
258 uint32 TabSlotPerDay
[GUILD_BANK_MAX_TABS
];
267 bool create(uint64 lGuid
, std::string gname
);
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
);
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
)
345 void Roster(WorldSession
*session
);
346 void Query(WorldSession
*session
);
348 void UpdateLogoutTime(uint64 guid
);
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();
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
);
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;
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
);
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
);
398 void LoadBankRightsFromDB(uint32 GuildId
);
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
);
408 void AddRank(std::string name
,uint32 rights
,uint32 money
);
423 uint32 BackgroundColor
;
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
];
440 bool m_eventlogloaded
;
441 uint32 m_onlinemembers
;
442 uint64 guildbank_money
;
443 uint8 purchased_tabs
;
446 uint32 GuildEventlogMaxGuid
;
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
);