You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.9 KiB
67 lines
1.9 KiB
2 years ago
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||
|
|
||
|
#include "SinglePlayerGS.h"
|
||
|
#include "Net/UnrealNetwork.h"
|
||
|
|
||
|
ASinglePlayerGS::ASinglePlayerGS()
|
||
|
: Super() {
|
||
2 years ago
|
bIsMultiplayer = false;
|
||
2 years ago
|
PrimaryActorTick.bCanEverTick = true;
|
||
|
SetActorTickInterval(0.5f);
|
||
|
}
|
||
|
|
||
|
void ASinglePlayerGS::BeginPlay() {
|
||
|
Super::BeginPlay();
|
||
|
UE_LOG(LogTemp, Warning, TEXT("SinglePlayer GameState BeginPlay"));
|
||
|
if (LivingTroopersCount.Num() < 2) {
|
||
|
LivingTroopersCount.SetNum(2);
|
||
|
}
|
||
|
EnemyAiManager = GetWorld()->SpawnActor<AEnemyAIController>(
|
||
|
AEnemyAIController::StaticClass(), FVector(0.0f, 0.0f, 1000.0f),
|
||
|
FRotator(0.0f, 0.0f, 0.0f), FActorSpawnParameters());
|
||
|
EnemyAiManager->InitializeTroopers(Troopers);
|
||
|
}
|
||
|
|
||
|
void ASinglePlayerGS::CycleTurns() {
|
||
|
if (CurrentPlayerTurn == 0) {
|
||
|
PlayerInTurn()->EndTurn();
|
||
|
}
|
||
|
for (const auto Trooper : Troopers) {
|
||
|
if (Trooper != nullptr) {
|
||
|
Trooper->ResetActionPoints();
|
||
|
}
|
||
|
}
|
||
|
CurrentPlayerTurn = !CurrentPlayerTurn;
|
||
|
if (CurrentPlayerTurn == 0) {
|
||
|
PlayerInTurn()->StartTurn();
|
||
|
} else {
|
||
|
EnemyAiManager->StartTurn();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void ASinglePlayerGS::Tick(float DeltaSeconds) {
|
||
|
Super::Tick(DeltaSeconds);
|
||
|
if (EnemyAiManager->bIsEnded) {
|
||
|
EnemyAiManager->bIsEnded = false;
|
||
2 years ago
|
EnemyAiManager->SpawnIfNeeded();
|
||
2 years ago
|
CycleTurns();
|
||
|
} else if (CurrentPlayerTurn == 1 && !EnemyAiManager->IsAITurn()) {
|
||
|
CycleTurns();
|
||
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
AEnemyAIController *ASinglePlayerGS::GetEnemyAIController() const {
|
||
2 years ago
|
return EnemyAiManager;
|
||
|
}
|
||
|
|
||
2 years ago
|
const TArray<TSubclassOf<ATrooper>> &ASinglePlayerGS::
|
||
2 years ago
|
GetTroopersAssets() const {
|
||
|
return TrooperBpAssets;
|
||
|
}
|
||
|
|
||
2 years ago
|
void ASinglePlayerGS::GetLifetimeReplicatedProps(
|
||
|
TArray<FLifetimeProperty> &OutLifetimeProps) const {
|
||
|
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
||
|
DOREPLIFETIME(ASinglePlayerGS, EnemyAiManager);
|
||
|
}
|