| 12 | #include "Blaster/BlasterComponents/LagCompensationComponent.h" |
| 13 | |
| 14 | void AHitScanWeapon::Fire(const FVector& HitTarget) |
| 15 | { |
| 16 | Super::Fire(HitTarget); |
| 17 | |
| 18 | APawn* OwnerPawn = Cast<APawn>(GetOwner()); |
| 19 | if (OwnerPawn == nullptr) return; |
| 20 | AController* InstigatorController = OwnerPawn->GetController(); |
| 21 | |
| 22 | const USkeletalMeshSocket* MuzzleFlashSocket = GetWeaponMesh()->GetSocketByName("MuzzleFlash"); |
| 23 | if (MuzzleFlashSocket) |
| 24 | { |
| 25 | FTransform SocketTransform = MuzzleFlashSocket->GetSocketTransform(GetWeaponMesh()); |
| 26 | FVector Start = SocketTransform.GetLocation(); |
| 27 | |
| 28 | FHitResult FireHit; |
| 29 | WeaponTraceHit(Start, HitTarget, FireHit); |
| 30 | |
| 31 | ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(FireHit.GetActor()); |
| 32 | if (BlasterCharacter && InstigatorController) |
| 33 | { |
| 34 | bool bCauseAuthDamage = !bUseServerSideRewind || OwnerPawn->IsLocallyControlled(); |
| 35 | if (HasAuthority() && bCauseAuthDamage) |
| 36 | { |
| 37 | const float DamageToCause = FireHit.BoneName.ToString() == FString("head") ? HeadShotDamage : Damage; |
| 38 | |
| 39 | UGameplayStatics::ApplyDamage( |
| 40 | BlasterCharacter, |
| 41 | DamageToCause, |
| 42 | InstigatorController, |
| 43 | this, |
| 44 | UDamageType::StaticClass() |
| 45 | ); |
| 46 | } |
| 47 | if (!HasAuthority() && bUseServerSideRewind) |
| 48 | { |
| 49 | BlasterOwnerCharacter = BlasterOwnerCharacter == nullptr ? Cast<ABlasterCharacter>(OwnerPawn) : BlasterOwnerCharacter; |
| 50 | BlasterOwnerController = BlasterOwnerController == nullptr ? Cast<ABlasterPlayerController>(InstigatorController) : BlasterOwnerController; |
| 51 | if (BlasterOwnerController && BlasterOwnerCharacter && BlasterOwnerCharacter->GetLagCompensation() && BlasterOwnerCharacter->IsLocallyControlled()) |
| 52 | { |
| 53 | BlasterOwnerCharacter->GetLagCompensation()->ServerScoreRequest( |
| 54 | BlasterCharacter, |
| 55 | Start, |
| 56 | HitTarget, |
| 57 | BlasterOwnerController->GetServerTime() - BlasterOwnerController->SingleTripTime |
| 58 | ); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | if (ImpactParticles) |
| 63 | { |
| 64 | UGameplayStatics::SpawnEmitterAtLocation( |
| 65 | GetWorld(), |
| 66 | ImpactParticles, |
| 67 | FireHit.ImpactPoint, |
| 68 | FireHit.ImpactNormal.Rotation() |
| 69 | ); |
| 70 | } |
| 71 | if (HitSound) |
nothing calls this directly
no test coverage detected