1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-28 15:17:46 +00:00
sapphire/src/world/Action/EventItemAction.cpp

116 lines
3.1 KiB
C++
Raw Normal View History

#include <string.h>
2018-03-06 22:22:19 +01:00
#include <Util/Util.h>
#include <Util/UtilMath.h>
#include <Logging/Logger.h>
#include <Network/CommonActorControl.h>
#include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h"
#include "Network/PacketWrappers/EffectPacket.h"
2017-08-08 13:53:47 +02:00
#include "Actor/Player.h"
#include "EventItemAction.h"
#include "Framework.h"
using namespace Sapphire::Common;
using namespace Sapphire::Network;
using namespace Sapphire::Network::Packets;
using namespace Sapphire::Network::Packets::Server;
using namespace Sapphire::Network::ActorControl;
2017-08-08 13:53:47 +02:00
Sapphire::Action::EventItemAction::EventItemAction()
2017-08-08 13:53:47 +02:00
{
m_handleActionType = HandleActionType::Event;
2017-08-08 13:53:47 +02:00
}
Sapphire::Action::EventItemAction::EventItemAction( Entity::CharaPtr pActor, uint32_t eventId, uint16_t action,
ActionCallback finishRef, ActionCallback interruptRef,
uint64_t additional )
2017-08-08 13:53:47 +02:00
{
m_additional = additional;
m_handleActionType = HandleActionType::Event;
m_eventId = eventId;
m_id = action;
// TODO: read the cast time from the action itself
m_castTime = 3000;
m_onActionFinishClb = finishRef;
m_onActionInterruptClb = interruptRef;
m_pSource = pActor;
m_bInterrupt = false;
2017-08-08 13:53:47 +02:00
}
Sapphire::Action::EventItemAction::~EventItemAction() = default;
2017-08-08 13:53:47 +02:00
void Sapphire::Action::EventItemAction::onStart()
2017-08-08 13:53:47 +02:00
{
if( !m_pSource )
return;
2017-08-08 13:53:47 +02:00
m_startTime = Util::getTimeMs();
2017-08-08 13:53:47 +02:00
auto castPacket = makeZonePacket< FFXIVIpcActorCast >( m_pSource->getId() );
castPacket->data().action_id = 1;
castPacket->data().unknown = 3;
castPacket->data().unknown_1 = m_id;
castPacket->data().cast_time = 3.0f;
castPacket->data().target_id = m_pSource->getId();
2017-08-08 13:53:47 +02:00
m_pSource->sendToInRangeSet( castPacket, true );
m_pSource->getAsPlayer()->setStateFlag( PlayerStateFlag::Casting );
2017-08-08 13:53:47 +02:00
}
void Sapphire::Action::EventItemAction::onFinish()
2017-08-08 13:53:47 +02:00
{
if( !m_pSource )
return;
try
{
2018-10-25 12:44:51 +11:00
auto effectPacket = std::make_shared< Server::EffectPacket >( m_pSource->getId(), m_additional, m_id );
effectPacket->setAnimationId( 1 );
2018-12-02 02:01:41 +01:00
effectPacket->setRotation( Util::floatToUInt16Rot( m_pSource->getRot() ) );
m_pSource->getAsPlayer()->unsetStateFlag( Common::PlayerStateFlag::Casting );
m_pSource->sendToInRangeSet( effectPacket, true );
if( m_onActionFinishClb )
m_onActionFinishClb( *m_pSource->getAsPlayer(), m_eventId, m_additional );
}
catch( std::exception& e )
{
2018-12-23 03:53:08 +01:00
Logger::error( e.what() );
}
2017-08-08 13:53:47 +02:00
}
void Sapphire::Action::EventItemAction::onInterrupt()
2017-08-08 13:53:47 +02:00
{
if( !m_pSource )
return;
try
{
auto control = makeActorControl142( m_pSource->getId(), ActorControlType::CastInterrupt, 0x219, 0x04, m_id );
if( m_pSource->isPlayer() )
{
m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::Casting );
m_pSource->sendToInRangeSet( control, true );
}
else
m_pSource->sendToInRangeSet( control );
if( m_onActionInterruptClb )
m_onActionInterruptClb( *m_pSource->getAsPlayer(), m_eventId, m_additional );
}
catch( std::exception& e )
{
2018-12-23 03:53:08 +01:00
Logger::error( e.what() );
}
2017-08-08 13:53:47 +02:00
}