Initial Commit - Lesson 31 (Commit #1)

This commit is contained in:
Norman Lansing
2026-02-24 22:39:26 -05:00
commit 9591e7f503
4631 changed files with 1019212 additions and 0 deletions

View File

@@ -0,0 +1,149 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "GameplayTagContainer.h"
#include "Interfaces/PlayerInterface.h"
#include "ShooterTypes/ShooterTypes.h"
#include "ShooterCharacter.generated.h"
class UEliminationComponent;
class UShooterHealthComponent;
class UShooterOverlay;
class UShooterHUDComponent;
class USpringArmComponent;
class UCameraComponent;
class UWeaponData;
class AWeapon;
class UCombatComponent;
class UInputAction;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FWeaponFirstReplicated, AWeapon*, Weapon);
UCLASS()
class FPSTEMPLATE_API AShooterCharacter : public ACharacter, public IPlayerInterface
{
GENERATED_BODY()
public:
AShooterCharacter();
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
virtual void PossessedBy(AController* NewController) override;
virtual void Tick(float DeltaTime) override;
virtual void OnRep_PlayerState() override;
virtual void BeginDestroy() override;
virtual void UnPossessed() override;
FRotator StartingAimRotation;
UPROPERTY(BlueprintReadOnly)
float AO_Yaw;
float InterpAO_Yaw;
UPROPERTY(BlueprintReadOnly)
float MovementOffsetYaw;
UPROPERTY(BlueprintReadOnly)
FTransform FABRIK_SocketTransform;
UPROPERTY(BlueprintReadOnly)
ETurningInPlace TurningStatus;
void TurnInPlace(float DeltaTime);
/** PlayerInterface */
virtual FName GetWeaponAttachPoint_Implementation(const FGameplayTag& WeaponType) const override;
virtual USkeletalMeshComponent* GetSpecifcPawnMesh_Implementation(bool WantFirstPerson) const override;
virtual USkeletalMeshComponent* GetPawnMesh_Implementation() const override;
virtual bool IsFirstPerson_Implementation() const override;
virtual bool DoDamage_Implementation(float DamageAmount, AActor* DamageInstigator) override;
virtual void AddAmmo_Implementation(const FGameplayTag& WeaponType, int32 AmmoAmount) override;
virtual AWeapon* GetCurrentWeapon_Implementation() override;
virtual int32 GetCarriedAmmo_Implementation() override;
virtual void InitializeWidgets_Implementation() override;
virtual void Notify_CycleWeapon_Implementation() override;
virtual void Notify_ReloadWeapon_Implementation() override;
virtual void Initiate_Crouch_Implementation() override;
virtual void Initiate_Jump_Implementation() override;
virtual bool IsDeadOrDying_Implementation() override;
virtual void WeaponReplicated_Implementation() override;
/** <end> PlayerInterface */
UFUNCTION(BlueprintCallable)
FRotator GetFixedAimRotation() const;
bool bWeaponFirstReplicated;
UPROPERTY(BlueprintAssignable)
FWeaponFirstReplicated OnWeaponFirstReplicated;
protected:
virtual void BeginPlay() override;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Aiming")
float DefaultFieldOfView;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Death")
TArray<TObjectPtr<UAnimMontage>> DeathMontages;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "HitReact")
TArray<TObjectPtr<UAnimMontage>> HitReacts;
UFUNCTION(BlueprintImplementableEvent)
void OnAim(bool bIsAiming);
UFUNCTION(BlueprintImplementableEvent)
void DeathEffects(AActor* DeathInstigator, UAnimMontage* DeathMontage);
UFUNCTION(NetMulticast, Reliable)
void Multicast_HitReact(int32 MontageIndex);
private:
void Input_CycleWeapon();
void Input_FireWeapon_Pressed();
void Input_FireWeapon_Released();
void Input_ReloadWeapon();
void Input_Aim_Pressed();
void Input_Aim_Released();
bool IsLocalFirstPerson() const;
UFUNCTION()
void OnDeathStarted(AActor* DyingActor, AActor* DeathInstigator);
/** 1st person view */
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Mesh, meta = (AllowPrivateAccess = "true"))
TObjectPtr<USkeletalMeshComponent> Mesh1P;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
TObjectPtr<UCombatComponent> Combat;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
TObjectPtr<UShooterHealthComponent> HealthComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
TObjectPtr<UEliminationComponent> EliminationComponent;
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
TObjectPtr<USpringArmComponent> SpringArm;
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
TObjectPtr<UCameraComponent> FirstPersonCamera;
UPROPERTY(EditAnywhere, Category="Input")
TObjectPtr<UInputAction> CycleWeaponAction;
UPROPERTY(EditAnywhere, Category="Input")
TObjectPtr<UInputAction> FireWeaponAction;
UPROPERTY(EditAnywhere, Category="Input")
TObjectPtr<UInputAction> ReloadWeaponAction;
UPROPERTY(EditAnywhere, Category="Input")
TObjectPtr<UInputAction> AimAction;
FTimerHandle InitiializeWidgets_Timer;
};

