From a1ec63742edd86d60ea1da304b3fcb77b82a5b2b Mon Sep 17 00:00:00 2001 From: charnet3d Date: Sat, 9 Mar 2024 19:28:12 +0100 Subject: [PATCH] Section 15: AI and Behavior Trees - Lecture 297 Weapon Trails --- .../Heroes/Grux/Meshes/Grux_Skeleton.uasset | 4 +- .../Sounds/WeaponSwings/AxeSwing1.uasset | 3 + .../Sounds/WeaponSwings/AxeSwing2.uasset | 3 + .../Sounds/WeaponSwings/AxeSwing3.uasset | 3 + .../Sounds/WeaponSwings/HeavySwing1.uasset | 3 + .../Sounds/WeaponSwings/HeavySwing2.uasset | 3 + .../Sounds/WeaponSwings/StickSwing1.uasset | 3 + .../Sounds/WeaponSwings/StickSwing2.uasset | 3 + .../Sounds/WeaponSwings/StickSwing3.uasset | 3 + .../Assets/Sounds/WeaponSwings/Swing1.uasset | 3 + .../Assets/Sounds/WeaponSwings/Swing2.uasset | 3 + .../Assets/Sounds/WeaponSwings/Swing3.uasset | 3 + .../Assets/Sounds/WeaponSwings/Swing4.uasset | 3 + .../Assets/Sounds/WeaponSwings/Swing5.uasset | 3 + .../Sounds/WeaponSwings/WeaponSwing.uasset | 3 + .../TwinBlast/TwinBlastCharacterBP.uasset | 4 +- .../Enemies/Animations/EnemyAttack.uasset | 3 + .../_Game/Enemies/Animations/EnemyHit.uasset | 4 +- Content/_Game/Enemies/EnemyBP.uasset | 4 +- Content/_Game/Enemies/GruxAnimBP.uasset | 4 +- .../_Game/EnemyController/BTT_Attack.uasset | 3 + .../EnemyController/EnemyBehaviorTree.uasset | 4 +- .../EnemyController/EnemyBlackboard.uasset | 4 +- .../GameMode/ShooterGameModeBaseBP.uasset | 4 +- Content/_Game/HUD/AmmoCountBP.uasset | 4 +- Content/_Game/HUD/CharacterHealthBar.uasset | 3 + Content/_Game/HUD/EnemyHealthBarBP.uasset | 4 +- Content/_Game/HUD/ShooterHUDOverlayBP.uasset | 4 +- Content/_Game/HUD/WeaponSlot.uasset | 4 +- Content/_Game/Maps/DefaultMap.umap | 4 +- Source/Shooter/Enemy.cpp | 140 +++++++++++++++++- Source/Shooter/Enemy.h | 75 +++++++++- Source/Shooter/ShooterCharacter.cpp | 21 ++- Source/Shooter/ShooterCharacter.h | 30 +++- 34 files changed, 338 insertions(+), 31 deletions(-) create mode 100644 Content/_Game/Assets/Sounds/WeaponSwings/AxeSwing1.uasset create mode 100644 Content/_Game/Assets/Sounds/WeaponSwings/AxeSwing2.uasset create mode 100644 Content/_Game/Assets/Sounds/WeaponSwings/AxeSwing3.uasset create mode 100644 Content/_Game/Assets/Sounds/WeaponSwings/HeavySwing1.uasset create mode 100644 Content/_Game/Assets/Sounds/WeaponSwings/HeavySwing2.uasset create mode 100644 Content/_Game/Assets/Sounds/WeaponSwings/StickSwing1.uasset create mode 100644 Content/_Game/Assets/Sounds/WeaponSwings/StickSwing2.uasset create mode 100644 Content/_Game/Assets/Sounds/WeaponSwings/StickSwing3.uasset create mode 100644 Content/_Game/Assets/Sounds/WeaponSwings/Swing1.uasset create mode 100644 Content/_Game/Assets/Sounds/WeaponSwings/Swing2.uasset create mode 100644 Content/_Game/Assets/Sounds/WeaponSwings/Swing3.uasset create mode 100644 Content/_Game/Assets/Sounds/WeaponSwings/Swing4.uasset create mode 100644 Content/_Game/Assets/Sounds/WeaponSwings/Swing5.uasset create mode 100644 Content/_Game/Assets/Sounds/WeaponSwings/WeaponSwing.uasset create mode 100644 Content/_Game/Enemies/Animations/EnemyAttack.uasset create mode 100644 Content/_Game/EnemyController/BTT_Attack.uasset create mode 100644 Content/_Game/HUD/CharacterHealthBar.uasset diff --git a/Content/ParagonGrux/Characters/Heroes/Grux/Meshes/Grux_Skeleton.uasset b/Content/ParagonGrux/Characters/Heroes/Grux/Meshes/Grux_Skeleton.uasset index bbddc3da..682efa5c 100644 --- a/Content/ParagonGrux/Characters/Heroes/Grux/Meshes/Grux_Skeleton.uasset +++ b/Content/ParagonGrux/Characters/Heroes/Grux/Meshes/Grux_Skeleton.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:35e50c562a22bd7c597cbbd5095a2cd93b8634f4e36086d8d34d7dc5c1391eb9 -size 67635 +oid sha256:106e9beb5cd50a30ebf8a4e94e2fcb7fe8b090b7f588acc7c58134cb195a8a75 +size 68822 diff --git a/Content/_Game/Assets/Sounds/WeaponSwings/AxeSwing1.uasset b/Content/_Game/Assets/Sounds/WeaponSwings/AxeSwing1.uasset new file mode 100644 index 00000000..d0d79ef0 --- /dev/null +++ b/Content/_Game/Assets/Sounds/WeaponSwings/AxeSwing1.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:92f8b6006df91500375d6190df13507184e827b03702a66153ea1b25290905aa +size 92510 diff --git a/Content/_Game/Assets/Sounds/WeaponSwings/AxeSwing2.uasset b/Content/_Game/Assets/Sounds/WeaponSwings/AxeSwing2.uasset new file mode 100644 index 00000000..054f2a40 --- /dev/null +++ b/Content/_Game/Assets/Sounds/WeaponSwings/AxeSwing2.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9f264773ca07b54c3608ae5b6c2da0a7fa327b2fe6aff4ae3ff7b89ff6c37881 +size 88874 diff --git a/Content/_Game/Assets/Sounds/WeaponSwings/AxeSwing3.uasset b/Content/_Game/Assets/Sounds/WeaponSwings/AxeSwing3.uasset new file mode 100644 index 00000000..baacdd8c --- /dev/null +++ b/Content/_Game/Assets/Sounds/WeaponSwings/AxeSwing3.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:13048759bce324f99f5185b02616ec0fc8317d36384ec3f92f4102af7789922f +size 78633 diff --git a/Content/_Game/Assets/Sounds/WeaponSwings/HeavySwing1.uasset b/Content/_Game/Assets/Sounds/WeaponSwings/HeavySwing1.uasset new file mode 100644 index 00000000..e0c34951 --- /dev/null +++ b/Content/_Game/Assets/Sounds/WeaponSwings/HeavySwing1.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1cfbd281dcd2a65fb636b604d94aa8a9767109f83ecbf30f37771717a02f8137 +size 147729 diff --git a/Content/_Game/Assets/Sounds/WeaponSwings/HeavySwing2.uasset b/Content/_Game/Assets/Sounds/WeaponSwings/HeavySwing2.uasset new file mode 100644 index 00000000..68fcb216 --- /dev/null +++ b/Content/_Game/Assets/Sounds/WeaponSwings/HeavySwing2.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:24279244061d509b5c58776790fe576811e129284e9b8507a0086aaabfd29278 +size 161100 diff --git a/Content/_Game/Assets/Sounds/WeaponSwings/StickSwing1.uasset b/Content/_Game/Assets/Sounds/WeaponSwings/StickSwing1.uasset new file mode 100644 index 00000000..056fc786 --- /dev/null +++ b/Content/_Game/Assets/Sounds/WeaponSwings/StickSwing1.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:48bc5450de93dcb3f82216d5bf04f450c39666d944915517ae842f7bb3112a16 +size 69426 diff --git a/Content/_Game/Assets/Sounds/WeaponSwings/StickSwing2.uasset b/Content/_Game/Assets/Sounds/WeaponSwings/StickSwing2.uasset new file mode 100644 index 00000000..e049423a --- /dev/null +++ b/Content/_Game/Assets/Sounds/WeaponSwings/StickSwing2.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8eba8f2d47ea7acdbd6d97ff0f8609307a37d3aae8035b2dc08faa5e2f653517 +size 74249 diff --git a/Content/_Game/Assets/Sounds/WeaponSwings/StickSwing3.uasset b/Content/_Game/Assets/Sounds/WeaponSwings/StickSwing3.uasset new file mode 100644 index 00000000..36d80c8c --- /dev/null +++ b/Content/_Game/Assets/Sounds/WeaponSwings/StickSwing3.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1de25945e7fdca398c3cf531ed47ce54d051f4891130b20eca3b09aa1152a719 +size 97508 diff --git a/Content/_Game/Assets/Sounds/WeaponSwings/Swing1.uasset b/Content/_Game/Assets/Sounds/WeaponSwings/Swing1.uasset new file mode 100644 index 00000000..423626ea --- /dev/null +++ b/Content/_Game/Assets/Sounds/WeaponSwings/Swing1.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:65cb0c0a0ce799fa2c9e1d009febb1217122b680c9880ca5db26342fdd3ac351 +size 91464 diff --git a/Content/_Game/Assets/Sounds/WeaponSwings/Swing2.uasset b/Content/_Game/Assets/Sounds/WeaponSwings/Swing2.uasset new file mode 100644 index 00000000..c7819036 --- /dev/null +++ b/Content/_Game/Assets/Sounds/WeaponSwings/Swing2.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9476f837fafa915957a5c1885a60156ebb9314d546606d45874e22e07ed66ba0 +size 116792 diff --git a/Content/_Game/Assets/Sounds/WeaponSwings/Swing3.uasset b/Content/_Game/Assets/Sounds/WeaponSwings/Swing3.uasset new file mode 100644 index 00000000..c415c177 --- /dev/null +++ b/Content/_Game/Assets/Sounds/WeaponSwings/Swing3.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d2ba82a75a65b2afecee4c46dccd855e91711e601d2f230b825acc1885dbb7ae +size 82054 diff --git a/Content/_Game/Assets/Sounds/WeaponSwings/Swing4.uasset b/Content/_Game/Assets/Sounds/WeaponSwings/Swing4.uasset new file mode 100644 index 00000000..938c98fb --- /dev/null +++ b/Content/_Game/Assets/Sounds/WeaponSwings/Swing4.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee0a3c78ea82c530031cc902c1982cd947c0f6e16a53bd2b428b48860b98563e +size 83243 diff --git a/Content/_Game/Assets/Sounds/WeaponSwings/Swing5.uasset b/Content/_Game/Assets/Sounds/WeaponSwings/Swing5.uasset new file mode 100644 index 00000000..6dd80e7c --- /dev/null +++ b/Content/_Game/Assets/Sounds/WeaponSwings/Swing5.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:071ed4b37e98da18fabce4b6837c888a29c05c8500a4b2fd4593802335e87362 +size 79486 diff --git a/Content/_Game/Assets/Sounds/WeaponSwings/WeaponSwing.uasset b/Content/_Game/Assets/Sounds/WeaponSwings/WeaponSwing.uasset new file mode 100644 index 00000000..6758e589 --- /dev/null +++ b/Content/_Game/Assets/Sounds/WeaponSwings/WeaponSwing.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f2bdc2363562b30300a5a776dc07ed25553a52c215990dbb86d4f029f4e12daa +size 10000 diff --git a/Content/_Game/Character/TwinBlast/TwinBlastCharacterBP.uasset b/Content/_Game/Character/TwinBlast/TwinBlastCharacterBP.uasset index 2aa57007..3769885b 100644 --- a/Content/_Game/Character/TwinBlast/TwinBlastCharacterBP.uasset +++ b/Content/_Game/Character/TwinBlast/TwinBlastCharacterBP.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f35bf0a98db5b13dffd385190efc53557db503b0b2c1d5981f2ca70f23c42ff9 -size 44814 +oid sha256:e3a140091e797fb2ae54369da7bf7987092628423dfdb9ce4fecf1da1ce178c9 +size 45451 diff --git a/Content/_Game/Enemies/Animations/EnemyAttack.uasset b/Content/_Game/Enemies/Animations/EnemyAttack.uasset new file mode 100644 index 00000000..98a9e405 --- /dev/null +++ b/Content/_Game/Enemies/Animations/EnemyAttack.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1800fef2f636a91e667cf5c6f37c326d48f9512cf348f1e629afeba0ba88dba3 +size 36893 diff --git a/Content/_Game/Enemies/Animations/EnemyHit.uasset b/Content/_Game/Enemies/Animations/EnemyHit.uasset index 74195cd9..1b498c74 100644 --- a/Content/_Game/Enemies/Animations/EnemyHit.uasset +++ b/Content/_Game/Enemies/Animations/EnemyHit.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9cd4fee853ead2ae252902c63c6977e30c9e3047954fd502ba8b27b086645f34 -size 14599 +oid sha256:a6d4f71b4233b843ad62c71eb9b5d60f2a3b92fa759f45d07743221cbac31924 +size 16371 diff --git a/Content/_Game/Enemies/EnemyBP.uasset b/Content/_Game/Enemies/EnemyBP.uasset index 0045e1ce..63d4ee3c 100644 --- a/Content/_Game/Enemies/EnemyBP.uasset +++ b/Content/_Game/Enemies/EnemyBP.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:afc1ca0b48635cfef741333769d512d723ca3f7571916815d28c51c26afd31ac -size 132582 +oid sha256:6bae38e1675b163348fed4a1e916fd6a68eeef1587449307018376b2cfc6e5e2 +size 134062 diff --git a/Content/_Game/Enemies/GruxAnimBP.uasset b/Content/_Game/Enemies/GruxAnimBP.uasset index 459a37b2..5d54c2f1 100644 --- a/Content/_Game/Enemies/GruxAnimBP.uasset +++ b/Content/_Game/Enemies/GruxAnimBP.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:552c7eb2f715478a0e787e82c170338e086d2cf4af4ec131bcea0236f654a124 -size 87718 +oid sha256:8e9e0e2ec5cda94f9b58c378e7683ba45e1a77838e9ddbbe8aec647e9333750a +size 123136 diff --git a/Content/_Game/EnemyController/BTT_Attack.uasset b/Content/_Game/EnemyController/BTT_Attack.uasset new file mode 100644 index 00000000..4bca475c --- /dev/null +++ b/Content/_Game/EnemyController/BTT_Attack.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2dae32088fb1d997f8d2be3245d7b6e561c01cd2c5085f93a5b41b57860bec2f +size 26779 diff --git a/Content/_Game/EnemyController/EnemyBehaviorTree.uasset b/Content/_Game/EnemyController/EnemyBehaviorTree.uasset index 11fb98f3..5fcde49d 100644 --- a/Content/_Game/EnemyController/EnemyBehaviorTree.uasset +++ b/Content/_Game/EnemyController/EnemyBehaviorTree.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:11ff4b9238b0193a8f98f84b2a2bc67ba683bde7a6d0a8d417de0b2f9cf1e081 -size 13198 +oid sha256:b179280f2e58e1e3525378a1317ed9c8e56fcd2c8d9eb4f8ebaf2c32e55bd22d +size 20979 diff --git a/Content/_Game/EnemyController/EnemyBlackboard.uasset b/Content/_Game/EnemyController/EnemyBlackboard.uasset index 5bb6c9d1..3558f588 100644 --- a/Content/_Game/EnemyController/EnemyBlackboard.uasset +++ b/Content/_Game/EnemyController/EnemyBlackboard.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:593304d55215bd4486d74c0aa1a76a3404473831416cca2680d3740640078517 -size 3565 +oid sha256:db02a2547f0e0c899923180e90ef5d5acdbda469f84c91f8df6f47dcb242205a +size 3857 diff --git a/Content/_Game/GameMode/ShooterGameModeBaseBP.uasset b/Content/_Game/GameMode/ShooterGameModeBaseBP.uasset index 4101dec8..0b6959cc 100644 --- a/Content/_Game/GameMode/ShooterGameModeBaseBP.uasset +++ b/Content/_Game/GameMode/ShooterGameModeBaseBP.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ee458bc2adee8da52efb3a45b05a55d6c94765298ab7f94f66e3cf6e1cff8065 -size 20847 +oid sha256:d7865e61b7bf5c193741780ca5e78b64c8ffb4181c1788c863491019c3db9b98 +size 20850 diff --git a/Content/_Game/HUD/AmmoCountBP.uasset b/Content/_Game/HUD/AmmoCountBP.uasset index af4fada5..1976ca3e 100644 --- a/Content/_Game/HUD/AmmoCountBP.uasset +++ b/Content/_Game/HUD/AmmoCountBP.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ada80f0faf968257307711c2fdb2c01648fe23483f12327cda012a5b25a47265 -size 106092 +oid sha256:2f4d1d6edaa193b393e5e90eb135f55ed213dacdb92ac10d0aa1b75b0da8ddd5 +size 104910 diff --git a/Content/_Game/HUD/CharacterHealthBar.uasset b/Content/_Game/HUD/CharacterHealthBar.uasset new file mode 100644 index 00000000..d488da3d --- /dev/null +++ b/Content/_Game/HUD/CharacterHealthBar.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ff03cba7d6e94f22d24349861e88f1e425adf2dd86667a16f0ccddf57b8399d4 +size 59216 diff --git a/Content/_Game/HUD/EnemyHealthBarBP.uasset b/Content/_Game/HUD/EnemyHealthBarBP.uasset index 19b825cb..ef02fb20 100644 --- a/Content/_Game/HUD/EnemyHealthBarBP.uasset +++ b/Content/_Game/HUD/EnemyHealthBarBP.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7c5c02d4e244564fbb503b7ff2dcd9eb0c45c1c383c396a1bac9ef3c932508ff -size 46652 +oid sha256:b9f91c2fcef3d0ea8c4c1aa58a0e13720e9602fc6c11b777dae7bf1654008c04 +size 45858 diff --git a/Content/_Game/HUD/ShooterHUDOverlayBP.uasset b/Content/_Game/HUD/ShooterHUDOverlayBP.uasset index 64142b3a..8215c484 100644 --- a/Content/_Game/HUD/ShooterHUDOverlayBP.uasset +++ b/Content/_Game/HUD/ShooterHUDOverlayBP.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:591b7464db29528f51663ca5dfa348250095bd99541491b5f30b941634f59794 -size 30217 +oid sha256:7025b1a8a76eef048fea6a5faf2fcb5e224f4023d4baebb680397f30a82b3cae +size 27170 diff --git a/Content/_Game/HUD/WeaponSlot.uasset b/Content/_Game/HUD/WeaponSlot.uasset index 70417194..2b78b7de 100644 --- a/Content/_Game/HUD/WeaponSlot.uasset +++ b/Content/_Game/HUD/WeaponSlot.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7f9723ba91f3458aeb55e6fcfe3f4309bef8ee576a4bc4abd15599227bcb1f75 -size 343817 +oid sha256:83589bd62ffb79fcd98fe7d04dc89c05e46a9e8609bc481a639305dbd40db21a +size 340775 diff --git a/Content/_Game/Maps/DefaultMap.umap b/Content/_Game/Maps/DefaultMap.umap index 8134432b..0fad0e41 100644 --- a/Content/_Game/Maps/DefaultMap.umap +++ b/Content/_Game/Maps/DefaultMap.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:822554c9946ebf2222f444df9837ddb0735ac222840db2cd4861afdf30579c54 -size 3652087 +oid sha256:1394f2e7127bc77feac2564e98a89a6d569d77f8967c0784ddc67b1f14cfd6e1 +size 3652563 diff --git a/Source/Shooter/Enemy.cpp b/Source/Shooter/Enemy.cpp index 3db64b69..e24e1b7f 100644 --- a/Source/Shooter/Enemy.cpp +++ b/Source/Shooter/Enemy.cpp @@ -13,6 +13,8 @@ #include "BehaviorTree/BlackboardComponent.h" #include "Components/SphereComponent.h" #include "ShooterCharacter.h" +#include "Components/BoxComponent.h" +#include "Components/CapsuleComponent.h" // Sets default values AEnemy::AEnemy() : @@ -24,7 +26,12 @@ AEnemy::AEnemy() : bCanHitReact(true), HitNumberDestroyTime(1.5f), bStunned(false), - StunChance(.5f) + StunChance(.5f), + AttackLFast(TEXT("AttackLFast")), + AttackRFast(TEXT("AttackRFast")), + AttackL(TEXT("AttackL")), + AttackR(TEXT("AttackR")), + BaseDamage(20.f) { // 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; @@ -32,6 +39,17 @@ AEnemy::AEnemy() : // Create the Agro Sphere AgroSphere = CreateDefaultSubobject(TEXT("AgroSphere")); AgroSphere->SetupAttachment(GetRootComponent()); + + // Create the Combat Range Sphere + CombatRangeSphere = CreateDefaultSubobject(TEXT("CombatRangeSphere")); + CombatRangeSphere->SetupAttachment(GetRootComponent()); + + // Construct left and right weapon collision boxes + LeftWeaponCollision = CreateDefaultSubobject(TEXT("Left Weapon Box")); + LeftWeaponCollision->SetupAttachment(GetMesh(), FName("LeftWeaponBone")); + + RightWeaponCollision = CreateDefaultSubobject(TEXT("Right Weapon Box")); + RightWeaponCollision->SetupAttachment(GetMesh(), FName("RightWeaponBone")); } // Called when the game starts or when spawned @@ -40,8 +58,27 @@ void AEnemy::BeginPlay() Super::BeginPlay(); AgroSphere->OnComponentBeginOverlap.AddDynamic(this, &AEnemy::AgroSphereOverlap); + CombatRangeSphere->OnComponentBeginOverlap.AddDynamic(this, &AEnemy::CombatRangeOverlap); + CombatRangeSphere->OnComponentEndOverlap.AddDynamic(this, &AEnemy::CombatRangeEndOverlap); + + // Bind functions to overlap events for weapon boxes + LeftWeaponCollision->OnComponentBeginOverlap.AddDynamic(this, &AEnemy::OnLeftWeaponOverlap); + RightWeaponCollision->OnComponentBeginOverlap.AddDynamic(this, &AEnemy::OnRightWeaponOverlap); + + // Set collision presets for weapon boxes + LeftWeaponCollision->SetCollisionEnabled(ECollisionEnabled::NoCollision); + LeftWeaponCollision->SetCollisionObjectType(ECollisionChannel::ECC_WorldDynamic); + LeftWeaponCollision->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore); + LeftWeaponCollision->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Overlap); + + RightWeaponCollision->SetCollisionEnabled(ECollisionEnabled::NoCollision); + RightWeaponCollision->SetCollisionObjectType(ECollisionChannel::ECC_WorldDynamic); + RightWeaponCollision->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore); + RightWeaponCollision->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Overlap); GetMesh()->SetCollisionResponseToChannel(ECollisionChannel::ECC_Visibility, ECollisionResponse::ECR_Block); + GetMesh()->SetCollisionResponseToChannel(ECollisionChannel::ECC_Camera, ECollisionResponse::ECR_Ignore); + GetCapsuleComponent()->SetCollisionResponseToChannel(ECollisionChannel::ECC_Camera, ECollisionResponse::ECR_Ignore); // Get the AI Controller EnemyController = Cast(GetController()); @@ -75,7 +112,8 @@ void AEnemy::PlayHitMontage(FName Section, float PlayRate) { if (!bCanHitReact) return; - if (UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance()) + UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance(); + if (AnimInstance && HitMontage) { AnimInstance->Montage_Play(HitMontage, PlayRate); AnimInstance->Montage_JumpToSection(Section, HitMontage); @@ -140,6 +178,104 @@ void AEnemy::SetStunned(bool Stunned) EnemyController->GetBlackboardComponent()->SetValueAsBool(TEXT("Stunned"), Stunned); } +void AEnemy::CombatRangeOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) +{ + if (!OtherActor) return; + if (Cast(OtherActor) == nullptr) return; + + bInAttackRange = true; + + if (!EnemyController) return; + EnemyController->GetBlackboardComponent()->SetValueAsBool(TEXT("InAttackRange"), true); + UE_LOG(LogTemp, Warning, TEXT("overlap player")); +} + +void AEnemy::CombatRangeEndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) +{ + if (!OtherActor) return; + if (Cast(OtherActor) == nullptr) return; + + bInAttackRange = false; + + if (!EnemyController) return; + EnemyController->GetBlackboardComponent()->SetValueAsBool(TEXT("InAttackRange"), false); + UE_LOG(LogTemp, Warning, TEXT("end overlap player")); +} + +void AEnemy::PlayAttackMontage(FName Section, float PlayRate) +{ + UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance(); + if (AnimInstance && AttackMontage) + { + AnimInstance->Montage_Play(AttackMontage, PlayRate); + AnimInstance->Montage_JumpToSection(Section, AttackMontage); + } +} + +FName AEnemy::GetAttackSectionName() const +{ + switch (FMath::RandRange(1, 4)) + { + case 1: + return AttackLFast; + case 2: + return AttackRFast; + case 3: + return AttackL; + case 4: + return AttackR; + default: + return AttackLFast; + } +} + +void AEnemy::DoDamage(AActor* Victim) +{ + if (!Victim) return; + if (auto const Character = Cast(Victim)) + { + UGameplayStatics::ApplyDamage(Character, BaseDamage, EnemyController, this, UDamageType::StaticClass()); + if (USoundCue* MeleeImpactSound = Character->GetMeleeImpactSound()) + { + UGameplayStatics::PlaySoundAtLocation(this, MeleeImpactSound, GetActorLocation()); + } + } +} + +void AEnemy::OnLeftWeaponOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) +{ + DoDamage(OtherActor); +} + +void AEnemy::OnRightWeaponOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) +{ + DoDamage(OtherActor); +} + +void AEnemy::ActivateLeftWeapon() +{ + LeftWeaponCollision->SetCollisionEnabled(ECollisionEnabled::QueryOnly); +} + +void AEnemy::DeactivateLeftWeapon() +{ + LeftWeaponCollision->SetCollisionEnabled(ECollisionEnabled::NoCollision); +} + +void AEnemy::ActivateRightWeapon() +{ + RightWeaponCollision->SetCollisionEnabled(ECollisionEnabled::QueryOnly); +} + +void AEnemy::DeactivateRightWeapon() +{ + RightWeaponCollision->SetCollisionEnabled(ECollisionEnabled::NoCollision); +} + // Called every frame void AEnemy::Tick(float DeltaTime) { diff --git a/Source/Shooter/Enemy.h b/Source/Shooter/Enemy.h index dc918075..fc530053 100644 --- a/Source/Shooter/Enemy.h +++ b/Source/Shooter/Enemy.h @@ -13,6 +13,7 @@ class UAnimMontage; class UBehaviorTree; class AEnemyController; class USphereComponent; +class UBoxComponent; UCLASS() class SHOOTER_API AEnemy : public ACharacter, public IBulletHitInterface @@ -48,6 +49,12 @@ protected: void UpdateHitNumbers(); + UFUNCTION(BlueprintCallable) + float GetHealth() const { return Health; } + + UFUNCTION(BlueprintCallable) + float GetMaxHealth() const { return MaxHealth; } + /** Called when something overlaps with the agro sphere */ UFUNCTION() void AgroSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, @@ -56,6 +63,43 @@ protected: UFUNCTION(BlueprintCallable) void SetStunned(bool Stunned); + + UFUNCTION() + void CombatRangeOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, + const FHitResult& SweepResult); + + UFUNCTION() + void CombatRangeEndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex); + + UFUNCTION(BlueprintCallable) + void PlayAttackMontage(FName Section, float PlayRate = 1.0f); + + UFUNCTION(BlueprintPure) + FName GetAttackSectionName() const; + + UFUNCTION() + void OnLeftWeaponOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, + const FHitResult& SweepResult); + UFUNCTION() + void OnRightWeaponOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, + const FHitResult& SweepResult); + + // Activate/Deactivate collision for weapon boxes + UFUNCTION(BlueprintCallable) + void ActivateLeftWeapon(); + UFUNCTION(BlueprintCallable) + void DeactivateLeftWeapon(); + + UFUNCTION(BlueprintCallable) + void ActivateRightWeapon(); + UFUNCTION(BlueprintCallable) + void DeactivateRightWeapon(); + + void DoDamage(AActor* Victim); private: /** Particles to spawn when hit by bullets */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true)) @@ -119,7 +163,7 @@ private: AEnemyController* EnemyController; /** Overlap sphere for when the enemy becomes hostile */ - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Behavior Tree", meta = (AllowPrivateAccess = true)) + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true)) USphereComponent* AgroSphere; /** True when playing the get hit animation */ @@ -129,6 +173,35 @@ private: /** Chance of being stunned. 0: no stun chance, 1: 100% stun chance */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true)) float StunChance; + + /** True when in attack rangel; time to attack */ + UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true)) + bool bInAttackRange; + + /** Overlap sphere for attack range */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true)) + USphereComponent* CombatRangeSphere; + + /** Montage containing different attacks */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true)) + UAnimMontage* AttackMontage; + + /** The 4 attack montage section names */ + FName AttackLFast; + FName AttackRFast; + FName AttackL; + FName AttackR; + + /** Collision volume for the left weapon */ + UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true)) + UBoxComponent* LeftWeaponCollision; + + /** Collision volume for the right weapon */ + UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true)) + UBoxComponent* RightWeaponCollision; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true)) + float BaseDamage; public: // Called every frame virtual void Tick(float DeltaTime) override; diff --git a/Source/Shooter/ShooterCharacter.cpp b/Source/Shooter/ShooterCharacter.cpp index 71b97964..bd751a39 100644 --- a/Source/Shooter/ShooterCharacter.cpp +++ b/Source/Shooter/ShooterCharacter.cpp @@ -77,7 +77,9 @@ AShooterCharacter::AShooterCharacter() : PickupSoundResetTime(0.2f), EquipSoundResetTime(0.2f), // Icon animation property - HighlightedSlot(-1) + HighlightedSlot(-1), + Health(100.f), + MaxHealth(100.f) { // 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; @@ -202,6 +204,23 @@ void AShooterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCo PlayerInputComponent->BindAction("5Key", IE_Pressed, this, &AShooterCharacter::Key5Pressed); } +float AShooterCharacter::TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent, AController* EventInstigator, + AActor* DamageCauser) +{ + float DamageInflicted = DamageAmount; + if (Health - DamageAmount <= 0.f) + { + DamageInflicted = Health; + Health = 0.f; + //Die(); + } + else + { + Health -= DamageAmount; + } + return DamageInflicted; +} + // Called every frame void AShooterCharacter::Tick(float DeltaTime) { diff --git a/Source/Shooter/ShooterCharacter.h b/Source/Shooter/ShooterCharacter.h index 76c533ce..a0f3cffe 100644 --- a/Source/Shooter/ShooterCharacter.h +++ b/Source/Shooter/ShooterCharacter.h @@ -63,6 +63,8 @@ public: // Called to bind functionality to input virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; + virtual float TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) override; + protected: // Called when the game starts or when spawned virtual void BeginPlay() override; @@ -486,7 +488,18 @@ private: /** The index for the currently highlighted slot */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = true)) int32 HighlightedSlot; + + /** Character health */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true)) + float Health; + + /** Character max health */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true)) + float MaxHealth; + /** Sound made when character gets hit by a melee attack */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true)) + USoundCue* MeleeImpactSound; public: /* Returns CameraBoom SubObject */ FORCEINLINE USpringArmComponent* GetCameraBoom() const { return CameraBoom; } @@ -528,5 +541,20 @@ public: void UnhighlightInventorySlot(); - FORCEINLINE AWeapon* GetEquippedWeapon() const { return EquippedWeapon; } + UFUNCTION(BlueprintCallable) + AWeapon* GetEquippedWeapon() const { return EquippedWeapon; } + + UFUNCTION(BlueprintCallable) + TMap GetAmmoMap() const { return AmmoMap; } + + UFUNCTION(BlueprintCallable) + TArray GetInventory() const { return Inventory; } + + UFUNCTION(BlueprintCallable) + float GetHealth() const { return Health; } + + UFUNCTION(BlueprintCallable) + float GetMaxHealth() const { return MaxHealth; } + + FORCEINLINE USoundCue* GetMeleeImpactSound() const { return MeleeImpactSound; } };