Add infos into target window
[ryzomcore.git] / ryzom / server / src / sabrina / magic_action_cure.cpp
blob4106031d2fd4fa3e65ba3ffab58eda7cf4d0b14a
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 "character.h"
23 #include "game_share/effect_families.h"
24 #include "game_share/magic_fx.h"
25 #include "s_link_effect_dot.h"
26 #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 CMagicActionCure : public IMagicAction
38 public:
39 CMagicActionCure()
40 :_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_EFFECT:
54 INFOLOG("MA_EFFECT: %s",((CSBrickParamMagicEffect *)brick.Params[i])->Effect.c_str());
55 EFFECT_FAMILIES::TEffectFamily effectFamily = EFFECT_FAMILIES::toEffectFamily( ((CSBrickParamMagicEffect *)brick.Params[i])->Effect );
56 if ( effectFamily == EFFECT_FAMILIES::Unknown )
58 nlwarning("<CMagicActionCure addBrick> invalid effect type %s", ((CSBrickParamMagicEffect *)brick.Params[i])->Effect.c_str());
59 return false;
61 _AffectedEffects.push_back(effectFamily);
62 break;
64 case TBrickParam::MA_DMG_TYPE:
66 INFOLOG("MA_DMG_TYPE: %s",((CSBrickParamMagicDmgType *)brick.Params[i])->DmgType.c_str());
67 DMGTYPE::EDamageType dmgType = DMGTYPE::stringToDamageType( ((CSBrickParamMagicDmgType *)brick.Params[i])->DmgType );
68 if ( dmgType == DMGTYPE::UNDEFINED )
70 nlwarning("<CMagicActionCure addBrick> invalid dmg type %s", ((CSBrickParamMagicDmgType *)brick.Params[i])->DmgType.c_str());
71 return false;
73 _AffectedDots.push_back(dmgType);
74 break;
76 case TBrickParam::MA_LINK_POWER:
77 INFOLOG("MA_LINK_POWER: %u",((CSBrickParamMagicLinkPower *)brick.Params[i])->Power);
78 _Power = uint16 ( ((CSBrickParamMagicLinkPower *)brick.Params[i])->Power );
79 break;
80 default:
81 // unused param, can be useful in the phrase
82 phrase->applyBrickParam( brick.Params[i] );
83 break;
86 ///\todo nico: check if everything is set
87 return true;
90 virtual bool validate(CMagicPhrase * phrase)
92 return PHRASE_UTILITIES::validateSpellTarget(phrase->getActor(),phrase->getTargets()[0],ACTNATURE::DEFENSIVE);
95 virtual void apply( CMagicPhrase * phrase, float successFactor,MBEHAV::CBehaviour & behav , bool isMad )
97 CEntityBase* actor = CEntityBaseManager::getEntityBasePtr( phrase->getActor() );
98 if ( !actor)
100 nlwarning("<CMagicActionCure apply> invalid actor: %u", phrase->getActor().getIndex() );
101 return;
103 if ( successFactor < 1.0f )
105 if ( actor->getId().getType() == RYZOMID::player )
106 CCharacter::sendMessageToClient( actor->getId(),"MAGIC_TOTAL_MISS" );
107 return;
109 const std::vector< TDataSetRow > & targets = phrase->getTargets();
110 for ( uint i = 0; i < targets.size(); i++ )
112 // check target
113 CEntityBase* target = CEntityBaseManager::getEntityBasePtr( targets[i] );
114 if ( !target)
115 continue;
116 if ( isMad || PHRASE_UTILITIES::validateSpellTarget(actor->getEntityRowId(),target->getEntityRowId(),ACTNATURE::DEFENSIVE) )
118 //behav.Spell.Resist = 0;
119 //behav.Spell.KillingBlow = 0;
121 for (uint i = 0; i < target->getSEffects().size(); )
123 CSEffect* effect = target->getSEffects()[i];
124 if ( effect )
126 bool removed = false;
127 if ( effect && effect->getPower() <= _Power )
129 if ( effect->getFamily() == EFFECT_FAMILIES::Dot )
131 behav.Spell.SpellId = MAGICFX::DoTBreak;
132 CSLinkEffectDot * dot = (CSLinkEffectDot *)effect;
133 for ( uint j = 0; j < _AffectedDots.size(); j++ )
135 if ( _AffectedDots[j] == dot->getDamageType() )
137 target->removeSabrinaEffect( dot );
138 removed = true;
139 break;
143 else
145 for ( uint j = 0; j < _AffectedEffects.size(); j++ )
147 if ( _AffectedEffects[j] >= EFFECT_FAMILIES::BeginCurse && _AffectedEffects[j] <= EFFECT_FAMILIES::EndCurse)
148 behav.Spell.SpellId = MAGICFX::CurseBreak;
149 else
150 behav.Spell.SpellId = MAGICFX::SicknessBreak;
151 if ( _AffectedEffects[j] == effect->getFamily() )
153 target->removeSabrinaEffect( effect );
154 removed = true;
155 break;
160 if ( !removed )
161 i++;
163 else
164 nlwarning("<CEntityBase dispellEffects> NULL effect #%u found in an entity. Debug needed",i);
165 behav.Spell.SpellIntensity = 5;
170 std::vector<EFFECT_FAMILIES::TEffectFamily> _AffectedEffects;
171 std::vector<DMGTYPE::EDamageType> _AffectedDots;
172 uint16 _Power;
175 BEGIN_MAGIC_ACTION_FACTORY(CMagicActionCure)
176 ADD_MAGIC_ACTION_TYPE( "mtcb" )
177 END_MAGIC_ACTION_FACTORY(CMagicActionCure)