diff --git a/Content/Blueprints/Character/BP_BlasterCharacter.uasset b/Content/Blueprints/Character/BP_BlasterCharacter.uasset index 7bb574b..c8f92be 100644 Binary files a/Content/Blueprints/Character/BP_BlasterCharacter.uasset and b/Content/Blueprints/Character/BP_BlasterCharacter.uasset differ diff --git a/Content/Blueprints/Weapon/BP_AssaultRifle.uasset b/Content/Blueprints/Weapon/BP_AssaultRifle.uasset index fcd2d8b..d93b95c 100644 Binary files a/Content/Blueprints/Weapon/BP_AssaultRifle.uasset and b/Content/Blueprints/Weapon/BP_AssaultRifle.uasset differ diff --git a/Content/Blueprints/Weapon/BP_GenadeLauncher.uasset b/Content/Blueprints/Weapon/BP_GenadeLauncher.uasset index 2daf2f5..9f62f91 100644 Binary files a/Content/Blueprints/Weapon/BP_GenadeLauncher.uasset and b/Content/Blueprints/Weapon/BP_GenadeLauncher.uasset differ diff --git a/Content/Blueprints/Weapon/BP_Pistol.uasset b/Content/Blueprints/Weapon/BP_Pistol.uasset index c4a505b..257b821 100644 Binary files a/Content/Blueprints/Weapon/BP_Pistol.uasset and b/Content/Blueprints/Weapon/BP_Pistol.uasset differ diff --git a/Content/Blueprints/Weapon/BP_RocketLauncher.uasset b/Content/Blueprints/Weapon/BP_RocketLauncher.uasset index fa09271..6bb603e 100644 Binary files a/Content/Blueprints/Weapon/BP_RocketLauncher.uasset and b/Content/Blueprints/Weapon/BP_RocketLauncher.uasset differ diff --git a/Content/Blueprints/Weapon/BP_Shotgun.uasset b/Content/Blueprints/Weapon/BP_Shotgun.uasset index 0b8f9c7..ee066db 100644 Binary files a/Content/Blueprints/Weapon/BP_Shotgun.uasset and b/Content/Blueprints/Weapon/BP_Shotgun.uasset differ diff --git a/Content/Blueprints/Weapon/BP_SniperRifle.uasset b/Content/Blueprints/Weapon/BP_SniperRifle.uasset index 19ebe08..c449dd3 100644 Binary files a/Content/Blueprints/Weapon/BP_SniperRifle.uasset and b/Content/Blueprints/Weapon/BP_SniperRifle.uasset differ diff --git a/Content/Blueprints/Weapon/BP_SubmachineGun.uasset b/Content/Blueprints/Weapon/BP_SubmachineGun.uasset index b221452..40026f4 100644 Binary files a/Content/Blueprints/Weapon/BP_SubmachineGun.uasset and b/Content/Blueprints/Weapon/BP_SubmachineGun.uasset differ diff --git a/Source/Blaster/Components/LagCompensationComponent.cpp b/Source/Blaster/Components/LagCompensationComponent.cpp index 3491064..5a56320 100644 --- a/Source/Blaster/Components/LagCompensationComponent.cpp +++ b/Source/Blaster/Components/LagCompensationComponent.cpp @@ -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& HitCharacters, const FVector_NetQuantize& TraceStart, const TArray& HitLocations, float HitTime) { diff --git a/Source/Blaster/Components/LagCompensationComponent.h b/Source/Blaster/Components/LagCompensationComponent.h index 1c3ae6e..2779d47 100644 --- a/Source/Blaster/Components/LagCompensationComponent.h +++ b/Source/Blaster/Components/LagCompensationComponent.h @@ -79,7 +79,7 @@ public: const FVector_NetQuantize& HitLocation, float HitTime ); - + // Projectiles FServerSideRewindResult ProjectilServerSideRewind( ABlasterCharacter* HitCharacter, @@ -96,7 +96,7 @@ public: const TArray& HitLocations, float HitTime ); - + UFUNCTION(Server, Reliable) void ServerScoreRequest( ABlasterCharacter* HitCharacter, @@ -105,14 +105,22 @@ public: float HitTime, AWeapon* DamageCauser ); - + + UFUNCTION(Server, Reliable) + void ProjectileServerScoreRequest( + ABlasterCharacter* HitCharacter, + const FVector_NetQuantize& TraceStart, + const FVector_NetQuantize100& InitialVelocity, + float HitTime + ); + FShotgunServerSideRewindResult ShotgunServerSideRewind( const TArray& HitCharacters, const FVector_NetQuantize& TraceStart, const TArray& HitLocations, float HitTime ); - + protected: virtual void BeginPlay() override; void SaveFramePackage(); @@ -141,14 +149,14 @@ protected: const FVector_NetQuantize100& InitialVelocity, float HitTime ); - + // Shotgun FShotgunServerSideRewindResult ShotgunConfirmHit( const TArray& FramePackages, const FVector_NetQuantize& TraceStart, const TArray& HitLocations ); - + private: UPROPERTY() ABlasterCharacter* Character; diff --git a/Source/Blaster/Weapon/HitScanWeapon.cpp b/Source/Blaster/Weapon/HitScanWeapon.cpp index 305e34b..bf13831 100644 --- a/Source/Blaster/Weapon/HitScanWeapon.cpp +++ b/Source/Blaster/Weapon/HitScanWeapon.cpp @@ -30,7 +30,8 @@ void AHitScanWeapon::Fire(const FVector& HitTarget) ABlasterCharacter* BlasterCharacter = Cast(FireHit.GetActor()); if (BlasterCharacter && InstigatorController) { - if (HasAuthority() && !bUseServerSideRewind) + bool bCauseAuthDamage = !bUseServerSideRewind || OwnerPawn->IsLocallyControlled(); + if (HasAuthority() && bCauseAuthDamage) { UGameplayStatics::ApplyDamage( BlasterCharacter, diff --git a/Source/Blaster/Weapon/ProjectileBullet.cpp b/Source/Blaster/Weapon/ProjectileBullet.cpp index 6110077..a2ef34f 100644 --- a/Source/Blaster/Weapon/ProjectileBullet.cpp +++ b/Source/Blaster/Weapon/ProjectileBullet.cpp @@ -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(GetOwner()); + ABlasterCharacter* OwnerCharacter = Cast(GetOwner()); if (OwnerCharacter) { - AController* OwnerController = OwnerCharacter->Controller; + ABlasterPlayerController* OwnerController = Cast(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(OtherActor); + if (bUseServerSideRewind && OwnerCharacter->GetLagCompensation() && OwnerCharacter->IsLocallyControlled() && HitCharacter) + { + OwnerCharacter->GetLagCompensation()->ProjectileServerScoreRequest( + HitCharacter, + TraceStart, + InitialVelocity, + OwnerController->GetServerTime() - OwnerController->SingleTripTime + ); + } } } diff --git a/Source/Blaster/Weapon/ProjectileWeapon.cpp b/Source/Blaster/Weapon/ProjectileWeapon.cpp index 0f508fa..ffe7e46 100644 --- a/Source/Blaster/Weapon/ProjectileWeapon.cpp +++ b/Source/Blaster/Weapon/ProjectileWeapon.cpp @@ -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(ServerSideRewindProjectileClass, SocketTransform.GetLocation(), TargetRotation, SpawnParams); - SpawnedProjectile->bUseServerSideRewind = false; + SpawnedProjectile->bUseServerSideRewind = true; } } else // Client, using SSR diff --git a/Source/Blaster/Weapon/Shotgun.cpp b/Source/Blaster/Weapon/Shotgun.cpp index 7ad8bbd..0333d54 100644 --- a/Source/Blaster/Weapon/Shotgun.cpp +++ b/Source/Blaster/Weapon/Shotgun.cpp @@ -69,7 +69,8 @@ void AShotgun::FireShotgun(const TArray& HitTargets) { if (HitPair.Key && InstigatorController) { - if (HasAuthority() && !bUseServerSideRewind) + bool bCauseAuthDamage = !bUseServerSideRewind || OwnerPawn->IsLocallyControlled(); + if (HasAuthority() && bCauseAuthDamage) { UGameplayStatics::ApplyDamage( HitPair.Key, // Character that was hit