From 97a23666d8d27b4af34a23c0be57e5ca2587d530 Mon Sep 17 00:00:00 2001 From: PHILIP WHITE Date: Sat, 27 Jan 2024 09:09:04 +0000 Subject: [PATCH] Add Item Pickup and Highlight for Item Stealing --- .../.idea/.idea.SeagullGame.dir/.idea/vcs.xml | 6 ++ SeagullGame/Content/AI/AIC_Enemy.uasset | 3 + SeagullGame/Content/AI/AI_Enemy.uasset | 3 + SeagullGame/Content/AI/BB_Enemy.uasset | 3 + SeagullGame/Content/AI/BTT_Chase.uasset | 3 + .../Content/AI/BTT_FindRandomPatrol.uasset | 3 + SeagullGame/Content/AI/BT_Enemy.uasset | 3 + .../Mannequins/Meshes/SK_Mannequin.uasset | 4 +- SeagullGame/Content/Fonts/upheavtt.uasset | 3 + .../Content/Fonts/upheavtt_Font.uasset | 3 + SeagullGame/Content/Items/BPI_Cube.uasset | 3 + SeagullGame/Content/Items/BPI_Cube_NP.uasset | 3 + .../Content/ThirdPerson/AI/AIC_Enemy.uasset | 3 - .../Content/ThirdPerson/AI/AI_Enemy.uasset | 3 - .../Content/ThirdPerson/AI/BB_Enemy.uasset | 3 - .../Content/ThirdPerson/AI/BTT_Chase.uasset | 3 - .../AI/BTT_FindRandomPatrol.uasset | 3 - .../Content/ThirdPerson/AI/BT_Enemy.uasset | 3 - .../Blueprints/BP_SeagullPlayer.uasset | 4 +- .../Blueprints/SKM_Quinn_Socket.uasset | 3 + .../TopDown/Input/Actions/IAS_Pickup.uasset | 3 + .../TopDown/Input/IMC_DefaultMain.uasset | 4 +- .../3/TG/E6S3QC0D0NIW660W8K9AY7.uasset | 3 - .../6/25/Y3O5AZUCBRGIK0G1642MVL.uasset | 3 + .../6/VI/ESHAVRHFZFA2JDR9ZAQIOE.uasset | 4 +- .../A/4W/BK95DJBD0PIVE7JMNNMPSX.uasset | 3 + .../C/EK/K75411SFI66JADVMYUHSE9.uasset | 4 +- SeagullGame/Source/SeagullGame/ItemActor.cpp | 26 ++++++ SeagullGame/Source/SeagullGame/ItemActor.h | 28 ++++++ .../SeagullGame/SeagullGameCharacter.cpp | 88 +++++++++++++++++++ .../Source/SeagullGame/SeagullGameCharacter.h | 36 ++++++++ 31 files changed, 236 insertions(+), 31 deletions(-) create mode 100644 SeagullGame/.idea/.idea.SeagullGame.dir/.idea/vcs.xml create mode 100644 SeagullGame/Content/AI/AIC_Enemy.uasset create mode 100644 SeagullGame/Content/AI/AI_Enemy.uasset create mode 100644 SeagullGame/Content/AI/BB_Enemy.uasset create mode 100644 SeagullGame/Content/AI/BTT_Chase.uasset create mode 100644 SeagullGame/Content/AI/BTT_FindRandomPatrol.uasset create mode 100644 SeagullGame/Content/AI/BT_Enemy.uasset create mode 100644 SeagullGame/Content/Fonts/upheavtt.uasset create mode 100644 SeagullGame/Content/Fonts/upheavtt_Font.uasset create mode 100644 SeagullGame/Content/Items/BPI_Cube.uasset create mode 100644 SeagullGame/Content/Items/BPI_Cube_NP.uasset delete mode 100644 SeagullGame/Content/ThirdPerson/AI/AIC_Enemy.uasset delete mode 100644 SeagullGame/Content/ThirdPerson/AI/AI_Enemy.uasset delete mode 100644 SeagullGame/Content/ThirdPerson/AI/BB_Enemy.uasset delete mode 100644 SeagullGame/Content/ThirdPerson/AI/BTT_Chase.uasset delete mode 100644 SeagullGame/Content/ThirdPerson/AI/BTT_FindRandomPatrol.uasset delete mode 100644 SeagullGame/Content/ThirdPerson/AI/BT_Enemy.uasset create mode 100644 SeagullGame/Content/TopDown/Blueprints/SKM_Quinn_Socket.uasset create mode 100644 SeagullGame/Content/TopDown/Input/Actions/IAS_Pickup.uasset delete mode 100644 SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/3/TG/E6S3QC0D0NIW660W8K9AY7.uasset create mode 100644 SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/6/25/Y3O5AZUCBRGIK0G1642MVL.uasset create mode 100644 SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/A/4W/BK95DJBD0PIVE7JMNNMPSX.uasset create mode 100644 SeagullGame/Source/SeagullGame/ItemActor.cpp create mode 100644 SeagullGame/Source/SeagullGame/ItemActor.h diff --git a/SeagullGame/.idea/.idea.SeagullGame.dir/.idea/vcs.xml b/SeagullGame/.idea/.idea.SeagullGame.dir/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/SeagullGame/.idea/.idea.SeagullGame.dir/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SeagullGame/Content/AI/AIC_Enemy.uasset b/SeagullGame/Content/AI/AIC_Enemy.uasset new file mode 100644 index 0000000..f35d6c3 --- /dev/null +++ b/SeagullGame/Content/AI/AIC_Enemy.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8ddabc007daa5c627c104ec5ea209f7d1383a51377436b2aaf27f4307b457e9a +size 100323 diff --git a/SeagullGame/Content/AI/AI_Enemy.uasset b/SeagullGame/Content/AI/AI_Enemy.uasset new file mode 100644 index 0000000..ab7f3d4 --- /dev/null +++ b/SeagullGame/Content/AI/AI_Enemy.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b36fa35c13337dbb237d9e11901dd115c69e92e275a193818bee5f2eec5ea72f +size 38612 diff --git a/SeagullGame/Content/AI/BB_Enemy.uasset b/SeagullGame/Content/AI/BB_Enemy.uasset new file mode 100644 index 0000000..e7b108d --- /dev/null +++ b/SeagullGame/Content/AI/BB_Enemy.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a8dd0271720b7bd65ddc3d4e83cda2e1d24be47fb36aa3adc6077d0705d011e0 +size 3218 diff --git a/SeagullGame/Content/AI/BTT_Chase.uasset b/SeagullGame/Content/AI/BTT_Chase.uasset new file mode 100644 index 0000000..b316873 --- /dev/null +++ b/SeagullGame/Content/AI/BTT_Chase.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:883e7d2927da541f2ebbb1dcb0052993fc48f59714506660d2f84aedc56b5300 +size 31455 diff --git a/SeagullGame/Content/AI/BTT_FindRandomPatrol.uasset b/SeagullGame/Content/AI/BTT_FindRandomPatrol.uasset new file mode 100644 index 0000000..e975094 --- /dev/null +++ b/SeagullGame/Content/AI/BTT_FindRandomPatrol.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7ee849ec64499a218dd28170b74ec5444966b9413e843089470be32975016312 +size 55215 diff --git a/SeagullGame/Content/AI/BT_Enemy.uasset b/SeagullGame/Content/AI/BT_Enemy.uasset new file mode 100644 index 0000000..3050779 --- /dev/null +++ b/SeagullGame/Content/AI/BT_Enemy.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d09eae4b7b49e783edb48b56c7ead31d784ae094233643be7d23a994dd634402 +size 20824 diff --git a/SeagullGame/Content/Characters/Mannequins/Meshes/SK_Mannequin.uasset b/SeagullGame/Content/Characters/Mannequins/Meshes/SK_Mannequin.uasset index e864a47..fe9feea 100644 --- a/SeagullGame/Content/Characters/Mannequins/Meshes/SK_Mannequin.uasset +++ b/SeagullGame/Content/Characters/Mannequins/Meshes/SK_Mannequin.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:777b2aa0a679b5d326814440204787ff0ba56b4ad9477a407b24d689155b050c -size 160872 +oid sha256:a63e4b739f75ec01983a0c5a5431e37cedf1a2773e7ca9d75ed2abb486d86b4f +size 158147 diff --git a/SeagullGame/Content/Fonts/upheavtt.uasset b/SeagullGame/Content/Fonts/upheavtt.uasset new file mode 100644 index 0000000..8b4ae3d --- /dev/null +++ b/SeagullGame/Content/Fonts/upheavtt.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:edb2095999fba2f20b1e19aa7278f16b8036169047e20415f0b1c1d195e7da30 +size 43340 diff --git a/SeagullGame/Content/Fonts/upheavtt_Font.uasset b/SeagullGame/Content/Fonts/upheavtt_Font.uasset new file mode 100644 index 0000000..528c638 --- /dev/null +++ b/SeagullGame/Content/Fonts/upheavtt_Font.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d780d2edb5ed062d3079ce871023e1e7e35b5617686bc1653359c840f0a0c73 +size 6307 diff --git a/SeagullGame/Content/Items/BPI_Cube.uasset b/SeagullGame/Content/Items/BPI_Cube.uasset new file mode 100644 index 0000000..7306b4a --- /dev/null +++ b/SeagullGame/Content/Items/BPI_Cube.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9743f6832cc2577d9ca8fc8ef165ce067ea9e22845cf7a7805a0c6201b3865a6 +size 27709 diff --git a/SeagullGame/Content/Items/BPI_Cube_NP.uasset b/SeagullGame/Content/Items/BPI_Cube_NP.uasset new file mode 100644 index 0000000..cc2b148 --- /dev/null +++ b/SeagullGame/Content/Items/BPI_Cube_NP.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2bb09d47e9957a698943f48cd8c7e2d8410012749f93c4ea1d8df8455bd9be61 +size 27274 diff --git a/SeagullGame/Content/ThirdPerson/AI/AIC_Enemy.uasset b/SeagullGame/Content/ThirdPerson/AI/AIC_Enemy.uasset deleted file mode 100644 index 8d67baf..0000000 --- a/SeagullGame/Content/ThirdPerson/AI/AIC_Enemy.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:e369290d59d22bf823a848f52ff261bc227ab6fff26b86506b30132210a2bf28 -size 100356 diff --git a/SeagullGame/Content/ThirdPerson/AI/AI_Enemy.uasset b/SeagullGame/Content/ThirdPerson/AI/AI_Enemy.uasset deleted file mode 100644 index 2bac7f6..0000000 --- a/SeagullGame/Content/ThirdPerson/AI/AI_Enemy.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:b81a3bb8bf66af58bc5da26c5353d90b1c7c75523eaacd11f9852168575c11c9 -size 39966 diff --git a/SeagullGame/Content/ThirdPerson/AI/BB_Enemy.uasset b/SeagullGame/Content/ThirdPerson/AI/BB_Enemy.uasset deleted file mode 100644 index 910cd30..0000000 --- a/SeagullGame/Content/ThirdPerson/AI/BB_Enemy.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:05d77761f39ddc1a1623a4094291d4b3f21493e29a653ec186cf227f265de2c5 -size 3242 diff --git a/SeagullGame/Content/ThirdPerson/AI/BTT_Chase.uasset b/SeagullGame/Content/ThirdPerson/AI/BTT_Chase.uasset deleted file mode 100644 index 6ca0f20..0000000 --- a/SeagullGame/Content/ThirdPerson/AI/BTT_Chase.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:99bd9df5f2529b15da348e3d5dc95edacd68411981ccaf84b54f999d192ce57c -size 31488 diff --git a/SeagullGame/Content/ThirdPerson/AI/BTT_FindRandomPatrol.uasset b/SeagullGame/Content/ThirdPerson/AI/BTT_FindRandomPatrol.uasset deleted file mode 100644 index 17bb946..0000000 --- a/SeagullGame/Content/ThirdPerson/AI/BTT_FindRandomPatrol.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:cc6a62145cd2abfa2ce68e2975dba8285a31c19f2d4431eb58c715ce642e916f -size 55273 diff --git a/SeagullGame/Content/ThirdPerson/AI/BT_Enemy.uasset b/SeagullGame/Content/ThirdPerson/AI/BT_Enemy.uasset deleted file mode 100644 index 99c3890..0000000 --- a/SeagullGame/Content/ThirdPerson/AI/BT_Enemy.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f2b1bbac489f5bc87196868a81e3efd6bae1538e66d25d4ca046f31576b12b39 -size 20846 diff --git a/SeagullGame/Content/TopDown/Blueprints/BP_SeagullPlayer.uasset b/SeagullGame/Content/TopDown/Blueprints/BP_SeagullPlayer.uasset index 215ed51..f5b75c2 100644 --- a/SeagullGame/Content/TopDown/Blueprints/BP_SeagullPlayer.uasset +++ b/SeagullGame/Content/TopDown/Blueprints/BP_SeagullPlayer.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d213e6b91b05e1d78a44a7482a5b4e738c98233654cc3b0270b9aeb50c8d0b25 -size 238639 +oid sha256:b17efa6e78d47b11a8027da9f9a9052d63ceaaba3d3987e5a31da727cd4a52fe +size 245570 diff --git a/SeagullGame/Content/TopDown/Blueprints/SKM_Quinn_Socket.uasset b/SeagullGame/Content/TopDown/Blueprints/SKM_Quinn_Socket.uasset new file mode 100644 index 0000000..5536ea4 --- /dev/null +++ b/SeagullGame/Content/TopDown/Blueprints/SKM_Quinn_Socket.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f4d57816d0d19885cd64768574bf2c0d8702369fceed8773d5745d83e7eaf12d +size 36495756 diff --git a/SeagullGame/Content/TopDown/Input/Actions/IAS_Pickup.uasset b/SeagullGame/Content/TopDown/Input/Actions/IAS_Pickup.uasset new file mode 100644 index 0000000..e3e733e --- /dev/null +++ b/SeagullGame/Content/TopDown/Input/Actions/IAS_Pickup.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7e43e55b132dda6947c875b1a25e1161e59ad09c8fcbe92d90ccb625a5c5f510 +size 1357 diff --git a/SeagullGame/Content/TopDown/Input/IMC_DefaultMain.uasset b/SeagullGame/Content/TopDown/Input/IMC_DefaultMain.uasset index 8728061..e389cd5 100644 --- a/SeagullGame/Content/TopDown/Input/IMC_DefaultMain.uasset +++ b/SeagullGame/Content/TopDown/Input/IMC_DefaultMain.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9d09e937cda8a135a12b4087e326939fd58d6c10a913d395a39cf38f5fd0a34e -size 12875 +oid sha256:24d6413be681637d45e7400e0e0206cd33504b0e3c4e7358f9e7db0e562e1774 +size 14137 diff --git a/SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/3/TG/E6S3QC0D0NIW660W8K9AY7.uasset b/SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/3/TG/E6S3QC0D0NIW660W8K9AY7.uasset deleted file mode 100644 index 0ea9827..0000000 --- a/SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/3/TG/E6S3QC0D0NIW660W8K9AY7.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:8f2950944bc4c2944e9597942d40351f5e5f97fe38f069b81cb2e932f625a10e -size 5970 diff --git a/SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/6/25/Y3O5AZUCBRGIK0G1642MVL.uasset b/SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/6/25/Y3O5AZUCBRGIK0G1642MVL.uasset new file mode 100644 index 0000000..277c33d --- /dev/null +++ b/SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/6/25/Y3O5AZUCBRGIK0G1642MVL.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dd144e23ae7b933cf9eff09eaf7b5f2181bf292d4579270add967b06b711eb30 +size 4240 diff --git a/SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/6/VI/ESHAVRHFZFA2JDR9ZAQIOE.uasset b/SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/6/VI/ESHAVRHFZFA2JDR9ZAQIOE.uasset index 0a3e814..1ee5701 100644 --- a/SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/6/VI/ESHAVRHFZFA2JDR9ZAQIOE.uasset +++ b/SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/6/VI/ESHAVRHFZFA2JDR9ZAQIOE.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1d68630aa4042b1ee62549eb347d7bd6d748cede30a08912e7942ee83fe8e3a9 -size 12519 +oid sha256:c6797f7bd1cc8833252cf692f23de4a261a2437d2e1988415835bfd0627e1848 +size 13001 diff --git a/SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/A/4W/BK95DJBD0PIVE7JMNNMPSX.uasset b/SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/A/4W/BK95DJBD0PIVE7JMNNMPSX.uasset new file mode 100644 index 0000000..b8457de --- /dev/null +++ b/SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/A/4W/BK95DJBD0PIVE7JMNNMPSX.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:019f700bf722c12cb9b7a815736d7c917ee73aa2a0cc097753a2caca09888b6b +size 4242 diff --git a/SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/C/EK/K75411SFI66JADVMYUHSE9.uasset b/SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/C/EK/K75411SFI66JADVMYUHSE9.uasset index 6b9b6f6..3594af7 100644 --- a/SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/C/EK/K75411SFI66JADVMYUHSE9.uasset +++ b/SeagullGame/Content/__ExternalActors__/TopDown/Maps/TopDownMap/C/EK/K75411SFI66JADVMYUHSE9.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cf62a0d4f8dde1344027f3124722e03e12cf2a520e1874503b761ba91880d222 -size 4021 +oid sha256:1de6811a4b1e24a674a58a1a6da11714705ddb08563d74cdc136be3bab0b126a +size 4312 diff --git a/SeagullGame/Source/SeagullGame/ItemActor.cpp b/SeagullGame/Source/SeagullGame/ItemActor.cpp new file mode 100644 index 0000000..ffe95b3 --- /dev/null +++ b/SeagullGame/Source/SeagullGame/ItemActor.cpp @@ -0,0 +1,26 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "ItemActor.h" + + +// Sets default values +AItemActor::AItemActor() +{ + // 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 AItemActor::BeginPlay() +{ + Super::BeginPlay(); + +} + +// Called every frame +void AItemActor::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); +} + diff --git a/SeagullGame/Source/SeagullGame/ItemActor.h b/SeagullGame/Source/SeagullGame/ItemActor.h new file mode 100644 index 0000000..dde13c7 --- /dev/null +++ b/SeagullGame/Source/SeagullGame/ItemActor.h @@ -0,0 +1,28 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Actor.h" +#include "ItemActor.generated.h" + +UCLASS() +class SEAGULLGAME_API AItemActor : public AActor +{ + GENERATED_BODY() + +public: + // Sets default values for this actor's properties + AItemActor(); + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Item") + TSubclassOf ItemNoPhysics; + +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/SeagullGame/Source/SeagullGame/SeagullGameCharacter.cpp b/SeagullGame/Source/SeagullGame/SeagullGameCharacter.cpp index 5faf330..f7d8f7c 100644 --- a/SeagullGame/Source/SeagullGame/SeagullGameCharacter.cpp +++ b/SeagullGame/Source/SeagullGame/SeagullGameCharacter.cpp @@ -4,8 +4,10 @@ #include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" +#include "ItemActor.h" #include "UObject/ConstructorHelpers.h" #include "Camera/CameraComponent.h" +#include "Components/BoxComponent.h" #include "Components/DecalComponent.h" #include "Components/CapsuleComponent.h" #include "GameFramework/CharacterMovementComponent.h" @@ -51,6 +53,27 @@ ASeagullGameCharacter::ASeagullGameCharacter() void ASeagullGameCharacter::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); + if (!IsValid(PickupBox)) return; + + TArray OverlappingActors; + PickupBox->GetOverlappingActors(OverlappingActors, AItemActor::StaticClass()); + float ClosestDistance = 0; + for (AActor* Actor : OverlappingActors) + { + if (Actor == this) continue; + float Distance = FVector::Dist(Actor->GetActorLocation(), GetActorLocation()); + if (ClosestItemActor == nullptr || Distance < ClosestDistance) + { + if (IsValid(ClosestItemActor)) + { + Cast(ClosestItemActor->GetComponentByClass(UMeshComponent::StaticClass()))->SetRenderCustomDepth(false); + } + ClosestItemActor = Actor; + ClosestDistance = Distance; + } + } + if (!IsValid(ClosestItemActor)) return; + Cast(ClosestItemActor->GetComponentByClass(UMeshComponent::StaticClass()))->SetRenderCustomDepth(true); } void ASeagullGameCharacter::BeginPlay() @@ -65,6 +88,9 @@ void ASeagullGameCharacter::BeginPlay() Subsystem->AddMappingContext(DefaultMappingContext, 0); } } + PickupBox = Cast(GetComponentByClass(UBoxComponent::StaticClass())); + PickupBox->OnComponentBeginOverlap.AddDynamic(this, &ASeagullGameCharacter::OnPickupBoxBeginOverlap); + PickupBox->OnComponentEndOverlap.AddDynamic(this, &ASeagullGameCharacter::OnPickupBoxEndOverlap); } void ASeagullGameCharacter::DamagePlayer(float DamageAmount) @@ -86,6 +112,65 @@ void ASeagullGameCharacter::HealPlayer(float HealAmount) } } +void ASeagullGameCharacter::StartGame() +{ + if (GetWorld()->GetTimerManager().IsTimerActive(GameTimerHandle)) + { + GetWorld()->GetTimerManager().ClearTimer(GameTimerHandle); + } + GetWorld()->GetTimerManager().SetTimer(GameTimerHandle, this, &ASeagullGameCharacter::EndGame, GameTime, false); +} + +void ASeagullGameCharacter::EndGame() +{ + OnGameEnd.Broadcast(); +} + +void ASeagullGameCharacter::PickupItem() +{ + if (IsValid(CurrentItem)) + { + DropItem(); + return; + } + USkeletalMeshComponent* MeshComponent = GetMesh(); + if (!MeshComponent->HasAnySockets()) return; + if (!IsValid(ClosestItemActor)) return; + CurrentItem = GetWorld()->SpawnActor(Cast(ClosestItemActor)->ItemNoPhysics); + CurrentItem->AttachToComponent(MeshComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale, "ItemSocket"); + CurrentItem->SetActorEnableCollision(false); + ClosestItemActor->Destroy(); +} + +void ASeagullGameCharacter::DropItem() +{ + if (!IsValid(CurrentItem)) return; + USkeletalMeshComponent* MeshComponent = GetMesh(); + CurrentItem->DetachFromActor(FDetachmentTransformRules::KeepWorldTransform); + FVector DropLocation = MeshComponent->GetSocketLocation("ItemSocket"); + DropLocation += GetActorForwardVector() * 100; + GetWorld()->SpawnActor(Cast(CurrentItem)->ItemNoPhysics, &DropLocation); + CurrentItem->Destroy(); + CurrentItem = nullptr; +} + +void ASeagullGameCharacter::OnPickupBoxBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) +{ +} + +void ASeagullGameCharacter::OnPickupBoxEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) +{ + if (!Cast(OtherActor)) return; + if (IsValid(OtherActor)) + { + if (OtherActor == ClosestItemActor) + { + Cast(OtherActor->GetComponentByClass(UMeshComponent::StaticClass()))->SetRenderCustomDepth(false); + ClosestItemActor = nullptr; + } + } +} + void ASeagullGameCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { // Set up action bindings @@ -100,6 +185,9 @@ void ASeagullGameCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInp //Looking // EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &ATP_ThirdPersonCharacter::Look); + + //Pickup + EnhancedInputComponent->BindAction(PickupAction, ETriggerEvent::Started, this, &ASeagullGameCharacter::PickupItem); } } diff --git a/SeagullGame/Source/SeagullGame/SeagullGameCharacter.h b/SeagullGame/Source/SeagullGame/SeagullGameCharacter.h index f4c1c92..46061b6 100644 --- a/SeagullGame/Source/SeagullGame/SeagullGameCharacter.h +++ b/SeagullGame/Source/SeagullGame/SeagullGameCharacter.h @@ -4,6 +4,8 @@ #include "CoreMinimal.h" #include "InputActionValue.h" +#include "ItemActor.h" +#include "Components/BoxComponent.h" #include "GameFramework/Character.h" #include "SeagullGameCharacter.generated.h" @@ -15,8 +17,12 @@ class ASeagullGameCharacter : public ACharacter public: DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnPlayerDeath); + DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnGameEnd); + UPROPERTY(BlueprintAssignable, Category = "Events") FOnPlayerDeath OnPlayerDeath; + UPROPERTY(BlueprintAssignable, Category = "Events") + FOnGameEnd OnGameEnd; ASeagullGameCharacter(); @@ -35,6 +41,10 @@ public: UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) class UInputAction* JumpAction; + /** Pickup Input Action */ + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) + class UInputAction* PickupAction; + /** Move Input Action */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) class UInputAction* MoveAction; @@ -57,6 +67,32 @@ public: UFUNCTION(BlueprintCallable, Category = "Health") void HealPlayer(float HealAmount); + UFUNCTION(Exec, BlueprintCallable, Category = "General") + void StartGame(); + UFUNCTION(BlueprintCallable, Category = "General") + void EndGame(); + UPROPERTY(BlueprintReadOnly, Category = "General") + FTimerHandle GameTimerHandle; + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "General") + float GameTime = 120; + + UFUNCTION(BlueprintCallable, Category = "Item") + void PickupItem(); + UFUNCTION(BlueprintCallable, Category = "Item") + void DropItem(); + UFUNCTION(BlueprintCallable, Category = "Item") + void OnPickupBoxBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, + int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult); + UFUNCTION(BlueprintCallable, Category = "Item") + void OnPickupBoxEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, + int32 OtherBodyIndex); + UPROPERTY(BlueprintReadOnly, Category = "Item") + AActor* CurrentItem; + UPROPERTY(BlueprintReadOnly, Category = "Item") + AActor* ClosestItemActor; + UPROPERTY(BlueprintReadOnly, Category = "Item") + UBoxComponent* PickupBox; + protected: // APawn interface virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;