Merge branch 'AI-n-Stuff' into dev

This commit is contained in:
Philip W 2024-04-10 16:21:34 +01:00
commit bb832fedd2
10 changed files with 175 additions and 82 deletions

Binary file not shown.

View File

@ -4,7 +4,6 @@
#include "AICharacter.h"
#include "Components/CapsuleComponent.h"
#include "Engine/DamageEvents.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "Perception/AIPerceptionStimuliSourceComponent.h"
#include "Perception/AISense_Sight.h"

View File

@ -55,7 +55,9 @@ void AAI_EnemyController::Tick(float DeltaTime)
Super::Tick(DeltaTime);
if (GetBlackboardComponent()->GetValueAsBool("CanSeePlayer"))
{
GetBlackboardComponent()->SetValueAsVector("TargetLocation", GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation());
GetBlackboardComponent()->SetValueAsVector("TargetLocation",
GetWorld()->GetFirstPlayerController()->GetPawn()->
GetActorLocation());
}
}
@ -71,14 +73,15 @@ void AAI_EnemyController::SetupPerceptionSystem()
SightConfig->SightRadius = 2000.0f;
SightConfig->LoseSightRadius = 2100.0f;
SightConfig->PeripheralVisionAngleDegrees = 70.0f;
SightConfig->SetMaxAge(20.0f);
SightConfig->AutoSuccessRangeFromLastSeenLocation = 520.0f;
SightConfig->SetMaxAge(5.0f);
SightConfig->AutoSuccessRangeFromLastSeenLocation = 100.0f;
SightConfig->DetectionByAffiliation.bDetectEnemies = true;
SightConfig->DetectionByAffiliation.bDetectFriendlies = true;
SightConfig->DetectionByAffiliation.bDetectNeutrals = true;
HearingConfig = CreateDefaultSubobject<UAISenseConfig_Hearing>(TEXT("Hearing Config"));
HearingConfig->HearingRange = 2000.0f;
HearingConfig->SetMaxAge(20.0f);
HearingConfig->DetectionByAffiliation.bDetectEnemies = true;
HearingConfig->DetectionByAffiliation.bDetectFriendlies = true;
HearingConfig->DetectionByAffiliation.bDetectNeutrals = true;
@ -88,7 +91,8 @@ void AAI_EnemyController::SetupPerceptionSystem()
SetPerceptionComponent(*CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("Perception Component")));
GetPerceptionComponent()->SetDominantSense(*SightConfig->GetSenseImplementation());
GetPerceptionComponent()->OnTargetPerceptionUpdated.AddDynamic(this, &AAI_EnemyController::OnTargetPerceptionUpdated);
GetPerceptionComponent()->OnTargetPerceptionUpdated.AddDynamic(
this, &AAI_EnemyController::OnTargetPerceptionUpdated);
GetPerceptionComponent()->ConfigureSense(*SightConfig);
GetPerceptionComponent()->ConfigureSense(*HearingConfig);
}
@ -102,6 +106,10 @@ void AAI_EnemyController::OnTargetPerceptionUpdated(AActor* Actor, FAIStimulus c
GetBlackboardComponent()->SetValueAsObject("TargetPlayer", Actor);
GetBlackboardComponent()->SetValueAsVector("TargetLocation", Stimulus.StimulusLocation);
GetBlackboardComponent()->SetValueAsBool("CanSeePlayer", true);
if (PlayerCharacter->CurrentOverlayState != EOverlayState::Default)
{
GetBlackboardComponent()->SetValueAsBool("IsHostile", true);
}
}
else if (!Stimulus.WasSuccessfullySensed() && Stimulus.Type == SightConfig->GetSenseID())
{
@ -116,5 +124,11 @@ void AAI_EnemyController::OnTargetPerceptionUpdated(AActor* Actor, FAIStimulus c
GetBlackboardComponent()->SetValueAsVector("InvestigationLocation", Stimulus.StimulusLocation);
GetBlackboardComponent()->SetValueAsBool("IsInvestigating", true);
}
else if (!Stimulus.WasSuccessfullySensed() && Stimulus.Type == HearingConfig->GetSenseID())
{
GetBlackboardComponent()->ClearValue("TargetPlayer");
GetBlackboardComponent()->ClearValue("InvestigationLocation");
GetBlackboardComponent()->SetValueAsBool("IsInvestigating", false);
}
}
}

View File

