1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-27 14:57:44 +00:00
sapphire/src/servers/Server_Zone/SkillHandler.cpp

107 lines
3.1 KiB
C++
Raw Normal View History

#include <Server_Common/Common.h>
#include <Server_Common/CommonNetwork.h>
2017-08-17 18:12:29 +02:00
#include <Server_Common/ExdData.h>
#include <Server_Common/GamePacketNew.h>
#include <Server_Common/PacketContainer.h>
2017-08-17 18:12:29 +02:00
#include <Server_Common/Logger.h>
#include <boost/format.hpp>
#include "GameConnection.h"
#include "Session.h"
#include "ServerNoticePacket.h"
#include "ActorControlPacket142.h"
#include "ActorControlPacket143.h"
#include "ActorControlPacket144.h"
2017-08-17 18:12:29 +02:00
#include "PlayerStateFlagsPacket.h"
#include "GameCommandHandler.h"
#include "Player.h"
#include "Forwards.h"
#include "Action.h"
#include "ActionTeleport.h"
#include "ActionCast.h"
2017-08-17 18:12:29 +02:00
#include "ScriptManager.h"
2017-08-17 18:12:29 +02:00
extern Core::Scripting::ScriptManager g_scriptMgr;
extern Core::Data::ExdData g_exdData;
extern Core::Logger g_log;
using namespace Core::Common;
using namespace Core::Network::Packets;
using namespace Core::Network::Packets::Server;
void Core::Network::GameConnection::skillHandler( const Packets::GamePacket& inPacket,
Entity::PlayerPtr pPlayer )
{
uint32_t action = inPacket.getValAt< uint32_t >( 0x24 );
uint32_t useCount = inPacket.getValAt< uint32_t >( 0x28 );
uint64_t targetId = inPacket.getValAt< uint64_t >( 0x30 );
if( action < 1000000 ) // normal action
{
std::string actionIdStr = boost::str( boost::format( "%|04X|" ) % action );
pPlayer->sendDebug( "---------------------------------------" );
pPlayer->sendDebug( "ActionHandler ( " + actionIdStr + " | " +
g_exdData.m_actionInfoMap[action].name +
" | " + std::to_string( targetId ) + " )" );
pPlayer->queuePacket( ActorControlPacket142( pPlayer->getId(), ActorControlType::ActionStart, 0x01, action ) );
if( action == 5 )
{
auto currentAction = pPlayer->getCurrentAction();
// we should always have an action here, if not there is a bug
assert( currentAction );
currentAction->onStart();
}
else
{
Core::Entity::ActorPtr targetActor = pPlayer;
if( targetId != pPlayer->getId() )
{
targetActor = pPlayer->lookupTargetById( targetId );
}
if( !pPlayer->actionHasCastTime( action ) )
{
g_scriptMgr.onCastFinish( pPlayer, targetActor, action );
}
else
{
Action::ActionCastPtr pActionCast( new Action::ActionCast( pPlayer, targetActor, action ) );
pPlayer->setCurrentAction( pActionCast );
pPlayer->sendDebug( "setCurrentAction()" );
pPlayer->getCurrentAction()->onStart();
}
}
}
else if( action < 2000000 ) // craft action
{
}
else if( action < 3000000 ) // item action
{
auto info = g_exdData.getEventItemInfo( action );
if( info )
{
g_log.debug( info->name );
g_scriptMgr.onEventItem( pPlayer, action, info->eventId, info->castTime, targetId );
}
}
else if( action > 3000000 ) // unknown
{
}
}