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"
27 #include "s_link_effect_hot.h"
29 using namespace NLNET
;
30 using namespace NLMISC
;
31 using namespace RY_GAME_SHARE
;
36 class CMagicActionHot
: public IMagicAction
40 :_HealHp(0),_HealSap(0),_HealSta(0),_CostPerUpdate(0),_Power(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");
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
;
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
);
70 // unused param, can be useful in the phrase
71 phrase
->applyBrickParam( brick
.Params
[i
] );
75 ///\todo nico: check if everything is set
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() );
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
;
106 linkEnergy
= SCORES::sap
;
108 for ( uint i
= 0; i
< targets
.size(); i
++ )
111 CEntityBase
* target
= CEntityBaseManager::getEntityBasePtr( targets
[i
] );
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( ) )
124 if ( isMad
|| PHRASE_UTILITIES::validateSpellTarget(actor
->getEntityRowId(),target
->getEntityRowId(),ACTNATURE::DEFENSIVE
) )
126 CSLinkEffectHot
* hot
= new CSLinkEffectHot( phrase
->getActor(),
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 );
151 BEGIN_MAGIC_ACTION_FACTORY(CMagicActionHot
)
152 ADD_MAGIC_ACTION_TYPE( "mlc" )
153 END_MAGIC_ACTION_FACTORY(CMagicActionHot
)