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

Added type checks for possibly object kinds

This commit is contained in:
Mordred 2018-02-22 17:06:30 +01:00
parent 6e5737f401
commit cb9a93db6c
2 changed files with 63 additions and 3 deletions

View file

@ -56,14 +56,57 @@ void Core::Entity::Actor::setRot( float rot )
m_rot = rot;
}
bool Core::Entity::Actor::isChara() const
{
return isPlayer() || isBattleNpc() || isEventNpc() || isRetainer() || isCompanion();
}
bool Core::Entity::Actor::isPlayer() const
{
return m_objKind == ObjKind::Player;
}
bool Core::Entity::Actor::isEventNpc() const
{
return m_objKind == ObjKind::EventNpc;
}
bool Core::Entity::Actor::isBattleNpc() const
{
return m_objKind == ObjKind::BattleNpc;
}
bool Core::Entity::Actor::isRetainer() const
{
return m_objKind == ObjKind::Retainer;
}
bool Core::Entity::Actor::isCompanion() const
{
return m_objKind == ObjKind::Companion;
}
bool Core::Entity::Actor::isEventObj() const
{
return m_objKind == ObjKind::EventObj;
}
bool Core::Entity::Actor::isHousingEventObj() const
{
return m_objKind == ObjKind::Housing;
}
bool Core::Entity::Actor::isAetheryte() const
{
return m_objKind == ObjKind::Aetheryte;
}
/*! \return pointer to this instance as ActorPtr */
Core::Entity::CharaPtr Core::Entity::Actor::getAsChara()
{
if( !isChara() )
return nullptr;
return boost::dynamic_pointer_cast< Entity::Chara, Entity::Actor >( shared_from_this() );
}
@ -75,6 +118,14 @@ Core::Entity::PlayerPtr Core::Entity::Actor::getAsPlayer()
return boost::dynamic_pointer_cast< Entity::Player, Entity::Actor >( shared_from_this() );
}
/*! \return pointer to this instance as PlayerPtr */
Core::Entity::EventObjectPtr Core::Entity::Actor::getAsEventObj()
{
if( !isEventObj() )
return nullptr;
return boost::dynamic_pointer_cast< Entity::EventObject, Entity::Actor >( shared_from_this() );
}
/*!
Add a given actor to the fitting in range set according to type
but also to the global actor map
@ -155,6 +206,7 @@ bool Core::Entity::Actor::isInRangeSet( ActorPtr pActor ) const
return !( m_inRangeActor.find( pActor ) == m_inRangeActor.end() );
}
/*! \return ActorPtr of the closest actor in range, if none, nullptr */
Core::Entity::ActorPtr Core::Entity::Actor::getClosestActor()
{
@ -186,7 +238,6 @@ Core::Entity::ActorPtr Core::Entity::Actor::getClosestActor()
return tmpActor;
}
/*! Clear the whole in range set, this does no cleanup */
void Core::Entity::Actor::clearInRangeSet()
{
@ -236,4 +287,4 @@ std::set< Core::Entity::ActorPtr > Core::Entity::Actor::getInRangeActors( bool i
tempInRange.insert( shared_from_this() );
return tempInRange;
}
}

View file

@ -31,7 +31,7 @@ namespace Entity {
GatheringPoint = 0x06,
EventObj = 0x07,
Mount = 0x08,
Companion = 0x09,
Companion = 0x09, // this probably actually means minion
Retainer = 0x0A,
Area = 0x0B,
Housing = 0x0C,
@ -71,7 +71,15 @@ namespace Entity {
float getRot() const;
void setRot( float rot );
bool isChara() const;
bool isPlayer() const;
bool isEventNpc() const;
bool isBattleNpc() const;
bool isRetainer() const;
bool isCompanion() const;
bool isEventObj() const;
bool isHousingEventObj() const;
bool isAetheryte() const;
///// IN RANGE LOGIC ///////////////////////////////
virtual void onRemoveInRangeActor( Actor& pActor ) {}
@ -103,6 +111,7 @@ namespace Entity {
CharaPtr getAsChara();
PlayerPtr getAsPlayer();
EventObjectPtr getAsEventObj();
};
}