1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
19 #include "s_link_effect.h"
20 #include "entity_manager.h"
21 #include "character.h"
22 #include "phrase_utilities_functions.h"
23 #include "game_share/entity_structure/statistic.h"
24 #include "nel/misc/random.h"
25 #include "s_link_effect.h"
28 using namespace NLMISC
;
29 using namespace RY_GAME_SHARE
;
31 extern CRandom RandomGenerator
;
33 double CSLinkEffect::_UpdatePeriod
= 4.0f
;
36 //-----------------------------------------------
37 // CSLinkEffect update
38 //-----------------------------------------------
39 bool CSLinkEffect::isTimeToUpdate()
41 const NLMISC::TGameCycle time
= CTickEventHandler::getGameCycle();
42 if ( time
>= _NextUpdate
)
44 _NextUpdate
= time
+ NLMISC::TGameCycle( _UpdatePeriod
/ CTickEventHandler::getGameTimeStep() );
48 }// CSLinkEffect update
52 //-----------------------------------------------
53 // CSLinkEffect update
54 //-----------------------------------------------
55 bool CSLinkEffect::update(uint32
& updateFlag
)
57 CEntityBase
* caster
= CEntityBaseManager::getEntityBasePtr( _CreatorRowId
);
60 nlwarning("<CSLinkEffectDot update> Invalid caster %u",_CreatorRowId
.getIndex() );
63 RY_GAME_SHARE::SCharacteristicsAndScores
& score
= caster
->getScores()._PhysicalScores
[_EnergyCost
];
64 if ( score
.Current
!= 0)
66 if ( score
.Current
> _CostPerUpdate
)
68 score
.Current
= score
.Current
- _CostPerUpdate
;
75 //-----------------------------------------------
76 // CSLinkEffect removed
77 //-----------------------------------------------
78 void CSLinkEffect::removed()
80 CEntityBase
* caster
= CEntityBaseManager::getEntityBasePtr( _CreatorRowId
);
83 nlwarning("<CSLinkEffectDot removed> Invalid caster %u",_CreatorRowId
.getIndex() );
86 caster
->removeLink( this );
89 //-----------------------------------------------
90 // CSLinkEffectOffensive apply
91 //-----------------------------------------------
92 bool CSLinkEffectOffensive::update( uint32
& updateFlag
)
94 if ( CSLinkEffect::update(updateFlag
) )
96 CEntityBase
* caster
= CEntityBaseManager::getEntityBasePtr( _CreatorRowId
);
99 nlwarning("<CSLinkEffectDot update> Invalid caster %u",_CreatorRowId
.getIndex() );
102 CEntityBase
* target
= CEntityBaseManager::getEntityBasePtr( _TargetRowId
);
105 nlwarning("<CSLinkEffectDot update> Invalid target %u",_TargetRowId
.getIndex() );
110 /* SSkill * skillResist = target->getSkills().getSkillStruct( SKILLS::MagicDefense ); //TODO skill missing
113 nlwarning("<CSLinkEffectDot update> MagicDefense is not a valid skill");
116 */ SSkill
* skillActor
= caster
->getSkills().getSkillStruct( _Skill
);
119 nlwarning("<CSLinkEffectDot update> %s is not a valid skill",SKILLS::toString(_Skill
).c_str());
122 const CSEffect
* debuff
= caster
->lookForSEffect( EFFECT_FAMILIES::DebuffSkillMagic
);
123 sint skillValue
= skillActor
->Current
;
125 skillValue
-= debuff
->getParamValue();
127 // cap skill values with brick power
128 if ( _Power
< skillValue
)
131 // get the chances ( delta level is divided by 10 because a level is 10
132 const uint8 chances
= PHRASE_UTILITIES::getSuccessChance( ( skillValue
/*- skillResist->Current*/ )/10 ); //TODO skill missing
133 const uint8 roll
= (uint8
)RandomGenerator
.rand( 99 );
135 _ResistFactor
= PHRASE_UTILITIES::getSucessFactor(chances
, roll
);
138 if ( _ResistFactor
> 0.0f
)
141 if ( _ResistFactor
> 1.0f
)
143 _ResistFactor
= 1.0f
;
148 if ( caster
->getId().getType() == RYZOMID::player
)
149 CCharacter::sendMessageToClient( caster
->getId(),"MAGIC_TOTAL_RESIST" );
150 if ( target
->getId().getType() == RYZOMID::player
)
151 CCharacter::sendMessageToClient( target
->getId(),"MAGIC_U_TOTAL_RESIST");
154 // compute resist XP gain, if such an effect was not already resisted
155 if ( target
->getId().getType() == RYZOMID::player
&& _ResistFactor
< 1.0f
)
157 ///\todo nico successFactor is the quality factor of the action for xp
159 // TODO skill missing
160 // ((CCharacter*) target)->actionReport( caster, ( skillResist->Current - skillValue)/10, ACTNATURE::DEFENSIVE, SKILLS::toString( SKILLS::MagicDefense ) );