diff --git a/Content/BattleField/BP_BattleUI.uasset b/Content/BattleField/BP_BattleUI.uasset index 1925d52..217c1f1 100644 Binary files a/Content/BattleField/BP_BattleUI.uasset and b/Content/BattleField/BP_BattleUI.uasset differ diff --git a/Content/BattleField/BattleFieldMap.umap b/Content/BattleField/BattleFieldMap.umap index 6c84f51..325f3d5 100644 Binary files a/Content/BattleField/BattleFieldMap.umap and b/Content/BattleField/BattleFieldMap.umap differ diff --git a/Source/TurnBasedTutorial/MyGameState.cpp b/Source/TurnBasedTutorial/MyGameState.cpp index 1b84b68..7d2409c 100644 --- a/Source/TurnBasedTutorial/MyGameState.cpp +++ b/Source/TurnBasedTutorial/MyGameState.cpp @@ -24,17 +24,15 @@ void AMyGameState::StartGame() const { PlayerInTurn()->StartTurn(); } -void AMyGameState::CycleTurns_Implementation(uint8 CurrentPlayerIndex) { - if (CurrentPlayerTurn == CurrentPlayerIndex) { - PlayerInTurn()->EndTurn(); - for (const auto Trooper : Troopers) { - if (Trooper != nullptr) { - Trooper->ResetActionPoints(); - } +void AMyGameState::CycleTurns_Implementation() { + PlayerInTurn()->EndTurn(); + for (const auto Trooper : Troopers) { + if (Trooper != nullptr) { + Trooper->ResetActionPoints(); } - CurrentPlayerTurn = !CurrentPlayerTurn; - PlayerInTurn()->StartTurn(); } + CurrentPlayerTurn = !CurrentPlayerTurn; + PlayerInTurn()->StartTurn(); } // void AMyGameState::CycleTurns(uint8 CurrentPlayerIndex) { diff --git a/Source/TurnBasedTutorial/MyGameState.h b/Source/TurnBasedTutorial/MyGameState.h index dafd47a..1c71b0f 100644 --- a/Source/TurnBasedTutorial/MyGameState.h +++ b/Source/TurnBasedTutorial/MyGameState.h @@ -24,7 +24,7 @@ public: void StartGame() const; UFUNCTION(BlueprintCallable, Server, Reliable) - void CycleTurns(uint8 CurrentPlayerIndex); + void CycleTurns(); UFUNCTION(BlueprintPure) AMyPlayerState *PlayerInTurn() const; diff --git a/Source/TurnBasedTutorial/MyPlayerController.cpp b/Source/TurnBasedTutorial/MyPlayerController.cpp index e89f66b..910726b 100644 --- a/Source/TurnBasedTutorial/MyPlayerController.cpp +++ b/Source/TurnBasedTutorial/MyPlayerController.cpp @@ -50,6 +50,13 @@ auto AMyPlayerController::GetMyGameMode() const { } +void AMyPlayerController::EndTurn() { + // if (GetMyPlayerState()->IsMyTurn()) { + // GetMyGameState()->CycleTurns(); + // } + GetMyPlayerState()->CycleTurns(); +} + // void AMyPlayerController::EndTurn_Implementation() { // GetMyPlayerState()->EndTurn(); // } @@ -125,17 +132,17 @@ void AMyPlayerController::SetPlayerIndex(uint8 NewPlayerIndex) { // GetMyPlayerState()->PlayerIndex = NewPlayerIndex; } -float AMyPlayerController::SetCurrentActionAndReturnRadius(int action) { - return GetMyPlayerState()->SetCurrentActionAndReturnRadius(action); - - // CurrentAction = action; - // UE_LOG(LogTemp, Warning, TEXT("SetCurrentAction: %d on Player Controller " - // "with index %d"), CurrentAction, PlayerIndex); - // if (SelectedTrooper) { - // return SelectedTrooper->GetActionRadius(CurrentAction); - // } - // return 0.0f; -} +// float AMyPlayerController::SetCurrentActionAndReturnRadius(int action) { +// return GetMyPlayerState()->SetCurrentActionAndReturnRadius(action); +// +// // CurrentAction = action; +// // UE_LOG(LogTemp, Warning, TEXT("SetCurrentAction: %d on Player Controller " +// // "with index %d"), CurrentAction, PlayerIndex); +// // if (SelectedTrooper) { +// // return SelectedTrooper->GetActionRadius(CurrentAction); +// // } +// // return 0.0f; +// } void AMyPlayerController::SetEnemySelection_Implementation( diff --git a/Source/TurnBasedTutorial/MyPlayerController.h b/Source/TurnBasedTutorial/MyPlayerController.h index f04607c..f341a53 100644 --- a/Source/TurnBasedTutorial/MyPlayerController.h +++ b/Source/TurnBasedTutorial/MyPlayerController.h @@ -19,6 +19,9 @@ public: AMyPlayerController(); + UFUNCTION(BlueprintCallable) + void EndTurn(); + // UFUNCTION(Client, Reliable) // void StartTurn(); @@ -37,8 +40,8 @@ public: UFUNCTION() void SetPlayerIndex(uint8 NewPlayerIndex); - UFUNCTION(BlueprintCallable) - float SetCurrentActionAndReturnRadius(int action); + // UFUNCTION(BlueprintCallable) + // float SetCurrentActionAndReturnRadius(int action); UFUNCTION(Client, Reliable) void SetEnemySelection(const TArray &Troopers) const; diff --git a/Source/TurnBasedTutorial/MyPlayerState.cpp b/Source/TurnBasedTutorial/MyPlayerState.cpp index cb29a24..ddfbcc0 100644 --- a/Source/TurnBasedTutorial/MyPlayerState.cpp +++ b/Source/TurnBasedTutorial/MyPlayerState.cpp @@ -19,6 +19,37 @@ void AMyPlayerState::SetPlayerIndex(uint8 NewPlayerIndex) { PlayerIndex = NewPlayerIndex; } +void AMyPlayerState::MoveTrooper_Implementation(ATrooper *Trooper, + FVector Location) { + if (Trooper->CheckMoveCorrectness(Location)) { + Trooper->MoveTrooper(Location); + // GetMyGameMode()->CycleTurns(); + } else { + GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Red, + FString::Printf( + TEXT("Out of move radius!"))); + } +} + +void AMyPlayerState::Attack_Implementation(ATrooper *Attacker, + FVector Location, + int ActionIndex) { + if (Attacker->CheckAttackCorrectness(Location, ActionIndex)) { + Attacker->Attack(ActionIndex); + } else { + GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Red, + FString::Printf( + TEXT( + "Out of radius or not enough Action Points!"))); + } +} + +void AMyPlayerState::CycleTurns() const { + if (bIsMyTurn) { + Cast(GetWorld()->GetGameState())->CycleTurns(); + } +} + bool AMyPlayerState::IsMyTurn() const { return bIsMyTurn; } @@ -53,30 +84,6 @@ void AMyPlayerState::EndTurn_Implementation() { } } -void AMyPlayerState::MoveTrooper_Implementation( - ATrooper *Trooper, - FVector Location) { - if (Trooper->CheckMoveCorrectness(Location)) { - Trooper->MoveTrooper(Location); - // GetMyGameMode()->CycleTurns(); - } else { - GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Red, - FString::Printf( - TEXT("Out of move radius!"))); - } -} - -void AMyPlayerState::Attack_Implementation(ATrooper *Attacker, - FVector Location, - int ActionIndex) { - if (Attacker && CurrentAction >= 1 && CurrentAction <= 2 && - Attacker->CheckAttackCorrectness(Location, CurrentAction)) { - Attacker->Attack(CurrentAction); - } else { - UE_LOG(LogTemp, Warning, - TEXT("Out of radius or not enough Action Points")); - } -} void AMyPlayerState::OnPlayerAction(const FHitResult &HitResult) { auto const NewlySelectedLocation = HitResult.Location; @@ -125,16 +132,13 @@ void AMyPlayerState::OnPlayerAction(const FHitResult &HitResult) { } } -float AMyPlayerState::SetCurrentActionAndReturnRadius(int Action) { +void AMyPlayerState::SetCurrentAction_Implementation(int Action) { CurrentAction = Action; UE_LOG(LogTemp, Warning, TEXT("SetCurrentAction: %d on Player Controller " "with index %d"), CurrentAction, PlayerIndex); - if (SelectedTrooper) { - return SelectedTrooper->GetActionRadius(CurrentAction); - } - return 0.0f; } + uint8 AMyPlayerState::GetPlayerIndex() { return PlayerIndex; } diff --git a/Source/TurnBasedTutorial/MyPlayerState.h b/Source/TurnBasedTutorial/MyPlayerState.h index cd08241..e073ef7 100644 --- a/Source/TurnBasedTutorial/MyPlayerState.h +++ b/Source/TurnBasedTutorial/MyPlayerState.h @@ -30,13 +30,16 @@ public: void Attack(ATrooper *Attacker, FVector Location, int ActionIndex); UFUNCTION() + void CycleTurns() const; + + UFUNCTION(BlueprintCallable) bool IsMyTurn() const; UFUNCTION() void OnPlayerAction(const FHitResult &HitResult); - UFUNCTION(BlueprintCallable) - float SetCurrentActionAndReturnRadius(int Action); + UFUNCTION(BlueprintCallable, Client, Reliable) + void SetCurrentAction(int Action); UFUNCTION(BlueprintCallable) uint8 GetPlayerIndex(); @@ -56,8 +59,7 @@ private: UPROPERTY(Replicated) int CurrentAction = 0; - - + UPROPERTY(Replicated) ATrooper *SelectedTrooper; }; diff --git a/Source/TurnBasedTutorial/Trooper.cpp b/Source/TurnBasedTutorial/Trooper.cpp index e999987..30df2c1 100644 --- a/Source/TurnBasedTutorial/Trooper.cpp +++ b/Source/TurnBasedTutorial/Trooper.cpp @@ -214,7 +214,8 @@ bool ATrooper::CheckMoveCorrectness(const FVector newPos) const { bool ATrooper::CheckAttackCorrectness(const FVector attackLocation, int abilityIndex) const { - return (attackLocation - CurrentLocation).Size() <= + return GetAbility(abilityIndex) != nullptr && ( + attackLocation - CurrentLocation).Size() <= GetAbility(abilityIndex)->ActionRadius && ActionPoints >= GetAbility(abilityIndex)->ActionCost; // return (attackLocation - CurrentLocation).Size() <= AttackRadius;