Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / sabrina / magic_action_negative_effect.cpp
blob09718ac26239a3fcf8fe3ef301c5e6bdeb137743
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.h"
29 using namespace NLNET;
30 using namespace NLMISC;
31 using namespace RY_GAME_SHARE;
32 using namespace std;
35 class CMagicActionNegativeEffect : public IMagicAction
37 public:
38 CMagicActionNegativeEffect()
39 :_EffectValue(0),_EffectFamily(EFFECT_FAMILIES::Unknown),_CostPerUpdate(0),_Power(0){}
40 protected:
41 virtual bool addBrick( const CStaticBrick & brick, CMagicPhrase * phrase, bool &effectEnd )
43 for ( uint i=0 ; i<brick.Params.size() ; ++i)
45 switch(brick.Params[i]->id())
47 case TBrickParam::MA_END:
48 INFOLOG("MA_END Found: end of effect");
49 effectEnd = true;
50 return true;
51 case TBrickParam::MA_EFFECT:
52 INFOLOG("MA_EFFECT: %s",((CSBrickParamMagicEffect *)brick.Params[i])->Effect.c_str());
53 _EffectFamily = EFFECT_FAMILIES::toEffectFamily( ((CSBrickParamMagicEffect *)brick.Params[i])->Effect );
54 if ( _EffectFamily == EFFECT_FAMILIES::Unknown )
56 nlwarning("<CMagicActionNegativeEffect addBrick> invalid effect type %s", ((CSBrickParamMagicEffect *)brick.Params[i])->Effect.c_str());
57 return false;
59 break;
60 case TBrickParam::MA_EFFECT_MOD:
61 INFOLOG("MA_EFFECT_MOD: %u",((CSBrickParamMagicEffectMod *)brick.Params[i])->EffectMod);
62 _EffectValue = ((CSBrickParamMagicEffectMod *)brick.Params[i])->EffectMod;
63 break;
65 case TBrickParam::MA_LINK_COST:
66 INFOLOG("MA_LINK_COST: %u",((CSBrickParamMagicLinkCost *)brick.Params[i])->Cost);
67 _CostPerUpdate = ((CSBrickParamMagicLinkCost *)brick.Params[i])->Cost;
68 break;
70 case TBrickParam::MA_LINK_POWER:
71 INFOLOG("MA_LINK_POWER: %u",((CSBrickParamMagicLinkPower *)brick.Params[i])->Power);
72 _Power = (uint8) ( ((CSBrickParamMagicLinkPower *)brick.Params[i])->Power );
73 break;
75 default:
76 // unused param, can be useful in the phrase
77 phrase->applyBrickParam( brick.Params[i] );
78 break;
81 ///\todo nico: check if everything is set
82 return true;
84 virtual bool validate(CMagicPhrase * phrase)
86 return PHRASE_UTILITIES::validateSpellTarget(phrase->getActor(),phrase->getTargets()[0],ACTNATURE::OFFENSIVE);
88 virtual void apply( CMagicPhrase * phrase, float successFactor,MBEHAV::CBehaviour & behav, bool isMad )
90 // behav.Spell.Resist = 0;
91 //behav.Spell.KillingBlow = 0;
92 behav.Spell.SpellIntensity = 5;
94 CEntityBase* actor = CEntityBaseManager::getEntityBasePtr( phrase->getActor() );
95 if (!actor)
96 return;
97 // if it is a "degradable" spell, i.e. a spell with a value, it is successful if successFactor > 0, otherwise, successFactor must be >=1)
98 if ( _EffectValue )
100 if ( successFactor <= 0.0f )
102 if ( actor->getId().getType() == RYZOMID::player )
103 CCharacter::sendMessageToClient( actor->getId(),"MAGIC_TOTAL_MISS" );
104 return;
107 else
109 if ( successFactor < 1.0f )
111 if ( actor->getId().getType() == RYZOMID::player )
112 CCharacter::sendMessageToClient( actor->getId(),"MAGIC_TOTAL_MISS" );
113 return;
117 /// apply success factor
118 _EffectValue = uint32( _EffectValue * successFactor);
120 const std::vector< TDataSetRow > & targets = phrase->getTargets();
122 SCORES::TScores linkEnergy;
123 if ( phrase->getHPCost() > 0 )
125 linkEnergy = SCORES::hit_points;
127 else
128 linkEnergy = SCORES::sap;
130 for ( uint i = 0; i < targets.size(); i++ )
132 // check target
133 CEntityBase* target = CEntityBaseManager::getEntityBasePtr( targets[i] );
134 if ( !target)
135 continue;
137 /// someone can only have 1 effect of a given type on a creature
138 const std::vector< CSEffect* > & effects = target->getSEffects();
139 for (uint j = 0; j < effects.size(); j++ )
141 if ( effects[j]->getFamily() == _EffectFamily && effects[j]->getCreatorRowId() == phrase->getActor( ) )
143 return;
147 if ( isMad || PHRASE_UTILITIES::validateSpellTarget(actor->getEntityRowId(),target->getEntityRowId(),ACTNATURE::OFFENSIVE) )
149 CSLinkEffectOffensive* effect = new CSLinkEffectOffensive(
150 phrase->getActor(),
151 targets[i],
152 _EffectFamily,
153 _CostPerUpdate,
154 linkEnergy,
155 _Skill,
156 _EffectValue,
157 _Power);
159 actor->addLink( effect );
160 target->addSabrinaEffect( effect );
161 behav.Spell.SpellId = MAGICFX::toMagicFx(_EffectFamily );
166 EFFECT_FAMILIES::TEffectFamily _EffectFamily;
167 sint32 _EffectValue;
168 uint _CostPerUpdate;
169 uint8 _Power;
172 BEGIN_MAGIC_ACTION_FACTORY(CMagicActionNegativeEffect)
173 ADD_MAGIC_ACTION_TYPE( "mlos" )
174 ADD_MAGIC_ACTION_TYPE( "mloc" )
175 END_MAGIC_ACTION_FACTORY(CMagicActionNegativeEffect)