1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-25 05:57:45 +00:00

Merge remote-tracking branch 'upstream/develop' into instancescripting

This commit is contained in:
Adam 2018-02-10 14:05:12 +11:00
commit bc5004598d
31 changed files with 335 additions and 423 deletions

View file

@ -7,6 +7,9 @@
#define TYPE_FORWARD( x ) \ #define TYPE_FORWARD( x ) \
class x; \ class x; \
typedef boost::shared_ptr< x > x ## Ptr; \ typedef boost::shared_ptr< x > x ## Ptr; \
template< typename...Args > \
x ## Ptr make_ ## x( Args &&...args ) { \
return boost::make_shared< x >( std::forward< Args >( args ) ... ); }\
typedef std::vector< x > x ## PtrList; typedef std::vector< x > x ## PtrList;
namespace Core namespace Core

View file

@ -42,7 +42,7 @@ Core::Network::GameConnection::~GameConnection()
// overwrite the parents onConnect for our game socket needs // overwrite the parents onConnect for our game socket needs
void Core::Network::GameConnection::OnAccept( const std::string & host, uint16_t port ) void Core::Network::GameConnection::OnAccept( const std::string & host, uint16_t port )
{ {
GameConnectionPtr connection( new GameConnection( m_hive, m_pAcceptor ) ); auto connection = make_GameConnection( m_hive, m_pAcceptor );
m_pAcceptor->Accept( connection ); m_pAcceptor->Accept( connection );
g_log.info( "Connect from " + m_socket.remote_endpoint().address().to_string() ); g_log.info( "Connect from " + m_socket.remote_endpoint().address().to_string() );
@ -76,7 +76,8 @@ void Core::Network::GameConnection::OnRecv( std::vector< uint8_t > & buffer )
// Dissect packet list // Dissect packet list
std::vector< Packets::FFXIVARR_PACKET_RAW > packetList; std::vector< Packets::FFXIVARR_PACKET_RAW > packetList;
const auto packetResult = Packets::getPackets(buffer, sizeof(struct FFXIVARR_PACKET_HEADER), packetHeader, packetList); const auto packetResult = Packets::getPackets( buffer, sizeof( struct FFXIVARR_PACKET_HEADER ),
packetHeader, packetList );
if( packetResult == Incomplete ) if( packetResult == Incomplete )
{ {
@ -252,7 +253,7 @@ bool Core::Network::GameConnection::sendServiceAccountList( FFXIVARR_PACKET_RAW&
if( g_serverLobby.getConfig()->getValue< bool >( "Settings.Parameters.AllowNoSessionConnect" ) && pSession == nullptr ) if( g_serverLobby.getConfig()->getValue< bool >( "Settings.Parameters.AllowNoSessionConnect" ) && pSession == nullptr )
{ {
LobbySessionPtr session( new Core::LobbySession() ); auto session = make_LobbySession();
session->setAccountID( 0 ); session->setAccountID( 0 );
session->setSessionId( (uint8_t *)&packet.data[0] + 0x20 ); session->setSessionId( (uint8_t *)&packet.data[0] + 0x20 );
pSession = session; pSession = session;

View file

@ -13,7 +13,7 @@ using namespace Core::Common;
// todo: add AoE actor limits (16, 32) // todo: add AoE actor limits (16, 32)
bool ActionCollision::isActorApplicable( ActorPtr actorPtr, TargetFilter targetFilter ) bool ActionCollision::isActorApplicable( Actor& actor, TargetFilter targetFilter )
{ {
bool actorApplicable = false; bool actorApplicable = false;
switch( targetFilter ) switch( targetFilter )
@ -25,29 +25,29 @@ bool ActionCollision::isActorApplicable( ActorPtr actorPtr, TargetFilter targetF
} }
case TargetFilter::Players: case TargetFilter::Players:
{ {
actorApplicable = actorPtr->isPlayer(); actorApplicable = actor.isPlayer();
break; break;
} }
case TargetFilter::Allies: case TargetFilter::Allies:
{ {
// todo: implement ally NPCs // todo: implement ally NPCs
actorApplicable = !actorPtr->isBNpc(); actorApplicable = !actor.isBattleNpc();
break; break;
} }
case TargetFilter::Party: case TargetFilter::Party:
{ {
// todo: implement party // todo: implement party
actorApplicable = actorPtr->isPlayer(); actorApplicable = actor.isPlayer();
break; break;
} }
case TargetFilter::Enemies: case TargetFilter::Enemies:
{ {
actorApplicable = actorPtr->isBNpc(); actorApplicable = actor.isBattleNpc();
break; break;
} }
} }
return ( actorApplicable && actorPtr->isAlive() ); return ( actorApplicable && actor.isAlive() );
} }
std::set< Core::Entity::ActorPtr > ActionCollision::getActorsHitFromAction( FFXIVARR_POSITION3 aoePosition, std::set< Core::Entity::ActorPtr > ActionCollision::getActorsHitFromAction( FFXIVARR_POSITION3 aoePosition,
@ -70,7 +70,7 @@ std::set< Core::Entity::ActorPtr > ActionCollision::getActorsHitFromAction( FFXI
assert( pActor ); assert( pActor );
// Don't bother wasting on collision if actor doesn't apply for it // Don't bother wasting on collision if actor doesn't apply for it
if ( !isActorApplicable( pActor, targetFilter ) ) if ( !isActorApplicable( *pActor, targetFilter ) )
continue; continue;
// Test our collision from actor with the area generated by the action from the AoE data // Test our collision from actor with the area generated by the action from the AoE data
@ -88,7 +88,7 @@ std::set< Core::Entity::ActorPtr > ActionCollision::getActorsHitFromAction( FFXI
{ {
assert( pActor ); assert( pActor );
if ( !isActorApplicable( pActor, targetFilter ) ) if ( !isActorApplicable( *pActor, targetFilter ) )
continue; continue;
if ( radiusCollision( pActor->getPos(), aoePosition, actionInfo->effectRange ) ) if ( radiusCollision( pActor->getPos(), aoePosition, actionInfo->effectRange ) )
@ -102,7 +102,7 @@ std::set< Core::Entity::ActorPtr > ActionCollision::getActorsHitFromAction( FFXI
{ {
assert( pActor ); assert( pActor );
if ( !isActorApplicable( pActor, targetFilter ) ) if ( !isActorApplicable( *pActor, targetFilter ) )
continue; continue;
if ( boxCollision( pActor->getPos(), aoePosition, actionInfo->xAxisModifier, actionInfo->effectRange ) ) if ( boxCollision( pActor->getPos(), aoePosition, actionInfo->xAxisModifier, actionInfo->effectRange ) )

View file

@ -23,7 +23,7 @@ namespace Entity {
{ {
public: public:
static bool isActorApplicable( ActorPtr actorPtr, TargetFilter targetFilter ); static bool isActorApplicable( Actor& actor, TargetFilter targetFilter );
static std::set< ActorPtr > getActorsHitFromAction( Common::FFXIVARR_POSITION3 aoePosition, static std::set< ActorPtr > getActorsHitFromAction( Common::FFXIVARR_POSITION3 aoePosition,
std::set< ActorPtr > actorsInRange, std::set< ActorPtr > actorsInRange,
boost::shared_ptr< Data::Action > actionInfo, boost::shared_ptr< Data::Action > actionInfo,

View file

@ -32,7 +32,8 @@ using namespace Core::Common;
using namespace Core::Network::Packets; using namespace Core::Network::Packets;
using namespace Core::Network::Packets::Server; using namespace Core::Network::Packets::Server;
Core::Entity::Actor::Actor() Core::Entity::Actor::Actor( ObjKind type ) :
GameObject( type )
{ {
// initialize the free slot queue // initialize the free slot queue
for( uint8_t i = 0; i < MAX_STATUS_EFFECTS; i++ ) for( uint8_t i = 0; i < MAX_STATUS_EFFECTS; i++ )
@ -45,48 +46,19 @@ Core::Entity::Actor::~Actor()
{ {
} }
/*! \return the id of the actor */
uint32_t Core::Entity::Actor::getId() const
{
return m_id;
}
/*! \return the actors position object */
Core::Common::FFXIVARR_POSITION3& Core::Entity::Actor::getPos()
{
return m_pos;
}
/*! \return the actors name */ /*! \return the actors name */
std::string Core::Entity::Actor::getName() const std::string Core::Entity::Actor::getName() const
{ {
return std::string( m_name ); return std::string( m_name );
} }
/*! \return true if the actor is of type player */
bool Core::Entity::Actor::isPlayer() const
{
return m_objKind == ObjKind::Player;
}
/*! \return true if the actor is of type mob */
bool Core::Entity::Actor::isBNpc() const
{
return m_objKind == ObjKind::BattleNpc;
}
/*! \return true if the actor is of type resident */
bool Core::Entity::Actor::isEventNpc() const
{
return m_objKind == ObjKind::EventNpc;
}
/*! \return list of actors currently in range */ /*! \return list of actors currently in range */
std::set< Core::Entity::ActorPtr > Core::Entity::Actor::getInRangeActors( bool includeSelf ) std::set< Core::Entity::ActorPtr > Core::Entity::Actor::getInRangeActors( bool includeSelf )
{ {
auto tempInRange = m_inRangeActors; auto tempInRange = m_inRangeActors;
if( includeSelf ) if( includeSelf )
tempInRange.insert( shared_from_this() ); tempInRange.insert( getAsActor() );
return tempInRange; return tempInRange;
} }
@ -286,7 +258,7 @@ Sets the actors position and notifies the zone to propagate the change
void Core::Entity::Actor::setPosition( const Common::FFXIVARR_POSITION3& pos ) void Core::Entity::Actor::setPosition( const Common::FFXIVARR_POSITION3& pos )
{ {
m_pos = pos; m_pos = pos;
m_pCurrentZone->changeActorPosition( shared_from_this() ); m_pCurrentZone->changeActorPosition( *this );
} }
void Core::Entity::Actor::setPosition( float x, float y, float z ) void Core::Entity::Actor::setPosition( float x, float y, float z )
@ -294,7 +266,7 @@ void Core::Entity::Actor::setPosition( float x, float y, float z )
m_pos.x = x; m_pos.x = x;
m_pos.y = y; m_pos.y = y;
m_pos.z = z; m_pos.z = z;
m_pCurrentZone->changeActorPosition( shared_from_this() ); m_pCurrentZone->changeActorPosition( *this );
} }
/*! /*!
@ -410,34 +382,10 @@ so players can have their own version and we can abolish the param.
*/ */
void Core::Entity::Actor::sendStatusUpdate( bool toSelf ) void Core::Entity::Actor::sendStatusUpdate( bool toSelf )
{ {
UpdateHpMpTpPacket updateHpPacket( shared_from_this() ); UpdateHpMpTpPacket updateHpPacket( *this );
sendToInRangeSet( updateHpPacket ); sendToInRangeSet( updateHpPacket );
} }
/*! \return pointer to this instance as PlayerPtr */
Core::Entity::PlayerPtr Core::Entity::Actor::getAsPlayer()
{
if( !isPlayer() )
return nullptr;
return boost::dynamic_pointer_cast< Entity::Player, Entity::Actor >( shared_from_this() );
}
/*! \return pointer to this instance as BattleNpcPtr */
Core::Entity::BattleNpcPtr Core::Entity::Actor::getAsBattleNpc()
{
if( !isBNpc() )
return nullptr;
return boost::reinterpret_pointer_cast< Entity::BattleNpc, Entity::Actor >( shared_from_this() );
}
/*! \return pointer to this instance as EventNpcPtr */
Core::Entity::EventNpcPtr Core::Entity::Actor::getAsEventNpc()
{
if( !isEventNpc() )
return nullptr;
return boost::reinterpret_pointer_cast< Entity::EventNpc, Entity::Actor >( shared_from_this() );
}
/*! \return ActionPtr of the currently registered action, or nullptr */ /*! \return ActionPtr of the currently registered action, or nullptr */
Core::Action::ActionPtr Core::Entity::Actor::getCurrentAction() const Core::Action::ActionPtr Core::Entity::Actor::getCurrentAction() const
{ {
@ -557,29 +505,26 @@ but also to the global actor map
\param ActorPtr to remove \param ActorPtr to remove
*/ */
void Core::Entity::Actor::removeInRangeActor( ActorPtr pActor ) void Core::Entity::Actor::removeInRangeActor( Actor& pActor )
{ {
// if this is null, something went wrong
assert( pActor );
// call virtual event // call virtual event
onRemoveInRangeActor( pActor ); onRemoveInRangeActor( pActor );
// remove actor from in range actor set // remove actor from in range actor set
m_inRangeActors.erase( pActor ); m_inRangeActors.erase( pActor.getAsActor() );
// if actor is a player, despawn ourself for him // if actor is a player, despawn ourself for him
// TODO: move to virtual onRemove? // TODO: move to virtual onRemove?
if( isPlayer() ) if( isPlayer() )
pActor->despawn( shared_from_this() ); pActor.despawn( getAsPlayer() );
if( pActor->isPlayer() ) if( pActor.isPlayer() )
{ {
auto pPlayer = pActor->getAsPlayer(); auto pPlayer = pActor.getAsPlayer();
m_inRangePlayers.erase( pPlayer ); m_inRangePlayers.erase( pPlayer );
} }
m_inRangeActorMap.erase( pActor->getId() ); m_inRangeActorMap.erase( pActor.getId() );
} }
/*! \return true if there is at least one actor in the in range set */ /*! \return true if there is at least one actor in the in range set */
@ -644,7 +589,7 @@ void Core::Entity::Actor::autoAttack( ActorPtr pTarget )
if( ( tick - m_lastAttack ) > 2500 ) if( ( tick - m_lastAttack ) > 2500 )
{ {
pTarget->onActionHostile( shared_from_this() ); pTarget->onActionHostile( *this );
m_lastAttack = tick; m_lastAttack = tick;
srand( static_cast< uint32_t >( tick ) ); srand( static_cast< uint32_t >( tick ) );
@ -681,12 +626,12 @@ ChaiScript Skill Handler.
\param bool should be send to self? \param bool should be send to self?
*/ */
void Core::Entity::Actor::handleScriptSkill( uint32_t type, uint16_t actionId, uint64_t param1, void Core::Entity::Actor::handleScriptSkill( uint32_t type, uint16_t actionId, uint64_t param1,
uint64_t param2, Entity::Actor& pTarget ) uint64_t param2, Entity::Actor& target )
{ {
if( isPlayer() ) if( isPlayer() )
{ {
getAsPlayer()->sendDebug( std::to_string( pTarget.getId() ) ); getAsPlayer()->sendDebug( std::to_string( target.getId() ) );
getAsPlayer()->sendDebug( "Handle script skill type: " + std::to_string( type ) ); getAsPlayer()->sendDebug( "Handle script skill type: " + std::to_string( type ) );
} }
@ -696,14 +641,14 @@ void Core::Entity::Actor::handleScriptSkill( uint32_t type, uint16_t actionId, u
// Prepare packet. This is seemingly common for all packets in the action handler. // Prepare packet. This is seemingly common for all packets in the action handler.
ZoneChannelPacket< FFXIVIpcEffect > effectPacket( getId() ); ZoneChannelPacket< FFXIVIpcEffect > effectPacket( getId() );
effectPacket.data().targetId = pTarget.getId(); effectPacket.data().targetId = target.getId();
effectPacket.data().actionAnimationId = actionId; effectPacket.data().actionAnimationId = actionId;
effectPacket.data().unknown_62 = 1; // Affects displaying action name next to number in floating text effectPacket.data().unknown_62 = 1; // Affects displaying action name next to number in floating text
effectPacket.data().unknown_2 = 1; // This seems to have an effect on the "double-cast finish" animation effectPacket.data().unknown_2 = 1; // This seems to have an effect on the "double-cast finish" animation
effectPacket.data().actionTextId = actionId; effectPacket.data().actionTextId = actionId;
effectPacket.data().numEffects = 1; effectPacket.data().numEffects = 1;
effectPacket.data().rotation = Math::Util::floatToUInt16Rot( getRotation() ); effectPacket.data().rotation = Math::Util::floatToUInt16Rot( getRotation() );
effectPacket.data().effectTarget = pTarget.getId(); effectPacket.data().effectTarget = target.getId();
// Todo: for each actor, calculate how much damage the calculated value should deal to them - 2-step damage calc. we only have 1-step // Todo: for each actor, calculate how much damage the calculated value should deal to them - 2-step damage calc. we only have 1-step
switch( type ) switch( type )
@ -719,21 +664,21 @@ void Core::Entity::Actor::handleScriptSkill( uint32_t type, uint16_t actionId, u
if( actionInfoPtr->castType == 1 && actionInfoPtr->effectRange != 0 || actionInfoPtr->castType != 1 ) if( actionInfoPtr->castType == 1 && actionInfoPtr->effectRange != 0 || actionInfoPtr->castType != 1 )
{ {
// If action on this specific target is valid... // If action on this specific target is valid...
if ( isPlayer() && !ActionCollision::isActorApplicable( pTarget.shared_from_this(), TargetFilter::Enemies ) ) if ( isPlayer() && !ActionCollision::isActorApplicable( target, TargetFilter::Enemies ) )
break; break;
sendToInRangeSet( effectPacket, true ); sendToInRangeSet( effectPacket, true );
if ( pTarget.isAlive() ) if ( target.isAlive() )
pTarget.onActionHostile( shared_from_this() ); target.onActionHostile( *this );
pTarget.takeDamage( static_cast< uint32_t >( param1 ) ); target.takeDamage( static_cast< uint32_t >( param1 ) );
} }
else else
{ {
auto actorsCollided = ActionCollision::getActorsHitFromAction( pTarget.getPos(), getInRangeActors( true ), auto actorsCollided = ActionCollision::getActorsHitFromAction( target.getPos(), getInRangeActors( true ),
actionInfoPtr, TargetFilter::Enemies ); actionInfoPtr, TargetFilter::Enemies );
for( const auto& pHitActor : actorsCollided ) for( const auto& pHitActor : actorsCollided )
@ -746,7 +691,7 @@ void Core::Entity::Actor::handleScriptSkill( uint32_t type, uint16_t actionId, u
if( pHitActor->isAlive() ) if( pHitActor->isAlive() )
pHitActor->onActionHostile( shared_from_this() ); pHitActor->onActionHostile( *this );
pHitActor->takeDamage( static_cast< uint32_t >( param1 ) ); pHitActor->takeDamage( static_cast< uint32_t >( param1 ) );
@ -774,23 +719,23 @@ void Core::Entity::Actor::handleScriptSkill( uint32_t type, uint16_t actionId, u
if( actionInfoPtr->castType == 1 && actionInfoPtr->effectRange != 0 || actionInfoPtr->castType != 1 ) if( actionInfoPtr->castType == 1 && actionInfoPtr->effectRange != 0 || actionInfoPtr->castType != 1 )
{ {
if( isPlayer() && !ActionCollision::isActorApplicable( pTarget.shared_from_this(), TargetFilter::Allies ) ) if( isPlayer() && !ActionCollision::isActorApplicable( target, TargetFilter::Allies ) )
break; break;
sendToInRangeSet( effectPacket, true ); sendToInRangeSet( effectPacket, true );
pTarget.heal( calculatedHeal ); target.heal( calculatedHeal );
} }
else else
{ {
// todo: get proper packets: the following was just kind of thrown together from what we know. // todo: get proper packets: the following was just kind of thrown together from what we know.
// atm buggy (packets look "delayed" from client) // atm buggy (packets look "delayed" from client)
auto actorsCollided = ActionCollision::getActorsHitFromAction( pTarget.getPos(), getInRangeActors( true ), auto actorsCollided = ActionCollision::getActorsHitFromAction( target.getPos(), getInRangeActors( true ),
actionInfoPtr, TargetFilter::Allies ); actionInfoPtr, TargetFilter::Allies );
for( auto pHitActor : actorsCollided ) for( auto pHitActor : actorsCollided )
{ {
effectPacket.data().targetId = pTarget.getId(); effectPacket.data().targetId = target.getId();
effectPacket.data().effectTarget = pHitActor->getId(); effectPacket.data().effectTarget = pHitActor->getId();
sendToInRangeSet( effectPacket, true ); sendToInRangeSet( effectPacket, true );
@ -844,22 +789,20 @@ void Core::Entity::Actor::addStatusEffect( StatusEffect::StatusEffectPtr pEffect
} }
/*! \param StatusEffectPtr to be applied to the actor */ /*! \param StatusEffectPtr to be applied to the actor */
void Core::Entity::Actor::addStatusEffectById( uint32_t id, int32_t duration, Entity::Actor& pSource, uint16_t param ) void Core::Entity::Actor::addStatusEffectById( uint32_t id, int32_t duration, Entity::Actor& source, uint16_t param )
{ {
StatusEffect::StatusEffectPtr effect( new StatusEffect::StatusEffect( id, pSource.shared_from_this(), auto effect = StatusEffect::make_StatusEffect( id, source.getAsActor(), getAsActor(), duration, 3000 );
shared_from_this(), duration, 3000 ) );
effect->setParam( param ); effect->setParam( param );
addStatusEffect( effect ); addStatusEffect( effect );
} }
/*! \param StatusEffectPtr to be applied to the actor */ /*! \param StatusEffectPtr to be applied to the actor */
void Core::Entity::Actor::addStatusEffectByIdIfNotExist( uint32_t id, int32_t duration, Entity::Actor& pSource, uint16_t param ) void Core::Entity::Actor::addStatusEffectByIdIfNotExist( uint32_t id, int32_t duration, Entity::Actor& source, uint16_t param )
{ {
if( hasStatusEffect( id ) ) if( hasStatusEffect( id ) )
return; return;
StatusEffect::StatusEffectPtr effect( new StatusEffect::StatusEffect( id, pSource.shared_from_this(), auto effect = StatusEffect::make_StatusEffect( id, source.getAsActor(), getAsActor(), duration, 3000 );
shared_from_this(), duration, 3000 ) );
effect->setParam( param ); effect->setParam( param );
addStatusEffect( effect ); addStatusEffect( effect );

View file

@ -5,6 +5,7 @@
#include <boost/enable_shared_from_this.hpp> #include <boost/enable_shared_from_this.hpp>
#include "Forwards.h" #include "Forwards.h"
#include "GameObject.h"
#include <set> #include <set>
#include <map> #include <map>
#include <queue> #include <queue>
@ -17,29 +18,9 @@ namespace Entity {
\brief Base class for all actors \brief Base class for all actors
*/ */
class Actor : public boost::enable_shared_from_this< Actor > class Actor : public GameObject
{ {
public: public:
enum ObjKind : uint8_t
{
None = 0x00,
Player = 0x01,
BattleNpc = 0x02,
EventNpc = 0x03,
Treasure = 0x04,
Aetheryte = 0x05,
GatheringPoint = 0x06,
EventObj = 0x07,
Mount = 0x08,
Companion = 0x09,
Retainer = 0x0A,
Area = 0x0B,
Housing = 0x0C,
Cutscene = 0x0D,
CardStand = 0x0E,
Exit = 0x0F,
};
enum Stance : uint8_t enum Stance : uint8_t
{ {
Passive = 0, Passive = 0,
@ -114,21 +95,9 @@ public:
} m_baseStats; } m_baseStats;
protected: protected:
// TODO: The position class should probably be abolished and
// the FFXIV_POS struct used instead ( the functions in there
// could be moved to a FFXIV_POS_Helper namespace and rotation to
// its own member )
/*! Position of the actor */
Common::FFXIVARR_POSITION3 m_pos;
float m_rot;
/*! Name of the actor */
char m_name[34]; char m_name[34];
/*! Id of the zone the actor currently is in */ /*! Id of the zone the actor currently is in */
uint32_t m_zoneId; uint32_t m_zoneId;
/*! Id of the actor */
uint32_t m_id;
/*! Type of the actor */
ObjKind m_objKind;
/*! Ptr to the ZoneObj the actor belongs to */ /*! Ptr to the ZoneObj the actor belongs to */
ZonePtr m_pCurrentZone; ZonePtr m_pCurrentZone;
/*! Last tick time for the actor ( in ms ) */ /*! Last tick time for the actor ( in ms ) */
@ -171,14 +140,12 @@ protected:
std::map< uint8_t, StatusEffect::StatusEffectPtr > m_statusEffectMap; std::map< uint8_t, StatusEffect::StatusEffectPtr > m_statusEffectMap;
public: public:
Actor(); Actor( ObjKind type );
virtual ~Actor(); virtual ~Actor() override;
virtual void calculateStats() {}; virtual void calculateStats() {};
uint32_t getId() const;
/// Status effect functions /// Status effect functions
void addStatusEffect( StatusEffect::StatusEffectPtr pEffect ); void addStatusEffect( StatusEffect::StatusEffectPtr pEffect );
void removeStatusEffect( uint8_t effectSlotId ); void removeStatusEffect( uint8_t effectSlotId );
@ -210,16 +177,8 @@ public:
float getRotation() const; float getRotation() const;
Common::FFXIVARR_POSITION3& getPos();
std::string getName() const; std::string getName() const;
bool isPlayer() const;
bool isBNpc() const;
bool isEventNpc() const;
std::set< ActorPtr > getInRangeActors( bool includeSelf = false ); std::set< ActorPtr > getInRangeActors( bool includeSelf = false );
bool face( const Common::FFXIVARR_POSITION3& p ); bool face( const Common::FFXIVARR_POSITION3& p );
@ -279,12 +238,12 @@ public:
virtual void autoAttack( ActorPtr pTarget ); virtual void autoAttack( ActorPtr pTarget );
virtual void spawn( PlayerPtr pTarget ) {} virtual void spawn( PlayerPtr pTarget ) {}
virtual void despawn( ActorPtr pTarget ) {} virtual void despawn( PlayerPtr pTarget ) {}
virtual void onRemoveInRangeActor( ActorPtr pActor ) {} virtual void onRemoveInRangeActor( Actor& pActor ) {}
virtual void onDeath() {}; virtual void onDeath() {};
virtual void onDamageTaken( Actor& pSource ) {}; virtual void onDamageTaken( Actor& pSource ) {};
virtual void onActionHostile( Core::Entity::ActorPtr pSource ) {}; virtual void onActionHostile( Actor& source ) {};
virtual void onActionFriendly( Actor& pSource ) {}; virtual void onActionFriendly( Actor& pSource ) {};
virtual void onTick() {}; virtual void onTick() {};
@ -296,10 +255,6 @@ public:
virtual bool checkAction(); virtual bool checkAction();
virtual void update( int64_t currTime ) {}; virtual void update( int64_t currTime ) {};
PlayerPtr getAsPlayer();
BattleNpcPtr getAsBattleNpc();
EventNpcPtr getAsEventNpc();
Action::ActionPtr getCurrentAction() const; Action::ActionPtr getCurrentAction() const;
void setCurrentAction( Action::ActionPtr pAction ); void setCurrentAction( Action::ActionPtr pAction );
@ -317,7 +272,7 @@ public:
virtual void addInRangeActor( ActorPtr pActor ); virtual void addInRangeActor( ActorPtr pActor );
// remove an actor from the in range set // remove an actor from the in range set
void removeInRangeActor( ActorPtr pActor ); void removeInRangeActor( Actor& pActor );
// return true if there is at least one actor in the in range set // return true if there is at least one actor in the in range set
bool hasInRangeActor() const; bool hasInRangeActor() const;

View file

@ -25,10 +25,10 @@ extern Core::Data::ExdDataGenerated g_exdDataGen;
uint32_t Core::Entity::BattleNpc::m_nextID = 1149241694; uint32_t Core::Entity::BattleNpc::m_nextID = 1149241694;
Core::Entity::BattleNpc::BattleNpc() Core::Entity::BattleNpc::BattleNpc() :
Actor( ObjKind::BattleNpc )
{ {
m_id = 0; m_id = 0;
m_objKind = ObjKind::BattleNpc;
m_status = ActorStatus::Idle; m_status = ActorStatus::Idle;
} }
@ -39,7 +39,8 @@ Core::Entity::BattleNpc::~BattleNpc()
Core::Entity::BattleNpc::BattleNpc( uint16_t modelId, uint16_t nameid, const Common::FFXIVARR_POSITION3& spawnPos, Core::Entity::BattleNpc::BattleNpc( uint16_t modelId, uint16_t nameid, const Common::FFXIVARR_POSITION3& spawnPos,
uint16_t bnpcBaseId, uint32_t type, uint8_t level, uint8_t behaviour, uint16_t bnpcBaseId, uint32_t type, uint8_t level, uint8_t behaviour,
uint32_t mobType ) : Actor() uint32_t mobType ) :
Actor( ObjKind::BattleNpc )
{ {
BattleNpc::m_nextID++; BattleNpc::m_nextID++;
m_id = BattleNpc::m_nextID; m_id = BattleNpc::m_nextID;
@ -48,8 +49,6 @@ Core::Entity::BattleNpc::BattleNpc( uint16_t modelId, uint16_t nameid, const Com
m_pos = spawnPos; m_pos = spawnPos;
m_posOrigin = spawnPos; m_posOrigin = spawnPos;
m_objKind = ObjKind::BattleNpc;
m_mode = MODE_IDLE; m_mode = MODE_IDLE;
m_targetId = static_cast< uint64_t >( INVALID_GAME_OBJECT_ID ); m_targetId = static_cast< uint64_t >( INVALID_GAME_OBJECT_ID );
@ -149,11 +148,8 @@ void Core::Entity::BattleNpc::spawn( PlayerPtr pTarget )
} }
// despawn // despawn
void Core::Entity::BattleNpc::despawn( ActorPtr pTarget ) void Core::Entity::BattleNpc::despawn( PlayerPtr pPlayer )
{ {
auto pPlayer = pTarget->getAsPlayer();
pPlayer->freePlayerSpawnId( getId() ); pPlayer->freePlayerSpawnId( getId() );
ActorControlPacket143 controlPacket( m_id, DespawnZoneScreenMsg, 0x04, getId(), 0x01 ); ActorControlPacket143 controlPacket( m_id, DespawnZoneScreenMsg, 0x04, getId(), 0x01 );
@ -181,11 +177,11 @@ uint8_t Core::Entity::BattleNpc::getbehavior() const
return m_behavior; return m_behavior;
} }
void Core::Entity::BattleNpc::hateListAdd( ActorPtr pActor, int32_t hateAmount ) void Core::Entity::BattleNpc::hateListAdd( Actor& actor, int32_t hateAmount )
{ {
auto hateEntry = new HateListEntry(); auto hateEntry = new HateListEntry();
hateEntry->m_hateAmount = hateAmount; hateEntry->m_hateAmount = hateAmount;
hateEntry->m_pActor = pActor; hateEntry->m_pActor = actor.getAsActor();
m_hateList.insert( hateEntry ); m_hateList.insert( hateEntry );
} }
@ -278,32 +274,32 @@ bool Core::Entity::BattleNpc::moveTo( Common::FFXIVARR_POSITION3& pos )
} }
void Core::Entity::BattleNpc::aggro( ActorPtr pActor ) void Core::Entity::BattleNpc::aggro( Actor& actor )
{ {
m_lastAttack = Util::getTimeMs(); m_lastAttack = Util::getTimeMs();
hateListUpdate( pActor, 1 ); hateListUpdate( actor, 1 );
changeTarget( pActor->getId() ); changeTarget( actor.getId() );
setStance( Stance::Active ); setStance( Stance::Active );
m_mode = MODE_COMBAT; m_mode = MODE_COMBAT;
if( pActor->isPlayer() ) if( actor.isPlayer() )
{ {
PlayerPtr tmpPlayer = pActor->getAsPlayer(); PlayerPtr tmpPlayer = actor.getAsPlayer();
tmpPlayer->queuePacket( ActorControlPacket142( getId(), 0, 1, 1 ) ); tmpPlayer->queuePacket( ActorControlPacket142( getId(), 0, 1, 1 ) );
tmpPlayer->onMobAggro( getAsBattleNpc() ); tmpPlayer->onMobAggro( getAsBattleNpc() );
} }
} }
void Core::Entity::BattleNpc::deaggro( ActorPtr pActor ) void Core::Entity::BattleNpc::deaggro( Actor& actor )
{ {
if( !hateListHasActor( pActor ) ) if( !hateListHasActor( actor ) )
hateListRemove( pActor ); hateListRemove( actor );
if( pActor->isPlayer() ) if( actor.isPlayer() )
{ {
PlayerPtr tmpPlayer = pActor->getAsPlayer(); PlayerPtr tmpPlayer = actor.getAsPlayer();
tmpPlayer->onMobDeaggro( getAsBattleNpc() ); tmpPlayer->onMobDeaggro( getAsBattleNpc() );
} }
} }
@ -314,7 +310,7 @@ void Core::Entity::BattleNpc::hateListClear()
for( ; it != m_hateList.end(); ++it ) for( ; it != m_hateList.end(); ++it )
{ {
if( isInRangeSet( ( *it )->m_pActor ) ) if( isInRangeSet( ( *it )->m_pActor ) )
deaggro( ( *it )->m_pActor ); deaggro( *( *it )->m_pActor );
HateListEntry* tmpListEntry = ( *it ); HateListEntry* tmpListEntry = ( *it );
delete tmpListEntry; delete tmpListEntry;
} }
@ -322,19 +318,19 @@ void Core::Entity::BattleNpc::hateListClear()
} }
void Core::Entity::BattleNpc::hateListRemove( ActorPtr pActor ) void Core::Entity::BattleNpc::hateListRemove( Actor& actor )
{ {
auto it = m_hateList.begin(); auto it = m_hateList.begin();
for( ; it != m_hateList.end(); ++it ) for( ; it != m_hateList.end(); ++it )
{ {
if( ( *it )->m_pActor == pActor ) if( ( *it )->m_pActor->getId() == actor.getId() )
{ {
HateListEntry* pEntry = *it; HateListEntry* pEntry = *it;
m_hateList.erase( it ); m_hateList.erase( it );
delete pEntry; delete pEntry;
if( pActor->isPlayer() ) if( actor.isPlayer() )
{ {
PlayerPtr tmpPlayer = pActor->getAsPlayer(); PlayerPtr tmpPlayer = actor.getAsPlayer();
tmpPlayer->onMobDeaggro( getAsBattleNpc() ); tmpPlayer->onMobDeaggro( getAsBattleNpc() );
} }
return; return;
@ -342,12 +338,12 @@ void Core::Entity::BattleNpc::hateListRemove( ActorPtr pActor )
} }
} }
bool Core::Entity::BattleNpc::hateListHasActor( ActorPtr pActor ) bool Core::Entity::BattleNpc::hateListHasActor( Actor& actor )
{ {
auto it = m_hateList.begin(); auto it = m_hateList.begin();
for( ; it != m_hateList.end(); ++it ) for( ; it != m_hateList.end(); ++it )
{ {
if( ( *it )->m_pActor == pActor ) if( ( *it )->m_pActor->getId() == actor.getId() )
return true; return true;
} }
return false; return false;
@ -363,13 +359,13 @@ uint32_t Core::Entity::BattleNpc::getNameId() const
return m_nameId; return m_nameId;
} }
void Core::Entity::BattleNpc::hateListUpdate( ActorPtr pActor, int32_t hateAmount ) void Core::Entity::BattleNpc::hateListUpdate( Actor& actor, int32_t hateAmount )
{ {
auto it = m_hateList.begin(); auto it = m_hateList.begin();
for( ; it != m_hateList.end(); ++it ) for( ; it != m_hateList.end(); ++it )
{ {
if( ( *it )->m_pActor == pActor ) if( ( *it )->m_pActor->getId() == actor.getId() )
{ {
( *it )->m_hateAmount += hateAmount; ( *it )->m_hateAmount += hateAmount;
return; return;
@ -378,7 +374,7 @@ void Core::Entity::BattleNpc::hateListUpdate( ActorPtr pActor, int32_t hateAmoun
auto hateEntry = new HateListEntry(); auto hateEntry = new HateListEntry();
hateEntry->m_hateAmount = hateAmount; hateEntry->m_hateAmount = hateAmount;
hateEntry->m_pActor = pActor; hateEntry->m_pActor = actor.getAsActor();
m_hateList.insert( hateEntry ); m_hateList.insert( hateEntry );
} }
@ -452,14 +448,14 @@ void Core::Entity::BattleNpc::onDeath()
hateListClear(); hateListClear();
} }
void Core::Entity::BattleNpc::onActionHostile( ActorPtr pSource ) void Core::Entity::BattleNpc::onActionHostile( Actor& source )
{ {
if( hateListGetHighest() == nullptr ) if( hateListGetHighest() == nullptr )
aggro( pSource ); aggro( source );
if( getClaimer() == nullptr ) if( getClaimer() == nullptr )
setOwner( pSource->getAsPlayer() ); setOwner( source.getAsPlayer() );
} }
Core::Entity::ActorPtr Core::Entity::BattleNpc::getClaimer() const Core::Entity::ActorPtr Core::Entity::BattleNpc::getClaimer() const
@ -526,7 +522,7 @@ void Core::Entity::BattleNpc::update( int64_t currTime )
if( pClosestActor != nullptr && !pClosestActor->isAlive() ) if( pClosestActor != nullptr && !pClosestActor->isAlive() )
{ {
hateListRemove( pClosestActor ); hateListRemove( *pClosestActor );
pClosestActor = hateListGetHighest(); pClosestActor = hateListGetHighest();
} }

View file

@ -24,7 +24,7 @@ class BattleNpc : public Actor
{ {
public: public:
BattleNpc(); BattleNpc();
~BattleNpc(); virtual ~BattleNpc() override;
BattleNpc( uint16_t modelId, uint16_t nameid, const Common::FFXIVARR_POSITION3& spawnPos, uint16_t bnpcBaseId = 0, BattleNpc( uint16_t modelId, uint16_t nameid, const Common::FFXIVARR_POSITION3& spawnPos, uint16_t bnpcBaseId = 0,
uint32_t type = 2, uint8_t level = 0, uint8_t behaviour = 1, uint32_t mobType = 0 ); uint32_t type = 2, uint8_t level = 0, uint8_t behaviour = 1, uint32_t mobType = 0 );
@ -42,7 +42,7 @@ public:
void spawn( PlayerPtr pTarget ) override; void spawn( PlayerPtr pTarget ) override;
// send despawn packets to pTarget // send despawn packets to pTarget
void despawn( ActorPtr pTarget ) override; void despawn( PlayerPtr pTarget ) override;
uint8_t getLevel() const override; uint8_t getLevel() const override;
@ -52,12 +52,12 @@ public:
uint8_t getbehavior() const; uint8_t getbehavior() const;
void hateListAdd( ActorPtr pActor, int32_t hateAmount ); void hateListAdd( Actor& actor, int32_t hateAmount );
void hateListUpdate( ActorPtr pActor, int32_t hateAmount ); void hateListUpdate( Actor& actor, int32_t hateAmount );
void hateListRemove( ActorPtr pActor ); void hateListRemove( Actor& actor );
bool hateListHasActor( ActorPtr pActor ); bool hateListHasActor( Actor& actor );
void resetPos(); void resetPos();
@ -67,15 +67,15 @@ public:
ActorPtr hateListGetHighest(); ActorPtr hateListGetHighest();
void aggro( ActorPtr pActor ); void aggro( Actor& actor );
void deaggro( ActorPtr pActor ); void deaggro( Actor& actor );
void setOwner( PlayerPtr pPlayer ); void setOwner( PlayerPtr pPlayer );
void onDeath() override; void onDeath() override;
void onActionHostile( ActorPtr pSource ) override; void onActionHostile( Actor& source ) override;
ActorPtr getClaimer() const; ActorPtr getClaimer() const;

View file

@ -23,10 +23,10 @@ extern Core::Logger g_log;
uint32_t Core::Entity::EventNpc::m_nextID = 1249241694; uint32_t Core::Entity::EventNpc::m_nextID = 1249241694;
Core::Entity::EventNpc::EventNpc() Core::Entity::EventNpc::EventNpc() :
Actor( ObjKind::EventNpc )
{ {
m_id = 0; m_id = 0;
m_objKind = ObjKind::EventNpc;
m_status = ActorStatus::Idle; m_status = ActorStatus::Idle;
} }
@ -35,7 +35,8 @@ Core::Entity::EventNpc::~EventNpc()
} }
Core::Entity::EventNpc::EventNpc( uint32_t enpcId, const Common::FFXIVARR_POSITION3& spawnPos, float rotation ) : Actor() Core::Entity::EventNpc::EventNpc( uint32_t enpcId, const Common::FFXIVARR_POSITION3& spawnPos, float rotation ) :
Actor( ObjKind::EventNpc )
{ {
EventNpc::m_nextID++; EventNpc::m_nextID++;
m_id = EventNpc::m_nextID; m_id = EventNpc::m_nextID;
@ -43,8 +44,6 @@ Core::Entity::EventNpc::EventNpc( uint32_t enpcId, const Common::FFXIVARR_POSITI
m_pos = spawnPos; m_pos = spawnPos;
m_posOrigin = spawnPos; m_posOrigin = spawnPos;
m_objKind = ObjKind::EventNpc;
m_targetId = static_cast< uint64_t >( INVALID_GAME_OBJECT_ID ); m_targetId = static_cast< uint64_t >( INVALID_GAME_OBJECT_ID );
m_maxHp = 150; m_maxHp = 150;
@ -68,7 +67,8 @@ Core::Entity::EventNpc::EventNpc( uint32_t enpcId, const Common::FFXIVARR_POSITI
} }
// spawn this player for pTarget // spawn this player for pTarget
// TODO: Retail additionally sends Look+Models for EventNpcs even though it is not needed, add when the new exd reader is implemented(also counts for BNPCs) /*! TODO: Retail additionally sends Look+Models for EventNpcs even though it is not needed,
add when the new exd reader is implemented(also counts for BNPCs) */
void Core::Entity::EventNpc::spawn( PlayerPtr pTarget ) void Core::Entity::EventNpc::spawn( PlayerPtr pTarget )
{ {
ZoneChannelPacket< FFXIVIpcNpcSpawn > spawnPacket( getId(), pTarget->getId() ); ZoneChannelPacket< FFXIVIpcNpcSpawn > spawnPacket( getId(), pTarget->getId() );
@ -94,16 +94,12 @@ void Core::Entity::EventNpc::spawn( PlayerPtr pTarget )
} }
// despawn // despawn
void Core::Entity::EventNpc::despawn( ActorPtr pTarget ) void Core::Entity::EventNpc::despawn( PlayerPtr pTarget )
{ {
pTarget->freePlayerSpawnId( getId() );
auto pPlayer = pTarget->getAsPlayer();
pPlayer->freePlayerSpawnId( getId() );
ActorControlPacket143 controlPacket( m_id, DespawnZoneScreenMsg, 0x04, getId(), 0x01 ); ActorControlPacket143 controlPacket( m_id, DespawnZoneScreenMsg, 0x04, getId(), 0x01 );
pPlayer->queuePacket( controlPacket ); pTarget->queuePacket( controlPacket );
} }
uint8_t Core::Entity::EventNpc::getLevel() const uint8_t Core::Entity::EventNpc::getLevel() const

View file

@ -11,7 +11,7 @@ class EventNpc : public Actor
{ {
public: public:
EventNpc(); EventNpc();
~EventNpc(); virtual ~EventNpc() override;
EventNpc( uint32_t enpcId, const Common::FFXIVARR_POSITION3& spawnPos, float rotation ); EventNpc( uint32_t enpcId, const Common::FFXIVARR_POSITION3& spawnPos, float rotation );
@ -19,7 +19,7 @@ public:
void spawn( PlayerPtr pTarget ) override; void spawn( PlayerPtr pTarget ) override;
// send despawn packets to pTarget // send despawn packets to pTarget
void despawn( ActorPtr pTarget ) override; void despawn( PlayerPtr pTarget ) override;
uint8_t getLevel() const override; uint8_t getLevel() const override;

View file

@ -1,5 +1,10 @@
#include "GameObject.h" #include "GameObject.h"
#include "Player.h"
#include "Actor.h"
#include "BattleNpc.h"
#include "EventNpc.h"
Core::Entity::GameObject::GameObject( ObjKind type ) : Core::Entity::GameObject::GameObject( ObjKind type ) :
m_objKind( type ) m_objKind( type )
{ {
@ -48,12 +53,42 @@ bool Core::Entity::GameObject::isPlayer() const
return m_objKind == ObjKind::Player; return m_objKind == ObjKind::Player;
} }
bool Core::Entity::GameObject::isBNpc() const bool Core::Entity::GameObject::isBattleNpc() const
{ {
return m_objKind == ObjKind::BattleNpc; return m_objKind == ObjKind::BattleNpc;
} }
bool Core::Entity::GameObject::isENpc() const bool Core::Entity::GameObject::isEventNpc() const
{ {
return m_objKind == ObjKind::EventNpc; return m_objKind == ObjKind::EventNpc;
} }
/*! \return pointer to this instance as ActorPtr */
Core::Entity::ActorPtr Core::Entity::GameObject::getAsActor()
{
return boost::dynamic_pointer_cast< Entity::Actor, Entity::GameObject >( shared_from_this() );
}
/*! \return pointer to this instance as PlayerPtr */
Core::Entity::PlayerPtr Core::Entity::GameObject::getAsPlayer()
{
if( !isPlayer() )
return nullptr;
return boost::dynamic_pointer_cast< Entity::Player, Entity::GameObject >( shared_from_this() );
}
/*! \return pointer to this instance as BattleNpcPtr */
Core::Entity::BattleNpcPtr Core::Entity::GameObject::getAsBattleNpc()
{
if( !isBattleNpc() )
return nullptr;
return boost::dynamic_pointer_cast< Entity::BattleNpc, Entity::GameObject >( shared_from_this() );
}
/*! \return pointer to this instance as EventNpcPtr */
Core::Entity::EventNpcPtr Core::Entity::GameObject::getAsEventNpc()
{
if( !isEventNpc() )
return nullptr;
return boost::dynamic_pointer_cast< Entity::EventNpc, Entity::GameObject >( shared_from_this() );
}

View file

@ -51,7 +51,7 @@ namespace Core {
public: public:
explicit GameObject( ObjKind type ); explicit GameObject( ObjKind type );
//virtual ~GameObject() {}; virtual ~GameObject() {};
uint32_t getId() const; uint32_t getId() const;
@ -65,12 +65,13 @@ namespace Core {
void setRot( float rot ); void setRot( float rot );
bool isPlayer() const; bool isPlayer() const;
bool isBNpc() const; bool isBattleNpc() const;
bool isENpc() const; bool isEventNpc() const;
ActorPtr getAsActor();
PlayerPtr getAsPlayer(); PlayerPtr getAsPlayer();
BattleNpcPtr getAsBNpc(); BattleNpcPtr getAsBattleNpc();
EventNpcPtr getAsENpc(); EventNpcPtr getAsEventNpc();
}; };
} }

View file

@ -53,7 +53,7 @@ using namespace Core::Network::Packets::Server;
// player constructor // player constructor
Core::Entity::Player::Player() : Core::Entity::Player::Player() :
Actor(), Actor( ObjKind::Player ),
m_lastWrite( 0 ), m_lastWrite( 0 ),
m_lastPing( 0 ), m_lastPing( 0 ),
m_bIsLogin( false ), m_bIsLogin( false ),
@ -74,7 +74,6 @@ Core::Entity::Player::Player() :
m_directorInitialized( false ) m_directorInitialized( false )
{ {
m_id = 0; m_id = 0;
m_objKind = ObjKind::Player;
m_currentStance = Stance::Passive; m_currentStance = Stance::Passive;
m_onlineStatus = 0; m_onlineStatus = 0;
m_queuedZoneing = nullptr; m_queuedZoneing = nullptr;
@ -660,29 +659,7 @@ void Core::Entity::Player::unlock()
void Core::Entity::Player::sendStatusUpdate( bool toSelf ) void Core::Entity::Player::sendStatusUpdate( bool toSelf )
{ {
// CGamePacket* pPE = new CGamePacket(0x140, 0x0128, getId(), getId()); sendToInRangeSet( UpdateHpMpTpPacket( *this ), true );
//pPE->setInt8At(0x20, static_cast<uint8_t>(getClass()));
// pPE->setInt8At(0x21, getLevel());
// pPE->setInt8At(0x22, getLevel());
// // current exp
// pPE->setInt32At(0x28, getExp());
// // rested exp
// //pPE->setInt32At(0x2C, m_hp);
// pPE->setInt32At(0x24, m_hp);
// pPE->setInt32At(0x28, getMaxHp());
// pPE->setInt16At(0x2C, m_mp);
// pPE->setInt16At(0x2E, getMaxMp());
// pPE->setInt16At(0x30, m_tp);
// sendToInRangeSet(pPE, toSelf);
sendToInRangeSet( UpdateHpMpTpPacket( shared_from_this() ), true );
} }
uint8_t Core::Entity::Player::getLevel() const uint8_t Core::Entity::Player::getLevel() const
@ -834,9 +811,9 @@ void Core::Entity::Player::spawn( Entity::PlayerPtr pTarget )
} }
// despawn // despawn
void Core::Entity::Player::despawn( Entity::ActorPtr pTarget ) void Core::Entity::Player::despawn( Entity::PlayerPtr pTarget )
{ {
auto pPlayer = pTarget->getAsPlayer(); auto pPlayer = pTarget;
pPlayer->freePlayerSpawnId( getId() ); pPlayer->freePlayerSpawnId( getId() );
@ -1444,7 +1421,7 @@ void Core::Entity::Player::autoAttack( ActorPtr pTarget )
auto mainWeap = m_pInventory->getItemAt( Inventory::GearSet0, auto mainWeap = m_pInventory->getItemAt( Inventory::GearSet0,
Inventory::EquipSlot::MainHand ); Inventory::EquipSlot::MainHand );
pTarget->onActionHostile( shared_from_this() ); pTarget->onActionHostile( *this );
//uint64_t tick = Util::getTimeMs(); //uint64_t tick = Util::getTimeMs();
//srand(static_cast< uint32_t >(tick)); //srand(static_cast< uint32_t >(tick));
@ -1634,7 +1611,7 @@ void Player::sendZonePackets()
if( getLastPing() == 0 ) if( getLastPing() == 0 )
sendQuestInfo(); sendQuestInfo();
getCurrentZone()->onEnterTerritory( getAsPlayer() ); getCurrentZone()->onEnterTerritory( *this );
m_bMarkedForZoning = false; m_bMarkedForZoning = false;
} }

View file

@ -421,7 +421,7 @@ public:
/*! send spawn packets to pTarget */ /*! send spawn packets to pTarget */
void spawn( PlayerPtr pTarget ) override; void spawn( PlayerPtr pTarget ) override;
/*! send despawn packets to pTarget */ /*! send despawn packets to pTarget */
void despawn( ActorPtr pTarget ) override; void despawn( PlayerPtr pTarget ) override;
// Player State Handling // Player State Handling
////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////

View file

@ -80,7 +80,7 @@ void Core::Entity::Player::eventStart( uint64_t actorId, uint32_t eventId,
uint32_t eventParam2 ) uint32_t eventParam2 )
{ {
Event::EventHandlerPtr newEvent( new Event::EventHandler( this, actorId, eventId, eventType, eventParam2 ) ); auto newEvent = Event::make_EventHandler( this, actorId, eventId, eventType, eventParam2 );
addEvent( newEvent ); addEvent( newEvent );
@ -227,8 +227,8 @@ void Core::Entity::Player::eventActionStart( uint32_t eventId,
ActionCallback interruptCallback, ActionCallback interruptCallback,
uint64_t additional ) uint64_t additional )
{ {
Action::ActionPtr pEventAction( new Action::EventAction( shared_from_this(), eventId, action, auto pEventAction = Action::make_EventAction( getAsActor(), eventId, action,
finishCallback, interruptCallback, additional ) ); finishCallback, interruptCallback, additional );
setCurrentAction( pEventAction ); setCurrentAction( pEventAction );
auto pEvent = getEvent( eventId ); auto pEvent = getEvent( eventId );
@ -257,8 +257,8 @@ void Core::Entity::Player::eventItemActionStart( uint32_t eventId,
ActionCallback interruptCallback, ActionCallback interruptCallback,
uint64_t additional ) uint64_t additional )
{ {
Action::ActionPtr pEventItemAction( new Action::EventItemAction( shared_from_this(), eventId, action, Action::ActionPtr pEventItemAction = Action::make_EventItemAction( getAsActor(), eventId, action,
finishCallback, interruptCallback, additional ) ); finishCallback, interruptCallback, additional );
setCurrentAction( pEventItemAction ); setCurrentAction( pEventItemAction );

View file

@ -202,11 +202,10 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession )
m_modelSubWeapon = 0; m_modelSubWeapon = 0;
m_lastTickTime = 0; m_lastTickTime = 0;
auto pPlayer = getAsPlayer();
// TODO: remove Inventory and actually inline it in Player class // TODO: remove Inventory and actually inline it in Player class
m_pInventory = InventoryPtr( new Inventory( pPlayer.get() ) ); m_pInventory = make_Inventory( this );
pPlayer->calculateStats(); calculateStats();
// first login, run the script event // first login, run the script event
if( m_bNewGame ) if( m_bNewGame )

View file

@ -345,7 +345,7 @@ void Core::DebugCommandHandler::add( char * data, Entity::Player& player, boost:
sscanf( params.c_str(), "%d %d %hu", &id, &duration, &param ); sscanf( params.c_str(), "%d %d %hu", &id, &duration, &param );
StatusEffect::StatusEffectPtr effect( new StatusEffect::StatusEffect( id, player.getAsPlayer(), player.getAsPlayer(), duration, 3000 ) ); auto effect = StatusEffect::make_StatusEffect( id, player.getAsPlayer(), player.getAsPlayer(), duration, 3000 );
effect->setParam( param ); effect->setParam( param );
player.addStatusEffect( effect ); player.addStatusEffect( effect );
@ -364,7 +364,7 @@ void Core::DebugCommandHandler::add( char * data, Entity::Player& player, boost:
sscanf( params.c_str(), "%d %d", &model, &name ); sscanf( params.c_str(), "%d %d", &model, &name );
Entity::BattleNpcPtr pBNpc( new Entity::BattleNpc( model, name, player.getPos() ) ); auto pBNpc = Entity::make_BattleNpc( model, name, player.getPos() );
auto pZone = player.getCurrentZone(); auto pZone = player.getCurrentZone();
pBNpc->setCurrentZone( pZone ); pBNpc->setCurrentZone( pZone );
@ -376,7 +376,7 @@ void Core::DebugCommandHandler::add( char * data, Entity::Player& player, boost:
// temporary research packet // temporary research packet
int32_t opcode; int32_t opcode;
sscanf( params.c_str(), "%x", &opcode ); sscanf( params.c_str(), "%x", &opcode );
Network::Packets::GamePacketPtr pPe( new Network::Packets::GamePacket( opcode, 0x30, player.getId(), player.getId() ) ); auto pPe = Network::Packets::make_GamePacket( opcode, 0x30, player.getId(), player.getId() );
player.queuePacket( pPe ); player.queuePacket( pPe );
} }
else if( subCommand == "eventnpc-self" ) else if( subCommand == "eventnpc-self" )
@ -400,7 +400,7 @@ void Core::DebugCommandHandler::add( char * data, Entity::Player& player, boost:
sscanf( params.c_str(), "%d", &id ); sscanf( params.c_str(), "%d", &id );
Entity::EventNpcPtr pENpc( new Entity::EventNpc( id, player.getPos(), player.getRotation() ) ); auto pENpc = Entity::make_EventNpc( id, player.getPos(), player.getRotation() );
auto pZone = player.getCurrentZone(); auto pZone = player.getCurrentZone();
pENpc->setCurrentZone( pZone ); pENpc->setCurrentZone( pZone );

View file

@ -39,24 +39,24 @@ uint8_t Core::Event::Director::getSequence() const
return m_sequence; return m_sequence;
} }
void Core::Event::Director::sendDirectorClear( Core::Entity::PlayerPtr pPlayer ) const void Core::Event::Director::sendDirectorClear( Core::Entity::Player& player ) const
{ {
pPlayer->queuePacket( ActorControlPacket143( pPlayer->getId(), DirectorClear, m_directorId ) ); player.queuePacket( ActorControlPacket143( player.getId(), DirectorClear, m_directorId ) );
} }
void Core::Event::Director::sendDirectorVars( Core::Entity::PlayerPtr pPlayer ) const void Core::Event::Director::sendDirectorVars( Core::Entity::Player& player ) const
{ {
ZoneChannelPacket< FFXIVIpcDirectorVars > varPacket( pPlayer->getId() ); ZoneChannelPacket< FFXIVIpcDirectorVars > varPacket( player.getId() );
varPacket.data().m_directorId = getDirectorId(); varPacket.data().m_directorId = getDirectorId();
varPacket.data().m_sequence = getSequence(); varPacket.data().m_sequence = getSequence();
varPacket.data().m_branch = 0; varPacket.data().m_branch = 0;
memcpy( varPacket.data().m_unionData, m_unionData.arrData, sizeof( varPacket.data().m_unionData ) ); memcpy( varPacket.data().m_unionData, m_unionData.arrData, sizeof( varPacket.data().m_unionData ) );
pPlayer->queuePacket( varPacket ); player.queuePacket( varPacket );
} }
void Core::Event::Director::sendDirectorInit( Core::Entity::PlayerPtr pPlayer ) const void Core::Event::Director::sendDirectorInit( Core::Entity::Player& player ) const
{ {
pPlayer->queuePacket( ActorControlPacket143( pPlayer->getId(), DirectorInit, m_directorId, m_contentId ) ); player.queuePacket( ActorControlPacket143( player.getId(), DirectorInit, m_directorId, m_contentId ) );
} }
Core::Event::Director::DirectorType Core::Event::Director::getType() const Core::Event::Director::DirectorType Core::Event::Director::getType() const

View file

@ -38,9 +38,9 @@ public:
uint8_t getSequence() const; uint8_t getSequence() const;
uint8_t getBranch() const; uint8_t getBranch() const;
void sendDirectorInit( Entity::PlayerPtr pPlayer ) const; void sendDirectorInit( Entity::Player& player ) const;
void sendDirectorClear( Entity::PlayerPtr pPlayer ) const; void sendDirectorClear( Entity::Player& player ) const;
void sendDirectorVars( Entity::PlayerPtr pPlayer ) const; void sendDirectorVars( Entity::Player& player ) const;
void setDirectorUI8AL( uint8_t value ); void setDirectorUI8AL( uint8_t value );
void setDirectorUI8AH( uint8_t value ); void setDirectorUI8AH( uint8_t value );

View file

@ -1,12 +1,17 @@
#ifndef _FORWARDS_H #ifndef _FORWARDS_H
#define _FORWARDS_H #define _FORWARDS_H
#include <utility>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <vector> #include <vector>
#define TYPE_FORWARD( x ) \ #define TYPE_FORWARD( x ) \
class x; \ class x; \
typedef boost::shared_ptr< x > x ## Ptr; \ typedef boost::shared_ptr< x > x ## Ptr; \
template< typename...Args > \
x ## Ptr make_ ## x( Args &&...args ) { \
return boost::make_shared< x >( std::forward< Args >( args ) ... ); }\
typedef std::vector< x > x ## PtrList; typedef std::vector< x > x ## PtrList;
namespace Core namespace Core
@ -29,6 +34,7 @@ namespace Core
namespace Entity namespace Entity
{ {
TYPE_FORWARD( GameObject );
TYPE_FORWARD( Actor ); TYPE_FORWARD( Actor );
TYPE_FORWARD( Player ); TYPE_FORWARD( Player );
TYPE_FORWARD( BattleNpc ); TYPE_FORWARD( BattleNpc );
@ -50,6 +56,7 @@ namespace Core
TYPE_FORWARD( ActionCast ); TYPE_FORWARD( ActionCast );
TYPE_FORWARD( ActionMount ); TYPE_FORWARD( ActionMount );
TYPE_FORWARD( EventAction ); TYPE_FORWARD( EventAction );
TYPE_FORWARD( EventItemAction );
} }
namespace Network namespace Network

View file

@ -36,7 +36,7 @@ Core::Inventory::Inventory( Core::Entity::Player* pOwner )
// shortcut for setting up inventory // shortcut for setting up inventory
// TODO: use a loop to set theese up? // TODO: use a loop to set theese up?
auto setupContainer = []( InventoryMap& map, InventoryType type ) auto setupContainer = []( InventoryMap& map, InventoryType type )
{ map[type] = ItemContainerPtr( new ItemContainer( type ) ); }; { map[type] = make_ItemContainer( type ); };
// main bags // main bags
setupContainer( m_inventoryMap, Bag0 ); setupContainer( m_inventoryMap, Bag0 );

View file

@ -219,7 +219,7 @@ void Core::Network::GameConnection::actionHandler( const Packets::GamePacket& in
if( !insufficientGil ) if( !insufficientGil )
{ {
Action::ActionTeleportPtr pActionTeleport( new Action::ActionTeleport( player.getAsPlayer(), param11, cost ) ); auto pActionTeleport = Action::make_ActionTeleport( player.getAsPlayer(), param11, cost );
player.setCurrentAction( pActionTeleport ); player.setCurrentAction( pActionTeleport );
} }
} }
@ -231,7 +231,7 @@ void Core::Network::GameConnection::actionHandler( const Packets::GamePacket& in
} }
case 0x321: // Director init finish case 0x321: // Director init finish
{ {
player.getCurrentZone()->onInitDirector( player.getAsPlayer() ); player.getCurrentZone()->onInitDirector( player );
break; break;
} }
default: default:

View file

@ -404,7 +404,7 @@ void Core::Network::GameConnection::pingHandler( const Packets::GamePacket& inPa
void Core::Network::GameConnection::finishLoadingHandler( const Packets::GamePacket& inPacket, void Core::Network::GameConnection::finishLoadingHandler( const Packets::GamePacket& inPacket,
Entity::Player& player ) Entity::Player& player )
{ {
player.getCurrentZone()->onFinishLoading( player.getAsPlayer() ); player.getCurrentZone()->onFinishLoading( player );
// player is done zoning // player is done zoning
player.setLoadingComplete( true ); player.setLoadingComplete( true );
@ -421,7 +421,7 @@ void Core::Network::GameConnection::finishLoadingHandler( const Packets::GamePac
player.spawn( player.getAsPlayer() ); player.spawn( player.getAsPlayer() );
// notify the zone of a change in position to force an "inRangeActor" update // notify the zone of a change in position to force an "inRangeActor" update
player.getCurrentZone()->changeActorPosition( player.getAsPlayer() ); player.getCurrentZone()->changeActorPosition( player );
} }
void Core::Network::GameConnection::socialListHandler( const Packets::GamePacket& inPacket, void Core::Network::GameConnection::socialListHandler( const Packets::GamePacket& inPacket,

View file

@ -87,7 +87,7 @@ void Core::Network::GameConnection::skillHandler( const Packets::GamePacket& inP
} }
else else
{ {
Action::ActionCastPtr pActionCast( new Action::ActionCast( player.getAsPlayer(), targetActor, action ) ); auto pActionCast = Action::make_ActionCast( player.getAsPlayer(), targetActor, action );
player.setCurrentAction( pActionCast ); player.setCurrentAction( pActionCast );
player.sendDebug( "setCurrentAction()" ); player.sendDebug( "setCurrentAction()" );
player.getCurrentAction()->onStart(); player.getCurrentAction()->onStart();
@ -118,7 +118,7 @@ void Core::Network::GameConnection::skillHandler( const Packets::GamePacket& inP
player.sendDebug( "Request mount " + std::to_string( action ) ); player.sendDebug( "Request mount " + std::to_string( action ) );
Action::ActionMountPtr pActionMount( new Action::ActionMount( player.getAsPlayer(), action ) ); auto pActionMount = Action::make_ActionMount( player.getAsPlayer(), action );
player.setCurrentAction( pActionMount ); player.setCurrentAction( pActionMount );
player.sendDebug( "setCurrentAction()" ); player.sendDebug( "setCurrentAction()" );
player.getCurrentAction()->onStart(); player.getCurrentAction()->onStart();

View file

@ -17,18 +17,18 @@ class UpdateHpMpTpPacket :
public ZoneChannelPacket< FFXIVIpcUpdateHpMpTp > public ZoneChannelPacket< FFXIVIpcUpdateHpMpTp >
{ {
public: public:
UpdateHpMpTpPacket( Entity::ActorPtr pActor ) : UpdateHpMpTpPacket( Entity::Actor& actor ) :
ZoneChannelPacket< FFXIVIpcUpdateHpMpTp >( pActor->getId(), pActor->getId() ) ZoneChannelPacket< FFXIVIpcUpdateHpMpTp >( actor.getId(), actor.getId() )
{ {
initialize( pActor ); initialize( actor );
}; };
private: private:
void initialize( Entity::ActorPtr pActor ) void initialize( Entity::Actor& actor )
{ {
m_data.hp = pActor->getHp(); m_data.hp = actor.getHp();
m_data.mp = pActor->getMp(); m_data.mp = actor.getMp();
m_data.tp = pActor->getTp(); m_data.tp = actor.getTp();
}; };
}; };

View file

@ -49,7 +49,7 @@ Core::Network::GameConnectionPtr Core::Session::getChatConnection() const
bool Core::Session::loadPlayer() bool Core::Session::loadPlayer()
{ {
m_pPlayer = Entity::PlayerPtr( new Entity::Player() ); m_pPlayer = Entity::make_Player();
if( !m_pPlayer->load( m_sessionId, shared_from_this() ) ) if( !m_pPlayer->load( m_sessionId, shared_from_this() ) )
{ {

View file

@ -51,32 +51,32 @@ Core::Data::ExdDataGenerated::InstanceContentPtr Core::InstanceContent::getInsta
return m_instanceContentInfo; return m_instanceContentInfo;
} }
void Core::InstanceContent::onEnterTerritory( Entity::PlayerPtr pPlayer ) void Core::InstanceContent::onEnterTerritory( Entity::Player& player )
{ {
g_log.debug( "InstanceContent::onEnterTerritory: Zone#" + std::to_string( getGuId() ) + "|" g_log.debug( "InstanceContent::onEnterTerritory: Zone#" + std::to_string( getGuId() ) + "|"
+ std::to_string( getInstanceContentId() ) + + std::to_string( getInstanceContentId() ) +
+ ", Entity#" + std::to_string( pPlayer->getId() ) ); + ", Entity#" + std::to_string( player.getId() ) );
// mark player as "bound by duty" // mark player as "bound by duty"
pPlayer->setStateFlag( PlayerStateFlag::BoundByDuty ); player.setStateFlag( PlayerStateFlag::BoundByDuty );
// if the instance was not started yet, director init is sent on enter event. // if the instance was not started yet, director init is sent on enter event.
// else it will be sent on finish loading. // else it will be sent on finish loading.
if( m_state == Created ) if( m_state == Created )
sendDirectorInit( pPlayer ); sendDirectorInit( player );
} }
void Core::InstanceContent::onLeaveTerritory( Entity::PlayerPtr pPlayer ) void Core::InstanceContent::onLeaveTerritory( Entity::Player& player )
{ {
g_log.debug( "InstanceContent::onLeaveTerritory: Zone#" + std::to_string( getGuId() ) + "|" g_log.debug( "InstanceContent::onLeaveTerritory: Zone#" + std::to_string( getGuId() ) + "|"
+ std::to_string( getInstanceContentId() ) + + std::to_string( getInstanceContentId() ) +
+ ", Entity#" + std::to_string( pPlayer->getId() ) ); + ", Entity#" + std::to_string( player.getId() ) );
sendDirectorClear( pPlayer ); sendDirectorClear( player );
pPlayer->setDirectorInitialized( false ); player.setDirectorInitialized( false );
// remove "bound by duty" state // remove "bound by duty" state
pPlayer->unsetStateFlag( PlayerStateFlag::BoundByDuty ); player.unsetStateFlag( PlayerStateFlag::BoundByDuty );
} }
void Core::InstanceContent::onUpdate( uint32_t currTime ) void Core::InstanceContent::onUpdate( uint32_t currTime )
@ -126,16 +126,16 @@ void Core::InstanceContent::onUpdate( uint32_t currTime )
g_scriptMgr.onInstanceUpdate( *this, currTime ); g_scriptMgr.onInstanceUpdate( *this, currTime );
} }
void Core::InstanceContent::onFinishLoading( Entity::PlayerPtr pPlayer ) void Core::InstanceContent::onFinishLoading( Entity::Player& player )
{ {
if( m_state != Created ) if( m_state != Created )
sendDirectorInit( pPlayer ); sendDirectorInit( player );
} }
void Core::InstanceContent::onInitDirector( Entity::PlayerPtr pPlayer ) void Core::InstanceContent::onInitDirector( Entity::Player& player )
{ {
sendDirectorVars( pPlayer ); sendDirectorVars( player );
pPlayer->setDirectorInitialized( true ); player.setDirectorInitialized( true );
} }
void Core::InstanceContent::setVar( uint8_t index, uint8_t value ) void Core::InstanceContent::setVar( uint8_t index, uint8_t value )
@ -210,7 +210,7 @@ void Core::InstanceContent::setVar( uint8_t index, uint8_t value )
for( const auto &playerIt : m_playerMap ) for( const auto &playerIt : m_playerMap )
{ {
sendDirectorVars( playerIt.second ); sendDirectorVars( *playerIt.second );
} }
} }

View file

@ -28,10 +28,10 @@ public:
uint32_t instanceContentId ); uint32_t instanceContentId );
virtual ~InstanceContent(); virtual ~InstanceContent();
void onEnterTerritory( Entity::PlayerPtr pPlayer ) override; void onEnterTerritory( Entity::Player& player ) override;
void onLeaveTerritory( Entity::PlayerPtr pPlayer ) override; void onLeaveTerritory( Entity::Player& player ) override;
void onFinishLoading( Entity::PlayerPtr pPlayer ) override; void onFinishLoading( Entity::Player& player ) override;
void onInitDirector( Entity::PlayerPtr pPlayer ) override; void onInitDirector( Entity::Player& player ) override;
void onUpdate( uint32_t currTime ) override; void onUpdate( uint32_t currTime ) override;
void setVar( uint8_t index, uint8_t value ); void setVar( uint8_t index, uint8_t value );

View file

@ -119,7 +119,7 @@ bool Core::TerritoryMgr::createDefaultTerritories()
"\t" + pPlaceName->name + "\t" + pPlaceName->name +
"\t" + ( isPrivateTerritory( territoryId ) ? "PRIVATE" : "PUBLIC" ) ); "\t" + ( isPrivateTerritory( territoryId ) ? "PRIVATE" : "PUBLIC" ) );
ZonePtr pZone( new Zone( territoryId, guid, territoryInfo->name, pPlaceName->name ) ); auto pZone = make_Zone( territoryId, guid, territoryInfo->name, pPlaceName->name );
pZone->init(); pZone->init();
InstanceIdToZonePtrMap instanceMap; InstanceIdToZonePtrMap instanceMap;
@ -149,7 +149,7 @@ Core::ZonePtr Core::TerritoryMgr::createTerritoryInstance( uint32_t territoryTyp
g_log.debug( "Starting instance for territory: " + std::to_string( territoryTypeId ) + " (" + pPlaceName->name + ")" ); g_log.debug( "Starting instance for territory: " + std::to_string( territoryTypeId ) + " (" + pPlaceName->name + ")" );
ZonePtr pZone = ZonePtr( new Zone( territoryTypeId, getNextInstanceId(), pTeri->name, pPlaceName->name ) ); auto pZone = make_Zone( territoryTypeId, getNextInstanceId(), pTeri->name, pPlaceName->name );
pZone->init(); pZone->init();
m_territoryInstanceMap[pZone->getTerritoryId()][pZone->getGuId()] = pZone; m_territoryInstanceMap[pZone->getTerritoryId()][pZone->getGuId()] = pZone;
@ -175,8 +175,8 @@ Core::ZonePtr Core::TerritoryMgr::createInstanceContent( uint32_t instanceConten
g_log.debug( "Starting instance for InstanceContent id: " + std::to_string( instanceContentId ) + g_log.debug( "Starting instance for InstanceContent id: " + std::to_string( instanceContentId ) +
" (" + pInstanceContent->name + ")" ); " (" + pInstanceContent->name + ")" );
ZonePtr pZone = ZonePtr( new InstanceContent( pInstanceContent, getNextInstanceId(), pTeri->name, auto pZone = make_InstanceContent( pInstanceContent, getNextInstanceId(),
pInstanceContent->name, instanceContentId ) ); pTeri->name, pInstanceContent->name, instanceContentId );
pZone->init(); pZone->init();
m_instanceContentToInstanceMap[instanceContentId][pZone->getGuId()] = pZone; m_instanceContentToInstanceMap[instanceContentId][pZone->getGuId()] = pZone;
@ -233,7 +233,7 @@ void Core::TerritoryMgr::loadTerritoryPositionMap()
float posO = pQR->getFloat( 6 ); float posO = pQR->getFloat( 6 );
uint32_t radius = pQR->getUInt( 7 ); uint32_t radius = pQR->getUInt( 7 );
m_territoryPositionMap[id] = ZonePositionPtr( new ZonePosition( id, targetZoneId, pos, radius, posO ) ); m_territoryPositionMap[id] = make_ZonePosition( id, targetZoneId, pos, radius, posO );
} }
} }

View file

@ -199,8 +199,7 @@ void Zone::loadCellCache()
uint32_t type = pQR->getUInt( 18 ); uint32_t type = pQR->getUInt( 18 );
Common::FFXIVARR_POSITION3 pos{ posX, posY, posZ }; Common::FFXIVARR_POSITION3 pos{ posX, posY, posZ };
Entity::BattleNpcPtr pBNpc( new Entity::BattleNpc( modelId, nameId, pos, auto pBNpc = Entity::make_BattleNpc( modelId, nameId, pos, sizeId, type, level, behaviour, mobType );
sizeId, type, level, behaviour, mobType ) );
pBNpc->setRotation( static_cast< float >( rotation ) ); pBNpc->setRotation( static_cast< float >( rotation ) );
cache.push_back( pBNpc ); cache.push_back( pBNpc );
} }
@ -306,7 +305,7 @@ void Zone::pushActor( Entity::ActorPtr pActor )
m_playerMap[pPlayer->getId()] = pPlayer; m_playerMap[pPlayer->getId()] = pPlayer;
updateCellActivity( cx, cy, 2 ); updateCellActivity( cx, cy, 2 );
} }
else if( pActor->isBNpc() ) else if( pActor->isBattleNpc() )
{ {
Entity::BattleNpcPtr pBNpc = pActor->getAsBattleNpc(); Entity::BattleNpcPtr pBNpc = pActor->getAsBattleNpc();
@ -346,10 +345,10 @@ void Zone::removeActor( Entity::ActorPtr pActor )
} }
m_playerMap.erase( pActor->getId() ); m_playerMap.erase( pActor->getId() );
onLeaveTerritory( pActor->getAsPlayer() ); onLeaveTerritory( *pActor->getAsPlayer() );
} }
else if( pActor->isBNpc() ) else if( pActor->isBattleNpc() )
m_BattleNpcMap.erase( pActor->getId() ); m_BattleNpcMap.erase( pActor->getId() );
// remove from lists of other actors // remove from lists of other actors
@ -361,7 +360,7 @@ void Zone::removeActor( Entity::ActorPtr pActor )
{ {
pCurAct = *iter; pCurAct = *iter;
auto iter2 = iter++; auto iter2 = iter++;
pCurAct->removeInRangeActor( pActor ); pCurAct->removeInRangeActor( *pActor );
} }
} }
pActor->clearInRangeSet(); pActor->clearInRangeSet();
@ -620,18 +619,18 @@ void Zone::updateCellActivity( uint32_t x, uint32_t y, int32_t radius )
} }
} }
void Zone::changeActorPosition( Entity::ActorPtr pActor ) void Zone::changeActorPosition( Entity::Actor& actor )
{ {
if( pActor->getCurrentZone() != shared_from_this() ) if( actor.getCurrentZone() != shared_from_this() )
return; return;
if( pActor->hasInRangeActor() ) if( actor.hasInRangeActor() )
{ {
Entity::ActorPtr pCurAct; Entity::ActorPtr pCurAct;
float fRange = 70.0f; float fRange = 70.0f;
for( auto iter = pActor->m_inRangeActors.begin(); iter != pActor->m_inRangeActors.end();) for( auto iter = actor.m_inRangeActors.begin(); iter != actor.m_inRangeActors.end();)
{ {
pCurAct = *iter; pCurAct = *iter;
auto iter2 = iter++; auto iter2 = iter++;
@ -639,18 +638,18 @@ void Zone::changeActorPosition( Entity::ActorPtr pActor )
float distance = Math::Util::distance( pCurAct->getPos().x, float distance = Math::Util::distance( pCurAct->getPos().x,
pCurAct->getPos().y, pCurAct->getPos().y,
pCurAct->getPos().z, pCurAct->getPos().z,
pActor->getPos().x, actor.getPos().x,
pActor->getPos().y, actor.getPos().y,
pActor->getPos().z ); actor.getPos().z );
if( fRange > 0.0f && distance > fRange ) if( fRange > 0.0f && distance > fRange )
{ {
pCurAct->removeInRangeActor( pActor ); pCurAct->removeInRangeActor( actor );
if( pActor->getCurrentZone() != shared_from_this() ) if( actor.getCurrentZone() != shared_from_this() )
return; return;
pActor->removeInRangeActor( *iter2 ); actor.removeInRangeActor( **iter2 );
// @TODO FIXME! // @TODO FIXME!
// this break is more or less a hack, iteration will break otherwise after removing // this break is more or less a hack, iteration will break otherwise after removing
@ -659,8 +658,8 @@ void Zone::changeActorPosition( Entity::ActorPtr pActor )
} }
} }
uint32_t cellX = getPosX( pActor->getPos().x ); uint32_t cellX = getPosX( actor.getPos().x );
uint32_t cellY = getPosY( pActor->getPos().z ); uint32_t cellY = getPosY( actor.getPos().z );
if( cellX >= _sizeX || cellY >= _sizeY ) if( cellX >= _sizeX || cellY >= _sizeY )
{ {
@ -668,7 +667,7 @@ void Zone::changeActorPosition( Entity::ActorPtr pActor )
} }
Cell* pCell = getCell( cellX, cellY ); Cell* pCell = getCell( cellX, cellY );
Cell* pOldCell = pActor->m_pCell; Cell* pOldCell = actor.m_pCell;
if( !pCell ) if( !pCell )
{ {
pCell = create( cellX, cellY ); pCell = create( cellX, cellY );
@ -680,15 +679,15 @@ void Zone::changeActorPosition( Entity::ActorPtr pActor )
{ {
if( pOldCell ) if( pOldCell )
pOldCell->removeActor( pActor ); pOldCell->removeActor( actor.getAsActor() );
pCell->addActor( pActor ); pCell->addActor( actor.getAsActor() );
pActor->m_pCell = pCell; actor.m_pCell = pCell;
// if player we need to update cell activity // if player we need to update cell activity
// radius = 2 is used in order to update both // radius = 2 is used in order to update both
// old and new cells // old and new cells
if( pActor->isPlayer() ) if( actor.isPlayer() )
{ {
updateCellActivity( cellX, cellY, 2 ); updateCellActivity( cellX, cellY, 2 );
if( pOldCell != nullptr ) if( pOldCell != nullptr )
@ -714,7 +713,7 @@ void Zone::changeActorPosition( Entity::ActorPtr pActor )
{ {
pCell = getCell( posX, posY ); pCell = getCell( posX, posY );
if( pCell ) if( pCell )
updateInRangeSet( pActor, pCell ); updateInRangeSet( actor.getAsActor(), pCell );
} }
} }
} }
@ -785,7 +784,7 @@ void Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell )
} }
} }
else if( ( pActor->isBNpc() || pActor->isEventNpc() ) && pCurAct->isPlayer() && pActor->isAlive() ) else if( ( pActor->isBattleNpc() || pActor->isEventNpc() ) && pCurAct->isPlayer() && pActor->isAlive() )
{ {
auto pPlayer = pCurAct->getAsPlayer(); auto pPlayer = pCurAct->getAsPlayer();
if( pPlayer->isLoadingComplete() ) if( pPlayer->isLoadingComplete() )
@ -804,16 +803,16 @@ void Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell )
} }
} }
void Zone::onEnterTerritory( Entity::PlayerPtr pPlayer ) void Zone::onEnterTerritory( Entity::Player& player )
{ {
g_log.debug( "Zone::onEnterTerritory: Zone#" + std::to_string( getGuId() ) + "|" + std::to_string( getTerritoryId() ) + g_log.debug( "Zone::onEnterTerritory: Zone#" + std::to_string( getGuId() ) + "|" + std::to_string( getTerritoryId() ) +
+ ", Entity#" + std::to_string( pPlayer->getId() ) ); + ", Entity#" + std::to_string( player.getId() ) );
} }
void Zone::onLeaveTerritory( Entity::PlayerPtr pPlayer ) void Zone::onLeaveTerritory( Entity::Player& player )
{ {
g_log.debug( "Zone::onLeaveTerritory: Zone#" + std::to_string( getGuId() ) + "|" + std::to_string( getTerritoryId() ) + g_log.debug( "Zone::onLeaveTerritory: Zone#" + std::to_string( getGuId() ) + "|" + std::to_string( getTerritoryId() ) +
+ ", Entity#" + std::to_string( pPlayer->getId() ) ); + ", Entity#" + std::to_string( player.getId() ) );
} }
void Zone::onUpdate( uint32_t currTime ) void Zone::onUpdate( uint32_t currTime )
@ -821,12 +820,12 @@ void Zone::onUpdate( uint32_t currTime )
} }
void Zone::onFinishLoading( Entity::PlayerPtr pPlayer ) void Zone::onFinishLoading( Entity::Player& player )
{ {
} }
void Zone::onInitDirector( Entity::PlayerPtr pPlayer ) void Zone::onInitDirector( Entity::Player& player )
{ {
} }

View file

@ -74,10 +74,10 @@ public:
virtual void loadCellCache(); virtual void loadCellCache();
virtual uint32_t getTerritoryId() const; virtual uint32_t getTerritoryId() const;
virtual void onEnterTerritory( Entity::PlayerPtr pPlayer ); virtual void onEnterTerritory( Entity::Player& player );
virtual void onFinishLoading( Entity::PlayerPtr pPlayer ); virtual void onFinishLoading( Entity::Player& player );
virtual void onInitDirector( Entity::PlayerPtr pPlayer ); virtual void onInitDirector( Entity::Player& player );
virtual void onLeaveTerritory( Entity::PlayerPtr pPlayer ); virtual void onLeaveTerritory( Entity::Player& player );
virtual void onUpdate( uint32_t currTime ); virtual void onUpdate( uint32_t currTime );
uint8_t getNextWeather(); uint8_t getNextWeather();
@ -86,7 +86,7 @@ public:
void removeActor( Entity::ActorPtr pActor ); void removeActor( Entity::ActorPtr pActor );
void changeActorPosition( Entity::ActorPtr pActor ); void changeActorPosition( Entity::Actor& pActor );
bool isCellActive( uint32_t x, uint32_t y ); bool isCellActive( uint32_t x, uint32_t y );