1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-01 00:27:44 +00:00

Merge pull request #796 from hkAlice/aggro-attempts

[3.0] adds int, unspecified type, type range and array of values to rngmgr; warning cleanups;
This commit is contained in:
Mordred 2022-02-20 23:02:58 +01:00 committed by GitHub
commit d262e3f5a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 126 additions and 92 deletions

View file

@ -1499,64 +1499,63 @@ namespace Sapphire::Common
using PlayerStateFlagList = std::vector< PlayerStateFlag >;
struct BNPCInstanceObject
{
uint16_t territoryType;
std::string bnpcName;
uint32_t instanceId;
uint32_t nameOffset;
float x;
float y;
float z;
float rotation;
uint32_t BaseId;
uint32_t PopWeather;
uint8_t PopTimeStart;
uint8_t PopTimeEnd;
uint32_t MoveAI;
uint8_t WanderingRange;
uint8_t Route;
uint16_t EventGroup;
uint32_t NameId;
uint32_t DropItem;
float SenseRangeRate;
uint16_t Level;
uint8_t ActiveType;
uint8_t PopInterval;
uint8_t PopRate;
uint8_t PopEvent;
uint8_t LinkGroup;
uint8_t LinkFamily;
uint8_t LinkRange;
uint8_t LinkCountLimit;
int8_t NonpopInitZone;
int8_t InvalidRepop;
int8_t LinkParent;
int8_t LinkOverride;
int8_t LinkReply;
int8_t Nonpop;
float HorizontalPopRange;
float VerticalPopRange;
int32_t BNpcBaseData;
uint8_t RepopId;
uint8_t BNPCRankId;
uint16_t TerritoryRange;
uint32_t BoundInstanceID;
uint32_t FateLayoutLabelId;
uint32_t NormalAI;
uint32_t ServerPathId;
uint32_t EquipmentID;
uint32_t CustomizeID;
};
struct BNPCInstanceObject
{
uint16_t territoryType;
std::string bnpcName;
uint32_t instanceId;
uint32_t nameOffset;
float x;
float y;
float z;
float rotation;
uint32_t BaseId;
uint32_t PopWeather;
uint8_t PopTimeStart;
uint8_t PopTimeEnd;
uint32_t MoveAI;
uint8_t WanderingRange;
uint8_t Route;
uint16_t EventGroup;
uint32_t NameId;
uint32_t DropItem;
float SenseRangeRate;
uint16_t Level;
uint8_t ActiveType;
uint8_t PopInterval;
uint8_t PopRate;
uint8_t PopEvent;
uint8_t LinkGroup;
uint8_t LinkFamily;
uint8_t LinkRange;
uint8_t LinkCountLimit;
int8_t NonpopInitZone;
int8_t InvalidRepop;
int8_t LinkParent;
int8_t LinkOverride;
int8_t LinkReply;
int8_t Nonpop;
float HorizontalPopRange;
float VerticalPopRange;
int32_t BNpcBaseData;
uint8_t RepopId;
uint8_t BNPCRankId;
uint16_t TerritoryRange;
uint32_t BoundInstanceID;
uint32_t FateLayoutLabelId;
uint32_t NormalAI;
uint32_t ServerPathId;
uint32_t EquipmentID;
uint32_t CustomizeID;
};
/*
* CellId is used to identify a cell in the cell container of a zone
*/
struct CellId
{
uint32_t x{ 0 };
uint32_t y{ 0 };
};
/*
* CellId is used to identify a cell in the cell container of a zone
*/
struct CellId
{
uint32_t x{ 0 };
uint32_t y{ 0 };
};
}

View file

