Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / sabrina / combat_action_stun.cpp
blob8c2713cacc92fedb880c12088eae3ae0e95fc65a
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/>.
20 #include "stdpch.h"
21 // net
22 #include "nel/net/message.h"
23 // misc
24 #include "nel/misc/bit_mem_stream.h"
25 // game_share
26 #include "game_share/generic_xml_msg_mngr.h"
28 #include "combat_action_stun.h"
29 #include "phrase_utilities_functions.h"
31 using namespace std;
32 using namespace NLMISC;
33 using namespace NLNET;
36 extern CGenericXmlMsgHeaderManager GenericMsgManager;
39 //--------------------------------------------------------------
40 // build()
41 //--------------------------------------------------------------
42 bool CCombatActionStun::build( const TDataSetRow & actorRowId, const std::vector< const CStaticBrick* >& bricks, uint &brickIndex, CCombatPhrase * phrase )
44 if (!phrase) return false;
46 _CombatPhrase = phrase;
47 _ActorRowId = actorRowId;
49 return true;
50 } // build //
53 //--------------------------------------------------------------
54 // apply()
55 //--------------------------------------------------------------
56 void CCombatActionStun::apply(CCombatPhrase *phrase)
58 CEntityBase *entity = CEntityBaseManager::getEntityBasePtr(_TargetRowId);
59 if (!entity)
60 return;
62 TGameCycle endDate = _StunDuration + CTickEventHandler::getGameCycle();
64 _StunEffect = new CCombatStunEffect( _ActorRowId, _TargetRowId, EFFECT_FAMILIES::CombatStun, _StunLevel, endDate);
65 if (!_StunEffect)
67 nlwarning("<CCombatActionStun::apply> Failed to allocate new CCombatStunEffect object !");
68 return;
71 _StunEffect->stunnedEntity(entity);
72 entity->stun();
73 entity->addSabrinaEffect(_StunEffect);
75 // send stun impulsion to the IOS
76 CMessage msgout( "IMPULSION_ID" );
77 msgout.serial( const_cast<CEntityId&> (entity->getId()) );
78 CBitMemStream bms;
79 GenericMsgManager.pushNameToStream( "STUN:STUN", bms);
80 uint16 tickCount = _StunDuration;
81 bms.serial( tickCount );
82 msgout.serialMemStream( bms );
83 CUnifiedNetwork::getInstance()->send( entity->getId().getDynamicId(), msgout );
85 // send message
86 PHRASE_UTILITIES::sendSimpleMessage( _TargetRowId, "OPS_EFFECT_STUN_BEGIN" );
87 PHRASE_UTILITIES::sendMessage( _ActorRowId, "OPS_EFFECT_STUN_BEGIN_E", _TargetRowId );
89 /// todo : send to spectators
90 } // apply //