189 - Score Request

This commit is contained in:
Kingsmedia 2022-05-27 18:36:56 +02:00
parent c455d1655d
commit de7d73125b
8 changed files with 90 additions and 28 deletions

Binary file not shown.

View File

@ -3,7 +3,9 @@
#include "LagCompensationComponent.h"
#include "Blaster/Weapon/Weapon.h"
#include "Components/BoxComponent.h"
#include "Kismet/GameplayStatics.h"
ULagCompensationComponent::ULagCompensationComponent()
{
@ -16,6 +18,24 @@ void ULagCompensationComponent::BeginPlay()
}
void ULagCompensationComponent::ServerScoreRequest_Implementation(ABlasterCharacter* HitCharacter, const FVector_NetQuantize& TraceStart,
const FVector_NetQuantize& HitLocation, float HitTime, AWeapon* DamageCauser)
{
const FServerSideRewindResult Confirm = ServerSideRewind(HitCharacter, TraceStart, HitLocation, HitTime);
if (Character && HitCharacter && DamageCauser && Confirm.bHitConfirmed)
{
UGameplayStatics::ApplyDamage(
HitCharacter,
DamageCauser->GetDamage(),
Character->Controller,
DamageCauser,
UDamageType::StaticClass()
);
}
}
void ULagCompensationComponent::SaveFramePackage(FFramePackage& Package)
{
Character = Character == nullptr ? Cast<ABlasterCharacter>(GetOwner()) : Character;
@ -116,11 +136,11 @@ FServerSideRewindResult ULagCompensationComponent::ConfirmHit(const FFramePackag
EnableCharacterMeshCollision(HitCharacter, ECollisionEnabled::QueryAndPhysics);
return FServerSideRewindResult{ true, false };
}
ResetHitBoxes(HitCharacter, CurrentFrame);
EnableCharacterMeshCollision(HitCharacter, ECollisionEnabled::QueryAndPhysics);
return FServerSideRewindResult{ false, false };
}
ResetHitBoxes(HitCharacter, CurrentFrame);
EnableCharacterMeshCollision(HitCharacter, ECollisionEnabled::QueryAndPhysics);
return FServerSideRewindResult{ false, false };
}
void ULagCompensationComponent::CacheBoxPositions(ABlasterCharacter* HitCharacter, FFramePackage& OutFramePackage)
@ -258,6 +278,12 @@ void ULagCompensationComponent::TickComponent(float DeltaTime, ELevelTick TickTy
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
SaveFramePackage();
}
void ULagCompensationComponent::SaveFramePackage()
{
if (Character == nullptr || !Character->HasAuthority()) return;
if (FrameHistory.Num() <= 1)
{
FFramePackage ThisFrame;
@ -270,12 +296,11 @@ void ULagCompensationComponent::TickComponent(float DeltaTime, ELevelTick TickTy
while (HistoryLength > MaxRecordTime)
{
FrameHistory.RemoveNode(FrameHistory.GetTail());
HistoryLength = FrameHistory.GetHead()->GetValue().Time - FrameHistory.GetTail()->GetValue().Time;
HistoryLength = FrameHistory.GetHead()->GetValue().Time - FrameHistory.GetTail()->GetValue().Time;
}
FFramePackage ThisFrame;
SaveFramePackage(ThisFrame);
FrameHistory.AddHead(ThisFrame);
ShowFramePackage(ThisFrame, FColor::Red);
// ShowFramePackage(ThisFrame, FColor::Red);
}
}
}

View File

@ -56,9 +56,18 @@ public:
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
void ShowFramePackage(const FFramePackage& Package, const FColor Color);
FServerSideRewindResult ServerSideRewind(class ABlasterCharacter* HitCharacter, const FVector_NetQuantize& TraceStart, const FVector_NetQuantize& HitLocation, float HitTime);
UFUNCTION(Server, Reliable)
void ServerScoreRequest(
ABlasterCharacter* HitCharacter,
const FVector_NetQuantize& TraceStart,
const FVector_NetQuantize& HitLocation,
float HitTime,
class AWeapon* DamageCauser
);
protected:
virtual void BeginPlay() override;
void SaveFramePackage();
void SaveFramePackage(FFramePackage& Package);
FFramePackage InterpBetweenFrames(const FFramePackage& OlderFrame, const FFramePackage& YoungerFrame, float HitTime);
FServerSideRewindResult ConfirmHit(const FFramePackage& Package, ABlasterCharacter* HitCharacter, const FVector_NetQuantize& TraceStart, const FVector_NetQuantize HitLocation);

