Add infos into target window
[ryzomcore.git] / ryzom / server / src / entities_game_service / death_penalties.h
blob02d3e48fbb653c0bd925d2843f588fef8fd440d3
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
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 Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef RY_DEATH_PENALTIES_H
18 #define RY_DEATH_PENALTIES_H
20 #include "egs_variables.h"
21 #include "game_share/persistent_data.h"
22 #include "game_share/skills.h"
24 #include "game_share/timer.h"
27 class CCharacter;
29 /**
30 * properties to manage death penalties
31 * \author Nicolas Brigand
32 * \author Nevrax France
33 * \date 2004
35 class CDeathPenalties
37 NL_INSTANCE_COUNTER_DECL(CDeathPenalties);
38 public:
40 // Start by declaring methods for persistent load/ save operations
41 // The following macro is defined in persistent_data.h
42 // At time of writing it evaluated to:
43 // void store(CPersistentDataRecord &pdr) const;
44 // void apply(CPersistentDataRecord &pdr);
46 DECLARE_PERSISTENCE_METHODS
48 CDeathPenalties()
49 :_NbDeath(0),_CurrentDeathXP(0.0),_DeathXPToGain(0.0),_BonusUpdateTime(0),_DeathPenaltyFactor(1.0f){}
51 void clear()
53 _NbDeath = 0;
54 _CurrentDeathXP = 0.0;
55 _DeathXPToGain = 0.0;
56 _BonusUpdateTime = 0;
59 void reset(CCharacter& user)
61 clear();
62 updataDb(user);
65 double getDeathXPToGain() { return _DeathXPToGain - _CurrentDeathXP; }
66 void addDeathXP(CCharacter *user, double xp)
68 _CurrentDeathXP += xp;
69 updataDb(*user);
72 void addDeath(CCharacter& user, float deathPenaltyFactor);
74 uint32 updateResorption( CCharacter& user );
76 void addXP( CCharacter& user, SKILLS::ESkills usedSkill, double & xp );
78 void addXP( CCharacter& user, SKILLS::ESkills usedSkill, double & xp, double xpRaw );
80 void serial( NLMISC::IStream & f )
82 f.xmlPush("death_penalties");
83 f.xmlPush("nb_death");
84 f.serial(_NbDeath);
85 f.xmlPop();
86 f.xmlPush("current_death_xp");
87 f.serial(_CurrentDeathXP);
88 f.xmlPop();
89 f.xmlPush("death_xp_to_gain");
90 f.serial(_DeathXPToGain);
91 f.xmlPop();
92 f.xmlPush("bonus_update_time");
93 f.serial(_BonusUpdateTime);
94 f.xmlPop();
95 f.xmlPush("nb_death");
98 void updataDb(CCharacter& user);
100 bool isNull() const { return (_NbDeath == 0); }
102 private:
103 /// number of death of the player ( reset when there is no more XP malus )
104 uint8 _NbDeath;
105 /// XP gained to recover from death
106 double _CurrentDeathXP;
107 /// XP to gain to recover from death malus
108 double _DeathXPToGain;
109 /// Last time at which bonus was given
110 uint32 _BonusUpdateTime;
111 /// factor of xp used for death penalty
112 float _DeathPenaltyFactor;
115 class CDeathPenaltiesTimerEvent:public CTimerEvent
117 public:
118 CDeathPenaltiesTimerEvent(CCharacter *parent);
119 void timerCallback(CTimer *owner);
120 private:
121 CCharacter *_Parent;
124 #endif // RY_DEATH_PENALTIES_H
126 /* End of death_penalties.h */