From 0901cc79737d7b144e83dfc4d2f5c6f1fa9237f9 Mon Sep 17 00:00:00 2001 From: PHILIP WHITE Date: Wed, 10 Apr 2024 15:36:17 +0100 Subject: [PATCH 1/2] Update AI to Be Hostile If Player is Holding a Weapon --- .../Source/EndlessVendetta/AI/AI_EnemyController.cpp | 4 ++++ .../Source/EndlessVendetta/EndlessVendettaCharacter.h | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/EndlessVendetta/Source/EndlessVendetta/AI/AI_EnemyController.cpp b/EndlessVendetta/Source/EndlessVendetta/AI/AI_EnemyController.cpp index 6d354168..8e248814 100644 --- a/EndlessVendetta/Source/EndlessVendetta/AI/AI_EnemyController.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/AI/AI_EnemyController.cpp @@ -102,6 +102,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()) { diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h index 04f7bd7d..33113e53 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h @@ -105,6 +105,8 @@ private: public: AEndlessVendettaCharacter(); + UPROPERTY(BlueprintReadOnly) + EOverlayState CurrentOverlayState = EOverlayState::Default; UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Stats") float CurrentHealth = 100.0f; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Stats") @@ -168,7 +170,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); From ab7127d52a0fc8d73d3067f64b5e9a314294f311 Mon Sep 17 00:00:00 2001 From: PHILIP WHITE Date: Wed, 10 Apr 2024 15:37:11 +0100 Subject: [PATCH 2/2] Update AI to Implement AI Sense Sound Emitting & Response --- .../AI/Enemy/Basic/BT_BasicEnemy.uasset | 4 +- .../AnimNotifys/Footstep_AnimNotify.uasset | 4 +- .../Blueprints/BP_MainCharacter.uasset | 4 +- .../C/ZX/8GZK30F02QUUO234VY329I.uasset | 2 +- .../Source/EndlessVendetta/AI/AICharacter.cpp | 1 - .../EndlessVendetta/AI/AI_EnemyController.cpp | 18 ++- .../EndlessVendettaCharacter.cpp | 129 ++++++++++++------ .../EndlessVendettaCharacter.h | 10 +- .../WeaponSystem/BaseWeaponClass.cpp | 73 ++++++---- .../WeaponSystem/BaseWeaponClass.h | 4 +- 10 files changed, 168 insertions(+), 81 deletions(-) diff --git a/EndlessVendetta/Content/AI/Enemy/Basic/BT_BasicEnemy.uasset b/EndlessVendetta/Content/AI/Enemy/Basic/BT_BasicEnemy.uasset index cdcb890d..60762ea3 100644 --- a/EndlessVendetta/Content/AI/Enemy/Basic/BT_BasicEnemy.uasset +++ b/EndlessVendetta/Content/AI/Enemy/Basic/BT_BasicEnemy.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0476e9712ee5e2767e2a60ae4bfdf21ca085b391c0215095f4981c8b785c07b1 -size 78165 +oid sha256:4f56cf78481c0fc10f209dd2c01ac7b71ae072415e08d1e355244f69fada4076 +size 83617 diff --git a/EndlessVendetta/Content/AdvancedLocomotionV4/Blueprints/AnimNotifys/Footstep_AnimNotify.uasset b/EndlessVendetta/Content/AdvancedLocomotionV4/Blueprints/AnimNotifys/Footstep_AnimNotify.uasset index cfbdfb0f..2bf153ee 100644 --- a/EndlessVendetta/Content/AdvancedLocomotionV4/Blueprints/AnimNotifys/Footstep_AnimNotify.uasset +++ b/EndlessVendetta/Content/AdvancedLocomotionV4/Blueprints/AnimNotifys/Footstep_AnimNotify.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c8030cc6b731fb1c3240e248191582d00b56f7311abc7425c50e581b600018bc -size 76768 +oid sha256:b7aed7c86e381b9a12e4547c04c7a3871525a024d004e58ae03737d824695501 +size 99167 diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_MainCharacter.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_MainCharacter.uasset index f71afd52..ef6ba360 100644 --- a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_MainCharacter.uasset +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_MainCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6a2be6fbc474306dff979b3f67151645475c6cadc6f3538c0b6ca673ed7f656a -size 1524063 +oid sha256:996444f59f21180ccbc392dd4dcb13c0336d74d5b5777901feb1c6a0e7981518 +size 1521696 diff --git a/EndlessVendetta/Content/__ExternalActors__/Levels/MovementTest/C/ZX/8GZK30F02QUUO234VY329I.uasset b/EndlessVendetta/Content/__ExternalActors__/Levels/MovementTest/C/ZX/8GZK30F02QUUO234VY329I.uasset index 77f61712..bafe0fae 100644 --- a/EndlessVendetta/Content/__ExternalActors__/Levels/MovementTest/C/ZX/8GZK30F02QUUO234VY329I.uasset +++ b/EndlessVendetta/Content/__ExternalActors__/Levels/MovementTest/C/ZX/8GZK30F02QUUO234VY329I.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:104af43d4801c8514455ec0cd4a2abf35fe76cb41c0c4268176e518963534429 +oid sha256:212620327497e7f328b680280ef08a2677468aca60ffbe8d64af7cd8acd8c3b7 size 8031 diff --git a/EndlessVendetta/Source/EndlessVendetta/AI/AICharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/AI/AICharacter.cpp index fb600020..be8f7e62 100644 --- a/EndlessVendetta/Source/EndlessVendetta/AI/AICharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/AI/AICharacter.cpp @@ -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" diff --git a/EndlessVendetta/Source/EndlessVendetta/AI/AI_EnemyController.cpp b/EndlessVendetta/Source/EndlessVendetta/AI/AI_EnemyController.cpp index 8e248814..5e89212f 100644 --- a/EndlessVendetta/Source/EndlessVendetta/AI/AI_EnemyController.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/AI/AI_EnemyController.cpp @@ -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(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(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); } @@ -120,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); + } } } diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index b7fd03dc..9e655970 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -30,6 +30,7 @@ AEndlessVendettaCharacter::AEndlessVendettaCharacter() GetCharacterMovement()->GetNavAgentPropertiesRef().bCanCrouch = true; // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(55.f, 96.0f); + CreateDefaultSubobject(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(GetComponentsByTag(USkeletalMeshComponent::StaticClass(), FName("FirstPersonArms"))[0]); - HeldWeapon = Cast(GetComponentsByTag(UChildActorComponent::StaticClass(), FName("Weapon"))[0]); + + PawnNoiseEmitterComp = Cast( + GetComponentByClass(UPawnNoiseEmitterComponent::StaticClass())); + + FirstPersonArms = Cast( + GetComponentsByTag(USkeletalMeshComponent::StaticClass(), FName("FirstPersonArms"))[0]); + HeldWeapon = Cast< + UChildActorComponent>(GetComponentsByTag(UChildActorComponent::StaticClass(), FName("Weapon"))[0]); bIsCurrentlyHoldingWeapon = false; UEVGameInstance* GI = Cast(GetWorld()->GetGameInstance()); @@ -93,12 +101,14 @@ void AEndlessVendettaCharacter::BeginPlay() //Add Input Mapping Context if (APlayerController* PlayerController = Cast(Controller)) { - if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(PlayerController->GetLocalPlayer())) + if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem< + UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer())) { Subsystem->AddMappingContext(DefaultMappingContext, 0); } } - AActor* GadgetManagerActor = GetWorld()->SpawnActor(GadgetManagerClass, GetActorLocation(), GetActorRotation()); + AActor* GadgetManagerActor = GetWorld()->SpawnActor(GadgetManagerClass, GetActorLocation(), + GetActorRotation()); GadgetManager = Cast(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(GetComponentByClass(UAC_PlayerDialogueInterpreter::StaticClass()))->NextDialogue(); + Cast(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(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(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 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(SpaceShipClass, TakeoffLoc.GetLocation(), TakeoffLoc.Rotator(), SpawnParams); + SpaceShip = GetWorld()->SpawnActor(SpaceShipClass, TakeoffLoc.GetLocation(), TakeoffLoc.Rotator(), + SpawnParams); PlayerOnShip = true; } diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h index 33113e53..1553a34d 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h @@ -35,6 +35,7 @@ UCLASS(config=Game) class AEndlessVendettaCharacter : public ACharacter { GENERATED_BODY() + public: UFUNCTION(BlueprintImplementableEvent) void TempEquippedPrimary(); @@ -105,8 +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") @@ -184,7 +189,7 @@ public: FSuccessfulHitEvent SuccessfulHitEvent; void SuccessfulHit(bool bIsHeadshot = false) const; - + protected: virtual void BeginPlay() override; virtual void Tick(float DeltaTime) override; @@ -312,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); diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp index 6fe6193b..d90949fc 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp @@ -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(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(GetWorld()->GetFirstPlayerController()->GetPawn())->GetFirstPersonCameraComponent(); - traceStart = Cast(GetComponentByClass(USkeletalMeshComponent::StaticClass()))->GetSocketLocation("Muzzle"); + UCameraComponent* CamComp = Cast(GetWorld()->GetFirstPlayerController()->GetPawn())-> + GetFirstPersonCameraComponent(); + traceStart = Cast(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(outHit.GetActor())->TakeDamage(tempWeaponDamage, FPointDamageEvent(), GetWorld()->GetFirstPlayerController(), this); + Cast(outHit.GetActor())->TakeDamage(tempWeaponDamage, FPointDamageEvent(), + GetWorld()->GetFirstPlayerController(), this); } if (ATargetDummy* TargetDummy = Cast(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(AddComponentByClass(USilencerAttachmentClass::StaticClass(), false, EmptyTransform, false)); + USceneComponent* SilencerAttachmentClass = Cast( + AddComponentByClass(USilencerAttachmentClass::StaticClass(), false, EmptyTransform, false)); SilencerAttachmentClass->ComponentTags.Add(FName("AttachmentType")); USkeletalMeshComponent* WeaponSkeletonMesh = FindComponentByClass(); 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(SilencerAttachmentClass, UStaticMeshComponent::StaticClass()); + UStaticMeshComponent* StaticMeshComp = NewObject( + 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(AddComponentByClass(UExtendedMagAttachmentClass::StaticClass(), false, EmptyTransform, false)); + USceneComponent* ExtendedMagAttachmentClass = Cast( + AddComponentByClass(UExtendedMagAttachmentClass::StaticClass(), false, EmptyTransform, false)); ExtendedMagAttachmentClass->ComponentTags.Add(FName("AttachmentType")); USkeletalMeshComponent* WeaponSkeletonMesh = FindComponentByClass(); 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(ExtendedMagAttachmentClass, UStaticMeshComponent::StaticClass()); + UStaticMeshComponent* StaticMeshComp = NewObject( + 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(AddComponentByClass(UGripAttachmentClass::StaticClass(), false, EmptyTransform, false)); + USceneComponent* GripAttachmentClass = Cast( + AddComponentByClass(UGripAttachmentClass::StaticClass(), false, EmptyTransform, false)); GripAttachmentClass->ComponentTags.Add(FName("AttachmentType")); USkeletalMeshComponent* WeaponSkeletonMesh = FindComponentByClass(); 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(GripAttachmentClass, UStaticMeshComponent::StaticClass()); + UStaticMeshComponent* StaticMeshComp = NewObject( + 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() { - } diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h index 2a67c1f6..583bb67a 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h @@ -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();