fix: Players are able to join a race without having a race car (#1149)

* Fixed Scrapped Racecar Stuck Issue

Changed RacingControlComponent to boot players back to the hub world when trying to race after dismantling a vehicle.

* Modified OnPlayerLoaded to fix Vehicle Inventory issue

* Change 3

---------

Co-authored-by: David Markowitz <EmosewaMC@gmail.com>
This commit is contained in:
TAHuntling 2023-10-08 19:38:48 -05:00 committed by GitHub
parent 74cc4176e1
commit 288991ef49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,23 +61,27 @@ RacingControlComponent::RacingControlComponent(Entity* parent)
RacingControlComponent::~RacingControlComponent() {}
void RacingControlComponent::OnPlayerLoaded(Entity* player) {
// If the race has already started, send the player back to the main world.
if (m_Loaded) {
auto* playerInstance = dynamic_cast<Player*>(player);
playerInstance->SendToZone(m_MainWorld);
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
if (!inventoryComponent) {
return;
}
const auto objectID = player->GetObjectID();
auto* vehicle = inventoryComponent->FindItemByLot(8092);
// If the race has already started, send the player back to the main world.
if (m_Loaded || !vehicle) {
auto* playerInstance = dynamic_cast<Player*>(player);
if(playerInstance){
playerInstance->SendToZone(m_MainWorld);
}
return;
}
m_LoadedPlayers++;
Game::logger->Log("RacingControlComponent", "Loading player %i",
m_LoadedPlayers);
m_LobbyPlayers.push_back(objectID);
m_LobbyPlayers.push_back(player->GetObjectID());
}
void RacingControlComponent::LoadPlayerVehicle(Entity* player,
@ -100,8 +104,13 @@ void RacingControlComponent::LoadPlayerVehicle(Entity* player,
if (item == nullptr) {
Game::logger->Log("RacingControlComponent", "Failed to find item");
auto* playerInstance = dynamic_cast<Player*>(player);
if(playerInstance){
m_LoadedPlayers--;
playerInstance->SendToZone(m_MainWorld);
}
return;
}
// Calculate the vehicle's starting position.