Skip to content

Commit

Permalink
Fixed spawning issues and navi problems in encounters
Browse files Browse the repository at this point in the history
  • Loading branch information
SapphireMordred committed Jan 11, 2025
1 parent 25ab437 commit c0aed54
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 87 deletions.
1 change: 1 addition & 0 deletions src/common/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,7 @@ namespace Sapphire::Common
CircularAOE = 2,
RectangularAOE = 3,
ConeAOE = 4,
CircularAOESelf = 5,
CircularAoEPlaced = 7
};

Expand Down
4 changes: 2 additions & 2 deletions src/scripts/instances/trials/TheBowlofEmbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class TheBowlofEmbers : public Sapphire::ScriptAPI::InstanceContentScript

void onInit( InstanceContent& instance ) override
{
instance.addEObj( "Entrance", 2000182, 4177874, 4177871, 5, { -16.000000f, 0.000000f, 0.000000f }, 1.000000f, 0.000000f, 0);
instance.addEObj( "Entrance", 2000182, 4177874, 4177871, 5, { -16.000000f, 0.000000f, 0.000000f }, 1.000000f, 0.000000f, 0);
// States -> vf_lock_on (id: 11) vf_lock_of (id: 12)
instance.addEObj( "Exit", 2000139, 0, 4177870, 4, { 16.000000f, 0.000000f, 0.000000f }, 1.000000f, 0.000000f, 0);
// instance.addEObj( "Exit", 2000139, 0, 4177870, 4, { 16.000000f, 0.000000f, 0.000000f }, 1.000000f, 0.000000f, 0);

}

Expand Down
12 changes: 7 additions & 5 deletions src/world/AI/Fsm/StateCombat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ void AI::Fsm::StateCombat::onUpdate( Entity::BNpc& bnpc, uint64_t tickCount )
if( !pHatedActor )
return;

pNaviProvider->updateAgentParameters( bnpc );
if( pNaviProvider && bnpc.pathingActive() )
pNaviProvider->updateAgentParameters( bnpc );

auto distanceOrig = Common::Util::distance( bnpc.getPos(), bnpc.getSpawnPos() );

Expand All @@ -42,7 +43,9 @@ void AI::Fsm::StateCombat::onUpdate( Entity::BNpc& bnpc, uint64_t tickCount )

}

