Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / client / src / interface_v3 / skill_manager.h
blobf47da38c5f791a2db25cb9d1222cdd2fa3767e3e
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef RY_SKILL_MANAGER_H
23 #define RY_SKILL_MANAGER_H
25 #include "nel/misc/types_nl.h"
26 #include "game_share/skills.h"
27 //#include "game_share/jobs.h"
28 #include "game_share/roles.h"
29 #include "nel/misc/cdb.h"
30 #include "brick_learned_callback.h"
31 #include "skill_change_callback.h"
33 #include "game_share/skills.h"
34 #include "game_share/memorization_set_types.h"
35 #include "../client_sheets/skills_tree_sheet.h"
36 #include "../client_sheets/unblock_titles_sheet.h"
38 // ***************************************************************************
39 /**
40 * class used to manage the skill tree
41 * \author Matthieu 'TrapII' Besson
42 * \author Nevrax France
43 * \date 2003 September
45 class CSkillManager
48 public:
50 /// The singleton's instance
51 static CSkillManager* getInstance()
53 if (!_Instance)
54 _Instance = new CSkillManager;
55 return _Instance;
58 // release singleton
59 static void releaseInstance()
61 delete _Instance;
62 _Instance = NULL;
65 /// Destructor
66 virtual ~CSkillManager();
68 // Initialize by loading skills (load the skill_tree stuffs) and organize so in the vector skill == index
69 void initInGame();
70 void uninitInGame();
72 bool isUnknown (SKILLS::ESkills eSkill);
74 SKILLS::ESkills getParent (SKILLS::ESkills eSkill);
76 const std::vector<SKILLS::ESkills> &getChildren (SKILLS::ESkills eSkill);
78 /// return true if 2 skills are on the same Branch (ie compatible). NB: return false if one is unknown
79 bool areSkillOnSameBranch(SKILLS::ESkills s0, SKILLS::ESkills s1);
81 /// return true if the skill s0 is an ancestor of skill s1 (true if s0==s1)
82 bool isSkillAncestor(SKILLS::ESkills s0, SKILLS::ESkills s1);
84 /// Get the MinSkillValue (ie the max skill value of the parent)
85 uint32 getMinSkillValue(SKILLS::ESkills eSkill);
87 /// Get the MaxSkillValue
88 uint32 getMaxSkillValue(SKILLS::ESkills eSkill);
90 /// Get the SkillValue in the database (BUFFED one)
91 uint32 getSkillValue(SKILLS::ESkills eSkill);
93 /// Get the SkillValue in the database (unBUFFED one)
94 uint32 getBaseSkillValue(SKILLS::ESkills eSkill);
97 /// Get the SkillValue in the database (BUFFED one). Get the max of the skill and its parent
98 uint32 getSkillValueMaxBranch(SKILLS::ESkills eSkill);
100 /// Get the SkillValue in the database (unBUFFED one). Get the max of the skill and its parent
101 uint32 getBaseSkillValueMaxBranch(SKILLS::ESkills eSkill);
103 /// Get the SkillValue in the database (BUFFED one). Get the max of the skill and its children
104 /// NB: warning: slow since recursive
105 uint32 getSkillValueMaxChildren(SKILLS::ESkills eSkill);
107 /// Get the MaxSkillValue in the branch (from parent to children) (BUFFED one)
108 /// NB: warning: slow since use getSkillValueMaxChildren
109 uint32 getBestSkillValue(SKILLS::ESkills eSkill);
111 /// Get the BaseSkillValue in the database (unBUFFED one). Get the max of the skill and its children
112 /// NB: fast O(1) since BaseSkillValue
113 uint32 getBaseSkillValueMaxChildren(SKILLS::ESkills eSkill);
115 /// return true if base skill max branch value is > required skill value
116 bool checkBaseSkillMetRequirement(SKILLS::ESkills eSkill, uint32 value);
118 /// Callback called when any skill change
119 void appendSkillChangeCallback(ISkillChangeCallback *cb);
120 void removeSkillChangeCallback(ISkillChangeCallback *cb);
122 /// CHARACTER TITLE
124 /// Append the brick learned callback to the brick manager
125 void initTitles();
127 /// Remove the callback
128 void uninitTitles();
130 /// Called when a skill change to look if we can unblock a title
131 void tryToUnblockTitleFromSkill(SKILLS::ESkills eSkill, sint32 value);
133 /// The same but with parsing all bricks wanted
134 void tryToUnblockTitleFromBricks(bool show_message = true);
136 /// The same but with civ allegiance
137 void tryToUnblockTitleFromCiv(bool show_message = true);
139 /// The same but with cult allegiance
140 void tryToUnblockTitleFromCult(bool show_message = true);
142 /// The same but with parsing all items wanted
143 void tryToUnblockTitleFromItems(bool show_message = true);
145 /// Called when a fame changes to look if we can unblock a title
146 void tryToUnblockTitleFromMinFames(uint32 factionIndex, sint32 fameValue);
147 void tryToUnblockTitleFromMaxFames(uint32 factionIndex, sint32 fameValue);
149 /// called after user chose a char, unblock titles from char time properties
150 void tryToUnblockTitleFromCharOldness( uint32 firstConnectedTime );
151 void tryToUnblockTitleFromCharPlayedTime( uint32 playedTime );
152 void tryToUnblockTitleFromAccountOldness( uint32 accountCreationTime );
154 /// called when ring ratings change
155 void tryToUnblockTitleFromRingRatings(uint32 authorRating, uint32 amRating, uint32 masterlessRating);
157 /// Unblock a reserved title from the server
158 void unblockTitleFromServer(CHARACTER_TITLE::ECharacterTitle ct);
160 /// Block a reserved title from the server
161 void blockTitleFromServer(CHARACTER_TITLE::ECharacterTitle ct);
163 /// Is the title unblocked and accessible to the player ?
164 bool isTitleUnblocked(CHARACTER_TITLE::ECharacterTitle ct) { return _TitlesUnblocked[ct].Unblocked; }
166 /// Is the title reserved (can be unblocked only by a server message)
167 bool isTitleReserved(CHARACTER_TITLE::ECharacterTitle ct) { return _UnblockTitle->TitlesUnblock[ct].Reserved; }
169 void setPlayerTitle(const std::string &name);
170 uint8 getPlayerTitle() const { return _CurrentTitle; }
172 protected:
174 void setCurrentTitle(uint8 title);
176 private:
177 // update parent skills max child value for given skill
178 void updateParentSkillsMaxChildValue(SKILLS::ESkills eSkill);
180 /// compute parent skills max child value for all skill tree
181 void computeMaxChildValues();
183 /// Constructor
184 CSkillManager();
186 /// Singleton's instance
187 static CSkillManager *_Instance;
189 CSkillsTreeSheet *_Tree;
191 // Minimum skills values
192 uint32 _MinSkillValue[SKILLS::NUM_SKILLS];
194 /// Nodes on skill values and base values
195 NLMISC::CCDBNodeLeaf *_SkillValues[SKILLS::NUM_SKILLS];
196 NLMISC::CCDBNodeLeaf *_SkillBaseValues[SKILLS::NUM_SKILLS];
198 // Max child baseskill value (used when checking requirements)
199 uint32 _MaxChildBaseSkillValue[SKILLS::NUM_SKILLS];
201 // CallBack set for skill changes
202 struct CSkillChangeObs : public NLMISC::ICDBNode::IPropertyObserver
204 virtual void update (NLMISC::ICDBNode * /* node */)
206 CSkillManager *pSM= CSkillManager::getInstance();
207 pSM->onSkillChange();
210 friend struct CSkillChangeObs;
211 CSkillChangeObs _SkillChangeObs;
212 typedef std::set<ISkillChangeCallback*> TSCCBSet;
213 TSCCBSet _SkillChangeCallbackSet;
214 void onSkillChange();
215 // Cache to know if skill really changed (not PROGRESS_BAR)
216 sint32 _CacheSkillValues[SKILLS::NUM_SKILLS];
217 sint32 _CacheSkillBaseValues[SKILLS::NUM_SKILLS];
219 // A node incremented at each change of skill (the number is not relevant)
220 NLMISC::CCDBNodeLeaf *_TrackSkillChange;
222 // "Title of the player" Management
223 // -----------------------------------------------------------------------------
224 friend class CHandlerTitleInit;
225 friend class CHandlerTitleButton;
226 friend class CHandlerTitleChanged;
228 struct SUnblockingTitle
230 bool Unblocked;
231 std::vector<bool> UnblockedSkillLists;
232 std::vector<bool> UnblockedBricks;
233 std::vector<bool> UnblockedMinFames;
234 std::vector<bool> UnblockedMaxFames;
235 std::vector<bool> UnblockedItemLists;
236 bool UnblockedCiv;
237 bool UnblockedCult;
238 bool UnblockedCharOldness;
239 bool UnblockedCharPlayedTime;
240 bool UnblockedAccountOldness;
241 bool UnblockedAuthorRating;
242 bool UnblockedAMRating;
243 bool UnblockedOrganizerRating;
247 std::vector<SUnblockingTitle> _TitlesUnblocked;
248 void checkTitleUnblocked(CHARACTER_TITLE::ECharacterTitle i, bool show_message = true);
250 uint8 _CurrentTitle;
251 std::vector<sint32> _UIUnblockedTitles;
252 CUnblockTitlesSheet *_UnblockTitle;
254 class CBrickLearnedCB : public IBrickLearnedCallback
256 public:
257 virtual void onBrickLearned()
259 CSkillManager::getInstance()->tryToUnblockTitleFromBricks();
263 CBrickLearnedCB BrickLearnedCB;
267 #define WIN_FAME_LIST "ui:interface:fame:content:fame_list:list"
268 #define TEMPLATE_FAME "fame_charac"
270 #endif // RY_SKILL_MANAGER_H
272 /* End of skill_manager.h */