chore: Move ghosting functionality to component

Tested that ghosting still works and players are still firing off the OnPlayerLeave and relevant handlers.
This commit is contained in:
David Markowitz
2024-01-12 22:56:03 -08:00
parent 1c5b8cc265
commit d3eb5a56d9
10 changed files with 159 additions and 143 deletions

View File

@@ -37,6 +37,7 @@
#include "eGameMessageType.h"
#include "ePlayerFlag.h"
#include "dConfig.h"
#include "GhostComponent.h"
#include "StringifiedEnum.h"
void GameMessageHandler::HandleMessage(RakNet::BitStream* inStream, const SystemAddress& sysAddr, LWOOBJID objectID, eGameMessageType messageID) {
@@ -108,9 +109,9 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream* inStream, const System
GameMessages::SendRestoreToPostLoadStats(entity, sysAddr);
entity->SetPlayerReadyForUpdates();
auto* player = dynamic_cast<Player*>(entity);
if (player != nullptr) {
player->ConstructLimboEntities();
auto* ghostComponent = entity->GetComponent<GhostComponent>();
if (ghostComponent != nullptr) {
ghostComponent->ConstructLimboEntities();
}
InventoryComponent* inv = entity->GetComponent<InventoryComponent>();
@@ -137,14 +138,14 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream* inStream, const System
Entity* zoneControl = Game::entityManager->GetZoneControlEntity();
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) {
script->OnPlayerLoaded(zoneControl, player);
script->OnPlayerLoaded(zoneControl, entity);
}
std::vector<Entity*> scriptedActs = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::SCRIPT);
for (Entity* scriptEntity : scriptedActs) {
if (scriptEntity->GetObjectID() != zoneControl->GetObjectID()) { // Don't want to trigger twice on instance worlds
for (CppScripts::Script* script : CppScripts::GetEntityScripts(scriptEntity)) {
script->OnPlayerLoaded(scriptEntity, player);
script->OnPlayerLoaded(scriptEntity, entity);
}
}
}

View File

@@ -78,6 +78,7 @@
#include "RailActivatorComponent.h"
#include "LevelProgressionComponent.h"
#include "DonationVendorComponent.h"
#include "GhostComponent.h"
// Message includes:
#include "dZoneManager.h"
@@ -4605,7 +4606,8 @@ void GameMessages::HandleToggleGhostReferenceOverride(RakNet::BitStream* inStrea
auto* player = PlayerManager::GetPlayer(sysAddr);
if (player != nullptr) {
player->SetGhostOverride(bOverride);
auto* ghostComponent = entity->GetComponent<GhostComponent>();
if (ghostComponent) ghostComponent->SetGhostOverride(bOverride);
Game::entityManager->UpdateGhosting(player);
}
@@ -4620,7 +4622,8 @@ void GameMessages::HandleSetGhostReferencePosition(RakNet::BitStream* inStream,
auto* player = PlayerManager::GetPlayer(sysAddr);
if (player != nullptr) {
player->SetGhostOverridePoint(position);
auto* ghostComponent = entity->GetComponent<GhostComponent>();
if (ghostComponent) ghostComponent->SetGhostOverridePoint(position);
Game::entityManager->UpdateGhosting(player);
}