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