View File

@@ -0,0 +1,113 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "ShooterHealthComponent.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FShooterHealth_DeathEvent, AActor*, OwningActor, AActor*, Instigator);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams(FShooterHealth_AttributeChanged, UShooterHealthComponent*, HealthComponent, float, OldValue, float, NewValue, AActor*, Instigator);
/**
* EDeathState
*
* Defines current state of death.
*/
UENUM(BlueprintType)
enum class EDeathState : uint8
{
NotDead = 0,
DeathStarted,
DeathFinished
};
/**
* UShooterHealthComponent
*
* An actor component used to handle anything related to health.
*/
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class FPSTEMPLATE_API UShooterHealthComponent : public UActorComponent
{
GENERATED_BODY()
public:
UShooterHealthComponent();
// Returns the health component if one exists on the specified actor.
UFUNCTION(BlueprintPure, Category = "Shooter|Health")
static UShooterHealthComponent* FindHealthComponent(const AActor* Actor) { return (Actor ? Actor->FindComponentByClass<UShooterHealthComponent>() : nullptr); }
// Returns the current health value.
UFUNCTION(BlueprintCallable, Category = "Shooter|Health")
float GetHealth() const { return Health; };
// Returns the current maximum health value.
UFUNCTION(BlueprintCallable, Category = "Shooter|Health")
float GetMaxHealth() const { return MaxHealth; };
// Returns the current health in the range [0.0, 1.0].
UFUNCTION(BlueprintCallable, Category = "Shooter|Health")
float GetHealthNormalized() const;
UFUNCTION(BlueprintCallable, Category = "Shooter|Health")
EDeathState GetDeathState() const { return DeathState; }
UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "Shooter|Health", Meta = (ExpandBoolAsExecs = "ReturnValue"))
bool IsDeadOrDying() const { return (DeathState > EDeathState::NotDead); }
// Begins the death sequence for the owner.
virtual void StartDeath(AActor* Instigator);
// Ends the death sequence for the owner.
virtual void FinishDeath(AActor* Instigator);
public:
// Delegate fired when the health value has changed. This is called on the client but the instigator may not be valid
UPROPERTY(BlueprintAssignable)
FShooterHealth_AttributeChanged OnHealthChanged;
// Delegate fired when the max health value has changed. This is called on the client but the instigator may not be valid
UPROPERTY(BlueprintAssignable)
FShooterHealth_AttributeChanged OnMaxHealthChanged;
// Delegate fired when the death sequence has started.
UPROPERTY(BlueprintAssignable)
FShooterHealth_DeathEvent OnDeathStarted;
// Delegate fired when the death sequence has finished.
UPROPERTY(BlueprintAssignable)
FShooterHealth_DeathEvent OnDeathFinished;
// return true if lethal
virtual bool ChangeHealthByAmount(float Amount, AActor* Instigator);
virtual void ChangeMaxHealthByAmount(float Amount, AActor* Instigator);
protected:
virtual void BeginPlay() override;
virtual void HandleOutOfHealth();
UFUNCTION()
virtual void OnRep_DeathState(EDeathState OldDeathState);
// Replicated state used to handle dying.
UPROPERTY(ReplicatedUsing = OnRep_DeathState)
EDeathState DeathState;
UPROPERTY(ReplicatedUsing=OnRep_Health)
float Health;
UPROPERTY(ReplicatedUsing=OnRep_MaxHealth)
float MaxHealth;
UFUNCTION()
void OnRep_Health(float OldValue);
UFUNCTION()
void OnRep_MaxHealth(float OldValue);
};