1
Fork 0
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:
Mordred 2019-01-23 22:37:55 +01:00
parent 239a98848e
commit 2973b27e26
4 changed files with 50 additions and 44 deletions

View file

@ -6,6 +6,7 @@
#include <Network/CommonActorControl.h> #include <Network/CommonActorControl.h>
#include <Network/PacketWrappers/EffectPacket.h> #include <Network/PacketWrappers/EffectPacket.h>
#include <Network/PacketDef/Zone/ClientZoneDef.h> #include <Network/PacketDef/Zone/ClientZoneDef.h>
#include <Logging/Logger.h>
#include "Forwards.h" #include "Forwards.h"
#include "Action/Action.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_spawnPos = m_pos;
m_timeOfDeath = 0;
m_maxHp = maxHp; m_maxHp = maxHp;
m_maxMp = 200; m_maxMp = 200;
m_hp = maxHp; m_hp = maxHp;
@ -135,6 +138,7 @@ void Sapphire::Entity::BNpc::spawn( PlayerPtr pTarget )
void Sapphire::Entity::BNpc::despawn( PlayerPtr pTarget ) void Sapphire::Entity::BNpc::despawn( PlayerPtr pTarget )
{ {
pTarget->freePlayerSpawnId( getId() ); pTarget->freePlayerSpawnId( getId() );
pTarget->queuePacket( makeActorControl143( m_id, DespawnZoneScreenMsg, 0x04, getId(), 0x01 ) );
} }
Sapphire::Entity::BNpcState Sapphire::Entity::BNpc::getState() const Sapphire::Entity::BNpcState Sapphire::Entity::BNpc::getState() const
@ -278,7 +282,7 @@ void Sapphire::Entity::BNpc::aggro( Sapphire::Entity::CharaPtr pChara )
if( pChara->isPlayer() ) if( pChara->isPlayer() )
{ {
PlayerPtr tmpPlayer = pChara->getAsPlayer(); 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() ); tmpPlayer->onMobAggro( getAsBNpc() );
} }
} }
@ -291,6 +295,7 @@ void Sapphire::Entity::BNpc::deaggro( Sapphire::Entity::CharaPtr pChara )
if( pChara->isPlayer() ) if( pChara->isPlayer() )
{ {
PlayerPtr tmpPlayer = pChara->getAsPlayer(); PlayerPtr tmpPlayer = pChara->getAsPlayer();
tmpPlayer->queuePacket( makeActorControl142( getId(), ActorControlType::ToggleWeapon, 0, 1, 1 ) );
tmpPlayer->onMobDeaggro( getAsBNpc() ); tmpPlayer->onMobDeaggro( getAsBNpc() );
} }
} }
@ -301,11 +306,12 @@ void Sapphire::Entity::BNpc::update( int64_t currTime )
const uint8_t aggroRange = 8; const uint8_t aggroRange = 8;
const uint8_t maxDistanceToOrigin = 30; const uint8_t maxDistanceToOrigin = 30;
if( m_status == ActorStatus::Dead )
return;
switch( m_state ) switch( m_state )
{ {
case BNpcState::Dead:
case BNpcState::JustDied:
return;
case BNpcState::Retreat: case BNpcState::Retreat:
{ {
if( moveTo( m_spawnPos ) ) if( moveTo( m_spawnPos ) )
@ -330,8 +336,6 @@ void Sapphire::Entity::BNpc::update( int64_t currTime )
if( distance < aggroRange && pClosestChara->isPlayer() ) if( distance < aggroRange && pClosestChara->isPlayer() )
aggro( pClosestChara ); aggro( pClosestChara );
//if( distance < aggroRange && getbehavior() == 2 )
// aggro( pClosestActor );
} }
} }
@ -404,5 +408,16 @@ void Sapphire::Entity::BNpc::onDeath()
setTargetId( INVALID_GAME_OBJECT_ID ); setTargetId( INVALID_GAME_OBJECT_ID );
m_currentStance = Stance::Passive; m_currentStance = Stance::Passive;
m_state = BNpcState::Dead; m_state = BNpcState::Dead;
m_timeOfDeath = Util::getTimeSeconds();
hateListClear(); hateListClear();
} }
uint32_t Sapphire::Entity::BNpc::getTimeOfDeath() const
{
return m_timeOfDeath;
}
void Sapphire::Entity::BNpc::setTimeOfDeath( uint32_t timeOfDeath )
{
m_timeOfDeath = timeOfDeath;
}

