Skip to content

Commit

Permalink
feat: transfer ownership to party leader on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed May 29, 2022
1 parent 991337b commit 7c6a9ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
30 changes: 16 additions & 14 deletions Code/client/Services/Generic/CharacterService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,21 @@ CharacterService::CharacterService(World& aWorld, entt::dispatcher& aDispatcher,

bool CharacterService::TakeOwnership(const uint32_t acFormId, const uint32_t acServerId, const entt::entity acEntity) const noexcept
{
Actor* const pActor = Cast<Actor>(TESForm::GetById(acFormId));
Actor* pActor = Cast<Actor>(TESForm::GetById(acFormId));
if (!pActor)
{
spdlog::error("Cannot find actor to take control over, form id: {:X}, server id: {:X}", acFormId, acServerId);
return false;
}

ActorExtension* pExtension = pActor->GetExtension();
if (pExtension->IsRemotePlayer())
{
spdlog::error("Cannot take control over remote player actor, form id: {:X}, server id: {:X}", acFormId, acServerId);
return false;
}

pActor->GetExtension()->SetRemote(false);
pExtension->SetRemote(false);

// TODO(cosideci): this should be done differently.
// Send an ownership claim request, and have the server broadcast the result.
Expand All @@ -136,6 +146,7 @@ bool CharacterService::TakeOwnership(const uint32_t acFormId, const uint32_t acS
m_world.remove<RemoteComponent, InterpolationComponent, RemoteAnimationComponent,
FaceGenComponent, CacheComponent, WaitingFor3D>(acEntity);

// TODO(cosideci): send current local data of actor with it(?)
RequestOwnershipClaim request;
request.ServerId = acServerId;

Expand Down Expand Up @@ -1221,20 +1232,11 @@ void CharacterService::ProcessNewEntity(entt::entity aEntity) const noexcept
{
if (m_world.GetPartyService().IsLeader() && !pActor->IsTemporary())
{
pActor->GetExtension()->SetRemote(false);

m_world.emplace<LocalComponent>(aEntity, pRemoteComponent->Id);
m_world.emplace<LocalAnimationComponent>(aEntity);
m_world.remove<RemoteComponent, InterpolationComponent, RemoteAnimationComponent,
FaceGenComponent, CacheComponent, WaitingFor3D>(aEntity);

spdlog::critical("Sending ownership claim for actor {:X} with server id {:X}", pActor->formID,
spdlog::info("Sending ownership claim for actor {:X} with server id {:X}", pActor->formID,
pRemoteComponent->Id);

// TODO(cosideci): send current local data of actor with it(?)
RequestOwnershipClaim request;
request.ServerId = pRemoteComponent->Id;
m_transport.Send(request);
TakeOwnership(pActor->formID, pRemoteComponent->Id, aEntity);

return;
}
else
Expand Down
2 changes: 0 additions & 2 deletions Code/client/Services/Generic/PartyService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ void PartyService::OnPartyJoined(const NotifyPartyJoined& acPartyJoined) noexcep
m_partyMembers = acPartyJoined.PlayerIds;

// Takes ownership of all actors
/*
if (m_isLeader)
{
auto view = m_world.view<FormIdComponent>(entt::exclude<ObjectComponent>);
Expand All @@ -103,7 +102,6 @@ void PartyService::OnPartyJoined(const NotifyPartyJoined& acPartyJoined) noexcep
m_world.GetCharacterService().ProcessNewEntity(entity);
}
}
*/
}

void PartyService::DestroyParty() noexcept
Expand Down

0 comments on commit 7c6a9ed

Please sign in to comment.