87 lines
2.7 KiB
C++
87 lines
2.7 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "ShotgunClass.h"
|
|
#include "EndlessVendetta/AI/EnemyCharacter.h"
|
|
#include "EndlessVendetta/BountySystem/ControlsTraining/TargetDummy.h"
|
|
#include "Engine/DamageEvents.h"
|
|
|
|
AShotgunClass::AShotgunClass()
|
|
{
|
|
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
ShotgunBulletSpread = FVector(10,10,10);
|
|
}
|
|
|
|
void AShotgunClass::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
}
|
|
|
|
void AShotgunClass::ClickDetectionTimer()
|
|
{
|
|
Super::ClickDetectionTimer();
|
|
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Magenta, TEXT("ClickDetectionTimer Activated"));
|
|
}
|
|
|
|
void AShotgunClass::Fire()
|
|
{
|
|
if(currentAmmoCount > 0 && !bSingleShotOnly)
|
|
{
|
|
bSingleShotOnly = true;
|
|
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Magenta, TEXT("Fire Activated"));
|
|
traceStart = GunStartArrow->GetComponentLocation();
|
|
if (GetWorldTimerManager().IsTimerActive(timerHandle)) return;
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
FVector newStartTrace = UKismetMathLibrary::RandomPointInBoundingBox(traceStart, ShotgunBulletSpread);
|
|
traceEnd = newStartTrace + (GunStartArrow->GetForwardVector() * BulletDistance);
|
|
GetWorld()->LineTraceSingleByChannel(outHit, newStartTrace, traceEnd, ECC_Visibility, collisionParams);
|
|
DrawDebugLine(this->GetWorld(), newStartTrace, traceEnd, FColor::Yellow , false, 500.2f, 0U, 0.2f);
|
|
if (outHit.bBlockingHit)
|
|
{
|
|
GEngine->AddOnScreenDebugMessage(-1, 20.f, FColor::Orange, FString(TEXT("SHOTGUN HIT")));
|
|
}
|
|
}
|
|
currentAmmoCount --;
|
|
playerControllerRef->PlayerCameraManager->StartCameraShake(CameraShakeClass, 1);
|
|
GenerateRecoilVector();
|
|
ClickDetectionTimer();
|
|
this->GetWorld()->GetTimerManager().SetTimer(ShotgunTimerHandle, this, &AShotgunClass::StopFire, FireRate, false);
|
|
bulletCountShoot += 1;
|
|
bStopShooting = false;
|
|
if (outHit.bBlockingHit)
|
|
{
|
|
if (outHit.Distance >= FMath::Floor(BulletDistance/2))
|
|
{
|
|
tempWeaponDamage = WeaponDamage / 2;
|
|
}
|
|
else
|
|
{
|
|
tempWeaponDamage = WeaponDamage;
|
|
}
|
|
if (ATargetDummy* TargetDummy = Cast<ATargetDummy>(outHit.GetActor())) TargetDummy->TargetShot();
|
|
if (!Cast<AAICharacter>(outHit.GetActor())) return;
|
|
Cast<AAICharacter>(outHit.GetActor())->TakeDamage(tempWeaponDamage, FPointDamageEvent(), GetWorld()->GetFirstPlayerController(), this);
|
|
}
|
|
HideNeedReloadUI();
|
|
}
|
|
else if(currentAmmoCount <= 0)
|
|
{
|
|
UE_LOG(LogTemp, Display, TEXT("No ammo, Ammo count: %d"), currentAmmoCount);
|
|
ShowNeedReloadUI();
|
|
}
|
|
}
|
|
|
|
void AShotgunClass::CancelFire()
|
|
{
|
|
Super::CancelFire();
|
|
}
|
|
|
|
void AShotgunClass::StopFire()
|
|
{
|
|
bSingleShotOnly = false;
|
|
}
|
|
|
|
|