1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-30 08:07:46 +00:00

Revert "Merge and minor cleanup"

This reverts commit 4c35944433.
This commit is contained in:
Mordred 2023-02-10 21:28:34 +01:00
parent 4c35944433
commit 4a8092b71e
4 changed files with 122 additions and 28 deletions

View file

@ -131,7 +131,11 @@ void Player::unload()
setLoadingComplete( false ); setLoadingComplete( false );
// unset player for removal // unset player for removal
setMarkedForRemoval( false ); setMarkedForRemoval( false );
// send updates to mgrs
if( getPartyId() != 0 )
partyMgr.onMemberDisconnect( *this );
fcMgr.onFcLogout( getCharacterId() );
syncLastDBWrite(); syncLastDBWrite();
} }

View file

@ -13,8 +13,8 @@
#include <Manager/HousingMgr.h> #include <Manager/HousingMgr.h>
#include <Manager/FreeCompanyMgr.h> #include <Manager/FreeCompanyMgr.h>
#include "Script/ScriptMgr.h" #include <Script/ScriptMgr.h>
#include "WorldServer.h" #include <WorldServer.h>
#include <Common.h> #include <Common.h>
#include <Network/PacketContainer.h> #include <Network/PacketContainer.h>
@ -23,19 +23,23 @@
#include <Network/PacketDef/Zone/ServerZoneDef.h> #include <Network/PacketDef/Zone/ServerZoneDef.h>
#include <Network/PacketWrappers/ActorControlPacket.h> #include <Network/PacketWrappers/ActorControlPacket.h>
#include <Network/PacketWrappers/ActorControlSelfPacket.h> #include <Network/PacketWrappers/ActorControlSelfPacket.h>
#include "Network/PacketWrappers/ActorControlTargetPacket.h" #include <Network/PacketWrappers/ActorControlTargetPacket.h>
#include "Network/PacketWrappers/InitZonePacket.h" #include <Network/PacketWrappers/InitZonePacket.h>
#include <Network/PacketWrappers/ModelEquipPacket.h> #include <Network/PacketWrappers/ModelEquipPacket.h>
#include "Network/PacketWrappers/PlayerSetupPacket.h" #include <Network/PacketWrappers/PlayerSetupPacket.h>
#include <Network/PacketWrappers/PlayerStateFlagsPacket.h> #include <Network/PacketWrappers/PlayerStateFlagsPacket.h>
#include <Network/PacketWrappers/UpdateHpMpTpPacket.h> #include <Network/PacketWrappers/UpdateHpMpTpPacket.h>
#include "Network/PacketWrappers/ServerNoticePacket.h" #include <Network/PacketWrappers/ServerNoticePacket.h>
#include "Network/PacketWrappers/ChatPacket.h" #include <Network/PacketWrappers/ChatPacket.h>
#include "Network/PacketWrappers/HudParamPacket.h" #include <Network/PacketWrappers/HudParamPacket.h>
#include <Actor/Player.h> #include <Actor/Player.h>
#include <Actor/BNpc.h> #include <Actor/BNpc.h>
#include <Inventory/Item.h>
#include <Util/UtilMath.h>
using namespace Sapphire; using namespace Sapphire;
using namespace Sapphire::World::Manager; using namespace Sapphire::World::Manager;
using namespace Sapphire::Network::Packets; using namespace Sapphire::Network::Packets;
@ -163,7 +167,11 @@ void PlayerMgr::onPlayerStatusUpdate( Entity::Player& player )
void PlayerMgr::onPlayerHpMpTpChanged( Entity::Player& player ) void PlayerMgr::onPlayerHpMpTpChanged( Entity::Player& player )
{ {
auto& server = Common::Service< World::WorldServer >::ref();
player.sendToInRangeSet( std::make_shared< UpdateHpMpTpPacket >( player ), true ); player.sendToInRangeSet( std::make_shared< UpdateHpMpTpPacket >( player ), true );
auto hudParamPacket = makeHudParam( player );
server.queueForPlayer( player.getCharacterId(), hudParamPacket );
} }
void PlayerMgr::onPlayerItemLevelUpdate( Entity::Player& player ) void PlayerMgr::onPlayerItemLevelUpdate( Entity::Player& player )
@ -213,6 +221,8 @@ void PlayerMgr::onGainExp( Entity::Player& player, uint32_t exp )
void PlayerMgr::onUnlockOrchestrion( Entity::Player& player, uint8_t songId, uint32_t itemId ) void PlayerMgr::onUnlockOrchestrion( Entity::Player& player, uint8_t songId, uint32_t itemId )
{ {
player.learnSong( songId, itemId );
auto& server = Common::Service< World::WorldServer >::ref(); auto& server = Common::Service< World::WorldServer >::ref();
server.queueForPlayer( player.getCharacterId(), makeActorControlSelf( player.getId(), ToggleOrchestrionUnlock, songId, 1, itemId ) ); server.queueForPlayer( player.getCharacterId(), makeActorControlSelf( player.getId(), ToggleOrchestrionUnlock, songId, 1, itemId ) );
} }
@ -225,21 +235,47 @@ void PlayerMgr::onChangeGear( Entity::Player& player )
void PlayerMgr::onGcUpdate( Entity::Player& player ) void PlayerMgr::onGcUpdate( Entity::Player& player )
{ {
auto& server = Common::Service< World::WorldServer >::ref(); auto& server = Common::Service< World::WorldServer >::ref();
auto gcAffPacket = makeZonePacket< FFXIVIpcGrandCompany >( player.getId() ); auto gcAffPacket = makeZonePacket< FFXIVIpcGrandCompany >( player.getId() );
gcAffPacket->data().ActiveCompanyId = player.getGc(); gcAffPacket->data().ActiveCompanyId = player.getGc();
gcAffPacket->data().MaelstromRank = player.getGcRankArray()[ 0 ]; gcAffPacket->data().MaelstromRank = player.getGcRankArray()[ 0 ];
gcAffPacket->data().TwinAdderRank = player.getGcRankArray()[ 1 ]; gcAffPacket->data().TwinAdderRank = player.getGcRankArray()[ 1 ];
gcAffPacket->data().ImmortalFlamesRank = player.getGcRankArray()[ 2 ]; gcAffPacket->data().ImmortalFlamesRank = player.getGcRankArray()[ 2 ];
server.queueForPlayer( player.getCharacterId(), gcAffPacket ); server.queueForPlayer( player.getCharacterId(), gcAffPacket );
} }
void PlayerMgr::onSetGc( Entity::Player& player, uint8_t gc )
{
player.setGc( gc );
onGcUpdate( player );
}
void PlayerMgr::onSetGcRank( Entity::Player& player, uint8_t gc, uint8_t rank )
{
player.setGcRankAt( gc, rank );
onGcUpdate( player );
}
void PlayerMgr::onCompanionUpdate( Entity::Player& player, uint8_t companionId ) void PlayerMgr::onCompanionUpdate( Entity::Player& player, uint8_t companionId )
{ {
auto& exdData = Common::Service< Data::ExdData >::ref();
auto companion = exdData.getRow< Excel::Companion >( companionId );
if( !companion )
return;
player.setCompanion( companionId );
player.sendToInRangeSet( makeActorControl( player.getId(), ActorControlType::ToggleCompanion, companionId ), true ); player.sendToInRangeSet( makeActorControl( player.getId(), ActorControlType::ToggleCompanion, companionId ), true );
} }
void PlayerMgr::onMountUpdate( Entity::Player& player, uint32_t mountId ) void PlayerMgr::onMountUpdate( Entity::Player& player, uint32_t mountId )
{ {
Common::Service< World::Manager::PlayerMgr >::ref().onMountUpdate( player, mountId );
if( mountId != 0 ) if( mountId != 0 )
{ {
player.sendToInRangeSet( makeActorControl( player.getId(), ActorControlType::SetStatus, player.sendToInRangeSet( makeActorControl( player.getId(), ActorControlType::SetStatus,
@ -330,17 +366,6 @@ void PlayerMgr::onLogin( Entity::Player& player )
} }
} }
void PlayerMgr::onLogout( Entity::Player& player )
{
auto& partyMgr = Common::Service< World::Manager::PartyMgr >::ref();
auto& fcMgr = Common::Service< World::Manager::FreeCompanyMgr >::ref();
// send updates to mgrs
if( player.getPartyId() != 0 )
partyMgr.onMemberDisconnect( player );
fcMgr.onFcLogout( player.getCharacterId() );
}
void PlayerMgr::onDeath( Entity::Player& player ) void PlayerMgr::onDeath( Entity::Player& player )
{ {
auto& scriptMgr = Common::Service< Scripting::ScriptMgr >::ref(); auto& scriptMgr = Common::Service< Scripting::ScriptMgr >::ref();
@ -436,6 +461,73 @@ void PlayerMgr::onZone( Sapphire::Entity::Player& player )
} }
void PlayerMgr::onUpdate( Entity::Player& player, uint64_t tickCount )
{
if( player.getHp() <= 0 && player.getStatus() != Common::ActorStatus::Dead )
{
player.die();
onDeath( player );
}
if( !player.isAlive() )
return;
if( !player.checkAction() )
{
if( player.getTargetId() && player.getStance() == Common::Stance::Active && player.isAutoattackOn() )
{
auto mainWeap = player.getItemAt( Common::GearSet0, Common::GearSetSlot::MainHand );
// @TODO i dislike this, iterating over all in range actors when you already know the id of the actor you need...
for( const auto& actor : player.getInRangeActors() )
{
if( actor->getId() == player.getTargetId() && actor->getAsChara()->isAlive() && mainWeap )
{
auto chara = actor->getAsChara();
// default autoattack range
float range = 3.f + chara->getRadius() + player.getRadius() * 0.5f;
// default autoattack range for ranged classes
auto classJob = player.getClass();
if( classJob == Common::ClassJob::Machinist || classJob == Common::ClassJob::Bard || classJob == Common::ClassJob::Archer )
range = 25.f + chara->getRadius() + player.getRadius() * 0.5f;
if( Common::Util::distance( player.getPos(), actor->getPos() ) <= range )
{
if( ( tickCount - player.getLastAttack() ) > mainWeap->getDelay() )
{
player.setLastAttack( tickCount );
player.autoAttack( actor->getAsChara() );
}
}
}
}
}
}
}
void PlayerMgr::onSetStateFlag( Sapphire::Entity::Player& player, Common::PlayerStateFlag flag )
{
auto prevOnlineStatus = player.getOnlineStatus();
player.setStateFlag( flag );
auto newOnlineStatus = player.getOnlineStatus();
onSendStateFlags( player, prevOnlineStatus != newOnlineStatus );
}
void PlayerMgr::onUnsetStateFlag( Sapphire::Entity::Player& player, Common::PlayerStateFlag flag )
{
auto prevOnlineStatus = player.getOnlineStatus();
player.unsetStateFlag( flag );
auto newOnlineStatus = player.getOnlineStatus();
onSendStateFlags( player, prevOnlineStatus != newOnlineStatus );
}
////////// Helper /////////// ////////// Helper ///////////

View file

@ -57,7 +57,6 @@ class PlayerMgr
void onHateListChanged( Sapphire::Entity::Player& player ); void onHateListChanged( Sapphire::Entity::Player& player );
void onLogin( Sapphire::Entity::Player& player ); void onLogin( Sapphire::Entity::Player& player );
void onLogout( Sapphire::Entity::Player& player );
void onDeath( Sapphire::Entity::Player& player ); void onDeath( Sapphire::Entity::Player& player );

View file

@ -1,4 +1,5 @@
#include <filesystem> #include <filesystem>
#include <time.h>
#include <Util/Util.h> #include <Util/Util.h>
#include <Network/PacketContainer.h> #include <Network/PacketContainer.h>
@ -77,9 +78,6 @@ void Sapphire::World::Session::close()
// remove the session from the player // remove the session from the player
if( m_pPlayer ) if( m_pPlayer )
{ {
auto& playerMgr = Common::Service< World::Manager::PlayerMgr >::ref();
playerMgr.onLogout( *m_pPlayer );
m_pPlayer->unload(); m_pPlayer->unload();
} }
} }
@ -118,7 +116,7 @@ void Sapphire::World::Session::startReplay( const std::string& path )
{ {
if( !fs::exists( path ) ) if( !fs::exists( path ) )
{ {
PlayerMgr::sendDebug( *getPlayer(), "Couldn't find folder {}.", path ); PlayerMgr::sendDebug( *getPlayer(), "Couldn't find folder." );
return; return;
} }
@ -131,11 +129,11 @@ void Sapphire::World::Session::startReplay( const std::string& path )
{ {
// Get the filename of the current element // Get the filename of the current element
auto fileName = it->path().filename().string(); auto fileName = it->path().filename().string();
auto unixTime = std::stoull( fileName.substr( 0, 14 ) ); auto unixTime = std::stoull( fileName.substr( 0, 14 ).c_str() );
if( unixTime > 1000000000 ) if( unixTime > 1000000000 )
{ {
loadedSets.emplace_back( unixTime, it->path().string() ); loadedSets.push_back( std::tuple< uint64_t, std::string >( unixTime, it->path().string() ) );
} }
} }
@ -149,7 +147,8 @@ void Sapphire::World::Session::startReplay( const std::string& path )
for( auto set : loadedSets ) for( auto set : loadedSets )
{ {
m_replayCache.emplace_back( Common::Util::getTimeMs() + ( std::get< 0 >( set ) - startTime ), std::get< 1 >( set ) ); m_replayCache.push_back( std::tuple< uint64_t, std::string >(
Common::Util::getTimeMs() + ( std::get< 0 >( set ) - startTime ), std::get< 1 >( set ) ) );
Logger::info( "Registering {0} for {1}", std::get< 1 >( set ), std::get< 0 >( set ) - startTime ); Logger::info( "Registering {0} for {1}", std::get< 1 >( set ), std::get< 0 >( set ) - startTime );
} }
@ -178,7 +177,7 @@ void Sapphire::World::Session::processReplay()
at++; at++;
} }
if( m_replayCache.empty() ) if( m_replayCache.size() == 0 )
m_isReplaying = false; m_isReplaying = false;
} }