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.2 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>
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;
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();
2017-11-21 18:43:09 +01:00
ZoneChannelPacket< FFXIVIpcActorCast > castPacket( m_pSource->getId() );
2017-08-08 13:53:47 +02:00
castPacket.data().action_id = 5;
castPacket.data().unknown = 1;
castPacket.data().cast_time = 5.0f;
castPacket.data().target_id = m_pSource->getId();
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( Inventory::CurrencyType::Gil ) < m_cost )
{
onInterrupt();
return;
}
pPlayer->removeCurrency( Inventory::CurrencyType::Gil, m_cost );
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
2017-11-21 18:43:09 +01:00
ZoneChannelPacket< FFXIVIpcEffect > effectPacket( pPlayer->getId() );
2017-08-08 13:53:47 +02:00
effectPacket.data().targetId = pPlayer->getId();
effectPacket.data().actionAnimationId = 5;
//effectPacket.data().unknown_3 = 1;
effectPacket.data().actionTextId = 5;
effectPacket.data().unknown_5 = 1;
effectPacket.data().numEffects = 1;
effectPacket.data().rotation = static_cast< uint16_t >( 0x8000 * ( ( pPlayer->getRot() + 3.1415926 ) ) / 3.1415926 );
2017-08-08 13:53:47 +02:00
effectPacket.data().effectTarget = pPlayer->getId();
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
auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt,
2017-11-28 17:43:00 +01:00
0x219, 0x04, m_id, 0 );
2017-08-08 13:53:47 +02:00
m_pSource->sendToInRangeSet( control, true );
}