diff --git a/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset b/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset index 4657f90..3a0876d 100644 Binary files a/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset and b/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset differ diff --git a/Content/Blueprints/Character/BP_BlasterCharacter.uasset b/Content/Blueprints/Character/BP_BlasterCharacter.uasset index e1aa765..7e88429 100644 Binary files a/Content/Blueprints/Character/BP_BlasterCharacter.uasset and b/Content/Blueprints/Character/BP_BlasterCharacter.uasset differ diff --git a/Content/Maps/BlasterMap.umap b/Content/Maps/BlasterMap.umap index 91cf764..fe90ccd 100644 Binary files a/Content/Maps/BlasterMap.umap and b/Content/Maps/BlasterMap.umap differ diff --git a/Source/Blaster/Character/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index 86a0ae2..bf58919 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -21,6 +21,7 @@ ABlasterCharacter::ABlasterCharacter() { PrimaryActorTick.bCanEverTick = true; + SpawnCollisionHandlingMethod = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn; CameraBoom = CreateDefaultSubobject(TEXT("CameraBoom")); CameraBoom->SetupAttachment(GetMesh()); CameraBoom->TargetArmLength = 350.f; @@ -105,17 +106,31 @@ void ABlasterCharacter::PlayEliminatedMontage() UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance(); if (AnimInstance && EliminatedMontage) { - UE_LOG(LogTemp, Warning, TEXT("Playing Eliminated Montage, %s"), (bEliminated ? "true" : "false")); AnimInstance->Montage_Play(EliminatedMontage); } } -void ABlasterCharacter::Eliminated_Implementation() +void ABlasterCharacter::Eliminated() +{ + MulticastEliminated(); + GetWorldTimerManager().SetTimer(EliminationTimer, this, &ABlasterCharacter::EliminationTimerFinished, EliminationDelay); +} + +void ABlasterCharacter::MulticastEliminated_Implementation() { bEliminated = true; PlayEliminatedMontage(); } +void ABlasterCharacter::EliminationTimerFinished() +{ + ABlasterGameMode* GameMode = GetWorld()->GetAuthGameMode(); + if (GameMode) + { + GameMode->RequestRespawn(this, Controller); + } +} + void ABlasterCharacter::PlayHitReactMontage() { if (Combat == nullptr || Combat->EquippedWeapon == nullptr) return; diff --git a/Source/Blaster/Character/BlasterCharacter.h b/Source/Blaster/Character/BlasterCharacter.h index 9818187..5b8c54c 100644 --- a/Source/Blaster/Character/BlasterCharacter.h +++ b/Source/Blaster/Character/BlasterCharacter.h @@ -23,8 +23,10 @@ public: void PlayFireMontage(bool bAiming); void PlayEliminatedMontage(); - UFUNCTION(NetMulticast, Reliable) void Eliminated(); + + UFUNCTION(NetMulticast, Reliable) + void MulticastEliminated(); protected: virtual void BeginPlay() override; @@ -115,6 +117,12 @@ private: class ABlasterPlayerController* BlasterPlayerController; bool bEliminated = false; + + UPROPERTY(EditDefaultsOnly) + float EliminationDelay = 3.f; + FTimerHandle EliminationTimer; + + void EliminationTimerFinished(); public: void SetOverlappingWeapon(AWeapon* Weapon); diff --git a/Source/Blaster/GameMode/BlasterGameMode.cpp b/Source/Blaster/GameMode/BlasterGameMode.cpp index 1056121..0659984 100644 --- a/Source/Blaster/GameMode/BlasterGameMode.cpp +++ b/Source/Blaster/GameMode/BlasterGameMode.cpp @@ -4,6 +4,8 @@ #include "BlasterGameMode.h" #include "Blaster/Character/BlasterCharacter.h" +#include "GameFramework/PlayerStart.h" +#include "Kismet/GameplayStatics.h" void ABlasterGameMode::PlayerEliminated(ABlasterCharacter* EliminatedCharacter, ABlasterPlayerController* VictimController, ABlasterPlayerController* AttackerController) @@ -12,5 +14,21 @@ void ABlasterGameMode::PlayerEliminated(ABlasterCharacter* EliminatedCharacter, { EliminatedCharacter->Eliminated(); } - +} + +void ABlasterGameMode::RequestRespawn(ACharacter* EliminatedCharacter, AController* EliminatedController) +{ + if (EliminatedCharacter) + { + EliminatedCharacter->Reset(); + EliminatedCharacter->Destroy(); + } + + if (EliminatedController) + { + TArray PlayerStarts; + UGameplayStatics::GetAllActorsOfClass(this, APlayerStart::StaticClass(), PlayerStarts); + const int32 Selection = FMath::RandRange(0, PlayerStarts.Num() - 1); + RestartPlayerAtPlayerStart(EliminatedController, PlayerStarts[Selection]); + } } diff --git a/Source/Blaster/GameMode/BlasterGameMode.h b/Source/Blaster/GameMode/BlasterGameMode.h index 0b64b0f..7e9560b 100644 --- a/Source/Blaster/GameMode/BlasterGameMode.h +++ b/Source/Blaster/GameMode/BlasterGameMode.h @@ -17,4 +17,5 @@ class BLASTER_API ABlasterGameMode : public AGameMode public: virtual void PlayerEliminated(class ABlasterCharacter* EliminatedCharacter, class ABlasterPlayerController* VictimController, class ABlasterPlayerController* AttackerController); + virtual void RequestRespawn(ACharacter* EliminatedCharacter, AController* EliminatedController); };