1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-26 22:37:45 +00:00
sapphire/src/servers/sapphire_zone/Action/ActionTeleport.cpp

114 lines
3.3 KiB
C++
Raw Normal View History

2018-03-06 22:22:19 +01:00
#include <Util/Util.h>
#include <Exd/ExdDataGenerated.h>
#include <Logging/Logger.h>
#include <Network/CommonActorControl.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 "ActionTeleport.h"
#include "Framework.h"
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;
using namespace Core::Network::ActorControl;
2017-08-08 13:53:47 +02:00
2018-03-09 00:06:44 +01:00
extern Core::Framework g_fw;
2017-08-08 13:53:47 +02:00
Core::Action::ActionTeleport::ActionTeleport()
{
m_handleActionType = HandleActionType::Event;
2017-08-08 13:53:47 +02:00
}
Core::Action::ActionTeleport::ActionTeleport( Entity::CharaPtr pActor, uint16_t targetZone, uint16_t cost )
2017-08-08 13:53:47 +02:00
{
2018-03-09 00:06:44 +01:00
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
2017-08-08 13:53:47 +02:00
m_startTime = 0;
m_id = 5;
2017-09-05 00:37:22 -03:00
m_handleActionType = HandleActionType::Teleport;
2018-03-09 00:06:44 +01:00
m_castTime = pExdData->get< Core::Data::Action >( 5 )->cast100ms * 100; // TODO: Add security checks.
2017-08-08 13:53:47 +02:00
m_pSource = pActor;
m_bInterrupt = false;
m_targetAetheryte = targetZone;
m_cost = cost;
}
Core::Action::ActionTeleport::~ActionTeleport()
{
}
void Core::Action::ActionTeleport::onStart()
{
if( !m_pSource )
return;
m_startTime = Util::getTimeMs();
2018-06-28 00:07:07 +02:00
auto castPacket = makeZonePacket< FFXIVIpcActorCast >( getId() );
castPacket->data().action_id = 5;
castPacket->data().unknown = 1;
castPacket->data().cast_time = 5.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 );
}
void Core::Action::ActionTeleport::onFinish()
{
if( !m_pSource )
return;
auto pPlayer = m_pSource->getAsPlayer();
// check we can finish teleporting
if( pPlayer->getCurrency( Common::CurrencyType::Gil ) < m_cost )
2017-08-08 13:53:47 +02:00
{
onInterrupt();
return;
}
pPlayer->removeCurrency( Common::CurrencyType::Gil, m_cost );
2017-08-08 13:53:47 +02:00
pPlayer->unsetStateFlag( PlayerStateFlag::Casting );
// TODO: not sure if this ever gets sent
//auto control = Network::Packets::Server::ActorControlPacket142( m_pSource->getId(), Common::ActorControlType::TeleportDone );
//m_pSource->sendToInRangeSet( control, false );
pPlayer->setZoningType( ZoneingType::Teleport );
2017-08-08 13:53:47 +02:00
2018-07-21 15:54:37 +10:00
auto effectPacket = makeZonePacket< Server::FFXIVIpcEffect >( getId() );
effectPacket->data().animationTargetId = pPlayer->getId();
2018-06-28 00:07:07 +02:00
effectPacket->data().actionAnimationId = 5;
2017-08-08 13:53:47 +02:00
//effectPacket.data().unknown_3 = 1;
2018-07-21 15:54:37 +10:00
effectPacket->data().actionAnimationId = 5;
2018-06-28 00:07:07 +02:00
effectPacket->data().numEffects = 1;
effectPacket->data().rotation = static_cast< uint16_t >( 0x8000 * ( ( pPlayer->getRot() + 3.1415926 ) ) / 3.1415926 );
effectPacket->data().effectTargetId = pPlayer->getId();
2017-08-08 13:53:47 +02:00
pPlayer->sendToInRangeSet( effectPacket, true );
pPlayer->teleport( m_targetAetheryte );
}
void Core::Action::ActionTeleport::onInterrupt()
{
if( !m_pSource )
return;
m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::Casting );
2017-08-08 13:53:47 +02:00
2018-06-28 00:07:07 +02:00
auto control = boost::make_shared< ActorControlPacket142 >( m_pSource->getId(), ActorControlType::CastInterrupt,
0x219, 0x04, m_id, 0 );
2017-08-08 13:53:47 +02:00
m_pSource->sendToInRangeSet( control, true );
}