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

139 lines
3.8 KiB
C++
Raw Normal View History

#include <common/Util/Util.h>
#include <common/Logging/Logger.h>
#include <common/Exd/ExdData.h>
2017-08-08 13:53:47 +02:00
#include "EventAction.h"
#include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h"
#include "Actor/Player.h"
#include "Event/Event.h"
2017-08-08 13:53:47 +02:00
extern Core::Logger g_log;
extern Core::Data::ExdData g_exdData;
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::ActorPtr pActor, uint32_t eventId, uint16_t action,
ActionCallback finishRef, ActionCallback interruptRef, uint64_t additional )
{
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;
m_castTime = g_exdData.m_EventActionInfoMap[action].castTime; // TODO: Add security checks.
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();
auto control = 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 );
m_pSource->getAsPlayer()->setStateFlag( PlayerStateFlag::SomeFlag );
2017-08-08 13:53:47 +02:00
m_pSource->getAsPlayer()->sendStateFlags();
}
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 );
auto control = ActorControlPacket142( m_pSource->getId(), Common::ActorControlType::CastStart, 0, m_id );
if( !pEvent->hasPlayedScene() )
m_pSource->getAsPlayer()->eventFinish( m_eventId, 1 );
else
pEvent->setPlayedScene( false );
if( m_pSource->isPlayer() )
{
m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::SomeFlag );
2017-08-08 13:53:47 +02:00
m_pSource->getAsPlayer()->sendStateFlags();
m_pSource->sendToInRangeSet( control, true );
}
else
m_pSource->sendToInRangeSet( control );
}
catch( std::exception& e )
{
g_log.error( e.what() );
}
}
void Core::Action::EventAction::onInterrupt()
{
if( !m_pSource )
return;
try
{
auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt,
0x219, 0x04, m_id );
if( m_pSource->isPlayer() )
{
auto control1 = ActorControlPacket143( m_pSource->getId(), ActorControlType::FreeEventPos, m_eventId );
m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::NoCombat );
m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::Occupied1 );
m_pSource->getAsPlayer()->sendStateFlags();
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 )
{
g_log.error( e.what() );
}
}