2018-03-02 07:22:25 -03:00
|
|
|
#include <string.h>
|
2017-08-18 17:16:15 +02:00
|
|
|
|
2018-03-06 22:22:19 +01:00
|
|
|
#include <Util/Util.h>
|
|
|
|
#include <Util/UtilMath.h>
|
|
|
|
#include <Logging/Logger.h>
|
2017-08-18 17:16:15 +02:00
|
|
|
|
2017-12-08 15:38:25 +01:00
|
|
|
#include "Network/PacketWrappers/ActorControlPacket142.h"
|
|
|
|
#include "Network/PacketWrappers/ActorControlPacket143.h"
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-03-02 07:22:25 -03:00
|
|
|
#include "Actor/Player.h"
|
|
|
|
|
|
|
|
#include "EventItemAction.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::EventItemAction::EventItemAction()
|
|
|
|
{
|
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::EventItemAction::EventItemAction( Entity::CharaPtr pActor, uint32_t eventId, uint16_t action,
|
2017-08-08 13:53:47 +02:00
|
|
|
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;
|
|
|
|
// 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-11-28 17:43:00 +01:00
|
|
|
Core::Action::EventItemAction::~EventItemAction() = default;
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
void Core::Action::EventItemAction::onStart()
|
|
|
|
{
|
|
|
|
if( !m_pSource )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_startTime = Util::getTimeMs();
|
|
|
|
|
2017-08-20 22:31:23 +02:00
|
|
|
GamePacketNew< FFXIVIpcActorCast, ServerZoneIpcType > castPacket( m_pSource->getId() );
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
m_pSource->sendToInRangeSet( castPacket, true );
|
|
|
|
m_pSource->getAsPlayer()->setStateFlag( PlayerStateFlag::Casting );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Action::EventItemAction::onFinish()
|
|
|
|
{
|
|
|
|
if( !m_pSource )
|
|
|
|
return;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2017-08-20 22:31:23 +02:00
|
|
|
GamePacketNew< FFXIVIpcEffect, ServerZoneIpcType > effectPacket( m_pSource->getId() );
|
2017-08-08 13:53:47 +02:00
|
|
|
effectPacket.data().targetId = static_cast< uint32_t >( m_additional );
|
|
|
|
effectPacket.data().actionAnimationId = 1;
|
|
|
|
// effectPacket.data().unknown_3 = 3;
|
|
|
|
effectPacket.data().actionTextId = m_id;
|
|
|
|
effectPacket.data().unknown_5 = 2;
|
|
|
|
effectPacket.data().numEffects = 1;
|
2018-02-22 18:12:36 +01:00
|
|
|
effectPacket.data().rotation = Math::Util::floatToUInt16Rot( m_pSource->getRot() );
|
2017-08-08 13:53:47 +02:00
|
|
|
effectPacket.data().effectTarget = static_cast< uint32_t >( m_additional );
|
|
|
|
|
|
|
|
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-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::EventItemAction::onInterrupt()
|
|
|
|
{
|
|
|
|
if( !m_pSource )
|
|
|
|
return;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
|
|
|
auto control = ActorControlPacket142( 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-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
|
|
|
}
|
|
|
|
|
|
|
|
}
|