Update Characters to Implement Damage Control
This commit is contained in:
parent
8ef1ecf488
commit
d4b7c4b2d6
@ -3,6 +3,7 @@
|
||||
|
||||
#include "CompanionCharacter.h"
|
||||
|
||||
#include "AI_CompanionController.h"
|
||||
#include "Perception/AIPerceptionStimuliSourceComponent.h"
|
||||
#include "Perception/AISense_Sight.h"
|
||||
|
||||
@ -38,6 +39,19 @@ UBehaviorTree* ACompanionCharacter::GetBehaviorTree() const
|
||||
return BehaviorTree;
|
||||
}
|
||||
|
||||
void ACompanionCharacter::TakeDamage(float DamageAmount)
|
||||
{
|
||||
CurrentHealth -= DamageAmount;
|
||||
if (CurrentHealth <= 0)
|
||||
{
|
||||
CurrentHealth = 0;
|
||||
UE_LOG(LogTemp, Warning, TEXT("Companion is dead"));
|
||||
|
||||
const AAI_CompanionController* AIController = Cast<AAI_CompanionController>(GetController());
|
||||
AIController->GetBrainComponent()->StopLogic("Companion is dead");
|
||||
}
|
||||
}
|
||||
|
||||
void ACompanionCharacter::SetupStimuliSourceComponent()
|
||||
{
|
||||
StimuliSourceComponent = CreateDefaultSubobject<UAIPerceptionStimuliSourceComponent>(TEXT("Stimuli Source Component"));
|
||||
|
@ -16,6 +16,13 @@ public:
|
||||
// Sets default values for this character's properties
|
||||
ACompanionCharacter();
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Stats")
|
||||
float CurrentHealth = 100.0f;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Stats")
|
||||
float MaxHealth = 100.0f;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Stats")
|
||||
float DefaultHealth = 100.0f;
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
@ -32,6 +39,9 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "AI")
|
||||
UBehaviorTree* GetBehaviorTree() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Damage Control")
|
||||
void TakeDamage(float DamageAmount);
|
||||
|
||||
private:
|
||||
class UAIPerceptionStimuliSourceComponent* StimuliSourceComponent;
|
||||
void SetupStimuliSourceComponent();
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "EnemyCharacter.h"
|
||||
|
||||
#include "AI_EnemyController.h"
|
||||
#include "Perception/AIPerceptionStimuliSourceComponent.h"
|
||||
#include "Perception/AISense_Sight.h"
|
||||
|
||||
@ -40,6 +41,19 @@ UBehaviorTree* AEnemyCharacter::GetBehaviorTree() const
|
||||
return BehaviorTree;
|
||||
}
|
||||
|
||||
void AEnemyCharacter::TakeDamage(float DamageAmount)
|
||||
{
|
||||
CurrentHealth -= DamageAmount;
|
||||
if (CurrentHealth <= 0)
|
||||
{
|
||||
CurrentHealth = 0;
|
||||
UE_LOG(LogTemp, Warning, TEXT("Enemy is dead"));
|
||||
|
||||
const AAI_EnemyController* AIController = Cast<AAI_EnemyController>(GetController());
|
||||
AIController->GetBrainComponent()->StopLogic("Enemy is dead");
|
||||
}
|
||||
}
|
||||
|
||||
void AEnemyCharacter::SetupStimuliSourceComponent()
|
||||
{
|
||||
StimuliSourceComponent = CreateDefaultSubobject<UAIPerceptionStimuliSourceComponent>(TEXT("Stimuli Source Component"));
|
||||
|
@ -16,12 +16,20 @@ public:
|
||||
// Sets default values for this character's properties
|
||||
AEnemyCharacter();
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Stats")
|
||||
float CurrentHealth = 100.0f;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Stats")
|
||||
float MaxHealth = 100.0f;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Stats")
|
||||
float DefaultHealth = 100.0f;
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI")
|
||||
UBehaviorTree* BehaviorTree;
|
||||
|
||||
public:
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
@ -32,6 +40,9 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "AI")
|
||||
UBehaviorTree* GetBehaviorTree() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Damage Control")
|
||||
void TakeDamage(float DamageAmount);
|
||||
|
||||
private:
|
||||
class UAIPerceptionStimuliSourceComponent* StimuliSourceComponent;
|
||||
void SetupStimuliSourceComponent();
|
||||
|
@ -100,13 +100,21 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent*
|
||||
void AEndlessVendettaCharacter::SetCrouch()
|
||||
{
|
||||
Crouch();
|
||||
GLog->Log("Crouching");
|
||||
}
|
||||
|
||||
void AEndlessVendettaCharacter::SetUnCrouch()
|
||||
{
|
||||
UnCrouch();
|
||||
GLog->Log("UnCrouching");
|
||||
}
|
||||
|
||||
void AEndlessVendettaCharacter::TakeDamage(float DamageAmount)
|
||||
{
|
||||
CurrentHealth -= DamageAmount;
|
||||
if (CurrentHealth <= 0)
|
||||
{
|
||||
CurrentHealth = 0;
|
||||
UE_LOG(LogTemp, Warning, TEXT("Player is dead"));
|
||||
}
|
||||
}
|
||||
|
||||
void AEndlessVendettaCharacter::ToggleRecon()
|
||||
|
@ -68,6 +68,13 @@ class AEndlessVendettaCharacter : public ACharacter
|
||||
public:
|
||||
AEndlessVendettaCharacter();
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Stats")
|
||||
float CurrentHealth = 100.0f;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Stats")
|
||||
float MaxHealth = 100.0f;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Stats")
|
||||
float DefaultHealth = 100.0f;
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay();
|
||||
|
||||
@ -99,7 +106,6 @@ public:
|
||||
TSubclassOf<ABaseWeaponClass> SecondaryWeaponClass;
|
||||
|
||||
ABaseWeaponClass* PrimaryWeapon;
|
||||
|
||||
ABaseWeaponClass* SecondaryWeapon;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Weapons")
|
||||
@ -113,11 +119,9 @@ protected:
|
||||
void Look(const FInputActionValue& Value);
|
||||
|
||||
void ToggleRecon();
|
||||
|
||||
void ToggleCombat();
|
||||
|
||||
void EquipPrimary();
|
||||
|
||||
void EquipSecondary();
|
||||
|
||||
//Called from Player BluePrints
|
||||
@ -138,4 +142,7 @@ public:
|
||||
USkeletalMeshComponent* GetMesh1P() const { return Mesh1P; }
|
||||
/** Returns FirstPersonCameraComponent Sub-object **/
|
||||
UCameraComponent* GetFirstPersonCameraComponent() const { return FirstPersonCameraComponent; }
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Damage Control")
|
||||
void TakeDamage(float DamageAmount);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user