1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-29 23:57:46 +00:00
sapphire/src/servers/sapphire_zone/Action/EventAction.cpp

144 lines
4.1 KiB
C++
Raw Normal View History

2018-03-06 22:22:19 +01:00
#include <Util/Util.h>
#include <Logging/Logger.h>
#include <Exd/ExdDataGenerated.h>
2017-08-08 13:53:47 +02:00
#include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h"
#include "Actor/Player.h"
2017-08-08 13:53:47 +02:00
#include "EventAction.h"
#include "Framework.h"
2018-03-09 00:06:44 +01:00
extern Core::Framework g_fw;
2017-08-08 13:53:47 +02:00
using namespace Core::Common;
using namespace Core::Network;
using namespace Core::Network::Packets;
using namespace Core::Network::Packets::Server;
Core::Action::EventAction::EventAction()
{
m_handleActionType = HandleActionType::Event;
2017-08-08 13:53:47 +02:00
}
Core::Action::EventAction::EventAction( Entity::CharaPtr pActor, uint32_t eventId, uint16_t action,
2017-08-08 13:53:47 +02:00
ActionCallback finishRef, ActionCallback interruptRef, uint64_t additional )
{
2018-03-09 00:06:44 +01:00
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
2017-08-08 13:53:47 +02:00
m_additional = additional;
2017-09-05 00:37:22 -03:00
m_handleActionType = HandleActionType::Event;
2017-08-08 13:53:47 +02:00
m_eventId = eventId;
m_id = action;
2018-03-09 00:06:44 +01:00
m_castTime = pExdData->get< Core::Data::EventAction >( action )->castTime * 1000; // TODO: Add security checks.
2017-08-08 13:53:47 +02:00
m_onActionFinishClb = finishRef;
m_onActionInterruptClb = interruptRef;
m_pSource = pActor;
m_bInterrupt = false;
}
Core::Action::EventAction::~EventAction()
{
}
void Core::Action::EventAction::onStart()
{
if( !m_pSource )
return;
m_startTime = Util::getTimeMs();
2018-06-28 00:07:07 +02:00
auto control = boost::make_shared< ActorControlPacket142 >( m_pSource->getId(), Common::ActorControlType::CastStart,
1, m_id, 0x4000004E );
2017-08-08 13:53:47 +02:00
if( m_pSource->isPlayer() )
{
m_pSource->sendToInRangeSet( control, true );
if( m_pSource->getAsPlayer()->hasStateFlag( PlayerStateFlag::InNpcEvent ) )
m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::InNpcEvent );
2017-08-08 13:53:47 +02:00
}
else
m_pSource->sendToInRangeSet( control );
}
void Core::Action::EventAction::onFinish()
{
if( !m_pSource )
return;
try
{
auto pEvent = m_pSource->getAsPlayer()->getEvent( m_eventId );
pEvent->setPlayedScene( false );
if( m_onActionFinishClb )
m_onActionFinishClb( *m_pSource->getAsPlayer(), m_eventId, m_additional );
2018-06-28 00:07:07 +02:00
auto control = boost::make_shared< ActorControlPacket142 >( m_pSource->getId(), Common::ActorControlType::CastStart,
0, m_id );
2017-08-08 13:53:47 +02:00
if( !pEvent->hasPlayedScene() )
m_pSource->getAsPlayer()->eventFinish( m_eventId, 1 );
else
pEvent->setPlayedScene( false );
if( m_pSource->isPlayer() )
{
//m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::Occupied2 );
2017-08-08 13:53:47 +02:00
m_pSource->sendToInRangeSet( control, true );
}
else
m_pSource->sendToInRangeSet( control );
}
catch( std::exception& e )
{
2018-03-09 00:06:44 +01:00
auto pLog = g_fw.get< Logger >();
pLog->error( e.what() );
2017-08-08 13:53:47 +02:00
}
}
void Core::Action::EventAction::onInterrupt()
{
if( !m_pSource )
return;
try
{
2018-06-28 00:07:07 +02:00
auto control = boost::make_shared< ActorControlPacket142 >( m_pSource->getId(), ActorControlType::CastInterrupt,
0x219, 0x04, m_id );
2017-08-08 13:53:47 +02:00
if( m_pSource->isPlayer() )
{
2018-06-28 00:07:07 +02:00
auto control1 = boost::make_shared< ActorControlPacket143 >( m_pSource->getId(), ActorControlType::FreeEventPos,
m_eventId );
2017-08-08 13:53:47 +02:00
//m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::NoCombat );
//m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::Occupied1 );
2017-08-08 13:53:47 +02:00
m_pSource->sendToInRangeSet( control );
m_pSource->sendToInRangeSet( control1 );
m_pSource->getAsPlayer()->queuePacket( control1 );
m_pSource->getAsPlayer()->queuePacket( control );
m_pSource->getAsPlayer()->eventFinish( m_eventId, 1 );
}
else
m_pSource->sendToInRangeSet( control );
if( m_onActionInterruptClb )
m_onActionInterruptClb( *m_pSource->getAsPlayer(), m_eventId, m_additional );
}
catch( std::exception& e )
{
2018-03-09 00:06:44 +01:00
auto pLog = g_fw.get< Logger >();
pLog->error( e.what() );
2017-08-08 13:53:47 +02:00
}
}