@ -731,6 +731,7 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
}
checkAggro();
break;
}
case BNpcState::Combat:
@ -796,6 +797,7 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
pNaviProvider->updateAgentParameters( *this );
}
}
break;
}
@ -832,20 +834,21 @@ void Sapphire::Entity::BNpc::onDeath()
{
auto& server = Common::Service< World::WorldServer >::ref();
auto& playerMgr = Common::Service< World::Manager::PlayerMgr >::ref();
auto& taskMgr = Common::Service< World::Manager::TaskMgr >::ref();
setTargetId( INVALID_GAME_OBJECT_ID64 );
m_currentStance = Stance::Passive;
m_state = BNpcState::Dead;
m_timeOfDeath = Util::getTimeSeconds();
setOwner( nullptr );
auto& taskMgr = Common::Service< World::Manager::TaskMgr >::ref();
taskMgr.queueTask( World::makeFadeBNpcTask( 10000, getAsBNpc() ) );
taskMgr.queueTask( World::makeRemoveBNpcTask( 12000, getAsBNpc() ) );
auto& exdData = Common::Service< Data::ExdData >::ref();
auto paramGrowthInfo = exdData.getRow< Excel::ParamGrow >( m_level );
for( auto& pHateEntry : m_hateList )
for( const auto& pHateEntry : m_hateList )
{
// TODO: handle drops
auto pPlayer = pHateEntry->m_pChara->getAsPlayer();
@ -855,6 +858,7 @@ void Sapphire::Entity::BNpc::onDeath()
pPlayer->gainExp( paramGrowthInfo->data().BaseExp );
}
}
hateListClear();
}

View file

