213 - Head Shots for Server-Side Rewind

This commit is contained in:
Kingsmedia 2022-05-29 15:28:58 +02:00
parent 9b45b23dfd
commit 2a5c6cb50a
11 changed files with 24 additions and 22 deletions

Binary file not shown.

View File

@ -32,7 +32,7 @@ void UBlasterAnimInstance::NativeUpdateAnimation(float DeltaTime)
bIsInAir = BlasterCharacter->GetCharacterMovement()->IsFalling();
bIsAccelerating = BlasterCharacter->GetCharacterMovement()->GetCurrentAcceleration().Size() > 0.f ? true : false;
bWeaponEquipped = BlasterCharacter->IsWeaponEquipped();
EquippedWeapon = BlasterCharacter->GetPrimaryWeapon();
EquippedWeapon = BlasterCharacter->GetEquippedWeapon();
bIsCrouched = BlasterCharacter->bIsCrouched;
bAiming = BlasterCharacter->IsAiming();
TurningInPlace = BlasterCharacter->GetTurningInPlace();

View File

@ -230,7 +230,7 @@ void ABlasterCharacter::MulticastEliminated_Implementation(bool bPlayerLeftGame)
GetActorLocation()
);
}
if (IsLocallyControlled() && GetPrimaryWeapon() && GetPrimaryWeapon()->IsSniper() && IsAiming())
if (IsLocallyControlled() && GetEquippedWeapon() && GetEquippedWeapon()->IsSniper() && IsAiming())
{
ShowSniperScopeWidget(false);
}
@ -517,7 +517,7 @@ void ABlasterCharacter::ReceiveDamage(AActor* DamagedActor, float Damage, const
if (bEliminated) return;
float DamageToHealth = Damage;
if (Shield > 0)
if (Shield > 0.f)
{
if (Shield >= Damage)
{
@ -526,8 +526,8 @@ void ABlasterCharacter::ReceiveDamage(AActor* DamagedActor, float Damage, const
}
else
{
DamageToHealth = FMath::Clamp(DamageToHealth - Shield, 0.f, Damage);
Shield = 0.f;
DamageToHealth = FMath::Clamp(DamageToHealth - (Damage - Shield), 0.f, Damage);
}
}
@ -963,7 +963,7 @@ bool ABlasterCharacter::IsAiming()
return Combat && Combat->bAiming;
}
AWeapon* ABlasterCharacter::GetPrimaryWeapon()
AWeapon* ABlasterCharacter::GetEquippedWeapon()
{
if (Combat == nullptr) return nullptr;
return Combat->EquippedWeapon;

View File

@ -310,7 +310,7 @@ public:
bool IsAiming();
FORCEINLINE float GetAO_Yaw() const { return AO_Yaw; }
FORCEINLINE float GetAO_Pitch() const { return AO_Pitch; }
AWeapon* GetPrimaryWeapon();
AWeapon* GetEquippedWeapon();
FORCEINLINE ETurningInPlace GetTurningInPlace() const { return TurningInPlace; }
FVector GetHitTarget() const;
FORCEINLINE UCameraComponent* GetFollowCamera() const { return FollowCamera; }

View File

@ -411,17 +411,19 @@ FFramePackage ULagCompensationComponent::GetFrameToCheck(ABlasterCharacter* HitC
return FrameToCheck;
}
void ULagCompensationComponent::ServerScoreRequest_Implementation(ABlasterCharacter* HitCharacter, const FVector_NetQuantize& TraceStart,
const FVector_NetQuantize& HitLocation, float HitTime, AWeapon* DamageCauser)
const FVector_NetQuantize& HitLocation, float HitTime)
{
const FServerSideRewindResult Confirm = ServerSideRewind(HitCharacter, TraceStart, HitLocation, HitTime);
if (Character && HitCharacter && DamageCauser && Confirm.bHitConfirmed)
if (Character && HitCharacter && Character->GetEquippedWeapon() && Confirm.bHitConfirmed)
{
const float Damage = Confirm.bHeadShot ? Character->GetEquippedWeapon()->GetHeadShotDamage() : Character->GetEquippedWeapon()->GetDamage();
UGameplayStatics::ApplyDamage(
HitCharacter,
DamageCauser->GetDamage(),
Damage,
Character->Controller,
DamageCauser,
Character->GetEquippedWeapon(),
UDamageType::StaticClass()
);
}
@ -432,13 +434,15 @@ void ULagCompensationComponent::ProjectileServerScoreRequest_Implementation(ABla
{
const FServerSideRewindResult Confirm = ProjectileServerSideRewind(HitCharacter, TraceStart, InitialVelocity, HitTime);
if (Character && HitCharacter && Confirm.bHitConfirmed)
if (Character && HitCharacter && Character->GetEquippedWeapon() && Confirm.bHitConfirmed)
{
const float Damage = Confirm.bHeadShot ? Character->GetEquippedWeapon()->GetHeadShotDamage() : Character->GetEquippedWeapon()->GetDamage();
UGameplayStatics::ApplyDamage(
HitCharacter,
Character->GetPrimaryWeapon()->GetDamage(),
Damage,
Character->Controller,
Character->GetPrimaryWeapon(),
Character->GetEquippedWeapon(),
UDamageType::StaticClass()
);
}
@ -451,22 +455,22 @@ void ULagCompensationComponent::ShotgunServerScoreRequest_Implementation(const T
for (auto& HitCharacter : HitCharacters)
{
if (HitCharacter == nullptr || Character == nullptr || HitCharacter->GetPrimaryWeapon() == nullptr) continue;
if (HitCharacter == nullptr || Character == nullptr || HitCharacter->GetEquippedWeapon() == nullptr) continue;
float TotalDamage = 0.f;
if (Confirm.Headshots.Contains(HitCharacter))
{
TotalDamage += Confirm.Headshots[HitCharacter] * Character->GetPrimaryWeapon()->GetDamage();
TotalDamage += Confirm.Headshots[HitCharacter] * Character->GetEquippedWeapon()->GetHeadShotDamage();
}
if (Confirm.BodyShots.Contains(HitCharacter))
{
TotalDamage += Confirm.BodyShots[HitCharacter] * Character->GetPrimaryWeapon()->GetDamage();
TotalDamage += Confirm.BodyShots[HitCharacter] * Character->GetEquippedWeapon()->GetDamage();
}
UGameplayStatics::ApplyDamage(
HitCharacter,
TotalDamage,
Character->Controller,
Character->GetPrimaryWeapon(),
Character->GetEquippedWeapon(),
UDamageType::StaticClass()
);
}

View File

@ -102,8 +102,7 @@ public:
ABlasterCharacter* HitCharacter,
const FVector_NetQuantize& TraceStart,
const FVector_NetQuantize& HitLocation,
float HitTime,
AWeapon* DamageCauser
float HitTime
);
UFUNCTION(Server, Reliable)

View File

@ -54,8 +54,7 @@ void AHitScanWeapon::Fire(const FVector& HitTarget)
BlasterCharacter,
Start,
HitTarget,
OwnerController->GetServerTime() - OwnerController->SingleTripTime,
this
OwnerController->GetServerTime() - OwnerController->SingleTripTime
);
}
}

View File

@ -161,7 +161,7 @@ void AWeapon::OnRep_Owner()
else
{
OwnerCharacter = OwnerCharacter == nullptr ? Cast<ABlasterCharacter>(Owner) : OwnerCharacter;
if (OwnerCharacter && OwnerCharacter->GetPrimaryWeapon() && OwnerCharacter->GetPrimaryWeapon() == this)
if (OwnerCharacter && OwnerCharacter->GetEquippedWeapon() && OwnerCharacter->GetEquippedWeapon() == this)
{
SetHUDAmmo();
}