199 - Projectile Score Request

This commit is contained in:
Kingsmedia 2022-05-28 10:30:24 +02:00
parent 4ae87bee2a
commit 6acf090c07
14 changed files with 60 additions and 13 deletions

View File

@ -37,6 +37,24 @@ void ULagCompensationComponent::ServerScoreRequest_Implementation(ABlasterCharac
}
}
void ULagCompensationComponent::ProjectileServerScoreRequest_Implementation(ABlasterCharacter* HitCharacter, const FVector_NetQuantize& TraceStart,
const FVector_NetQuantize100& InitialVelocity, float HitTime)
{
const FServerSideRewindResult Confirm = ProjectilServerSideRewind(HitCharacter, TraceStart, InitialVelocity, HitTime);
if (Character && HitCharacter && Confirm.bHitConfirmed)
{
UGameplayStatics::ApplyDamage(
HitCharacter,
Character->GetPrimaryWeapon()->GetDamage(),
Character->Controller,
Character->GetPrimaryWeapon(),
UDamageType::StaticClass()
);
}
}
void ULagCompensationComponent::ShotgunServerScoreRequest_Implementation(const TArray<ABlasterCharacter*>& HitCharacters, const FVector_NetQuantize& TraceStart,
const TArray<FVector_NetQuantize>& HitLocations, float HitTime)
{

View File

@ -106,6 +106,14 @@ public:
AWeapon* DamageCauser
);
UFUNCTION(Server, Reliable)
void ProjectileServerScoreRequest(
ABlasterCharacter* HitCharacter,
const FVector_NetQuantize& TraceStart,
const FVector_NetQuantize100& InitialVelocity,
float HitTime
);
FShotgunServerSideRewindResult ShotgunServerSideRewind(
const TArray<ABlasterCharacter*>& HitCharacters,
const FVector_NetQuantize& TraceStart,

View File

@ -30,7 +30,8 @@ void AHitScanWeapon::Fire(const FVector& HitTarget)
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(FireHit.GetActor());
if (BlasterCharacter && InstigatorController)
{
if (HasAuthority() && !bUseServerSideRewind)
bool bCauseAuthDamage = !bUseServerSideRewind || OwnerPawn->IsLocallyControlled();
if (HasAuthority() && bCauseAuthDamage)
{
UGameplayStatics::ApplyDamage(
BlasterCharacter,

View File

@ -3,6 +3,9 @@
#include "ProjectileBullet.h"
#include "Blaster/Character/BlasterCharacter.h"
#include "Blaster/Components/LagCompensationComponent.h"
#include "Blaster/PlayerController/BlasterPlayerController.h"
#include "GameFramework/Character.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "Kismet/GameplayStatics.h"
@ -35,13 +38,29 @@ void AProjectileBullet::PostEditChangeProperty(FPropertyChangedEvent& Event)
void AProjectileBullet::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
ACharacter* OwnerCharacter = Cast<ACharacter>(GetOwner());
ABlasterCharacter* OwnerCharacter = Cast<ABlasterCharacter>(GetOwner());
if (OwnerCharacter)
{
AController* OwnerController = OwnerCharacter->Controller;
ABlasterPlayerController* OwnerController = Cast<ABlasterPlayerController>(OwnerCharacter->Controller);
if (OwnerController)
{
UGameplayStatics::ApplyDamage(OtherActor, Damage, OwnerController, this, UDamageType::StaticClass());
if (OwnerCharacter->HasAuthority() && !bUseServerSideRewind)
{
UGameplayStatics::ApplyDamage(OtherActor, Damage, OwnerController, this, UDamageType::StaticClass());
Super::OnHit(HitComp, OtherActor, OtherComp, NormalImpulse, Hit);
return;
}
ABlasterCharacter* HitCharacter = Cast<ABlasterCharacter>(OtherActor);
if (bUseServerSideRewind && OwnerCharacter->GetLagCompensation() && OwnerCharacter->IsLocallyControlled() && HitCharacter)
{
OwnerCharacter->GetLagCompensation()->ProjectileServerScoreRequest(
HitCharacter,
TraceStart,
InitialVelocity,
OwnerController->GetServerTime() - OwnerController->SingleTripTime
);
}
}
}

View File

@ -35,10 +35,10 @@ void AProjectileWeapon::Fire(const FVector& HitTarget)
SpawnedProjectile->bUseServerSideRewind = false;
SpawnedProjectile->Damage = Damage;
}
else // Server, not locally controlled - spawn non-replicated projectile, no SSR
else // Server, not locally controlled - spawn non-replicated projectile, SSR
{
SpawnedProjectile = World->SpawnActor<AProjectile>(ServerSideRewindProjectileClass, SocketTransform.GetLocation(), TargetRotation, SpawnParams);
SpawnedProjectile->bUseServerSideRewind = false;
SpawnedProjectile->bUseServerSideRewind = true;
}
}
else // Client, using SSR

View File

@ -69,7 +69,8 @@ void AShotgun::FireShotgun(const TArray<FVector_NetQuantize>& HitTargets)
{
if (HitPair.Key && InstigatorController)
{
if (HasAuthority() && !bUseServerSideRewind)
bool bCauseAuthDamage = !bUseServerSideRewind || OwnerPawn->IsLocallyControlled();
if (HasAuthority() && bCauseAuthDamage)
{
UGameplayStatics::ApplyDamage(
HitPair.Key, // Character that was hit