From e34909565ec204907c12732755d8c27386e25898 Mon Sep 17 00:00:00 2001 From: eyakm1 Date: Sun, 18 Jun 2023 02:53:09 +0300 Subject: [PATCH] Implemented persistent choose of troopers --- Content/MainMenu/MainMenuLevel.umap | Bin 33270 -> 33270 bytes .../BattleMode/BattleGameMode.cpp | 24 ++++++++++-------- .../BattleMode/BattleGameMode.h | 6 +++++ .../BattleMode/BattlePlayerController.cpp | 10 ++++++++ .../BattleMode/BattlePlayerController.h | 3 +++ .../Singleplayer/SinglePlayerGM.cpp | 14 +++++----- .../BattleMode/Singleplayer/SinglePlayerGM.h | 2 +- 7 files changed, 41 insertions(+), 18 deletions(-) diff --git a/Content/MainMenu/MainMenuLevel.umap b/Content/MainMenu/MainMenuLevel.umap index 2756307b8f39353a28db73e7ebb9c3d78e13459f..e7ad0bc255ee2c79d97a102d3c40ba48f515fc69 100644 GIT binary patch delta 166 zcmV;X09pU`g97%00HCQcBnftcS;wJ#2X zSs-3T000006qA8|8M6s?SO*N6m5xQ4IaS3o^BzT$QGhiBn70u_lhJ=Ul3EIrFnuwT UkQWTI-+t}^lUskev(11h0kj50J^%m! delta 167 zcmV;Y09gO_g97%00H9Fn|o{qVy_j$S$4 zn)n9>000006qA8|8M6s?SO*Mvm5xQQIaS3&^BzT$QGhWF;AQE--nS7$z&(Stlkt3T VlaLn-v)_L10h3#QxwFlHDFI@}N}~V( diff --git a/Source/TurnBasedTutorial/BattleMode/BattleGameMode.cpp b/Source/TurnBasedTutorial/BattleMode/BattleGameMode.cpp index fa50582..9133697 100644 --- a/Source/TurnBasedTutorial/BattleMode/BattleGameMode.cpp +++ b/Source/TurnBasedTutorial/BattleMode/BattleGameMode.cpp @@ -35,10 +35,10 @@ void ABattleGameMode::InitializeBattleField_Implementation() { uint8 TrooperCount = 0; TArray bpPaths{ + TEXT("Blueprint'/Game/Troopers/TrooperWizard.TrooperWizard_C'"), TEXT( "Blueprint'/Game/Troopers/TrooperSkeletonMelee.TrooperSkeletonMelee_C'" - ), - TEXT("Blueprint'/Game/Troopers/TrooperWizard.TrooperWizard_C'") + ) }; // TArray LoadedBpAssets; for (int i = 0; i < bpPaths.Num(); ++i) { @@ -52,7 +52,7 @@ void ABattleGameMode::InitializeBattleField_Implementation() { FTransform SpawnLocationAndRotation(Rotation); SpawnLocationAndRotation.SetLocation(Location); AActor *Spawned = GetWorld()->SpawnActorDeferred( - LoadedBpAssets[i % 2], SpawnLocationAndRotation); + LoadedBpAssets[FirstPlayerTrooperKinds[i]], SpawnLocationAndRotation); // AActor *Spawned = GetWorld()->SpawnActorDeferred( // ATrooper::StaticClass(), SpawnLocationAndRotation); Cast(Spawned)->Initialize( @@ -69,7 +69,7 @@ void ABattleGameMode::InitializeBattleField_Implementation() { FTransform SpawnLocationAndRotation(Rotation); SpawnLocationAndRotation.SetLocation(Location); AActor *Spawned = GetWorld()->SpawnActorDeferred( - LoadedBpAssets[i % 2], SpawnLocationAndRotation); + LoadedBpAssets[SecondPlayerTrooperKinds[i]], SpawnLocationAndRotation); // AActor *Spawned = GetWorld()->SpawnActorDeferred( // ATrooper::StaticClass(), SpawnLocationAndRotation); Cast(Spawned)->Initialize( @@ -79,11 +79,6 @@ void ABattleGameMode::InitializeBattleField_Implementation() { GetMyGameState()->AddTrooper(Cast(Spawned)); Location += {0.f, 500.f, 0.0f}; } - } else { - // Cast(GetMyGameState())->GetEnemyAIController()-> - // SetTrooperAssetsAndSpawn( - // LoadedBpAssets, - // TrooperCount); } } @@ -140,8 +135,17 @@ void ABattleGameMode::PostLogin(APlayerController *NewPlayer) { CurrentNumberOfPlayers - 1); Cast(NewPlayer)-> StartPlayingMusic(BackgroundSound); + + if (CurrentNumberOfPlayers == 1) + { + FirstPlayerTrooperKinds = Cast(NewPlayer)->TrooperKinds; + } else if (CurrentNumberOfPlayers == 2) + { + SecondPlayerTrooperKinds = Cast(NewPlayer)->TrooperKinds; + } + UE_LOG(LogTemp, Warning, TEXT("%d"), CurrentNumberOfPlayers); - if (CurrentNumberOfPlayers == 2) { + if (!bIsMultiplayer || CurrentNumberOfPlayers == 2) { UE_LOG(LogTemp, Warning, TEXT("Game Start")); // start the game // dynamic_cast( diff --git a/Source/TurnBasedTutorial/BattleMode/BattleGameMode.h b/Source/TurnBasedTutorial/BattleMode/BattleGameMode.h index c19e163..2005a77 100644 --- a/Source/TurnBasedTutorial/BattleMode/BattleGameMode.h +++ b/Source/TurnBasedTutorial/BattleMode/BattleGameMode.h @@ -36,6 +36,12 @@ protected: UPROPERTY() bool bIsMultiplayer = true; + UPROPERTY() + TArray FirstPlayerTrooperKinds; + + UPROPERTY() + TArray SecondPlayerTrooperKinds; + void InitializeSpawnPointsIfNeeded(AController *Player); UFUNCTION(Server, Reliable) diff --git a/Source/TurnBasedTutorial/BattleMode/BattlePlayerController.cpp b/Source/TurnBasedTutorial/BattleMode/BattlePlayerController.cpp index 45f8989..e79e3fc 100644 --- a/Source/TurnBasedTutorial/BattleMode/BattlePlayerController.cpp +++ b/Source/TurnBasedTutorial/BattleMode/BattlePlayerController.cpp @@ -7,12 +7,22 @@ #include "BattlePlayerState.h" #include "Blueprint/UserWidget.h" #include "Net/UnrealNetwork.h" +#include "TurnBasedTutorial/ManageSquad/SelectedTrooperSaveGame.h" ABattlePlayerController::ABattlePlayerController() : Super()/*, bIsMyTurn(false), SelectedTrooper(nullptr)*/ { UE_LOG(LogTemp, Warning, TEXT("Player controller created")); SetShowMouseCursor(true); PlayerIndex = 0; + + if (UGameplayStatics::DoesSaveGameExist("Selected troopers", 0)) { + const USelectedTrooperSaveGame *SaveGameInstance = Cast< + USelectedTrooperSaveGame>( + UGameplayStatics::LoadGameFromSlot(TEXT("Selected troopers"), 0)); + TrooperKinds = SaveGameInstance->SelectedTroopers; + } else { + TrooperKinds = {0, 0, 0, 0, 0}; + } } void ABattlePlayerController::BeginPlay() { diff --git a/Source/TurnBasedTutorial/BattleMode/BattlePlayerController.h b/Source/TurnBasedTutorial/BattleMode/BattlePlayerController.h index 02ed29c..12da459 100644 --- a/Source/TurnBasedTutorial/BattleMode/BattlePlayerController.h +++ b/Source/TurnBasedTutorial/BattleMode/BattlePlayerController.h @@ -57,6 +57,9 @@ public: UFUNCTION(Client, Reliable) void SetWidgetTurn(bool bIsMyTurn); + UPROPERTY() + TArray TrooperKinds; + private: UFUNCTION(Client, Reliable) void CreateBattleWidget(); diff --git a/Source/TurnBasedTutorial/BattleMode/Singleplayer/SinglePlayerGM.cpp b/Source/TurnBasedTutorial/BattleMode/Singleplayer/SinglePlayerGM.cpp index 0a8af20..d52ab0a 100644 --- a/Source/TurnBasedTutorial/BattleMode/Singleplayer/SinglePlayerGM.cpp +++ b/Source/TurnBasedTutorial/BattleMode/Singleplayer/SinglePlayerGM.cpp @@ -13,12 +13,12 @@ ASinglePlayerGM::ASinglePlayerGM() void ASinglePlayerGM::BeginPlay() { Super::BeginPlay(); UE_LOG(LogTemp, Warning, TEXT("SinglePlayer GameMode BeginPlay")); - GameStateClass = ASinglePlayerGS::StaticClass(); - StartGame(); + // GameStateClass = ASinglePlayerGS::StaticClass(); + // StartGame(); } -void ASinglePlayerGM::PostLogin(APlayerController *NewPlayer) { - AGameMode::PostLogin(NewPlayer); - Cast(NewPlayer)-> - StartPlayingMusic(BackgroundSound); -} +// void ASinglePlayerGM::PostLogin(APlayerController *NewPlayer) { +// AGameMode::PostLogin(NewPlayer); +// Cast(NewPlayer)-> +// StartPlayingMusic(BackgroundSound); +// } diff --git a/Source/TurnBasedTutorial/BattleMode/Singleplayer/SinglePlayerGM.h b/Source/TurnBasedTutorial/BattleMode/Singleplayer/SinglePlayerGM.h index 08d73ab..9d12fa9 100644 --- a/Source/TurnBasedTutorial/BattleMode/Singleplayer/SinglePlayerGM.h +++ b/Source/TurnBasedTutorial/BattleMode/Singleplayer/SinglePlayerGM.h @@ -18,5 +18,5 @@ public: virtual void BeginPlay() override; - virtual void PostLogin(APlayerController *NewPlayer) override; + // virtual void PostLogin(APlayerController *NewPlayer) override; };