mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-28 15:17:46 +00:00
Despawn and respawn dead bnpcs
This commit is contained in:
parent
239a98848e
commit
2973b27e26
4 changed files with 50 additions and 44 deletions
|
@ -6,6 +6,7 @@
|
|||
#include <Network/CommonActorControl.h>
|
||||
#include <Network/PacketWrappers/EffectPacket.h>
|
||||
#include <Network/PacketDef/Zone/ClientZoneDef.h>
|
||||
#include <Logging/Logger.h>
|
||||
|
||||
#include "Forwards.h"
|
||||
#include "Action/Action.h"
|
||||
|
@ -67,6 +68,8 @@ Sapphire::Entity::BNpc::BNpc( uint32_t id, BNpcTemplatePtr pTemplate, float posX
|
|||
|
||||
m_spawnPos = m_pos;
|
||||
|
||||
m_timeOfDeath = 0;
|
||||
|
||||
m_maxHp = maxHp;
|
||||
m_maxMp = 200;
|
||||
m_hp = maxHp;
|
||||
|
@ -135,6 +138,7 @@ void Sapphire::Entity::BNpc::spawn( PlayerPtr pTarget )
|
|||
void Sapphire::Entity::BNpc::despawn( PlayerPtr pTarget )
|
||||
{
|
||||
pTarget->freePlayerSpawnId( getId() );
|
||||
pTarget->queuePacket( makeActorControl143( m_id, DespawnZoneScreenMsg, 0x04, getId(), 0x01 ) );
|
||||
}
|
||||
|
||||
Sapphire::Entity::BNpcState Sapphire::Entity::BNpc::getState() const
|
||||
|
@ -278,7 +282,7 @@ void Sapphire::Entity::BNpc::aggro( Sapphire::Entity::CharaPtr pChara )
|
|||
if( pChara->isPlayer() )
|
||||
{
|
||||
PlayerPtr tmpPlayer = pChara->getAsPlayer();
|
||||
tmpPlayer->queuePacket( makeActorControl142( getId(), ActorControlType::ToggleWeapon, 0, 1, 1 ) );
|
||||
tmpPlayer->queuePacket( makeActorControl142( getId(), ActorControlType::ToggleWeapon, 1, 1, 1 ) );
|
||||
tmpPlayer->onMobAggro( getAsBNpc() );
|
||||
}
|
||||
}
|
||||
|
@ -291,6 +295,7 @@ void Sapphire::Entity::BNpc::deaggro( Sapphire::Entity::CharaPtr pChara )
|
|||
if( pChara->isPlayer() )
|
||||
{
|
||||
PlayerPtr tmpPlayer = pChara->getAsPlayer();
|
||||
tmpPlayer->queuePacket( makeActorControl142( getId(), ActorControlType::ToggleWeapon, 0, 1, 1 ) );
|
||||
tmpPlayer->onMobDeaggro( getAsBNpc() );
|
||||
}
|
||||
}
|
||||
|
@ -301,11 +306,12 @@ void Sapphire::Entity::BNpc::update( int64_t currTime )
|
|||
const uint8_t aggroRange = 8;
|
||||
const uint8_t maxDistanceToOrigin = 30;
|
||||
|
||||
if( m_status == ActorStatus::Dead )
|
||||
return;
|
||||
|
||||
switch( m_state )
|
||||
{
|
||||
case BNpcState::Dead:
|
||||
case BNpcState::JustDied:
|
||||
return;
|
||||
|
||||
case BNpcState::Retreat:
|
||||
{
|
||||
if( moveTo( m_spawnPos ) )
|
||||
|
@ -330,8 +336,6 @@ void Sapphire::Entity::BNpc::update( int64_t currTime )
|
|||
|
||||
if( distance < aggroRange && pClosestChara->isPlayer() )
|
||||
aggro( pClosestChara );
|
||||
//if( distance < aggroRange && getbehavior() == 2 )
|
||||
// aggro( pClosestActor );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -404,5 +408,16 @@ void Sapphire::Entity::BNpc::onDeath()
|
|||
setTargetId( INVALID_GAME_OBJECT_ID );
|
||||
m_currentStance = Stance::Passive;
|
||||
m_state = BNpcState::Dead;
|
||||
m_timeOfDeath = Util::getTimeSeconds();
|
||||
hateListClear();
|
||||
}
|
||||
|
||||
uint32_t Sapphire::Entity::BNpc::getTimeOfDeath() const
|
||||
{
|
||||
return m_timeOfDeath;
|
||||
}
|
||||
|
||||
void Sapphire::Entity::BNpc::setTimeOfDeath( uint32_t timeOfDeath )
|
||||
{
|
||||
m_timeOfDeath = timeOfDeath;
|
||||
}
|
||||
|
|
|
@ -83,6 +83,9 @@ namespace Sapphire::Entity
|
|||
|
||||
void onDeath() override;
|
||||
|
||||
uint32_t getTimeOfDeath() const;
|
||||
void setTimeOfDeath( uint32_t timeOfDeath);
|
||||
|
||||
private:
|
||||
uint32_t m_bNpcBaseId;
|
||||
uint32_t m_bNpcNameId;
|
||||
|
@ -96,6 +99,8 @@ namespace Sapphire::Entity
|
|||
uint32_t m_displayFlags;
|
||||
uint8_t m_level;
|
||||
|
||||
uint32_t m_timeOfDeath;
|
||||
|
||||
Common::FFXIVARR_POSITION3 m_spawnPos;
|
||||
|
||||
BNpcState m_state;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <Network/PacketDef/Zone/ServerZoneDef.h>
|
||||
#include <Network/GamePacketNew.h>
|
||||
#include <Util/Util.h>
|
||||
#include <Common.h>
|
||||
#include "Actor/Player.h"
|
||||
#include "Actor/BNpc.h"
|
||||
#include "Forwards.h"
|
||||
|
@ -57,6 +58,8 @@ namespace Sapphire::Network::Packets::Server
|
|||
|
||||
m_data.classJob = 0;
|
||||
|
||||
m_data.targetId = Common::INVALID_GAME_OBJECT_ID;
|
||||
|
||||
//m_data.u23 = 0x04;
|
||||
//m_data.u24 = 256;
|
||||
m_data.state = static_cast< uint8_t >( bnpc.getStatus() );
|
||||
|
|
|
@ -381,31 +381,12 @@ bool Sapphire::Zone::checkWeather()
|
|||
|
||||
void Sapphire::Zone::updateBNpcs( int64_t tickCount )
|
||||
{
|
||||
if( ( tickCount - m_lastMobUpdate ) > 250 )
|
||||
{
|
||||
if( ( tickCount - m_lastMobUpdate ) <= 250 )
|
||||
return;
|
||||
|
||||
m_lastMobUpdate = tickCount;
|
||||
uint32_t currTime = Sapphire::Util::getTimeSeconds();
|
||||
|
||||
/*for( auto it3 = m_BattleNpcDeadMap.begin(); it3 != m_BattleNpcDeadMap.end(); ++it3 )
|
||||
{
|
||||
|
||||
Entity::BattleNpcPtr pBNpc = *it3;
|
||||
|
||||
if( ( currTime - pBNpc->getTimeOfDeath() ) > 60 )
|
||||
{
|
||||
|
||||
pBNpc->resetHp();
|
||||
pBNpc->resetMp();
|
||||
pBNpc->resetPos();
|
||||
pushActor( pBNpc );
|
||||
|
||||
m_BattleNpcDeadMap.erase( it3 );
|
||||
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
for( auto entry : m_bNpcMap )
|
||||
{
|
||||
Entity::BNpcPtr pBNpc = entry.second;
|
||||
|
@ -413,16 +394,13 @@ void Sapphire::Zone::updateBNpcs( int64_t tickCount )
|
|||
if( !pBNpc )
|
||||
continue;
|
||||
|
||||
//if( !pBNpc->isAlive() && currTime - pBNpc->getTimeOfDeath() > ( 10 ) )
|
||||
//{
|
||||
// removeActor( pBNpc );
|
||||
// m_BattleNpcDeadMap.insert( pBNpc );
|
||||
// break;
|
||||
//}
|
||||
if( !pBNpc->isAlive() && currTime - pBNpc->getTimeOfDeath() > 10 )
|
||||
{
|
||||
removeActor( pBNpc );
|
||||
break;
|
||||
}
|
||||
|
||||
pBNpc->update( tickCount );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -844,6 +822,11 @@ void Sapphire::Zone::updateSpawnPoints()
|
|||
|
||||
pushActor( pBNpc );
|
||||
}
|
||||
else if( point->getLinkedBNpc() && !point->getLinkedBNpc()->isAlive() )
|
||||
{
|
||||
point->setTimeOfDeath( Util::getTimeSeconds() );
|
||||
point->setLinkedBNpc( nullptr );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue