Skip to content

Commit

Permalink
fix: missing player characters
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed Jun 15, 2022
1 parent 32e87f8 commit 6fb4a9c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
19 changes: 13 additions & 6 deletions Code/client/Services/Generic/CharacterService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ void CharacterService::OnAssignCharacter(const AssignCharacterResponse& acMessag
return;
}

// TODO: how could this possibly trigger?
// it's kinda interfering with my WaitingFor3D code
if (acMessage.PlayerId != 0)
m_world.emplace_or_replace<PlayerComponent>(cEntity, acMessage.PlayerId);

Expand Down Expand Up @@ -465,9 +467,6 @@ void CharacterService::OnCharacterSpawn(const CharacterSpawnRequest& acMessage)

spdlog::info("CharacterSpawnRequest, server id: {:X}, form id: {:X}", acMessage.ServerId, pActor->formID);

// TODO(cosideci): why?
m_world.emplace_or_replace<FormIdComponent>(*entity, pActor->formID);

if (pActor->IsDisabled())
pActor->Enable();

Expand Down Expand Up @@ -1446,7 +1445,7 @@ void CharacterService::CancelServerAssignment(const entt::entity aEntity, const
if (m_world.all_of<RemoteComponent>(aEntity))
{
Actor* pActor = Cast<Actor>(TESForm::GetById(aFormId));
m_world.remove<PlayerComponent>(aEntity);
m_world.remove<PlayerComponent>(aEntity);

if (pActor)
{
Expand Down Expand Up @@ -1526,7 +1525,10 @@ Actor* CharacterService::CreateCharacterForEntity(entt::entity aEntity) const no
auto* pInterpolationComponent = m_world.try_get<InterpolationComponent>(aEntity);

if (!pWaitingFor3D || !pInterpolationComponent)
{
spdlog::error(__FUNCTION__ ": could not find WaitingFor3D or InterpolationComponent");
return nullptr;
}

auto& acMessage = pWaitingFor3D->SpawnRequest;

Expand Down Expand Up @@ -1558,10 +1560,13 @@ Actor* CharacterService::CreateCharacterForEntity(entt::entity aEntity) const no
pActor = Actor::Create(pNpc);
}

auto& remoteComponent = m_world.get<RemoteComponent>(aEntity);

if (!pActor)
{
spdlog::error(__FUNCTION__ ": could not spawn actor for remote server id {:X}.", remoteComponent.Id);
return nullptr;

m_world.emplace_or_replace<FormIdComponent>(aEntity, pActor->formID);
}

pActor->GetExtension()->SetRemote(true);
pActor->rotation.x = acMessage.Rotation.x;
Expand All @@ -1580,6 +1585,8 @@ Actor* CharacterService::CreateCharacterForEntity(entt::entity aEntity) const no
if (pActor->IsDead() != acMessage.IsDead)
acMessage.IsDead ? pActor->Kill() : pActor->Respawn();

spdlog::info("Spawned character for entity, server id: {:X}", remoteComponent.Id);

return pActor;
}

Expand Down
13 changes: 7 additions & 6 deletions Code/client/Services/Generic/OverlayService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ OverlayService::OverlayService(World& aWorld, TransportService& transport, entt:
m_playerJoinedConnection = aDispatcher.sink<NotifyPlayerJoined>().connect<&OverlayService::OnPlayerJoined>(this);
m_playerLeftConnection = aDispatcher.sink<NotifyPlayerLeft>().connect<&OverlayService::OnPlayerLeft>(this);
m_playerDialogueConnection = aDispatcher.sink<NotifyPlayerDialogue>().connect<&OverlayService::OnPlayerDialogue>(this);
m_playerAddedConnection = m_world.on_construct<PlayerComponent>().connect<&OverlayService::OnPlayerComponentAdded>(this);
m_playerAddedConnection = m_world.on_update<PlayerComponent>().connect<&OverlayService::OnPlayerComponentAdded>(this);
m_playerAddedConnection = m_world.on_destroy<WaitingFor3D>().connect<&OverlayService::OnWaitingFor3DRemoved>(this);
m_playerRemovedConnection = m_world.on_destroy<PlayerComponent>().connect<&OverlayService::OnPlayerComponentRemoved>(this);
m_playerLevelConnection = aDispatcher.sink<NotifyPlayerLevel>().connect<&OverlayService::OnPlayerLevel>(this);
m_cellChangedConnection = aDispatcher.sink<NotifyPlayerCellChanged>().connect<&OverlayService::OnPlayerCellChanged>(this);
Expand Down Expand Up @@ -292,8 +291,12 @@ void OverlayService::OnDisconnectedEvent(const DisconnectedEvent&) noexcept
SendSystemMessage("Disconnected from server");
}

void OverlayService::OnPlayerComponentAdded(entt::registry& aRegistry, entt::entity aEntity) const noexcept
void OverlayService::OnWaitingFor3DRemoved(entt::registry& aRegistry, entt::entity aEntity) const noexcept
{
const auto* pPlayerComponent = m_world.try_get<PlayerComponent>(aEntity);
if (!pPlayerComponent)
return;

const auto& formIdComponent = m_world.get<FormIdComponent>(aEntity);

Actor* pActor = Cast<Actor>(TESForm::GetById(formIdComponent.Id));
Expand All @@ -305,10 +308,8 @@ void OverlayService::OnPlayerComponentAdded(entt::registry& aRegistry, entt::ent

float percentage = CalculateHealthPercentage(pActor);

const auto& playerComponent = m_world.get<PlayerComponent>(aEntity);

auto pArguments = CefListValue::Create();
pArguments->SetInt(0, playerComponent.Id);
pArguments->SetInt(0, pPlayerComponent->Id);
pArguments->SetInt(1, static_cast<int>(percentage));

m_pOverlay->ExecuteAsync("setPlayer3dLoaded", pArguments);
Expand Down
2 changes: 1 addition & 1 deletion Code/client/Services/OverlayService.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct OverlayService
void OnUpdate(const UpdateEvent&) noexcept;
void OnConnectedEvent(const ConnectedEvent&) noexcept;
void OnDisconnectedEvent(const DisconnectedEvent&) noexcept;
void OnPlayerComponentAdded(entt::registry& aRegistry, entt::entity aEntity) const noexcept;
void OnWaitingFor3DRemoved(entt::registry& aRegistry, entt::entity aEntity) const noexcept;
void OnPlayerComponentRemoved(entt::registry& aRegistry, entt::entity aEntity) const noexcept;
void OnConnectionError(const ConnectionErrorEvent& acConnectedEvent) const noexcept;
void OnChatMessageReceived(const NotifyChatMessageBroadcast&) noexcept;
Expand Down

0 comments on commit 6fb4a9c

Please sign in to comment.