Implemented persistent choose of troopers

pull/8/head
eyakm1 2 years ago
parent 1eb65de5e6
commit e34909565e

@ -35,10 +35,10 @@ void ABattleGameMode::InitializeBattleField_Implementation() {
uint8 TrooperCount = 0; uint8 TrooperCount = 0;
TArray<const TCHAR *> bpPaths{ TArray<const TCHAR *> bpPaths{
TEXT("Blueprint'/Game/Troopers/TrooperWizard.TrooperWizard_C'"),
TEXT( TEXT(
"Blueprint'/Game/Troopers/TrooperSkeletonMelee.TrooperSkeletonMelee_C'" "Blueprint'/Game/Troopers/TrooperSkeletonMelee.TrooperSkeletonMelee_C'"
), )
TEXT("Blueprint'/Game/Troopers/TrooperWizard.TrooperWizard_C'")
}; };
// TArray<UClass *> LoadedBpAssets; // TArray<UClass *> LoadedBpAssets;
for (int i = 0; i < bpPaths.Num(); ++i) { for (int i = 0; i < bpPaths.Num(); ++i) {
@ -52,7 +52,7 @@ void ABattleGameMode::InitializeBattleField_Implementation() {
FTransform SpawnLocationAndRotation(Rotation); FTransform SpawnLocationAndRotation(Rotation);
SpawnLocationAndRotation.SetLocation(Location); SpawnLocationAndRotation.SetLocation(Location);
AActor *Spawned = GetWorld()->SpawnActorDeferred<ATrooper>( AActor *Spawned = GetWorld()->SpawnActorDeferred<ATrooper>(
LoadedBpAssets[i % 2], SpawnLocationAndRotation); LoadedBpAssets[FirstPlayerTrooperKinds[i]], SpawnLocationAndRotation);
// AActor *Spawned = GetWorld()->SpawnActorDeferred<ATrooper>( // AActor *Spawned = GetWorld()->SpawnActorDeferred<ATrooper>(
// ATrooper::StaticClass(), SpawnLocationAndRotation); // ATrooper::StaticClass(), SpawnLocationAndRotation);
Cast<ATrooper>(Spawned)->Initialize( Cast<ATrooper>(Spawned)->Initialize(
@ -69,7 +69,7 @@ void ABattleGameMode::InitializeBattleField_Implementation() {
FTransform SpawnLocationAndRotation(Rotation); FTransform SpawnLocationAndRotation(Rotation);
SpawnLocationAndRotation.SetLocation(Location); SpawnLocationAndRotation.SetLocation(Location);
AActor *Spawned = GetWorld()->SpawnActorDeferred<ATrooper>( AActor *Spawned = GetWorld()->SpawnActorDeferred<ATrooper>(
LoadedBpAssets[i % 2], SpawnLocationAndRotation); LoadedBpAssets[SecondPlayerTrooperKinds[i]], SpawnLocationAndRotation);
// AActor *Spawned = GetWorld()->SpawnActorDeferred<ATrooper>( // AActor *Spawned = GetWorld()->SpawnActorDeferred<ATrooper>(
// ATrooper::StaticClass(), SpawnLocationAndRotation); // ATrooper::StaticClass(), SpawnLocationAndRotation);
Cast<ATrooper>(Spawned)->Initialize( Cast<ATrooper>(Spawned)->Initialize(
@ -79,11 +79,6 @@ void ABattleGameMode::InitializeBattleField_Implementation() {
GetMyGameState()->AddTrooper(Cast<ATrooper>(Spawned)); GetMyGameState()->AddTrooper(Cast<ATrooper>(Spawned));
Location += {0.f, 500.f, 0.0f}; Location += {0.f, 500.f, 0.0f};
} }
} else {
// Cast<ASinglePlayerGS>(GetMyGameState())->GetEnemyAIController()->
// SetTrooperAssetsAndSpawn(
// LoadedBpAssets,
// TrooperCount);
} }
} }
@ -140,8 +135,17 @@ void ABattleGameMode::PostLogin(APlayerController *NewPlayer) {
CurrentNumberOfPlayers - 1); CurrentNumberOfPlayers - 1);
Cast<ABattlePlayerController>(NewPlayer)-> Cast<ABattlePlayerController>(NewPlayer)->
StartPlayingMusic(BackgroundSound); StartPlayingMusic(BackgroundSound);
if (CurrentNumberOfPlayers == 1)
{
FirstPlayerTrooperKinds = Cast<ABattlePlayerController>(NewPlayer)->TrooperKinds;
} else if (CurrentNumberOfPlayers == 2)
{
SecondPlayerTrooperKinds = Cast<ABattlePlayerController>(NewPlayer)->TrooperKinds;
}
UE_LOG(LogTemp, Warning, TEXT("%d"), CurrentNumberOfPlayers); UE_LOG(LogTemp, Warning, TEXT("%d"), CurrentNumberOfPlayers);
if (CurrentNumberOfPlayers == 2) { if (!bIsMultiplayer || CurrentNumberOfPlayers == 2) {
UE_LOG(LogTemp, Warning, TEXT("Game Start")); UE_LOG(LogTemp, Warning, TEXT("Game Start"));
// start the game // start the game
// dynamic_cast<AMyGameState *>( // dynamic_cast<AMyGameState *>(

@ -36,6 +36,12 @@ protected:
UPROPERTY() UPROPERTY()
bool bIsMultiplayer = true; bool bIsMultiplayer = true;
UPROPERTY()
TArray<uint8> FirstPlayerTrooperKinds;
UPROPERTY()
TArray<uint8> SecondPlayerTrooperKinds;
void InitializeSpawnPointsIfNeeded(AController *Player); void InitializeSpawnPointsIfNeeded(AController *Player);
UFUNCTION(Server, Reliable) UFUNCTION(Server, Reliable)

@ -7,12 +7,22 @@
#include "BattlePlayerState.h" #include "BattlePlayerState.h"
#include "Blueprint/UserWidget.h" #include "Blueprint/UserWidget.h"
#include "Net/UnrealNetwork.h" #include "Net/UnrealNetwork.h"
#include "TurnBasedTutorial/ManageSquad/SelectedTrooperSaveGame.h"
ABattlePlayerController::ABattlePlayerController() ABattlePlayerController::ABattlePlayerController()
: Super()/*, bIsMyTurn(false), SelectedTrooper(nullptr)*/ { : Super()/*, bIsMyTurn(false), SelectedTrooper(nullptr)*/ {
UE_LOG(LogTemp, Warning, TEXT("Player controller created")); UE_LOG(LogTemp, Warning, TEXT("Player controller created"));
SetShowMouseCursor(true); SetShowMouseCursor(true);
PlayerIndex = 0; 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() { void ABattlePlayerController::BeginPlay() {

@ -57,6 +57,9 @@ public:
UFUNCTION(Client, Reliable) UFUNCTION(Client, Reliable)
void SetWidgetTurn(bool bIsMyTurn); void SetWidgetTurn(bool bIsMyTurn);
UPROPERTY()
TArray<uint8> TrooperKinds;
private: private:
UFUNCTION(Client, Reliable) UFUNCTION(Client, Reliable)
void CreateBattleWidget(); void CreateBattleWidget();

@ -13,12 +13,12 @@ ASinglePlayerGM::ASinglePlayerGM()
void ASinglePlayerGM::BeginPlay() { void ASinglePlayerGM::BeginPlay() {
Super::BeginPlay(); Super::BeginPlay();
UE_LOG(LogTemp, Warning, TEXT("SinglePlayer GameMode BeginPlay")); UE_LOG(LogTemp, Warning, TEXT("SinglePlayer GameMode BeginPlay"));
GameStateClass = ASinglePlayerGS::StaticClass(); // GameStateClass = ASinglePlayerGS::StaticClass();
StartGame(); // StartGame();
} }
void ASinglePlayerGM::PostLogin(APlayerController *NewPlayer) { // void ASinglePlayerGM::PostLogin(APlayerController *NewPlayer) {
AGameMode::PostLogin(NewPlayer); // AGameMode::PostLogin(NewPlayer);
Cast<ABattlePlayerController>(NewPlayer)-> // Cast<ABattlePlayerController>(NewPlayer)->
StartPlayingMusic(BackgroundSound); // StartPlayingMusic(BackgroundSound);
} // }

@ -18,5 +18,5 @@ public:
virtual void BeginPlay() override; virtual void BeginPlay() override;
virtual void PostLogin(APlayerController *NewPlayer) override; // virtual void PostLogin(APlayerController *NewPlayer) override;
}; };

Loading…
Cancel
Save