@ -474,7 +474,7 @@ Sapphire::Entity::Player::InvSlotPair Sapphire::Entity::Player::getFreeBagSlot()
Sapphire::Entity::Player::InvSlotPair Sapphire::Entity::Player::getFreeContainerSlot( uint32_t containerId )
{
auto freeSlot = static_cast < int8_t >( m_storageMap[ containerId ]->getFreeSlot() );
auto freeSlot = static_cast< int8_t >( m_storageMap[ containerId ]->getFreeSlot() );
if( freeSlot != -1 )
return std::make_pair( containerId, freeSlot );

View file

@ -45,6 +45,7 @@
#include "WorldServer.h"
#include "Session.h"
#include <Manager/RNGMgr.h>
using namespace Sapphire::Network;
using namespace Sapphire::Network::Packets;

View file

@ -53,7 +53,7 @@ bool LinkshellMgr::loadLinkshells()
size_t entryCount = inData.size() / 8;
std::vector< uint64_t > list( entryCount );
for( int i = 0; i < entryCount; ++i )
for( uint64_t i = 0; i < entryCount; ++i )
{
auto val = *reinterpret_cast< const uint64_t* >( &inData[ i * 8 ] );
list[ i ] = val;

View file

@ -8,6 +8,7 @@
#include <random>
#include <memory>
#include <type_traits>
#include <vector>
namespace Sapphire::World::Manager
{
@ -19,24 +20,47 @@ namespace Sapphire::World::Manager
{
public:
RandGenerator( std::shared_ptr< std::mt19937 > pEngine, T minRange = std::numeric_limits< T >::min(), T maxRange = std::numeric_limits< T >::max() )
: m_engine( pEngine ), m_dist( minRange, maxRange )
: m_engine( pEngine ), m_fpuDist( minRange, maxRange ), m_intDist( minRange, maxRange )
{
}
// returns a single value for T type on set ranges, deducing real or integer distribution from given numeric type
T next()
{
return m_dist( *m_engine );
if constexpr( std::is_integral< T >::value )
return m_intDist( *m_engine );
return m_fpuDist( *m_engine );
}
private:
std::uniform_real_distribution< T > m_dist;
// returns an array of size nSize with values type T on set ranges, deducing real or integer distribution from given numeric type
template< std::size_t nSize >
const std::array< T, nSize > nextCount()
{
std::array< T, nSize > _valPush;
for( auto i = 0; i < nSize; ++i )
{
if constexpr( std::is_integral< T >::value )
_valPush[ i ] = ( m_intDist( *m_engine ) );
else
_valPush[ i ] = ( m_fpuDist( *m_engine ) );
}
return _valPush;
}
protected:
std::uniform_real_distribution<> m_fpuDist;
std::uniform_int_distribution<> m_intDist;
std::shared_ptr< std::mt19937 > m_engine;
};
class RNGMgr
{
public:
// Constructs a manager to supply states for random integer and float distribution using a Mersenne Twister engine
RNGMgr()
{
m_engine = std::make_shared< std::mt19937 >( *engineSeed< std::mt19937::state_size >() );
@ -48,7 +72,7 @@ namespace Sapphire::World::Manager
RNGMgr& operator=( const RNGMgr& pRNGMgr ) = delete;
/*!
* @brief Creates a RNG with specified parameters for multiple uses
* @brief Creates a state with specified parameters for multiple uses
* @tparam Numeric type to be used for the generator
* @param Minimum value possible for the random value
* @param Maximum value possible for the random value
@ -60,6 +84,17 @@ namespace Sapphire::World::Manager
return RandGenerator< T >( m_engine, minRange, maxRange );
}
/*!
* @brief Creates a state with only typed data arithmetic range
* @tparam Numeric type to be used for the generator and range (::min(), ::max() of numeric type)
* @return Random number generator object
*/
template< typename T, typename = typename std::enable_if< std::is_arithmetic< T >::value, T >::type >
RandGenerator< T > getRandGenerator()
{
return RandGenerator< T >( m_engine );
}
private:
template< std::size_t STATE_SIZE >
@ -70,6 +105,11 @@ namespace Sapphire::World::Manager
std::array< uint32_t, STATE_SIZE > seedArray;
std::random_device rd;
// check if kernel can supply sufficiently non-deterministic output
if( rd.entropy() == 0.f )
Logger::error( "Kernel random device entropy reported zero - Random number generator may be poor quality" );
std::generate_n( seedArray.data(), seedArray.size(), std::ref( rd ) );
auto pSeq = std::make_unique< std::seed_seq >( std::begin( seedArray ), std::end( seedArray ) );

View file

@ -26,7 +26,8 @@ using namespace Sapphire;
using namespace Sapphire::World::Manager;
TerritoryMgr::TerritoryMgr() :
m_lastInstanceId( 10000 )
m_lastInstanceId( 10000 ),
m_inRangeDistance( 0 )
{
}

View file

@ -78,7 +78,7 @@ void Sapphire::Network::GameConnection::getCommonlistHandler( const Packets::FFX
const size_t itemsPerPage = 10;
// this func paginates any commonlist entry, associating them with online player data and hierarchy ID (optional)
auto generateEntries = [&]( const auto& idVec, size_t offset, const std::vector< Common::HierarchyData >& hierarchyVec ) -> std::vector< PlayerEntry >
auto generateEntries = [ & ]( const auto& idVec, size_t offset, const std::vector< Common::HierarchyData >& hierarchyVec ) -> std::vector< PlayerEntry >
{
std::vector< PlayerEntry > entries;

View file

@ -448,10 +448,9 @@ void Sapphire::Network::GameConnection::commandHandler( const Packets::FFXIVARR_
}
case PacketCommand::TARGET_DECIDE: // Change target
{
uint64_t targetId = param1;
if( targetId == player.getTargetId() || targetId == 0xE0000000 )
if( targetId == player.getTargetId() || targetId == Common::INVALID_GAME_OBJECT_ID )
targetId = 0;
player.changeTarget( targetId );

View file

@ -641,7 +641,7 @@ void Sapphire::Network::GameConnection::gearSetEquip( const Packets::FFXIVARR_PA
auto& server = Common::Service< World::WorldServer >::ref();
// Loop over all slots
for (int slot = 0; slot < 14; slot++ )
for( int slot = 0; slot < 14; ++slot )
{
const auto fromSlot = packet.data().containerIndex[ slot ];
const auto fromContainer = packet.data().storageId[ slot ];
@ -659,19 +659,19 @@ void Sapphire::Network::GameConnection::gearSetEquip( const Packets::FFXIVARR_PA
ackPacket->data().operationType = operationType;
server.queueForPlayer( player.getCharacterId(), ackPacket );
if ( fromItem && equippedItem )
if( fromItem && equippedItem )
{
player.swapItem( fromContainer, fromSlot, Common::GearSet0, slot );
server.queueForPlayer( player.getCharacterId(), std::make_shared< UpdateInventorySlotPacket >( player.getId(), fromSlot, fromContainer, *equippedItem, 0 ) );
server.queueForPlayer( player.getCharacterId(), std::make_shared< UpdateInventorySlotPacket >( player.getId(), slot, Common::GearSet0, *fromItem, 0 ) );
}
else if ( fromItem && !equippedItem )
else if( fromItem && !equippedItem )
{
player.moveItem( fromContainer, fromSlot, Common::GearSet0, slot );
server.queueForPlayer( player.getCharacterId(), std::make_shared< UpdateInventorySlotPacket >( player.getId(), fromSlot, fromContainer, 0 ) );
server.queueForPlayer( player.getCharacterId(), std::make_shared< UpdateInventorySlotPacket >( player.getId(), slot, Common::GearSet0, *fromItem, 0 ) );
}
else if ( !fromItem && equippedItem )
else if( !fromItem && equippedItem )
{
auto containerId = World::Manager::ItemMgr::getCharaEquipSlotCategoryToArmoryId( static_cast< Common::EquipSlotCategory >( equippedItem->getSlot() ) );
auto freeSlot = player.getFreeContainerSlot( containerId ).second;

View file

@ -7,15 +7,6 @@
namespace Sapphire::Network::Packets::WorldPackets::Server
{
uint64_t ExecuteCharacterID;
uint64_t TargetCharacterID;
uint8_t ExecuteIdentity;
uint8_t TargetIdentity;
uint8_t UpdateStatus;
uint8_t Count;
char ExecuteCharacterName[32];
char TargetCharacterName[32];
class PcPartyUpdatePacket : public ZoneChannelPacket< FFXIVIpcPcPartyUpdate >
{
public:

View file

@ -50,7 +50,7 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
memcpy( m_data.Aetheryte, player.getAetheryteArray().data(), sizeof( m_data.Aetheryte ) );
// Set the class levels and exp.
for( uint8_t i = 0; i < 23; i++ )
for( uint8_t i = 0; i < Common::CLASSJOB_TOTAL; ++i )
{
m_data.Lv[ i ] = player.getClassArray()[ i ];
m_data.Exp[ i ] = player.getExpArray()[ i ];

View file

@ -54,6 +54,7 @@ using namespace Sapphire::World::Manager;
Territory::Territory() :
m_territoryTypeId( 0 ),
m_ident(),
m_guId( 0 ),
m_currentWeather( Common::Weather::FairSkies ),
m_weatherOverride( Common::Weather::None ),
@ -908,7 +909,6 @@ bool Territory::loadBNpcs()
while( res->next() )
{
auto bnpc = std::make_shared< Common::BNPCInstanceObject >();
bnpc->territoryType = res->getInt( 1 );
@ -970,8 +970,6 @@ bool Territory::loadBNpcs()
m_spawnInfo.emplace_back( info );
}
}
return true;
}

View file

@ -60,7 +60,8 @@ WorldServer::WorldServer( const std::string& configName ) :
m_configName( configName ),
m_bRunning( true ),
m_lastDBPingTime( 0 ),
m_worldId( 67 )
m_worldId( 67 ),
m_port( 0 )
{
}
@ -162,6 +163,9 @@ void WorldServer::run( int32_t argc, char* argv[] )
}
Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::set( pDb );
auto pRNGMgr = std::make_shared< Manager::RNGMgr >();
Common::Service< Manager::RNGMgr >::set( pRNGMgr );
Logger::info( "Loading all players" );
if( !loadPlayers() )
{
@ -192,9 +196,6 @@ void WorldServer::run( int32_t argc, char* argv[] )
auto pNaviMgr = std::make_shared< Manager::NaviMgr >();
Common::Service< Manager::NaviMgr >::set( pNaviMgr );
auto pRNGMgr = std::make_shared< Manager::RNGMgr >();
Common::Service< Manager::RNGMgr >::set( pRNGMgr );
Logger::info( "TerritoryMgr: Setting up zones" );
auto pTeriMgr = std::make_shared< Manager::TerritoryMgr >();
auto pHousingMgr = std::make_shared< Manager::HousingMgr >();