208 - Spawning the Crown

This commit is contained in:
Kingsmedia 2022-05-28 22:21:03 +02:00
parent 45b9f170e7
commit 4fa586e648
8 changed files with 84 additions and 68 deletions

View File

@ -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<ABlasterGameState>(UGameplayStatics::GetGameState(this));
if (BlasterGameState && BlasterGameState->TopScoringPlayers.Contains(BlasterPlayerState))
{
MulticastGainedTheLead();
}
}
}
}
void ABlasterCharacter::UpdateDissolveMaterial(float DissolveValue)

View File

@ -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<AWeapon> DefaultWeaponClass;
// Grenade
UPROPERTY(VisibleAnywhere)
UStaticMeshComponent* AttachedGrenade;

View File

@ -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<UBoxComponent>(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<UBoxComponent>(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<UBoxComponent>(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<UBoxComponent>(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<ABlasterCharacter>(ConfirmHitResult.GetActor());
if (BlasterCharacter)
{
if (ConfirmHitResult.Component.IsValid())
{
UBoxComponent* Box = Cast<UBoxComponent>(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<ABlasterCharacter>(ConfirmHitResult.GetActor());
if (BlasterCharacter)
{
if (ConfirmHitResult.Component.IsValid())
{
UBoxComponent* Box = Cast<UBoxComponent>(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]++;

View File

@ -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);

View File

@ -83,8 +83,33 @@ void ABlasterGameMode::PlayerEliminated(class ABlasterCharacter* EliminatedChara
if (AttackerPlayerState && AttackerPlayerState != VictimPlayerState && BlasterGameState)
{
TArray<ABlasterPlayerState*> PlayersCurrentlyInTheLead;
for (auto LeadPlayer : BlasterGameState->TopScoringPlayers)
{
PlayersCurrentlyInTheLead.Add(LeadPlayer);
}
AttackerPlayerState->IncreaseScore(1.f);
BlasterGameState->UpdateTopScore(AttackerPlayerState);
if (BlasterGameState->TopScoringPlayers.Contains(AttackerPlayerState))
{
ABlasterCharacter* Leader = Cast<ABlasterCharacter>(AttackerPlayerState->GetPawn());
if (Leader)
{
Leader->MulticastGainedTheLead();
}
}
for (int32 i = 0; i < PlayersCurrentlyInTheLead.Num(); i++)
{
if (!BlasterGameState->TopScoringPlayers.Contains(PlayersCurrentlyInTheLead[i]))
{
ABlasterCharacter* Loser = Cast<ABlasterCharacter>(PlayersCurrentlyInTheLead[i]->GetPawn());
if (Loser)
{
Loser->MulticastLostTheLead();
}
}
}
}
if (VictimPlayerState)
{

View File

@ -30,5 +30,4 @@ void ABlasterGameState::UpdateTopScore(ABlasterPlayerState* ScoringPlayer)
TopScoringPlayers.AddUnique(ScoringPlayer);
TopScore = ScoringPlayer->GetScore();
}
}

View File

@ -112,8 +112,6 @@ void AHitScanWeapon::WeaponTraceHit(const FVector& TraceStart, const FVector& Hi
BeamEnd = OutHit.ImpactPoint;
}
// DrawDebugSphere(GetWorld(), BeamEnd, 16.f, 12, FColor::Orange, true);
if (BeamParticles)
{
UParticleSystemComponent* Beam = UGameplayStatics::SpawnEmitterAtLocation(