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/>.
20 #include "magic_action.h"
21 #include "magic_phrase.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"
29 using namespace NLNET
;
30 using namespace NLMISC
;
31 using namespace RY_GAME_SHARE
;
36 class CMagicActionBasicHeal
: public IMagicAction
39 CMagicActionBasicHeal()
40 :_HealHp(0),_HealSap(0),_HealSta(0){}
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");
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
;
59 // unused param, can be useful in the phrase
60 phrase
->applyBrickParam( brick
.Params
[i
] );
64 ///\todo nico: check if everything is set
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
)
74 // - behaviour + messages de chat
77 CEntityBase
* actor
= CEntityBaseManager::getEntityBasePtr( phrase
->getActor() );
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();
88 SSkill
* skillCast
= actor
->getSkills().getSkillStruct( _Skill
);
91 nlwarning("<CMagicActionHeal apply> %s is not a valid skill",SKILLS::toString(_Skill
).c_str());
94 const CSEffect
* debuff
= actor
->lookForSEffect( EFFECT_FAMILIES::DebuffSkillMagic
);
95 sint skillValue
= skillCast
->Current
;
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
108 CEntityBase
* target
= CEntityBaseManager::getEntityBasePtr( targets
[i
] );
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
;
127 PHRASE_UTILITIES::sendScoreModifierSpellMessage( actor
, target
, realHealHp
,SCORES::hit_points
, ACTNATURE::DEFENSIVE
);
128 score
.Current
= score
.Max
;
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
;
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
;
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 );
176 BEGIN_MAGIC_ACTION_FACTORY(CMagicActionBasicHeal
)
177 ADD_MAGIC_ACTION_TYPE( "mtch" )
178 END_MAGIC_ACTION_FACTORY(CMagicActionBasicHeal
)