mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-26 22:37:45 +00:00
Task for dead bnpc removal
This commit is contained in:
parent
e7eb8df433
commit
097a00b913
4 changed files with 70 additions and 15 deletions
|
@ -41,6 +41,8 @@
|
||||||
#include <Manager/TerritoryMgr.h>
|
#include <Manager/TerritoryMgr.h>
|
||||||
#include <Manager/RNGMgr.h>
|
#include <Manager/RNGMgr.h>
|
||||||
#include <Manager/PlayerMgr.h>
|
#include <Manager/PlayerMgr.h>
|
||||||
|
#include <Manager/TaskMgr.h>
|
||||||
|
#include <Task/RemoveBNpcTask.h>
|
||||||
#include <Service.h>
|
#include <Service.h>
|
||||||
|
|
||||||
using namespace Sapphire::Common;
|
using namespace Sapphire::Common;
|
||||||
|
@ -774,6 +776,9 @@ void Sapphire::Entity::BNpc::onDeath()
|
||||||
m_timeOfDeath = Util::getTimeSeconds();
|
m_timeOfDeath = Util::getTimeSeconds();
|
||||||
setOwner( nullptr );
|
setOwner( nullptr );
|
||||||
|
|
||||||
|
auto& taskMgr = Common::Service< World::Manager::TaskMgr >::ref();
|
||||||
|
auto removeTask = std::make_shared< Sapphire::World::RemoveBNpcTask >( 10000, getAsBNpc() );
|
||||||
|
taskMgr.queueTask( removeTask );
|
||||||
|
|
||||||
auto& exdData = Common::Service< Data::ExdData >::ref();
|
auto& exdData = Common::Service< Data::ExdData >::ref();
|
||||||
auto paramGrowthInfo = exdData.getRow< Component::Excel::ParamGrow >( m_level );
|
auto paramGrowthInfo = exdData.getRow< Component::Excel::ParamGrow >( m_level );
|
||||||
|
|
42
src/world/Task/RemoveBNpcTask.cpp
Normal file
42
src/world/Task/RemoveBNpcTask.cpp
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#include "RemoveBNpcTask.h"
|
||||||
|
|
||||||
|
#include <Logging/Logger.h>
|
||||||
|
#include <Actor/BNpc.h>
|
||||||
|
#include <Manager/TerritoryMgr.h>
|
||||||
|
#include <Service.h>
|
||||||
|
|
||||||
|
#include <Territory/Territory.h>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
using namespace Sapphire::World;
|
||||||
|
|
||||||
|
RemoveBNpcTask::RemoveBNpcTask( uint64_t delayTime, Entity::BNpcPtr bnpc ) :
|
||||||
|
Task( delayTime ),
|
||||||
|
m_pBNpc( std::move( bnpc ) )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveBNpcTask::onQueue()
|
||||||
|
{
|
||||||
|
Logger::debug( { __FUNCTION__ } );
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveBNpcTask::execute()
|
||||||
|
{
|
||||||
|
Logger::info( toString() );
|
||||||
|
|
||||||
|
auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref();
|
||||||
|
auto pZone = teriMgr.getTerritoryByGuId( m_pBNpc->getTerritoryId() );
|
||||||
|
|
||||||
|
if( !pZone )
|
||||||
|
return;
|
||||||
|
|
||||||
|
pZone->removeActor( m_pBNpc );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string RemoveBNpcTask::toString()
|
||||||
|
{
|
||||||
|
return fmt::format( "RemoveBNpcTask: BNpc#{}, TerritoryId#{}, ElapsedTimeMs: {}", m_pBNpc->getId(), m_pBNpc->getTerritoryId(), getDelayTimeMs() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
23
src/world/Task/RemoveBNpcTask.h
Normal file
23
src/world/Task/RemoveBNpcTask.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <ForwardsZone.h>
|
||||||
|
#include "Task.h"
|
||||||
|
|
||||||
|
namespace Sapphire::World
|
||||||
|
{
|
||||||
|
|
||||||
|
class RemoveBNpcTask : public Task
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RemoveBNpcTask( uint64_t delayTime, Entity::BNpcPtr bnpc );
|
||||||
|
|
||||||
|
void onQueue() override;
|
||||||
|
void execute() override;
|
||||||
|
std::string toString() override;
|
||||||
|
private:
|
||||||
|
Entity::BNpcPtr m_pBNpc;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -417,21 +417,6 @@ void Sapphire::Territory::updateBNpcs( uint64_t tickCount )
|
||||||
m_lastMobUpdate = tickCount;
|
m_lastMobUpdate = tickCount;
|
||||||
uint64_t currTime = Common::Util::getTimeSeconds();
|
uint64_t currTime = Common::Util::getTimeSeconds();
|
||||||
|
|
||||||
for( const auto& entry : m_bNpcMap )
|
|
||||||
{
|
|
||||||
Entity::BNpcPtr pBNpc = entry.second;
|
|
||||||
|
|
||||||
if( !pBNpc )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if( !pBNpc->isAlive() )
|
|
||||||
if( currTime - pBNpc->getTimeOfDeath() > 10 )
|
|
||||||
{
|
|
||||||
removeActor( pBNpc );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update loop may move actors from cell to cell, breaking iterator validity
|
// Update loop may move actors from cell to cell, breaking iterator validity
|
||||||
std::vector< Entity::BNpcPtr > activeBNpc;
|
std::vector< Entity::BNpcPtr > activeBNpc;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue