1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef RY_GUILD_MANAGER_H
24 #define RY_GUILD_MANAGER_H
26 #include "nel/misc/types_nl.h"
27 #include "obs_huge_list.h"
28 #include "dbgroup_list_sheet_text.h"
29 #include "nel/misc/cdb.h"
30 #include "game_share/guild_grade.h"
31 #include "game_share/misc_const.h"
33 // Must be the same as in database.xml
34 #define MAX_GUILD_MEMBER 256
36 // ***************************************************************************
39 uint32 Index
; // Index in the DB
42 EGSPD::CGuildGrade::TGuildGrade Grade
;
43 TCharConnectionState Online
;
50 Grade
= EGSPD::CGuildGrade::Member
;
54 // ***************************************************************************
60 bool QuitGuildAvailable
;
62 //////////////////////
67 QuitGuildAvailable
= true;
71 // ***************************************************************************
73 * class used to manage the guild of the current player
74 * for the moment its used only to regroup access to the good data
75 * \author Matthieu 'TrapII' Besson
76 * \author Nevrax France
84 /// The singleton 's instance
85 static CGuildManager
* getInstance()
87 if (_Instance
== NULL
)
88 _Instance
= new CGuildManager
;
94 if (_Instance
!= NULL
)
100 virtual ~CGuildManager();
102 const SGuild
&getGuild() { return _Guild
; }
103 const std::vector
<SGuildMember
> &getGuildMembers() { return _GuildMembers
; }
108 START_SORT_ORDER
= sort_grade
,
114 void sortGuildMembers(TSortOrder order
= sort_grade
);
116 /// Check if the guild is a proxified guild (not managed on the actual shard)
119 /// Called from server (impulse message)
120 //void init (const std::vector< std::pair<uint32,uint8> > &NameGrade);
122 /// Called from server (if MemberName==0 and MemberGrade==Unknown then remove the entry)
123 //void set (uint32 indexMember, uint32 MemberName, uint8 MemberGrade, bool bOnline);
125 /// Indicate if the player belongs to a guild
128 /// Tell if we can recruit (invit a player in our guild)
131 /// Indicate if the player belongs to a guild
132 bool isLeaderOfTheGuild();
134 /// If the player is in a guild get the guild name else return empty
135 std::string
getGuildName();
137 /// If the player is in a guild get the amount of money the guild owns else return zero
140 /// If the player is in a guild get the XP the guild owns else return zero
143 /// If the player is in a guild get the guild grade
144 EGSPD::CGuildGrade::TGuildGrade
getGrade() { return _Grade
; }
146 // Called once by frame to check if we have to rebuild interface
149 // Launch ascensor interface
150 void launchAscensor();
152 // Quit ascensor interface
155 // Launch join proposal interface (when a guild member player wants to invite you in its guild)
156 void launchJoinProposal(uint32 phraseID
);
159 void quitJoinProposal();
161 // When quitting a guild we have to close all guild interfaces
162 void closeAllInterfaces();
164 // Rebuild guild interface now
165 void rebuildInterface();
167 // Open the guild window
168 void openGuildWindow();
170 // Icon manipulations
171 // ------------------
172 // Icon is designed like this :
173 // back image : 4 bits at pos 0
174 // symbol image : 6 bits at pos 4
175 // invert symbol : 1 bits at pos 10
176 // color back 1 R : 8 bits at pos 11
177 // color back 1 G : 8 bits at pos 19
178 // color back 1 B : 8 bits at pos 27
179 // color back 2 R : 8 bits at pos 35
180 // color back 2 G : 8 bits at pos 43
181 // color back 2 B : 8 bits at pos 51
183 static uint64
iconMake (uint8 back
, uint8 symb
, bool inv
, NLMISC::CRGBA col1
, NLMISC::CRGBA col2
)
185 return ((uint64
)(back
&15)) | (((uint64
)(symb
&63))<<4) | (((uint64
)(inv
&1))<<10) | \
186 (((uint64
)(col1
.R
&255))<<11) | (((uint64
)(col1
.G
&255))<<19) | (((uint64
)(col1
.B
&255))<<27) | \
187 (((uint64
)(col2
.R
&255))<<35) | (((uint64
)(col2
.G
&255))<<43) | (((uint64
)(col2
.B
&255))<<51);
190 static uint8
iconGetBack(uint64 icon
) { return (uint8
)(icon
&15); }
191 static uint8
iconGetSymbol(uint64 icon
) { return (uint8
)(icon
>>4)&63; }
192 static bool iconGetInvertSymbol(uint64 icon
) { return ((uint8
)(icon
>>10)&1)==0?false:true; }
193 static NLMISC::CRGBA
iconGetColor1(uint64 icon
) { return NLMISC::CRGBA((uint8
)(icon
>>11)&255,(uint8
)(icon
>>19)&255,(uint8
)(icon
>>27)&255); }
194 static NLMISC::CRGBA
iconGetColor2(uint64 icon
) { return NLMISC::CRGBA((uint8
)(icon
>>35)&255,(uint8
)(icon
>>43)&255,(uint8
)(icon
>>51)&255); }
196 static void iconSetBack(uint64
&icon
,uint8 n
) { icon
&= ~((uint64
)15); icon
|= ((uint64
)n
&15); }
197 static void iconSetSymbol(uint64
&icon
,uint8 n
) { icon
&= ~((uint64
)63<<4); icon
|= (((uint64
)n
&63)<<4); }
198 static void iconSetInvertSymbol(uint64
&icon
,bool inv
) { icon
&= ~((uint64
)1<<10); uint64 n
= inv
? 1 : 0; icon
|= n
<< 10; }
199 static void iconSetColor1(uint64
&icon
, NLMISC::CRGBA col
) { icon
&= ~((uint64
)255<<11); icon
&= ~((uint64
)255<<19); icon
&= ~((uint64
)255<<27);
200 icon
|= ((uint64
)col
.R
<<11); icon
|= ((uint64
)col
.G
<<19); icon
|= ((uint64
)col
.B
<<27); }
201 static void iconSetColor2(uint64
&icon
, NLMISC::CRGBA col
) { icon
&= ~((uint64
)255<<35); icon
&= ~((uint64
)255<<43); icon
&= ~((uint64
)255<<51);
202 icon
|= ((uint64
)col
.R
<<35); icon
|= ((uint64
)col
.G
<<43); icon
|= ((uint64
)col
.B
<<51); }
209 // Rebuild (at next update) this is called internally by the observer on DB
210 void rebuildBasic() { _NeedRebuild
= true; }
211 // Need to rebuild Members at next update (+all). this is called internally by the observer on DB
212 void rebuildBasicAndMembers() { _NeedRebuild
= _NeedRebuildMembers
= true; }
215 // Database management stuff
216 class CDBObs
: public NLMISC::ICDBNode::IPropertyObserver
219 virtual void update(NLMISC::ICDBNode
* node
);
221 class CDBObsMembers
: public NLMISC::ICDBNode::IPropertyObserver
224 virtual void update(NLMISC::ICDBNode
* node
);
228 CDBObsMembers _DBObsMembers
;
230 friend class CDBObsMembers
;
232 void initDBObservers();
234 // need rebuild data?
236 bool _NeedRebuildMembers
;
237 // need update (typically names, after rebuild done)
239 bool _NeedUpdateMembers
;
246 /// Singleton's instance
247 static CGuildManager
* _Instance
;
249 // Does the local player belongs to a guild ?
251 // Name Description and icon of the local player guild
253 // Grade of local player giving administration rights
254 // Leader : bear | invite | xp | (kick/set rank) members, bearer, recruiter, officer, high officer or Leader
255 // High Officer : bear | invite | xp | (kick/set rank) members, bearer, recruiter or officer
256 // Officer : bear | invite | kick members, recruiter or bearer
257 // Recruiter : invite
260 // bear=can bear the banner, invite=can invite other players to the guild, xp= can spend XP guild on role masters
261 // kick=can kick a player out of the guild, set rank=set the rank of a guild member
262 EGSPD::CGuildGrade::TGuildGrade _Grade
;
263 // Guild Members of the guild the local player belong to
264 std::vector
<SGuildMember
> _GuildMembers
;
267 CHugeListObs Ascensors
;
269 // flag set to true when EGS says the player has joined the guild
272 // Join Proposal handling
273 uint32 _JoinPropPhraseID
;
274 std::string _JoinPropPhrase
;
275 bool _JoinPropUpdate
;
279 // ***************************************************************************
280 class CDBGroupListAscensor
: public CDBGroupListSheetText
284 struct CSheetChildAscensor
: public CDBGroupListSheetText::CSheetChild
286 enum TAscensorEntryType
295 sint32 SecondSheetIdCache
;
297 virtual void init(CDBGroupListSheetText
*pFather
, uint index
);
298 virtual bool isInvalidated(CDBGroupListSheetText
*pFather
);
299 virtual void updateViewText(CDBGroupListSheetText
* /* pFather */) { }
300 virtual bool isSheetValid(CDBGroupListSheetText
*pFather
);
303 CDBGroupListAscensor(const TCtorParam
¶m
) : CDBGroupListSheetText(param
)
305 _CheckCoordAccelerated
= false; // isInvalidated called each frame
308 virtual CSheetChild
*createSheetChild() { return new CSheetChildAscensor
; }
313 #endif // RY_GUILD_MANAGER_H
315 /* End of guild_manager.h */