bool UPartyBeaconState::SwapTeams(const FUniqueNetIdRepl& PartyLeader, const FUniqueNetIdRepl& OtherPartyLeader) { bool bSuccess = false; int32 ResIdx = GetExistingReservation(PartyLeader); int32 OtherResIdx = GetExistingReservation(OtherPartyLeader); if (ResIdx != INDEX_NONE && OtherResIdx != INDEX_NONE) { FPartyReservation& PartyRes = Reservations[ResIdx]; FPartyReservation& OtherPartyRes = Reservations[OtherResIdx]; if (PartyRes.TeamNum != OtherPartyRes.TeamNum) { int32 TeamSize = GetNumPlayersOnTeam(PartyRes.TeamNum); int32 OtherTeamSize = GetNumPlayersOnTeam(OtherPartyRes.TeamNum); // Will the new teams fit bool bValidTeamSizeA = (PartyRes.PartyMembers.Num() + (OtherTeamSize - OtherPartyRes.PartyMembers.Num())) <= NumPlayersPerTeam; bool bValidTeamSizeB = (OtherPartyRes.PartyMembers.Num() + (TeamSize - PartyRes.PartyMembers.Num())) <= NumPlayersPerTeam; if (bValidTeamSizeA && bValidTeamSizeB) { Swap(PartyRes.TeamNum, OtherPartyRes.TeamNum); bSuccess = true; } } } return bSuccess; }
bool UPartyBeaconState::ChangeTeam(const FUniqueNetIdRepl& PartyLeader, int32 NewTeamNum) { bool bSuccess = false; if (NewTeamNum >= 0 && NewTeamNum < NumTeams) { int32 ResIdx = GetExistingReservation(PartyLeader); if (ResIdx != INDEX_NONE) { FPartyReservation& PartyRes = Reservations[ResIdx]; if (PartyRes.TeamNum != NewTeamNum) { int32 OtherTeamSize = GetNumPlayersOnTeam(NewTeamNum); bool bValidTeamSize = (PartyRes.PartyMembers.Num() + OtherTeamSize) <= NumPlayersPerTeam; if (bValidTeamSize) { PartyRes.TeamNum = NewTeamNum; bSuccess = true; } } } } return bSuccess; }
EPartyReservationResult::Type APartyBeaconHost::AddPartyReservation(const FPartyReservation& ReservationRequest) { EPartyReservationResult::Type Result = EPartyReservationResult::GeneralError; int32 IncomingPartySize = ReservationRequest.PartyMembers.Num(); if (NumConsumedReservations + IncomingPartySize <= MaxReservations) { const int32 ExistingReservationIdx = GetExistingReservation(ReservationRequest.PartyLeader); if (ExistingReservationIdx == INDEX_NONE) { bool bContinue = true; if (ValidatePlayers.IsBound()) { bContinue = ValidatePlayers.Execute(ReservationRequest.PartyMembers); } if (bContinue) { NumConsumedReservations += IncomingPartySize; Reservations.Add(ReservationRequest); // Keep track of newly added players for (int32 Count = 0; Count < ReservationRequest.PartyMembers.Num(); Count++) { NewPlayerAdded(ReservationRequest.PartyMembers[Count]); } ReservationChanged.ExecuteIfBound(); if (NumConsumedReservations == MaxReservations) { ReservationsFull.ExecuteIfBound(); } Result = EPartyReservationResult::ReservationAccepted; } else { Result = EPartyReservationResult::ReservationDenied_Banned; } } else { Result = EPartyReservationResult::ReservationDuplicate; } } else { Result = EPartyReservationResult::PartyLimitReached; } return Result; }
bool UPartyBeaconState::RemoveReservation(const FUniqueNetIdRepl& PartyLeader) { const int32 ExistingReservationIdx = GetExistingReservation(PartyLeader); if (ExistingReservationIdx != INDEX_NONE) { NumConsumedReservations -= Reservations[ExistingReservationIdx].PartyMembers.Num(); Reservations.RemoveAtSwap(ExistingReservationIdx); return true; } return false; }
bool UPartyBeaconState::RemoveReservation(const FUniqueNetIdRepl& PartyLeader) { const int32 ExistingReservationIdx = GetExistingReservation(PartyLeader); if (ExistingReservationIdx != INDEX_NONE) { NumConsumedReservations -= Reservations[ExistingReservationIdx].PartyMembers.Num(); Reservations.RemoveAtSwap(ExistingReservationIdx); // Possibly shuffle existing teams so that beacon can accommodate biggest open slots BestFitTeamAssignmentJiggle(); return true; } return false; }
void APartyBeaconHost::RemovePartyReservation(const FUniqueNetIdRepl& PartyLeader) { const int32 ExistingReservationIdx = GetExistingReservation(PartyLeader); if (ExistingReservationIdx != INDEX_NONE) { NumConsumedReservations -= Reservations[ExistingReservationIdx].PartyMembers.Num(); Reservations.RemoveAtSwap(ExistingReservationIdx); CancelationReceived.ExecuteIfBound(*PartyLeader); ReservationChanged.ExecuteIfBound(); } else { UE_LOG(LogBeacon, Warning, TEXT("Failed to find reservation to cancel for leader %s:"), *PartyLeader->ToString()); } }