From 9d0dc5d0ac7e8409c18b788a1d60066a76ad209e Mon Sep 17 00:00:00 2001 From: Kingsmedia Date: Tue, 10 May 2022 16:03:35 +0200 Subject: [PATCH] 127 - Restart Game --- .../GameModes/BP_BlasterGameMode.uasset | Bin 20388 -> 20388 bytes .../Blaster/Character/BlasterAnimInstance.cpp | 4 +- Source/Blaster/Character/BlasterCharacter.cpp | 92 +++++++++++------- Source/Blaster/Character/BlasterCharacter.h | 7 ++ Source/Blaster/Components/CombatComponent.h | 3 +- Source/Blaster/GameMode/BlasterGameMode.cpp | 6 +- .../BlasterPlayerController.cpp | 8 ++ 7 files changed, 79 insertions(+), 41 deletions(-) diff --git a/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset b/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset index 4923297aefee46d5aa5201f3b1a0f6c6bfbfcdc5..15b9ff2e66c2aa7ad19d81e89617e08a6e4e5702 100644 GIT binary patch delta 79 zcmZ27pK-~2#tnXq0`j|0Kf1AHg71RA8Vr0}@_jeQF{;?e6*!tOK!666W`WW`>civ( Uwld5Gj?R-8T1srbZhKY`0NVK$2><{9 delta 79 zcmZ27pK-~2#tnXq0)l7G%_=@>=f0w4vD5P1{}yeIV^pz`Ti{^A00A0MngvP&DTT=k UY-N}iI5n+a diff --git a/Source/Blaster/Character/BlasterAnimInstance.cpp b/Source/Blaster/Character/BlasterAnimInstance.cpp index 50df4ce..fb8c071 100644 --- a/Source/Blaster/Character/BlasterAnimInstance.cpp +++ b/Source/Blaster/Character/BlasterAnimInstance.cpp @@ -76,6 +76,6 @@ void UBlasterAnimInstance::NativeUpdateAnimation(float DeltaSeconds) } bUseFABRIK = BlasterCharacter->GetCombatState() != ECombatState::ECS_Reloading; - bUseAimOffsets = BlasterCharacter->GetCombatState() != ECombatState::ECS_Reloading; - bTransformRightHand = BlasterCharacter->GetCombatState() != ECombatState::ECS_Reloading; + bUseAimOffsets = BlasterCharacter->GetCombatState() != ECombatState::ECS_Reloading && !BlasterCharacter->GetDisableGameplay(); + bTransformRightHand = BlasterCharacter->GetCombatState() != ECombatState::ECS_Reloading && !BlasterCharacter->GetDisableGameplay(); } diff --git a/Source/Blaster/Character/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index 9a3c412..4d07751 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -73,6 +73,7 @@ void ABlasterCharacter::GetLifetimeReplicatedProps(TArray& Ou DOREPLIFETIME_CONDITION(ABlasterCharacter, OverlappingWeapon, COND_OwnerOnly); DOREPLIFETIME(ABlasterCharacter, Health); + DOREPLIFETIME(ABlasterCharacter, bDisableGameplay); } void ABlasterCharacter::OnRep_ReplicatedMovement() @@ -91,6 +92,10 @@ void ABlasterCharacter::Destroyed() { EliminationBotComponent->DestroyComponent(); } + if (Combat && Combat->EquippedWeapon) + { + Combat->EquippedWeapon->Destroy(); + } } void ABlasterCharacter::PostInitializeComponents() @@ -176,11 +181,8 @@ void ABlasterCharacter::MulticastEliminated_Implementation() // Disable character movement GetCharacterMovement()->DisableMovement(); GetCharacterMovement()->StopMovementImmediately(); - if (BlasterPlayerController) - { - DisableInput(BlasterPlayerController); - } - + bDisableGameplay = true; + // Disable collision GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); GetMesh()->SetCollisionEnabled(ECollisionEnabled::NoCollision); @@ -243,10 +245,14 @@ void ABlasterCharacter::ReceiveDamage(AActor* DamagedActor, float Damage, const } } -void ABlasterCharacter::Tick(float DeltaTime) +void ABlasterCharacter::RotateInPlace(float DeltaTime) { - Super::Tick(DeltaTime); - + if (bDisableGameplay) + { + bUseControllerRotationYaw = false; + TurningInPlace = ETurningInPlace::ETIP_NotTurning; + return; + } if (GetLocalRole() > ROLE_SimulatedProxy && IsLocallyControlled()) { AimOffset(DeltaTime); @@ -260,7 +266,13 @@ void ABlasterCharacter::Tick(float DeltaTime) } CalculateAO_Pitch(); } +} +void ABlasterCharacter::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + + RotateInPlace(DeltaTime); HideCameraIfCharacterClose(); PollInit(); } @@ -300,6 +312,7 @@ void ABlasterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCo void ABlasterCharacter::MoveForward(float Value) { + if (bDisableGameplay) return; if (Controller != nullptr && Value != 0.f) { const FRotator YawRotation(0.f, Controller->GetControlRotation().Yaw, 0.f); @@ -311,6 +324,7 @@ void ABlasterCharacter::MoveForward(float Value) void ABlasterCharacter::MoveRight(float Value) { + if (bDisableGameplay) return; if (Controller != nullptr && Value != 0.f) { const FRotator YawRotation(0.f, Controller->GetControlRotation().Yaw, 0.f); @@ -332,6 +346,7 @@ void ABlasterCharacter::LookUp(float Value) void ABlasterCharacter::EquipButtonPressed() { + if (bDisableGameplay) return; if (Combat) { if (HasAuthority()) @@ -347,6 +362,7 @@ void ABlasterCharacter::EquipButtonPressed() void ABlasterCharacter::ReloadButtonPressed() { + if (bDisableGameplay) return; if (Combat) { Combat->Reload(); @@ -355,6 +371,7 @@ void ABlasterCharacter::ReloadButtonPressed() void ABlasterCharacter::CrouchButtonPressed() { + if (bDisableGameplay) return; if (bIsCrouched) { UnCrouch(); @@ -367,6 +384,7 @@ void ABlasterCharacter::CrouchButtonPressed() void ABlasterCharacter::AimButtonPressed() { + if (bDisableGameplay) return; if (Combat) { Combat->SetAiming(true); @@ -375,12 +393,42 @@ void ABlasterCharacter::AimButtonPressed() void ABlasterCharacter::AimButtonReleased() { + if (bDisableGameplay) return; if (Combat) { Combat->SetAiming(false); } } +void ABlasterCharacter::Jump() +{ + if (bDisableGameplay) return; + if (bIsCrouched) + { + UnCrouch(); + } + else + { + Super::Jump(); + } +} + +void ABlasterCharacter::FireButtonPressed() +{ + if (Combat) + { + Combat->FireButtonPressed(true); + } +} + +void ABlasterCharacter::FireButtonReleased() +{ + if (Combat) + { + Combat->FireButtonPressed(false); + } +} + void ABlasterCharacter::AimOffset(float DeltaTime) { if (Combat && Combat->EquippedWeapon == nullptr) return; @@ -464,34 +512,6 @@ void ABlasterCharacter::SimProxiesTurn() TurningInPlace = ETurningInPlace::ETIP_NotTurning; } -void ABlasterCharacter::Jump() -{ - if (bIsCrouched) - { - UnCrouch(); - } - else - { - Super::Jump(); - } -} - -void ABlasterCharacter::FireButtonPressed() -{ - if (Combat) - { - Combat->FireButtonPressed(true); - } -} - -void ABlasterCharacter::FireButtonReleased() -{ - if (Combat) - { - Combat->FireButtonPressed(false); - } -} - void ABlasterCharacter::ServerEquipButtonPressed_Implementation() { EquipButtonPressed(); diff --git a/Source/Blaster/Character/BlasterCharacter.h b/Source/Blaster/Character/BlasterCharacter.h index 497f5d8..eeca674 100644 --- a/Source/Blaster/Character/BlasterCharacter.h +++ b/Source/Blaster/Character/BlasterCharacter.h @@ -24,6 +24,7 @@ public: virtual void PostInitializeComponents() override; virtual void OnRep_ReplicatedMovement() override; virtual void Destroyed() override; + void RotateInPlace(float DeltaTime); void PlayFireMontage(bool bAiming); void PlayReloadMontage(); void PlayEliminatedMontage(); @@ -33,6 +34,9 @@ public: UFUNCTION(NetMulticast, Reliable) void MulticastEliminated(); + UPROPERTY(Replicated) + bool bDisableGameplay = false; + protected: virtual void BeginPlay() override; @@ -55,6 +59,7 @@ protected: UFUNCTION() void ReceiveDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType, class AController* InstigatorController, AActor* DamageCauser); + void UpdateHUDHealth(); // Poll for any relevant classes and initialize them void PollInit(); @@ -186,4 +191,6 @@ public: FORCEINLINE float GetHealth() const { return Health; } FORCEINLINE float GetMaxHealth() const { return MaxHealth; } ECombatState GetCombatState() const; + FORCEINLINE UCombatComponent* GetCombat() const { return Combat; } + FORCEINLINE bool GetDisableGameplay() const { return bDisableGameplay; } }; diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index 3095fcd..a53d39d 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -29,6 +29,7 @@ public: void FinishedReloading(); void UpdateAmmoValues(); + void FireButtonPressed(bool bPressed); protected: virtual void BeginPlay() override; void SetAiming(bool bIsAiming); @@ -40,8 +41,6 @@ protected: void OnRep_EquippedWeapon(); void Fire(); - void FireButtonPressed(bool bPressed); - UFUNCTION(Server, Reliable) void ServerFire(const FVector_NetQuantize& TraceHitTarget); diff --git a/Source/Blaster/GameMode/BlasterGameMode.cpp b/Source/Blaster/GameMode/BlasterGameMode.cpp index 365d459..bc78cf4 100644 --- a/Source/Blaster/GameMode/BlasterGameMode.cpp +++ b/Source/Blaster/GameMode/BlasterGameMode.cpp @@ -49,7 +49,11 @@ void ABlasterGameMode::Tick(float DeltaSeconds) } else if (MatchState == MatchState::Cooldown) { - CountDownTime = CooldownTime + WarmupTime + MatchTime - GetWorld()->GetTimeSeconds() + LevelStartingTime; + CountDownTime = WarmupTime + MatchTime + CooldownTime - GetWorld()->GetTimeSeconds() + LevelStartingTime; + if (CountDownTime <= 0.f) + { + RestartGame(); + } } } diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.cpp b/Source/Blaster/PlayerController/BlasterPlayerController.cpp index d41e7dc..9906af8 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.cpp +++ b/Source/Blaster/PlayerController/BlasterPlayerController.cpp @@ -4,6 +4,7 @@ #include "BlasterPlayerController.h" #include "Blaster/Character/BlasterCharacter.h" +#include "Blaster/Components/CombatComponent.h" #include "Blaster/GameMode/BlasterGameMode.h" #include "Blaster/HUD/Announcement.h" #include "Blaster/HUD/BlasterHUD.h" @@ -108,6 +109,13 @@ void ABlasterPlayerController::HandleCooldown() BlasterHUD->Announcement->SetVisibility(ESlateVisibility::Visible); } } + + ABlasterCharacter* BlasterCharacter = Cast(GetPawn()); + if (BlasterCharacter && BlasterCharacter->GetCombat()) + { + BlasterCharacter->bDisableGameplay = true; + BlasterCharacter->GetCombat()->FireButtonPressed(false); + } } void ABlasterPlayerController::OnMatchStateSet(FName State)