D1/Source/D1/CombatCharacter.h

199 lines
7.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "InputActionValue.h"
#include "InputAction.h"
#include "Interface/CombatInterface.h"
#include "Components/StateManagerComponent.h"
#include "Components/StatsComponent.h"
#include "Definitions/GameEnums.h"
#include "CombatCharacter.generated.h"
UCLASS(config=Game)
class ACombatCharacter : public ACharacter, public ICombatInterface
{
GENERATED_BODY()
/** Camera boom positioning the camera behind the character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class USpringArmComponent* CameraBoom;
/** Follow camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class UCameraComponent* FollowCamera;
/** MappingContext */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
class UInputMappingContext* DefaultMappingContext;
/** Jump Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
class UInputAction* JumpAction;
/** Move Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
class UInputAction* MoveAction;
/** Look Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
class UInputAction* LookAction;
/* Interact Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
class UInputAction* InteractAction;
/* ToggleCombat Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
class UInputAction* ToggleCombatAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
class UInputAction* LightAttackAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
class UInputAction* HeavyAttackAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
class UInputAction* DodgeAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
class UInputAction* ToggleWalkAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
class UInputAction* SprintAction;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Input, meta = (AllowPrivateAccess = "true"))
float ChargeAttackTime;
public:
ACombatCharacter();
public:
/** Returns CameraBoom subobject **/
FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
/** Returns FollowCamera subobject **/
FORCEINLINE class UCameraComponent* GetFollowCamera() const { return FollowCamera; }
protected:
// APawn interface
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
virtual void BeginPlay() override;
virtual float TakeDamage(float Damage, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) override;
public:
// Inherited via ICombatInterface
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void ContinueAttack();
virtual void ContinueAttack_Implementation() override;
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void ResetAttack();
virtual void ResetAttack_Implementation() override;
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void ResetCombat();
virtual void ResetCombat_Implementation() override;
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
FRotator GetDesiredRotation();
virtual FRotator GetDesiredRotation_Implementation() override;
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
bool CanReceiveDamage();
virtual bool CanReceiveDamage_Implementation() override;
protected:
//Input Funcs
void Move(const FInputActionValue& Value);
void Look(const FInputActionValue& Value);
void Jumping(const FInputActionValue& Value);
void Interact(const FInputActionValue& Value);
void ToggleCombat(const FInputActionValue& Value);
void LightAttack(const FInputActionValue& Value);
void LightChargeAttack(const FInputActionInstance& Instance);
void HeavyAttack(const FInputActionValue& Value);
void Dodge(const FInputActionValue& Value);
void ToggleWalk(const FInputActionValue& Value);
void StartSprint(const FInputActionValue& Value);
void StopSprint(const FInputActionValue& Value);
private://Delegate
void CharacterStateBegin(ECharacterState CharState);
void CharacterStateEnd(ECharacterState CharState);
void CharacterActionBegin(ECharacterAction CharAction);
void CharacterActionEnd(ECharacterAction CharAction);
void CharacterCurrentStatValueUpdated(EStats statType, float value);
private:
void ToggleCombatEvent();
void AttackEvent();
void ApplyHitReactionPhysicsVelocity(float InitialSpeed);
void EnableRagdoll();
void SetMovementSpeedMode(EMovementSpeedMode NewSpeedMode);
FORCEINLINE EMovementSpeedMode GetMovementSpeedMode() const { return MovementSpeedMode; }
bool ResetChargeAttack();
void DisableSprint();
void SprintStaminaCost();
private:
void PerformAttack(ECharacterAction attackType, int32 attackIndex);
void PerformDodge();
bool PerformAction(ECharacterState characterState, ECharacterAction characterAction, int32 montageIndex);
void PerformDeath();
protected:
bool CanPerformToggleCombat();
bool CanPerformAttack();
bool CanPerformDodge();
bool CanJumping();
bool CanReceiveHitReaction();
bool CanPerformSprint();
ECharacterAction GetDesiredAttackType();
public:
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Components", meta=(AllowPrivateAccess="true"))
TObjectPtr<class UCombatComponent> CombatComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Components", meta=(AllowPrivateAccess="true"))
TObjectPtr<UStateManagerComponent> StateManagerComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Components", meta=(AllowPrivateAccess="true"))
TObjectPtr<UStatsComponent> StatsComponent;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Weapon", meta = (AllowPrivateAccess = "true"))
TSubclassOf<class ABaseEquippable> Weapon;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hit", meta = (AllowPrivateAccess = "true"))
FName PelvisBoneName;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hit", meta = (AllowPrivateAccess = "true"))
TObjectPtr<UAnimMontage> HitMontage;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hit", meta = (AllowPrivateAccess = "true"))
TObjectPtr<class USoundBase> HitSound;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Hit", meta = (AllowPrivateAccess = "true"))
TObjectPtr<class UParticleSystem> HitEmitter;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MovementSpeed", meta = (AllowPrivateAccess = "true"))
EMovementSpeedMode MovementSpeedMode;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MovementSpeed", meta = (AllowPrivateAccess = "true"))
float WalkingSpeed;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MovementSpeed", meta = (AllowPrivateAccess = "true"))
float JoggingSpeed;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MovementSpeed", meta = (AllowPrivateAccess = "true"))
float SprintSpeed;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats", meta = (AllowPrivateAccess = "true"))
float Health;
private:
FTimerHandle StaminaTimerHandle;
private:
bool IsHeavyAttack;
float AttackHeldTime;
bool bAttackCharged;
};