Add infos into target window
[ryzomcore.git] / ryzom / server / src / sabrina / magic_action_debuff.cpp
blobc9f5542f352de3f990ee7e0559c5968afa049b82
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 "s_link_effect_debuff_skill.h"
27 using namespace NLNET;
28 using namespace NLMISC;
29 using namespace RY_GAME_SHARE;
30 using namespace std;
33 class CMagicActionDebuffSkill : public IMagicAction
35 public:
36 CMagicActionDebuffSkill()
37 :_TargetSkill(SKILLS::unknown),_DebuffValue(0){}
38 protected:
39 virtual bool addBrick( const CStaticBrick & brick, CMagicPhrase * phrase )
41 for ( uint i=0 ; i<brick.Params.size() ; ++i)
43 switch(brick.Params[i]->id())
46 case TBrickParam::MA_DEBUFF:
47 INFOLOG("MA_DEBUFF: %u",((CSBrickParamMagicDebuff *)brick.Params[i])->Debuff);
48 _DebuffValue = ((CSBrickParamMagicDebuff *)brick.Params[i])->Debuff;
49 break;
51 case TBrickParam::MA_LINK_COST:
52 INFOLOG("MA_LINK_COST: %u",((CSBrickParamMagicLinkCost *)brick.Params[i])->Cost);
53 _CostPerUpdate = ((CSBrickParamMagicLinkCost *)brick.Params[i])->Cost;
54 break;
56 case TBrickParam::SKILL:
58 INFOLOG("SKILL: %s",((CSBrickParamSkill *)brick.Params[i])->Skill.c_str());
59 _Skill = SKILLS::toSkill( ((CSBrickParamSkill *)brick.Params[i])->Skill );
60 if ( _Skill == SKILLS::unknown )
62 nlwarning( "<CMagicActionDebuffSkill addBrick> invalid skill type %s", ((CSBrickParamSkill *)brick.Params[i])->Skill.c_str() );
63 return false;
65 break;
67 default:
68 // unused param, can be useful in the phrase
69 phrase->applyBrickParam( brick.Params[i] );
70 break;
73 ///\todo nico: check if everything is set
74 return true;
76 virtual bool validate(CMagicPhrase * phrase)
78 return PHRASE_UTILITIES::validateSpellTarget(phrase->getActor(),phrase->getTargets()[0],ACTNATURE::OFFENSIVE);
80 virtual void apply( CMagicPhrase * phrase, float successFactor,MBEHAV::CBehaviour & behav )
82 ///\todo nico:
83 // - location
84 // - armor + shield
85 // - player damages + on armor
86 // - behaviour + chat messages
87 // - aggro
89 /// test resistance
90 if ( successFactor < 0.0f )
92 ///\todo nico
93 return;
96 /// apply success factor
97 _DebuffValue = uint32( _DebuffValue * successFactor);
99 const std::vector< TDataSetRow > & targets = phrase->getTargets();
100 CEntityBase* actor = CEntityBaseManager::getEntityBasePtr( phrase->getActor() );
101 if (!actor)
102 return;
104 SCORES::EScores linkEnergy;
105 if ( phrase->getSapCost() > 0 )
107 linkEnergy = SCORES::sap;
109 else
110 linkEnergy = SCORES::hit_points;;
111 for ( uint i = 0; i < targets.size(); i++ )
113 // check target
114 CEntityBase* target = CEntityBaseManager::getEntityBasePtr( targets[i] );
115 if ( !target)
116 continue;
118 if ( PHRASE_UTILITIES::validateSpellTarget(actor,target,ACTNATURE::OFFENSIVE) )
120 CSLinkEffectDebuffSkill* debuff = new CSLinkEffectDebuffSkill( phrase->getActor(),
121 targets[i],
122 _UpdatePeriod,
123 _CostPerUpdate,
124 linkEnergy,
125 _Skill,
126 _TargetSkill,
127 _DebuffValue );
128 actor->addLink( debuff );
129 target->addSabrinaEffect( debuff );
134 SKILLS::ESkills _TargetSkill;
135 sint32 _DebuffValue;
136 uint _CostPerUpdate;
138 MAGIC_ACTION_FACTORY( CMagicActionDebuffSkill,BRICK_FAMILIES::MADebuffSkill )