Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / sabrina / magic_action_heal.cpp
blobb4b0a12aaf358e5b2455971bbcb795e44e7188a4
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/>.
19 #include "stdpch.h"
20 #include "magic_action.h"
21 #include "magic_phrase.h"
22 #include "creature.h"
23 #include "character.h"
24 #include "phrase_utilities_functions.h"
25 #include "game_share/entity_structure/statistic.h"
26 #include "game_share/magic_fx.h"
27 #include "s_effect.h"
29 using namespace NLNET;
30 using namespace NLMISC;
31 using namespace RY_GAME_SHARE;
32 using namespace std;
36 class CMagicActionBasicHeal : public IMagicAction
38 public:
39 CMagicActionBasicHeal()
40 :_HealHp(0),_HealSap(0),_HealSta(0){}
41 protected:
42 virtual bool addBrick( const CStaticBrick & brick, CMagicPhrase * phrase, bool &effectEnd )
44 for ( uint i=0 ; i<brick.Params.size() ; ++i)
46 switch(brick.Params[i]->id())
48 case TBrickParam::MA_END:
49 INFOLOG("MA_END Found: end of effect");
50 effectEnd = true;
51 return true;
52 case TBrickParam::MA_HEAL:
53 INFOLOG("MA_HEAL: %u %u %u",((CSBrickParamMagicHeal *)brick.Params[i])->Hp,((CSBrickParamMagicHeal *)brick.Params[i])->Sap,((CSBrickParamMagicHeal *)brick.Params[i])->Sta);
54 _HealHp = ((CSBrickParamMagicHeal *)brick.Params[i])->Hp;
55 _HealSap = ((CSBrickParamMagicHeal *)brick.Params[i])->Sap;
56 _HealSta = ((CSBrickParamMagicHeal *)brick.Params[i])->Sta;
58 default:
59 // unused param, can be useful in the phrase
60 phrase->applyBrickParam( brick.Params[i] );
61 break;
64 ///\todo nico: check if everything is set
65 return true;
67 virtual bool validate(CMagicPhrase * phrase)
69 return PHRASE_UTILITIES::validateSpellTarget(phrase->getActor(),phrase->getTargets()[0],ACTNATURE::DEFENSIVE);
71 virtual void apply( CMagicPhrase * phrase, float successFactor,MBEHAV::CBehaviour & behav , bool isMad )
73 ///\todo nico:
74 // - behaviour + messages de chat
75 // - aggro
77 CEntityBase* actor = CEntityBaseManager::getEntityBasePtr( phrase->getActor() );
78 if (!actor)
79 return;
80 if ( successFactor <= 0.0f )
82 if ( actor->getId().getType() == RYZOMID::player )
83 CCharacter::sendMessageToClient( actor->getId(),"MAGIC_TOTAL_MISS" );
85 const std::vector< TDataSetRow > & targets = phrase->getTargets();
87 /// compute XP gain
88 SSkill * skillCast = actor->getSkills().getSkillStruct( _Skill );
89 if ( ! skillCast )
91 nlwarning("<CMagicActionHeal apply> %s is not a valid skill",SKILLS::toString(_Skill).c_str());
92 return;
94 const CSEffect * debuff = actor->lookForSEffect( EFFECT_FAMILIES::DebuffSkillMagic );
95 sint skillValue = skillCast->Current;
96 if ( debuff )
97 skillValue -= debuff->getParamValue();
99 if ( actor->getId().getType() == RYZOMID::player )
101 ///\todo nico successFactor is the quality factor of the action for xp
102 ((CCharacter*) actor)->actionReport( NULL, ( skillValue - phrase->getSabrinaCost() )/10, ACTNATURE::DEFENSIVE, SKILLS::toString( _Skill ) );
104 for ( uint i = 0; i < targets.size(); i++ )
106 ///\todo nico : healing a bad guy is PVP, but it should be possible to heal escort NPCS
107 // check target
108 CEntityBase* target = CEntityBaseManager::getEntityBasePtr( targets[i] );
109 if ( !target)
110 continue;
112 if ( isMad || PHRASE_UTILITIES::validateSpellTarget(actor->getEntityRowId(),target->getEntityRowId(),ACTNATURE::DEFENSIVE) )
114 //behav.Magic.SpellPower = PHRASE_UTILITIES::getAttackIntensity( phrase->getSabrinaCost() );
115 //behav.Spell.Resist = 0;
116 //behav.Spell.KillingBlow = 0;
119 sint32 realHealHp = 0;
121 RY_GAME_SHARE::SCharacteristicsAndScores &score = target->getScores()._PhysicalScores[SCORES::hit_points];
122 score.Current = score.Current + sint32(_HealHp * successFactor);
123 if ( score.Current >= score.Max )
125 realHealHp = sint32(_HealHp * successFactor) + score.Max - score.Current;
126 if ( realHealHp > 0)
127 PHRASE_UTILITIES::sendScoreModifierSpellMessage( actor, target, realHealHp,SCORES::hit_points , ACTNATURE::DEFENSIVE);
128 score.Current = score.Max;
130 else
131 PHRASE_UTILITIES::sendScoreModifierSpellMessage( actor, target, realHealHp ,SCORES::hit_points , ACTNATURE::DEFENSIVE);
133 sint32 realHealSap = 0;
135 RY_GAME_SHARE::SCharacteristicsAndScores &score = target->getScores()._PhysicalScores[SCORES::sap];
136 score.Current = score.Current + sint32(_HealSap * successFactor);
137 if ( score.Current >= score.Max )
139 realHealSap = sint32(_HealSap * successFactor) + score.Max - score.Current;
140 if ( realHealSap > 0)
141 PHRASE_UTILITIES::sendScoreModifierSpellMessage( actor, target, realHealSap,SCORES::sap , ACTNATURE::DEFENSIVE);
142 score.Current = score.Max;
144 else
145 PHRASE_UTILITIES::sendScoreModifierSpellMessage( actor, target, realHealSap ,SCORES::sap , ACTNATURE::DEFENSIVE);
148 sint32 realHealSta = 0;
150 RY_GAME_SHARE::SCharacteristicsAndScores &score = target->getScores()._PhysicalScores[SCORES::stamina];
151 score.Current = score.Current + sint32(_HealSta * successFactor);
152 if ( score.Current >= score.Max )
154 realHealSta = sint32(_HealSta * successFactor) + score.Max - score.Current;
155 if ( realHealSta > 0)
156 PHRASE_UTILITIES::sendScoreModifierSpellMessage( actor, target, realHealSta,SCORES::stamina , ACTNATURE::DEFENSIVE);
157 score.Current = score.Max;
159 else
160 PHRASE_UTILITIES::sendScoreModifierSpellMessage( actor, target, realHealSta ,SCORES::stamina , ACTNATURE::DEFENSIVE);
162 /*behav.Magic.ImpactIntensity = PHRASE_UTILITIES::getImpactIntensity( realHealHp ,targets[i],SCORES::hit_points);
163 behav.Magic.ImpactIntensity += PHRASE_UTILITIES::getImpactIntensity( realHealSap ,targets[i],SCORES::sap);
164 behav.Magic.ImpactIntensity = PHRASE_UTILITIES::getImpactIntensity( realHealSta ,targets[i],SCORES::stamina);
166 behav.Spell.SpellIntensity = 5;
167 behav.Spell.SpellId = MAGICFX::healtoMagicFx( _HealHp,_HealSap,_HealSta,false );
171 sint32 _HealHp;
172 sint32 _HealSap;
173 sint32 _HealSta;
176 BEGIN_MAGIC_ACTION_FACTORY(CMagicActionBasicHeal)
177 ADD_MAGIC_ACTION_TYPE( "mtch" )
178 END_MAGIC_ACTION_FACTORY(CMagicActionBasicHeal)