MCPcopy Create free account
hub / github.com/DruidMech/MultiplayerCourseBlasterGame / Fire

Method Fire

Source/Blaster/Weapon/HitScanWeapon.cpp:14–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12#include "Blaster/BlasterComponents/LagCompensationComponent.h"
13
14void 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)

Callers

nothing calls this directly

Calls 1

GetServerTimeMethod · 0.80

Tested by

no test coverage detected