if( !hasQueuedAction && !bnpc.hasFlag( Entity::Immobile ) && distance > ( bnpc.getNaviTargetReachedDistance() + pHatedActor->getRadius() ) )
if( bnpc.pathingActive() && !hasQueuedAction &&
!bnpc.hasFlag( Entity::Immobile ) &&
distance > ( bnpc.getNaviTargetReachedDistance() + pHatedActor->getRadius() ) )
{

if( pNaviProvider )
Expand All @@ -53,14 +56,13 @@ void AI::Fsm::StateCombat::onUpdate( Entity::BNpc& bnpc, uint64_t tickCount )

pNaviProvider->syncPosToChara( bnpc );

if( !hasQueuedAction && distance < ( bnpc.getNaviTargetReachedDistance() + pHatedActor->getRadius() ) )
if( !hasQueuedAction && (distance < ( bnpc.getNaviTargetReachedDistance() + pHatedActor->getRadius() ) || !bnpc.pathingActive() ) )
{
// todo: dont turn if facing
if( !bnpc.hasFlag( Entity::TurningDisabled ) )
bnpc.face( pHatedActor->getPos() );

if( !hasQueuedAction )
bnpc.processGambits( tickCount );
bnpc.processGambits( tickCount );

// in combat range. ATTACK!
if( !bnpc.hasFlag( Entity::BNpcFlag::AutoAttackDisabled ) )
Expand Down
4 changes: 2 additions & 2 deletions src/world/AI/Fsm/StateRoam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void AI::Fsm::StateRoam::onUpdate( Entity::BNpc& bnpc, uint64_t tickCount )
auto pZone = teriMgr.getTerritoryByGuId( bnpc.getTerritoryId() );
auto pNaviProvider = pZone->getNaviProvider();

if( bnpc.hasFlag( Entity::NoRoam ) )
if( bnpc.hasFlag( Entity::NoRoam ) || bnpc.hasFlag( Entity::Immobile ) || !bnpc.pathingActive() )
{
bnpc.setRoamTargetReached( true );
return;
Expand All @@ -38,7 +38,7 @@ void AI::Fsm::StateRoam::onEnter( Entity::BNpc& bnpc )
auto pZone = teriMgr.getTerritoryByGuId( bnpc.getTerritoryId() );
auto pNaviProvider = pZone->getNaviProvider();

if( !pNaviProvider )
if( !pNaviProvider || bnpc.hasFlag( Entity::NoRoam ) || bnpc.hasFlag( Entity::Immobile ) )
{
bnpc.setRoamTargetReached( true );
return;
Expand Down
25 changes: 25 additions & 0 deletions src/world/Actor/BNpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ BNpc::BNpc( uint32_t id, std::shared_ptr< Common::BNPCInstanceObject > pInfo, co
m_pos.x = pInfo->x;
m_pos.y = pInfo->y;
m_pos.z = pInfo->z;
m_lastPos = m_pos;
m_rot = pInfo->rotation;
m_level = pInfo->Level <= 0 ? 1 : pInfo->Level;
m_invincibilityType = InvincibilityNone;
Expand Down Expand Up @@ -203,6 +204,7 @@ BNpc::BNpc( uint32_t id, std::shared_ptr< Common::BNPCInstanceObject > pInfo, co
m_pos.x = pInfo->x;
m_pos.y = pInfo->y;
m_pos.z = pInfo->z;
m_lastPos = m_pos;
m_rot = pInfo->rotation;
m_level = pInfo->Level <= 0 ? 1 : pInfo->Level;
m_invincibilityType = InvincibilityNone;
Expand Down Expand Up @@ -832,7 +834,30 @@ bool BNpc::hasFlag( uint32_t flag ) const

void BNpc::setFlag( uint32_t flag )
{
uint32_t oldFlags = m_flags;
m_flags |= flag;

auto& teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref();
auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() );


if( pZone && ( oldFlags & Entity::Immobile ) != Entity::Immobile &&
( m_flags & Entity::Immobile ) == Entity::Immobile )
{
auto pNaviProvider = pZone->getNaviProvider();
pNaviProvider->removeAgent( *this );
setAgentId( 0 );
setPathingActive( false );
}
else if( pZone && ( oldFlags & Entity::Immobile ) == Entity::Immobile &&
( m_flags & Entity::Immobile ) != Entity::Immobile )
{
auto pNaviProvider = pZone->getNaviProvider();
pNaviProvider->removeAgent( *this );
auto agentId = pNaviProvider->addAgent( *this );
setAgentId( agentId );
setPathingActive( true );
}
}

void BNpc::removeFlag( uint32_t flag )
Expand Down
2 changes: 1 addition & 1 deletion src/world/Actor/Chara.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace Sapphire::Entity
std::map< uint8_t, StatusEffect::StatusEffectPtr > m_statusEffectMap;

/*! Detour Crowd AgentId */
uint32_t m_agentId;
uint32_t m_agentId{0};

/*! Detour Crowd actor scale */
float m_radius;
Expand Down
10 changes: 10 additions & 0 deletions src/world/Actor/Npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,13 @@ Npc::Npc( ObjKind type ) : Chara( type )
Npc::~Npc()
{
}

bool Npc::pathingActive() const
{
return m_bPathingActive;
}

void Npc::setPathingActive( bool pathing )
{
m_bPathingActive = pathing;
}
6 changes: 6 additions & 0 deletions src/world/Actor/Npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ namespace Sapphire::Entity
Npc( Common::ObjKind type );

virtual ~Npc() override;
bool pathingActive() const;
void setPathingActive( bool pathing );

private:
bool m_bPathingActive{true};


};

Expand Down
70 changes: 0 additions & 70 deletions src/world/Encounter/InstanceContent/IfritNormal.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ namespace Sapphire

void start() override
{
auto ifritInitState = makeIfritPhaseOneState();

addState( ifritInitState );

m_status = EncounterFightStatus::ACTIVE;
}
Expand All @@ -51,60 +48,6 @@ namespace Sapphire
init();
}

EncounterStatePtr makeIfritPhaseOneState()
{
auto ifritInitState = std::make_shared< EncounterState >( shared_from_this() );
ifritInitState->setOnUpdateCallback( [ & ]( EncounterFightPtr pEncounter, EncounterState state ) {
auto timeElapsedMs = state.getElapsedTime();

auto pIfrit = pEncounter->getBNpc( NPC_IFRIT );

pIfrit->setRot( pIfrit->getRot() + .2f );

// todo: use gambits+timelines for this
if( timeElapsedMs > 10000 )
{
state.setFinishFlag();
return;
}

// todo: use gambits+timelines for this
if( timeElapsedMs > 5000 )
{
auto ifritTwoState = makeIfritPhaseTwoState();
pEncounter->addState( ifritTwoState );
}
} );

ifritInitState->setOnFinishCallback( [ & ]( EncounterFightPtr pEncounter, EncounterState state ) {
Logger::info( "stage 1 finish - enrage" );

auto pIfrit = pEncounter->getBNpc( NPC_IFRIT );
pIfrit->hateListGetHighest()->die();
} );

return ifritInitState;
}

EncounterStatePtr makeIfritPhaseTwoState()
{
auto ifritTwoState = std::make_shared< EncounterState >( shared_from_this() );
ifritTwoState->setOnUpdateCallback( [ & ]( EncounterFightPtr pEncounter, EncounterState state ) {
auto timeElapsedMs = state.getElapsedTime();

auto pIfrit = pEncounter->getBNpc( NPC_IFRIT );

pIfrit->setRot( pIfrit->getRot() - .2f );

// todo: use gambits+timelines for this
if( timeElapsedMs > 5000 )
{
state.setFinishFlag();
}
} );

return ifritTwoState;
}

void update( uint64_t deltaTime ) override
{
Expand All @@ -126,19 +69,6 @@ namespace Sapphire

m_pInstance->getEncounterTimeline().update( getInstance(), deltaTime );

//*
if( m_stateStack; !m_stateStack->empty() )
{
if( m_stateStack->top()->shouldFinish() )
{
m_stateStack->top()->finish();
m_stateStack->pop();
}

if( !m_stateStack->empty() )
m_stateStack->top()->update( deltaTime );
}
//*/
}
};
}// namespace Sapphire
4 changes: 2 additions & 2 deletions src/world/Encounter/TimelineActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ namespace Sapphire::Encounter
auto pParent = pTeri->getActiveBNpcByLayoutId( m_layoutId );
Common::BNpcType type = pParent ? pParent->getBNpcType() : Common::BNpcType::Enemy;

pActor = pTeri->createBNpcFromLayoutId( m_layoutId, 1000, type );
pActor = pTeri->createBNpcFromLayoutIdNoPush( m_layoutId, 1000, type );
m_subActors[ name ] = pActor;

pActor->setInvincibilityType( Common::InvincibilityIgnoreDamage );
Expand All @@ -189,7 +189,7 @@ namespace Sapphire::Encounter
auto& playerMgr = Common::Service< World::Manager::PlayerMgr >::ref();
for( const auto& player : pTeri->getPlayers() )
{
pActor->spawn( player.second );
// pActor->spawn( player.second );
playerMgr.sendDebug( *player.second, fmt::format( "Spawned subactor {}", name ) );
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/world/Encounter/Timepoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,16 +658,15 @@ namespace Sapphire::Encounter

// todo: probably have this info in the timepoint data
if( !pBNpc )
pBNpc = pTeri->createBNpcFromLayoutId( pSpawnData->m_layoutId, 100, Common::BNpcType::Enemy );
pBNpc = pTeri->createBNpcFromLayoutIdNoPush( pSpawnData->m_layoutId, 100, Common::BNpcType::Enemy );

if( pBNpc )
{
pBNpc->clearFlags();
pBNpc->setFlag( pSpawnData->m_flags );
pBNpc->init();

for( const auto& player : pTeri->getPlayers() )
pBNpc->spawn( player.second );
pTeri->pushActor( pBNpc );
}
}
break;
Expand Down
18 changes: 16 additions & 2 deletions src/world/Territory/Territory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,11 @@ void Territory::pushActor( const Entity::GameObjectPtr& pActor )
{
auto pBNpc = pActor->getAsBNpc();

if( m_pNaviProvider )
if( m_pNaviProvider && pBNpc->pathingActive() )
{
agentId = m_pNaviProvider->addAgent( *pBNpc );
pBNpc->setAgentId( agentId );
pBNpc->setAgentId( agentId );
}

m_bNpcMap[ pBNpc->getId() ] = pBNpc;
updateCellActivity( cx, cy, 1 );
Expand Down Expand Up @@ -854,6 +856,18 @@ Entity::BNpcPtr Territory::createBNpcFromLayoutId( uint32_t layoutId, uint32_t h
return pBNpc;
}

Entity::BNpcPtr Territory::createBNpcFromLayoutIdNoPush( uint32_t layoutId, uint32_t hp, Common::BNpcType bnpcType, uint32_t triggerOwnerId )
{
auto infoPtr = m_bNpcBaseMap.find( layoutId );
if( infoPtr == m_bNpcBaseMap.end() )
return nullptr;

auto pBNpc = std::make_shared< Entity::BNpc >( getNextActorId(), infoPtr->second, *this, hp, bnpcType );
pBNpc->init();
pBNpc->setTriggerOwnerId( triggerOwnerId );
return pBNpc;
}

Entity::BNpcPtr Territory::getActiveBNpcByEntityId( uint32_t entityId )
{
auto it = m_bNpcMap.find( entityId );
Expand Down
1 change: 1 addition & 0 deletions src/world/Territory/Territory.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ namespace Sapphire
void addEObj( Entity::EventObjectPtr object );

Entity::BNpcPtr createBNpcFromLayoutId( uint32_t levelId, uint32_t hp, Common::BNpcType bnpcType, uint32_t triggerOwnerId = 0 );
Entity::BNpcPtr createBNpcFromLayoutIdNoPush( uint32_t levelId, uint32_t hp, Common::BNpcType bnpcType, uint32_t triggerOwnerId = 0 );

Entity::BNpcPtr getActiveBNpcByEntityId( uint32_t entityId );

Expand Down

0 comments on commit c0aed54

Please sign in to comment.