Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / sabrina / s_link_effect.cpp
blob3d52a03a31f76b65d32a70a84ef19e5ef8bd5e3d
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/>.
18 #include "stdpch.h"
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"
27 using namespace std;
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() );
45 return true;
47 return false;
48 }// CSLinkEffect update
52 //-----------------------------------------------
53 // CSLinkEffect update
54 //-----------------------------------------------
55 bool CSLinkEffect::update(uint32 & updateFlag)
57 CEntityBase * caster = CEntityBaseManager::getEntityBasePtr( _CreatorRowId );
58 if ( !caster )
60 nlwarning("<CSLinkEffectDot update> Invalid caster %u",_CreatorRowId.getIndex() );
61 return true;
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;
69 return false;
72 return true;
75 //-----------------------------------------------
76 // CSLinkEffect removed
77 //-----------------------------------------------
78 void CSLinkEffect::removed()
80 CEntityBase * caster = CEntityBaseManager::getEntityBasePtr( _CreatorRowId );
81 if ( !caster )
83 nlwarning("<CSLinkEffectDot removed> Invalid caster %u",_CreatorRowId.getIndex() );
84 return;
86 caster->removeLink( this );
89 //-----------------------------------------------
90 // CSLinkEffectOffensive apply
91 //-----------------------------------------------
92 bool CSLinkEffectOffensive::update( uint32 & updateFlag )
94 if ( CSLinkEffect::update(updateFlag) )
95 return true;
96 CEntityBase * caster = CEntityBaseManager::getEntityBasePtr( _CreatorRowId );
97 if ( !caster )
99 nlwarning("<CSLinkEffectDot update> Invalid caster %u",_CreatorRowId.getIndex() );
100 return true;
102 CEntityBase * target = CEntityBaseManager::getEntityBasePtr( _TargetRowId );
103 if ( !target )
105 nlwarning("<CSLinkEffectDot update> Invalid target %u",_TargetRowId.getIndex() );
106 return true;
109 // test resistance
110 /* SSkill * skillResist = target->getSkills().getSkillStruct( SKILLS::MagicDefense ); //TODO skill missing
111 if ( ! skillResist )
113 nlwarning("<CSLinkEffectDot update> MagicDefense is not a valid skill");
114 return true;
116 */ SSkill * skillActor = caster->getSkills().getSkillStruct( _Skill );
117 if ( ! skillActor )
119 nlwarning("<CSLinkEffectDot update> %s is not a valid skill",SKILLS::toString(_Skill).c_str());
120 return true;
122 const CSEffect * debuff = caster->lookForSEffect( EFFECT_FAMILIES::DebuffSkillMagic );
123 sint skillValue = skillActor->Current;
124 if ( debuff )
125 skillValue -= debuff->getParamValue();
127 // cap skill values with brick power
128 if ( _Power < skillValue )
129 skillValue = _Power;
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);
137 bool end = true;
138 if ( _ResistFactor > 0.0f )
140 end = false;
141 if ( _ResistFactor > 1.0f )
143 _ResistFactor = 1.0f;
146 else
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 ) );
162 return end;