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

refactoring various files

This commit is contained in:
Mordred 2017-11-28 00:09:36 +01:00
parent 7d00d5cb40
commit bd4dc893c4
14 changed files with 119 additions and 182 deletions

View file

@ -38,8 +38,8 @@ Core::Entity::BattleNpc::~BattleNpc()
} }
Core::Entity::BattleNpc::BattleNpc( uint32_t modelId, uint32_t nameid, const Common::FFXIVARR_POSITION3& spawnPos, Core::Entity::BattleNpc::BattleNpc( uint16_t modelId, uint16_t nameid, const Common::FFXIVARR_POSITION3& spawnPos,
uint32_t sizeId, uint32_t type, uint32_t level, uint32_t behaviour, uint16_t bnpcBaseId, uint32_t type, uint8_t level, uint8_t behaviour,
uint32_t mobType ) uint32_t mobType )
{ {
BattleNpc::m_nextID++; BattleNpc::m_nextID++;
@ -52,7 +52,7 @@ Core::Entity::BattleNpc::BattleNpc( uint32_t modelId, uint32_t nameid, const Com
m_objKind = ObjKind::BattleNpc; m_objKind = ObjKind::BattleNpc;
m_mode = MODE_IDLE; m_mode = MODE_IDLE;
m_targetId = INVALID_GAME_OBJECT_ID; m_targetId = static_cast< uint64_t >( INVALID_GAME_OBJECT_ID );
m_maxHp = 150; m_maxHp = 150;
m_maxMp = 100; m_maxMp = 100;
@ -66,14 +66,14 @@ Core::Entity::BattleNpc::BattleNpc( uint32_t modelId, uint32_t nameid, const Com
m_currentStance = Stance::Passive; m_currentStance = Stance::Passive;
m_class = ClassJob::Gladiator; m_class = ClassJob::Gladiator;
m_level = level > 0 ? level : 70; m_level = level > uint8_t{0} ? level : uint8_t{70};
m_modelId = modelId; m_modelId = modelId;
m_nameId = nameid; m_nameId = nameid;
m_behavior = behaviour; m_behavior = behaviour;
m_bnpcBaseId = sizeId; m_bnpcBaseId = bnpcBaseId;
m_status = ActorStatus::Idle; m_status = ActorStatus::Idle;
@ -189,7 +189,7 @@ uint8_t Core::Entity::BattleNpc::getbehavior() const
void Core::Entity::BattleNpc::hateListAdd( Core::Entity::ActorPtr pActor, int32_t hateAmount ) void Core::Entity::BattleNpc::hateListAdd( Core::Entity::ActorPtr pActor, int32_t hateAmount )
{ {
HateListEntry* hateEntry = new HateListEntry(); auto hateEntry = new HateListEntry();
hateEntry->m_hateAmount = hateAmount; hateEntry->m_hateAmount = hateAmount;
hateEntry->m_pActor = pActor; hateEntry->m_pActor = pActor;
@ -262,7 +262,7 @@ bool Core::Entity::BattleNpc::moveTo( Common::FFXIVARR_POSITION3& pos )
float y = ( getPos().y + pos.y ) * 0.5f; // fake value while there is no collision float y = ( getPos().y + pos.y ) * 0.5f; // fake value while there is no collision
float z = static_cast< float >( sinf( angle ) * 1.1f ); float z = static_cast< float >( sinf( angle ) * 1.1f );
Common::FFXIVARR_POSITION3 newPos; Common::FFXIVARR_POSITION3 newPos{};
newPos.x = getPos().x + x; newPos.x = getPos().x + x;
newPos.y = y; newPos.y = y;
@ -270,13 +270,11 @@ bool Core::Entity::BattleNpc::moveTo( Common::FFXIVARR_POSITION3& pos )
setPosition( newPos ); setPosition( newPos );
Common::FFXIVARR_POSITION3 tmpPos; Common::FFXIVARR_POSITION3 tmpPos{};
tmpPos.x = getPos().x + x; tmpPos.x = getPos().x + x;
tmpPos.y = y; tmpPos.y = y;
tmpPos.z = getPos().z + z; tmpPos.z = getPos().z + z;
angle = angle * 2;
setPosition( tmpPos ); setPosition( tmpPos );
setRotation(newRot); setRotation(newRot);
@ -384,7 +382,7 @@ void Core::Entity::BattleNpc::hateListUpdate( Core::Entity::ActorPtr pActor, int
} }
} }
HateListEntry* hateEntry = new HateListEntry(); auto hateEntry = new HateListEntry();
hateEntry->m_hateAmount = hateAmount; hateEntry->m_hateAmount = hateAmount;
hateEntry->m_pActor = pActor; hateEntry->m_pActor = pActor;
m_hateList.insert( hateEntry ); m_hateList.insert( hateEntry );
@ -427,7 +425,7 @@ void Core::Entity::BattleNpc::onDeath()
if( pHateEntry->m_pActor->isPlayer() ) // && pHateEntry->m_hateAmount >= plsBeHatedThisMuchAtLeast ) if( pHateEntry->m_pActor->isPlayer() ) // && pHateEntry->m_hateAmount >= plsBeHatedThisMuchAtLeast )
{ {
uint8_t level = pHateEntry->m_pActor->getLevel(); uint8_t level = pHateEntry->m_pActor->getLevel();
auto levelDiff = (int)this->m_level - (int)level; auto levelDiff = static_cast< int32_t >( this->m_level ) - level;
auto cappedLevelDiff = Math::Util::clamp( levelDiff, 1, 6 ); auto cappedLevelDiff = Math::Util::clamp( levelDiff, 1, 6 );
auto expNeeded = g_exdData.m_paramGrowthInfoMap[m_level + cappedLevelDiff - 1].needed_exp; auto expNeeded = g_exdData.m_paramGrowthInfoMap[m_level + cappedLevelDiff - 1].needed_exp;
@ -449,7 +447,7 @@ void Core::Entity::BattleNpc::onDeath()
// todo: this is actually retarded, we need real rand() // todo: this is actually retarded, we need real rand()
srand( static_cast< unsigned int> ( time( NULL ) ) ); srand( static_cast< uint32_t > ( time( nullptr ) ) );
auto pPlayer = pHateEntry->m_pActor->getAsPlayer(); auto pPlayer = pHateEntry->m_pActor->getAsPlayer();
pPlayer->gainExp( exp ); pPlayer->gainExp( exp );
@ -517,7 +515,7 @@ void Core::Entity::BattleNpc::update( int64_t currTime )
{ {
ActorPtr pClosestActor = getClosestActor(); ActorPtr pClosestActor = getClosestActor();
if( ( pClosestActor != nullptr ) && pClosestActor->isAlive() ) if( pClosestActor && pClosestActor->isAlive() )
{ {
distance = Math::Util::distance( getPos().x, getPos().y, getPos().z, distance = Math::Util::distance( getPos().x, getPos().y, getPos().z,
pClosestActor->getPos().x, pClosestActor->getPos().x,

View file

@ -27,7 +27,8 @@ public:
BattleNpc(); BattleNpc();
~BattleNpc(); ~BattleNpc();
BattleNpc( uint32_t modelId, uint32_t nameid, const Common::FFXIVARR_POSITION3& spawnPos, uint32_t sizeId = 0, uint32_t type = 2, uint32_t level = 0, uint32_t behaviour = 1, uint32_t mobType = 0 ); BattleNpc( uint16_t modelId, uint16_t nameid, const Common::FFXIVARR_POSITION3& spawnPos, uint16_t bnpcBaseId = 0,
uint32_t type = 2, uint8_t level = 0, uint8_t behaviour = 1, uint32_t mobType = 0 );
//BattleNpc( uint32_t modelId, //BattleNpc( uint32_t modelId,
// uint32_t nameId, // uint32_t nameId,

View file

@ -895,10 +895,8 @@ Core::Entity::ActorPtr Core::Entity::Player::lookupTargetById( uint64_t targetId
for( auto actor : inRange ) for( auto actor : inRange )
{ {
if( actor->getId() == targetId ) if( actor->getId() == targetId )
{
targetActor = actor; targetActor = actor;
} }
}
return targetActor; return targetActor;
} }
@ -1209,27 +1207,28 @@ void Core::Entity::Player::queuePacket( Core::Network::Packets::GamePacketPtr pP
{ {
auto pSession = g_serverZone.getSession( m_id ); auto pSession = g_serverZone.getSession( m_id );
if( pSession ) if( !pSession )
{ return;
auto pZoneCon = pSession->getZoneConnection(); auto pZoneCon = pSession->getZoneConnection();
if( pZoneCon ) if( pZoneCon )
pZoneCon->queueOutPacket( pPacket ); pZoneCon->queueOutPacket( pPacket );
}
} }
void Core::Entity::Player::queueChatPacket( Core::Network::Packets::GamePacketPtr pPacket ) void Core::Entity::Player::queueChatPacket( Core::Network::Packets::GamePacketPtr pPacket )
{ {
auto pSession = g_serverZone.getSession( m_id ); auto pSession = g_serverZone.getSession( m_id );
if( pSession ) if( !pSession )
{ return;
auto pChatCon = pSession->getChatConnection(); auto pChatCon = pSession->getChatConnection();
if( pChatCon ) if( pChatCon )
pChatCon->queueOutPacket( pPacket ); pChatCon->queueOutPacket( pPacket );
} }
}
bool Core::Entity::Player::isLoadingComplete() const bool Core::Entity::Player::isLoadingComplete() const
{ {
@ -1460,7 +1459,8 @@ void Core::Entity::Player::mount( uint32_t id )
void Core::Entity::Player::dismount() void Core::Entity::Player::dismount()
{ {
sendToInRangeSet( ActorControlPacket142( getId(), ActorControlType::SetStatus, static_cast< uint8_t >( Entity::Actor::ActorStatus::Idle )), true ); sendToInRangeSet( ActorControlPacket142( getId(), ActorControlType::SetStatus,
static_cast< uint8_t >( Entity::Actor::ActorStatus::Idle )), true );
sendToInRangeSet( ActorControlPacket143( getId(), ActorControlType::Dismount, 1 ), true ); sendToInRangeSet( ActorControlPacket143( getId(), ActorControlType::Dismount, 1 ), true );
m_mount = 0; m_mount = 0;
} }
@ -1473,7 +1473,8 @@ uint8_t Core::Entity::Player::getCurrentMount() const
void Core::Entity::Player::autoAttack( ActorPtr pTarget ) void Core::Entity::Player::autoAttack( ActorPtr pTarget )
{ {
auto mainWeap = m_pInventory->getItemAt(Inventory::GearSet0, Inventory::EquipSlot::MainHand); auto mainWeap = m_pInventory->getItemAt( Inventory::GearSet0,
Inventory::EquipSlot::MainHand );
pTarget->onActionHostile( shared_from_this() ); pTarget->onActionHostile( shared_from_this() );
//uint64_t tick = Util::getTimeMs(); //uint64_t tick = Util::getTimeMs();

View file

@ -522,7 +522,6 @@ public:
void setEorzeaTimeOffset( uint64_t timestamp ); void setEorzeaTimeOffset( uint64_t timestamp );
// Database // Database
void updateDbAllQuests() const; void updateDbAllQuests() const;
void deleteQuest( uint16_t questId ) const; void deleteQuest( uint16_t questId ) const;

View file

@ -69,8 +69,8 @@ void Core::Entity::Player::removeEvent( uint32_t eventId )
void Core::Entity::Player::checkEvent( uint32_t eventId ) void Core::Entity::Player::checkEvent( uint32_t eventId )
{ {
auto pEvent = getEvent( eventId ); auto pEvent = getEvent( eventId );
if( pEvent )
if( !pEvent->hasPlayedScene() ) if( pEvent && !pEvent->hasPlayedScene() )
eventFinish( eventId, 1 ); eventFinish( eventId, 1 );
} }
@ -282,7 +282,8 @@ void Core::Entity::Player::eventItemActionStart( uint32_t eventId,
void Core::Entity::Player::onLogin() void Core::Entity::Player::onLogin()
{ {
for( auto& child : g_serverZone.getConfig()->getChild( "Settings.Parameters.MotDArray" ) ) { for( auto& child : g_serverZone.getConfig()->getChild( "Settings.Parameters.MotDArray" ) )
{
sendNotice( child.second.data() ); sendNotice( child.second.data() );
} }
} }

View file

@ -195,10 +195,8 @@ bool Core::Entity::Player::tryAddItem( uint16_t catalogId, uint32_t quantity )
for( uint16_t i = 0; i < 4; i++ ) for( uint16_t i = 0; i < 4; i++ )
{ {
if( m_pInventory->addItem( i, -1, catalogId, quantity ) != -1 ) if( m_pInventory->addItem( i, -1, catalogId, quantity ) != -1 )
{
return true; return true;
} }
}
return false; return false;
} }

View file

@ -45,7 +45,7 @@ void Core::Entity::Player::removeQuest( uint16_t questId )
{ {
ZoneChannelPacket< FFXIVIpcQuestUpdate > questUpdatePacket( getId() ); ZoneChannelPacket< FFXIVIpcQuestUpdate > questUpdatePacket( getId() );
questUpdatePacket.data().slot = idx; questUpdatePacket.data().slot = static_cast< uint8_t >( idx );
questUpdatePacket.data().questInfo.c.questId = 0; questUpdatePacket.data().questInfo.c.questId = 0;
questUpdatePacket.data().questInfo.c.sequence = 0xFF; questUpdatePacket.data().questInfo.c.sequence = 0xFF;
queuePacket( questUpdatePacket ); queuePacket( questUpdatePacket );
@ -1023,6 +1023,7 @@ bool Core::Entity::Player::giveQuestRewards( uint32_t questId, uint32_t optional
auto paramGrowth = g_exdData.m_paramGrowthInfoMap[questInfo->quest_level]; auto paramGrowth = g_exdData.m_paramGrowthInfoMap[questInfo->quest_level];
// TODO: use the correct formula, this one is wrong
uint32_t exp = ( questInfo->reward_exp_factor * paramGrowth.quest_exp_mod * ( 45 + 5 * questInfo->quest_level) ) / 100; uint32_t exp = ( questInfo->reward_exp_factor * paramGrowth.quest_exp_mod * ( 45 + 5 * questInfo->quest_level) ) / 100;
exp = exp + ( questInfo->reward_exp_factor / 100 ) * 10000; exp = exp + ( questInfo->reward_exp_factor / 100 ) * 10000;

View file

@ -126,7 +126,7 @@ void Core::Network::GameConnection::OnRecv( std::vector< uint8_t > & buffer )
{ {
// This is assumed packet always start with valid FFXIVARR_PACKET_HEADER for now. // This is assumed packet always start with valid FFXIVARR_PACKET_HEADER for now.
Packets::FFXIVARR_PACKET_HEADER packetHeader; Packets::FFXIVARR_PACKET_HEADER packetHeader{};
const auto headerResult = Packets::getHeader(buffer, 0, packetHeader); const auto headerResult = Packets::getHeader(buffer, 0, packetHeader);
if (headerResult == Incomplete) if (headerResult == Incomplete)
@ -369,8 +369,6 @@ void Core::Network::GameConnection::handlePackets( const Core::Network::Packets:
for( auto inPacket : packetData ) for( auto inPacket : packetData )
{ {
switch( inPacket.segHdr.type ) switch( inPacket.segHdr.type )
{ {
case 1: case 1:
@ -459,58 +457,5 @@ void Core::Network::GameConnection::handlePackets( const Core::Network::Packets:
} }
} }
//// try to retrieve the session for this id
//auto session = g_serverZone.getSession( inPacket.segHdr.source_actor );
//auto pCon = boost::static_pointer_cast< GameConnection, Connection >( shared_from_this() );
//// check if this is a zoning notification
//if( *reinterpret_cast< uint16_t* >( &inPacket.data[2] ) == 0x9999 )
//{
// // if we already have a session in this connection, reload the player
// if( session )
// g_serverZone.updateSession( inPacket.segHdr.source_actor );
// else
// {
// // if not, create a new session
// g_serverZone.createSession( inPacket.segHdr.source_actor );
// session = g_serverZone.getSession( inPacket.segHdr.source_actor );
// }
// // set the zoneingType for the player so the correct animation can be played
// auto pPlayer = session->getPlayer();
// ZoneingType zoneType = static_cast< ZoneingType >( *reinterpret_cast< uint16_t* >( &inPacket.data[18] ) );
// switch( zoneType )
// {
// case ZoneingType::Teleport:
// pPlayer->setTeleporting( true );
// break;
// case ZoneingType::Return:
// pPlayer->setReturning( true );
// break;
// default:
// break;
// }
// // place this connection in the session
// session->setZoneConnection( pCon );
// // actually perform the zoning
// session->getPlayer()->setZone( *reinterpret_cast< uint16_t* >( &inPacket.data[16] ) );
//}
//else
//{
// if( !session )
// {
// g_serverZone.createSession( inPacket.segHdr.source_actor );
// session = g_serverZone.getSession( inPacket.segHdr.source_actor );
// session->setZoneConnection( pCon );
// }
// queueInPacket( GamePacketPtr( new GamePacket( inPacket ) ) );
//}
//// if not set, set the session for this connection
//if( !m_pSession && session )
// m_pSession = session;
} }
} }

View file

@ -52,7 +52,7 @@ void Core::Network::GameConnection::actionHandler( const Packets::GamePacket& in
uint64_t param1 = inPacket.getValAt< uint64_t >( 0x24 ); uint64_t param1 = inPacket.getValAt< uint64_t >( 0x24 );
uint32_t param11 = inPacket.getValAt< uint32_t >( 0x24 ); uint32_t param11 = inPacket.getValAt< uint32_t >( 0x24 );
uint32_t param12 = inPacket.getValAt< uint32_t >( 0x28 ); uint32_t param12 = inPacket.getValAt< uint32_t >( 0x28 );
uint32_t param2 = inPacket.getValAt< uint32_t >( 0x2c ); uint32_t param2 = inPacket.getValAt< uint32_t >( 0x2C );
uint64_t param3 = inPacket.getValAt< uint64_t >( 0x38 ); uint64_t param3 = inPacket.getValAt< uint64_t >( 0x38 );
g_log.debug( "[" + std::to_string( m_pSession->getId() ) + "] Incoming action: " + g_log.debug( "[" + std::to_string( m_pSession->getId() ) + "] Incoming action: " +
@ -115,7 +115,7 @@ void Core::Network::GameConnection::actionHandler( const Packets::GamePacket& in
} }
case 0x69: // Cancel cast case 0x69: // Cancel cast
{ {
if( pPlayer->getCurrentAction() != nullptr ) if( pPlayer->getCurrentAction() )
pPlayer->getCurrentAction()->setInterrupted(); pPlayer->getCurrentAction()->setInterrupted();
break; break;
} }
@ -190,8 +190,6 @@ void Core::Network::GameConnection::actionHandler( const Packets::GamePacket& in
break; break;
case ZoneingType::FadeIn: case ZoneingType::FadeIn:
break; break;
default:
break;
} }
pPlayer->setZoningType( Common::ZoneingType::None ); pPlayer->setZoningType( Common::ZoneingType::None );
@ -216,7 +214,7 @@ void Core::Network::GameConnection::actionHandler( const Packets::GamePacket& in
pow( fromAetheryte->map_coord_y - targetAetheryte->map_coord_y, 2 ) ) / 2 ) + 100 ); pow( fromAetheryte->map_coord_y - targetAetheryte->map_coord_y, 2 ) ) / 2 ) + 100 );
// cap at 999 gil // cap at 999 gil
cost = cost > 999 ? 999 : cost; cost = cost > uint16_t{999} ? uint16_t{999} : cost;
bool insufficientGil = pPlayer->getCurrency( Inventory::CurrencyType::Gil ) < cost; bool insufficientGil = pPlayer->getCurrency( Inventory::CurrencyType::Gil ) < cost;
// todo: figure out what param1 really does // todo: figure out what param1 really does

View file

@ -90,8 +90,8 @@ void Core::Network::GameConnection::inventoryModifyHandler( const Packets::GameP
break; break;
default: default:
break; break;
} }
} }

View file

@ -300,7 +300,7 @@ void Core::Network::GameConnection::zoneLineHandler( const Packets::GamePacket&
auto pLine = g_zoneMgr.getZonePosition( zoneLineId ); auto pLine = g_zoneMgr.getZonePosition( zoneLineId );
Common::FFXIVARR_POSITION3 targetPos; Common::FFXIVARR_POSITION3 targetPos{};
uint32_t targetZone; uint32_t targetZone;
float rotation = 0.0f; float rotation = 0.0f;

View file

@ -314,7 +314,6 @@ void Zone::pushActor( Entity::ActorPtr pActor )
void Zone::removeActor( Entity::ActorPtr pActor ) void Zone::removeActor( Entity::ActorPtr pActor )
{ {
if( pActor->m_pCell ) if( pActor->m_pCell )
{ {
pActor->m_pCell->removeActor( pActor ); pActor->m_pCell->removeActor( pActor );

View file

@ -14,13 +14,9 @@ extern Core::Data::ExdData g_exdData;
namespace Core { namespace Core {
ZoneMgr::ZoneMgr() ZoneMgr::ZoneMgr() = default;
{
}
ZoneMgr::~ZoneMgr() ZoneMgr::~ZoneMgr() = default;
{
}
void ZoneMgr::loadZonePositionMap() void ZoneMgr::loadZonePositionMap()
{ {