2018-03-06 22:22:19 +01:00
|
|
|
#include <Util/Util.h>
|
|
|
|
#include <Logging/Logger.h>
|
|
|
|
#include <Exd/ExdDataGenerated.h>
|
2018-06-23 21:38:04 +02:00
|
|
|
#include <Network/CommonActorControl.h>
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2017-12-08 15:38:25 +01:00
|
|
|
#include "Network/PacketWrappers/ActorControlPacket142.h"
|
|
|
|
#include "Network/PacketWrappers/ActorControlPacket143.h"
|
2018-03-02 07:22:25 -03:00
|
|
|
|
2017-12-18 12:36:52 +01:00
|
|
|
#include "Actor/Player.h"
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-03-02 07:22:25 -03: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;
|
2018-06-23 21:38:04 +02:00
|
|
|
using namespace Core::Network::ActorControl;
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
Core::Action::EventAction::EventAction()
|
|
|
|
{
|
2017-12-08 15:38:25 +01:00
|
|
|
m_handleActionType = HandleActionType::Event;
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
2018-02-20 22:46:44 +01: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-07-03 15:01:13 +02:00
|
|
|
auto control = boost::make_shared< ActorControlPacket142 >( m_pSource->getId(), ActorControlType::CastStart,
|
2018-06-28 00:07:07 +02:00
|
|
|
1, m_id, 0x4000004E );
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
if( m_pSource->isPlayer() )
|
|
|
|
{
|
|
|
|
m_pSource->sendToInRangeSet( control, true );
|
2018-02-21 23:30:35 +01:00
|
|
|
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-07-03 15:01:13 +02:00
|
|
|
auto control = boost::make_shared< ActorControlPacket142 >( m_pSource->getId(), ActorControlType::CastStart,
|
2018-06-28 00:07:07 +02:00
|
|
|
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() )
|
|
|
|
{
|
2018-02-15 23:50:28 +01:00
|
|
|
//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
|
|
|
|
2018-02-15 23:50:28 +01: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
|
|
|
}
|
|
|
|
|
|
|
|
}
|