Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / sabrina / magic_action_hot.cpp
blob1f11e64c620a4d83b2b702816d1aac5683116cd1
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_link_effect_hot.h"
29 using namespace NLNET;
30 using namespace NLMISC;
31 using namespace RY_GAME_SHARE;
32 using namespace std;
36 class CMagicActionHot : public IMagicAction
38 public:
39 CMagicActionHot()
40 :_HealHp(0),_HealSap(0),_HealSta(0),_CostPerUpdate(0),_Power(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;
53 case TBrickParam::MA_HEAL:
54 INFOLOG("MA_HEAL: %u %u %u",((CSBrickParamMagicHeal *)brick.Params[i])->Hp,((CSBrickParamMagicHeal *)brick.Params[i])->Sap,((CSBrickParamMagicHeal *)brick.Params[i])->Sta);
55 _HealHp = ((CSBrickParamMagicHeal *)brick.Params[i])->Hp;
56 _HealSap = ((CSBrickParamMagicHeal *)brick.Params[i])->Sap;
57 _HealSta = ((CSBrickParamMagicHeal *)brick.Params[i])->Sta;
59 case TBrickParam::MA_LINK_COST:
60 INFOLOG("MA_LINK_COST: %u",((CSBrickParamMagicLinkCost *)brick.Params[i])->Cost);
61 _CostPerUpdate = ((CSBrickParamMagicLinkCost *)brick.Params[i])->Cost;
62 break;
64 case TBrickParam::MA_LINK_POWER:
65 INFOLOG("MA_LINK_POWER: %u",((CSBrickParamMagicLinkPower *)brick.Params[i])->Power);
66 _Power = (uint8) ( ((CSBrickParamMagicLinkPower *)brick.Params[i])->Power );
67 break;
69 default:
70 // unused param, can be useful in the phrase
71 phrase->applyBrickParam( brick.Params[i] );
72 break;
75 ///\todo nico: check if everything is set
76 return true;
78 virtual bool validate(CMagicPhrase * phrase)
80 return PHRASE_UTILITIES::validateSpellTarget(phrase->getActor(),phrase->getTargets()[0],ACTNATURE::DEFENSIVE);
82 virtual void apply( CMagicPhrase * phrase, float successFactor,MBEHAV::CBehaviour & behav , bool isMad )
84 // behav.Spell.Resist = 0;
85 //behav.Spell.KillingBlow = 0;
86 behav.Spell.SpellIntensity = 5;
87 CEntityBase* actor = CEntityBaseManager::getEntityBasePtr( phrase->getActor() );
88 if (!actor)
89 return;
90 if ( successFactor <= 0.0f )
92 if ( actor->getId().getType() == RYZOMID::player )
93 CCharacter::sendMessageToClient( actor->getId(),"MAGIC_TOTAL_MISS" );
96 /// apply success factor
98 const std::vector< TDataSetRow > & targets = phrase->getTargets();
100 SCORES::TScores linkEnergy;
101 if ( phrase->getHPCost() > 0 )
103 linkEnergy = SCORES::hit_points;
105 else
106 linkEnergy = SCORES::sap;
108 for ( uint i = 0; i < targets.size(); i++ )
110 // check target
111 CEntityBase* target = CEntityBaseManager::getEntityBasePtr( targets[i] );
112 if ( !target)
113 continue;
115 /// someone can only have 1 effect of a given type on a creature
116 const std::vector< CSEffect* > & effects = target->getSEffects();
117 for (uint j = 0; j < effects.size(); j++ )
119 if ( effects[j]->getFamily() == EFFECT_FAMILIES::Hot && effects[j]->getCreatorRowId() == phrase->getActor( ) )
121 return;
124 if ( isMad || PHRASE_UTILITIES::validateSpellTarget(actor->getEntityRowId(),target->getEntityRowId(),ACTNATURE::DEFENSIVE) )
126 CSLinkEffectHot* hot = new CSLinkEffectHot( phrase->getActor(),
127 targets[i],
128 _CostPerUpdate,
129 linkEnergy,
130 _Skill,
131 _Power,
132 uint32(_HealHp * successFactor* CSLinkEffect::getUpdatePeriod()),
133 uint32(_HealSap * successFactor* CSLinkEffect::getUpdatePeriod()),
134 uint32(_HealSta * successFactor* CSLinkEffect::getUpdatePeriod()) );
136 actor->addLink( hot );
137 target->addSabrinaEffect( hot );
140 behav.Spell.SpellId = MAGICFX::healtoMagicFx( _HealHp,_HealSap,_HealSta,true );
144 sint32 _HealHp;
145 sint32 _HealSap;
146 sint32 _HealSta;
147 uint _CostPerUpdate;
148 uint8 _Power;
151 BEGIN_MAGIC_ACTION_FACTORY(CMagicActionHot)
152 ADD_MAGIC_ACTION_TYPE( "mlc" )
153 END_MAGIC_ACTION_FACTORY(CMagicActionHot)