Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / sabrina / magic_action_dot.cpp
blob6116784bf6d8ec3ebf28dad7878fddb99593ccf0
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 "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;
32 using namespace std;
36 class CMagicActionDot : public IMagicAction
38 public:
39 CMagicActionDot()
40 :_DmgHp(0),_DmgSap(0),_DmgSta(0),_DmgType(DMGTYPE::UNDEFINED),_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;
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());
58 return false;
60 break;
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;
67 break;
69 case TBrickParam::MA_LINK_COST:
70 INFOLOG("MA_LINK_COST: %u",((CSBrickParamMagicLinkCost *)brick.Params[i])->Cost);
71 _CostPerUpdate = ((CSBrickParamMagicLinkCost *)brick.Params[i])->Cost;
72 break;
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 );
77 break;
79 default:
80 // unused param, can be useful in the phrase
81 phrase->applyBrickParam( brick.Params[i] );
82 break;
85 ///\todo nico: check if everything is set
86 return true;
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() );
99 if (!actor)
100 return;
102 ///\todo nico:
103 // - location
104 // - armor + shield
105 // - player damages + on armor
106 // - behaviour + chat messages
107 // - aggro
109 if ( successFactor <= 0.0f )
111 if ( actor->getId().getType() == RYZOMID::player )
112 CCharacter::sendMessageToClient( actor->getId(),"MAGIC_TOTAL_MISS" );
113 return;
116 const std::vector< TDataSetRow > & targets = phrase->getTargets();
118 SCORES::TScores linkEnergy;
119 if ( phrase->getHPCost() > 0 )
121 linkEnergy = SCORES::hit_points;
123 else
124 linkEnergy = SCORES::sap;
125 for ( uint i = 0; i < targets.size(); i++ )
127 // check target
128 CEntityBase* target = CEntityBaseManager::getEntityBasePtr( targets[i] );
129 if ( !target)
130 continue;
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( ) )
137 return;
141 if ( isMad || PHRASE_UTILITIES::validateSpellTarget(actor->getEntityRowId(),target->getEntityRowId(),ACTNATURE::OFFENSIVE) )
144 CSLinkEffectDot* dot = new CSLinkEffectDot( phrase->getActor(),
145 targets[i],
146 _CostPerUpdate,
147 linkEnergy,
148 _Skill,
149 _DmgType,
150 _Power,
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;
161 sint32 _DmgHp;
162 sint32 _DmgSap;
163 sint32 _DmgSta;
164 sint32 _CostPerUpdate;
165 uint8 _Power;
167 BEGIN_MAGIC_ACTION_FACTORY(CMagicActionDot)
168 ADD_MAGIC_ACTION_TYPE( "mlod" )
169 ADD_MAGIC_ACTION_TYPE( "mloe" )
170 END_MAGIC_ACTION_FACTORY(CMagicActionDot)