1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-04 09:47:46 +00:00

fix incorrect radius for bnpc

- pass filters to snapshot
- fix replay not formatting debug message correctly
This commit is contained in:
Tahir 2024-06-26 20:44:36 +01:00
parent 3727306613
commit 73094fb85c
8 changed files with 31 additions and 22 deletions

View file

@ -39,8 +39,12 @@ float Util::distance2D( float x, float y, float x1, float y1 )
float Util::calcAngTo( float x, float y, float x1, float y1 )
{
float dx = x - x1;
float dy = y - y1;
float dx = x1 - x;
float dy = y1 - y;
if( dx == 0.0f && dy == 0.0f )
return 0.0f;
if( dy != 0.0f )
{
return atan2( dy, dx );
@ -55,6 +59,10 @@ float Util::calcAngFrom( float x, float y, float x1, float y1 )
{
float dx = x - x1;
float dy = y - y1;
if( dx == 0.0f && dy == 0.0f )
return 0.0f;
if( dy != 0.0f )
{
return atan2( dy, dx );

View file

@ -50,8 +50,9 @@ void AI::Fsm::StateCombat::onUpdate( Entity::BNpc& bnpc, uint64_t tickCount )
pNaviProvider->syncPosToChara( bnpc );
if( distance < ( bnpc.getNaviTargetReachedDistance() + bnpc.getRadius() + pHatedActor->getRadius() ) )
if( distance < ( bnpc.getNaviTargetReachedDistance() + pHatedActor->getRadius() ) )
{
// todo: dont turn if facing
if( !bnpc.hasFlag( Entity::TurningDisabled ) )
bnpc.face( pHatedActor->getPos() );

View file

@ -159,7 +159,9 @@ namespace Sapphire::World::AI
}
void Snapshot::createSnapshot( Entity::CharaPtr pSrc, const std::set< Entity::GameObjectPtr >& inRange,
int count, bool fillWithRandom, const std::vector< uint32_t >& exclude )
uint32_t count, bool fillWithRandom,
const std::vector< TargetSelectFilterPtr >& filters,
const std::vector< uint32_t >& exclude )
{
m_results.clear();
m_targetIds.clear();
@ -179,7 +181,7 @@ namespace Sapphire::World::AI
continue;
bool matches = true;
for( const auto& filter : m_filters )
for( const auto& filter : filters )
{
if( !filter->isApplicable( pSrc, pChara ) )
{
@ -190,7 +192,7 @@ namespace Sapphire::World::AI
if( matches )
{
CharaEntry entry;
CharaEntry entry{};
entry.m_entityId = pChara->getId();
entry.m_pos = pChara->getPos();
entry.m_rot = pChara->getRot();
@ -226,7 +228,7 @@ namespace Sapphire::World::AI
std::shuffle( remaining.begin(), remaining.end(), *RNGMgr.getRNGEngine() );
auto pChara = remaining.back();
CharaEntry entry;
CharaEntry entry{};
entry.m_entityId = pChara->getId();
entry.m_pos = pChara->getPos();
entry.m_rot = pChara->getRot();
@ -236,7 +238,7 @@ namespace Sapphire::World::AI
}
// sort by distance at the end always
auto srcPos = pSrc->getPos();
const auto& srcPos = pSrc->getPos();
std::sort( m_results.begin(), m_results.end(),
[ srcPos ]( CharaEntry l, CharaEntry r )
{

View file

@ -227,18 +227,16 @@ namespace Sapphire::World::AI
using Results = std::vector< CharaEntry >;
using TargetIds = std::vector< uint32_t >;
private:
std::vector< TargetSelectFilterPtr > m_filters;
std::vector< CharaEntry > m_results;
std::vector< uint32_t > m_targetIds;
public:
Snapshot( const std::vector< TargetSelectFilterPtr >& filters ) :
m_filters( filters )
{
}
Snapshot() {}
void createSnapshot( Entity::CharaPtr pSrc, const std::set< Entity::GameObjectPtr >& inRange,
int count, bool fillWithRandom, const std::vector< uint32_t >& exclude = {} );
uint32_t count, bool fillWithRandom,
const std::vector< TargetSelectFilterPtr >& filters,
const std::vector< uint32_t >& exclude = {} );
// returns actors sorted by distance
const std::vector< CharaEntry >& getResults() const;

View file

@ -174,7 +174,7 @@ BNpc::BNpc( uint32_t id, std::shared_ptr< Common::BNPCInstanceObject > pInfo, co
}
// todo: is this actually good?
m_naviTargetReachedDistance = m_radius * 2;
m_naviTargetReachedDistance = m_radius;
calculateStats();
@ -274,7 +274,7 @@ BNpc::BNpc( uint32_t id, std::shared_ptr< Common::BNPCInstanceObject > pInfo, co
auto modelChara = exdData.getRow< Excel::ModelChara >( bNpcBaseData->data().Model );
if( modelChara )
{
auto modelSkeleton = exdData.getRow< Excel::ModelSkeleton >( modelChara->data().ModelType );
auto modelSkeleton = exdData.getRow< Excel::ModelSkeleton >( modelChara->data().SkeletonId );
if( modelSkeleton )
m_radius *= modelSkeleton->data().Radius;
}

View file

@ -34,7 +34,7 @@ namespace Sapphire::Encounter
auto filtersJ = json.at( "filters" ).items();
for( const auto& filterJ : filtersJ )
{
auto filterV = filterJ.value();
auto& filterV = filterJ.value();
auto name = filterV.at( "type" ).get< std::string >();
auto typeId = filterMap.find( name )->second;
auto negate = filterV.at( "negate" ).get< bool >();
@ -115,14 +115,13 @@ namespace Sapphire::Encounter
default:
break;
}
filters.push_back( pFilter );
m_filters.push_back( pFilter );
}
m_snapshot = World::AI::Snapshot( filters );
}
void Selector::createSnapshot( Entity::CharaPtr pSrc, const std::vector< uint32_t >& exclude )
{
m_snapshot.createSnapshot( pSrc, pSrc->getInRangeActors(), m_count, m_fillWithRandom, exclude );
m_snapshot.createSnapshot( pSrc, pSrc->getInRangeActors(), m_count, m_fillWithRandom, m_filters, exclude );
}
const World::AI::Snapshot::Results& Selector::getResults()

View file

@ -13,10 +13,11 @@ namespace Sapphire::Encounter
std::string m_name;
bool m_fillWithRandom{ true };
uint32_t m_count{ 0 };
std::vector< World::AI::TargetSelectFilterPtr > m_filters;
World::AI::Snapshot m_snapshot;
public:
Selector() : m_snapshot( {} ){};
Selector(){}
void createSnapshot( Entity::CharaPtr pSrc, const std::vector< uint32_t >& exclude = {} );
const World::AI::Snapshot::Results& getResults();
const World::AI::Snapshot::TargetIds& getTargetIds();

View file

@ -160,7 +160,7 @@ void Sapphire::World::Session::startReplay( const std::string& path )
Logger::info( "Registering {0} for {1}, oldTime {2}", std::get< 1 >( set ), setTime - startTime, setTime );
}
PlayerMgr::sendDebug( *getPlayer(), "Registered {0} sets for replay" ), m_replayCache.size();
PlayerMgr::sendDebug( *getPlayer(), "Registered {0} sets for replay" , m_replayCache.size() );
m_isReplaying = true;
}