@ -30,6 +30,7 @@ AEndlessVendettaCharacter::AEndlessVendettaCharacter()
GetCharacterMovement()->GetNavAgentPropertiesRef().bCanCrouch = true;
// Set size for collision capsule
GetCapsuleComponent()->InitCapsuleSize(55.f, 96.0f);
CreateDefaultSubobject<UPawnNoiseEmitterComponent>(TEXT("PawnNoiseEmitter"));
}
void AEndlessVendettaCharacter::IncrementRestrictedBoundsCount()
@ -65,8 +66,9 @@ void AEndlessVendettaCharacter::ReloadAnimationComplete()
}
}
void AEndlessVendettaCharacter::SetOverlayState(const EOverlayState OverlayState) const
void AEndlessVendettaCharacter::SetOverlayState(const EOverlayState OverlayState)
{
CurrentOverlayState = OverlayState;
SetOverlayStateEvent.Broadcast(OverlayState);
}
@ -79,8 +81,14 @@ void AEndlessVendettaCharacter::BeginPlay()
{
// Call the base class
Super::BeginPlay();
FirstPersonArms = Cast<USkeletalMeshComponent>(GetComponentsByTag(USkeletalMeshComponent::StaticClass(), FName("FirstPersonArms"))[0]);
HeldWeapon = Cast<UChildActorComponent>(GetComponentsByTag(UChildActorComponent::StaticClass(), FName("Weapon"))[0]);
PawnNoiseEmitterComp = Cast<UPawnNoiseEmitterComponent>(
GetComponentByClass(UPawnNoiseEmitterComponent::StaticClass()));
FirstPersonArms = Cast<USkeletalMeshComponent>(
GetComponentsByTag(USkeletalMeshComponent::StaticClass(), FName("FirstPersonArms"))[0]);
HeldWeapon = Cast<
UChildActorComponent>(GetComponentsByTag(UChildActorComponent::StaticClass(), FName("Weapon"))[0]);
bIsCurrentlyHoldingWeapon = false;
UEVGameInstance* GI = Cast<UEVGameInstance>(GetWorld()->GetGameInstance());
@ -93,12 +101,14 @@ void AEndlessVendettaCharacter::BeginPlay()
//Add Input Mapping Context
if (APlayerController* PlayerController = Cast<APlayerController>(Controller))
{
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer()))
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<
UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer()))
{
Subsystem->AddMappingContext(DefaultMappingContext, 0);
}
}
AActor* GadgetManagerActor = GetWorld()->SpawnActor<AActor>(GadgetManagerClass, GetActorLocation(), GetActorRotation());
AActor* GadgetManagerActor = GetWorld()->SpawnActor<AActor>(GadgetManagerClass, GetActorLocation(),
GetActorRotation());
GadgetManager = Cast<AGadgetManager>(GadgetManagerActor);
FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
GadgetManagerActor->AttachToComponent(GetRootComponent(), AttachmentRules);
@ -168,7 +178,8 @@ void AEndlessVendettaCharacter::RegenHealth()
if (GetWorld()->GetTimerManager().GetTimerRate(RegenHealthTimerHandle) > 1.0f)
{
GetWorld()->GetTimerManager().ClearTimer(RegenHealthTimerHandle);
GetWorld()->GetTimerManager().SetTimer(RegenHealthTimerHandle, this, &AEndlessVendettaCharacter::RegenHealth, 1.0f, true);
GetWorld()->GetTimerManager().SetTimer(RegenHealthTimerHandle, this, &AEndlessVendettaCharacter::RegenHealth,
1.0f, true);
}
if (CurrentHealth >= MaxHealth) GetWorld()->GetTimerManager().ClearTimer(RegenHealthTimerHandle);
}
@ -215,37 +226,53 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent*
//Moving
// EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::Move);
EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::Sprint);
EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Completed, this, &AEndlessVendettaCharacter::StopSprint);
EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Started, this,
&AEndlessVendettaCharacter::Sprint);
EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Completed, this,
&AEndlessVendettaCharacter::StopSprint);
//Looking
// EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::Look);
// Gadget Toggling
EnhancedInputComponent->BindAction(ReconAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::ToggleRecon);
EnhancedInputComponent->BindAction(CombatAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::ToggleCombat);
EnhancedInputComponent->BindAction(ReconAction, ETriggerEvent::Started, this,
&AEndlessVendettaCharacter::ToggleRecon);
EnhancedInputComponent->BindAction(CombatAction, ETriggerEvent::Started, this,
&AEndlessVendettaCharacter::ToggleCombat);
//Weapon Switching
EnhancedInputComponent->BindAction(EquipPrimaryWeapon, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::EquipPrimary);
EnhancedInputComponent->BindAction(EquipSecondaryWeapon, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::EquipSecondary);
EnhancedInputComponent->BindAction(EquipPrimaryWeapon, ETriggerEvent::Triggered, this,
&AEndlessVendettaCharacter::EquipPrimary);
EnhancedInputComponent->BindAction(EquipSecondaryWeapon, ETriggerEvent::Triggered, this,
&AEndlessVendettaCharacter::EquipSecondary);
//Weapon Shooting
EnhancedInputComponent->BindAction(TapShootAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::FireCaller);
EnhancedInputComponent->BindAction(TapShootAction, ETriggerEvent::Completed, this, &AEndlessVendettaCharacter::StopFire);
EnhancedInputComponent->BindAction(GunAimInAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::GunRightClick);
EnhancedInputComponent->BindAction(GunAimInAction, ETriggerEvent::Completed, this, &AEndlessVendettaCharacter::StopGunRightClick);
EnhancedInputComponent->BindAction(TapShootAction, ETriggerEvent::Triggered, this,
&AEndlessVendettaCharacter::FireCaller);
EnhancedInputComponent->BindAction(TapShootAction, ETriggerEvent::Completed, this,
&AEndlessVendettaCharacter::StopFire);
EnhancedInputComponent->BindAction(GunAimInAction, ETriggerEvent::Triggered, this,
&AEndlessVendettaCharacter::GunRightClick);
EnhancedInputComponent->BindAction(GunAimInAction, ETriggerEvent::Completed, this,
&AEndlessVendettaCharacter::StopGunRightClick);
//Weapon Reloading
EnhancedInputComponent->BindAction(GunReloadAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::GunReload);
EnhancedInputComponent->BindAction(GunReloadAction, ETriggerEvent::Started, this,
&AEndlessVendettaCharacter::GunReload);
//Crouching
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::SetCrouch);
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Completed, this, &AEndlessVendettaCharacter::SetUnCrouch);
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Started, this,
&AEndlessVendettaCharacter::SetCrouch);
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Completed, this,
&AEndlessVendettaCharacter::SetUnCrouch);
//Interacting
EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::Interact);
EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::HoldInteract);
EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Canceled, this, &AEndlessVendettaCharacter::StoppedHoldingInteract);
EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Started, this,
&AEndlessVendettaCharacter::Interact);
EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Triggered, this,
&AEndlessVendettaCharacter::HoldInteract);
EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Canceled, this,
&AEndlessVendettaCharacter::StoppedHoldingInteract);
}
}
@ -256,7 +283,8 @@ void AEndlessVendettaCharacter::Interact()
if (InPauseMenu) return;
if (bIsInDialogue)
{
Cast<UAC_PlayerDialogueInterpreter>(GetComponentByClass(UAC_PlayerDialogueInterpreter::StaticClass()))->NextDialogue();
Cast<UAC_PlayerDialogueInterpreter>(GetComponentByClass(UAC_PlayerDialogueInterpreter::StaticClass()))->
NextDialogue();
return;
}
StartedHoldingInteract(1.f / HoldForInteractionDuration);
@ -301,7 +329,8 @@ void AEndlessVendettaCharacter::SetUnCrouch()
UnCrouch();
}
float AEndlessVendettaCharacter::TakeDamage(const float DamageAmount, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser)
float AEndlessVendettaCharacter::TakeDamage(const float DamageAmount, FDamageEvent const& DamageEvent,
AController* EventInstigator, AActor* DamageCauser)
{
CurrentHealth -= DamageAmount;
if (CurrentHealth <= 0)
@ -330,7 +359,8 @@ float AEndlessVendettaCharacter::TakeDamage(const float DamageAmount, FDamageEve
TookDamage.Broadcast();
GetWorld()->GetTimerManager().ClearTimer(RegenHealthTimerHandle);
GetWorld()->GetTimerManager().SetTimer(RegenHealthTimerHandle, this, &AEndlessVendettaCharacter::RegenHealth, 5.0f, true);
GetWorld()->GetTimerManager().SetTimer(RegenHealthTimerHandle, this, &AEndlessVendettaCharacter::RegenHealth, 5.0f,
true);
return Super::TakeDamage(DamageAmount, DamageEvent, EventInstigator, DamageCauser);
}
@ -351,7 +381,8 @@ void AEndlessVendettaCharacter::ToggleRecon()
return;
}
if (GadgetManager->IsValidCombatGadget() && GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat())
if (GadgetManager->IsValidCombatGadget() && GadgetManager->IsCombatEquipped() && !GadgetManager->
TryToUnequipCombat())
{
// Do nothing if combat is equipped and can't be unequipped at this moment
return;
@ -418,8 +449,11 @@ void AEndlessVendettaCharacter::EquipPrimary()
if (IsValid(SecondaryWeapon)) EquipSecondary();
if (GadgetManager->IsValidReconGadget() && GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return;
if (GadgetManager->IsValidCombatGadget() && GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return;
if (GadgetManager->IsValidReconGadget() && GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon())
return;
if (GadgetManager->IsValidCombatGadget() && GadgetManager->IsCombatEquipped() && !GadgetManager->
TryToUnequipCombat())
return;
//this code handles when you FIRST dont have any primary weapon
if (!IsValid(PrimaryWeapon))
@ -441,7 +475,7 @@ void AEndlessVendettaCharacter::EquipPrimary()
}
//For when you already have all your weapons and ur switching with 1 and 2 or when your picking up a weapon with a weapon in hand
if (PrimaryWeaponClass != nullptr)
{
{
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Green, TEXT("non ifstatement code running"));
PrimaryWeaponActor->AttachToComponent(FirstPersonArms, AttachmentRules, FName("GripPoint"));
PrimaryWeapon = Cast<ABaseWeaponClass>(PrimaryWeaponActor);
@ -482,8 +516,11 @@ void AEndlessVendettaCharacter::EquipSecondary()
if (IsValid(PrimaryWeapon)) EquipPrimary();
if (GadgetManager->IsValidReconGadget() && GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return;
if (GadgetManager->IsValidCombatGadget() && GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return;
if (GadgetManager->IsValidReconGadget() && GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon())
return;
if (GadgetManager->IsValidCombatGadget() && GadgetManager->IsCombatEquipped() && !GadgetManager->
TryToUnequipCombat())
return;
if (!IsValid(SecondaryWeapon))
{
@ -562,10 +599,13 @@ void AEndlessVendettaCharacter::WeaponSwitcher(AActor* Outhit)
{
if (bIsCurrentlyHoldingWeapon)
{
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Blue, TEXT("bIsCurrentlyHoldingSecondaryCalled, trying to spawn secondary weapon actor"));
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Blue,
TEXT(
"bIsCurrentlyHoldingSecondaryCalled, trying to spawn secondary weapon actor"));
SecondaryWeaponActor = GetWorld()->SpawnActor<AActor>(SecondaryWeaponClass, spawnParams);
}
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Orange, TEXT("EquipSecondarycalled skipped bIsCurrentlyHoldingWeapon check"));
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Orange,
TEXT("EquipSecondarycalled skipped bIsCurrentlyHoldingWeapon check"));
EquipSecondary();
}
bIsWeaponPickedUp = true;
@ -619,14 +659,16 @@ void AEndlessVendettaCharacter::GunRightClick()
bIsScoped = true;
PrimaryWeapon->WeaponScopedFire();
StartPrimaryWeaponADS();
this->GetFirstPersonCameraComponent()->SetFieldOfView(50); //change this number to a number you can change in editor eventually
this->GetFirstPersonCameraComponent()->SetFieldOfView(50);
//change this number to a number you can change in editor eventually
}
if (IsValid(SecondaryWeapon) && !bIsScoped)
{
bIsScoped = true;
SecondaryWeapon->WeaponScopedFire();
StartSecondaryWeaponADS();
this->GetFirstPersonCameraComponent()->SetFieldOfView(50); //change this number to a number you can change in editor eventually
this->GetFirstPersonCameraComponent()->SetFieldOfView(50);
//change this number to a number you can change in editor eventually
}
}
@ -771,8 +813,11 @@ bool AEndlessVendettaCharacter::GetHasRifle()
bool AEndlessVendettaCharacter::UpdateGadgetType(TSubclassOf<AGadgetBase> NewGadgetClass)
{
if (NewGadgetClass.GetDefaultObject()->IsA(AReconGadget::StaticClass()) && GadgetManager->ReconCantBeSwitchedOut()) return false;
if (NewGadgetClass.GetDefaultObject()->IsA(ACombatGadget::StaticClass()) && GadgetManager->CombatCantBeSwitchedOut()) return false;
if (NewGadgetClass.GetDefaultObject()->IsA(AReconGadget::StaticClass()) && GadgetManager->ReconCantBeSwitchedOut())
return false;
if (NewGadgetClass.GetDefaultObject()->IsA(ACombatGadget::StaticClass()) && GadgetManager->
CombatCantBeSwitchedOut())
return false;
for (UActorComponent* PlayersCamera : GetComponentsByTag(UCameraComponent::StaticClass(), FName("PlayersCamera")))
{
@ -804,8 +849,11 @@ void AEndlessVendettaCharacter::HoldInteract()
return;
}
if (GadgetManager->IsValidReconGadget() && GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return;
if (GadgetManager->IsValidCombatGadget() && GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return;
if (GadgetManager->IsValidReconGadget() && GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon())
return;
if (GadgetManager->IsValidCombatGadget() && GadgetManager->IsCombatEquipped() && !GadgetManager->
TryToUnequipCombat())
return;
FTransform TakeOffTransform = GetActorTransform();
FVector NewLoc = TakeOffTransform.GetLocation();
@ -822,7 +870,8 @@ void AEndlessVendettaCharacter::EnterShip(FTransform TakeoffLoc)
if (IsValid(SecondaryWeapon)) EquipSecondary();
FActorSpawnParameters SpawnParams;
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
SpaceShip = GetWorld()->SpawnActor<ASpaceShip>(SpaceShipClass, TakeoffLoc.GetLocation(), TakeoffLoc.Rotator(), SpawnParams);
SpaceShip = GetWorld()->SpawnActor<ASpaceShip>(SpaceShipClass, TakeoffLoc.GetLocation(), TakeoffLoc.Rotator(),
SpawnParams);
PlayerOnShip = true;
}

View File

@ -35,6 +35,7 @@ UCLASS(config=Game)
class AEndlessVendettaCharacter : public ACharacter
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintImplementableEvent)
void TempEquippedPrimary();
@ -105,6 +106,12 @@ private:
public:
AEndlessVendettaCharacter();
UPROPERTY(BlueprintReadOnly)
UPawnNoiseEmitterComponent* PawnNoiseEmitterComp;
UPROPERTY(BlueprintReadOnly)
EOverlayState CurrentOverlayState = EOverlayState::Default;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Stats")
float CurrentHealth = 100.0f;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats")
@ -168,7 +175,7 @@ public:
FSetOverlayState SetOverlayStateEvent;
UFUNCTION(BlueprintCallable, Category = "Weapon")
void SetOverlayState(EOverlayState OverlayState) const;
void SetOverlayState(EOverlayState OverlayState);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FRestrictedAreaStatusChangedSignature, bool, bIsInRestrictedAreaLmao);
@ -182,7 +189,7 @@ public:
FSuccessfulHitEvent SuccessfulHitEvent;
void SuccessfulHit(bool bIsHeadshot = false) const;
protected:
virtual void BeginPlay() override;
virtual void Tick(float DeltaTime) override;
@ -310,7 +317,8 @@ public:
UCameraComponent* GetFirstPersonCameraComponent() const { return FirstPersonCameraComponent; }
UFUNCTION(BlueprintCallable, Category = "Damage Control")
virtual float TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) override;
virtual float TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent, AController* EventInstigator,
AActor* DamageCauser) override;
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FTookDamage);

