1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-27 14:57:44 +00:00

Even more refactoring for cleaner code

This commit is contained in:
Mordred 2017-11-28 17:43:00 +01:00
parent ff0f793cb9
commit 8174d4082c
13 changed files with 47 additions and 39 deletions

View file

@ -12,7 +12,7 @@ Core::Action::Action::~Action()
} }
uint32_t Core::Action::Action::getId() const uint16_t Core::Action::Action::getId() const
{ {
return m_id; return m_id;
} }

View file

@ -13,7 +13,7 @@ namespace Core { namespace Action {
Action(); Action();
virtual ~Action(); virtual ~Action();
uint32_t getId() const; uint16_t getId() const;
Common::HandleActionType getHandleActionType() const; Common::HandleActionType getHandleActionType() const;
@ -41,7 +41,7 @@ namespace Core { namespace Action {
virtual bool update(); virtual bool update();
protected: protected:
uint32_t m_id; uint16_t m_id;
Common::HandleActionType m_handleActionType; Common::HandleActionType m_handleActionType;
uint64_t m_startTime; uint64_t m_startTime;

View file

@ -26,7 +26,7 @@ Core::Action::ActionCast::ActionCast()
m_handleActionType = Common::HandleActionType::Event; m_handleActionType = Common::HandleActionType::Event;
} }
Core::Action::ActionCast::ActionCast( Entity::ActorPtr pActor, Entity::ActorPtr pTarget, uint32_t actionId ) Core::Action::ActionCast::ActionCast( Entity::ActorPtr pActor, Entity::ActorPtr pTarget, uint16_t actionId )
{ {
m_startTime = 0; m_startTime = 0;
m_id = actionId; m_id = actionId;
@ -37,10 +37,7 @@ Core::Action::ActionCast::ActionCast( Entity::ActorPtr pActor, Entity::ActorPtr
m_bInterrupt = false; m_bInterrupt = false;
} }
Core::Action::ActionCast::~ActionCast() Core::Action::ActionCast::~ActionCast() = default;
{
}
void Core::Action::ActionCast::onStart() void Core::Action::ActionCast::onStart()
{ {

View file

@ -14,7 +14,7 @@ namespace Core { namespace Action {
ActionCast(); ActionCast();
~ActionCast(); ~ActionCast();
ActionCast( Entity::ActorPtr pActor, Entity::ActorPtr pTarget, uint32_t actionId ); ActionCast( Entity::ActorPtr pActor, Entity::ActorPtr pTarget, uint16_t actionId );
void onStart() override; void onStart() override;
void onFinish() override; void onFinish() override;

View file

@ -50,7 +50,10 @@ bool ActionCollision::isActorApplicable( ActorPtr actorPtr, TargetFilter targetF
return ( actorApplicable && actorPtr->isAlive() ); return ( actorApplicable && actorPtr->isAlive() );
} }
std::set< Core::Entity::ActorPtr > ActionCollision::getActorsHitFromAction( FFXIVARR_POSITION3 aoePosition, std::set< ActorPtr > actorsInRange, boost::shared_ptr< Core::Data::ActionInfo > actionInfo, TargetFilter targetFilter ) std::set< Core::Entity::ActorPtr > ActionCollision::getActorsHitFromAction( FFXIVARR_POSITION3 aoePosition,
std::set< ActorPtr > actorsInRange,
boost::shared_ptr< Core::Data::ActionInfo > actionInfo,
TargetFilter targetFilter )
{ {
std::set< ActorPtr > actorsCollided; std::set< ActorPtr > actorsCollided;

View file

@ -23,11 +23,17 @@ namespace Core {
public: public:
static bool isActorApplicable( ActorPtr actorPtr, TargetFilter targetFilter ); static bool isActorApplicable( ActorPtr actorPtr, TargetFilter targetFilter );
static std::set< ActorPtr > getActorsHitFromAction( Common::FFXIVARR_POSITION3 aoePosition, std::set< ActorPtr > actorsInRange, boost::shared_ptr< Data::ActionInfo > actionInfo, TargetFilter targetFilter ); static std::set< ActorPtr > getActorsHitFromAction( Common::FFXIVARR_POSITION3 aoePosition,
std::set< ActorPtr > actorsInRange,
boost::shared_ptr< Data::ActionInfo > actionInfo,
TargetFilter targetFilter );
private: private:
static bool radiusCollision( Common::FFXIVARR_POSITION3 actorPosition, Common::FFXIVARR_POSITION3 aoePosition, uint16_t radius ); static bool radiusCollision( Common::FFXIVARR_POSITION3 actorPosition, Common::FFXIVARR_POSITION3 aoePosition,
static bool boxCollision( Common::FFXIVARR_POSITION3 actorPosition, Common::FFXIVARR_POSITION3 aoePosition, uint16_t width, uint16_t height ); uint16_t radius );
static bool boxCollision( Common::FFXIVARR_POSITION3 actorPosition, Common::FFXIVARR_POSITION3 aoePosition,
uint16_t width, uint16_t height );
}; };

View file

@ -26,7 +26,7 @@ Core::Action::ActionMount::ActionMount()
m_handleActionType = Common::HandleActionType::Event; m_handleActionType = Common::HandleActionType::Event;
} }
Core::Action::ActionMount::ActionMount( Entity::ActorPtr pActor, uint32_t mountId ) Core::Action::ActionMount::ActionMount( Entity::ActorPtr pActor, uint16_t mountId )
{ {
m_startTime = 0; m_startTime = 0;
m_id = mountId; m_id = mountId;
@ -54,7 +54,8 @@ void Core::Action::ActionMount::onStart()
castPacket.data().action_id = m_id; castPacket.data().action_id = m_id;
castPacket.data().skillType = Common::SkillType::MountSkill; castPacket.data().skillType = Common::SkillType::MountSkill;
castPacket.data().unknown_1 = m_id; castPacket.data().unknown_1 = m_id;
castPacket.data().cast_time = static_cast< float >( m_castTime / 1000 ); // This is used for the cast bar above the target bar of the caster. // 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(); castPacket.data().target_id = m_pSource->getAsPlayer()->getId();
m_pSource->sendToInRangeSet( castPacket, true ); m_pSource->sendToInRangeSet( castPacket, true );

View file

@ -14,7 +14,7 @@ namespace Core { namespace Action {
ActionMount(); ActionMount();
~ActionMount(); ~ActionMount();
ActionMount( Entity::ActorPtr pActor, uint32_t mountId ); ActionMount( Entity::ActorPtr pActor, uint16_t mountId );
void onStart() override; void onStart() override;
void onFinish() override; void onFinish() override;

View file

@ -22,7 +22,7 @@ Core::Action::EventItemAction::EventItemAction()
m_handleActionType = Common::HandleActionType::Event; m_handleActionType = Common::HandleActionType::Event;
} }
Core::Action::EventItemAction::EventItemAction( Entity::ActorPtr pActor, uint32_t eventId, uint32_t action, Core::Action::EventItemAction::EventItemAction( Entity::ActorPtr pActor, uint32_t eventId, uint16_t action,
ActionCallback finishRef, ActionCallback interruptRef, uint64_t additional ) ActionCallback finishRef, ActionCallback interruptRef, uint64_t additional )
{ {
m_additional = additional; m_additional = additional;
@ -37,10 +37,7 @@ Core::Action::EventItemAction::EventItemAction( Entity::ActorPtr pActor, uint32_
m_bInterrupt = false; m_bInterrupt = false;
} }
Core::Action::EventItemAction::~EventItemAction() Core::Action::EventItemAction::~EventItemAction() = default;
{
}
void Core::Action::EventItemAction::onStart() void Core::Action::EventItemAction::onStart()
{ {

View file

@ -13,7 +13,7 @@ namespace Core { namespace Action {
EventItemAction(); EventItemAction();
~EventItemAction(); ~EventItemAction();
EventItemAction( Entity::ActorPtr pActor, uint32_t eventId, uint32_t action, EventItemAction( Entity::ActorPtr pActor, uint32_t eventId, uint16_t action,
ActionCallback finishRef, ActionCallback interruptRef, uint64_t additional ); ActionCallback finishRef, ActionCallback interruptRef, uint64_t additional );
void onStart() override; void onStart() override;

View file

@ -210,7 +210,6 @@ void Core::Entity::Actor::setInvincibilityType( Common::InvincibilityType type )
m_invincibilityType = type; m_invincibilityType = type;
} }
/*! \return current status of the actor */ /*! \return current status of the actor */
Core::Entity::Actor::ActorStatus Core::Entity::Actor::getStatus() const Core::Entity::Actor::ActorStatus Core::Entity::Actor::getStatus() const
{ {
@ -450,7 +449,7 @@ Core::Entity::ActorPtr Core::Entity::Actor::getClosestActor()
// arbitrary high number // arbitrary high number
float minDistance = 10000; float minDistance = 10000;
for( auto pCurAct : m_inRangeActors ) for( const auto& pCurAct : m_inRangeActors )
{ {
float distance = Math::Util::distance( getPos().x, float distance = Math::Util::distance( getPos().x,
getPos().y, getPos().y,
@ -492,7 +491,7 @@ void Core::Entity::Actor::sendToInRangeSet( Network::Packets::GamePacketPtr pPac
if( m_inRangePlayers.empty() ) if( m_inRangePlayers.empty() )
return; return;
for( auto pCurAct : m_inRangePlayers ) for( const auto &pCurAct : m_inRangePlayers )
{ {
assert( pCurAct ); assert( pCurAct );
pPacket->setValAt< uint32_t >( 0x04, m_id ); pPacket->setValAt< uint32_t >( 0x04, m_id );
@ -625,8 +624,8 @@ void Core::Entity::Actor::autoAttack( ActorPtr pTarget )
m_lastAttack = tick; m_lastAttack = tick;
srand( static_cast< uint32_t >( tick ) ); srand( static_cast< uint32_t >( tick ) );
uint32_t damage = 10 + rand() % 12; uint16_t damage = static_cast< uint16_t >( 10 + rand() % 12 );
uint32_t variation = 0 + rand() % 4; uint32_t variation = static_cast< uint32_t >( 0 + rand() % 4 );
ZoneChannelPacket< FFXIVIpcEffect > effectPacket( getId() ); ZoneChannelPacket< FFXIVIpcEffect > effectPacket( getId() );
effectPacket.data().targetId = pTarget->getId(); effectPacket.data().targetId = pTarget->getId();
@ -657,7 +656,8 @@ ChaiScript Skill Handler.
\param GamePacketPtr to send \param GamePacketPtr to send
\param bool should be send to self? \param bool should be send to self?
*/ */
void Core::Entity::Actor::handleScriptSkill( uint32_t type, uint32_t actionId, uint64_t param1, uint64_t param2, Entity::Actor& pTarget ) void Core::Entity::Actor::handleScriptSkill( uint32_t type, uint16_t actionId, uint64_t param1,
uint64_t param2, Entity::Actor& pTarget )
{ {
if ( isPlayer() ) if ( isPlayer() )
@ -709,14 +709,16 @@ void Core::Entity::Actor::handleScriptSkill( uint32_t type, uint32_t actionId, u
else else
{ {
std::set< ActorPtr > actorsCollided = ActionCollision::getActorsHitFromAction( pTarget.getPos(), getInRangeActors( true ), actionInfoPtr, TargetFilter::Enemies ); auto actorsCollided = ActionCollision::getActorsHitFromAction( pTarget.getPos(), getInRangeActors( true ),
actionInfoPtr, TargetFilter::Enemies );
for ( auto pHitActor : actorsCollided ) for ( const auto& pHitActor : actorsCollided )
{ {
effectPacket.data().targetId = pHitActor->getId(); effectPacket.data().targetId = pHitActor->getId();
effectPacket.data().effectTarget = pHitActor->getId(); effectPacket.data().effectTarget = pHitActor->getId();
sendToInRangeSet( effectPacket, true ); // todo: send to range of what? ourselves? when mob script hits this is going to be lacking // todo: send to range of what? ourselves? when mob script hits this is going to be lacking
sendToInRangeSet( effectPacket, true );
pHitActor->takeDamage( static_cast< uint32_t >( param1 ) ); pHitActor->takeDamage( static_cast< uint32_t >( param1 ) );
@ -756,9 +758,11 @@ void Core::Entity::Actor::handleScriptSkill( uint32_t type, uint32_t actionId, u
} }
else else
{ {
// todo: get proper packets: the following was just kind of thrown together from what we know. atm buggy (packets look "delayed" from client) // todo: get proper packets: the following was just kind of thrown together from what we know.
// atm buggy (packets look "delayed" from client)
std::set< ActorPtr > actorsCollided = ActionCollision::getActorsHitFromAction( pTarget.getPos(), getInRangeActors( true ), actionInfoPtr, TargetFilter::Allies ); auto actorsCollided = ActionCollision::getActorsHitFromAction( pTarget.getPos(), getInRangeActors( true ),
actionInfoPtr, TargetFilter::Allies );
for ( auto pHitActor : actorsCollided ) for ( auto pHitActor : actorsCollided )
{ {

View file

@ -249,7 +249,7 @@ public:
void setStatus( ActorStatus status ); void setStatus( ActorStatus status );
void handleScriptSkill( uint32_t type, uint32_t actionId, uint64_t param1, uint64_t param2, Entity::Actor& target ); void handleScriptSkill( uint32_t type, uint16_t actionId, uint64_t param1, uint64_t param2, Entity::Actor& target );
virtual void autoAttack( ActorPtr pTarget ); virtual void autoAttack( ActorPtr pTarget );