Skip to content

Commit

Permalink
Next big batch of packet cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SapphireMordred committed Mar 6, 2023
1 parent aead026 commit 5fdbc90
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 145 deletions.
24 changes: 15 additions & 9 deletions src/world/Actor/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ void Player::learnSong( uint8_t songId, uint32_t itemId )
Util::valueToFlagByteIndexValue( songId, value, index );

m_orchestrion[ index ] |= value;

Network::Util::Player::sendActorControlSelf( *this, ToggleOrchestrionUnlock, songId, 1, itemId );
}

bool Player::hasReward( Common::UnlockEntry unlockId ) const
Expand Down Expand Up @@ -599,14 +601,14 @@ bool Player::hasMount( uint32_t mountId ) const
void Player::gainExp( uint32_t amount )
{
uint32_t currentExp = getExp();

uint16_t level = getLevel();
auto currentClass = static_cast< uint8_t >( getClass() );

if( level >= Common::MAX_PLAYER_LEVEL )
{
setExp( 0 );
if( currentExp != 0 )
Service< World::Manager::PlayerMgr >::ref().onGainExp( *this, 0 );
Network::Util::Player::sendActorControlSelf( *this, UpdateUiExp, currentClass, 0 );

return;
}
Expand All @@ -619,9 +621,7 @@ void Player::gainExp( uint32_t amount )
if( ( currentExp + amount ) >= neededExpToLevel )
{
// levelup
amount = ( currentExp + amount - neededExpToLevel ) > neededExpToLevelPlus1 ?
neededExpToLevelPlus1 - 1 :
( currentExp + amount - neededExpToLevel );
amount = ( currentExp + amount - neededExpToLevel ) > neededExpToLevelPlus1 ? neededExpToLevelPlus1 - 1 : ( currentExp + amount - neededExpToLevel );

if( level + 1 >= Common::MAX_PLAYER_LEVEL )
amount = 0;
Expand All @@ -630,11 +630,10 @@ void Player::gainExp( uint32_t amount )
levelUp();
}
else
{
setExp( currentExp + amount );
}

Service< World::Manager::PlayerMgr >::ref().onGainExp( *this, amount );
Network::Util::Player::sendActorControlSelf( *this, GainExpMsg, currentClass, amount );
Network::Util::Player::sendActorControlSelf( *this, UpdateUiExp, currentClass, getExp() );
}

void Player::levelUp()
Expand All @@ -643,8 +642,10 @@ void Player::levelUp()
m_mp = getMaxMp();

setLevel( getLevel() + 1 );
Network::Util::Player::sendActorControl( getInRangePlayerIds( true ), *this, LevelUpEffect, static_cast< uint8_t >( getClass() ), getLevel(), getLevel() - 1 );

Service< World::Manager::PlayerMgr >::ref().onLevelUp( *this );
auto& achvMgr = Common::Service< World::Manager::AchievementMgr >::ref();
achvMgr.progressAchievementByType< Common::Achievement::Type::Classjob >( *this, static_cast< uint32_t >( getClass() ) );
Service< World::Manager::MapMgr >::ref().updateQuests( *this );
}

Expand Down Expand Up @@ -727,6 +728,11 @@ void Player::setLevel( uint8_t level )
auto& exdData = Common::Service< Data::ExdData >::ref();
uint8_t classJobIndex = exdData.getRow< Excel::ClassJob >( static_cast< uint8_t >( getClass() ) )->data().WorkIndex;
m_classArray[ classJobIndex ] = level;

calculateStats();
Network::Util::Player::sendBaseParams( *this );
Network::Util::Player::sendHudParam( *this );
Network::Util::Player::sendStatusUpdate( *this );
}

void Player::setLevelForClass( uint8_t level, Common::ClassJob classjob )
Expand Down
8 changes: 6 additions & 2 deletions src/world/Manager/AchievementMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
#include <Util/Util.h>

#include "AchievementMgr.h"
#include "PlayerMgr.h"
#include <Network/Util/PlayerUtil.h>
#include <Network/CommonActorControl.h>

using namespace Sapphire;
using namespace Sapphire::Network;
using namespace Sapphire::Network::ActorControl;
using namespace Sapphire::Network::Packets;
using namespace Sapphire::World::Manager;

