From c7b50ca1e9172708d8658f3239d06c5efcbc404d Mon Sep 17 00:00:00 2001 From: Mordred Date: Fri, 17 Mar 2023 22:01:06 +0100 Subject: [PATCH] Keep cells active for 20 seconds even after all players left. Also reset target and autoattack state on player on change zone. --- src/world/Task/MoveTerritoryTask.cpp | 4 ++++ src/world/Territory/Cell.cpp | 9 +++++++++ src/world/Territory/Cell.h | 4 ++++ src/world/Territory/Territory.cpp | 8 +++++--- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/world/Task/MoveTerritoryTask.cpp b/src/world/Task/MoveTerritoryTask.cpp index 30194d9d..b7d9c061 100644 --- a/src/world/Task/MoveTerritoryTask.cpp +++ b/src/world/Task/MoveTerritoryTask.cpp @@ -41,6 +41,10 @@ void MoveTerritoryTask::execute() if( !pPlayer ) return; + pPlayer->setTargetId( 0 ); + pPlayer->setStance( Common::Stance::Passive ); + pPlayer->setAutoattack( false ); + auto inRangePlayerIds = pPlayer->getInRangePlayerIds( true ); auto warpStart = makeActorControlSelf( pPlayer->getId(), WarpStart, m_warpInfo.m_warpType, 1, 0, m_warpInfo.m_targetTerritoryId, 1 ); diff --git a/src/world/Territory/Cell.cpp b/src/world/Territory/Cell.cpp index 2eebc7a7..42bda667 100644 --- a/src/world/Territory/Cell.cpp +++ b/src/world/Territory/Cell.cpp @@ -102,3 +102,12 @@ void Sapphire::Cell::unload() removeActors(); } +uint32_t Sapphire::Cell::getLastActiveTime() const +{ + return m_lastActiveTime; +} + +void Sapphire::Cell::setLastActiveTime( uint32_t lastActiveTime ) +{ + m_lastActiveTime = lastActiveTime; +} \ No newline at end of file diff --git a/src/world/Territory/Cell.h b/src/world/Territory/Cell.h index 07c0cfc3..4aca5791 100644 --- a/src/world/Territory/Cell.h +++ b/src/world/Territory/Cell.h @@ -20,6 +20,7 @@ private: bool m_bActive; uint16_t m_playerCount; + uint32_t m_lastActiveTime; public: Cell(); @@ -82,6 +83,9 @@ public: { return m_posY; } + + uint32_t getLastActiveTime() const; + void setLastActiveTime( uint32_t lastActiveTime ); }; } diff --git a/src/world/Territory/Territory.cpp b/src/world/Territory/Territory.cpp index 375c7071..de4a5c4f 100644 --- a/src/world/Territory/Territory.cpp +++ b/src/world/Territory/Territory.cpp @@ -528,6 +528,7 @@ bool Territory::isCellActive( uint32_t x, uint32_t y ) uint32_t posY; CellPtr pCell; + uint32_t time = Common::Util::getTimeSeconds(); for( posX = startX; posX <= endX; posX++ ) { @@ -535,7 +536,7 @@ bool Territory::isCellActive( uint32_t x, uint32_t y ) { pCell = getCellPtr( posX, posY ); - if( pCell && ( pCell->hasPlayers() || pCell->isForcedActive() ) ) + if( pCell && ( pCell->hasPlayers() || pCell->isForcedActive() || ( time - pCell->getLastActiveTime() ) < 20 ) ) return true; } } @@ -566,13 +567,13 @@ void Territory::updateCellActivity( uint32_t x, uint32_t y, int32_t radius ) { pCell = create( posX, posY ); pCell->init( posX, posY ); - pCell->setActivity( true ); - + pCell->setLastActiveTime( Common::Util::getTimeSeconds() ); } } else { + pCell->setLastActiveTime( Common::Util::getTimeSeconds() ); //Cell is now active 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() ) pCell->setActivity( false ); } + } } }