ELoginStatus::Type FOnlineIdentityAmazon::GetLoginStatus(int32 LocalUserNum) const { TSharedPtr<const FUniqueNetId> UserId = GetUniquePlayerId(LocalUserNum); if (UserId.IsValid()) { return GetLoginStatus(*UserId); } return ELoginStatus::NotLoggedIn; }
virtual FReply OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent) override { const FKey Key = InKeyEvent.GetKey(); if (Key == EKeys::Enter) { MenuOwner->HandleLoginUIClosed(TSharedPtr<const FUniqueNetId>(), 0); } else if (!MenuOwner->GetControlsLocked() && Key == EKeys::Gamepad_FaceButton_Bottom) { bool bSkipToMainMenu = true; { const auto OnlineSub = IOnlineSubsystem::Get(); if (OnlineSub) { const auto IdentityInterface = OnlineSub->GetIdentityInterface(); if (IdentityInterface.IsValid()) { TSharedPtr<GenericApplication> GenericApplication = FSlateApplication::Get().GetPlatformApplication(); const bool bIsLicensed = GenericApplication->ApplicationLicenseValid(); const auto LoginStatus = IdentityInterface->GetLoginStatus(InKeyEvent.GetUserIndex()); if (LoginStatus == ELoginStatus::NotLoggedIn || !bIsLicensed) { // Show the account picker. const auto ExternalUI = OnlineSub->GetExternalUIInterface(); if (ExternalUI.IsValid()) { ExternalUI->ShowLoginUI(InKeyEvent.GetUserIndex(), false, IOnlineExternalUI::FOnLoginUIClosedDelegate::CreateSP(MenuOwner, &FShooterWelcomeMenu::HandleLoginUIClosed)); bSkipToMainMenu = false; } } } } } if (bSkipToMainMenu) { const auto OnlineSub = IOnlineSubsystem::Get(); if (OnlineSub) { const auto IdentityInterface = OnlineSub->GetIdentityInterface(); if (IdentityInterface.IsValid()) { TSharedPtr<const FUniqueNetId> UserId = IdentityInterface->GetUniquePlayerId(InKeyEvent.GetUserIndex()); // If we couldn't show the external login UI for any reason, or if the user is // already logged in, just advance to the main menu immediately. MenuOwner->HandleLoginUIClosed(UserId, InKeyEvent.GetUserIndex()); } } } return FReply::Handled(); } return FReply::Unhandled(); }
FString FOnlineIdentityFacebook::GetPlayerNickname(int32 LocalUserNum) const { TSharedPtr<const FUniqueNetId> UserId = GetUniquePlayerId(LocalUserNum); if (UserId.IsValid()) { return GetPlayerNickname(*UserId); } return TEXT(""); }
FString FOnlineIdentityNull::GetPlayerNickname(int32 LocalUserNum) const { TSharedPtr<FUniqueNetId> UniqueId = GetUniquePlayerId(LocalUserNum); if (UniqueId.IsValid()) { return UniqueId->ToString(); } return TEXT("NullUser"); }
FPlatformUserId FOnlineIdentityAmazon::GetPlatformUserIdFromUniqueNetId(const FUniqueNetId& UniqueNetId) { for (int i = 0; i < MAX_LOCAL_PLAYERS; ++i) { auto CurrentUniqueId = GetUniquePlayerId(i); if (CurrentUniqueId.IsValid() && (*CurrentUniqueId == UniqueNetId)) { return i; } } return PLATFORMUSERID_NONE; }
FString FOnlineIdentityAmazon::GetAuthToken(int32 LocalUserNum) const { TSharedPtr<const FUniqueNetId> UserId = GetUniquePlayerId(LocalUserNum); if (UserId.IsValid()) { TSharedPtr<FUserOnlineAccount> UserAccount = GetUserAccount(*UserId); if (UserAccount.IsValid()) { return UserAccount->GetAccessToken(); } } return FString(); }
void AShooterPlayerController::OnDeathMessage(class AShooterPlayerState* KillerPlayerState, class AShooterPlayerState* KilledPlayerState, const UDamageType* KillerDamageType) { AShooterHUD* ShooterHUD = GetShooterHUD(); if (ShooterHUD) { ShooterHUD->ShowDeathMessage(KillerPlayerState, KilledPlayerState, KillerDamageType); } ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player); if (LocalPlayer && LocalPlayer->GetUniqueNetId().IsValid() && KilledPlayerState->UniqueId.IsValid()) { // if this controller is the player who died, update the hero stat. if (*LocalPlayer->GetUniqueNetId() == *KilledPlayerState->UniqueId) { const auto Events = Online::GetEventsInterface(); const auto Identity = Online::GetIdentityInterface(); if (Events.IsValid() && Identity.IsValid()) { int32 UserIndex = LocalPlayer->ControllerId; TSharedPtr<FUniqueNetId> UniqueID = Identity->GetUniquePlayerId(UserIndex); if (UniqueID.IsValid()) { ACharacter* Pawn = GetCharacter(); check(Pawn); FVector Location = Pawn->GetActorLocation(); FOnlineEventParms Params; Params.Add( TEXT( "SectionId" ), FVariantData( (int32)1 ) ); Params.Add( TEXT( "GameplayModeId" ), FVariantData( (int32)1 ) ); Params.Add( TEXT( "DifficultyLevelId" ), FVariantData( (int32)0 ) ); Params.Add( TEXT( "PlayerRoleId" ), FVariantData( (int32)0 ) ); Params.Add( TEXT( "PlayerWeaponId" ), FVariantData( (int32)0 ) ); Params.Add( TEXT( "EnemyRoleId" ), FVariantData( (int32)0 ) ); Params.Add( TEXT( "EnemyWeaponId" ), FVariantData( (int32)0 ) ); Params.Add( TEXT( "LocationX" ), FVariantData( Location.X ) ); Params.Add( TEXT( "LocationY" ), FVariantData( Location.Y ) ); Params.Add( TEXT( "LocationZ" ), FVariantData( Location.Z ) ); Events->TriggerEvent(*UniqueID, TEXT("PlayerDeath"), Params); } } } } }
void AShooterPlayerController::OnKill() { UpdateAchievementProgress(ACH_FRAG_SOMEONE, 100.0f); const auto Events = Online::GetEventsInterface(); const auto Identity = Online::GetIdentityInterface(); if (Events.IsValid() && Identity.IsValid()) { ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player); if (LocalPlayer) { int32 UserIndex = LocalPlayer->ControllerId; TSharedPtr<FUniqueNetId> UniqueID = Identity->GetUniquePlayerId(UserIndex); if (UniqueID.IsValid()) { ACharacter* Pawn = GetCharacter(); // If player is dead, use location stored during pawn cleanup. FVector Location = LastDeathLocation; if (Pawn) { Pawn->GetActorLocation(); } FOnlineEventParms Params; Params.Add( TEXT( "SectionId" ), FVariantData( (int32)1 ) ); Params.Add( TEXT( "GameplayModeId" ), FVariantData( (int32)1 ) ); Params.Add( TEXT( "DifficultyLevelId" ), FVariantData( (int32)0 ) ); Params.Add( TEXT( "PlayerRoleId" ), FVariantData( (int32)0 ) ); Params.Add( TEXT( "PlayerWeaponId" ), FVariantData( (int32)0 ) ); Params.Add( TEXT( "EnemyRoleId" ), FVariantData( (int32)0 ) ); Params.Add( TEXT( "KillTypeId" ), FVariantData( (int32)0 ) ); Params.Add( TEXT( "LocationX" ), FVariantData( Location.X ) ); Params.Add( TEXT( "LocationY" ), FVariantData( Location.Y ) ); Params.Add( TEXT( "LocationZ" ), FVariantData( Location.Z ) ); Params.Add( TEXT( "EnemyWeaponId" ), FVariantData( (int32)0 ) ); Events->TriggerEvent(*UniqueID, TEXT("KillOponent"), Params); } } } }
bool FOnlineIdentityAmazon::Logout(int32 LocalUserNum) { TSharedPtr<const FUniqueNetId> UserId = GetUniquePlayerId(LocalUserNum); if (UserId.IsValid()) { // remove cached user account UserAccounts.Remove(UserId->ToString()); // remove cached user id UserIds.Remove(LocalUserNum); // not async but should call completion delegate anyway TriggerOnLogoutCompleteDelegates(LocalUserNum, true); return true; } else { UE_LOG(LogOnline, Warning, TEXT("No logged in user found for LocalUserNum=%d."), LocalUserNum); TriggerOnLogoutCompleteDelegates(LocalUserNum, false); } return false; }
void AShooterPlayerController::UpdateAchievementsOnGameEnd() { ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player); if (LocalPlayer) { AShooterPlayerState* ShooterPlayerState = Cast<AShooterPlayerState>(PlayerState); if (ShooterPlayerState) { const UShooterPersistentUser* PersistentUser = GetPersistentUser(); if (PersistentUser) { const int32 Wins = PersistentUser->GetWins(); const int32 Losses = PersistentUser->GetLosses(); const int32 Matches = Wins + Losses; const int32 TotalKills = PersistentUser->GetKills(); const int32 MatchScore = (int32)ShooterPlayerState->GetScore(); const int32 TotalBulletsFired = PersistentUser->GetBulletsFired(); const int32 TotalRocketsFired = PersistentUser->GetRocketsFired(); float TotalGameAchievement = 0; float CurrentGameAchievement = 0; /////////////////////////////////////// // Kill achievements { float fSomeKillPct = ((float)TotalKills / (float)SomeKillsCount) * 100.0f; fSomeKillPct = FMath::RoundToFloat(fSomeKillPct); UpdateAchievementProgress(ACH_SOME_KILLS, fSomeKillPct); CurrentGameAchievement += FMath::Min(fSomeKillPct, 100.0f); TotalGameAchievement += 100; } { float fLotsKillPct = ((float)TotalKills / (float)LotsKillsCount) * 100.0f; fLotsKillPct = FMath::RoundToFloat(fLotsKillPct); UpdateAchievementProgress(ACH_LOTS_KILLS, fLotsKillPct); CurrentGameAchievement += FMath::Min(fLotsKillPct, 100.0f); TotalGameAchievement += 100; } /////////////////////////////////////// /////////////////////////////////////// // Match Achievements { UpdateAchievementProgress(ACH_FINISH_MATCH, 100.0f); CurrentGameAchievement += 100; TotalGameAchievement += 100; } { float fLotsRoundsPct = ((float)Matches / (float)LotsMatchesCount) * 100.0f; fLotsRoundsPct = FMath::RoundToFloat(fLotsRoundsPct); UpdateAchievementProgress(ACH_LOTS_MATCHES, fLotsRoundsPct); CurrentGameAchievement += FMath::Min(fLotsRoundsPct, 100.0f); TotalGameAchievement += 100; } /////////////////////////////////////// /////////////////////////////////////// // Win Achievements if (Wins >= 1) { UpdateAchievementProgress(ACH_FIRST_WIN, 100.0f); CurrentGameAchievement += 100.0f; } TotalGameAchievement += 100; { float fLotsWinPct = ((float)Wins / (float)LotsWinsCount) * 100.0f; fLotsWinPct = FMath::RoundToInt(fLotsWinPct); UpdateAchievementProgress(ACH_LOTS_WIN, fLotsWinPct); CurrentGameAchievement += FMath::Min(fLotsWinPct, 100.0f); TotalGameAchievement += 100; } { float fManyWinPct = ((float)Wins / (float)ManyWinsCount) * 100.0f; fManyWinPct = FMath::RoundToInt(fManyWinPct); UpdateAchievementProgress(ACH_MANY_WIN, fManyWinPct); CurrentGameAchievement += FMath::Min(fManyWinPct, 100.0f); TotalGameAchievement += 100; } /////////////////////////////////////// /////////////////////////////////////// // Ammo Achievements { float fLotsBulletsPct = ((float)TotalBulletsFired / (float)LotsBulletsCount) * 100.0f; fLotsBulletsPct = FMath::RoundToFloat(fLotsBulletsPct); UpdateAchievementProgress(ACH_SHOOT_BULLETS, fLotsBulletsPct); CurrentGameAchievement += FMath::Min(fLotsBulletsPct, 100.0f); TotalGameAchievement += 100; } { float fLotsRocketsPct = ((float)TotalRocketsFired / (float)LotsRocketsCount) * 100.0f; fLotsRocketsPct = FMath::RoundToFloat(fLotsRocketsPct); UpdateAchievementProgress(ACH_SHOOT_ROCKETS, fLotsRocketsPct); CurrentGameAchievement += FMath::Min(fLotsRocketsPct, 100.0f); TotalGameAchievement += 100; } /////////////////////////////////////// /////////////////////////////////////// // Score Achievements { float fGoodScorePct = ((float)MatchScore / (float)GoodScoreCount) * 100.0f; fGoodScorePct = FMath::RoundToFloat(fGoodScorePct); UpdateAchievementProgress(ACH_GOOD_SCORE, fGoodScorePct); } { float fGreatScorePct = ((float)MatchScore / (float)GreatScoreCount) * 100.0f; fGreatScorePct = FMath::RoundToFloat(fGreatScorePct); UpdateAchievementProgress(ACH_GREAT_SCORE, fGreatScorePct); } /////////////////////////////////////// /////////////////////////////////////// // Map Play Achievements UWorld* World = GetWorld(); if (World) { FString MapName = *FPackageName::GetShortName(World->PersistentLevel->GetOutermost()->GetName()); if (MapName.Find(TEXT("Highrise")) != -1) { UpdateAchievementProgress(ACH_PLAY_HIGHRISE, 100.0f); } else if (MapName.Find(TEXT("Sanctuary")) != -1) { UpdateAchievementProgress(ACH_PLAY_SANCTUARY, 100.0f); } } /////////////////////////////////////// const auto Events = Online::GetEventsInterface(); const auto Identity = Online::GetIdentityInterface(); if (Events.IsValid() && Identity.IsValid()) { int32 UserIndex = LocalPlayer->ControllerId; TSharedPtr<FUniqueNetId> UniqueID = Identity->GetUniquePlayerId(UserIndex); if (UniqueID.IsValid()) { FOnlineEventParms Params; float fGamePct = (CurrentGameAchievement / TotalGameAchievement) * 100.0f; fGamePct = FMath::RoundToFloat(fGamePct); Params.Add( TEXT( "CompletionPercent" ), FVariantData( (float)fGamePct ) ); if (UniqueID.IsValid()) { Events->TriggerEvent(*UniqueID, TEXT("GameProgress"), Params); } } } } } } }