View File

@ -468,7 +468,8 @@ void ABlasterPlayerController::ServerRequestServerTime_Implementation(float Time
void ABlasterPlayerController::ClientReportServerTime_Implementation(float TimeOfClientRequest, float TimeServerReceivedClientRequest)
{
float RoundTripTime = GetWorld()->GetTimeSeconds() - TimeOfClientRequest;
float CurrentServerTime = TimeServerReceivedClientRequest + 0.5f * RoundTripTime;
SingleTripTime = 0.5f * RoundTripTime;
float CurrentServerTime = TimeServerReceivedClientRequest + SingleTripTime;
ClientServerDelta = CurrentServerTime - GetWorld()->GetTimeSeconds();
}

View File

@ -44,6 +44,8 @@ public:
void OnMatchStateSet(FName State);
void HandleCooldown();
float SingleTripTime = 0.f;
protected:

View File

@ -4,6 +4,8 @@
#include "HitScanWeapon.h"
#include "Blaster/Character/BlasterCharacter.h"
#include "Blaster/Components/LagCompensationComponent.h"
#include "Blaster/PlayerController/BlasterPlayerController.h"
#include "Engine/SkeletalMeshSocket.h"
#include "Kismet/GameplayStatics.h"
#include "Particles/ParticleSystemComponent.h"
@ -26,15 +28,34 @@ void AHitScanWeapon::Fire(const FVector& HitTarget)
WeaponTraceHit(Start, HitTarget, FireHit);
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(FireHit.GetActor());
if (BlasterCharacter && HasAuthority() && InstigatorController)
if (BlasterCharacter && InstigatorController)
{
UGameplayStatics::ApplyDamage(
BlasterCharacter,
Damage,
InstigatorController,
this,
UDamageType::StaticClass()
);
if (HasAuthority() && !bUseServerSideRewind)
{
UGameplayStatics::ApplyDamage(
BlasterCharacter,
Damage,
InstigatorController,
this,
UDamageType::StaticClass()
);
}
else if (!HasAuthority() && bUseServerSideRewind)
{
OwnerCharacter = OwnerCharacter == nullptr ? Cast<ABlasterCharacter>(OwnerPawn) : OwnerCharacter;
OwnerController = OwnerController == nullptr ? Cast<ABlasterPlayerController>(InstigatorController) : OwnerController;
if (OwnerCharacter && OwnerController && OwnerCharacter->GetLagCompensation())
{
OwnerCharacter->GetLagCompensation()->ServerScoreRequest(
BlasterCharacter,
Start,
HitTarget,
OwnerController->GetServerTime() - OwnerController->SingleTripTime,
this
);
}
}
}
if (ImpactParticles)
{

View File

@ -26,9 +26,6 @@ protected:
UPROPERTY(EditAnywhere)
USoundCue* HitSound;
UPROPERTY(EditAnywhere)
float Damage = 20.f;
private:
UPROPERTY(EditAnywhere)

View File

@ -124,6 +124,18 @@ protected:
UPROPERTY(EditAnywhere, Category = "Weapon Scatter")
float SphereRadius = 75.f;
UPROPERTY(EditAnywhere)
float Damage = 20.f;
UPROPERTY(EditAnywhere)
bool bUseServerSideRewind = false;
UPROPERTY()
class ABlasterCharacter* OwnerCharacter;
UPROPERTY()
class ABlasterPlayerController* OwnerController;
private:
UPROPERTY(VisibleAnywhere, Category = "Weapon Properties")
USkeletalMeshComponent* WeaponMesh;
@ -164,12 +176,6 @@ private:
// Incremented in SpendRound(), decremented in ClientUpdateAmmo()
int32 Sequence = 0;
UPROPERTY()
class ABlasterCharacter* OwnerCharacter;
UPROPERTY()
class ABlasterPlayerController* OwnerController;
UPROPERTY(EditAnywhere)
EWeaponType WeaponType;
@ -184,7 +190,8 @@ public:
FORCEINLINE int32 GetMagCapacity() const { return MagCapacity; }
bool IsEmpty();
bool IsFull();
FORCEINLINE float GetDamage() const { return Damage; }
// Convenience methods for WeaponType
FORCEINLINE bool IsPistol() const { return WeaponType == EWeaponType::EWT_Pistol; }
FORCEINLINE bool IsSMG() const { return WeaponType == EWeaponType::EWT_SubmachineGun; }