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;
TArray<const TCHAR *> bpPaths{
TEXT("Blueprint'/Game/Troopers/TrooperWizard.TrooperWizard_C'"),
TEXT(
"Blueprint'/Game/Troopers/TrooperSkeletonMelee.TrooperSkeletonMelee_C'"
),
TEXT("Blueprint'/Game/Troopers/TrooperWizard.TrooperWizard_C'")
)
};
// TArray<UClass *> 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<ATrooper>(
LoadedBpAssets[i % 2], SpawnLocationAndRotation);
LoadedBpAssets[FirstPlayerTrooperKinds[i]], SpawnLocationAndRotation);
// AActor *Spawned = GetWorld()->SpawnActorDeferred<ATrooper>(
// ATrooper::StaticClass(), SpawnLocationAndRotation);
Cast<ATrooper>(Spawned)->Initialize(
@ -69,7 +69,7 @@ void ABattleGameMode::InitializeBattleField_Implementation() {
FTransform SpawnLocationAndRotation(Rotation);
SpawnLocationAndRotation.SetLocation(Location);
AActor *Spawned = GetWorld()->SpawnActorDeferred<ATrooper>(
LoadedBpAssets[i % 2], SpawnLocationAndRotation);
LoadedBpAssets[SecondPlayerTrooperKinds[i]], SpawnLocationAndRotation);
// AActor *Spawned = GetWorld()->SpawnActorDeferred<ATrooper>(
// ATrooper::StaticClass(), SpawnLocationAndRotation);
Cast<ATrooper>(Spawned)->Initialize(
@ -79,11 +79,6 @@ void ABattleGameMode::InitializeBattleField_Implementation() {
GetMyGameState()->AddTrooper(Cast<ATrooper>(Spawned));
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);
Cast<ABattlePlayerController>(NewPlayer)->
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);
if (CurrentNumberOfPlayers == 2) {
if (!bIsMultiplayer || CurrentNumberOfPlayers == 2) {
UE_LOG(LogTemp, Warning, TEXT("Game Start"));
// start the game
// dynamic_cast<AMyGameState *>(

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

@ -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() {

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

@ -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<ABattlePlayerController>(NewPlayer)->
StartPlayingMusic(BackgroundSound);
}
// void ASinglePlayerGM::PostLogin(APlayerController *NewPlayer) {
// AGameMode::PostLogin(NewPlayer);
// Cast<ABattlePlayerController>(NewPlayer)->
// StartPlayingMusic(BackgroundSound);
// }

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

Loading…
Cancel
Save