From cc21d38a0fa03b5ab0e467576b7fb3997561ae49 Mon Sep 17 00:00:00 2001 From: baz Date: Tue, 27 Feb 2024 21:44:07 +0000 Subject: [PATCH] Add Weapon Cooldown Decorator --- Content/Enemy/BT_Attacking_State.uasset | 4 ++-- .../Nakatomi/Decorators/BTDWeaponCooldown.cpp | 23 +++++++++++++++++++ .../Nakatomi/Decorators/BTDWeaponCooldown.h | 19 +++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 Source/Nakatomi/Decorators/BTDWeaponCooldown.cpp create mode 100644 Source/Nakatomi/Decorators/BTDWeaponCooldown.h diff --git a/Content/Enemy/BT_Attacking_State.uasset b/Content/Enemy/BT_Attacking_State.uasset index e84ca7f..ad8ad93 100644 --- a/Content/Enemy/BT_Attacking_State.uasset +++ b/Content/Enemy/BT_Attacking_State.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8a5236e64bd434f6de908e6e96b843882a5b2b94caf1301b2473f05100a85d26 -size 25814 +oid sha256:d2d10560f8fc5d39c97cae7f1db8463469d5723c0966a4ee8a69fe5f986a9f0a +size 25779 diff --git a/Source/Nakatomi/Decorators/BTDWeaponCooldown.cpp b/Source/Nakatomi/Decorators/BTDWeaponCooldown.cpp new file mode 100644 index 0000000..3855d0b --- /dev/null +++ b/Source/Nakatomi/Decorators/BTDWeaponCooldown.cpp @@ -0,0 +1,23 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "../Decorators/BTDWeaponCooldown.h" + +#include "AIController.h" +#include "Nakatomi/EnemyCharacter.h" + +void UBTDWeaponCooldown::TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds) +{ + AEnemyCharacter* EnemyCharacter = Cast(OwnerComp.GetAIOwner()->GetPawn()); + + if (EnemyCharacter && EnemyCharacter->GetCurrentWeapon()) + { + const float Cooldown = EnemyCharacter->GetCurrentWeapon()->GetWeaponProperties()->WeaponCooldown; + if (CoolDownTime != Cooldown) + { + CoolDownTime = Cooldown; + } + } + + Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds); +} diff --git a/Source/Nakatomi/Decorators/BTDWeaponCooldown.h b/Source/Nakatomi/Decorators/BTDWeaponCooldown.h new file mode 100644 index 0000000..5367200 --- /dev/null +++ b/Source/Nakatomi/Decorators/BTDWeaponCooldown.h @@ -0,0 +1,19 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/Decorators/BTDecorator_Cooldown.h" +#include "BTDWeaponCooldown.generated.h" + +/** + * + */ +UCLASS() +class NAKATOMI_API UBTDWeaponCooldown : public UBTDecorator_Cooldown +{ + GENERATED_BODY() + +protected: + virtual void TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds) override; +};