diff --git a/Content/Blueprints/Character/BP_BlasterCharacter.uasset b/Content/Blueprints/Character/BP_BlasterCharacter.uasset index 8005537..cf71e47 100644 Binary files a/Content/Blueprints/Character/BP_BlasterCharacter.uasset and b/Content/Blueprints/Character/BP_BlasterCharacter.uasset differ diff --git a/Source/Blaster/Character/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index 41e1cce..b0b7ec4 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -3,11 +3,14 @@ #include "BlasterCharacter.h" +#include "NiagaraComponent.h" +#include "NiagaraFunctionLibrary.h" #include "Blaster/Blaster.h" #include "Blaster/Components/BuffComponent.h" #include "Blaster/Components/CombatComponent.h" #include "Blaster/Components/LagCompensationComponent.h" #include "Blaster/GameMode/BlasterGameMode.h" +#include "Blaster/GameState/BlasterGameState.h" #include "Blaster/PlayerController/BlasterPlayerController.h" #include "Blaster/PlayerState/BlasterPlayerState.h" #include "Blaster/Weapon/Weapon.h" @@ -231,7 +234,10 @@ void ABlasterCharacter::MulticastEliminated_Implementation(bool bPlayerLeftGame) { ShowSniperScopeWidget(false); } - + if (CrownComponent) + { + CrownComponent->DestroyComponent(); + } GetWorldTimerManager().SetTimer( EliminationTimer, this, @@ -281,6 +287,36 @@ void ABlasterCharacter::Destroyed() } } +void ABlasterCharacter::MulticastGainedTheLead_Implementation() +{ + if (CrownSystem == nullptr) return; + if (CrownComponent == nullptr) + { + CrownComponent = UNiagaraFunctionLibrary::SpawnSystemAttached( + CrownSystem, + GetCapsuleComponent(), + FName(), + GetActorLocation() + FVector(0.f, 0.f, 110.f), + GetActorRotation(), + EAttachLocation::KeepWorldPosition, + false + ); + } + + if (CrownComponent) + { + CrownComponent->Activate(); + } +} + +void ABlasterCharacter::MulticastLostTheLead_Implementation() +{ + if (CrownComponent) + { + CrownComponent->DestroyComponent(); + } +} + void ABlasterCharacter::BeginPlay() { Super::BeginPlay(); @@ -864,8 +900,15 @@ void ABlasterCharacter::PollInit() // Initialize Score now we have the PlayerState BlasterPlayerState->IncreaseScore(0.f); BlasterPlayerState->IncreaseDefeats(0); + + const ABlasterGameState* BlasterGameState = Cast(UGameplayStatics::GetGameState(this)); + if (BlasterGameState && BlasterGameState->TopScoringPlayers.Contains(BlasterPlayerState)) + { + MulticastGainedTheLead(); + } } } + } void ABlasterCharacter::UpdateDissolveMaterial(float DissolveValue) diff --git a/Source/Blaster/Character/BlasterCharacter.h b/Source/Blaster/Character/BlasterCharacter.h index c9632c2..f079a3c 100644 --- a/Source/Blaster/Character/BlasterCharacter.h +++ b/Source/Blaster/Character/BlasterCharacter.h @@ -60,6 +60,13 @@ public: void ServerLeaveGame(); FOnLeftGame OnLeftGame; + + UFUNCTION(NetMulticast, Reliable) + void MulticastGainedTheLead(); + + UFUNCTION(NetMulticast, Reliable) + void MulticastLostTheLead(); + protected: virtual void BeginPlay() override; @@ -273,7 +280,7 @@ private: UPROPERTY(EditAnywhere, Category = Elimination) UMaterialInstance* DissolveMaterialInstance; - // Elimination bot + // Elimination effects UPROPERTY(EditAnywhere) UParticleSystem* EliminationBotEffect; @@ -283,12 +290,17 @@ private: UPROPERTY(EditAnywhere) USoundCue* EliminationBotSound; + UPROPERTY(EditAnywhere) + class UNiagaraSystem* CrownSystem; + + UPROPERTY() + class UNiagaraComponent* CrownComponent; + // Default weapon UPROPERTY(EditAnywhere) TSubclassOf DefaultWeaponClass; // Grenade - UPROPERTY(VisibleAnywhere) UStaticMeshComponent* AttachedGrenade; diff --git a/Source/Blaster/Components/LagCompensationComponent.cpp b/Source/Blaster/Components/LagCompensationComponent.cpp index 5a56320..0d1f08e 100644 --- a/Source/Blaster/Components/LagCompensationComponent.cpp +++ b/Source/Blaster/Components/LagCompensationComponent.cpp @@ -13,12 +13,6 @@ ULagCompensationComponent::ULagCompensationComponent() PrimaryComponentTick.bCanEverTick = true; } -void ULagCompensationComponent::BeginPlay() -{ - Super::BeginPlay(); - -} - void ULagCompensationComponent::ServerScoreRequest_Implementation(ABlasterCharacter* HitCharacter, const FVector_NetQuantize& TraceStart, const FVector_NetQuantize& HitLocation, float HitTime, AWeapon* DamageCauser) { @@ -26,7 +20,6 @@ void ULagCompensationComponent::ServerScoreRequest_Implementation(ABlasterCharac if (Character && HitCharacter && DamageCauser && Confirm.bHitConfirmed) { - UGameplayStatics::ApplyDamage( HitCharacter, DamageCauser->GetDamage(), @@ -44,7 +37,6 @@ void ULagCompensationComponent::ProjectileServerScoreRequest_Implementation(ABla if (Character && HitCharacter && Confirm.bHitConfirmed) { - UGameplayStatics::ApplyDamage( HitCharacter, Character->GetPrimaryWeapon()->GetDamage(), @@ -103,7 +95,6 @@ void ULagCompensationComponent::SaveFramePackage() FFramePackage ThisFrame; SaveFramePackage(ThisFrame); FrameHistory.AddHead(ThisFrame); - // ShowFramePackage(ThisFrame, FColor::Red); } } @@ -167,8 +158,7 @@ FServerSideRewindResult ULagCompensationComponent::ConfirmHit(const FFramePackag HeadBox->SetCollisionResponseToChannel(ECC_HitBox, ECR_Block); const FVector TraceEnd = TraceStart + (HitLocation - TraceStart) * 1.25f; - UWorld* World = GetWorld(); - if (World) + if (UWorld* World = GetWorld()) { FHitResult ConfirmHitResult; World->LineTraceSingleByChannel( @@ -180,14 +170,6 @@ FServerSideRewindResult ULagCompensationComponent::ConfirmHit(const FFramePackag if (ConfirmHitResult.bBlockingHit) // we hit the head, return early { - if (ConfirmHitResult.Component.IsValid()) - { - UBoxComponent* Box = Cast(ConfirmHitResult.Component); - if (Box) - { - DrawDebugBox(GetWorld(), Box->GetComponentLocation(), Box->GetScaledBoxExtent(), FQuat(Box->GetComponentRotation()), FColor::Red, false, 8.f); - } - } ResetHitBoxes(HitCharacter, CurrentFrame); EnableCharacterMeshCollision(HitCharacter, ECollisionEnabled::QueryAndPhysics); return FServerSideRewindResult{ true, true }; @@ -212,14 +194,6 @@ FServerSideRewindResult ULagCompensationComponent::ConfirmHit(const FFramePackag if (ConfirmHitResult.bBlockingHit) { - if (ConfirmHitResult.Component.IsValid()) - { - UBoxComponent* Box = Cast(ConfirmHitResult.Component); - if (Box) - { - DrawDebugBox(GetWorld(), Box->GetComponentLocation(), Box->GetScaledBoxExtent(), FQuat(Box->GetComponentRotation()), FColor::Blue, false, 8.f); - } - } ResetHitBoxes(HitCharacter, CurrentFrame); EnableCharacterMeshCollision(HitCharacter, ECollisionEnabled::QueryAndPhysics); return FServerSideRewindResult{ true, false }; @@ -253,22 +227,12 @@ FServerSideRewindResult ULagCompensationComponent::ProjectileConfirmHit(const FF PathParams.ProjectileRadius = 5.f; PathParams.TraceChannel = ECC_HitBox; PathParams.ActorsToIgnore.Add(GetOwner()); - PathParams.DrawDebugTime = 5.f; - PathParams.DrawDebugType = EDrawDebugTrace::ForDuration; FPredictProjectilePathResult PathResult; UGameplayStatics::PredictProjectilePath(this, PathParams, PathResult); if (PathResult.HitResult.bBlockingHit) // we hit the head, return early { - if (PathResult.HitResult.Component.IsValid()) - { - UBoxComponent* Box = Cast(PathResult.HitResult.Component); - if (Box) - { - DrawDebugBox(GetWorld(), Box->GetComponentLocation(), Box->GetScaledBoxExtent(), FQuat(Box->GetComponentRotation()), FColor::Red, false, 8.f); - } - } ResetHitBoxes(HitCharacter, CurrentFrame); EnableCharacterMeshCollision(HitCharacter, ECollisionEnabled::QueryAndPhysics); return FServerSideRewindResult{ true, true }; @@ -287,14 +251,6 @@ FServerSideRewindResult ULagCompensationComponent::ProjectileConfirmHit(const FF UGameplayStatics::PredictProjectilePath(this, PathParams, PathResult); if (PathResult.HitResult.bBlockingHit) { - if (PathResult.HitResult.Component.IsValid()) - { - UBoxComponent* Box = Cast(PathResult.HitResult.Component); - if (Box) - { - DrawDebugBox(GetWorld(), Box->GetComponentLocation(), Box->GetScaledBoxExtent(), FQuat(Box->GetComponentRotation()), FColor::Blue, false, 8.f); - } - } ResetHitBoxes(HitCharacter, CurrentFrame); EnableCharacterMeshCollision(HitCharacter, ECollisionEnabled::QueryAndPhysics); return FServerSideRewindResult{ true, false }; @@ -353,14 +309,6 @@ FShotgunServerSideRewindResult ULagCompensationComponent::ShotgunConfirmHit(cons ABlasterCharacter* BlasterCharacter = Cast(ConfirmHitResult.GetActor()); if (BlasterCharacter) { - if (ConfirmHitResult.Component.IsValid()) - { - UBoxComponent* Box = Cast(ConfirmHitResult.Component); - if (Box) - { - DrawDebugBox(GetWorld(), Box->GetComponentLocation(), Box->GetScaledBoxExtent(), FQuat(Box->GetComponentRotation()), FColor::Red, false, 8.f); - } - } if (ShotgunResult.Headshots.Contains(BlasterCharacter)) { ShotgunResult.Headshots[BlasterCharacter]++; @@ -405,14 +353,6 @@ FShotgunServerSideRewindResult ULagCompensationComponent::ShotgunConfirmHit(cons ABlasterCharacter* BlasterCharacter = Cast(ConfirmHitResult.GetActor()); if (BlasterCharacter) { - if (ConfirmHitResult.Component.IsValid()) - { - UBoxComponent* Box = Cast(ConfirmHitResult.Component); - if (Box) - { - DrawDebugBox(GetWorld(), Box->GetComponentLocation(), Box->GetScaledBoxExtent(), FQuat(Box->GetComponentRotation()), FColor::Blue, false, 8.f); - } - } if (ShotgunResult.BodyShots.Contains(BlasterCharacter)) { ShotgunResult.BodyShots[BlasterCharacter]++; diff --git a/Source/Blaster/Components/LagCompensationComponent.h b/Source/Blaster/Components/LagCompensationComponent.h index 2779d47..908d07d 100644 --- a/Source/Blaster/Components/LagCompensationComponent.h +++ b/Source/Blaster/Components/LagCompensationComponent.h @@ -122,7 +122,6 @@ public: ); protected: - virtual void BeginPlay() override; void SaveFramePackage(); void SaveFramePackage(FFramePackage& Package); FFramePackage InterpBetweenFrames(const FFramePackage& OlderFrame, const FFramePackage& YoungerFrame, float HitTime); diff --git a/Source/Blaster/GameMode/BlasterGameMode.cpp b/Source/Blaster/GameMode/BlasterGameMode.cpp index f732d65..0c045da 100644 --- a/Source/Blaster/GameMode/BlasterGameMode.cpp +++ b/Source/Blaster/GameMode/BlasterGameMode.cpp @@ -83,8 +83,33 @@ void ABlasterGameMode::PlayerEliminated(class ABlasterCharacter* EliminatedChara if (AttackerPlayerState && AttackerPlayerState != VictimPlayerState && BlasterGameState) { + TArray PlayersCurrentlyInTheLead; + for (auto LeadPlayer : BlasterGameState->TopScoringPlayers) + { + PlayersCurrentlyInTheLead.Add(LeadPlayer); + } AttackerPlayerState->IncreaseScore(1.f); BlasterGameState->UpdateTopScore(AttackerPlayerState); + + if (BlasterGameState->TopScoringPlayers.Contains(AttackerPlayerState)) + { + ABlasterCharacter* Leader = Cast(AttackerPlayerState->GetPawn()); + if (Leader) + { + Leader->MulticastGainedTheLead(); + } + } + for (int32 i = 0; i < PlayersCurrentlyInTheLead.Num(); i++) + { + if (!BlasterGameState->TopScoringPlayers.Contains(PlayersCurrentlyInTheLead[i])) + { + ABlasterCharacter* Loser = Cast(PlayersCurrentlyInTheLead[i]->GetPawn()); + if (Loser) + { + Loser->MulticastLostTheLead(); + } + } + } } if (VictimPlayerState) { diff --git a/Source/Blaster/GameState/BlasterGameState.cpp b/Source/Blaster/GameState/BlasterGameState.cpp index 7077045..8fa3ce8 100644 --- a/Source/Blaster/GameState/BlasterGameState.cpp +++ b/Source/Blaster/GameState/BlasterGameState.cpp @@ -30,5 +30,4 @@ void ABlasterGameState::UpdateTopScore(ABlasterPlayerState* ScoringPlayer) TopScoringPlayers.AddUnique(ScoringPlayer); TopScore = ScoringPlayer->GetScore(); } - } diff --git a/Source/Blaster/Weapon/HitScanWeapon.cpp b/Source/Blaster/Weapon/HitScanWeapon.cpp index e1dd7b9..a76c95f 100644 --- a/Source/Blaster/Weapon/HitScanWeapon.cpp +++ b/Source/Blaster/Weapon/HitScanWeapon.cpp @@ -111,8 +111,6 @@ void AHitScanWeapon::WeaponTraceHit(const FVector& TraceStart, const FVector& Hi { BeamEnd = OutHit.ImpactPoint; } - - // DrawDebugSphere(GetWorld(), BeamEnd, 16.f, 12, FColor::Orange, true); if (BeamParticles) {