View file

@ -83,6 +83,9 @@ namespace Sapphire::Entity
void onDeath() override; void onDeath() override;
uint32_t getTimeOfDeath() const;
void setTimeOfDeath( uint32_t timeOfDeath);
private: private:
uint32_t m_bNpcBaseId; uint32_t m_bNpcBaseId;
uint32_t m_bNpcNameId; uint32_t m_bNpcNameId;
@ -96,6 +99,8 @@ namespace Sapphire::Entity
uint32_t m_displayFlags; uint32_t m_displayFlags;
uint8_t m_level; uint8_t m_level;
uint32_t m_timeOfDeath;
Common::FFXIVARR_POSITION3 m_spawnPos; Common::FFXIVARR_POSITION3 m_spawnPos;
BNpcState m_state; BNpcState m_state;

View file

@ -4,6 +4,7 @@
#include <Network/PacketDef/Zone/ServerZoneDef.h> #include <Network/PacketDef/Zone/ServerZoneDef.h>
#include <Network/GamePacketNew.h> #include <Network/GamePacketNew.h>
#include <Util/Util.h> #include <Util/Util.h>
#include <Common.h>
#include "Actor/Player.h" #include "Actor/Player.h"
#include "Actor/BNpc.h" #include "Actor/BNpc.h"
#include "Forwards.h" #include "Forwards.h"
@ -57,6 +58,8 @@ namespace Sapphire::Network::Packets::Server
m_data.classJob = 0; m_data.classJob = 0;
m_data.targetId = Common::INVALID_GAME_OBJECT_ID;
//m_data.u23 = 0x04; //m_data.u23 = 0x04;
//m_data.u24 = 256; //m_data.u24 = 256;
m_data.state = static_cast< uint8_t >( bnpc.getStatus() ); m_data.state = static_cast< uint8_t >( bnpc.getStatus() );

View file

@ -381,49 +381,27 @@ bool Sapphire::Zone::checkWeather()
void Sapphire::Zone::updateBNpcs( int64_t tickCount ) 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 ) m_lastMobUpdate = tickCount;
{ uint32_t currTime = Sapphire::Util::getTimeSeconds();
Entity::BattleNpcPtr pBNpc = *it3; for( auto entry : m_bNpcMap )
{
Entity::BNpcPtr pBNpc = entry.second;
if( ( currTime - pBNpc->getTimeOfDeath() ) > 60 ) if( !pBNpc )
{ continue;
pBNpc->resetHp(); if( !pBNpc->isAlive() && currTime - pBNpc->getTimeOfDeath() > 10 )
pBNpc->resetMp(); {
pBNpc->resetPos(); removeActor( pBNpc );
pushActor( pBNpc ); break;
}
m_BattleNpcDeadMap.erase( it3 ); pBNpc->update( tickCount );
}
break;
}
}*/
for( auto entry : m_bNpcMap )
{
Entity::BNpcPtr pBNpc = entry.second;
if( !pBNpc )
continue;
//if( !pBNpc->isAlive() && currTime - pBNpc->getTimeOfDeath() > ( 10 ) )
//{
// removeActor( pBNpc );
// m_BattleNpcDeadMap.insert( pBNpc );
// break;
//}
pBNpc->update( tickCount );
}
}
} }
@ -844,6 +822,11 @@ void Sapphire::Zone::updateSpawnPoints()
pushActor( pBNpc ); pushActor( pBNpc );
} }
else if( point->getLinkedBNpc() && !point->getLinkedBNpc()->isAlive() )
{
point->setTimeOfDeath( Util::getTimeSeconds() );
point->setLinkedBNpc( nullptr );
}
} }
} }