From 77951cd5eed7a24595af8a8fa7e712ee3853e9e8 Mon Sep 17 00:00:00 2001 From: eyakm1 Date: Fri, 24 Mar 2023 05:50:58 +0300 Subject: [PATCH] Basic replication of turns implemented --- Content/BP_MyGameMode.uasset | Bin 18328 -> 18906 bytes Content/BP_MyPlayerController.uasset | Bin 17924 -> 18135 bytes Content/BattleField/BattleFieldMap.umap | Bin 634586 -> 634586 bytes Source/TurnBasedTutorial/MyGameMode.cpp | 122 ++++++++++++++---- Source/TurnBasedTutorial/MyGameMode.h | 23 +++- .../TurnBasedTutorial/MyPlayerController.cpp | 118 ++++++++++------- Source/TurnBasedTutorial/MyPlayerController.h | 18 ++- 7 files changed, 203 insertions(+), 78 deletions(-) diff --git a/Content/BP_MyGameMode.uasset b/Content/BP_MyGameMode.uasset index aec131aa9663b371392550cc13b129a15d663a17..d432830cc35fdb2c9d7da503cd34e5417e10e93c 100644 GIT binary patch delta 4576 zcmcgvYiv|i5Iz@5p|sj3?Y1DVEl>-hl%?I$g|dZh!GMoN zMWaNd&&?`+uPkf780H0?wmXG zotZgv=FHjq@-gkA)cX6g2g-$*B7|7m6Z8X15Pk4_LX#IgbB}+S(y}X6h#Zh4rwB1< z6+(k?Ri+Rwc(%av_Q0v<2M!LcdgjM|@0s((XP;c^zVOtEt?SBb&71{KSNgbD$6(f~9X);%JzLfCl7o%~voJgw7`4ZohN6w{6V< zZ@2G&KjiKS_Jw-7yZs^Y`6owD58lu=Ptq~cQ88_9@xh_5-WXh!5S}tC3sBKU+}*z3 zUh&2HTb~Yomh^)bPNYE6iC=?gX3)5Wcr@l$z+kLMjKS0*~1UOj;Zm&gfXHM_=>F|Cnh+P|8i+1KlVYogvlN{M3A&m7$r^pPN9EYKVI4~T*NM8`L z*%?>*NYF?OuXa?7%&W<^{{`!(h!nHYOET~ZTF*eayzX+yJrxP^@l>n*PndGuG%c5= zU@?A7f;SSE*cW$&`Wglw1wOHKdvbe1OIoH8C)@fUtK7 zc77Q4N?J-TW*JW_T18k1E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$J-620CqWWJY3!H8}!)q}+JGweN0mTK@R$D;(8*G;~ M)HrQley#fKe>08E)c^nh diff --git a/Content/BP_MyPlayerController.uasset b/Content/BP_MyPlayerController.uasset index ca2c84fc00157287addc28893871079a9578f8ff..42ec990ce4879254ade9a65204482fbc4015161f 100644 GIT binary patch delta 1083 zcma)5Ur19?7(eGuZJWB?{ms=?ZcI~_ZMi>gDzrJLn2@;;>Pgt#osQizpn55@m$=YBvlr_jD1w55h#m@j5b7n6Akxk~-c27paDLzS{mys3?|1GwcXA4U zp2pcMv+10h5BMGxBcwqHwQCVF5!+pY&>tg0nD~=~m?HB&ncCmgPx^y5&aAE{$A5TM z$3TtaRU6uC1tbp{%?N#Llf2!rO~$4ZArAf)SAdB9qMb40!v>NOZBN8vLaH^^Ees3| zrX%T5)L~hg6GMtR6;{AViIw0Y#g`PnQ!FaARw?8LoNRxQE(c`4Q??4|ER`yxDPE`e zoZ>f%j7C~LO0k1rA*3``Rj%?`xac;hc5BVkyvG#3P~6fSgVS1{`nbGh(+RWMIAg7c z2y269+A_H8RzfptRL{wZvh@&da=;AhWsZ1d*9sP$k@>I__UOFKn2)aX=&IqTj%Ajc zXlU1anYVsvaR$cnIEwlrZb7BAp6+l~@hB#)A;>Wp)%5DoODi=K{Xr6D}qh7F;6g8tsZ) zK&TbbbW&MBc2xv9*lL-?2)0|o1jC`SbCN>oY~_+ehMi1@&BnKm2&oKzsb5I(L&?Y} z9~Jr%sbM}onC3J6iD5p{n;A^od7A^((0xP;u|X-Ti{t~-;u@L@o5_@GxpL$nD zZzP!%V!SXSq(}L9Ix-;C@`*T~N%USwr22RwM@U7YQpz4Zh0^cQO;RK+t`m7J`z|In M1c$LW5t_jN0m6?AL;wH) delta 796 zcmYLGO=uHA6rP!+ZL-;HHrZ^Fwp&q>YNM4l>?WHfDfw&lWVC|f!GnsZr4&>U|0t!U zhYE@@4^N_pf{;Un%7UIs@K~CINTH}jl;TlQ5eX{P+08T#%zNMW&HI~~jeB_hF0NEa zSbb2*fy}!e-Qwa6?0I!D(K>PPoZO zseNqQSIkP#tKqi;6Cz5{SW;Bgm>2w@oXrMWFfYk;r{vzh%>F#^lJ82O!of=HRhU1#%M z)L}ex5GF-~eAt2g&=iB@e%e0C_zjXZ7>q;1FOo}Hn|cBUxszw0v#-e#@#O0)4f3~2Q TTcxWQaPc@y7v{|qV{`Z)IR?b~ diff --git a/Content/BattleField/BattleFieldMap.umap b/Content/BattleField/BattleFieldMap.umap index d3fb3a4750280a1055653e30529c9b9e7561feb5..2c00f7a6471996c67fac462d41735ef19c8cb70c 100644 GIT binary patch delta 267 zcmcb0SMAnawGC#B3cjLg_iw-Db>A#!dAYp$l=`xJr{*Z~9P#a$mHK4YYW{_r!x*2c zure|L!Da`w)4YsAn|VyOv$3iI1=Kd5u$rX7Wuj|fq-S8MXJWiLC3z;3!26Bwd8^N^ zcUarKF#k(Vu={4-GzUqjhM@X5=E=*Nw@%*B^lfr<%W{DOIU4Ub+%Wanz&y#|NO^1|4Z$dWDX%ceJKE|UXi z8FDnFu^s&UKmXw5i!*VN`&2=QIq z<6<8C*X7^jht(>R6V$jSJGA-;G!^*^dQQIN+;vkiC@WnebMu_ml_ESv?_-Z1SL}0S zU^wACIdGOCP&o_BDWlE%CtsW?H@Ro7^yIq=T+L@^wV$2E2*gZ4%nZaVK+FonY(UHo N#2nkt&f?@10RT0AZ)^Yn diff --git a/Source/TurnBasedTutorial/MyGameMode.cpp b/Source/TurnBasedTutorial/MyGameMode.cpp index 3f36c01..2103d43 100644 --- a/Source/TurnBasedTutorial/MyGameMode.cpp +++ b/Source/TurnBasedTutorial/MyGameMode.cpp @@ -2,7 +2,8 @@ #include "MyGameMode.h" #include "Kismet/GameplayStatics.h" - +#include "MyPawn.h" +#include "MyGameState.h" AMyGameMode::AMyGameMode() : Super() { @@ -15,35 +16,35 @@ AMyGameMode::AMyGameMode() : Super() void AMyGameMode::BeginPlay() { Super::BeginPlay(); - ATrooper::InitNumberOfTroopersForId(); - UE_LOG(LogTemp, Warning, TEXT("GameMode BeginPlay")); - if (GetWorld()->GetMapName().Contains("BattleFieldMap")) - { - UE_LOG(LogTemp, Warning, TEXT("Player Logined")); - InitializeBattleField(); - GetPlayerController()->StartTurn(); - } + // ATrooper::InitNumberOfTroopersForId(); + // UE_LOG(LogTemp, Warning, TEXT("GameMode BeginPlay")); + // if (GetWorld()->GetMapName().Contains("BattleFieldMap")) + // { + // UE_LOG(LogTemp, Warning, TEXT("Player Logined")); + // InitializeBattleField(); + // GetMyPlayerController()->StartTurn(); + // } } void AMyGameMode::InitializeBattleField() const { - FVector Location(2000.0f, -1000.0f, 0.0f); - FRotator Rotation(0.0f, 180.0f, 0.0f); - FActorSpawnParameters const SpawnInfo; - for (int i = 0; i < 5; ++i) - { - AActor* Spawned = GetWorld()->SpawnActor(Location, Rotation, SpawnInfo); - dynamic_cast(Spawned)->InitTrooper(Location, true); - Location += {0.f, 500.f, 0.0f}; - } - Location = {-2000.0f, -1000.0f, 0.0f}; - Rotation = {0.0f, 0.0f, 0.0f}; - for (int i = 0; i < 5; ++i) - { - AActor* Spawned = GetWorld()->SpawnActor(Location, Rotation, SpawnInfo); - dynamic_cast(Spawned)->InitTrooper(Location, false); - Location += {0.f, 500.f, 0.0f}; - } + // FVector Location(2000.0f, -1000.0f, 0.0f); + // FRotator Rotation(0.0f, 180.0f, 0.0f); + // FActorSpawnParameters const SpawnInfo; + // for (int i = 0; i < 5; ++i) + // { + // AActor* Spawned = GetWorld()->SpawnActor(Location, Rotation, SpawnInfo); + // dynamic_cast(Spawned)->InitTrooper(Location, true); + // Location += {0.f, 500.f, 0.0f}; + // } + // Location = {-2000.0f, -1000.0f, 0.0f}; + // Rotation = {0.0f, 0.0f, 0.0f}; + // for (int i = 0; i < 5; ++i) + // { + // AActor* Spawned = GetWorld()->SpawnActor(Location, Rotation, SpawnInfo); + // dynamic_cast(Spawned)->InitTrooper(Location, false); + // Location += {0.f, 500.f, 0.0f}; + // } } @@ -58,10 +59,13 @@ AActor* AMyGameMode::ChoosePlayerStart_Implementation(AController* Player) void AMyGameMode::InitializeSpawnPointsIfNeeded(AController* Player) { + UE_LOG(LogTemp, Warning, TEXT("InitializeSpawnPointsIfNeeded")); if (SpawnPoints.Num() != 0) { + UE_LOG(LogTemp, Warning, TEXT("InitializeSpawnPointsIfNeeded Exit %d"), SpawnPoints.Num()); return; } + UE_LOG(LogTemp, Warning, TEXT("Rebuilding spawnpoints")); const auto World = GetWorld(); for (TActorIterator PlayerStartIterator(GetWorld()); PlayerStartIterator; ++PlayerStartIterator) { @@ -70,6 +74,7 @@ void AMyGameMode::InitializeSpawnPointsIfNeeded(AController* Player) const APawn* PawnToFit = PawnClass ? PawnClass->GetDefaultObject() : nullptr; const FVector ActorLocation = PlayerStart->GetActorLocation(); const FRotator ActorRotation = PlayerStart->GetActorRotation(); + UE_LOG(LogTemp, Warning, TEXT("PlayerStart iterator %d"), PlayerStartIterator->GetPlayerIndex()); if (!World->EncroachingBlockingGeometry(PawnToFit, ActorLocation, ActorRotation)) { SpawnPoints.Add(PlayerStartIterator->GetPlayerIndex(), *PlayerStartIterator); @@ -79,7 +84,68 @@ void AMyGameMode::InitializeSpawnPointsIfNeeded(AController* Player) } -AMyPlayerController* AMyGameMode::GetPlayerController() const +void AMyGameMode::PostLogin(APlayerController* NewPlayer) +{ + Super::PostLogin(NewPlayer); + UE_LOG(LogTemp, Warning, TEXT("PostLogin")); + const auto World = GetWorld(); + const auto CurrentNumberOfPlayers = GetNumPlayers(); + UE_LOG(LogTemp, Warning, TEXT("%d"), CurrentNumberOfPlayers); + if (CurrentNumberOfPlayers == 2) + { + UE_LOG(LogTemp, Warning, TEXT("Game Start")); + // start the game + StartGame(); + } + else + { + // delay the game + UE_LOG(LogTemp, Warning, TEXT("Game Delay")); + } +} + + +void AMyGameMode::StartGame() +{ + PlayerInTurn()->StartTurn(); +} + + +AMyPlayerController* AMyGameMode::PlayerInTurn() const +{ + return GetMyPlayerController(CurrentPlayerTurn); +} + +AMyPlayerController* AMyGameMode::PlayerNotInTurn() const +{ + uint8 PlayerControllerIndexNotInTurn = 0; + if (CurrentPlayerTurn == 0) + { + PlayerControllerIndexNotInTurn = 1; + } + else + { + PlayerControllerIndexNotInTurn = 0; + } + return GetMyPlayerController(PlayerControllerIndexNotInTurn); +} + +void AMyGameMode::CycleTurns() +{ + PlayerInTurn()->EndTurn(); + if (CurrentPlayerTurn == 0) + { + CurrentPlayerTurn = 1; + } + else + { + CurrentPlayerTurn = 0; + } + PlayerInTurn()->StartTurn(); +} + + +AMyPlayerController* AMyGameMode::GetMyPlayerController(uint8 const PlayerIndex) const { - return dynamic_cast(UGameplayStatics::GetPlayerController(GetWorld(), 0)); + return dynamic_cast(UGameplayStatics::GetPlayerController(GetWorld(), PlayerIndex)); } diff --git a/Source/TurnBasedTutorial/MyGameMode.h b/Source/TurnBasedTutorial/MyGameMode.h index 9d0eb1b..2304cbd 100644 --- a/Source/TurnBasedTutorial/MyGameMode.h +++ b/Source/TurnBasedTutorial/MyGameMode.h @@ -5,8 +5,6 @@ #include "CoreMinimal.h" #include "EngineUtils.h" #include "MyPlayerController.h" -#include "MyGameState.h" -#include "MyPawn.h" #include "MyPlayerStart.h" #include "GameFramework/GameMode.h" #include "MyGameMode.generated.h" @@ -22,14 +20,31 @@ public: virtual AActor* ChoosePlayerStart_Implementation(AController* Player) override; + virtual void PostLogin(APlayerController* NewPlayer) override; + virtual void BeginPlay() override; + UFUNCTION(BlueprintCallable) + void CycleTurns(); + private: void InitializeSpawnPointsIfNeeded(AController* Player); void InitializeBattleField() const; - TMap SpawnPoints; + TMap SpawnPoints{}; + + AMyPlayerController* GetMyPlayerController(uint8 const PlayerIndex) const; + + UFUNCTION(BlueprintCallable) + void StartGame(); + + UFUNCTION(BlueprintPure) + AMyPlayerController* PlayerInTurn() const; + + UFUNCTION(BlueprintPure) + AMyPlayerController* PlayerNotInTurn() const; - AMyPlayerController* GetPlayerController() const; + UPROPERTY() + uint8 CurrentPlayerTurn{0}; }; diff --git a/Source/TurnBasedTutorial/MyPlayerController.cpp b/Source/TurnBasedTutorial/MyPlayerController.cpp index 76ee933..8056434 100644 --- a/Source/TurnBasedTutorial/MyPlayerController.cpp +++ b/Source/TurnBasedTutorial/MyPlayerController.cpp @@ -1,8 +1,10 @@ // Fill out your copyright notice in the Description page of Project Settings. #include "MyPlayerController.h" +#include "Kismet/GameplayStatics.h" +#include "MyGameMode.h" -AMyPlayerController::AMyPlayerController() : Super(), IsMyTurn(false), SelectedTrooper(nullptr) +AMyPlayerController::AMyPlayerController() : Super(), bIsMyTurn(false), SelectedTrooper(nullptr) { UE_LOG(LogTemp, Warning, TEXT("Player controller created")); } @@ -14,64 +16,92 @@ void AMyPlayerController::SetupInputComponent() &AMyPlayerController::OnLeftMouseClick); } -void AMyPlayerController::StartTurn() +void AMyPlayerController::SetMyTurn(bool bMyTurn) { - IsMyTurn = true; + bIsMyTurn = bMyTurn; + if (bIsMyTurn) + { + GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Green, + FString::Printf( + TEXT("YOUR TURN!"))); + } + // OnMyTurnChanged.ExecuteIfBound(bIsMyTurn); +} + +void AMyPlayerController::StartTurn_Implementation() +{ + SetMyTurn(true); UE_LOG(LogTemp, Warning, TEXT("Your turn")); } -void AMyPlayerController::EndTurn() +void AMyPlayerController::EndTurn_Implementation() { - IsMyTurn = false; + SetMyTurn(false); UE_LOG(LogTemp, Warning, TEXT("Not your turn")); } void AMyPlayerController::SetTrooperIsMoving(bool isMoving) { - IsThereTrooperMoving = isMoving; + bIsThereTrooperMoving = isMoving; +} + +auto AMyPlayerController::GetMyGameMode() const +{ + return dynamic_cast(UGameplayStatics::GetGameMode(GetWorld())); +} + +void AMyPlayerController::MoveHero_Implementation() +{ + GetMyGameMode()->CycleTurns(); } + void AMyPlayerController::OnLeftMouseClick() { - if (IsThereTrooperMoving) + // if (bIsThereTrooperMoving) + // { + // return; + // } + // UE_LOG(LogTemp, Warning, TEXT("Mouse clicked")); + // FHitResult HitResult; + // bool const IsHitResult = GetHitResultUnderCursorByChannel(TraceTypeQuery1, false, HitResult); + // if (IsHitResult) + // { + // AActor* Actor = HitResult.Actor.Get(); + // if (Actor->ActorHasTag(FName("Trooper"))) + // { + // ATrooper* Trooper = dynamic_cast(Actor); + // if (Trooper != nullptr && Trooper != SelectedTrooper) + // { + // if (Trooper->IsOnPlayersSide()) + // { + // UE_LOG(LogTemp, Warning, TEXT("Hitted trooper id: %d, on our side"), + // Trooper->GetId()); + // SelectedTrooper = Trooper; + // } + // else + // { + // UE_LOG(LogTemp, Warning, TEXT("Hitted trooper id: %d, enemy"), + // Trooper->GetId()); + // UE_LOG(LogTemp, Warning, TEXT("Trooper #%d hit enemy trooper #%d"), + // SelectedTrooper->GetId(), Trooper->GetId()); + // } + // } + // } + // else if (Actor->ActorHasTag(FName("Floor"))) + // { + // UE_LOG(LogTemp, Warning, TEXT("Hitted floor: %f, %f, %f"), HitResult.Location.X, + // HitResult.Location.Y, HitResult.Location.Z); + // if (SelectedTrooper != nullptr) + // { + // SelectedTrooper->MoveTrooper(HitResult.Location); + // bIsThereTrooperMoving = true; + // } + // } + // } + if (!bIsMyTurn) { return; } - UE_LOG(LogTemp, Warning, TEXT("Mouse clicked")); - FHitResult HitResult; - bool const IsHitResult = GetHitResultUnderCursorByChannel(TraceTypeQuery1, false, HitResult); - if (IsHitResult) - { - AActor* Actor = HitResult.Actor.Get(); - if (Actor->ActorHasTag(FName("Trooper"))) - { - ATrooper* Trooper = dynamic_cast(Actor); - if (Trooper != nullptr && Trooper != SelectedTrooper) - { - if (Trooper->IsOnPlayersSide()) - { - UE_LOG(LogTemp, Warning, TEXT("Hitted trooper id: %d, on our side"), - Trooper->GetId()); - SelectedTrooper = Trooper; - } - else - { - UE_LOG(LogTemp, Warning, TEXT("Hitted trooper id: %d, enemy"), - Trooper->GetId()); - UE_LOG(LogTemp, Warning, TEXT("Trooper #%d hit enemy trooper #%d"), - SelectedTrooper->GetId(), Trooper->GetId()); - } - } - } - else if (Actor->ActorHasTag(FName("Floor"))) - { - UE_LOG(LogTemp, Warning, TEXT("Hitted floor: %f, %f, %f"), HitResult.Location.X, - HitResult.Location.Y, HitResult.Location.Z); - if (SelectedTrooper != nullptr) - { - SelectedTrooper->MoveTrooper(HitResult.Location); - IsThereTrooperMoving = true; - } - } - } + MoveHero(); } diff --git a/Source/TurnBasedTutorial/MyPlayerController.h b/Source/TurnBasedTutorial/MyPlayerController.h index 357e164..2060f43 100644 --- a/Source/TurnBasedTutorial/MyPlayerController.h +++ b/Source/TurnBasedTutorial/MyPlayerController.h @@ -9,28 +9,42 @@ /** * */ + +// DECLARE_DYNAMIC_DELEGATE_OneParam(FOnMyTurnChangedDelegate, bool, bMyTurn); + UCLASS() class TURNBASEDTUTORIAL_API AMyPlayerController : public APlayerController { GENERATED_BODY() public: + // FOnMyTurnChangedDelegate OnMyTurnChanged; + AMyPlayerController(); + UFUNCTION(Client, Reliable) void StartTurn(); + UFUNCTION(Client, Reliable) void EndTurn(); + UFUNCTION(Server, Reliable) + void MoveHero(); + virtual void SetupInputComponent() override; void SetTrooperIsMoving(bool isMoving); private: - bool IsMyTurn; + bool bIsMyTurn; - bool IsThereTrooperMoving = false; + bool bIsThereTrooperMoving = false; ATrooper* SelectedTrooper; void OnLeftMouseClick(); + + void SetMyTurn(bool bMyTurn); + + auto GetMyGameMode() const; };