Expand Down Expand Up @@ -67,7 +69,9 @@ void AchievementMgr::unlockAchievement( Entity::Player& player, uint32_t achieve

// fire packets
player.setAchievementData( achvData );
Common::Service< World::Manager::PlayerMgr >::ref().onUnlockAchievement( player, achievementId );
Network::Util::Player::sendAchievementList( player );
Network::Util::Player::sendActorControl( player, AchievementComplete, achievementId );
Network::Util::Player::sendActorControl( player, AchievementObtainMsg, achievementId );

// check and add title to player
auto achvTitleId = achvExd->data().Title;
Expand Down
14 changes: 14 additions & 0 deletions src/world/Manager/HousingMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,20 @@ void HousingMgr::sendLandFlagsSlot( Entity::Player& player, Common::LandFlagsSlo

void HousingMgr::sendLandFlags( Entity::Player& player )
{
if( Sapphire::LandPtr pLand = getLandByOwnerId( player.getCharacterId() ) )
{
uint32_t state = 0;
if( pLand->getHouse() )
{
state |= Common::LandFlags::CHARA_HOUSING_LAND_DATA_FLAG_HOUSE;

// todo: remove this, debug for now
state |= Common::LandFlags::CHARA_HOUSING_LAND_DATA_FLAG_AETHERYTE;
}

player.setLandFlags( Common::LandFlagsSlot::Private, state, pLand->getLandIdent() );
}

auto landFlags = makeZonePacket< FFXIVIpcCharaHousing >( player.getId() );

landFlags->data().FcLands = player.getCharaLandData( Common::LandFlagsSlot::FreeCompany );
Expand Down
128 changes: 12 additions & 116 deletions src/world/Manager/PlayerMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#include <Network/PacketWrappers/ActorControlTargetPacket.h>
#include <Network/PacketWrappers/InitZonePacket.h>
#include <Network/PacketWrappers/PlayerSetupPacket.h>
#include <Network/PacketWrappers/ConditionPacket.h>
#include <Network/PacketWrappers/RestingPacket.h>
#include <Network/PacketWrappers/ServerNoticePacket.h>
#include <Network/PacketWrappers/ChatPacket.h>
#include <Network/PacketWrappers/HudParamPacket.h>
Expand Down Expand Up @@ -214,76 +212,6 @@ Sapphire::Entity::PlayerPtr PlayerMgr::syncPlayer( uint64_t characterId )
return pPlayer;
}

void PlayerMgr::onAchievementListChanged( Entity::Player& player )
{
auto achvData = player.getAchievementData();

auto achvPacket = makeZonePacket< FFXIVIpcAchievement >( player.getId() );
std::memcpy( &achvPacket->data().complete[ 0 ], &achvData.unlockList[ 0 ], sizeof( achvPacket->data().complete ) );
std::memcpy( &achvPacket->data().history[ 0 ], &achvData.history[ 0 ], sizeof( achvPacket->data().history ) );

server().queueForPlayer( player.getCharacterId(), achvPacket );
}

void PlayerMgr::onAchievementProgressChanged( Entity::Player& player, uint32_t achievementId )
{

auto& achvMgr = Common::Service< Manager::AchievementMgr >::ref();

auto achvProgress = achvMgr.getAchievementDataById( player, achievementId );

auto pAchvProgressPacket = makeActorControl( player.getId(), AchievementSetRate, achievementId, achvProgress.first, achvProgress.second );
server().queueForPlayer( player.getCharacterId(), pAchvProgressPacket );
}

void PlayerMgr::onUnlockAchievement( Entity::Player& player, uint32_t achievementId )
{
onAchievementListChanged( player );

server().queueForPlayer( player.getCharacterId(), makeActorControl( player.getId(), AchievementComplete, achievementId ) );
server().queueForPlayer( player.getCharacterId(), makeActorControl( player.getId(), AchievementObtainMsg, achievementId ) );
}

void PlayerMgr::onRestingTick( Entity::Player& player )
{
server().queueForPlayers( player.getInRangePlayerIds( true ), std::make_shared< RestingPacket >( player ) );
}

void PlayerMgr::onLevelUp( Entity::Player& player )
{
player.calculateStats();
Network::Util::Player::sendBaseParams( player );
Network::Util::Player::sendHudParam( player );

auto inRangePlayerIds = player.getInRangePlayerIds( true );

Network::Util::Player::sendActorControl( inRangePlayerIds, player, LevelUpEffect, static_cast< uint8_t >( player.getClass() ),
player.getLevel(), player.getLevel() - 1 );

Network::Util::Player::sendStatusUpdate( player );

auto& achvMgr = Common::Service< World::Manager::AchievementMgr >::ref();
achvMgr.progressAchievementByType< Common::Achievement::Type::Classjob >( player, static_cast< uint32_t >( player.getClass() ) );
}

void PlayerMgr::onGainExp( Entity::Player& player, uint32_t exp )
{

if( exp != 0 )
server().queueForPlayer( player.getCharacterId(), makeActorControlSelf( player.getId(), GainExpMsg,
static_cast< uint8_t >( player.getClass() ), exp ) );

server().queueForPlayer( player.getCharacterId(), makeActorControlSelf( player.getId(), UpdateUiExp,
static_cast< uint8_t >( player.getClass() ), player.getExp() ) );
}

void PlayerMgr::onUnlockOrchestrion( Entity::Player& player, uint8_t songId, uint32_t itemId )
{
player.learnSong( songId, itemId );

server().queueForPlayer( player.getCharacterId(), makeActorControlSelf( player.getId(), ToggleOrchestrionUnlock, songId, 1, itemId ) );
}

void PlayerMgr::onMobKill( Entity::Player& player, Entity::BNpc& bnpc )
{
auto& scriptMgr = Common::Service< Scripting::ScriptMgr >::ref();
Expand Down Expand Up @@ -325,7 +253,6 @@ void PlayerMgr::onMoveZone( Sapphire::Entity::Player& player )
{
auto& teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref();
auto& housingMgr = Common::Service< HousingMgr >::ref();
auto& partyMgr = Common::Service< World::Manager::PartyMgr >::ref();

auto pZone = teriMgr.getTerritoryByGuId( player.getTerritoryId() );
if( !pZone )
Expand All @@ -335,17 +262,14 @@ void PlayerMgr::onMoveZone( Sapphire::Entity::Player& player )
}
auto& teri = *pZone;

auto initPacket = makeZonePacket< FFXIVIpcLogin >( player.getId() );
initPacket->data().playerActorId = player.getId();

server().queueForPlayer( player.getCharacterId(), initPacket );
Network::Util::Player::sendLogin( player );

player.sendInventory();

if( player.isLogin() )
{
server().queueForPlayer( player.getCharacterId(), makeActorControlSelf( player.getId(), SetConfigFlags, player.getConfigFlags(), 1 ) );
server().queueForPlayer( player.getCharacterId(), makeActorControlSelf( player.getId(), SetMaxGearSets, player.getMaxGearSets() ) );
Network::Util::Player::sendActorControlSelf( player, SetConfigFlags, player.getConfigFlags(), 1 );
Network::Util::Player::sendActorControlSelf( player, SetMaxGearSets, player.getMaxGearSets() );
}

// set flags, will be reset automatically by zoning ( only on client side though )
Expand All @@ -355,63 +279,35 @@ void PlayerMgr::onMoveZone( Sapphire::Entity::Player& player )
Network::Util::Player::sendHuntingLog( player );

if( player.isLogin() )
server().queueForPlayer( player.getCharacterId(), makePlayerSetup( player ) );
Network::Util::Player::sendPlayerSetup( player );

Network::Util::Player::sendRecastGroups( player );
Network::Util::Player::sendBaseParams( player );
Network::Util::Player::sendActorControl( player, SetItemLevel, player.getItemLevel() );
if( player.isLogin() )
{
auto classInfo = makeZonePacket< FFXIVIpcChangeClass >( player.getId() );
classInfo->data().ClassJob = static_cast< uint8_t >( player.getClass() );
classInfo->data().Lv = player.getLevel();
classInfo->data().Lv1 = player.getLevel();
if( player.isLogin() )
classInfo->data().Login = 1;
server().queueForPlayer( player.getCharacterId(), classInfo );

server().queueForPlayer( player.getCharacterId(), makeActorControl( player.getId(), 0x112, 0x24 ) ); // unknown

auto contentFinderList = makeZonePacket< FFXIVIpcContentAttainFlags >( player.getId() );
std::memset( &contentFinderList->data(), 0xFF, sizeof( contentFinderList->data() ) );
server().queueForPlayer( player.getCharacterId(), contentFinderList );

Network::Util::Player::sendChangeClass( player );
Network::Util::Player::sendActorControl( player, 0x112, 0x24 ); // unknown
Network::Util::Player::sendContentAttainFlags( player );
player.clearSoldItems();
}

if( Sapphire::LandPtr pLand = housingMgr.getLandByOwnerId( player.getCharacterId() ) )
{
uint32_t state = 0;
if( pLand->getHouse() )
{
state |= Common::LandFlags::CHARA_HOUSING_LAND_DATA_FLAG_HOUSE;

// todo: remove this, debug for now
state |= Common::LandFlags::CHARA_HOUSING_LAND_DATA_FLAG_AETHERYTE;
}

player.setLandFlags( Common::LandFlagsSlot::Private, state, pLand->getLandIdent() );
}

housingMgr.sendLandFlags( player );

server().queueForPlayer( player.getCharacterId(), makeInitZone( player, teri ) );

teri.onPlayerZoneIn( player );
Network::Util::Player::sendInitZone( player );

if( player.isLogin() )
{
server().queueForPlayer( player.getCharacterId(),
{
makeZonePacket< FFXIVIpcDailyQuests >( player.getId() ),
makeZonePacket< FFXIVIpcQuestRepeatFlags >( player.getId() )
} );
Network::Util::Player::sendDailyQuests( player );
Network::Util::Player::sendQuestRepeatFlags( player );

auto &questMgr = Common::Service< World::Manager::QuestMgr >::ref();
questMgr.sendQuestsInfo( player );
Network::Util::Player::sendGrandCompany( player );
}

teri.onPlayerZoneIn( player );

}

void PlayerMgr::onUpdate( Entity::Player& player, uint64_t tickCount )
Expand Down
12 changes: 0 additions & 12 deletions src/world/Manager/PlayerMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ namespace Sapphire::World::Manager
bool loadPlayers();
Entity::PlayerPtr syncPlayer( uint64_t characterId );

void onUnlockAchievement( Sapphire::Entity::Player& player, uint32_t achievementId );

void onRestingTick( Sapphire::Entity::Player& player );

void onLevelUp( Sapphire::Entity::Player& player );

void onGainExp( Sapphire::Entity::Player& player, uint32_t exp );

void onUnlockOrchestrion( Sapphire::Entity::Player& player, uint8_t songId, uint32_t itemId );

void onMobKill( Sapphire::Entity::Player& player, Sapphire::Entity::BNpc& bnpc );

void sendLoginMessage( Sapphire::Entity::Player& player );
Expand All @@ -43,8 +33,6 @@ namespace Sapphire::World::Manager
void onMoveZone( Sapphire::Entity::Player& player );

void onUpdate( Sapphire::Entity::Player& player, uint64_t tickCount );
void onAchievementListChanged( Sapphire::Entity::Player& player );
void onAchievementProgressChanged( Sapphire::Entity::Player& player, uint32_t achievementId );

//////////// Helpers

Expand Down
6 changes: 2 additions & 4 deletions src/world/Network/Handlers/GMCommandHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ void Sapphire::Network::GameConnection::gmCommandHandler( const Packets::FFXIVAR
{
targetPlayer->setLevel( static_cast< uint8_t >( param1 ) );
PlayerMgr::sendServerNotice( player, "Level for {0} was set to {1}", targetPlayer->getName(), param1 );
auto playerMgr = Common::Service< World::Manager::PlayerMgr >::ref();
playerMgr.onLevelUp(player);
break;
}
case GmCommand::Race:
Expand Down Expand Up @@ -330,13 +328,13 @@ void Sapphire::Network::GameConnection::gmCommandHandler( const Packets::FFXIVAR
if( param2 == 0 )
{
for( uint8_t i = 0; i < 255; i++ )
Service< World::Manager::PlayerMgr >::ref().onUnlockOrchestrion( *targetPlayer, i, 0 );
targetPlayer->learnSong( i, 0 );

PlayerMgr::sendServerNotice( player, "All Songs for {0} were turned on.", targetPlayer->getName() );
}
else
{
Service< World::Manager::PlayerMgr >::ref().onUnlockOrchestrion( *targetPlayer, static_cast< uint8_t >( param2 ), 0 );
targetPlayer->learnSong( static_cast< uint8_t >( param2 ), 0 );
PlayerMgr::sendServerNotice( player, "Song {0} for {1} was turned on.", param2, targetPlayer->getName() );
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/world/Network/Handlers/PacketCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "Manager/HousingMgr.h"
#include "Manager/WarpMgr.h"
#include "Manager/AchievementMgr.h"

#include "Network/GameConnection.h"

Expand Down Expand Up @@ -600,12 +601,15 @@ void Sapphire::Network::GameConnection::commandHandler( const Packets::FFXIVARR_
}
case PacketCommand::ACHIEVEMENT_REQUEST_RATE:
{
playerMgr().onAchievementProgressChanged( player, data.Arg0 );
auto achievementId = data.Arg0;
auto& achvMgr = Common::Service< AchievementMgr >::ref();
auto achvProgress = achvMgr.getAchievementDataById( player, achievementId );
Network::Util::Player::sendActorControl( player, AchievementSetRate, achievementId, achvProgress.first, achvProgress.second );
break;
}
case PacketCommand::ACHIEVEMENT_REQUEST:
{
playerMgr().onAchievementListChanged( player );
Network::Util::Player::sendAchievementList( player );
break;
}
case PacketCommand::TELEPO_INQUIRY: // Teleport
Expand Down
Loading

0 comments on commit 5fdbc90

Please sign in to comment.