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

75 lines
2.4 KiB
C++
Raw Normal View History

2020-01-23 22:36:01 +09:00
#include "MountAction.h"
#include <Actor/Player.h>
2020-01-23 22:36:01 +09:00
#include <Manager/PlayerMgr.h>
#include <Manager/MgrUtil.h>
#include <Network/GameConnection.h>
2020-01-23 22:36:01 +09:00
#include <Network/CommonActorControl.h>
#include <Network/PacketWrappers/ActorControlSelfPacket.h>
2020-01-23 22:36:01 +09:00
#include <Service.h>
2020-01-23 22:36:01 +09:00
#include <Util/UtilMath.h>
#include "WorldServer.h"
#include "Session.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;
using namespace Sapphire::World::Manager;
2020-01-23 22:36:01 +09:00
MountAction::MountAction( Sapphire::Entity::CharaPtr source, uint16_t mountId, uint16_t sequence,
2022-01-27 21:24:54 +01:00
std::shared_ptr< Excel::ExcelStruct< 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 )
{
m_actionKind = Common::SkillType::MountSkill;
2020-01-23 22:36:01 +09:00
}
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 = m_actionKind;
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();
server().queueForPlayers( m_pSource->getInRangePlayerIds( true ), castPacket );
2020-01-23 22:36:01 +09:00
2023-02-20 15:25:57 +01:00
Common::Service< World::Manager::PlayerMgr >::ref().setCondition( *player, Common::PlayerCondition::Casting );
2020-01-23 22:36:01 +09:00
auto actionStartPkt = makeActorControlSelf( m_pSource->getId(), ActorControlType::ActionStart, 1, getId(), m_recastTimeMs / 10 );
server().queueForPlayer( m_pSource->getAsPlayer()->getCharacterId(), actionStartPkt );
2020-01-23 22:36:01 +09:00
}
void MountAction::execute()
{
assert( m_pSource );
2023-02-20 15:25:57 +01:00
Common::Service< World::Manager::PlayerMgr >::ref().removeCondition( *m_pSource->getAsPlayer(), Common::PlayerCondition::Casting );
2020-01-23 22:36:01 +09:00
m_effectBuilder->mount( m_pSource, m_mountId );
m_effectBuilder->buildAndSendPackets( { m_pSource } );
2020-01-23 22:36:01 +09:00
}