View File

@ -49,7 +49,8 @@ void ABaseWeaponClass::BeginPlay()
if (!IsValid(endlessVendettaChar)) return;
for (UActorComponent* actorComp : playerInWorld->GetComponentsByTag(UArrowComponent::StaticClass(), FName("GunStart")))
for (UActorComponent* actorComp : playerInWorld->GetComponentsByTag(UArrowComponent::StaticClass(),
FName("GunStart")))
{
GunStartArrow = Cast<UArrowComponent>(actorComp);
break;
@ -83,7 +84,8 @@ void ABaseWeaponClass::Tick(float DeltaTime)
// Recoil Handling ////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ABaseWeaponClass::GenerateRecoilVector()
{
float angle = FMath::RandRange(recoilMaxAngleLeft, -recoilMaxAngleRight); //randomg recoil vector angle between left and right
float angle = FMath::RandRange(recoilMaxAngleLeft, -recoilMaxAngleRight);
//randomg recoil vector angle between left and right
float recMag = recoilMagnitude * 252.f; //converting degrees to controller units
float tempMag = -FMath::RandRange(recMag * recoilMinMultiplier, recMag); // recoil magnitude
@ -131,11 +133,13 @@ void ABaseWeaponClass::nullSamples()
float ABaseWeaponClass::GetRecoilPitch(float Amp, float Time)
{
//Using the trapez method and we are getting the surface under the curve, each trapezoid consist of square and right triangle
float lower = recoilCurvez1 < Amp ? recoilCurvez1 : Amp; //get which point is common for both triangle and square of trapezoid
float lower = recoilCurvez1 < Amp ? recoilCurvez1 : Amp;
//get which point is common for both triangle and square of trapezoid
//lower point
float mult = (Time - recoilCurvet) * lower; //getting surface of square
mult += (Time - recoilCurvet) * (Amp - recoilCurvez1) / 2.0f; //getting and adding surface of triangle
return (recoilResultPitch * mult) / playerControllerRef->InputPitchScale_DEPRECATED; //calculating and return recoil force for current frame
return (recoilResultPitch * mult) / playerControllerRef->InputPitchScale_DEPRECATED;
//calculating and return recoil force for current frame
}
@ -176,16 +180,18 @@ void ABaseWeaponClass::CancelFire()
void ABaseWeaponClass::Fire()
{
if (currentAmmoCount <= 0)
{
UE_LOG(LogTemp, Display, TEXT("No ammo, Ammo count: %d"), currentAmmoCount);
ShowNeedReloadUI();
{
UE_LOG(LogTemp, Display, TEXT("No ammo, Ammo count: %d"), currentAmmoCount);
ShowNeedReloadUI();
return;
}
}
if (GetWorldTimerManager().IsTimerActive(timerHandle)) return;
//do damage fallof based off distance
UCameraComponent* CamComp = Cast<AEndlessVendettaCharacter>(GetWorld()->GetFirstPlayerController()->GetPawn())->GetFirstPersonCameraComponent();
traceStart = Cast<USkeletalMeshComponent>(GetComponentByClass(USkeletalMeshComponent::StaticClass()))->GetSocketLocation("Muzzle");
UCameraComponent* CamComp = Cast<AEndlessVendettaCharacter>(GetWorld()->GetFirstPlayerController()->GetPawn())->
GetFirstPersonCameraComponent();
traceStart = Cast<USkeletalMeshComponent>(GetComponentByClass(USkeletalMeshComponent::StaticClass()))->
GetSocketLocation("Muzzle");
traceEnd = CamComp->GetComponentLocation() + CamComp->GetForwardVector() * BulletDistance;
FCollisionObjectQueryParams ObjectQueryParams;
ObjectQueryParams.AddObjectTypesToQuery(ECC_Pawn);
@ -194,6 +200,7 @@ void ABaseWeaponClass::Fire()
GetWorld()->LineTraceSingleByObjectType(outHit, traceStart, traceEnd, ObjectQueryParams, collisionParams);
WeaponFired.Broadcast();
playerControllerRef->PlayerCameraManager->StartCameraShake(CameraShakeClass, 1);
endlessVendettaChar->PawnNoiseEmitterComp->MakeNoise(endlessVendettaChar, 1, traceStart);
currentAmmoCount -= 1;
GenerateRecoilVector();
ClickDetectionTimer();
@ -220,7 +227,8 @@ void ABaseWeaponClass::Fire()
{
endlessVendettaChar->SuccessfulHit();
}
Cast<AAICharacter>(outHit.GetActor())->TakeDamage(tempWeaponDamage, FPointDamageEvent(), GetWorld()->GetFirstPlayerController(), this);
Cast<AAICharacter>(outHit.GetActor())->TakeDamage(tempWeaponDamage, FPointDamageEvent(),
GetWorld()->GetFirstPlayerController(), this);
}
if (ATargetDummy* TargetDummy = Cast<ATargetDummy>(outHit.GetActor()))
{
@ -229,7 +237,6 @@ void ABaseWeaponClass::Fire()
}
}
HideNeedReloadUI();
}
void ABaseWeaponClass::WeaponScopedFire()
@ -286,7 +293,8 @@ void ABaseWeaponClass::SetupSilencerAttachment(UStaticMesh* SilencerMesh)
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT("SETTING UP SILENCER ATTACHMENTS"));
FTransform EmptyTransform;
USceneComponent* SilencerAttachmentClass = Cast<USceneComponent>(AddComponentByClass(USilencerAttachmentClass::StaticClass(), false, EmptyTransform, false));
USceneComponent* SilencerAttachmentClass = Cast<USceneComponent>(
AddComponentByClass(USilencerAttachmentClass::StaticClass(), false, EmptyTransform, false));
SilencerAttachmentClass->ComponentTags.Add(FName("AttachmentType"));
USkeletalMeshComponent* WeaponSkeletonMesh = FindComponentByClass<USkeletalMeshComponent>();
if (IsValid(SilencerAttachmentClass))
@ -294,16 +302,20 @@ void ABaseWeaponClass::SetupSilencerAttachment(UStaticMesh* SilencerMesh)
if (IsValid(WeaponSkeletonMesh))
{
//this handles giving the weapon the required component class/code
SilencerAttachmentClass->AttachToComponent(WeaponSkeletonMesh, FAttachmentTransformRules::SnapToTargetIncludingScale, FName(TEXT("SilencerMeshSocket")));
SilencerAttachmentClass->AttachToComponent(WeaponSkeletonMesh,
FAttachmentTransformRules::SnapToTargetIncludingScale,
FName(TEXT("SilencerMeshSocket")));
UE_LOG(LogTemp, Display, TEXT("All Attachment is valid"));
//this makes it showup in editor for better debugging
SilencerAttachmentClass->CreationMethod = EComponentCreationMethod::Instance;
SilencerAttachmentClass->RegisterComponent();
//below handles seeing the physical attachment you selected
UStaticMeshComponent* StaticMeshComp = NewObject<UStaticMeshComponent>(SilencerAttachmentClass, UStaticMeshComponent::StaticClass());
UStaticMeshComponent* StaticMeshComp = NewObject<UStaticMeshComponent>(
SilencerAttachmentClass, UStaticMeshComponent::StaticClass());
if (IsValid(StaticMeshComp))
{
StaticMeshComp->AttachToComponent(SilencerAttachmentClass, FAttachmentTransformRules::SnapToTargetIncludingScale);
StaticMeshComp->AttachToComponent(SilencerAttachmentClass,
FAttachmentTransformRules::SnapToTargetIncludingScale);
StaticMeshComp->SetStaticMesh(SilencerMesh);
StaticMeshComp->SetRelativeRotation(FRotator(0, 90, 0));
StaticMeshComp->SetCollisionEnabled(ECollisionEnabled::NoCollision);
@ -321,7 +333,8 @@ void ABaseWeaponClass::SetupExtendedMagAttachment(UStaticMesh* ExtendedMagMesh)
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT("SETTING UP EXTENDEDMAG ATTACHMENTS"));
FTransform EmptyTransform;
USceneComponent* ExtendedMagAttachmentClass = Cast<USceneComponent>(AddComponentByClass(UExtendedMagAttachmentClass::StaticClass(), false, EmptyTransform, false));
USceneComponent* ExtendedMagAttachmentClass = Cast<USceneComponent>(
AddComponentByClass(UExtendedMagAttachmentClass::StaticClass(), false, EmptyTransform, false));
ExtendedMagAttachmentClass->ComponentTags.Add(FName("AttachmentType"));
USkeletalMeshComponent* WeaponSkeletonMesh = FindComponentByClass<USkeletalMeshComponent>();
if (IsValid(ExtendedMagAttachmentClass))
@ -329,16 +342,20 @@ void ABaseWeaponClass::SetupExtendedMagAttachment(UStaticMesh* ExtendedMagMesh)
if (IsValid(WeaponSkeletonMesh))
{
//this handles giving the weapon the required component class/code
ExtendedMagAttachmentClass->AttachToComponent(WeaponSkeletonMesh, FAttachmentTransformRules::SnapToTargetIncludingScale, FName(TEXT("ExtendedMagSocket")));
ExtendedMagAttachmentClass->AttachToComponent(WeaponSkeletonMesh,
FAttachmentTransformRules::SnapToTargetIncludingScale,
FName(TEXT("ExtendedMagSocket")));
UE_LOG(LogTemp, Display, TEXT("All Attachment is valid"));
//this makes it showup in editor for better debugging
ExtendedMagAttachmentClass->CreationMethod = EComponentCreationMethod::Instance;
ExtendedMagAttachmentClass->RegisterComponent();
//below handles seeing the physical attachment you selected
UStaticMeshComponent* StaticMeshComp = NewObject<UStaticMeshComponent>(ExtendedMagAttachmentClass, UStaticMeshComponent::StaticClass());
UStaticMeshComponent* StaticMeshComp = NewObject<UStaticMeshComponent>(
ExtendedMagAttachmentClass, UStaticMeshComponent::StaticClass());
if (IsValid(StaticMeshComp))
{
StaticMeshComp->AttachToComponent(ExtendedMagAttachmentClass, FAttachmentTransformRules::SnapToTargetIncludingScale);
StaticMeshComp->AttachToComponent(ExtendedMagAttachmentClass,
FAttachmentTransformRules::SnapToTargetIncludingScale);
StaticMeshComp->SetStaticMesh(ExtendedMagMesh);
StaticMeshComp->SetRelativeRotation(FRotator(0, 180, 0));
StaticMeshComp->SetCollisionEnabled(ECollisionEnabled::NoCollision);
@ -356,7 +373,8 @@ void ABaseWeaponClass::SetupGripAttachment(UStaticMesh* GripMesh)
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT("SETTING UP GRIP ATTACHMENTS"));
FTransform EmptyTransform;
USceneComponent* GripAttachmentClass = Cast<USceneComponent>(AddComponentByClass(UGripAttachmentClass::StaticClass(), false, EmptyTransform, false));
USceneComponent* GripAttachmentClass = Cast<USceneComponent>(
AddComponentByClass(UGripAttachmentClass::StaticClass(), false, EmptyTransform, false));
GripAttachmentClass->ComponentTags.Add(FName("AttachmentType"));
USkeletalMeshComponent* WeaponSkeletonMesh = FindComponentByClass<USkeletalMeshComponent>();
if (IsValid(GripAttachmentClass))
@ -364,16 +382,20 @@ void ABaseWeaponClass::SetupGripAttachment(UStaticMesh* GripMesh)
if (IsValid(WeaponSkeletonMesh))
{
//this handles giving the weapon the required component class/code
GripAttachmentClass->AttachToComponent(WeaponSkeletonMesh, FAttachmentTransformRules::SnapToTargetIncludingScale, FName(TEXT("GripMeshSocket")));
GripAttachmentClass->AttachToComponent(WeaponSkeletonMesh,
FAttachmentTransformRules::SnapToTargetIncludingScale,
FName(TEXT("GripMeshSocket")));
UE_LOG(LogTemp, Display, TEXT("All Attachment is valid"));
//this makes it showup in editor for better debugging
GripAttachmentClass->CreationMethod = EComponentCreationMethod::Instance;
GripAttachmentClass->RegisterComponent();
//below handles seeing the physical attachment you selected
UStaticMeshComponent* StaticMeshComp = NewObject<UStaticMeshComponent>(GripAttachmentClass, UStaticMeshComponent::StaticClass());
UStaticMeshComponent* StaticMeshComp = NewObject<UStaticMeshComponent>(
GripAttachmentClass, UStaticMeshComponent::StaticClass());
if (IsValid(StaticMeshComp))
{
StaticMeshComp->AttachToComponent(GripAttachmentClass, FAttachmentTransformRules::SnapToTargetIncludingScale);
StaticMeshComp->AttachToComponent(GripAttachmentClass,
FAttachmentTransformRules::SnapToTargetIncludingScale);
StaticMeshComp->SetStaticMesh(GripMesh);
StaticMeshComp->SetRelativeRotation(FRotator(0, 0, 0));
StaticMeshComp->SetCollisionEnabled(ECollisionEnabled::NoCollision);
@ -387,5 +409,4 @@ void ABaseWeaponClass::SetupGripAttachment(UStaticMesh* GripMesh)
void ABaseWeaponClass::RemoveAllAttachments()
{
}

View File

@ -5,6 +5,7 @@
#include "CoreMinimal.h"
#include "WeaponItemClass.h"
#include "Components/ArrowComponent.h"
#include "Components/PawnNoiseEmitterComponent.h"
#include "Kismet/KismetMathLibrary.h"
#include "EndlessVendetta/InteractionInterface.h"
#include "Engine/EngineTypes.h"
@ -50,6 +51,7 @@ protected:
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
void ReloadTimer();
float currentPitch;
@ -184,7 +186,7 @@ public:
UFUNCTION(BlueprintCallable)
void RemoveAllAttachments();
//
UFUNCTION(BlueprintImplementableEvent)
void ShowReloadingWidget();