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

108 lines
3.1 KiB
C++
Raw Normal View History

2018-03-06 22:22:19 +01:00
#include <Common.h>
#include <Util/Util.h>
#include <Util/UtilMath.h>
#include <Logging/Logger.h>
#include <Network/CommonActorControl.h>
#include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h"
#include "Network/PacketWrappers/ActorControlPacket144.h"
2018-09-20 23:31:38 +02:00
#include "Network/PacketWrappers/EffectPacket.h"
#include "Actor/Player.h"
#include "Script/ScriptMgr.h"
#include "ActionMount.h"
#include "Framework.h"
2017-10-18 15:49:19 +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-10-18 15:49:19 +02:00
extern Core::Framework g_framework;
2017-10-18 15:49:19 +02:00
Core::Action::ActionMount::ActionMount()
{
m_handleActionType = HandleActionType::Event;
2017-10-18 15:49:19 +02:00
}
Core::Action::ActionMount::ActionMount( Entity::CharaPtr pActor, uint16_t mountId )
2017-10-18 15:49:19 +02:00
{
m_startTime = 0;
m_id = mountId;
m_handleActionType = HandleActionType::Spell;
m_castTime = 1000;
m_pSource = pActor;
m_bInterrupt = false;
2017-10-18 15:49:19 +02:00
}
Core::Action::ActionMount::~ActionMount()
{
}
void Core::Action::ActionMount::onStart()
{
if( !m_pSource )
return;
2017-10-18 15:49:19 +02:00
m_pSource->getAsPlayer()->sendDebug( "ActionMount::onStart()" );
m_startTime = Util::getTimeMs();
2017-10-18 15:49:19 +02:00
auto castPacket = makeZonePacket< FFXIVIpcActorCast >( getId() );
castPacket->data().action_id = m_id;
castPacket->data().skillType = Common::SkillType::MountSkill;
castPacket->data().unknown_1 = m_id;
// This is used for the cast bar above the target bar of the caster.
castPacket->data().cast_time = static_cast< float >( m_castTime / 1000 );
castPacket->data().target_id = m_pSource->getAsPlayer()->getId();
2017-10-18 15:49:19 +02:00
m_pSource->sendToInRangeSet( castPacket, true );
m_pSource->getAsPlayer()->setStateFlag( PlayerStateFlag::Casting );
2017-10-18 15:49:19 +02:00
}
void Core::Action::ActionMount::onFinish()
{
if( !m_pSource )
return;
2017-10-18 15:49:19 +02:00
auto pPlayer = m_pSource->getAsPlayer();
pPlayer->sendDebug( "ActionMount::onFinish()" );
2017-10-18 15:49:19 +02:00
pPlayer->unsetStateFlag( PlayerStateFlag::Casting );
2017-10-18 15:49:19 +02:00
2018-10-25 12:44:51 +11:00
auto effectPacket = std::make_shared< Server::EffectPacket >( getId(), pPlayer->getId(), 4 );
effectPacket->setRotation( Math::Util::floatToUInt16Rot( pPlayer->getRot() ) );
Server::EffectEntry effectEntry{};
effectEntry.effectType = ActionEffectType::Mount;
effectEntry.hitSeverity = ActionHitSeverityType::CritDamage;
effectEntry.value = m_id;
effectPacket->addEffect( effectEntry );
2017-10-18 15:49:19 +02:00
pPlayer->sendToInRangeSet( effectPacket, true );
2017-10-18 15:49:19 +02:00
pPlayer->mount( m_id );
2017-10-18 15:49:19 +02:00
}
void Core::Action::ActionMount::onInterrupt()
{
if( !m_pSource )
return;
2017-10-18 15:49:19 +02:00
//m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::Occupied1 );
m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::Casting );
2017-10-18 15:49:19 +02:00
auto control = makeActorControl142( m_pSource->getId(), ActorControlType::CastInterrupt, 0x219, 1, m_id, 0 );
2017-10-18 15:49:19 +02:00
// Note: When cast interrupt from taking too much damage, set the last value to 1. This enables the cast interrupt effect. Example:
// auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt, 0x219, 1, m_id, 0 );
2017-10-18 15:49:19 +02:00
m_pSource->sendToInRangeSet( control, true );
2017-10-18 15:49:19 +02:00
}