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 "game_share/entity_structure/statistic.h"
25 #include "game_share/magic_fx.h"
26 #include "s_link_effect_dot.h"
27 #include "phrase_utilities_functions.h"
29 using namespace NLNET
;
30 using namespace NLMISC
;
31 using namespace RY_GAME_SHARE
;
36 class CMagicActionDot
: public IMagicAction
40 :_DmgHp(0),_DmgSap(0),_DmgSta(0),_DmgType(DMGTYPE::UNDEFINED
),_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");
52 case TBrickParam::MA_DMG_TYPE
:
53 INFOLOG("MA_DMG_TYPE: %s",((CSBrickParamMagicDmgType
*)brick
.Params
[i
])->DmgType
.c_str());
54 _DmgType
= DMGTYPE::stringToDamageType( ((CSBrickParamMagicDmgType
*)brick
.Params
[i
])->DmgType
);
55 if ( _DmgType
== DMGTYPE::UNDEFINED
)
57 nlwarning("<CMagicActionBasicDamage addBrick> invalid dmg type %s", ((CSBrickParamMagicDmgType
*)brick
.Params
[i
])->DmgType
.c_str());
62 case TBrickParam::MA_DMG
:
63 INFOLOG("MA_DMG: %u %u %u",((CSBrickParamMagicDmg
*)brick
.Params
[i
])->Hp
,((CSBrickParamMagicDmg
*)brick
.Params
[i
])->Sap
,((CSBrickParamMagicDmg
*)brick
.Params
[i
])->Sta
);
64 _DmgHp
= ((CSBrickParamMagicDmg
*)brick
.Params
[i
])->Hp
;
65 _DmgSap
= ((CSBrickParamMagicDmg
*)brick
.Params
[i
])->Sap
;
66 _DmgSta
= ((CSBrickParamMagicDmg
*)brick
.Params
[i
])->Sta
;
69 case TBrickParam::MA_LINK_COST
:
70 INFOLOG("MA_LINK_COST: %u",((CSBrickParamMagicLinkCost
*)brick
.Params
[i
])->Cost
);
71 _CostPerUpdate
= ((CSBrickParamMagicLinkCost
*)brick
.Params
[i
])->Cost
;
74 case TBrickParam::MA_LINK_POWER
:
75 INFOLOG("MA_LINK_POWER: %u",((CSBrickParamMagicLinkPower
*)brick
.Params
[i
])->Power
);
76 _Power
= (uint8
) ( ((CSBrickParamMagicLinkPower
*)brick
.Params
[i
])->Power
);
80 // unused param, can be useful in the phrase
81 phrase
->applyBrickParam( brick
.Params
[i
] );
85 ///\todo nico: check if everything is set
88 virtual bool validate(CMagicPhrase
* phrase
)
90 return PHRASE_UTILITIES::validateSpellTarget(phrase
->getActor(),phrase
->getTargets()[0],ACTNATURE::OFFENSIVE
);
92 virtual void apply( CMagicPhrase
* phrase
, float successFactor
,MBEHAV::CBehaviour
& behav
, bool isMad
)
94 //behav.Spell.Resist = 0;
95 //behav.Spell.KillingBlow = 0;
96 behav
.Spell
.SpellIntensity
= 5;
98 CEntityBase
* actor
= CEntityBaseManager::getEntityBasePtr( phrase
->getActor() );
105 // - player damages + on armor
106 // - behaviour + chat messages
109 if ( successFactor
<= 0.0f
)
111 if ( actor
->getId().getType() == RYZOMID::player
)
112 CCharacter::sendMessageToClient( actor
->getId(),"MAGIC_TOTAL_MISS" );
116 const std::vector
< TDataSetRow
> & targets
= phrase
->getTargets();
118 SCORES::TScores linkEnergy
;
119 if ( phrase
->getHPCost() > 0 )
121 linkEnergy
= SCORES::hit_points
;
124 linkEnergy
= SCORES::sap
;
125 for ( uint i
= 0; i
< targets
.size(); i
++ )
128 CEntityBase
* target
= CEntityBaseManager::getEntityBasePtr( targets
[i
] );
132 const std::vector
< CSEffect
* > & effects
= target
->getSEffects();
133 for (uint j
= 0; j
< effects
.size(); j
++ )
135 if ( effects
[j
]->getFamily() == EFFECT_FAMILIES::Dot
&& effects
[j
]->getCreatorRowId() == phrase
->getActor( ) )
141 if ( isMad
|| PHRASE_UTILITIES::validateSpellTarget(actor
->getEntityRowId(),target
->getEntityRowId(),ACTNATURE::OFFENSIVE
) )
144 CSLinkEffectDot
* dot
= new CSLinkEffectDot( phrase
->getActor(),
151 sint32(_DmgHp
* successFactor
* CSLinkEffect::getUpdatePeriod()),
152 sint32(_DmgSap
* successFactor
* CSLinkEffect::getUpdatePeriod()),
153 sint32(_DmgSta
* successFactor
* CSLinkEffect::getUpdatePeriod()) );
154 actor
->addLink( dot
);
155 target
->addSabrinaEffect( dot
);
156 behav
.Spell
.SpellId
= MAGICFX::toMagicFx( _DmgType
,false);
160 DMGTYPE::EDamageType _DmgType
;
164 sint32 _CostPerUpdate
;
167 BEGIN_MAGIC_ACTION_FACTORY(CMagicActionDot
)
168 ADD_MAGIC_ACTION_TYPE( "mlod" )
169 ADD_MAGIC_ACTION_TYPE( "mloe" )
170 END_MAGIC_ACTION_FACTORY(CMagicActionDot
)