Untitled
unknown
plain_text
7 months ago
2.1 kB
9
Indexable
void ATPC_BasePlayerController::RequestAssignTeam_Implementation(int32 InTeamIndex)
{
if (!HasAuthority()) return;
ATAC_PlayerState* PS = GetPlayerState<ATAC_PlayerState>();
if (!PS) return;
if (PS->IsInAnySquad())
{
PS->ServerLeaveSquad();
}
bool bIsAutoAssign = (PS->GetTeamIndex() < 0);
int32 OldTeamCount = GetNumPlayersInTeam(PS->GetTeamIndex());
int32 NewTeamCount = GetNumPlayersInTeam(InTeamIndex);
int32 HypotheticalOld = bIsAutoAssign ? OldTeamCount : (OldTeamCount - 1);
int32 HypotheticalNew = NewTeamCount + 1;
int32 Difference = HypotheticalNew - HypotheticalOld;
bool bIsBalanced = bIsAutoAssign
? (FMath::Abs(Difference) <= 1)
: (FMath::Abs(Difference) <= 2);
bool bUnderMax = (HypotheticalNew <= 50);
if (bIsBalanced && bUnderMax)
{
PS->ServerAssignTeam(InTeamIndex);
PS->SelectedRoleData.RoleID = -1;
PS->SelectedRoleData.RoleName = NAME_None;
if (ATAC_GameState* GS = GetWorld()->GetGameState<ATAC_GameState>())
{
GS->BroadcastPlayerCounts();
}
if (AFOW_Handler* FOWHandler = AFOW_Handler::GetFOWHandler(this))
{
if (AFOW_FogStateReplication_Server* ServerFog = Cast<AFOW_FogStateReplication_Server>(FOWHandler->GetFogStateReplication()))
{
AFOW_FogStateReplication* ClientFog = ServerFog->FindClientNetworkFromController(this);
if (ClientFog)
{
if (AFOW_FogStateReplication_Client* ClientFogC = Cast<AFOW_FogStateReplication_Client>(ClientFog))
{
ClientFogC->ServerRPC_RequestTeamChange(InTeamIndex);
}
}
}
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Unbalanced"));
PS->ClientOnTeamAssignFailed(TEXT("Unbalanced or full team!"));
}
ForceNetUpdate();
}Editor is loading...
Leave a Comment