Advertisement
Fieol

Untitled

May 3rd, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 74.58 KB | None | 0 0
  1. // Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
  2.  
  3. #include "VizGame.h"
  4. #include "Windows/WindowsWindow.h"
  5. #include "Player/VizPlayerController.h"
  6. #include "VizCreateEditPawn.h"
  7. #include "Player/VizPlayerCameraManager.h"
  8. #include "Player/VizCheatManager.h"
  9. #include "Player/VizLocalPlayer.h"
  10. #include "Online/VizPlayerState.h"
  11. #include "Inventory/VizInventoryContainerActor.h"
  12. //#include "Weapons/VizWeapon.h"
  13. #include "UI/Menu/VizIngameMenu.h"
  14. #include "UI/Style/VizStyle.h"
  15. #include "UI/VizHUD.h"
  16. #include "Online.h"
  17. #include "OnlineAchievementsInterface.h"
  18. #include "OnlineEventsInterface.h"
  19. #include "OnlineIdentityInterface.h"
  20. #include "OnlineSessionInterface.h"
  21. #include "VizGameInstance.h"
  22. #include "VizLeaderboards.h"
  23. #include "VizGameViewportClient.h"
  24. #include "WidgetManagers/VizWidgetManager.h"
  25. #include "Inventory/VizInventoryPreview.h"
  26. #include "../../Inventory/VizEquipmentContainer.h"
  27. #include "VizGameMode.h"
  28. #include "VizTypes.h"
  29. #include "Actors/VizPathManager.h"
  30. #include "Environment/VizSnowClassificationManager.h"
  31. #include "../../Inventory/VizPlayerInventory.h"
  32. #include "../../Inventory/VizInventoryContainerActor.h"
  33. #define  ACH_FRAG_SOMEONE    TEXT("ACH_FRAG_SOMEONE")
  34. #define  ACH_SOME_KILLS        TEXT("ACH_SOME_KILLS")
  35. #define  ACH_LOTS_KILLS        TEXT("ACH_LOTS_KILLS")
  36. #define  ACH_FINISH_MATCH    TEXT("ACH_FINISH_MATCH")
  37. #define  ACH_LOTS_MATCHES    TEXT("ACH_LOTS_MATCHES")
  38. #define  ACH_FIRST_WIN        TEXT("ACH_FIRST_WIN")
  39. #define  ACH_LOTS_WIN        TEXT("ACH_LOTS_WIN")
  40. #define  ACH_MANY_WIN        TEXT("ACH_MANY_WIN")
  41. #define  ACH_SHOOT_BULLETS    TEXT("ACH_SHOOT_BULLETS")
  42. #define  ACH_SHOOT_ROCKETS    TEXT("ACH_SHOOT_ROCKETS")
  43. #define  ACH_GOOD_SCORE        TEXT("ACH_GOOD_SCORE")
  44. #define  ACH_GREAT_SCORE    TEXT("ACH_GREAT_SCORE")
  45. #define  ACH_PLAY_SANCTUARY    TEXT("ACH_PLAY_SANCTUARY")
  46. #define  ACH_PLAY_HIGHRISE    TEXT("ACH_PLAY_HIGHRISE")
  47.  
  48. static const int32 SomeKillsCount = 10;
  49. static const int32 LotsKillsCount = 20;
  50. static const int32 LotsMatchesCount = 5;
  51. static const int32 LotsWinsCount = 3;
  52. static const int32 ManyWinsCount = 5;
  53. static const int32 LotsBulletsCount = 100;
  54. static const int32 LotsRocketsCount = 10;
  55. static const int32 GoodScoreCount = 10;
  56. static const int32 GreatScoreCount = 15;
  57.  
  58. AVizPlayerController::AVizPlayerController(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
  59. {
  60.     PlayerCameraManagerClass = AVizPlayerCameraManager::StaticClass();
  61.     CheatClass = UVizCheatManager::StaticClass();
  62.     bAllowGameActions = true;
  63.     bGameEndedFrame = false;
  64.     LastDeathLocation = FVector::ZeroVector;
  65.  
  66.     ServerSayString = TEXT("Say");
  67.     VizFriendUpdateTimer = 0.0f;
  68.     bHasSentStartEvents = false;
  69. }
  70.  
  71. void AVizPlayerController::SetupInputComponent()
  72. {
  73.     Super::SetupInputComponent();
  74.  
  75.     // UI input
  76.     InputComponent->BindAction("InGameMenu", IE_Pressed, this, &AVizPlayerController::OnToggleInGameMenu);
  77.     InputComponent->BindAction("Scoreboard", IE_Pressed, this, &AVizPlayerController::OnShowScoreboard);
  78.     InputComponent->BindAction("Scoreboard", IE_Released, this, &AVizPlayerController::OnHideScoreboard);
  79.     InputComponent->BindAction("ConditionalCloseScoreboard", IE_Pressed, this, &AVizPlayerController::OnConditionalCloseScoreboard);
  80.     InputComponent->BindAction("ToggleScoreboard", IE_Pressed, this, &AVizPlayerController::OnToggleScoreboard);
  81.     InputComponent->BindAction("TraineeMap", IE_Pressed, this, &AVizPlayerController::ToggleTraineeMap);
  82.     InputComponent->BindAction("TraineeSnowTests", IE_Pressed, this, &AVizPlayerController::ToggleTraineeSnowTests);
  83.     InputComponent->BindAction("TraineeInventory", IE_Pressed, this, &AVizPlayerController::ToggleTraineeInventory);
  84.     InputComponent->BindAction("SpawnInventory", IE_Released, this, &AVizPlayerController::SpawnAllInventory);
  85.     InputComponent->BindAction("ClearInventory", IE_Released, this, &AVizPlayerController::ClearAllInventory);
  86.     // voice chat
  87.     InputComponent->BindAction("PushToTalk", IE_Pressed, this, &APlayerController::StartTalking);
  88.     InputComponent->BindAction("PushToTalk", IE_Released, this, &APlayerController::StopTalking);
  89.  
  90.     InputComponent->BindAction("ToggleChat", IE_Pressed, this, &AVizPlayerController::ToggleChatWindow);
  91.  
  92.     //Mouse Click
  93.     InputComponent->BindAction("LeftMouseUp", IE_Released, this, &AVizPlayerController::OnLeftMouseUp);
  94.  
  95.     //Debug
  96.     InputComponent->BindAction("DebugKey", IE_Released, this, &AVizPlayerController::DebugTest);
  97.     InputComponent->BindAction("EnableTrainerUI", IE_Released, this, &AVizPlayerController::TestNetworkCommunication);
  98.     InputComponent->BindAction("CallDog", IE_Pressed, this, &AVizPlayerController::OnCallDog);
  99. }
  100.  
  101.  
  102. void AVizPlayerController::TestNetworkCommunication()
  103. {
  104.  //   UpdateQuestionID_OnServer(QuestionID);
  105. }
  106.  
  107. void AVizPlayerController::SendQuestionIDtoClient(int32 QuesID)
  108. {
  109.     QuestionID = QuesID;
  110.     UpdateQuestionID_OnServer(QuesID);
  111.     V_LOGM(LogViz, "In Trainer Question ID is: %s", *FString::FromInt((QuestionID)));
  112. }
  113.  
  114. void AVizPlayerController::SendQuestionIDtoTrainer(int32 answerString)
  115. {
  116. //    FString *str = answerString;
  117.     SendAnswerToTrainer_OnServer(answerString);
  118.     V_LOGM(LogViz, "In Trainee Question Answer  is:  %s", *FString::FromInt((answerString)));
  119. }
  120.  
  121. void AVizPlayerController::SendAnswerToTrainer_OnServer_Implementation(int32 answer)
  122. {
  123.     AVizGameMode* gm = Cast<AVizGameMode>(GetWorld()->GetAuthGameMode());
  124.  
  125.     V_LOGM(LogViz, "Server looking for Trainer");
  126.  
  127.     gm->SendToTrainer(answer);
  128. }
  129.  
  130. bool AVizPlayerController::SendAnswerToTrainer_OnServer_Validate(int32 answer)
  131. {
  132.     return true;
  133. }
  134.  
  135.  
  136. void AVizPlayerController::UpdateQuestionID_OnServer_Implementation(int32 id)
  137. {
  138.     AVizGameMode* gm = Cast<AVizGameMode>(GetWorld()->GetAuthGameMode());
  139.  
  140.     V_LOGM(LogViz, "Server looking for Trainee");
  141.  
  142.     gm->AskTrainee(id);
  143. }
  144.  
  145. bool AVizPlayerController::UpdateQuestionID_OnServer_Validate(int32 id)
  146. {
  147.     return true;
  148. }
  149.  
  150. void AVizPlayerController::QuestionAsked_Implementation(int32 id)
  151. {
  152.     QuestionID = id;
  153.  
  154.     V_LOGM(LogViz, "Trainee got the Question ID! Its is %s", *FString::FromInt((QuestionID)));
  155.  
  156.     UpdateCharacterUI();
  157.  
  158.     TraineeFirstPersonPawn = Cast<AVizCharacter>(GetPawn());
  159.  
  160.     //TraineeFirstPersonPawn->SetScoringWidgetIndex(QuestionID);
  161.     TraineeFirstPersonPawn->UpdateQuestionFromCharacter(QuestionID);
  162. }
  163.  
  164. void AVizPlayerController::AnswerSent_Implementation(int32 answer)
  165. {
  166.     V_LOGM(LogViz, "Trainer got the Answer! Its is %s", *FString::FromInt((answer)));
  167.     trainerUIMultiWidget->TrainerTraineeScoreTabWidget->ShowAnswer(answer);
  168.     trainerUIMultiWidget->TrainerUIMultiWidget->ShowAnswer(answer);
  169.  
  170. //  UpdateCharacterUI( widget , answer);
  171. }
  172.  
  173. void AVizPlayerController::SetTrainerUIWidget() {
  174.     trainerUIMultiWidget = CreateWidget<UVizTrainerMenuMultiUIWidget>(this, TrainerUIBP);
  175.  
  176.     AVizCreateEditPawn * pawn = Cast<AVizCreateEditPawn>(GetPawn());
  177.     pawn->SetTrainerUI(trainerUIMultiWidget);
  178.  
  179. }
  180.  
  181. void AVizPlayerController::PostInitializeComponents()
  182. {
  183.     Super::PostInitializeComponents();
  184.     FVizStyle::Initialize();
  185.     VizFriendUpdateTimer = 0;
  186.  
  187.     //Find snow classification
  188.  
  189.     TArray<AActor*> FoundActors;
  190.     UGameplayStatics::GetAllActorsOfClass(GetWorld(), AVizSnowClassificationManager::StaticClass(), FoundActors);
  191.  
  192.     if(FoundActors.Num() > 0)
  193.     {
  194.         m_pSnowProperty = Cast<AVizSnowClassificationManager>(FoundActors[0]);
  195.     }
  196. }
  197. void AVizPlayerController :: MapScrolling(float ScrollDirection)
  198. {
  199.  
  200.     float newWidth = m_scenemap->GetCaptureComponent2D()->OrthoWidth;
  201.     float maxOrthoWidth = 1000000.0; // xxxx to be based on landscape maximum extents; same size as width/length
  202.     float minOrthoWidth = 1000.0;
  203.     float zoomDelta = 0.2;
  204.     newWidth = newWidth - ScrollDirection * newWidth* zoomDelta;
  205.     newWidth = (newWidth >= maxOrthoWidth) ? maxOrthoWidth : newWidth;
  206.     newWidth = (newWidth <= minOrthoWidth) ? minOrthoWidth : newWidth;
  207.  
  208.     m_scenemap->GetCaptureComponent2D()->OrthoWidth = newWidth;
  209.      
  210. }
  211.  
  212.  
  213. void AVizPlayerController :: MapPan(FVector2D PanMap, float deltatime)
  214. {
  215.  
  216.     FVector camLocaton = m_scenemap->GetActorLocation();
  217.     float maxOrthoWidth = 1000000.0; // xxxx to be based on landscape maximum extents; same size as width/length
  218.     float panRate = 30000.0;
  219.     float currentWidth = m_scenemap->GetCaptureComponent2D()->OrthoWidth;
  220.  
  221.     float camMaxOffset = maxOrthoWidth - 0.5*currentWidth;
  222.     float camMinOffset = currentWidth*0.5;
  223.  
  224.     camLocaton -= FVector(PanMap.Y, 0, 0) * deltatime * panRate;
  225.     camLocaton += FVector(0, PanMap.X, 0) * deltatime * panRate;
  226.  
  227.     camLocaton.X = (camLocaton.X >= camMaxOffset) ? camMaxOffset : camLocaton.X;
  228.     camLocaton.X = (camLocaton.X <= camMinOffset) ? camMinOffset : camLocaton.X;
  229.  
  230.     camLocaton.Y = (camLocaton.Y >= camMaxOffset) ? camMaxOffset : camLocaton.Y;
  231.     camLocaton.Y = (camLocaton.Y <= camMinOffset) ? camMinOffset : camLocaton.Y;
  232.  
  233.     m_scenemap->SetActorLocation(camLocaton);
  234.  
  235. }
  236.  
  237. FVector AVizPlayerController::FetchCamLoc()
  238. {
  239.     if (m_scenemap)
  240.     {
  241.         return m_scenemap->GetActorLocation();
  242.     }
  243.     return FVector::ZeroVector;
  244. }
  245.  
  246. float AVizPlayerController::FetchcamOrthoWidth()
  247. {
  248.     if (m_scenemap)
  249.     {
  250.         return m_scenemap->GetCaptureComponent2D()->OrthoWidth;
  251.     }
  252.     return 0.0;
  253.  
  254. }
  255.  
  256. void AVizPlayerController::BeginPlay()
  257. {
  258.     Super::BeginPlay();
  259.  
  260.     // Read all equipment data
  261.     m_pInventoryManager = NewObject<UVizInventoryManager>();
  262.     m_pInventoryManager->ReadInventoryData(EquipmentData, EquipmentDetailsData);
  263.  
  264.     // Initialize EquipmentContainer and GameInventory
  265.     m_pEquipmentContainer = NewObject<UVizEquipmentContainer>();
  266.     m_pEquipmentContainer->Initialize(m_pInventoryManager);
  267.     m_pGameInventory = NewObject<UVizGameInventory>();
  268.     m_pGameInventory->Initialize(m_pInventoryManager);    
  269.  
  270.     if (SceneMapBP)
  271.     {
  272.         m_scenemap = (ASceneCapture2D*)GetWorld()->SpawnActor(SceneMapBP);
  273.         m_scenemap->SetActorLocation(MapScenceCamPosition);
  274.  
  275.         FRotator MapRotator;
  276.         MapRotator.Roll = 0.0f;
  277.         MapRotator.Pitch = -90.0f;
  278.         MapRotator.Yaw = -90.0f;
  279.         m_scenemap->SetActorRotation(MapRotator);
  280.         m_scenemap->GetCaptureComponent2D()->ProjectionType = ECameraProjectionMode::Orthographic;
  281.         m_scenemap->GetCaptureComponent2D()->OrthoWidth = 1000000.0f;
  282.         //    m_scenemap->GetCaptureComponent2D()->bCaptureEveryFrame = false;
  283.         m_scenemap->GetCaptureComponent2D()->TextureTarget = MapTexture;
  284.  
  285.         GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FString::SanitizeFloat(m_scenemap->GetCaptureComponent2D()->OrthoWidth));
  286.  
  287.         //FString::SanitizeFloat(m_scenemap->GetCaptureComponent2D()->OrthoWidth);
  288.         //    m_scenemap->GetCaptureComponent2D()->OrthoWidth
  289.     }
  290.  
  291.     //! TODO: Store and retrieve this information from the LocalPlayer.
  292.     UGameInstance* gameInstance = GetWorld()->GetGameInstance();
  293.     UVizGameInstance* vizgameinstance = Cast<UVizGameInstance>(gameInstance);
  294.     bool trainerB = vizgameinstance->IsTrainer;
  295.     bool bHMD;
  296.  
  297.  
  298.     //Check for Head Mounting Device
  299.     if (GEngine->HMDDevice.Get())
  300.     {
  301.         bHMD = true;
  302.     }
  303.     else
  304.     {
  305.         bHMD = false;
  306.     }
  307.  
  308.     //Make sure that controller has data before creating widgets
  309.     if (!IsRunningDedicatedServer())
  310.     {
  311.         V_LOG(LogViz, "Calling Update Pawn Possession");
  312.         V_LOGVALUEB(LogViz, trainerB);
  313.         V_LOGVALUEB(LogViz, bHMD);
  314.  
  315.        
  316.         UpdatePawnPossession(trainerB, bHMD);
  317.  
  318.         RequestForMapInfo_Server();
  319.         RequestForObjectives_Server();
  320.         RequestForQuestionData_Server();
  321.         RequestForSnowTests_Server();
  322.         RequestForGameInventoryData_Server();
  323.         RequestForBindingWeatherParticleLocation();
  324.  
  325.         if(m_pWidgetManager)
  326.         {
  327. //            m_pWidgetManager->ShowSelectionMenu();
  328.  
  329.             /*if(GEngine->HMDDevice.Get())
  330.             {
  331.                 DisableHMD();
  332.             }*/
  333.         }
  334.     }
  335.  
  336.     if (InventoryPreviewBP)
  337.     {
  338.         m_pInventoryPreview = (AVizInventoryPreview*)GetWorld()->SpawnActor(InventoryPreviewBP);
  339.         m_pInventoryPreview->SetActorLocation(PreviewLocation);
  340.     }
  341.  
  342.     if(InventoryContainerBP)
  343.     {
  344.         m_pInventoryContainer = (AVizInventoryContainerActor*)GetWorld()->SpawnActor(InventoryContainerBP);
  345.     }
  346.  
  347.     //if (DogAICharaterBP)
  348.     //{
  349.     //    m_pDogCharacterBP = (ACharacter*)GetWorld()->SpawnActor(DogAICharaterBP);
  350.     //    m_pDogCharacterBP->SetActorLocation(TraineeFPPawn->GetActorLocation());
  351.     //    //m_pDogCharacterBP->SimulatePhysics = true;
  352.     //}
  353.     //
  354.  //   m_pAIManager = NewObject<UVizAIManager>();
  355.  //   m_pAIManager->Start(m_pDogCharacterBP, GEngine->GetWorld());
  356.      
  357.  
  358.     //If VR is detected , switch to VR Pawn
  359.     /*if(GEngine->HMDDevice.Get())
  360.     {
  361.         PossesCharacter(1);
  362.     }*/
  363. }
  364.  
  365.  
  366. void AVizPlayerController::UpdatePawnPossession_Implementation(bool bTrainer,bool bHMD)
  367. {
  368.     V_LOG_LINE(LogViz);
  369.     V_LOGVALUEB(LogViz, bTrainer);
  370.     V_LOGVALUEB(LogViz, bHMD);
  371.  
  372. //    bTrainer = false;
  373.  
  374.     AVizCharacter* myPawn = Cast<AVizCharacter>(GetPawn());
  375.     if (myPawn)
  376.     {
  377. //        V_LOG(LogViz, "Pawn is valid.");
  378. //        V_LOG(LogViz, myPawn->GetClass()->GetName());
  379. //        if (!bTrainer)
  380. //        {
  381. //            myPawn->GetPlayerInventory()->Initialize(m_pInventoryManager);
  382. //            this->Possess(myPawn);
  383. //            TraineeFirstPersonPawn = myPawn;
  384. //            V_LOG(LogViz, "Possessing VizCharacter");
  385. //
  386. ////            if (bHMD)
  387. //            {
  388. //                V_LOG(LogViz, "Possessing VR Pawn");
  389. //                PossesCharacter(1);
  390. //              if (myPawn->Destroy())
  391. //              {
  392. //                  V_LOG(LogViz, "Trainee pawn destroyed");
  393. //              }
  394. //              else
  395. //              {
  396. //                  V_LOG(LogViz, "Trainee pawn could not be destroyed");
  397. //              }
  398. //             
  399. //            }
  400. //
  401.             //Spawn the Dog AI Companion from Code
  402.             if (DogAICharaterBP)
  403.             {
  404.                 m_pDogCharacterBP = (AAIDogCharacter*)GetWorld()->SpawnActor(DogAICharaterBP);
  405.                 m_pDogCharacterBP->SetActorLocation(myPawn->GetActorLocation());
  406.                 //m_pDogCharacterBP->CallDog();
  407.  
  408.             }
  409. //            
  410. //        }        
  411.     }
  412.  
  413.  
  414.     if (bTrainer)
  415.     {
  416.         V_LOG(LogViz, "Creating AVizCreateEditPawn");
  417.        
  418.         this->GetPawn()->bHidden = true;
  419.         this->UnPossess();
  420.  
  421.  
  422.         FVector Pos(603921.4,303261.4,69713.7);
  423.         FRotator Rotation(0, 0, 0);
  424.         FActorSpawnParameters params;
  425.  
  426.        
  427.         trainerPawn = GetWorld()->SpawnActor<AVizCreateEditPawn>(TrainerPawn , Pos, Rotation, params);
  428.         trainerPawn->SetReplicates(true);
  429.         trainerPawn->SetReplicateMovement(true);
  430.         if (trainerPawn)
  431.         {
  432.             this->Possess(trainerPawn);
  433.             if (myPawn->Destroy())
  434.             {
  435.                 V_LOG(LogViz, "Trainee pawn destroyed");
  436.             }
  437.             else
  438.             {
  439.                 V_LOG(LogViz, "Trainee pawn could not be destroyed");
  440.             }
  441.         }
  442.     }
  443.  
  444.     TraineeFirstPersonPawn = nullptr;
  445.  
  446.     if (DogAICharaterBP)
  447.     {
  448.         //m_pDogCharacterBP = (ACharacter*)GetWorld()->SpawnActor(DogAICharaterBP);
  449.         //m_pDogCharacterBP->SetActorLocation(TraineeFPPawn->GetActorLocation());
  450.         //m_pDogCharacterBP->SimulatePhysics = true;
  451.     }
  452.    
  453.  
  454.    
  455.  
  456.     //m_pAIManager = NewObject<UVizAIManager>();
  457.     //m_pAIManager->Start(m_pDogCharacterBP, GEngine->GetWorld());
  458. }
  459.  
  460. void AVizPlayerController::OnCallDog()
  461. {
  462.     m_pDogCharacterBP->CallDog();
  463. }
  464. bool AVizPlayerController::UpdatePawnPossession_Validate(bool bTrainer,bool bHMD)
  465. {
  466.     return true;
  467. }
  468.  
  469. void AVizPlayerController::Tick(float DeltaSeconds)
  470. {
  471.     Super::Tick(DeltaSeconds);
  472.  
  473.     if (!IsRunningDedicatedServer())
  474.     {
  475.         GetAllPlayerPosition();
  476.     }
  477.    
  478.  
  479.     if (IsGameMenuVisible())
  480.     {
  481.         if (VizFriendUpdateTimer > 0)
  482.         {
  483.             VizFriendUpdateTimer -= DeltaSeconds;
  484.         }
  485.         else
  486.         {
  487.             TSharedPtr<class FVizFriends> VizFriends = VizIngameMenu->GetVizFriends();
  488.             ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player);
  489.             if (VizFriends.IsValid() && LocalPlayer && LocalPlayer->GetControllerId() >= 0)
  490.             {
  491.                 VizFriends->UpdateFriends(LocalPlayer->GetControllerId());
  492.             }
  493.             VizFriendUpdateTimer = 4; //make sure the time between calls is long enough that we won't trigger (0x80552C81) and not exceed the web api rate limit
  494.         }
  495.     }
  496.  
  497.     // Is this the first frame after the game has ended
  498.     if (bGameEndedFrame)
  499.     {
  500.         bGameEndedFrame = false;
  501.  
  502.         // ONLY PUT CODE HERE WHICH YOU DON'T WANT TO BE DONE DUE TO HOST LOSS
  503.  
  504.         // Do we need to show the end of round scoreboard?
  505.         if (IsPrimaryPlayer())
  506.         {
  507.             AVizHUD* VizHUD = GetVizHUD();
  508.             if (VizHUD)
  509.             {
  510.                 VizHUD->ShowScoreboard(true, true);
  511.             }
  512.         }
  513.     }
  514.  
  515.     //Update Minimap
  516.     if (m_bIsMinimapEnabled || m_bIsGameMapEnabled)
  517.     {
  518.         m_pWidgetManagerBase->UpdateMapObjects(m_aMiniMapObjects);
  519.     }
  520. }
  521.  
  522. void AVizPlayerController::QueryAchievements()
  523. {
  524.     // precache achievements
  525.     ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player);
  526.     if (LocalPlayer && LocalPlayer->GetControllerId() != -1)
  527.     {
  528.         IOnlineSubsystem* OnlineSub = IOnlineSubsystem::Get();
  529.         if(OnlineSub)
  530.         {
  531.             IOnlineIdentityPtr Identity = OnlineSub->GetIdentityInterface();
  532.             if (Identity.IsValid())
  533.             {
  534.                 TSharedPtr<const FUniqueNetId> UserId = Identity->GetUniquePlayerId(LocalPlayer->GetControllerId());
  535.  
  536.                 if (UserId.IsValid())
  537.                 {
  538.                     IOnlineAchievementsPtr Achievements = OnlineSub->GetAchievementsInterface();
  539.  
  540.                     if (Achievements.IsValid())
  541.                     {
  542.                         Achievements->QueryAchievements( *UserId.Get(), FOnQueryAchievementsCompleteDelegate::CreateUObject( this, &AVizPlayerController::OnQueryAchievementsComplete ));
  543.                     }
  544.                 }
  545.                 else
  546.                 {
  547.                     UE_LOG(LogOnline, Warning, TEXT("No valid user id for this controller."));
  548.                 }
  549.             }
  550.             else
  551.             {
  552.                 UE_LOG(LogOnline, Warning, TEXT("No valid identity interface."));
  553.             }
  554.         }
  555.         else
  556.         {
  557.             UE_LOG(LogOnline, Warning, TEXT("No default online subsystem."));
  558.         }
  559.     }
  560.     else
  561.     {
  562.         UE_LOG(LogOnline, Warning, TEXT("No local player, cannot read achievements."));
  563.     }
  564. }
  565.  
  566. void AVizPlayerController::OnQueryAchievementsComplete(const FUniqueNetId& PlayerId, const bool bWasSuccessful )
  567. {
  568.     UE_LOG(LogOnline, Display, TEXT("AVizPlayerController::OnQueryAchievementsComplete(bWasSuccessful = %s)"), bWasSuccessful ? TEXT("TRUE") : TEXT("FALSE"));
  569. }
  570.  
  571. void AVizPlayerController::UnFreeze()
  572. {
  573.     ServerRestartPlayer();
  574. }
  575.  
  576. void AVizPlayerController::FailedToSpawnPawn()
  577. {
  578.     if(StateName == NAME_Inactive)
  579.     {
  580.         BeginInactiveState();
  581.     }
  582.     Super::FailedToSpawnPawn();
  583. }
  584.  
  585. void AVizPlayerController::PawnPendingDestroy(APawn* P)
  586. {
  587.     LastDeathLocation = P->GetActorLocation();
  588.     FVector CameraLocation = LastDeathLocation + FVector(0, 0, 300.0f);
  589.     FRotator CameraRotation(-90.0f, 0.0f, 0.0f);
  590.     FindDeathCameraSpot(CameraLocation, CameraRotation);
  591.  
  592.     Super::PawnPendingDestroy(P);
  593.  
  594.     ClientSetSpectatorCamera(CameraLocation, CameraRotation);
  595. }
  596.  
  597. void AVizPlayerController::GameHasEnded(class AActor* EndGameFocus, bool bIsWinner)
  598. {
  599.     UpdateSaveFileOnGameEnd(bIsWinner);
  600.     UpdateAchievementsOnGameEnd();
  601.     UpdateLeaderboardsOnGameEnd();
  602.  
  603.     Super::GameHasEnded(EndGameFocus, bIsWinner);
  604. }
  605.  
  606. void AVizPlayerController::ClientSetSpectatorCamera_Implementation(FVector CameraLocation, FRotator CameraRotation)
  607. {
  608.     SetInitialLocationAndRotation(CameraLocation, CameraRotation);
  609.     SetViewTarget(this);
  610. }
  611.  
  612. bool AVizPlayerController::FindDeathCameraSpot(FVector& CameraLocation, FRotator& CameraRotation)
  613. {
  614.     const FVector PawnLocation = GetPawn()->GetActorLocation();
  615.     FRotator ViewDir = GetControlRotation();
  616.     ViewDir.Pitch = -45.0f;
  617.  
  618.     const float YawOffsets[] = { 0.0f, -180.0f, 90.0f, -90.0f, 45.0f, -45.0f, 135.0f, -135.0f };
  619.     const float CameraOffset = 600.0f;
  620.     FCollisionQueryParams TraceParams(TEXT("DeathCamera"), true, GetPawn());
  621.  
  622.     FHitResult HitResult;
  623.     for (int32 i = 0; i < ARRAY_COUNT(YawOffsets); i++)
  624.     {
  625.         FRotator CameraDir = ViewDir;
  626.         CameraDir.Yaw += YawOffsets[i];
  627.         CameraDir.Normalize();
  628.  
  629.         const FVector TestLocation = PawnLocation - CameraDir.Vector() * CameraOffset;
  630.        
  631.         const bool bBlocked = GetWorld()->LineTraceSingleByChannel(HitResult, PawnLocation, TestLocation, ECC_Camera, TraceParams);
  632.  
  633.         if (!bBlocked)
  634.         {
  635.             CameraLocation = TestLocation;
  636.             CameraRotation = CameraDir;
  637.             return true;
  638.         }
  639.     }
  640.  
  641.     return false;
  642. }
  643.  
  644. bool AVizPlayerController::ServerCheat_Validate(const FString& Msg)
  645. {
  646.     return true;
  647. }
  648.  
  649. void AVizPlayerController::ServerCheat_Implementation(const FString& Msg)
  650. {
  651.     if (CheatManager)
  652.     {
  653.         ClientMessage(ConsoleCommand(Msg));
  654.     }
  655. }
  656.  
  657. void AVizPlayerController::SimulateInputKey(FKey Key, bool bPressed)
  658. {
  659.     InputKey(Key, bPressed ? IE_Pressed : IE_Released, 1, false);
  660. }
  661.  
  662. void AVizPlayerController::OnDeathMessage(class AVizPlayerState* KillerPlayerState, class AVizPlayerState* KilledPlayerState, const UDamageType* KillerDamageType)
  663. {
  664.     AVizHUD* VizHUD = GetVizHUD();
  665.     if (VizHUD)
  666.     {
  667.         VizHUD->ShowDeathMessage(KillerPlayerState, KilledPlayerState, KillerDamageType);        
  668.     }
  669.  
  670.     ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player);
  671.     if (LocalPlayer && LocalPlayer->GetCachedUniqueNetId().IsValid() && KilledPlayerState->UniqueId.IsValid())
  672.     {
  673.         // if this controller is the player who died, update the hero stat.
  674.         if (*LocalPlayer->GetCachedUniqueNetId() == *KilledPlayerState->UniqueId)
  675.         {
  676.             const auto Events = Online::GetEventsInterface();
  677.             const auto Identity = Online::GetIdentityInterface();
  678.  
  679.             if (Events.IsValid() && Identity.IsValid())
  680.             {                            
  681.                 const int32 UserIndex = LocalPlayer->GetControllerId();
  682.                 TSharedPtr<const FUniqueNetId> UniqueID = Identity->GetUniquePlayerId(UserIndex);
  683.                 if (UniqueID.IsValid())
  684.                 {                
  685.                     AVizCharacter* pPawn = Cast<AVizCharacter>(GetCharacter());
  686.                     //AVizWeapon* Weapon = Pawn ? Pawn->GetWeapon() : NULL;
  687.  
  688.                     FVector Location = pPawn ? pPawn->GetActorLocation() : FVector::ZeroVector;
  689.                     //int32 WeaponType = Weapon ? (int32)Weapon->GetAmmoType() : 0;
  690.  
  691.                     FOnlineEventParms Params;
  692.                     Params.Add( TEXT( "SectionId" ), FVariantData( (int32)0 ) ); // unused
  693.                     Params.Add( TEXT( "GameplayModeId" ), FVariantData( (int32)1 ) ); // @todo determine game mode (ffa v tdm)
  694.                     Params.Add( TEXT( "DifficultyLevelId" ), FVariantData( (int32)0 ) ); // unused
  695.  
  696.                     Params.Add( TEXT( "PlayerRoleId" ), FVariantData( (int32)0 ) ); // unused
  697.                     //Params.Add( TEXT( "PlayerWeaponId" ), FVariantData( (int32)WeaponType ) );
  698.                     Params.Add( TEXT( "EnemyRoleId" ), FVariantData( (int32)0 ) ); // unused
  699.                     Params.Add( TEXT( "EnemyWeaponId" ), FVariantData( (int32)0 ) ); // untracked
  700.                
  701.                     Params.Add( TEXT( "LocationX" ), FVariantData( Location.X ) );
  702.                     Params.Add( TEXT( "LocationY" ), FVariantData( Location.Y ) );
  703.                     Params.Add( TEXT( "LocationZ" ), FVariantData( Location.Z ) );
  704.                                        
  705.                     Events->TriggerEvent(*UniqueID, TEXT("PlayerDeath"), Params);
  706.                 }
  707.             }
  708.         }
  709.     }    
  710. }
  711.  
  712. void AVizPlayerController::UpdateAchievementProgress( const FString& Id, float Percent )
  713. {
  714.     ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player);
  715.     if (LocalPlayer)
  716.     {
  717.         IOnlineSubsystem* OnlineSub = IOnlineSubsystem::Get();
  718.         if(OnlineSub)
  719.         {
  720.             IOnlineIdentityPtr Identity = OnlineSub->GetIdentityInterface();
  721.             if (Identity.IsValid())
  722.             {
  723.                 TSharedPtr<const FUniqueNetId> UserId = LocalPlayer->GetCachedUniqueNetId();
  724.  
  725.                 if (UserId.IsValid())
  726.                 {
  727.  
  728.                     IOnlineAchievementsPtr Achievements = OnlineSub->GetAchievementsInterface();
  729.                     if (Achievements.IsValid() && (!WriteObject.IsValid() || WriteObject->WriteState != EOnlineAsyncTaskState::InProgress))
  730.                     {
  731.                         WriteObject = MakeShareable(new FOnlineAchievementsWrite());
  732.                         WriteObject->SetFloatStat(*Id, Percent);
  733.  
  734.                         FOnlineAchievementsWriteRef WriteObjectRef = WriteObject.ToSharedRef();
  735.                         Achievements->WriteAchievements(*UserId, WriteObjectRef);
  736.                     }
  737.                     else
  738.                     {
  739.                         UE_LOG(LogOnline, Warning, TEXT("No valid achievement interface or another write is in progress."));
  740.                     }
  741.                 }
  742.                 else
  743.                 {
  744.                     UE_LOG(LogOnline, Warning, TEXT("No valid user id for this controller."));
  745.                 }
  746.             }
  747.             else
  748.             {
  749.                 UE_LOG(LogOnline, Warning, TEXT("No valid identity interface."));
  750.             }
  751.         }
  752.         else
  753.         {
  754.             UE_LOG(LogOnline, Warning, TEXT("No default online subsystem."));
  755.         }
  756.     }
  757.     else
  758.     {
  759.         UE_LOG(LogOnline, Warning, TEXT("No local player, cannot update achievements."));
  760.     }
  761. }
  762.  
  763. void AVizPlayerController::OnToggleInGameMenu()
  764. {
  765.     if( GEngine->GameViewport == nullptr )
  766.     {
  767.         return;
  768.     }
  769.  
  770.     // this is not ideal, but necessary to prevent both players from pausing at the same time on the same frame
  771.     UWorld* GameWorld = GEngine->GameViewport->GetWorld();
  772.  
  773.     for(auto It = GameWorld->GetControllerIterator(); It; ++It)
  774.     {
  775.         AVizPlayerController* Controller = Cast<AVizPlayerController>(*It);
  776.         if(Controller && Controller->IsPaused())
  777.         {
  778.             return;
  779.         }
  780.     }
  781.  
  782.     // if no one's paused, pause
  783.     if (VizIngameMenu.IsValid())
  784.     {
  785.         VizIngameMenu->ToggleGameMenu();
  786.     }
  787. }
  788.  
  789. void AVizPlayerController::OnConditionalCloseScoreboard()
  790. {
  791.     AVizHUD* VizHUD = GetVizHUD();
  792.     if(VizHUD && ( VizHUD->IsMatchOver() == false ))
  793.     {
  794.         VizHUD->ConditionalCloseScoreboard();
  795.     }
  796. }
  797.  
  798. void AVizPlayerController::OnToggleScoreboard()
  799. {
  800.     AVizHUD* VizHUD = GetVizHUD();
  801.     if(VizHUD && ( VizHUD->IsMatchOver() == false ))
  802.     {
  803.         VizHUD->ToggleScoreboard();
  804.     }
  805. }
  806.  
  807. void AVizPlayerController::OnShowScoreboard()
  808. {
  809.     AVizHUD* VizHUD = GetVizHUD();
  810.     if(VizHUD)
  811.     {
  812.         VizHUD->ShowScoreboard(true);
  813.     }
  814. }
  815.  
  816. void AVizPlayerController::OnHideScoreboard()
  817. {
  818.     AVizHUD* VizHUD = GetVizHUD();
  819.     // If have a valid match and the match is over - hide the scoreboard
  820.     if( (VizHUD != NULL ) && ( VizHUD->IsMatchOver() == false ) )
  821.     {
  822.         VizHUD->ShowScoreboard(false);
  823.     }
  824. }
  825.  
  826. bool AVizPlayerController::IsGameMenuVisible() const
  827. {
  828.     bool Result = false;
  829.     if (VizIngameMenu.IsValid())
  830.     {
  831.         Result = VizIngameMenu->GetIsGameMenuUp();
  832.     }
  833.  
  834.     return Result;
  835. }
  836.  
  837. void AVizPlayerController::SetHealthRegen(bool bEnable)
  838. {
  839.     bHealthRegen = bEnable;
  840. }
  841.  
  842. void AVizPlayerController::SetGodMode(bool bEnable)
  843. {
  844.     bGodMode = bEnable;
  845. }
  846.  
  847. void AVizPlayerController::ClientGameStarted_Implementation()
  848. {
  849.     bAllowGameActions = true;
  850.  
  851.     // Enable controls mode now the game has started
  852.     SetIgnoreMoveInput(false);
  853.  
  854.     AVizHUD* VizHUD = GetVizHUD();
  855.     if (VizHUD)
  856.     {
  857.         VizHUD->SetMatchState(EVizMatchState::Playing);
  858.         VizHUD->ShowScoreboard(false);
  859.     }
  860.     bGameEndedFrame = false;
  861.  
  862.     QueryAchievements();
  863.  
  864.     // Send round start event
  865.     const auto Events = Online::GetEventsInterface();
  866.     ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player);
  867.  
  868.     if(LocalPlayer != nullptr && Events.IsValid())
  869.     {
  870.         auto UniqueId = LocalPlayer->GetPreferredUniqueNetId();
  871.  
  872.         if (UniqueId.IsValid())
  873.         {
  874.             // Generate a new session id
  875.             Events->SetPlayerSessionId(*UniqueId, FGuid::NewGuid());
  876.  
  877.             FString MapName = *FPackageName::GetShortName(GetWorld()->PersistentLevel->GetOutermost()->GetName());
  878.  
  879.             // Fire session start event for all cases
  880.             FOnlineEventParms Params;
  881.             Params.Add( TEXT( "GameplayModeId" ), FVariantData( (int32)1 ) ); // @todo determine game mode (ffa v tdm)
  882.             Params.Add( TEXT( "DifficultyLevelId" ), FVariantData( (int32)0 ) ); // unused
  883.             Params.Add( TEXT( "MapName" ), FVariantData( MapName ) );
  884.            
  885.             Events->TriggerEvent(*UniqueId, TEXT("PlayerSessionStart"), Params);
  886.  
  887.             // Online matches require the MultiplayerRoundStart event as well
  888.             UVizGameInstance* SGI = GetWorld() != NULL ? Cast<UVizGameInstance>(GetWorld()->GetGameInstance()) : NULL;
  889.  
  890.             if (SGI->GetIsOnline())
  891.             {
  892.                 FOnlineEventParms MultiplayerParams;
  893.  
  894.                 // @todo: fill in with real values
  895.                 MultiplayerParams.Add( TEXT( "SectionId" ), FVariantData( (int32)0 ) ); // unused
  896.                 MultiplayerParams.Add( TEXT( "GameplayModeId" ), FVariantData( (int32)1 ) ); // @todo determine game mode (ffa v tdm)
  897.                 MultiplayerParams.Add( TEXT( "MatchTypeId" ), FVariantData( (int32)1 ) ); // @todo abstract the specific meaning of this value across platforms
  898.                 MultiplayerParams.Add( TEXT( "DifficultyLevelId" ), FVariantData( (int32)0 ) ); // unused
  899.                
  900.                 Events->TriggerEvent(*UniqueId, TEXT("MultiplayerRoundStart"), MultiplayerParams);
  901.             }
  902.  
  903.             bHasSentStartEvents = true;
  904.         }
  905.     }
  906. }
  907.  
  908. /** Starts the online game using the session name in the PlayerState */
  909. void AVizPlayerController::ClientStartOnlineGame_Implementation()
  910. {
  911.     if (!IsPrimaryPlayer())
  912.         return;
  913.  
  914.     AVizPlayerState* VizPlayerState = Cast<AVizPlayerState>(PlayerState);
  915.     if (VizPlayerState)
  916.     {
  917.         IOnlineSubsystem* OnlineSub = IOnlineSubsystem::Get();
  918.         if (OnlineSub)
  919.         {
  920.             IOnlineSessionPtr Sessions = OnlineSub->GetSessionInterface();
  921.             if (Sessions.IsValid())
  922.             {
  923.                 UE_LOG(LogOnline, Log, TEXT("Starting session %s on client"), *VizPlayerState->SessionName.ToString() );
  924.                 Sessions->StartSession(VizPlayerState->SessionName);
  925.             }
  926.         }
  927.     }
  928.     else
  929.     {
  930.         // Keep retrying until player state is replicated
  931.         GetWorld()->GetTimerManager().SetTimer(TimerHandle_ClientStartOnlineGame, this, &AVizPlayerController::ClientStartOnlineGame_Implementation, 0.2f, false);
  932.     }
  933. }
  934.  
  935. /** Ends the online game using the session name in the PlayerState */
  936. void AVizPlayerController::ClientEndOnlineGame_Implementation()
  937. {
  938.     if (!IsPrimaryPlayer())
  939.         return;
  940.  
  941.     AVizPlayerState* VizPlayerState = Cast<AVizPlayerState>(PlayerState);
  942.     if (VizPlayerState)
  943.     {
  944.         IOnlineSubsystem* OnlineSub = IOnlineSubsystem::Get();
  945.         if (OnlineSub)
  946.         {
  947.             IOnlineSessionPtr Sessions = OnlineSub->GetSessionInterface();
  948.             if (Sessions.IsValid())
  949.             {
  950.                 UE_LOG(LogOnline, Log, TEXT("Ending session %s on client"), *VizPlayerState->SessionName.ToString() );
  951.                 Sessions->EndSession(VizPlayerState->SessionName);
  952.             }
  953.         }
  954.     }
  955. }
  956.  
  957. void AVizPlayerController::HandleReturnToMainMenu()
  958. {
  959.     OnHideScoreboard();
  960.     CleanupSessionOnReturnToMenu();
  961. }
  962.  
  963. void AVizPlayerController::ClientReturnToMainMenu_Implementation(const FString& InReturnReason)
  964. {        
  965.     UVizGameInstance* SGI = GetWorld() != NULL ? Cast<UVizGameInstance>(GetWorld()->GetGameInstance()) : NULL;
  966.  
  967.     if ( !ensure( SGI != NULL ) )
  968.     {
  969.         return;
  970.     }
  971.  
  972.     if ( GetNetMode() == NM_Client )
  973.     {
  974.         const FText ReturnReason    = NSLOCTEXT( "NetworkErrors", "HostQuit", "The host has quit the match." );
  975.         const FText OKButton        = NSLOCTEXT( "DialogButtons", "OKAY", "OK" );
  976.  
  977.         SGI->ShowMessageThenGotoState( ReturnReason, OKButton, FText::GetEmpty(), VizGameInstanceState::MainMenu );
  978.     }
  979.     else
  980.     {
  981.         SGI->GotoState(VizGameInstanceState::MainMenu);
  982.     }
  983.  
  984.     // Clear the flag so we don't do normal end of round stuff next
  985.     bGameEndedFrame = false;
  986. }
  987.  
  988. /** Ends and/or destroys game session */
  989. void AVizPlayerController::CleanupSessionOnReturnToMenu()
  990. {
  991.     UVizGameInstance * SGI = GetWorld() != NULL ? Cast<UVizGameInstance>( GetWorld()->GetGameInstance() ) : NULL;
  992.  
  993.     if ( ensure( SGI != NULL ) )
  994.     {
  995.         SGI->CleanupSessionOnReturnToMenu();
  996.     }
  997. }
  998.  
  999. void AVizPlayerController::ClientGameEnded_Implementation(class AActor* EndGameFocus, bool bIsWinner)
  1000. {
  1001.     Super::ClientGameEnded_Implementation(EndGameFocus, bIsWinner);
  1002.    
  1003.     // Disable controls now the game has ended
  1004.     SetIgnoreMoveInput(true);
  1005.  
  1006.     bAllowGameActions = false;
  1007.  
  1008.     // Make sure that we still have valid view target
  1009.     SetViewTarget(GetPawn());
  1010.  
  1011.     AVizHUD* VizHUD = GetVizHUD();
  1012.     if (VizHUD)
  1013.     {
  1014.         VizHUD->SetMatchState(bIsWinner ? EVizMatchState::Won : EVizMatchState::Lost);
  1015.     }
  1016.  
  1017.     UpdateSaveFileOnGameEnd(bIsWinner);
  1018.     UpdateAchievementsOnGameEnd();
  1019.     UpdateLeaderboardsOnGameEnd();
  1020.  
  1021.     // Flag that the game has just ended (if it's ended due to host loss we want to wait for ClientReturnToMainMenu_Implementation first, incase we don't want to process)
  1022.     bGameEndedFrame = true;
  1023. }
  1024.  
  1025. void AVizPlayerController::ClientSendRoundEndEvent_Implementation(bool bIsWinner, int32 ExpendedTimeInSeconds)
  1026. {
  1027.     const auto Events = Online::GetEventsInterface();
  1028.     ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player);
  1029.  
  1030.     if(bHasSentStartEvents && LocalPlayer != nullptr && Events.IsValid())
  1031.     {    
  1032.         auto UniqueId = LocalPlayer->GetPreferredUniqueNetId();
  1033.  
  1034.         if (UniqueId.IsValid())
  1035.         {
  1036.             FString MapName = *FPackageName::GetShortName(GetWorld()->PersistentLevel->GetOutermost()->GetName());
  1037.             AVizPlayerState* VizPlayerState = Cast<AVizPlayerState>(PlayerState);
  1038.             int32 PlayerScore = VizPlayerState ? VizPlayerState->GetScore() : 0;
  1039.            
  1040.             // Fire session end event for all cases
  1041.             FOnlineEventParms Params;
  1042.             Params.Add( TEXT( "GameplayModeId" ), FVariantData( (int32)1 ) ); // @todo determine game mode (ffa v tdm)
  1043.             Params.Add( TEXT( "DifficultyLevelId" ), FVariantData( (int32)0 ) ); // unused
  1044.             Params.Add( TEXT( "ExitStatusId" ), FVariantData( (int32)0 ) ); // unused
  1045.             Params.Add( TEXT( "PlayerScore" ), FVariantData( (int32)PlayerScore ) );
  1046.             Params.Add( TEXT( "PlayerWon" ), FVariantData( (bool)bIsWinner ) );
  1047.             Params.Add( TEXT( "MapName" ), FVariantData( MapName ) );
  1048.             Params.Add( TEXT( "MapNameString" ), FVariantData( MapName ) ); // @todo workaround for a bug in backend service, remove when fixed
  1049.            
  1050.             Events->TriggerEvent(*UniqueId, TEXT("PlayerSessionEnd"), Params);
  1051.  
  1052.             // Online matches require the MultiplayerRoundEnd event as well
  1053.             UVizGameInstance* SGI = GetWorld() != NULL ? Cast<UVizGameInstance>(GetWorld()->GetGameInstance()) : NULL;
  1054.             if (SGI->GetIsOnline())
  1055.             {
  1056.                 FOnlineEventParms MultiplayerParams;
  1057.  
  1058.                 AVizGameState* const MyGameState = GetWorld() != NULL ? GetWorld()->GetGameState<AVizGameState>() : NULL;
  1059.                 if (ensure(MyGameState != nullptr))
  1060.                 {
  1061.                     MultiplayerParams.Add( TEXT( "SectionId" ), FVariantData( (int32)0 ) ); // unused
  1062.                     MultiplayerParams.Add( TEXT( "GameplayModeId" ), FVariantData( (int32)1 ) ); // @todo determine game mode (ffa v tdm)
  1063.                     MultiplayerParams.Add( TEXT( "MatchTypeId" ), FVariantData( (int32)1 ) ); // @todo abstract the specific meaning of this value across platforms
  1064.                     MultiplayerParams.Add( TEXT( "DifficultyLevelId" ), FVariantData( (int32)0 ) ); // unused
  1065.                     MultiplayerParams.Add( TEXT( "TimeInSeconds" ), FVariantData( (float)ExpendedTimeInSeconds ) );
  1066.                     MultiplayerParams.Add( TEXT( "ExitStatusId" ), FVariantData( (int32)0 ) ); // unused
  1067.                    
  1068.                     Events->TriggerEvent(*UniqueId, TEXT("MultiplayerRoundEnd"), MultiplayerParams);
  1069.                 }
  1070.             }
  1071.         }
  1072.  
  1073.         bHasSentStartEvents = false;
  1074.     }
  1075. }
  1076.  
  1077. void AVizPlayerController::SetCinematicMode(bool bInCinematicMode, bool bHidePlayer, bool bAffectsHUD, bool bAffectsMovement, bool bAffectsTurning)
  1078. {
  1079.     Super::SetCinematicMode(bInCinematicMode, bHidePlayer, bAffectsHUD, bAffectsMovement, bAffectsTurning);
  1080.  
  1081.     // If we have a pawn we need to determine if we should show/hide the weapon
  1082.     AVizCharacter* MyPawn = Cast<AVizCharacter>(GetPawn());
  1083.     /*AVizWeapon* MyWeapon = MyPawn ? MyPawn->GetWeapon() : NULL;
  1084.     if (MyWeapon)
  1085.     {
  1086.         if (bInCinematicMode && bHidePlayer)
  1087.         {
  1088.             MyWeapon->SetActorHiddenInGame(true);
  1089.         }
  1090.         else if (!bCinematicMode)
  1091.         {
  1092.             MyWeapon->SetActorHiddenInGame(false);
  1093.         }
  1094.     }*/
  1095. }
  1096.  
  1097. bool AVizPlayerController::IsMoveInputIgnored() const
  1098. {
  1099.     if (IsInState(NAME_Spectating))
  1100.     {
  1101.         return false;
  1102.     }
  1103.     else
  1104.     {
  1105.         return Super::IsMoveInputIgnored();
  1106.     }
  1107. }
  1108.  
  1109. bool AVizPlayerController::IsLookInputIgnored() const
  1110. {
  1111.     if (IsInState(NAME_Spectating))
  1112.     {
  1113.         return false;
  1114.     }
  1115.     else
  1116.     {
  1117.         return Super::IsLookInputIgnored();
  1118.     }
  1119. }
  1120.  
  1121. void AVizPlayerController::InitInputSystem()
  1122. {
  1123.     Super::InitInputSystem();
  1124.  
  1125.     UVizPersistentUser* PersistentUser = GetPersistentUser();
  1126.     if(PersistentUser)
  1127.     {
  1128.         PersistentUser->TellInputAboutKeybindings();
  1129.     }
  1130. }
  1131.  
  1132. void AVizPlayerController::GetLifetimeReplicatedProps( TArray< FLifetimeProperty > & OutLifetimeProps ) const
  1133. {
  1134.     Super::GetLifetimeReplicatedProps( OutLifetimeProps );
  1135. }
  1136.  
  1137. void AVizPlayerController::Suicide()
  1138. {
  1139.     if ( IsInState(NAME_Playing) )
  1140.     {
  1141.         ServerSuicide();
  1142.     }
  1143. }
  1144.  
  1145. bool AVizPlayerController::ServerSuicide_Validate()
  1146. {
  1147.     return true;
  1148. }
  1149.  
  1150. void AVizPlayerController::ServerSuicide_Implementation()
  1151. {
  1152.     // TODO @Anindo
  1153.     /*if ( (GetPawn() != NULL) && ((GetWorld()->TimeSeconds - GetPawn()->CreationTime > 1) || (GetNetMode() == NM_Standalone)) )
  1154.     {
  1155.         AVizCharacter* MyPawn = Cast<AVizCharacter>(GetPawn());
  1156.         if (MyPawn)
  1157.         {
  1158.             MyPawn->Suicide();
  1159.         }
  1160.     }*/
  1161. }
  1162.  
  1163. //bool AVizPlayerController::HasInfiniteAmmo() const
  1164. //{
  1165. //    return bInfiniteAmmo;
  1166. //}
  1167. //
  1168. //bool AVizPlayerController::HasInfiniteClip() const
  1169. //{
  1170. //    return bInfiniteClip;
  1171. //}
  1172.  
  1173. bool AVizPlayerController::HasHealthRegen() const
  1174. {
  1175.     return bHealthRegen;
  1176. }
  1177.  
  1178. bool AVizPlayerController::HasGodMode() const
  1179. {
  1180.     return bGodMode;
  1181. }
  1182.  
  1183. bool AVizPlayerController::IsGameInputAllowed() const
  1184. {
  1185.     return bAllowGameActions && !bCinematicMode;
  1186. }
  1187.  
  1188. void AVizPlayerController::ToggleChatWindow()
  1189. {
  1190.     AVizHUD* VizHUD = Cast<AVizHUD>(GetHUD());
  1191.     if (VizHUD)
  1192.     {
  1193.         VizHUD->ToggleChat();
  1194.     }
  1195. }
  1196.  
  1197. void AVizPlayerController::OnLeftMouseUp()
  1198. {
  1199.     if (OnMouseUpEvent.IsBound())
  1200.     {
  1201.         OnMouseUpEvent.Execute();
  1202.     }
  1203. }
  1204.  
  1205. void AVizPlayerController::ClientTeamMessage_Implementation( APlayerState* SenderPlayerState, const FString& S, FName Type, float MsgLifeTime  )
  1206. {
  1207.     AVizHUD* VizHUD = Cast<AVizHUD>(GetHUD());
  1208.     if (VizHUD)
  1209.     {
  1210.         if( Type == ServerSayString )
  1211.         {
  1212.             if( SenderPlayerState != PlayerState  )
  1213.             {
  1214.                 VizHUD->AddChatLine(FText::FromString(S), false);
  1215.             }
  1216.         }
  1217.     }
  1218. }
  1219.  
  1220. void AVizPlayerController::Say( const FString& Msg )
  1221. {
  1222.     ServerSay(Msg);
  1223. }
  1224.  
  1225. bool AVizPlayerController::ServerSay_Validate( const FString& Msg )
  1226. {
  1227.     return true;
  1228. }
  1229.  
  1230. void AVizPlayerController::ServerSay_Implementation( const FString& Msg )
  1231. {
  1232.     AGameMode * pGameMode = Cast<AGameMode>(GetWorld()->GetAuthGameMode());
  1233.     if (pGameMode)
  1234.     {
  1235.         pGameMode->Broadcast(this, Msg, ServerSayString);
  1236.     }
  1237. }
  1238.  
  1239. AVizHUD* AVizPlayerController::GetVizHUD() const
  1240. {
  1241.     return Cast<AVizHUD>(GetHUD());
  1242. }
  1243.  
  1244.  
  1245. UVizPersistentUser* AVizPlayerController::GetPersistentUser() const
  1246. {
  1247.     UVizLocalPlayer* const VizLocalPlayer = Cast<UVizLocalPlayer>(Player);
  1248.     return VizLocalPlayer ? VizLocalPlayer->GetPersistentUser() : nullptr;
  1249. }
  1250.  
  1251. bool AVizPlayerController::SetPause(bool bPause, FCanUnpause CanUnpauseDelegate /*= FCanUnpause()*/)
  1252. {
  1253.     const bool Result = APlayerController::SetPause(bPause, CanUnpauseDelegate);
  1254.  
  1255.     // Update rich presence.
  1256.     const auto PresenceInterface = Online::GetPresenceInterface();
  1257.     const auto Events = Online::GetEventsInterface();
  1258.     const auto LocalPlayer = Cast<ULocalPlayer>(Player);
  1259.     TSharedPtr<const FUniqueNetId> UserId = LocalPlayer ? LocalPlayer->GetCachedUniqueNetId() : nullptr;
  1260.  
  1261.     if(PresenceInterface.IsValid() && UserId.IsValid())
  1262.     {
  1263.         FOnlineUserPresenceStatus PresenceStatus;
  1264.         if(Result && bPause)
  1265.         {
  1266.             PresenceStatus.Properties.Add(DefaultPresenceKey, FString("Paused"));
  1267.         }
  1268.         else
  1269.         {
  1270.             PresenceStatus.Properties.Add(DefaultPresenceKey, FString("InGame"));
  1271.         }
  1272.         PresenceInterface->SetPresence(*UserId, PresenceStatus);
  1273.  
  1274.     }
  1275.  
  1276.     // Don't send pause events while online since the game doesn't actually pause
  1277.     if(GetNetMode() == NM_Standalone && Events.IsValid() && PlayerState->UniqueId.IsValid())
  1278.     {
  1279.         FOnlineEventParms Params;
  1280.         Params.Add( TEXT( "GameplayModeId" ), FVariantData( (int32)1 ) ); // @todo determine game mode (ffa v tdm)
  1281.         Params.Add( TEXT( "DifficultyLevelId" ), FVariantData( (int32)0 ) ); // unused
  1282.         if(Result && bPause)
  1283.         {
  1284.             Events->TriggerEvent(*PlayerState->UniqueId, TEXT("PlayerSessionPause"), Params);
  1285.         }
  1286.         else
  1287.         {
  1288.             Events->TriggerEvent(*PlayerState->UniqueId, TEXT("PlayerSessionResume"), Params);
  1289.         }
  1290.     }
  1291.  
  1292.     return Result;
  1293. }
  1294.  
  1295. void AVizPlayerController::ShowInGameMenu()
  1296. {
  1297.     AVizHUD* VizHUD = GetVizHUD();    
  1298.     if(VizIngameMenu.IsValid() && !VizIngameMenu->GetIsGameMenuUp() && VizHUD && (VizHUD->IsMatchOver() == false))
  1299.     {
  1300.         VizIngameMenu->ToggleGameMenu();
  1301.     }
  1302. }
  1303. void AVizPlayerController::UpdateAchievementsOnGameEnd()
  1304. {
  1305.     ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player);
  1306.     if (LocalPlayer)
  1307.     {
  1308.         AVizPlayerState* VizPlayerState = Cast<AVizPlayerState>(PlayerState);
  1309.         if (VizPlayerState)
  1310.         {            
  1311.             const UVizPersistentUser*  PersistentUser = GetPersistentUser();
  1312.  
  1313.             if (PersistentUser)
  1314.             {                        
  1315.                 const int32 Wins = PersistentUser->GetWins();
  1316.                 const int32 Losses = PersistentUser->GetLosses();
  1317.                 const int32 Matches = Wins + Losses;
  1318.  
  1319.                 const int32 TotalKills = PersistentUser->GetKills();
  1320.                 const int32 MatchScore = (int32)VizPlayerState->GetScore();
  1321.  
  1322.                 const int32 TotalBulletsFired = PersistentUser->GetBulletsFired();
  1323.                 const int32 TotalRocketsFired = PersistentUser->GetRocketsFired();
  1324.            
  1325.                 float TotalGameAchievement = 0;
  1326.                 float CurrentGameAchievement = 0;
  1327.            
  1328.                 ///////////////////////////////////////
  1329.                 // Kill achievements
  1330.                 if (TotalKills >= 1)
  1331.                 {
  1332.                     CurrentGameAchievement += 100.0f;
  1333.                 }
  1334.                 TotalGameAchievement += 100;
  1335.  
  1336.                 {
  1337.                     float fSomeKillPct = ((float)TotalKills / (float)SomeKillsCount) * 100.0f;
  1338.                     fSomeKillPct = FMath::RoundToFloat(fSomeKillPct);
  1339.                     UpdateAchievementProgress(ACH_SOME_KILLS, fSomeKillPct);
  1340.  
  1341.                     CurrentGameAchievement += FMath::Min(fSomeKillPct, 100.0f);
  1342.                     TotalGameAchievement += 100;
  1343.                 }
  1344.  
  1345.                 {
  1346.                     float fLotsKillPct = ((float)TotalKills / (float)LotsKillsCount) * 100.0f;
  1347.                     fLotsKillPct = FMath::RoundToFloat(fLotsKillPct);
  1348.                     UpdateAchievementProgress(ACH_LOTS_KILLS, fLotsKillPct);
  1349.  
  1350.                     CurrentGameAchievement += FMath::Min(fLotsKillPct, 100.0f);
  1351.                     TotalGameAchievement += 100;
  1352.                 }
  1353.                 ///////////////////////////////////////
  1354.  
  1355.                 ///////////////////////////////////////
  1356.                 // Match Achievements
  1357.                 {
  1358.                     UpdateAchievementProgress(ACH_FINISH_MATCH, 100.0f);
  1359.  
  1360.                     CurrentGameAchievement += 100;
  1361.                     TotalGameAchievement += 100;
  1362.                 }
  1363.            
  1364.                 {
  1365.                     float fLotsRoundsPct = ((float)Matches / (float)LotsMatchesCount) * 100.0f;
  1366.                     fLotsRoundsPct = FMath::RoundToFloat(fLotsRoundsPct);
  1367.                     UpdateAchievementProgress(ACH_LOTS_MATCHES, fLotsRoundsPct);
  1368.  
  1369.                     CurrentGameAchievement += FMath::Min(fLotsRoundsPct, 100.0f);
  1370.                     TotalGameAchievement += 100;
  1371.                 }
  1372.                 ///////////////////////////////////////
  1373.  
  1374.                 ///////////////////////////////////////
  1375.                 // Win Achievements
  1376.                 if (Wins >= 1)
  1377.                 {
  1378.                     UpdateAchievementProgress(ACH_FIRST_WIN, 100.0f);
  1379.  
  1380.                     CurrentGameAchievement += 100.0f;
  1381.                 }
  1382.                 TotalGameAchievement += 100;
  1383.  
  1384.                 {            
  1385.                     float fLotsWinPct = ((float)Wins / (float)LotsWinsCount) * 100.0f;
  1386.                     fLotsWinPct = FMath::RoundToInt(fLotsWinPct);
  1387.                     UpdateAchievementProgress(ACH_LOTS_WIN, fLotsWinPct);
  1388.  
  1389.                     CurrentGameAchievement += FMath::Min(fLotsWinPct, 100.0f);
  1390.                     TotalGameAchievement += 100;
  1391.                 }
  1392.  
  1393.                 {            
  1394.                     float fManyWinPct = ((float)Wins / (float)ManyWinsCount) * 100.0f;
  1395.                     fManyWinPct = FMath::RoundToInt(fManyWinPct);
  1396.                     UpdateAchievementProgress(ACH_MANY_WIN, fManyWinPct);
  1397.  
  1398.                     CurrentGameAchievement += FMath::Min(fManyWinPct, 100.0f);
  1399.                     TotalGameAchievement += 100;
  1400.                 }
  1401.                 ///////////////////////////////////////
  1402.  
  1403.                 ///////////////////////////////////////
  1404.                 // Ammo Achievements
  1405.                 {
  1406.                     float fLotsBulletsPct = ((float)TotalBulletsFired / (float)LotsBulletsCount) * 100.0f;
  1407.                     fLotsBulletsPct = FMath::RoundToFloat(fLotsBulletsPct);
  1408.                     UpdateAchievementProgress(ACH_SHOOT_BULLETS, fLotsBulletsPct);
  1409.  
  1410.                     CurrentGameAchievement += FMath::Min(fLotsBulletsPct, 100.0f);
  1411.                     TotalGameAchievement += 100;
  1412.                 }
  1413.  
  1414.                 {
  1415.                     float fLotsRocketsPct = ((float)TotalRocketsFired / (float)LotsRocketsCount) * 100.0f;
  1416.                     fLotsRocketsPct = FMath::RoundToFloat(fLotsRocketsPct);
  1417.                     UpdateAchievementProgress(ACH_SHOOT_ROCKETS, fLotsRocketsPct);
  1418.  
  1419.                     CurrentGameAchievement += FMath::Min(fLotsRocketsPct, 100.0f);
  1420.                     TotalGameAchievement += 100;
  1421.                 }
  1422.                 ///////////////////////////////////////
  1423.  
  1424.                 ///////////////////////////////////////
  1425.                 // Score Achievements
  1426.                 {
  1427.                     float fGoodScorePct = ((float)MatchScore / (float)GoodScoreCount) * 100.0f;
  1428.                     fGoodScorePct = FMath::RoundToFloat(fGoodScorePct);
  1429.                     UpdateAchievementProgress(ACH_GOOD_SCORE, fGoodScorePct);
  1430.                 }
  1431.  
  1432.                 {
  1433.                     float fGreatScorePct = ((float)MatchScore / (float)GreatScoreCount) * 100.0f;
  1434.                     fGreatScorePct = FMath::RoundToFloat(fGreatScorePct);
  1435.                     UpdateAchievementProgress(ACH_GREAT_SCORE, fGreatScorePct);
  1436.                 }
  1437.                 ///////////////////////////////////////
  1438.  
  1439.                 ///////////////////////////////////////
  1440.                 // Map Play Achievements
  1441.                 UWorld* World = GetWorld();
  1442.                 if (World)
  1443.                 {            
  1444.                     FString MapName = *FPackageName::GetShortName(World->PersistentLevel->GetOutermost()->GetName());
  1445.                     if (MapName.Find(TEXT("Highrise")) != -1)
  1446.                     {
  1447.                         UpdateAchievementProgress(ACH_PLAY_HIGHRISE, 100.0f);
  1448.                     }
  1449.                     else if (MapName.Find(TEXT("Sanctuary")) != -1)
  1450.                     {
  1451.                         UpdateAchievementProgress(ACH_PLAY_SANCTUARY, 100.0f);
  1452.                     }
  1453.                 }
  1454.                 ///////////////////////////////////////            
  1455.  
  1456.                 const auto Events = Online::GetEventsInterface();
  1457.                 const auto Identity = Online::GetIdentityInterface();
  1458.  
  1459.                 if (Events.IsValid() && Identity.IsValid())
  1460.                 {                            
  1461.                     const int32 UserIndex = LocalPlayer->GetControllerId();
  1462.                     TSharedPtr<const FUniqueNetId> UniqueID = Identity->GetUniquePlayerId(UserIndex);
  1463.                     if (UniqueID.IsValid())
  1464.                     {                
  1465.                         FOnlineEventParms Params;
  1466.  
  1467.                         float fGamePct = (CurrentGameAchievement / TotalGameAchievement) * 100.0f;
  1468.                         fGamePct = FMath::RoundToFloat(fGamePct);
  1469.                         Params.Add( TEXT( "CompletionPercent" ), FVariantData( (float)fGamePct ) );
  1470.                         if (UniqueID.IsValid())
  1471.                         {                
  1472.                             Events->TriggerEvent(*UniqueID, TEXT("GameProgress"), Params);
  1473.                         }
  1474.                     }
  1475.                 }
  1476.             }
  1477.         }
  1478.     }
  1479. }
  1480.  
  1481. void AVizPlayerController::UpdateLeaderboardsOnGameEnd()
  1482. {
  1483.     ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player);
  1484.     if (LocalPlayer)
  1485.     {
  1486.         // update leaderboards - note this does not respect existing scores and overwrites them. We would first need to read the leaderboards if we wanted to do that.
  1487.         IOnlineSubsystem* const OnlineSub = IOnlineSubsystem::Get();
  1488.         if (OnlineSub)
  1489.         {
  1490.             IOnlineIdentityPtr Identity = OnlineSub->GetIdentityInterface();
  1491.             if (Identity.IsValid())
  1492.             {
  1493.                 TSharedPtr<const FUniqueNetId> UserId = Identity->GetUniquePlayerId(LocalPlayer->GetControllerId());
  1494.                 if (UserId.IsValid())
  1495.                 {
  1496.                     IOnlineLeaderboardsPtr Leaderboards = OnlineSub->GetLeaderboardsInterface();
  1497.                     if (Leaderboards.IsValid())
  1498.                     {
  1499.                         AVizPlayerState* VizPlayerState = Cast<AVizPlayerState>(PlayerState);
  1500.                         if (VizPlayerState)
  1501.                         {
  1502.                             FVizAllTimeMatchResultsWrite ResultsWriteObject;
  1503.  
  1504.                             ResultsWriteObject.SetIntStat(LEADERBOARD_STAT_SCORE, VizPlayerState->GetKills());
  1505.                             ResultsWriteObject.SetIntStat(LEADERBOARD_STAT_KILLS, VizPlayerState->GetKills());
  1506.                             ResultsWriteObject.SetIntStat(LEADERBOARD_STAT_DEATHS, VizPlayerState->GetDeaths());
  1507.                             ResultsWriteObject.SetIntStat(LEADERBOARD_STAT_MATCHESPLAYED, 1);
  1508.  
  1509.                             // the call will copy the user id and write object to its own memory
  1510.                             Leaderboards->WriteLeaderboards(VizPlayerState->SessionName, *UserId, ResultsWriteObject);
  1511.                             Leaderboards->FlushLeaderboards(TEXT("VizGAME"));
  1512.                         }
  1513.                     }
  1514.                 }
  1515.             }
  1516.         }
  1517.     }
  1518. }
  1519.  
  1520. void AVizPlayerController::UpdateSaveFileOnGameEnd(bool bIsWinner)
  1521. {
  1522.     AVizPlayerState* VizPlayerState = Cast<AVizPlayerState>(PlayerState);
  1523.     if (VizPlayerState)
  1524.     {
  1525.         // update local saved profile
  1526.         UVizPersistentUser* const PersistentUser = GetPersistentUser();
  1527.         if (PersistentUser)
  1528.         {
  1529.             PersistentUser->AddMatchResult(VizPlayerState->GetKills(), VizPlayerState->GetDeaths(), VizPlayerState->GetNumBulletsFired(), VizPlayerState->GetNumRocketsFired(), bIsWinner);
  1530.             PersistentUser->SaveIfDirty();
  1531.         }
  1532.     }
  1533. }
  1534.  
  1535. void AVizPlayerController::OnWidgetManagerCreated()
  1536. {
  1537.     m_pWidgetManager = Cast<UVizWidgetManager>(m_pWidgetManagerBase);
  1538.     m_pWidgetManager->Init(this);
  1539.     m_pWidgetManager->CreateWidgets(this);
  1540.  
  1541. }
  1542.  
  1543. void AVizPlayerController::PreClientTravel(const FString& PendingURL, ETravelType TravelType, bool bIsSeamlessTravel)
  1544. {
  1545.     Super::PreClientTravel( PendingURL, TravelType, bIsSeamlessTravel );
  1546.  
  1547.     if ( GetWorld() != NULL )
  1548.     {
  1549.         UVizGameViewportClient* VizViewport = Cast<UVizGameViewportClient>( GetWorld()->GetGameViewport() );
  1550.  
  1551.         if ( VizViewport != NULL )
  1552.         {
  1553.             VizViewport->ShowLoadingScreen();
  1554.         }
  1555.        
  1556.         AVizHUD* VizHUD = Cast<AVizHUD>(GetHUD());
  1557.         if (VizHUD != nullptr)
  1558.         {
  1559.             // Passing true to bFocus here ensures that focus is returned to the game viewport.
  1560.             VizHUD->ShowScoreboard(false, true);
  1561.         }
  1562.     }
  1563. }
  1564.  
  1565. void AVizPlayerController::OnGameMapEnabled(bool bEnabled)
  1566. {
  1567.     if (GEngine->HMDDevice.Get())
  1568.     {
  1569.         return;
  1570.     }
  1571.  
  1572.     if (bEnabled)
  1573.     {
  1574.         m_pWidgetManagerBase->ShowLevelMapOptionsScreen();
  1575.     }
  1576.     else
  1577.     {
  1578.         m_pWidgetManagerBase->RemoveLevelMapOptionsScreen();
  1579.     }
  1580. }
  1581.  
  1582. void AVizPlayerController::OnRadioBroadcastEventTriggered(float fTimeInSeconds)
  1583. {
  1584.     GetWorld()->GetTimerManager().SetTimer(m_timerHandle_RadioBroadcast, this, &AVizPlayerController::OnRadioBroadcastEventStopped, fTimeInSeconds, false);
  1585.  
  1586.     m_pWidgetManager->OnRadioBroadcastEventTriggered(fTimeInSeconds);
  1587. }
  1588. void AVizPlayerController::OnRadioBroadcastEventStopped()
  1589. {
  1590.     m_pWidgetManager->OnRadioBroadcastEventStopped();
  1591. }
  1592.  
  1593. void AVizPlayerController::OnShowTestSubmitForm()
  1594. {
  1595.     if (GEngine->HMDDevice.Get())
  1596.     {
  1597.         return;
  1598.     }
  1599.  
  1600.     m_pWidgetManager->ShowTestSubmitForm();
  1601. }
  1602.  
  1603. void AVizPlayerController::GetMapData(FMapInfo& mapInfo)
  1604. {
  1605.     mapInfo = m_MapInfo;
  1606. }
  1607.  
  1608. void AVizPlayerController::RequestForMapInfo_Server_Implementation()
  1609. {
  1610.     TArray<FVector2D> points;
  1611.     FMapInfo mapInfo;
  1612.  
  1613.  
  1614.     AVizGameMode* pGameMode = GetWorld()->GetAuthGameMode<AVizGameMode>();
  1615.  
  1616.     if (pGameMode)
  1617.     {
  1618.         pGameMode->GetMapData(mapInfo);
  1619.     }
  1620.  
  1621.     OnMapInfoReceived_Client(mapInfo);
  1622. }
  1623.  
  1624. bool AVizPlayerController::RequestForMapInfo_Server_Validate()
  1625. {
  1626.     return Role >= ROLE_Authority;
  1627. }
  1628.  
  1629. void AVizPlayerController::OnMapInfoReceived_Client_Implementation(const FMapInfo & mapInfo)
  1630. {
  1631.     m_MapInfo = mapInfo;
  1632.  
  1633.     //If guidance arrow is enabled , spawn pathmanager and set data
  1634.     if(PathManagerBP)
  1635.     {
  1636.    
  1637.         m_pPathManager = Cast<AVizPathManager>(GetWorld()->SpawnActor(PathManagerBP));
  1638.    
  1639.         m_pPathManager->SetCharacterReference(Cast<AVizCharacter>(GetPawn()), m_MapInfo.EnableGuidanceArrows);
  1640.  
  1641.         m_pPathManager->SpawnPathCheckpoints(m_MapInfo.MapPath);
  1642.  
  1643.     }
  1644. }
  1645.  
  1646. void AVizPlayerController::ToggleTraineeMap()
  1647. {
  1648.     APawn* pawn = GetPawn();
  1649.  
  1650.     AVizCharacter* MyPawn = Cast<AVizCharacter>(GetPawn());
  1651.  
  1652.     if (GEngine->HMDDevice.Get())
  1653.     {
  1654.  //       return;
  1655.     }
  1656.  
  1657.     if(m_bMapToggleOn)
  1658.     {
  1659. //        m_pWidgetManager->RemoveTraineeMap();
  1660.         MyPawn->TraineeUIWidget->SetWidget(NULL);
  1661.         MyPawn->TraineeUIWidget->SetVisibility(false);
  1662.         ReturnToGameMode();
  1663.     }
  1664.     else
  1665.     {
  1666.         m_pWidgetManager->ShowTraineeMap(MyPawn);
  1667.         MyPawn->TraineeUIWidget->SetVisibility(true);
  1668.        
  1669.         m_bTestToggleOn = false;
  1670.         m_bInventoryToggleOn = false;
  1671.     }
  1672.  
  1673.     m_bMapToggleOn = !m_bMapToggleOn;
  1674.  
  1675. }
  1676.  
  1677. void AVizPlayerController::ToggleTraineeSnowTests()
  1678. {
  1679.     if (GEngine->HMDDevice.Get())
  1680.     {
  1681.         return;
  1682.     }
  1683.  
  1684.     if (m_bTestToggleOn)
  1685.     {
  1686.         m_pWidgetManager->RemoveTraineeSnowTests();
  1687.  
  1688.         AVizCharacter*    currentPawn = Cast<AVizCharacter>(GetPawn());
  1689.  
  1690.         if(!currentPawn || (currentPawn && !currentPawn->CurrentTest))
  1691.         {
  1692.             ReturnToGameMode();
  1693.         }
  1694.        
  1695.     }
  1696.     else
  1697.     {
  1698.         m_pWidgetManager->ShowTraineeSnowTests();
  1699.  
  1700.         m_bInventoryToggleOn = false;
  1701.         m_bMapToggleOn = false;
  1702.     }
  1703.  
  1704.     m_bTestToggleOn = !m_bTestToggleOn;
  1705. }
  1706.  
  1707. void AVizPlayerController::ToggleTraineeInventory()
  1708. {
  1709.     if (GEngine->HMDDevice.Get())
  1710.     {
  1711.         return;
  1712.     }
  1713.  
  1714.     if (m_bInventoryToggleOn)
  1715.     {
  1716.         m_pWidgetManager->RemoveTraineeInventory();
  1717.  
  1718.         ReturnToGameMode();
  1719.        
  1720.     }
  1721.     else
  1722.     {
  1723.         m_pWidgetManager->ShowTraineeInventory();
  1724.  
  1725.         m_bTestToggleOn = false;
  1726.         m_bMapToggleOn = false;
  1727.     }
  1728.  
  1729.     m_bInventoryToggleOn = !m_bInventoryToggleOn;
  1730. }
  1731.  
  1732. void AVizPlayerController::SpawnAllInventory()
  1733. {
  1734.     if(m_pInventoryContainer)
  1735.     {
  1736.         FVector inventorySpawnPoint = GetPawn()->GetActorRightVector() * 100.0f + GetPawn()->GetActorLocation();
  1737.  
  1738.         //m_pInventoryContainer->SpawnActors(m_aPlayerInventoryData,inventorySpawnPoint); // Should be this
  1739.         m_pInventoryContainer->SpawnActors(m_aGameInventoryData, inventorySpawnPoint);
  1740.     }
  1741. }
  1742.  
  1743. void AVizPlayerController::ClearAllInventory()
  1744. {
  1745.     if (m_pInventoryContainer)
  1746.     {
  1747.         m_pInventoryContainer->ClearItems();
  1748.     }
  1749. }
  1750.  
  1751. void AVizPlayerController::RequestForObjectives_Server_Implementation()
  1752. {
  1753.     AVizGameMode* pGameMode = GetWorld()->GetAuthGameMode<AVizGameMode>();
  1754.     FString strObjectives;
  1755.  
  1756.     if (pGameMode)
  1757.     {
  1758.         pGameMode->GetObjectives(strObjectives);
  1759.     }
  1760.  
  1761.     OnObjectivesReceived_Client(strObjectives);
  1762. }
  1763.  
  1764. bool AVizPlayerController::RequestForObjectives_Server_Validate()
  1765. {
  1766.     return Role >= ROLE_Authority;
  1767. }
  1768.  
  1769. void AVizPlayerController::OnObjectivesReceived_Client_Implementation(const FString & objectives)
  1770. {
  1771.     m_strObjectives = objectives;
  1772. }
  1773.  
  1774. void AVizPlayerController::GetObjectives(FString & objectives)
  1775. {
  1776.     objectives = m_strObjectives;
  1777. }
  1778.  
  1779. void AVizPlayerController::RequestForQuestionData_Server_Implementation()
  1780. {
  1781.     AVizGameMode* pGameMode = GetWorld()->GetAuthGameMode<AVizGameMode>();
  1782.     FUIQuestionDataStruct questionData;
  1783.  
  1784.     if (pGameMode)
  1785.     {
  1786.         pGameMode->GetQuestionData(questionData);
  1787.     }
  1788.  
  1789.     OnQuestionDataReceived_Client(questionData);
  1790. }
  1791.  
  1792. bool AVizPlayerController::RequestForQuestionData_Server_Validate()
  1793. {
  1794.     return Role >= ROLE_Authority;
  1795. }
  1796.  
  1797. void AVizPlayerController::OnQuestionDataReceived_Client_Implementation(const FUIQuestionDataStruct &questionData)
  1798. {
  1799.     m_questionData = questionData;
  1800. }
  1801.  
  1802. void AVizPlayerController::GetQuestionData(FUIQuestionDataStruct & questionData)
  1803. {
  1804.     questionData = m_questionData;
  1805. }
  1806.  
  1807.  
  1808. void AVizPlayerController::RequestForGameInventoryData_Server_Implementation()
  1809. {
  1810.     TArray<FUIEquipmentData> aGameInventoryData;
  1811.  
  1812.     // for now no sink is required
  1813.     // we are casting to gamemode_edit
  1814.     AVizGameMode * pGameMode = Cast<AVizGameMode>(GetWorld()->GetAuthGameMode());
  1815.     if (pGameMode)
  1816.     {
  1817.         const TMap<TEnumAsByte<Equipment::Type>, int32> & equipmentsAllowed = pGameMode->GetEquipmentsAllowed();
  1818.         TArray<TEnumAsByte<Equipment::Type>> aKeys;
  1819.         equipmentsAllowed.GenerateKeyArray(aKeys);
  1820.         for (int i = 0; i < aKeys.Num(); i++)
  1821.         {
  1822.             aGameInventoryData.Add(FUIEquipmentData());
  1823.             FEquipmentData * pEquipment = m_pInventoryManager->GetEquipment(aKeys[i]);
  1824. #if PERFORM_SAFETY_CHECKS
  1825.             if(pEquipment == nullptr){
  1826.                 V_LOG_ERRORM(LogViz, "Inventory item not found in database : %d" , int(aKeys[i]));
  1827.                 continue;
  1828.             }
  1829. #else
  1830.             check(pEquipment);
  1831. #endif
  1832.             aGameInventoryData[i].Type = pEquipment->Type;
  1833.             aGameInventoryData[i].Description = pEquipment->Description;
  1834.             aGameInventoryData[i].Texture = pEquipment->UITexture;
  1835.             aGameInventoryData[i].Count = equipmentsAllowed[aKeys[i]];
  1836.             aGameInventoryData[i].Weight = pEquipment->Weight;
  1837.         }
  1838.     }
  1839.  
  1840.     OnGameInventoryDataReceived_Client(aGameInventoryData);
  1841. }
  1842.  
  1843. bool AVizPlayerController::RequestForGameInventoryData_Server_Validate()
  1844. {
  1845.     return Role >= ROLE_Authority;
  1846. }
  1847.  
  1848. void AVizPlayerController::OnGameInventoryDataReceived_Client_Implementation(const TArray<FUIEquipmentData> & aGameInventoryData)
  1849. {
  1850.     m_aGameInventoryData = aGameInventoryData;
  1851. }
  1852.  
  1853. void AVizPlayerController::RequestForSnowTests_Server_Implementation()
  1854. {
  1855.     TArray<Test::Type> aSnowTests;
  1856.  
  1857.     AVizGameMode* pGameMode = GetWorld()->GetAuthGameMode<AVizGameMode>();
  1858.  
  1859.     if (pGameMode)
  1860.     {
  1861.         pGameMode->GetSnowTests(aSnowTests);
  1862.     }
  1863.  
  1864.     TArray<TEnumAsByte<Test::Type>> snowTests;
  1865.  
  1866.     for (int32 i = 0; i < aSnowTests.Num(); i++)
  1867.     {
  1868.         snowTests.Add((TEnumAsByte<Test::Type>)aSnowTests[i]);
  1869.     }
  1870.  
  1871.     OnSnowTestsReceived_Client(snowTests);
  1872. }
  1873.  
  1874. bool AVizPlayerController::RequestForSnowTests_Server_Validate()
  1875. {
  1876.     return Role >= ROLE_Authority;
  1877. }
  1878.  
  1879. void AVizPlayerController::OnSnowTestsReceived_Client_Implementation(const TArray<TEnumAsByte<Test::Type>> & aSnowTests)
  1880. {
  1881.     m_aSnowTests = aSnowTests;
  1882. }
  1883.  
  1884. void AVizPlayerController::GetSnowTests(TArray<TEnumAsByte<Test::Type>> & aSnowTests)
  1885. {
  1886.     aSnowTests = m_aSnowTests;
  1887. }
  1888.  
  1889. void AVizPlayerController::OnGameEnd()
  1890. {
  1891.     if(m_pWidgetManager)
  1892.     {
  1893.         m_pWidgetManager->ShowEndGameWidget();
  1894.     }
  1895. }
  1896.  
  1897. void AVizPlayerController::PerformTest(int32 testIndex)
  1898. {
  1899.     AVizCharacter*    currentPawn = Cast<AVizCharacter>(GetPawn());
  1900.  
  1901.     if(currentPawn)
  1902.     {
  1903.         switch (testIndex)
  1904.         {
  1905.             case 0 :
  1906.             {
  1907.                 currentPawn->CreateSnowTestGeneric(Test::TT_SKI_TEST);
  1908.             }
  1909.             break;
  1910.             case 1:
  1911.             {
  1912.                 currentPawn->CreateSnowTestGeneric(Test::TT_RUTSCHBLOCK_TEST);
  1913.             }
  1914.             break;
  1915.             case 2:
  1916.             {
  1917.                 currentPawn->CreateSnowTestGeneric(Test::TT_SHOVEL_SHEAR_TEST);
  1918.             }
  1919.             break;
  1920.             case 3:
  1921.             {
  1922.                 currentPawn->CreateSnowTestGeneric(Test::TT_COLLAPSE_TEST);
  1923.             }
  1924.             break;
  1925.             case 4:
  1926.             {
  1927.                 currentPawn->CreateSnowTestGeneric(Test::TT_TILT_BOARD_TEST);
  1928.             }
  1929.             break;
  1930.             case 5:
  1931.             {
  1932.                 currentPawn->CreateSurfaceAnalysisTest(SurfaceAnalysisType::SA_WIND_DIRECTION);
  1933.             }
  1934.             break;
  1935.             case 6:
  1936.             {
  1937.                 currentPawn->CreateSurfaceAnalysisTest(SurfaceAnalysisType::SA_SNOW_SOFTNESS);
  1938.             }
  1939.             break;
  1940.         default:
  1941.             break;
  1942.         }
  1943.    
  1944.     }
  1945.     ToggleTraineeSnowTests(); // To close window
  1946.     bShowMouseCursor = true;
  1947. }
  1948.  
  1949. void AVizPlayerController::DebugTest()
  1950. {
  1951.     AVizCharacter*    currentPawn = Cast<AVizCharacter>(GetPawn());
  1952.     if (currentPawn)
  1953.     {
  1954.         currentPawn->CreateSnowTestGeneric(Test::TT_SHOVEL_SHEAR_TEST);
  1955.     }
  1956. }
  1957.  
  1958. void AVizPlayerController::OnReadyClicked()
  1959. {
  1960.     if (m_pWidgetManager)
  1961.     {
  1962.         m_pWidgetManager->RemoveSelectionMenu();
  1963.  
  1964. //        EnableHMD();
  1965.     }
  1966. }
  1967.  
  1968. void AVizPlayerController::CheckForGameInventoryItem_Server_Implementation(Equipment::Type pType)
  1969. {
  1970.     TArray<FUIEquipmentData> aGameInventoryData;
  1971.     bool itemFound = false;
  1972.     AVizGameMode * pGameMode = Cast<AVizGameMode>(GetWorld()->GetAuthGameMode());
  1973.     if (pGameMode)
  1974.     {
  1975.         itemFound = pGameMode->CheckAndRemoveAllowedEquipment(pType);
  1976.  
  1977.         UpdateGameInventory_Client(pType, itemFound);
  1978.  
  1979.         pGameMode->BroadcastEquipmentChange();
  1980.     }
  1981.  
  1982.    
  1983. }
  1984.  
  1985. bool AVizPlayerController::CheckIfItemCanBeAdded(TEnumAsByte<Equipment::Type> pType)
  1986. {
  1987.     for (int i = 0; i < m_aGameInventoryData.Num(); i++)
  1988.     {
  1989.         if (m_aGameInventoryData[i].Type == pType)
  1990.         {
  1991.             AVizCharacter* myChar = Cast<AVizCharacter>(GetPawn());
  1992.  
  1993.             if (myChar)
  1994.             {
  1995.                 return myChar->CanCarryLoad(m_aGameInventoryData[i].Weight);
  1996.             }
  1997.  
  1998.             break;
  1999.         }
  2000.     }
  2001.  
  2002.     return false;
  2003. }
  2004.  
  2005. bool AVizPlayerController::CheckForGameInventoryItem_Server_Validate(Equipment::Type pType)
  2006. {
  2007.     return Role >= ROLE_Authority;
  2008. }
  2009.  
  2010. void AVizPlayerController::AddGameInventoryItem_Server_Implementation()
  2011. {
  2012.     AVizGameMode * pGameMode = Cast<AVizGameMode>(GetWorld()->GetAuthGameMode());
  2013.     if (pGameMode)
  2014.     {
  2015.         pGameMode->AddEquipmentAllowed(m_PendingEquipmentToRemove.Type);
  2016.  
  2017.         pGameMode->BroadcastEquipmentChange();
  2018.     }
  2019.  
  2020. }
  2021.  
  2022. bool AVizPlayerController::AddGameInventoryItem_Server_Validate()
  2023. {
  2024.     return Role >= ROLE_Authority;
  2025. }
  2026.  
  2027. void AVizPlayerController::UpdateGameInventory_Client_Implementation(Equipment::Type pType, bool itemFound)
  2028. {
  2029.     m_ItemExistsOnServer = itemFound;
  2030.    
  2031.     if(itemFound)
  2032.     {
  2033.         for(int i = 0 ; i < m_aGameInventoryData.Num(); i++)
  2034.         {
  2035.             if(m_aGameInventoryData[i].Type == pType)
  2036.             {
  2037.                 m_PendingEquipmentToAdd = m_aGameInventoryData[i];
  2038.  
  2039.                 m_aGameInventoryData[i].Count--;
  2040.  
  2041.                 if (m_aGameInventoryData[i].Count == 0)
  2042.                 {
  2043.                     m_aGameInventoryData.Swap(i, m_aGameInventoryData.Num() - 1);
  2044.                     m_aGameInventoryData.RemoveAt(m_aGameInventoryData.Num() - 1, 1, true);
  2045.                 }
  2046.            
  2047.                 break;
  2048.             }
  2049.         }
  2050.  
  2051.        
  2052.     }
  2053. }
  2054.  
  2055. void AVizPlayerController::OnItemActionPerformed(TEnumAsByte<Equipment::Type> pType, TEnumAsByte<ItemAction::Type> pAction)
  2056. {
  2057.     //Do nothing
  2058.     GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "Inventory Action Goes here");
  2059. }
  2060.  
  2061. bool AVizPlayerController::CheckForGameInventoryItem(TEnumAsByte<Equipment::Type> pType)
  2062. {
  2063.     CheckForGameInventoryItem_Server(pType);
  2064.  
  2065.     bool oldValue = m_ItemExistsOnServer;
  2066.     m_ItemExistsOnServer = false;
  2067.     return oldValue;
  2068. }
  2069.  
  2070. void AVizPlayerController::OnGameInventoryClicked(TEnumAsByte<Equipment::Type> pType)
  2071. {
  2072.     // Add Item to character
  2073.     AVizCharacter* myChar = Cast<AVizCharacter>(GetPawn());
  2074.  
  2075.     if(myChar)
  2076.     {
  2077.         myChar->GetPlayerInventory()->AddItem(m_PendingEquipmentToAdd.Type);
  2078.  
  2079.         m_aPlayerInventoryData.Add(m_PendingEquipmentToAdd);
  2080.  
  2081.         //Weight Changed
  2082.         OnWeightChanged.Broadcast(myChar->GetCurrentLoad(), myChar->GetMaxLoad());
  2083.     }
  2084. }
  2085.  
  2086. void AVizPlayerController::OnPlayerInventoryClicked(TEnumAsByte<Equipment::Type> pType)
  2087. {
  2088.     // Remove from character
  2089.     AVizCharacter* myChar = Cast<AVizCharacter>(GetPawn());
  2090.  
  2091.     if (myChar)
  2092.     {
  2093.         myChar->GetPlayerInventory()->RemoveItem(pType);
  2094.  
  2095.         //Local changes
  2096.         for(int i = 0 ; i < m_aPlayerInventoryData.Num() ; i++)
  2097.         {
  2098.             if(m_aPlayerInventoryData[i].Type == pType)
  2099.             {
  2100.                 m_PendingEquipmentToRemove = m_aPlayerInventoryData[i];
  2101.                 m_aPlayerInventoryData[i].Count--;
  2102.  
  2103.                 if (m_aPlayerInventoryData[i].Count == 0)
  2104.                 {
  2105.                     m_aPlayerInventoryData.Swap(i, m_aPlayerInventoryData.Num() - 1);
  2106.                     m_aPlayerInventoryData.RemoveAt(m_aPlayerInventoryData.Num() - 1, 1, true);
  2107.  
  2108.                     break;
  2109.                 }
  2110.             }
  2111.         }
  2112.        
  2113.         //Add to server
  2114.         AddGameInventoryItem_Server();
  2115.  
  2116.         //Weight Changed
  2117.         OnWeightChanged.Broadcast(myChar->GetCurrentLoad(), myChar->GetMaxLoad());
  2118.     }
  2119.  
  2120.     //RequestForGameInventoryData_Server();
  2121. }
  2122.  
  2123. void AVizPlayerController::BindWidgetToDelegate(UVizBaseWidget* widgetObject)
  2124. {
  2125.     UVizTraineeEquipmentWidget* equipmentWidget = Cast<UVizTraineeEquipmentWidget>(widgetObject);
  2126.  
  2127.     if(equipmentWidget)
  2128.     {
  2129.         //Bind events for Game Equipment Update
  2130.         TScriptDelegate<FWeakObjectPtr> updateEquipment;
  2131.         updateEquipment.BindUFunction(equipmentWidget, "UpdateInventoryContent");
  2132.  
  2133.         UpdateGameEquipment.Add(updateEquipment);
  2134.  
  2135.         //Weight Change
  2136.         TScriptDelegate<FWeakObjectPtr> weightChange;
  2137.         weightChange.BindUFunction(equipmentWidget, "OnPlayerLoadIncreased");
  2138.  
  2139.         OnWeightChanged.AddUnique(weightChange);
  2140.  
  2141.         AVizCharacter* myChar = Cast<AVizCharacter>(GetPawn());
  2142.        
  2143.         if(myChar)
  2144.         {
  2145.             OnWeightChanged.Broadcast(myChar->GetCurrentLoad(), myChar->GetMaxLoad());
  2146.         }
  2147.  
  2148.         UpdateGameEquipment.Broadcast();
  2149.     }
  2150.  
  2151.     UVizTraineeItemSelectionWidget* inventoryWidget = Cast<UVizTraineeItemSelectionWidget>(widgetObject);
  2152.  
  2153.     if(inventoryWidget)
  2154.     {
  2155.         //Weight Change
  2156.         TScriptDelegate<FWeakObjectPtr> weightChange;
  2157.         weightChange.BindUFunction(inventoryWidget, "OnPlayerLoadIncreased");
  2158.  
  2159.         OnWeightChanged.AddUnique(weightChange);
  2160.  
  2161.         AVizCharacter* myChar = Cast<AVizCharacter>(GetPawn());
  2162.  
  2163.         if (myChar)
  2164.         {
  2165.             OnWeightChanged.Broadcast(myChar->GetCurrentLoad(), myChar->GetMaxLoad());
  2166.         }
  2167.     }
  2168. }
  2169.  
  2170. void AVizPlayerController::GetInventorySize(FIntPoint & InventorySize)
  2171. {
  2172.     // TODO @ Vamshi
  2173.     // Temp
  2174.     InventorySize.X = 5;
  2175.     InventorySize.Y = 5;
  2176. }
  2177.  
  2178. void AVizPlayerController::GetUIGameInventoryData(TArray<FUIEquipmentData> & aUIGameInventoryData)
  2179. {
  2180.     aUIGameInventoryData.Empty();
  2181.     aUIGameInventoryData = m_aGameInventoryData;
  2182. }
  2183.  
  2184. void AVizPlayerController::GetUIPlayerInventoryData(TArray<FUIEquipmentData> & aUIGameInventoryData)
  2185. {
  2186.     AVizCharacter * pCharacter = Cast<AVizCharacter>(GetPawn());
  2187.     if (pCharacter)
  2188.     {
  2189.         const TMap<TEnumAsByte<Equipment::Type>, int32> & equipmentsAllowed = pCharacter->GetPlayerInventory()->GetAllEquipmentsWithCount();
  2190.         TArray<TEnumAsByte<Equipment::Type>> aKeys;
  2191.         equipmentsAllowed.GenerateKeyArray(aKeys);
  2192.         for (int i = 0; i < aKeys.Num(); i++)
  2193.         {
  2194.             aUIGameInventoryData.Add(FUIEquipmentData());
  2195.             FEquipmentData * pEquipment = m_pInventoryManager->GetEquipment(aKeys[i]);
  2196.             check(pEquipment);
  2197.             aUIGameInventoryData[i].Type = pEquipment->Type;
  2198.             aUIGameInventoryData[i].Description = pEquipment->Description;
  2199.             aUIGameInventoryData[i].Texture = pEquipment->UITexture;
  2200.             aUIGameInventoryData[i].Count = equipmentsAllowed[aKeys[i]];
  2201.             aUIGameInventoryData[i].Weight = pEquipment->Weight;
  2202.         }
  2203.     }
  2204. }
  2205.  
  2206. void AVizPlayerController::UpdateInventory()
  2207. {
  2208.     RequestForGameInventoryData_Server();
  2209.  
  2210.     UpdateGameEquipment.Broadcast();
  2211. }
  2212.  
  2213. UVizInventoryManager * AVizPlayerController::GetInventoryManager() const
  2214. {
  2215.     return m_pInventoryManager;
  2216. }
  2217.  
  2218. AVizInventoryPreview* AVizPlayerController::GetInventoryPreview() const
  2219. {
  2220.     return m_pInventoryPreview;
  2221. }
  2222.  
  2223. void AVizPlayerController::ReturnToGameMode()
  2224. {
  2225.     FInputModeGameOnly GameOnlyMode;
  2226.     SetInputMode(GameOnlyMode);
  2227.     bShowMouseCursor = false;
  2228. }
  2229.  
  2230. AVizSnowClassificationManager* AVizPlayerController::GetSnowClassificationManager() const
  2231. {
  2232.     return m_pSnowProperty;
  2233. }
  2234.  
  2235. void AVizPlayerController::RequestForBindingWeatherParticleLocation()
  2236. {
  2237.     //! Turn the flag on with the request. Will be turned off when request is completed.
  2238.     m_boundParticleLocationRequested = true;
  2239.     RequestForBindingWeatherParticleLocation_Server();
  2240. }
  2241.  
  2242. void AVizPlayerController::RequestForBindingWeatherParticleLocation_Server_Implementation()
  2243. {
  2244.     AVizGameMode * pGameMode = Cast<AVizGameMode>(GetWorld()->GetAuthGameMode());
  2245.     if (pGameMode)
  2246.     {
  2247.         BindParticleLocation(pGameMode->GetWeatherManager());
  2248.     }
  2249. }
  2250.  
  2251. bool AVizPlayerController::RequestForBindingWeatherParticleLocation_Server_Validate()
  2252. {
  2253.     return Role >= ROLE_Authority;
  2254. }
  2255.  
  2256. void AVizPlayerController::BindParticleLocation_Implementation(AVizWeatherManager* weatherManager)
  2257. {
  2258.     IVizPlayerMovement* currentPawn =  Cast<AVizCharacter>(GetPawn());
  2259.  
  2260.     if (!currentPawn)
  2261.     {
  2262.         currentPawn = Cast<AVizCreateEditPawn>(GetPawn());
  2263.     }
  2264.  
  2265.     if (currentPawn)
  2266.     {
  2267.         if (weatherManager)
  2268.         {
  2269.             weatherManager->BindParticleLocation(currentPawn);
  2270.         }
  2271.  
  2272.         //! Particle location bound request is successful ,
  2273.         m_boundParticleLocationRequested = false;
  2274.     }    
  2275.    
  2276. }
  2277.  
  2278. void AVizPlayerController::OnRep_Pawn()
  2279. {
  2280.     Super::OnRep_Pawn();
  2281.  
  2282.     V_LOG_LINE(LogViz);
  2283.  
  2284.     GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("Pawn updated"));
  2285.  
  2286.     //! Check if particle location bound was requested but could not be completed.
  2287.     //! Try again now as the pawn have been replicated
  2288.     if(m_boundParticleLocationRequested)
  2289.     {
  2290.         RequestForBindingWeatherParticleLocation_Server();
  2291.     }    
  2292. }
  2293.  
  2294. void AVizPlayerController::GetAllPlayerPosition()
  2295. {
  2296.     int32 i = 0;
  2297.     for (TActorIterator<APawn> ActorItr(GetWorld()); ActorItr; ++ActorItr)
  2298.     {
  2299.         APawn* pwn = *ActorItr;
  2300.  
  2301.         AVizCreateEditPawn* trainer_pwn = Cast<AVizCreateEditPawn>(pwn);
  2302.         AVizVRCharacter* trainee_pwn = Cast<AVizVRCharacter>(pwn);
  2303.         if (trainer_pwn)
  2304.         {
  2305.             FVector trainer_position;
  2306.             trainer_position = trainer_pwn->GetActorLocation();
  2307.             V_LOGM(LogViz, "Trainer Pawn Found. Position is  = %s", *trainer_position.ToString());
  2308.         }
  2309.         i++;
  2310.  
  2311.         /*else if(trainee_pwn)
  2312.         {
  2313.             FVector trainer_position;
  2314.             trainer_position = trainer_pwn->K2_GetActorLocation();
  2315.             V_LOGM(LogViz, "Trainee Pawn Found. Position is  = %s", *trainer_position.ToString());
  2316.         }*/
  2317.        
  2318.     }
  2319.  
  2320.     V_LOGM(LogViz, "No of Clients  = %d", i);
  2321.  
  2322. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement