blaster/Source/Blaster/Weapon/ProjectileBullet.cpp

95 lines
3.2 KiB
C++
Raw Normal View History

2022-05-07 11:03:19 +00:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "ProjectileBullet.h"
2022-05-28 08:30:24 +00:00
#include "Blaster/Character/BlasterCharacter.h"
#include "Blaster/Components/LagCompensationComponent.h"
#include "Blaster/PlayerController/BlasterPlayerController.h"
2022-05-07 11:03:19 +00:00
#include "GameFramework/Character.h"
2022-05-19 09:10:41 +00:00
#include "GameFramework/ProjectileMovementComponent.h"
2022-05-07 11:03:19 +00:00
#include "Kismet/GameplayStatics.h"
2022-05-19 09:10:41 +00:00
AProjectileBullet::AProjectileBullet()
{
ProjectileMovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovementComponent"));
ProjectileMovementComponent->bRotationFollowsVelocity = true;
ProjectileMovementComponent->SetIsReplicated(true);
2022-05-27 20:37:59 +00:00
ProjectileMovementComponent->InitialSpeed = InitialSpeed;
ProjectileMovementComponent->MaxSpeed = InitialSpeed;
2022-05-19 09:10:41 +00:00
}
2022-05-27 20:52:03 +00:00
#if WITH_EDITOR
void AProjectileBullet::PostEditChangeProperty(FPropertyChangedEvent& Event)
{
Super::PostEditChangeProperty(Event);
const FName PropertyName = Event.Property != nullptr ? Event.Property->GetFName() : NAME_None;
if (PropertyName == GET_MEMBER_NAME_CHECKED(AProjectileBullet, InitialSpeed))
{
if (ProjectileMovementComponent)
{
ProjectileMovementComponent->InitialSpeed = InitialSpeed;
ProjectileMovementComponent->MaxSpeed = InitialSpeed;
}
}
}
#endif
2022-05-07 11:03:19 +00:00
void AProjectileBullet::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
2022-05-28 08:30:24 +00:00
ABlasterCharacter* OwnerCharacter = Cast<ABlasterCharacter>(GetOwner());
2022-05-07 11:03:19 +00:00
if (OwnerCharacter)
{
2022-05-28 08:30:24 +00:00
ABlasterPlayerController* OwnerController = Cast<ABlasterPlayerController>(OwnerCharacter->Controller);
2022-05-07 11:03:19 +00:00
if (OwnerController)
{
2022-05-28 08:30:24 +00:00
if (OwnerCharacter->HasAuthority() && !bUseServerSideRewind)
{
2022-05-29 12:35:57 +00:00
const float DamageToCause = Hit.BoneName.ToString() == FString("head") ? HeadShotDamage : Damage;
UGameplayStatics::ApplyDamage(OtherActor, DamageToCause, OwnerController, this, UDamageType::StaticClass());
2022-05-28 08:30:24 +00:00
Super::OnHit(HitComp, OtherActor, OtherComp, NormalImpulse, Hit);
return;
}
ABlasterCharacter* HitCharacter = Cast<ABlasterCharacter>(OtherActor);
if (bUseServerSideRewind && OwnerCharacter->GetLagCompensation() && OwnerCharacter->IsLocallyControlled() && HitCharacter)
{
OwnerCharacter->GetLagCompensation()->ProjectileServerScoreRequest(
HitCharacter,
TraceStart,
InitialVelocity,
OwnerController->GetServerTime() - OwnerController->SingleTripTime
);
}
2022-05-07 11:03:19 +00:00
}
}
Super::OnHit(HitComp, OtherActor, OtherComp, NormalImpulse, Hit);
}
2022-05-27 20:37:59 +00:00
void AProjectileBullet::BeginPlay()
{
Super::BeginPlay();
2022-05-27 22:28:02 +00:00
/*
2022-05-27 20:37:59 +00:00
FPredictProjectilePathParams PathParams;
PathParams.bTraceWithChannel = true;
PathParams.bTraceWithCollision = true;
PathParams.DrawDebugTime = 5.f;
PathParams.DrawDebugType = EDrawDebugTrace::ForDuration;
PathParams.LaunchVelocity = GetActorForwardVector() * InitialSpeed;
PathParams.MaxSimTime = 4.f;
PathParams.ProjectileRadius = 5.f;
PathParams.SimFrequency = 30.f;
PathParams.StartLocation = GetActorLocation();
PathParams.TraceChannel = ECollisionChannel::ECC_Visibility;
PathParams.ActorsToIgnore.Add(this);
FPredictProjectilePathResult PathResult;
2022-05-29 09:59:15 +00:00
2022-05-27 20:37:59 +00:00
UGameplayStatics::PredictProjectilePath(this, PathParams, PathResult);
2022-05-27 22:28:02 +00:00
*/
2022-05-27 20:37:59 +00:00
}