1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-25 14:07:46 +00:00

Added events to zone for inheritance handling

This commit is contained in:
Mordred 2018-02-04 23:35:16 +01:00
parent af90b006ac
commit 6ed0baf91f
9 changed files with 81 additions and 22 deletions

View file

@ -32,7 +32,7 @@ bool ActionCollision::isActorApplicable( ActorPtr actorPtr, TargetFilter targetF
case TargetFilter::Allies:
{
// todo: implement ally NPCs
actorApplicable = !actorPtr->isMob();
actorApplicable = !actorPtr->isBNpc();
break;
}
case TargetFilter::Party:
@ -43,7 +43,7 @@ bool ActionCollision::isActorApplicable( ActorPtr actorPtr, TargetFilter targetF
}
case TargetFilter::Enemies:
{
actorApplicable = actorPtr->isMob();
actorApplicable = actorPtr->isBNpc();
break;
}
}

View file

@ -68,7 +68,7 @@ bool Core::Entity::Actor::isPlayer() const
}
/*! \return true if the actor is of type mob */
bool Core::Entity::Actor::isMob() const
bool Core::Entity::Actor::isBNpc() const
{
return m_objKind == ObjKind::BattleNpc;
}
@ -416,18 +416,24 @@ void Core::Entity::Actor::sendStatusUpdate( bool toSelf )
/*! \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() );
}

View file

@ -215,7 +215,7 @@ public:
bool isPlayer() const;
bool isMob() const;
bool isBNpc() const;
bool isEventNpc() const;

View file

@ -90,7 +90,6 @@ Core::Entity::Player::Player() :
Core::Entity::Player::~Player()
{
g_log.debug( "PlayerObj destroyed" );
}
// TODO: add a proper calculation based on race / job / level / gear

View file

@ -1,5 +1,13 @@
#include "InstanceContent.h"
#include <common/Logging/Logger.h>
#include <common/Util/Util.h>
#include <common/Util/UtilMath.h>
#include "Actor/Player.h"
extern Core::Logger g_log;
Core::InstanceContent::InstanceContent( boost::shared_ptr< Core::Data::InstanceContent > pInstanceContent,
uint32_t guId,
const std::string& internalName,
@ -23,7 +31,26 @@ uint32_t Core::InstanceContent::getInstanceContentId() const
return m_instanceContentId;
}
boost::shared_ptr< Core::Data::InstanceContent > Core::InstanceContent::getInstanceContentInfo() const
Core::Data::ExdDataGenerated::InstanceContentPtr Core::InstanceContent::getInstanceContentInfo() const
{
return m_instanceContentInfo;
}
void Core::InstanceContent::onEnterTerritory( Entity::PlayerPtr pPlayer )
{
g_log.debug( "InstanceContent::onEnterTerritory: Zone#" + std::to_string( getGuId() ) + "|"
+ std::to_string( getInstanceContentId() ) +
+ ", Entity#" + std::to_string( pPlayer->getId() ) );
}
void Core::InstanceContent::onLeaveTerritory( Entity::PlayerPtr pPlayer )
{
g_log.debug( "InstanceContent::onLeaveTerritory: Zone#" + std::to_string( getGuId() ) + "|"
+ std::to_string( getInstanceContentId() ) +
+ ", Entity#" + std::to_string( pPlayer->getId() ) );
}
void Core::InstanceContent::onUpdate( uint32_t currTime )
{
}

View file

@ -25,6 +25,10 @@ public:
uint32_t instanceContentId );
virtual ~InstanceContent();
void onEnterTerritory( Entity::PlayerPtr pPlayer ) override;
void onLeaveTerritory( Entity::PlayerPtr pPlayer ) override;
void onUpdate( uint32_t currTime ) override;
Core::Data::ExdDataGenerated::InstanceContentPtr getInstanceContentInfo() const;
uint32_t getInstanceContentId() const;

View file

@ -275,12 +275,12 @@ void Core::TerritoryMgr::updateTerritoryInstances( uint32_t currentTime )
{
for( auto& zone : m_zoneSet )
{
zone->runZoneLogic( currentTime );
zone->update( currentTime );
}
for( auto& zone : m_instanceZoneSet )
{
zone->runZoneLogic( currentTime );
zone->update( currentTime );
}
}

View file

@ -304,7 +304,6 @@ void Zone::pushActor( Entity::ActorPtr pActor )
if( pActor->isPlayer() )
{
g_log.debug( "[Zone:" + m_internalName + "] Adding player [" + std::to_string( pActor->getId() ) + "]" );
auto pPlayer = pActor->getAsPlayer();
auto pSession = g_serverZone.getSession( pPlayer->getId() );
@ -313,8 +312,10 @@ void Zone::pushActor( Entity::ActorPtr pActor )
m_playerMap[pPlayer->getId()] = pPlayer;
updateCellActivity( cx, cy, 2 );
onEnterTerritory( pPlayer );
}
else if( pActor->isMob() )
else if( pActor->isBNpc() )
{
Entity::BattleNpcPtr pBNpc = pActor->getAsBattleNpc();
@ -329,6 +330,7 @@ void Zone::pushActor( Entity::ActorPtr pActor )
pENpc->setPosition( pENpc->getPos() );
}
}
void Zone::removeActor( Entity::ActorPtr pActor )
@ -343,7 +345,6 @@ void Zone::removeActor( Entity::ActorPtr pActor )
if( pActor->isPlayer() )
{
g_log.debug( "[Zone:" + m_internalName + "] Removing player [" + std::to_string( pActor->getId() ) + "]" );
// If it's a player and he's inside boundaries - update his nearby cells
if( pActor->getPos().x <= _maxX && pActor->getPos().x >= _minX &&
pActor->getPos().z <= _maxY && pActor->getPos().z >= _minY )
@ -354,8 +355,10 @@ void Zone::removeActor( Entity::ActorPtr pActor )
}
m_playerMap.erase( pActor->getId() );
onLeaveTerritory( pActor->getAsPlayer() );
}
else if( pActor->isMob() )
else if( pActor->isBNpc() )
m_BattleNpcMap.erase( pActor->getId() );
// remove from lists of other actors
@ -502,7 +505,7 @@ void Zone::updateBnpcs( int64_t tickCount )
}
}
bool Zone::runZoneLogic( uint32_t currTime )
bool Zone::update( uint32_t currTime )
{
int64_t tickCount = Util::getTimeMs();
@ -523,12 +526,11 @@ bool Zone::runZoneLogic( uint32_t currTime )
}
// this session is not linked to this area anymore, remove it from zone session list
if( ( !pSession->getPlayer()->getCurrentZone() ) || ( pSession->getPlayer()->getCurrentZone() != shared_from_this() ) )
if( ( !pSession->getPlayer()->getCurrentZone() )
|| ( pSession->getPlayer()->getCurrentZone() != shared_from_this() ) )
{
g_log.debug( "[Zone:" + m_internalName + "] removing session " + std::to_string( pSession->getId() ) );
if( pSession->getPlayer()->getCell() )
removeActor( pSession->getPlayer() );
// if( pSession->getPlayer()->getCell() )
// removeActor( pSession->getPlayer() );
it = m_sessionSet.erase( it );
continue;
@ -550,6 +552,8 @@ bool Zone::runZoneLogic( uint32_t currTime )
updateBnpcs( tickCount );
onUpdate( currTime );
return true;
}
@ -792,7 +796,7 @@ void Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell )
}
}
else if( ( pActor->isMob() || pActor->isEventNpc() ) && pCurAct->isPlayer() && pActor->isAlive() )
else if( ( pActor->isBNpc() || pActor->isEventNpc() ) && pCurAct->isPlayer() && pActor->isAlive() )
{
auto pPlayer = pCurAct->getAsPlayer();
if( pPlayer->isLoadingComplete() )
@ -811,4 +815,21 @@ void Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell )
}
}
void Zone::onEnterTerritory( Entity::PlayerPtr pPlayer )
{
g_log.debug( "Zone::onEnterTerritory: Zone#" + std::to_string( getGuId() ) + "|" + std::to_string( getTerritoryId() ) +
+ ", Entity#" + std::to_string( pPlayer->getId() ) );
}
void Zone::onLeaveTerritory( Entity::PlayerPtr pPlayer )
{
g_log.debug( "Zone::onLeaveTerritory: Zone#" + std::to_string( getGuId() ) + "|" + std::to_string( getTerritoryId() ) +
+ ", Entity#" + std::to_string( pPlayer->getId() ) );
}
void Zone::onUpdate( uint32_t currTime )
{
}
}

View file

@ -79,6 +79,10 @@ public:
CellCache* getCellCacheAndCreate( uint32_t cellx, uint32_t celly );
virtual void loadCellCache();
virtual uint32_t getTerritoryId();
virtual void onEnterTerritory( Entity::PlayerPtr pPlayer );
virtual void onLeaveTerritory( Entity::PlayerPtr pPlayer );
virtual void onUpdate( uint32_t currTime );
uint8_t getNextWeather();
@ -96,8 +100,6 @@ public:
void queueOutPacketForRange( Entity::Player& sourcePlayer, uint32_t range, Network::Packets::GamePacketPtr pPacketEntry );
virtual uint32_t getTerritoryId();
Common::RegionType getType() const;
uint16_t getGuId() const;
@ -112,7 +114,7 @@ public:
bool checkWeather();
void updateBnpcs( int64_t tickCount );
bool runZoneLogic( uint32_t currTime );
bool update( uint32_t currTime );
};