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.h"
29 using namespace NLNET
;
30 using namespace NLMISC
;
31 using namespace RY_GAME_SHARE
;
35 class CMagicActionNegativeEffect
: public IMagicAction
38 CMagicActionNegativeEffect()
39 :_EffectValue(0),_EffectFamily(EFFECT_FAMILIES::Unknown
),_CostPerUpdate(0),_Power(0){}
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");
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());
60 case TBrickParam::MA_EFFECT_MOD
:
61 INFOLOG("MA_EFFECT_MOD: %u",((CSBrickParamMagicEffectMod
*)brick
.Params
[i
])->EffectMod
);
62 _EffectValue
= ((CSBrickParamMagicEffectMod
*)brick
.Params
[i
])->EffectMod
;
65 case TBrickParam::MA_LINK_COST
:
66 INFOLOG("MA_LINK_COST: %u",((CSBrickParamMagicLinkCost
*)brick
.Params
[i
])->Cost
);
67 _CostPerUpdate
= ((CSBrickParamMagicLinkCost
*)brick
.Params
[i
])->Cost
;
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
);
76 // unused param, can be useful in the phrase
77 phrase
->applyBrickParam( brick
.Params
[i
] );
81 ///\todo nico: check if everything is set
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() );
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)
100 if ( successFactor
<= 0.0f
)
102 if ( actor
->getId().getType() == RYZOMID::player
)
103 CCharacter::sendMessageToClient( actor
->getId(),"MAGIC_TOTAL_MISS" );
109 if ( successFactor
< 1.0f
)
111 if ( actor
->getId().getType() == RYZOMID::player
)
112 CCharacter::sendMessageToClient( actor
->getId(),"MAGIC_TOTAL_MISS" );
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
;
128 linkEnergy
= SCORES::sap
;
130 for ( uint i
= 0; i
< targets
.size(); i
++ )
133 CEntityBase
* target
= CEntityBaseManager::getEntityBasePtr( targets
[i
] );
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( ) )
147 if ( isMad
|| PHRASE_UTILITIES::validateSpellTarget(actor
->getEntityRowId(),target
->getEntityRowId(),ACTNATURE::OFFENSIVE
) )
149 CSLinkEffectOffensive
* effect
= new CSLinkEffectOffensive(
159 actor
->addLink( effect
);
160 target
->addSabrinaEffect( effect
);
161 behav
.Spell
.SpellId
= MAGICFX::toMagicFx(_EffectFamily
);
166 EFFECT_FAMILIES::TEffectFamily _EffectFamily
;
172 BEGIN_MAGIC_ACTION_FACTORY(CMagicActionNegativeEffect
)
173 ADD_MAGIC_ACTION_TYPE( "mlos" )
174 ADD_MAGIC_ACTION_TYPE( "mloc" )
175 END_MAGIC_ACTION_FACTORY(CMagicActionNegativeEffect
)