diff --git a/Content/MainMenu/MainMenuLevel.umap b/Content/MainMenu/MainMenuLevel.umap index 2756307..e7ad0bc 100644 Binary files a/Content/MainMenu/MainMenuLevel.umap and b/Content/MainMenu/MainMenuLevel.umap differ 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; };