diff --git a/.idea/.idea.AIStealthTask/.idea/vcs.xml b/.idea/.idea.AIStealthTask/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..9661ac713428efbad557d3ba3a62216b5bb7d226 --- /dev/null +++ b/.idea/.idea.AIStealthTask/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/AIStealthTask.uproject b/AIStealthTask.uproject index 5efea1ca706580219d4d1cbb62e68557081dd202..91f89550596dea5ec7b8855f685cea501b0e6c5d 100644 --- a/AIStealthTask.uproject +++ b/AIStealthTask.uproject @@ -10,7 +10,8 @@ "LoadingPhase": "Default", "AdditionalDependencies": [ "Engine", - "AIModule" + "AIModule", + "UMG" ] } ], diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index 46747b7e76638b721ce50922865dcdea6386a0cf..0c962be71e8344de750bac3ad9f77e68df5efc3c 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -1,7 +1,7 @@ [/Script/EngineSettings.GameMapsSettings] GameDefaultMap=/Game/ThirdPerson/Maps/ThirdPersonMap.ThirdPersonMap EditorStartupMap=/Game/ThirdPerson/Maps/ThirdPersonMap.ThirdPersonMap -GlobalDefaultGameMode="/Script/AIStealthTask.AIStealthTaskGameMode" +GlobalDefaultGameMode=/Game/Blueprints/NewGameMode.NewGameMode_C [/Script/Engine.RendererSettings] r.ReflectionMethod=1 @@ -72,6 +72,7 @@ ManualIPAddress= [CoreRedirects] +ClassRedirects=(OldName="/Script/AIStealthTask.AICharacter",NewName="/Script/AIStealthTask.STAICharacter") +ClassRedirects=(OldName="/Script/AIStealthTask.HealthAmmountBTDecorator",NewName="/Script/AIStealthTask.HealthAmountBTDecorator") ++ClassRedirects=(OldName="/Script/AIStealthTask.FindSoundService",NewName="/Script/AIStealthTask.DealDamageService") [/Script/Engine.PhysicsSettings] PhysicErrorCorrection=(PingExtrapolation=0.100000,PingLimit=100.000000,ErrorPerLinearDifference=1.000000,ErrorPerAngularDifference=1.000000,MaxRestoredStateError=1.000000,MaxLinearHardSnapDistance=400.000000,PositionLerp=0.000000,AngleLerp=0.400000,LinearVelocityCoefficient=100.000000,AngularVelocityCoefficient=10.000000,ErrorAccumulationSeconds=0.500000,ErrorAccumulationDistanceSq=15.000000,ErrorAccumulationSimilarity=100.000000) diff --git a/Config/DefaultInput.ini b/Config/DefaultInput.ini index 7ad02ceeb85b79cceb24c4fe9be626d4a60abf64..abfa4745034da726ea528d993265c22d3674ee0d 100644 --- a/Config/DefaultInput.ini +++ b/Config/DefaultInput.ini @@ -70,6 +70,7 @@ bEnableLegacyInputScales=True bEnableMotionControls=True bFilterInputByPlatformUser=False bShouldFlushPressedKeysOnViewportFocusLost=True +bEnableDynamicComponentInputBinding=True bAlwaysShowTouchInterface=False bShowConsoleOnFourFingerTap=True bEnableGestureRecognizer=False @@ -78,6 +79,7 @@ DefaultViewportMouseCaptureMode=CapturePermanently_IncludingInitialMouseDown DefaultViewportMouseLockMode=LockOnCapture FOVScale=0.011110 DoubleClickTime=0.200000 ++ActionMappings=(ActionName="Interact",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=E) DefaultPlayerInputClass=/Script/EnhancedInput.EnhancedPlayerInput DefaultInputComponentClass=/Script/EnhancedInput.EnhancedInputComponent DefaultTouchInterface=/Engine/MobileResources/HUD/DefaultVirtualJoysticks.DefaultVirtualJoysticks diff --git a/Content/AI/AIBehaviorTree.uasset b/Content/AI/AIBehaviorTree.uasset index ffa125cf813a620871f10b10f97f53b2e2978c89..ee4acad54ef2a617f3916982b80a62042597397b 100644 --- a/Content/AI/AIBehaviorTree.uasset +++ b/Content/AI/AIBehaviorTree.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fa708c90bb613592290124606b5ab603d02e84631617906aab4e0271c3544af2 -size 9894 +oid sha256:cc2ce60f5b7cf342c1ebe484b7a29b43767495f1c3281a932a1e888971c82d20 +size 25655 diff --git a/Content/AI/AIBlackBoard.uasset b/Content/AI/AIBlackBoard.uasset index 7762ee77ad56a6cb935ead79b9fd165811c03d7a..2179a2933b79dd59a55c90dd2a5e9b64d7480173 100644 --- a/Content/AI/AIBlackBoard.uasset +++ b/Content/AI/AIBlackBoard.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:938df064993b70558d9ab2328ef7e826c4d8a5c7c3d5b869dbd415707f485616 -size 2847 +oid sha256:97916530818a4d79f9444a1d64700cc8277f56cd612d1e53aa541a0e1927771f +size 3143 diff --git a/Content/AI/EQS_ContextCharacter.uasset b/Content/AI/EQS_ContextCharacter.uasset new file mode 100644 index 0000000000000000000000000000000000000000..510da541fe10dfe14e623b3935aab866060e691e --- /dev/null +++ b/Content/AI/EQS_ContextCharacter.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9aa9de284230c1f2d9c0d66eba001cd8f51241cc35f5675f78592d0e4c32c23e +size 23084 diff --git a/Content/AI/NearEnemyEQS.uasset b/Content/AI/NearEnemyEQS.uasset new file mode 100644 index 0000000000000000000000000000000000000000..856772f7918ff8c7f59fc541c63be57521a1145b --- /dev/null +++ b/Content/AI/NearEnemyEQS.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:077d025cfe7b50334eb45b674be46d6f2c1c967dc84527229fc4380d57776867 +size 6201 diff --git a/Content/AI/NearSoundEQS.uasset b/Content/AI/NearSoundEQS.uasset new file mode 100644 index 0000000000000000000000000000000000000000..307334a976ef79fe0aa943663aa18b1648edfe26 --- /dev/null +++ b/Content/AI/NearSoundEQS.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fdbb4ed61bd3a53a540a1be6fff43c94a79c013b005ba44a8a7f50dadd940dca +size 6044 diff --git a/Content/AI/TestPawnBlueprint.uasset b/Content/AI/TestPawnBlueprint.uasset index a75745a9bb61b09ffd26e88a5f5ef0f2474f56e0..55993a7f64c0587be65fa5b6c1afa755bce23e72 100644 --- a/Content/AI/TestPawnBlueprint.uasset +++ b/Content/AI/TestPawnBlueprint.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2eb0a9d200ba7910bc271d3733a6db44d42f5ad25ec8b54c59b2b77f344dacda -size 22638 +oid sha256:2df99ef36272dd0668774288d733255d15e8922c56d8af748e3680808b14eb41 +size 23121 diff --git a/Content/Blueprints/NewGameMode.uasset b/Content/Blueprints/NewGameMode.uasset new file mode 100644 index 0000000000000000000000000000000000000000..346588ba4bc172f212df29d1724e38c5fc5034b1 --- /dev/null +++ b/Content/Blueprints/NewGameMode.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d1ea9a3afbe1c25b59c3996a296887e246759a3590f5dedf48208b6a5ca8aa99 +size 18992 diff --git a/Content/Blueprints/NewHUD.uasset b/Content/Blueprints/NewHUD.uasset new file mode 100644 index 0000000000000000000000000000000000000000..43f9854bcf76fdfaca36deecf9286502f25e3890 --- /dev/null +++ b/Content/Blueprints/NewHUD.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:47b6872218a54fc9a35ac8e5037713a5db3b2aac058777c5dcce1cb640839ff6 +size 30407 diff --git a/Content/ThirdPerson/Blueprints/EnemyCharacter.uasset b/Content/ThirdPerson/Blueprints/EnemyCharacter.uasset index 9f8b05b83bd05a3fd8572d7b6376de257718c960..a5b5649de60d44486de4c30b19fd5ff7df029599 100644 --- a/Content/ThirdPerson/Blueprints/EnemyCharacter.uasset +++ b/Content/ThirdPerson/Blueprints/EnemyCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d48ce4784b160aa4b97e1be5379795905130b9783fc583e2f25af7669fed863a -size 34811 +oid sha256:6c697a30c4023598ebfdb2ff2b6dd71ac16257d100dce7ebc6c555b61eca9b2e +size 35353 diff --git a/Content/Triggers/MyActivateAIButtonTrigger.uasset b/Content/Triggers/MyActivateAIButtonTrigger.uasset new file mode 100644 index 0000000000000000000000000000000000000000..9ceacd7d2d892dc736f9a9a47f8ffaea948190d7 --- /dev/null +++ b/Content/Triggers/MyActivateAIButtonTrigger.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca186a50739ca5e4d6a35beec92ac3c5c2d8433ecbbea90a38d2ce2223398b6b +size 28977 diff --git a/Content/UI/WBP_PlayerHealth.uasset b/Content/UI/WBP_PlayerHealth.uasset new file mode 100644 index 0000000000000000000000000000000000000000..025cf7fb2faebf5ccebe0857a789e196e38d3425 --- /dev/null +++ b/Content/UI/WBP_PlayerHealth.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:73879918b5353c6c0752db50943be44776719626570c22e5e54423cb9dd5956e +size 35045 diff --git a/Content/UI/WBP_SwitchAI.uasset b/Content/UI/WBP_SwitchAI.uasset new file mode 100644 index 0000000000000000000000000000000000000000..3b7ab2a971f1f4882a575ede3ccd4fac5f94c8d8 --- /dev/null +++ b/Content/UI/WBP_SwitchAI.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e6740eab2c7bd0bd5e235073399d96aec4ffb4b1bfcf13305b26ed71ce97156 +size 25282 diff --git a/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/E/66/G11OMD30DUB0PBH5PHAYH6.uasset b/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/E/66/G11OMD30DUB0PBH5PHAYH6.uasset new file mode 100644 index 0000000000000000000000000000000000000000..25c67fdac2d7f978ccc88c2d84704ce153dcafaa --- /dev/null +++ b/Content/__ExternalActors__/ThirdPerson/Maps/ThirdPersonMap/E/66/G11OMD30DUB0PBH5PHAYH6.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:12536ce038413369ebe68885dca3b7c6dfc1fb4214cc412e74ae51fb1cadc945 +size 5228 diff --git a/Source/AIStealthTask/Private/AI/BaseAICharacter.cpp b/Source/AIStealthTask/Private/AI/BaseAICharacter.cpp index 233643792f1da3a77ca16456358b7e8761d81599..fe484422246935d33ea342a0a85972d8a78e6ddb 100644 --- a/Source/AIStealthTask/Private/AI/BaseAICharacter.cpp +++ b/Source/AIStealthTask/Private/AI/BaseAICharacter.cpp @@ -11,6 +11,7 @@ ABaseAICharacter::ABaseAICharacter() // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; WalkSoundComponent=CreateDefaultSubobject<UWalkSoundComponent>("WalkSoundComponent"); + HealthComponent=CreateDefaultSubobject<UHealthComponent>("HealthComponent"); } // Called when the game starts or when spawned diff --git a/Source/AIStealthTask/Private/AI/STAICharacter.cpp b/Source/AIStealthTask/Private/AI/STAICharacter.cpp index ed3cd29f663812712b6da10823133eba29bafc22..8cb61151ae8ce305a653f624bb39760367f39a89 100644 --- a/Source/AIStealthTask/Private/AI/STAICharacter.cpp +++ b/Source/AIStealthTask/Private/AI/STAICharacter.cpp @@ -23,7 +23,7 @@ ASTAICharacter::ASTAICharacter(const FObjectInitializer& ObjInit) GetCharacterMovement()->MaxWalkSpeed = 500.f; GetCharacterMovement()->MinAnalogWalkSpeed = 20.f; GetCharacterMovement()->BrakingDecelerationWalking = 2000.f; - + StateSignComponent=CreateDefaultSubobject<UAIStateSignComponent>("StateSignComponent"); } void ASTAICharacter::Tick(float DeltaTime) diff --git a/Source/AIStealthTask/Private/AI/Services/DealDamageService.cpp b/Source/AIStealthTask/Private/AI/Services/DealDamageService.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b1d7430fc9731a89afd9cf0b24c3efd412708fa4 --- /dev/null +++ b/Source/AIStealthTask/Private/AI/Services/DealDamageService.cpp @@ -0,0 +1,45 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "AI/Services/DealDamageService.h" + +#include "AIController.h" +#include "StealthTestAIPerceptionComponent.h" +#include "AIStealthTask/AIStealthTaskCharacter.h" +#include "BehaviorTree/BlackboardComponent.h" +#include "Engine/DamageEvents.h" + + +UDealDamageService::UDealDamageService() +{ + +} + +void UDealDamageService::TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds) +{ + if(const auto Blackboard=OwnerComp.GetBlackboardComponent()) + { + const FVector TraceStart=OwnerComp.GetOwner()->GetActorLocation(); + const FVector TraceEnd=Cast<AActor>(Blackboard->GetValueAsObject("EnemyActor"))->GetActorLocation(); + if(FVector::Distance(TraceStart,TraceEnd)<300.0f){ + FCollisionQueryParams CollisionParams; + CollisionParams.AddIgnoredActor(OwnerComp.GetOwner()); + FHitResult HitResult; + GetWorld()->LineTraceSingleByChannel(HitResult,TraceStart,TraceEnd,ECollisionChannel::ECC_Visibility,CollisionParams); + + DrawDebugLine(GetWorld(),TraceStart,TraceEnd,FColor::Red,false,3.0f,0,3.0f); + + if(HitResult.bBlockingHit) + { + const auto Player=Cast<AAIStealthTaskCharacter>(HitResult.GetActor()); + if(Player) + { + FPointDamageEvent PointDamageEvent; + Player->TakeDamage(25.0f,PointDamageEvent,Cast<AController>(OwnerComp.GetOwner()),OwnerComp.GetOwner()); + + } + } + } + } + Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds); +} diff --git a/Source/AIStealthTask/Private/AI/Services/FindEnemyService.cpp b/Source/AIStealthTask/Private/AI/Services/FindEnemyService.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ae06e958b94d83f5963165340df592689a8ae12f --- /dev/null +++ b/Source/AIStealthTask/Private/AI/Services/FindEnemyService.cpp @@ -0,0 +1,30 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "AI/Services/FindEnemyService.h" + +#include "AIController.h" +#include "StealthTestAIPerceptionComponent.h" +#include "BehaviorTree/BlackboardComponent.h" + +UFindEnemyService::UFindEnemyService() +{ + NodeName = "Find Enemy"; +} + +void UFindEnemyService::TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds) +{ + if(const auto Blackboard=OwnerComp.GetBlackboardComponent()) + { + const auto Controller=OwnerComp.GetAIOwner(); + const auto PerceptionComponent=Cast<UStealthTestAIPerceptionComponent>(Controller->GetComponentByClass(UStealthTestAIPerceptionComponent::StaticClass())); + if(PerceptionComponent) + { + Blackboard->SetValueAsObject(EnemyActorKey.SelectedKeyName,PerceptionComponent->GetClosestEnemy()); + + Blackboard->SetValueAsObject(SoundSourceKey.SelectedKeyName,PerceptionComponent->GetClosestSound()); + //GLog->Log(Blackboard->GetValueAsName("EnemyActor").ToString()); + } + } + Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds); +} diff --git a/Source/AIStealthTask/Private/AI/ShootService.cpp b/Source/AIStealthTask/Private/AI/ShootService.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7093f7339f3e14c34fb655d0dca6c3315d3751cd --- /dev/null +++ b/Source/AIStealthTask/Private/AI/ShootService.cpp @@ -0,0 +1,5 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "AI/ShootService.h" + diff --git a/Source/AIStealthTask/Private/AI/Tasks/ChangeAIStateTask.cpp b/Source/AIStealthTask/Private/AI/Tasks/ChangeAIStateTask.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b83e8976a8a6317a9b049dab1ccd507cb7278a86 --- /dev/null +++ b/Source/AIStealthTask/Private/AI/Tasks/ChangeAIStateTask.cpp @@ -0,0 +1,21 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "AI/Tasks/ChangeAIStateTask.h" + +#include "AIStateSignComponent.h" + +UChangeAIStateTask::UChangeAIStateTask() +{ + NodeName="ChangeAIState"; +} + +EBTNodeResult::Type UChangeAIStateTask::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) +{ + const auto StateComponent=Cast<UAIStateSignComponent>(OwnerComp.GetOwner()->GetComponentByClass(UAIStateSignComponent::StaticClass())); + if(StateComponent) + { + StateComponent->SetAIState(AIState); + } + return Super::ExecuteTask(OwnerComp, NodeMemory); +} diff --git a/Source/AIStealthTask/Private/AI/Tasks/FireInEnemyTask.cpp b/Source/AIStealthTask/Private/AI/Tasks/FireInEnemyTask.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dd3c814917d3e27af11b1b1cc15ecdf66bac5124 --- /dev/null +++ b/Source/AIStealthTask/Private/AI/Tasks/FireInEnemyTask.cpp @@ -0,0 +1,41 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "AI/Tasks/FireInEnemyTask.h" + +#include "AIStealthTask/AIStealthTaskCharacter.h" +#include "BehaviorTree/BlackboardComponent.h" +#include "Engine/DamageEvents.h" + +UFireInEnemyTask::UFireInEnemyTask() +{ +} + +EBTNodeResult::Type UFireInEnemyTask::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) +{ + if(const auto Blackboard=OwnerComp.GetBlackboardComponent()) + { + const FVector TraceStart=OwnerComp.GetOwner()->GetActorLocation(); + const FVector TraceEnd=Cast<AActor>(Blackboard->GetValueAsObject("EnemyActor"))->GetActorLocation(); + if(FVector::Distance(TraceStart,TraceEnd)<350.0f){ + FCollisionQueryParams CollisionParams; + CollisionParams.AddIgnoredActor(OwnerComp.GetOwner()); + FHitResult HitResult; + GetWorld()->LineTraceSingleByChannel(HitResult,TraceStart,TraceEnd,ECollisionChannel::ECC_Visibility,CollisionParams); + + DrawDebugLine(GetWorld(),TraceStart,TraceEnd,FColor::Red,false,3.0f,0,3.0f); + + if(HitResult.bBlockingHit) + { + const auto Player=Cast<AAIStealthTaskCharacter>(HitResult.GetActor()); + if(Player) + { + FPointDamageEvent PointDamageEvent; + Player->TakeDamage(25.0f,PointDamageEvent,Cast<AController>(OwnerComp.GetOwner()),OwnerComp.GetOwner()); + + } + } + } + } + return Super::ExecuteTask(OwnerComp, NodeMemory); +} diff --git a/Source/AIStealthTask/Private/AITaskGameMode.cpp b/Source/AIStealthTask/Private/AITaskGameMode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4d94df72b38e78dc1c3ddcdd37b0bb15dc742ee5 --- /dev/null +++ b/Source/AIStealthTask/Private/AITaskGameMode.cpp @@ -0,0 +1,5 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "AITaskGameMode.h" + diff --git a/Source/AIStealthTask/Private/ActivateAIButtonTrigger.cpp b/Source/AIStealthTask/Private/ActivateAIButtonTrigger.cpp index 5f68a97eaaaaaa7212a31862d218412c7839b5f5..1f6ee4b13078aac87937c432e389142480bb3ad2 100644 --- a/Source/AIStealthTask/Private/ActivateAIButtonTrigger.cpp +++ b/Source/AIStealthTask/Private/ActivateAIButtonTrigger.cpp @@ -3,18 +3,63 @@ #include "ActivateAIButtonTrigger.h" +#include "BrainComponent.h" +#include "MyAIController.h" +#include "UnrealWidgetFwd.h" +#include "AIStealthTask/AIStealthTaskCharacter.h" +#include "Blueprint/UserWidget.h" +#include "Components/SphereComponent.h" +#include "Kismet/GameplayStatics.h" + // Sets default values AActivateAIButtonTrigger::AActivateAIButtonTrigger() { // 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; - + SphereComponent=CreateDefaultSubobject<USphereComponent>("TipTrigger"); + SphereComponent->OnComponentBeginOverlap.AddDynamic(this,&AActivateAIButtonTrigger::OnSphereComponentCollision); + SphereComponent->OnComponentEndOverlap.AddDynamic(this,&AActivateAIButtonTrigger::OnOverlapEnd); } // Called when the game starts or when spawned void AActivateAIButtonTrigger::BeginPlay() { Super::BeginPlay(); + InputComponent=NewObject<UInputComponent>(this); + InputComponent->RegisterComponent(); + if(InputComponent) + { + EnableInput(GetWorld()->GetFirstPlayerController()); + } +} + +void AActivateAIButtonTrigger::OnButtonBeenPress() +{ + TArray<AActor*> AIs; + UGameplayStatics::GetAllActorsOfClass(GetWorld(),AMyAIController::StaticClass(),AIs); + + if(!AIWorking) + { + AIWorking=true; + GLog->Log("AI Enabled"); + + for(auto bot :AIs) + { + + Cast<AMyAIController>(bot)->BrainComponent->StopLogic("Stopped"); + } + } + else + { + AIWorking=false; + GLog->Log("AI Disabled"); + for(auto bot :AIs) + { + + Cast<AMyAIController>(bot)->BrainComponent->StartLogic(); + } + } + Widget->ChangeCurrentMode(); } @@ -25,3 +70,40 @@ void AActivateAIButtonTrigger::Tick(float DeltaTime) } +void AActivateAIButtonTrigger::OnSphereComponentCollision(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) +{ + auto Player=Cast<AAIStealthTaskCharacter>(OtherActor); + if(!Player|| !TipWidget) return; + Widget=CreateWidget<UTurnOnOffAIWidget>(GetWorld(),TipWidget); + if(Widget) + { + if(AIWorking) + { + Widget->ChangeCurrentMode(); + } + Widget->AddToViewport(); + + } + InputComponent->ClearActionBindings(); + + InputComponent->BindAction("Interact",IE_Pressed,this,&AActivateAIButtonTrigger::OnButtonBeenPress); +} + +void AActivateAIButtonTrigger::OnOverlapEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) +{ + GLog->Log("OverlapEnded"); + auto PlayerCharacter=Cast<AAIStealthTaskCharacter>(OtherActor); + if(PlayerCharacter) + { + GLog->Log("Remowing"); + if(Widget) + { + Widget->RemoveFromParent(); + } + Widget=nullptr; + InputComponent->ClearActionBindings(); + } +} + diff --git a/Source/AIStealthTask/Private/ActivateAIButtonTrigger.cpp~ b/Source/AIStealthTask/Private/ActivateAIButtonTrigger.cpp~ new file mode 100644 index 0000000000000000000000000000000000000000..1f6ee4b13078aac87937c432e389142480bb3ad2 --- /dev/null +++ b/Source/AIStealthTask/Private/ActivateAIButtonTrigger.cpp~ @@ -0,0 +1,109 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "ActivateAIButtonTrigger.h" + +#include "BrainComponent.h" +#include "MyAIController.h" +#include "UnrealWidgetFwd.h" +#include "AIStealthTask/AIStealthTaskCharacter.h" +#include "Blueprint/UserWidget.h" +#include "Components/SphereComponent.h" +#include "Kismet/GameplayStatics.h" + +// Sets default values +AActivateAIButtonTrigger::AActivateAIButtonTrigger() +{ + // 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; + SphereComponent=CreateDefaultSubobject<USphereComponent>("TipTrigger"); + SphereComponent->OnComponentBeginOverlap.AddDynamic(this,&AActivateAIButtonTrigger::OnSphereComponentCollision); + SphereComponent->OnComponentEndOverlap.AddDynamic(this,&AActivateAIButtonTrigger::OnOverlapEnd); +} + +// Called when the game starts or when spawned +void AActivateAIButtonTrigger::BeginPlay() +{ + Super::BeginPlay(); + InputComponent=NewObject<UInputComponent>(this); + InputComponent->RegisterComponent(); + if(InputComponent) + { + EnableInput(GetWorld()->GetFirstPlayerController()); + } +} + +void AActivateAIButtonTrigger::OnButtonBeenPress() +{ + TArray<AActor*> AIs; + UGameplayStatics::GetAllActorsOfClass(GetWorld(),AMyAIController::StaticClass(),AIs); + + if(!AIWorking) + { + AIWorking=true; + GLog->Log("AI Enabled"); + + for(auto bot :AIs) + { + + Cast<AMyAIController>(bot)->BrainComponent->StopLogic("Stopped"); + } + } + else + { + AIWorking=false; + GLog->Log("AI Disabled"); + for(auto bot :AIs) + { + + Cast<AMyAIController>(bot)->BrainComponent->StartLogic(); + } + } + Widget->ChangeCurrentMode(); + +} + +// Called every frame +void AActivateAIButtonTrigger::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + +} + +void AActivateAIButtonTrigger::OnSphereComponentCollision(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) +{ + auto Player=Cast<AAIStealthTaskCharacter>(OtherActor); + if(!Player|| !TipWidget) return; + Widget=CreateWidget<UTurnOnOffAIWidget>(GetWorld(),TipWidget); + if(Widget) + { + if(AIWorking) + { + Widget->ChangeCurrentMode(); + } + Widget->AddToViewport(); + + } + InputComponent->ClearActionBindings(); + + InputComponent->BindAction("Interact",IE_Pressed,this,&AActivateAIButtonTrigger::OnButtonBeenPress); +} + +void AActivateAIButtonTrigger::OnOverlapEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) +{ + GLog->Log("OverlapEnded"); + auto PlayerCharacter=Cast<AAIStealthTaskCharacter>(OtherActor); + if(PlayerCharacter) + { + GLog->Log("Remowing"); + if(Widget) + { + Widget->RemoveFromParent(); + } + Widget=nullptr; + InputComponent->ClearActionBindings(); + } +} + diff --git a/Source/AIStealthTask/Private/Components/AIStateSignComponent.cpp b/Source/AIStealthTask/Private/Components/AIStateSignComponent.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5f210a82b175c788fe1227a1123ed1df87734e76 --- /dev/null +++ b/Source/AIStealthTask/Private/Components/AIStateSignComponent.cpp @@ -0,0 +1,43 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Components/AIStateSignComponent.h" + +// Sets default values for this component's properties +UAIStateSignComponent::UAIStateSignComponent() +{ + // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features + // off to improve performance if you don't need them. + PrimaryComponentTick.bCanEverTick = true; + CurrentMeshComponent=CreateDefaultSubobject<UStaticMeshComponent>(TEXT("SignMesh")); + // ... +} + + +// Called when the game starts +void UAIStateSignComponent::BeginPlay() +{ + Super::BeginPlay(); + + // ... + +} + + +// Called every frame +void UAIStateSignComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + // ... +} + +void UAIStateSignComponent::SetAIState(TEnumAsByte<EAIStates> newState) +{ + CurrentState=newState; + if(StateSigns.Contains(CurrentState)) + { + CurrentMeshComponent = StateSigns[CurrentState]; + } +} + diff --git a/Source/AIStealthTask/Private/Components/StealthTestAIPerceptionComponent.cpp b/Source/AIStealthTask/Private/Components/StealthTestAIPerceptionComponent.cpp index febfd55bf5a13671766ec5c678f3d37c11cd2398..3b5f9b871d69acdc65a356fed46e10deb825fa81 100644 --- a/Source/AIStealthTask/Private/Components/StealthTestAIPerceptionComponent.cpp +++ b/Source/AIStealthTask/Private/Components/StealthTestAIPerceptionComponent.cpp @@ -3,16 +3,20 @@ #include "Components/StealthTestAIPerceptionComponent.h" +#include <string> + #include "AIController.h" #include "HealthComponent.h" #include "AIStealthTask/AIStealthTaskCharacter.h" #include "Perception/AISense_Damage.h" +#include "Perception/AISense_Hearing.h" #include "Perception/AISense_Sight.h" AActor* UStealthTestAIPerceptionComponent::GetClosestEnemy() { TArray<AActor*> DetectedActors; GetCurrentlyPerceivedActors(UAISense_Sight::StaticClass(),DetectedActors); + //GLog->Log(FString::FromInt(DetectedActors.Num())); if(DetectedActors.Num()==0) { GetCurrentlyPerceivedActors(UAISense_Damage::StaticClass(),DetectedActors); @@ -28,6 +32,7 @@ AActor* UStealthTestAIPerceptionComponent::GetClosestEnemy() for(const auto DetectedActor: DetectedActors) { const auto Player=Cast<AAIStealthTaskCharacter>(DetectedActor); + //GLog->Log("Player: "+Player->GetName()); if(Player) { const auto HealthComponent=Player->GetComponentByClass(UHealthComponent::StaticClass()); @@ -47,5 +52,38 @@ AActor* UStealthTestAIPerceptionComponent::GetClosestEnemy() AActor* UStealthTestAIPerceptionComponent::GetClosestSound() { - return nullptr; + TArray<AActor*> DetectedActors; + GetCurrentlyPerceivedActors(UAISense_Hearing::StaticClass(),DetectedActors); + if(DetectedActors.Num()==0) + { + GetCurrentlyPerceivedActors(UAISense_Damage::StaticClass(),DetectedActors); + if(DetectedActors.Num()==0) return nullptr; + } + const auto Controller=Cast<AAIController>(GetOwner()); + if (!Controller) return nullptr; + + const auto Pawn=Controller->GetPawn(); + if(!Pawn) return nullptr; + float ClosestDistance=MAX_FLT; + AActor* ClosestPawn=nullptr; + GLog->Log(FString::FromInt(DetectedActors.Num())); + for(const auto DetectedActor: DetectedActors) + { + const auto Player=Cast<AAIStealthTaskCharacter>(DetectedActor); + //GLog->Log("Player: "+Player->GetName()); + if(Player) + { + const auto HealthComponent=Player->GetComponentByClass(UHealthComponent::StaticClass()); + if(HealthComponent) + { + const auto CurrentDistance=(DetectedActor->GetActorLocation()-Pawn->GetActorLocation()).Size(); + if(CurrentDistance<ClosestDistance) + { + ClosestDistance=CurrentDistance; + ClosestPawn=DetectedActor; + } + } + } + } + return ClosestPawn; } diff --git a/Source/AIStealthTask/Private/Components/WalkSoundComponent.cpp b/Source/AIStealthTask/Private/Components/WalkSoundComponent.cpp index 073723ed295cfe4b8025ccff00a431a63b707b44..b60f3b0d36fa1fbbe444e7af4383036d9dda524f 100644 --- a/Source/AIStealthTask/Private/Components/WalkSoundComponent.cpp +++ b/Source/AIStealthTask/Private/Components/WalkSoundComponent.cpp @@ -33,7 +33,7 @@ void UWalkSoundComponent::PlayStepSound() CollisionParams.AddIgnoredActor(OwnerActor); FHitResult HitResult; GetWorld()->LineTraceSingleByChannel(HitResult,TraceStart,TraceEnd,ECollisionChannel::ECC_Visibility,CollisionParams); - GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, HitResult.TraceEnd.ToString()); + DrawDebugLine(GetWorld(),TraceStart,TraceEnd,FColor::Blue,false,3.0f,0,3.0f); DrawDebugSphere(GetWorld(),HitResult.ImpactPoint,10.0f,24,FColor::Red,false,5.0f); if(HitResult.bBlockingHit) diff --git a/Source/AIStealthTask/Private/Projectiles/BaseProjectile.cpp b/Source/AIStealthTask/Private/Projectiles/BaseProjectile.cpp new file mode 100644 index 0000000000000000000000000000000000000000..11d74c1858777694c75c947372b515387be865e4 --- /dev/null +++ b/Source/AIStealthTask/Private/Projectiles/BaseProjectile.cpp @@ -0,0 +1,27 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Projectiles/BaseProjectile.h" + +// Sets default values +ABaseProjectile::ABaseProjectile() +{ + // 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; + +} + +// Called when the game starts or when spawned +void ABaseProjectile::BeginPlay() +{ + Super::BeginPlay(); + +} + +// Called every frame +void ABaseProjectile::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + +} + diff --git a/Source/AIStealthTask/Private/UI/EnemyHealthWidget.cpp b/Source/AIStealthTask/Private/UI/EnemyHealthWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..77a88b9590c3f776347d1994d32ea76483b42e70 --- /dev/null +++ b/Source/AIStealthTask/Private/UI/EnemyHealthWidget.cpp @@ -0,0 +1,5 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "UI/EnemyHealthWidget.h" + diff --git a/Source/AIStealthTask/Private/UI/NearEnemyEnvQueryContext.cpp b/Source/AIStealthTask/Private/UI/NearEnemyEnvQueryContext.cpp new file mode 100644 index 0000000000000000000000000000000000000000..704c13bd6d8320c4d468f2bc887dd86f2e307646 --- /dev/null +++ b/Source/AIStealthTask/Private/UI/NearEnemyEnvQueryContext.cpp @@ -0,0 +1,24 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "UI/NearEnemyEnvQueryContext.h" + +#include "BehaviorTree/BlackboardComponent.h" +#include "Blueprint/AIBlueprintHelperLibrary.h" +#include "EnvironmentQuery/EnvQueryTypes.h" +#include "EnvironmentQuery/Items/EnvQueryItemType_Actor.h" + +UNearEnemyEnvQueryContext::UNearEnemyEnvQueryContext() +{ +} + +void UNearEnemyEnvQueryContext::ProvideContext(FEnvQueryInstance& QueryInstance, FEnvQueryContextData& ContextData) const +{ + const auto QueryOwner = Cast<AActor>(QueryInstance.Owner.Get()); + + const auto Blackboard = UAIBlueprintHelperLibrary::GetBlackboard(QueryOwner); + if (!Blackboard) return; + + const auto ContextActor = Blackboard->GetValueAsObject(EnemyActorKeyName); + UEnvQueryItemType_Actor::SetContextHelper(ContextData, Cast<AActor>(ContextActor)); +} diff --git a/Source/AIStealthTask/Private/UI/PlayerHealthWidget.cpp b/Source/AIStealthTask/Private/UI/PlayerHealthWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5e788102bf7737d9000efe21743dbc6d468502af --- /dev/null +++ b/Source/AIStealthTask/Private/UI/PlayerHealthWidget.cpp @@ -0,0 +1,63 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "UI/PlayerHealthWidget.h" + +#include "HealthComponent.h" +#include "Components/ProgressBar.h" + +float UPlayerHealthWidget::GetHealthPercent() const +{ + const auto HealthComponent = Cast<UHealthComponent>(GetOwningPlayerPawn()); + if (!HealthComponent) return 0.0f; + + return HealthComponent->GetHealthPercent(); +} + +bool UPlayerHealthWidget::IsPlayerAlive() const +{ + const auto HealthComponent = Cast<UHealthComponent>(GetOwningPlayerPawn()); + return HealthComponent && !HealthComponent->IsDead(); +} + +void UPlayerHealthWidget::NativeOnInitialized() +{ + Super::NativeOnInitialized(); + + if (GetOwningPlayer()) + { + GetOwningPlayer()->GetOnNewPawnNotifier().AddUObject(this, &UPlayerHealthWidget::OnNewPawn); + OnNewPawn(GetOwningPlayerPawn()); + } +} + +void UPlayerHealthWidget::OnHealthChanged(float Health, float HealthDelta) +{ + if (HealthDelta < 0.0f) + { + OnTakeDamage(); + + } + UpdateHealthBar(); +} + +void UPlayerHealthWidget::OnNewPawn(APawn* NewPawn) +{ + if(!NewPawn) return; + const auto Component = NewPawn->GetComponentByClass(UPlayerHealthWidget::StaticClass()); + const auto HealthComponent=Cast<UHealthComponent>(Component); + if (HealthComponent && !HealthComponent->OnHealthChanged.IsBoundToObject(this)) + { + HealthComponent->OnHealthChanged.AddUObject(this, &UPlayerHealthWidget::OnHealthChanged); + } + UpdateHealthBar(); +} + +void UPlayerHealthWidget::UpdateHealthBar() +{ + if(HealthProgressBar) + { + + HealthProgressBar->SetFillColorAndOpacity(GetHealthPercent()>PercentColorThreshold? GoodColor : BadColor); + } +} diff --git a/Source/AIStealthTask/Private/UI/TurnOnOffAIWidget.cpp b/Source/AIStealthTask/Private/UI/TurnOnOffAIWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8f08380e732521ad9e8748052498904d9d2cc199 --- /dev/null +++ b/Source/AIStealthTask/Private/UI/TurnOnOffAIWidget.cpp @@ -0,0 +1,32 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "UI/TurnOnOffAIWidget.h" + +#include "Components/TextBlock.h" + +void UTurnOnOffAIWidget::NativeOnInitialized() +{ + Super::NativeOnInitialized(); + UpdateText(); +} + +void UTurnOnOffAIWidget::ChangeCurrentMode() +{ + if(CurrentText==TurnOnAIText) + { + CurrentText=TurnOffAIText; + UpdateText(); + } + else + { + CurrentText=TurnOnAIText; + UpdateText(); + } +} + +void UTurnOnOffAIWidget::UpdateText() +{ + ActionTextBlock->Text=FText::FromString(CurrentText); +} + diff --git a/Source/AIStealthTask/Public/AI/STAICharacter.h b/Source/AIStealthTask/Public/AI/STAICharacter.h index e9288441d2329261e2aaa7d335c455eac6e42991..da57f246cc6b08b66ba6f92cf82f02fd3685808b 100644 --- a/Source/AIStealthTask/Public/AI/STAICharacter.h +++ b/Source/AIStealthTask/Public/AI/STAICharacter.h @@ -3,6 +3,7 @@ #pragma once #include "CoreMinimal.h" +#include "AIStateSignComponent.h" #include "AI/BaseAICharacter.h" #include "STAICharacter.generated.h" @@ -25,7 +26,8 @@ protected: UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Health") float HealthVisibilityDistance = 1000.0f; - + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Health") + UAIStateSignComponent* StateSignComponent; virtual void BeginPlay() override; virtual void OnDeath() override; diff --git a/Source/AIStealthTask/Public/AI/Services/DealDamageService.h b/Source/AIStealthTask/Public/AI/Services/DealDamageService.h new file mode 100644 index 0000000000000000000000000000000000000000..ca047db3ea62bcd394daeda8a3fe81d53a18d62c --- /dev/null +++ b/Source/AIStealthTask/Public/AI/Services/DealDamageService.h @@ -0,0 +1,23 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/BTService.h" +#include "DealDamageService.generated.h" + +/** + * + */ +UCLASS() +class AISTEALTHTASK_API UDealDamageService : public UBTService +{ + GENERATED_BODY() +public: + UDealDamageService(); +protected: + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI") + FBlackboardKeySelector EnemyActorKey; + + virtual void TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds) override; +}; diff --git a/Source/AIStealthTask/Public/AI/Services/FindEnemyService.h b/Source/AIStealthTask/Public/AI/Services/FindEnemyService.h new file mode 100644 index 0000000000000000000000000000000000000000..d6acf12686dacab2e36b370a923f85b1610e20a1 --- /dev/null +++ b/Source/AIStealthTask/Public/AI/Services/FindEnemyService.h @@ -0,0 +1,26 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/BTService.h" +#include "FindEnemyService.generated.h" + +/** + * + */ +UCLASS() +class AISTEALTHTASK_API UFindEnemyService : public UBTService +{ + GENERATED_BODY() + +public: + UFindEnemyService(); +protected: + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI") + FBlackboardKeySelector EnemyActorKey; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI") + FBlackboardKeySelector SoundSourceKey; + + virtual void TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds) override; +}; diff --git a/Source/AIStealthTask/Public/AI/Services/FindSoundService.h~ b/Source/AIStealthTask/Public/AI/Services/FindSoundService.h~ new file mode 100644 index 0000000000000000000000000000000000000000..67d0e47cb303a327bd0af26687ff640a2747b6d8 --- /dev/null +++ b/Source/AIStealthTask/Public/AI/Services/FindSoundService.h~ @@ -0,0 +1,23 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/BTService.h" +#include "FindSoundService.generated.h" + +/** + * + */ +UCLASS() +class AISTEALTHTASK_API UFindSoundService : public UBTService +{ + GENERATED_BODY() +public: + UFindEnemyService(); +protected: + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI") + FBlackboardKeySelector EnemyActorKey; + + virtual void TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds) override; +}; diff --git a/Source/AIStealthTask/Public/AI/ShootService.h b/Source/AIStealthTask/Public/AI/ShootService.h new file mode 100644 index 0000000000000000000000000000000000000000..9e6723c427d6e90ea9c482ceb4e6b19b5ef118b9 --- /dev/null +++ b/Source/AIStealthTask/Public/AI/ShootService.h @@ -0,0 +1,17 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/BTService.h" +#include "ShootService.generated.h" + +/** + * + */ +UCLASS() +class AISTEALTHTASK_API UShootService : public UBTService +{ + GENERATED_BODY() + +}; diff --git a/Source/AIStealthTask/Public/AI/Tasks/ChangeAIStateTask.h b/Source/AIStealthTask/Public/AI/Tasks/ChangeAIStateTask.h new file mode 100644 index 0000000000000000000000000000000000000000..75411bfbb36c1a3c05dfebb478327280ee96e45f --- /dev/null +++ b/Source/AIStealthTask/Public/AI/Tasks/ChangeAIStateTask.h @@ -0,0 +1,24 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "STCoreTypes.h" +#include "BehaviorTree/BTTaskNode.h" +#include "ChangeAIStateTask.generated.h" + +/** + * + */ +UCLASS() +class AISTEALTHTASK_API UChangeAIStateTask : public UBTTaskNode +{ + GENERATED_BODY() +public: + UChangeAIStateTask(); + virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override; +protected: + UPROPERTY(EditAnywhere,BlueprintReadWrite,Category="State") + TEnumAsByte<EAIStates> AIState=EAIStates::Roaming; + +}; diff --git a/Source/AIStealthTask/Public/AI/Tasks/FireInEnemyTask.h b/Source/AIStealthTask/Public/AI/Tasks/FireInEnemyTask.h new file mode 100644 index 0000000000000000000000000000000000000000..45a06e079797ec9c68619f0df63ed9b2a8595702 --- /dev/null +++ b/Source/AIStealthTask/Public/AI/Tasks/FireInEnemyTask.h @@ -0,0 +1,21 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "STCoreTypes.h" +#include "BehaviorTree/BTTaskNode.h" +#include "FireInEnemyTask.generated.h" + +/** + * + */ +UCLASS() +class AISTEALTHTASK_API UFireInEnemyTask : public UBTTaskNode +{ + GENERATED_BODY() +public: + UFireInEnemyTask(); + virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override; +protected: +}; diff --git a/Source/AIStealthTask/Public/AITaskGameMode.h b/Source/AIStealthTask/Public/AITaskGameMode.h new file mode 100644 index 0000000000000000000000000000000000000000..d9e17594ad1a5ae823dec0b2b026510383190564 --- /dev/null +++ b/Source/AIStealthTask/Public/AITaskGameMode.h @@ -0,0 +1,17 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "AIStealthTask/AIStealthTaskGameMode.h" +#include "AITaskGameMode.generated.h" + +/** + * + */ +UCLASS() +class AISTEALTHTASK_API AAITaskGameMode : public AAIStealthTaskGameMode +{ + GENERATED_BODY() + +}; diff --git a/Source/AIStealthTask/Public/ActivateAIButtonTrigger.h b/Source/AIStealthTask/Public/ActivateAIButtonTrigger.h index 4d07c7a0a70a846b696d32bca8f0a9ed8985bb5f..f7262467b54a68659c4357ba80c4964e5df32d43 100644 --- a/Source/AIStealthTask/Public/ActivateAIButtonTrigger.h +++ b/Source/AIStealthTask/Public/ActivateAIButtonTrigger.h @@ -4,8 +4,10 @@ #include "CoreMinimal.h" #include "GameFramework/Actor.h" +#include "UI/TurnOnOffAIWidget.h" #include "ActivateAIButtonTrigger.generated.h" +class USphereComponent; UCLASS() class AISTEALTHTASK_API AActivateAIButtonTrigger : public AActor { @@ -18,8 +20,27 @@ public: protected: // Called when the game starts or when spawned virtual void BeginPlay() override; + UPROPERTY(EditAnywhere,BlueprintReadWrite) + USphereComponent* SphereComponent; + UPROPERTY(EditAnywhere,BlueprintReadWrite,Category="UI") + TSubclassOf<UUserWidget> TipWidget; + + UTurnOnOffAIWidget* Widget; + bool AIWorking=false; + UFUNCTION() + void OnButtonBeenPress(); public: // Called every frame virtual void Tick(float DeltaTime) override; - UFUNC \ No newline at end of file + UFUNCTION() + void OnSphereComponentCollision(UPrimitiveComponent* OverlappedComponent, + AActor* OtherActor, + UPrimitiveComponent* OtherComp, + int32 OtherBodyIndex, + bool bFromSweep, + const FHitResult &SweepResult); + UFUNCTION() + void OnOverlapEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex); +}; diff --git a/Source/AIStealthTask/Public/Components/AIStateSignComponent.h b/Source/AIStealthTask/Public/Components/AIStateSignComponent.h new file mode 100644 index 0000000000000000000000000000000000000000..2d240e6f378ad5f3455554bba3b8e07ba2976fa1 --- /dev/null +++ b/Source/AIStealthTask/Public/Components/AIStateSignComponent.h @@ -0,0 +1,33 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "STCoreTypes.h" +#include "Components/ActorComponent.h" +#include "AIStateSignComponent.generated.h" + + +UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +class AISTEALTHTASK_API UAIStateSignComponent : public UActorComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UAIStateSignComponent(); + +protected: + // Called when the game starts + virtual void BeginPlay() override; + UPROPERTY(EditAnywhere,BlueprintReadWrite,Category="States") + TMap<TEnumAsByte<EAIStates>,UStaticMeshComponent*> StateSigns; + UPROPERTY(EditAnywhere,BlueprintReadWrite,Category="MeshComponent") + UStaticMeshComponent* CurrentMeshComponent; + TEnumAsByte<EAIStates> CurrentState=EAIStates::Roaming; +public: + // Called every frame + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + void SetAIState(TEnumAsByte<EAIStates> newState); + +}; diff --git a/Source/AIStealthTask/Public/Projectiles/BaseProjectile.h b/Source/AIStealthTask/Public/Projectiles/BaseProjectile.h new file mode 100644 index 0000000000000000000000000000000000000000..f8d18a158068e41b03f6185621086876e2b871d1 --- /dev/null +++ b/Source/AIStealthTask/Public/Projectiles/BaseProjectile.h @@ -0,0 +1,26 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Actor.h" +#include "BaseProjectile.generated.h" + +UCLASS() +class AISTEALTHTASK_API ABaseProjectile : public AActor +{ + GENERATED_BODY() + +public: + // Sets default values for this actor's properties + ABaseProjectile(); + +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void Tick(float DeltaTime) override; + +}; diff --git a/Source/AIStealthTask/Public/STCoreTypes.h b/Source/AIStealthTask/Public/STCoreTypes.h index cc53bdfbbdf188c7aef86e749f71c99c8f2ee75f..2cdd6413883e69507a2830e75d7f527fe52ff818 100644 --- a/Source/AIStealthTask/Public/STCoreTypes.h +++ b/Source/AIStealthTask/Public/STCoreTypes.h @@ -18,4 +18,13 @@ struct FStepSoundData }; DECLARE_MULTICAST_DELEGATE(FOnDeathSignature); -DECLARE_MULTICAST_DELEGATE_TwoParams(FOnHealthChangedSignature, float, float); \ No newline at end of file +DECLARE_MULTICAST_DELEGATE_TwoParams(FOnHealthChangedSignature, float, float); + +UENUM(BlueprintType) +enum class EAIStates:uint8 +{ + Roaming, + Investigating, + Attacking +}; + diff --git a/Source/AIStealthTask/Public/UI/EnemyHealthWidget.h b/Source/AIStealthTask/Public/UI/EnemyHealthWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..380c8108397a93087c4c2bab80b876cfc223989e --- /dev/null +++ b/Source/AIStealthTask/Public/UI/EnemyHealthWidget.h @@ -0,0 +1,17 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Blueprint/UserWidget.h" +#include "EnemyHealthWidget.generated.h" + +/** + * + */ +UCLASS() +class AISTEALTHTASK_API UEnemyHealthWidget : public UUserWidget +{ + GENERATED_BODY() + +}; diff --git a/Source/AIStealthTask/Public/UI/NearEnemyEnvQueryContext.h b/Source/AIStealthTask/Public/UI/NearEnemyEnvQueryContext.h new file mode 100644 index 0000000000000000000000000000000000000000..8a068718551c224d0ffd508d660834b2926f75bb --- /dev/null +++ b/Source/AIStealthTask/Public/UI/NearEnemyEnvQueryContext.h @@ -0,0 +1,23 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "EnvironmentQuery/EnvQueryContext.h" +#include "NearEnemyEnvQueryContext.generated.h" + +/** + * + */ +UCLASS() +class AISTEALTHTASK_API UNearEnemyEnvQueryContext : public UEnvQueryContext +{ + GENERATED_BODY() + UNearEnemyEnvQueryContext(); +public: + virtual void ProvideContext(FEnvQueryInstance& QueryInstance, FEnvQueryContextData& ContextData) const override; + +protected: + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI") + FName EnemyActorKeyName = "EnemyActor"; +}; diff --git a/Source/AIStealthTask/Public/UI/PlayerHealthWidget.h b/Source/AIStealthTask/Public/UI/PlayerHealthWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..ca14426f6d1a7877e62252dbe03c7d51a98ddca3 --- /dev/null +++ b/Source/AIStealthTask/Public/UI/PlayerHealthWidget.h @@ -0,0 +1,40 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Blueprint/UserWidget.h" +#include "PlayerHealthWidget.generated.h" + +class UProgressBar; +/** + * + */ +UCLASS() +class AISTEALTHTASK_API UPlayerHealthWidget : public UUserWidget +{ + GENERATED_BODY() +public: + UFUNCTION(BlueprintCallable, Category = "UI") + float GetHealthPercent() const; + UFUNCTION(BlueprintCallable, Category = "UI") + bool IsPlayerAlive() const; + UFUNCTION(BlueprintImplementableEvent, Category = "UI") + void OnTakeDamage(); + virtual void NativeOnInitialized() override; + +protected: + UPROPERTY(meta = (BindWidget)) + UProgressBar* HealthProgressBar; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "UI") + float PercentColorThreshold = 0.3f; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "UI") + FLinearColor GoodColor = FLinearColor::White; + + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "UI") + FLinearColor BadColor = FLinearColor::Red; +private: + void OnHealthChanged(float Health, float HealthDelta); + void OnNewPawn(APawn* NewPawn); + void UpdateHealthBar(); +}; \ No newline at end of file diff --git a/Source/AIStealthTask/Public/UI/TurnOnOffAIWidget.h b/Source/AIStealthTask/Public/UI/TurnOnOffAIWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..7e8d569b5209adff3757c9e4dacc6823c3ed2a08 --- /dev/null +++ b/Source/AIStealthTask/Public/UI/TurnOnOffAIWidget.h @@ -0,0 +1,30 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Blueprint/UserWidget.h" +#include "TurnOnOffAIWidget.generated.h" + +class UTextBlock; +/** + * + */ +UCLASS() +class AISTEALTHTASK_API UTurnOnOffAIWidget : public UUserWidget +{ + GENERATED_BODY() + + UPROPERTY(meta=(BindWidget)) + UTextBlock* ActionTextBlock; + virtual void NativeOnInitialized() override; +public: + UPROPERTY(EditAnywhere,BlueprintReadWrite) + FString TurnOnAIText="Press E to turn on AI"; + UPROPERTY(EditAnywhere,BlueprintReadWrite) + FString TurnOffAIText="Press E to turn off AI"; + void ChangeCurrentMode(); +private: + FString CurrentText=TurnOnAIText; + void UpdateText(); +};