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

77 lines
2.3 KiB
C++
Raw Normal View History

2020-01-23 22:36:01 +09:00
#include "MountAction.h"
#include <Exd/ExdData.h>
2020-01-23 22:36:01 +09:00
#include "Actor/Player.h"
#include <Network/CommonActorControl.h>
#include "Network/PacketWrappers/ActorControlSelfPacket.h"
#include <Service.h>
2020-01-23 22:36:01 +09:00
#include <Util/UtilMath.h>
#include "WorldServer.h"
#include "Session.h"
#include "Network/GameConnection.h"
2020-01-23 22:36:01 +09:00
using namespace Sapphire;
using namespace Sapphire::Network::Packets;
using namespace Sapphire::Network::Packets::WorldPackets::Server;
2020-01-23 22:36:01 +09:00
using namespace Sapphire::Network::ActorControl;
using namespace Sapphire::World::Action;
MountAction::MountAction( Sapphire::Entity::CharaPtr source, uint16_t mountId, uint16_t sequence,
std::shared_ptr< Component::Excel::ExcelStruct< Component::Excel::Action > > actionData ) :
2020-03-01 01:00:57 +11:00
Action::Action( source, 4, sequence, actionData ),
2020-01-23 22:36:01 +09:00
m_mountId( mountId )
{
}
bool MountAction::preCheck()
{
// todo: check if mount is unlocked
return m_pSource->isPlayer();
}
void MountAction::start()
{
assert( m_pSource );
m_startTime = Common::Util::getTimeMs();
auto player = m_pSource->getAsPlayer();
auto castPacket = makeZonePacket< FFXIVIpcActorCast >( m_pSource->getId() );
2020-01-23 22:36:01 +09:00
auto& data = castPacket->data();
data.Action = static_cast< uint16_t >( m_id );
data.ActionKind = Common::SkillType::MountSkill;
data.CastTime = m_castTimeMs / 1000.f;
data.Target = static_cast< uint32_t >( m_targetId );
data.BallistaEntityId = 0xE0000000;
2020-01-23 22:36:01 +09:00
auto pos = m_pSource->getPos();
data.TargetPos[ 0 ] = Common::Util::floatToUInt16( pos.x );
data.TargetPos[ 1 ] = Common::Util::floatToUInt16( pos.y );
data.TargetPos[ 2 ] = Common::Util::floatToUInt16( pos.z );
data.Dir = m_pSource->getRot();
2020-01-23 22:36:01 +09:00
m_pSource->sendToInRangeSet( castPacket, true );
player->setStateFlag( Common::PlayerStateFlag::Casting );
auto actionStartPkt = makeActorControlSelf( m_pSource->getId(), ActorControlType::ActionStart, 1, getId(), m_recastTimeMs / 10 );
auto& server = Common::Service< World::WorldServer >::ref();
server.queueForPlayer( m_pSource->getAsPlayer()->getCharacterId(), actionStartPkt );
2020-01-23 22:36:01 +09:00
}
void MountAction::execute()
{
assert( m_pSource );
m_pSource->getAsPlayer()->unsetStateFlag( Common::PlayerStateFlag::Casting );
2020-01-23 22:36:01 +09:00
m_effectBuilder->mount( m_pSource, m_mountId );
m_effectBuilder->buildAndSendPackets();
}