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

Keep cells active for 20 seconds even after all players left.

Also reset target and autoattack state on player on change zone.
This commit is contained in:
Mordred 2023-03-17 22:01:06 +01:00
parent e72fe535f6
commit c7b50ca1e9
4 changed files with 22 additions and 3 deletions

View file

@ -41,6 +41,10 @@ void MoveTerritoryTask::execute()
if( !pPlayer ) if( !pPlayer )
return; return;
pPlayer->setTargetId( 0 );
pPlayer->setStance( Common::Stance::Passive );
pPlayer->setAutoattack( false );
auto inRangePlayerIds = pPlayer->getInRangePlayerIds( true ); auto inRangePlayerIds = pPlayer->getInRangePlayerIds( true );
auto warpStart = makeActorControlSelf( pPlayer->getId(), WarpStart, m_warpInfo.m_warpType, 1, 0, m_warpInfo.m_targetTerritoryId, 1 ); auto warpStart = makeActorControlSelf( pPlayer->getId(), WarpStart, m_warpInfo.m_warpType, 1, 0, m_warpInfo.m_targetTerritoryId, 1 );

View file

@ -102,3 +102,12 @@ void Sapphire::Cell::unload()
removeActors(); removeActors();
} }
uint32_t Sapphire::Cell::getLastActiveTime() const
{
return m_lastActiveTime;
}
void Sapphire::Cell::setLastActiveTime( uint32_t lastActiveTime )
{
m_lastActiveTime = lastActiveTime;
}

View file

@ -20,6 +20,7 @@ private:
bool m_bActive; bool m_bActive;
uint16_t m_playerCount; uint16_t m_playerCount;
uint32_t m_lastActiveTime;
public: public:
Cell(); Cell();
@ -82,6 +83,9 @@ public:
{ {
return m_posY; return m_posY;
} }
uint32_t getLastActiveTime() const;
void setLastActiveTime( uint32_t lastActiveTime );
}; };
} }

View file

@ -528,6 +528,7 @@ bool Territory::isCellActive( uint32_t x, uint32_t y )
uint32_t posY; uint32_t posY;
CellPtr pCell; CellPtr pCell;
uint32_t time = Common::Util::getTimeSeconds();
for( posX = startX; posX <= endX; posX++ ) for( posX = startX; posX <= endX; posX++ )
{ {
@ -535,7 +536,7 @@ bool Territory::isCellActive( uint32_t x, uint32_t y )
{ {
pCell = getCellPtr( posX, posY ); pCell = getCellPtr( posX, posY );
if( pCell && ( pCell->hasPlayers() || pCell->isForcedActive() ) ) if( pCell && ( pCell->hasPlayers() || pCell->isForcedActive() || ( time - pCell->getLastActiveTime() ) < 20 ) )
return true; return true;
} }
} }
@ -566,13 +567,13 @@ void Territory::updateCellActivity( uint32_t x, uint32_t y, int32_t radius )
{ {
pCell = create( posX, posY ); pCell = create( posX, posY );
pCell->init( posX, posY ); pCell->init( posX, posY );
pCell->setActivity( true ); pCell->setActivity( true );
pCell->setLastActiveTime( Common::Util::getTimeSeconds() );
} }
} }
else else
{ {
pCell->setLastActiveTime( Common::Util::getTimeSeconds() );
//Cell is now active //Cell is now active
if( isCellActive( posX, posY ) && !pCell->isActive() ) if( isCellActive( posX, posY ) && !pCell->isActive() )
{ {
@ -581,6 +582,7 @@ void Territory::updateCellActivity( uint32_t x, uint32_t y, int32_t radius )
else if( !isCellActive( posX, posY ) && pCell->isActive() ) else if( !isCellActive( posX, posY ) && pCell->isActive() )
pCell->setActivity( false ); pCell->setActivity( false );
} }
} }
} }
} }