This repository has been archived on 2026-05-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
AgrarianGameArchive/Source/AgrarianGame/AgrarianGameCharacter.h
T

173 lines
6.1 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Logging/LogMacros.h"
#include "AgrarianGameCharacter.generated.h"
class USpringArmComponent;
class UCameraComponent;
class UInputAction;
class UAgrarianBuildingPlacementComponent;
class UAgrarianCraftingComponent;
class UAgrarianInventoryComponent;
class UAgrarianSurvivalComponent;
struct FInputActionValue;
DECLARE_LOG_CATEGORY_EXTERN(LogTemplateCharacter, Log, All);
/**
* A simple player-controllable third person character
* Implements a controllable orbiting camera
*/
UCLASS(abstract)
class AAgrarianGameCharacter : public ACharacter
{
GENERATED_BODY()
/** Camera boom positioning the camera behind the character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components", meta = (AllowPrivateAccess = "true"))
USpringArmComponent* CameraBoom;
/** Follow camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components", meta = (AllowPrivateAccess = "true"))
UCameraComponent* FollowCamera;
/** Replicated survival state for hunger, thirst, stamina, health, temperature, and injury. */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components", meta = (AllowPrivateAccess = "true"))
UAgrarianSurvivalComponent* SurvivalComponent;
/** Replicated inventory used by gathering, primitive crafting, and early economy prototypes. */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components", meta = (AllowPrivateAccess = "true"))
UAgrarianInventoryComponent* InventoryComponent;
/** Primitive crafting component for MVP recipes and future knowledge progression. */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components", meta = (AllowPrivateAccess = "true"))
UAgrarianCraftingComponent* CraftingComponent;
/** Server-authoritative primitive building placement component. */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components", meta = (AllowPrivateAccess = "true"))
UAgrarianBuildingPlacementComponent* BuildingPlacementComponent;
protected:
/** Jump Input Action */
UPROPERTY(EditAnywhere, Category="Input")
UInputAction* JumpAction;
/** Move Input Action */
UPROPERTY(EditAnywhere, Category="Input")
UInputAction* MoveAction;
/** Look Input Action */
UPROPERTY(EditAnywhere, Category="Input")
UInputAction* LookAction;
/** Mouse Look Input Action */
UPROPERTY(EditAnywhere, Category="Input")
UInputAction* MouseLookAction;
/** Interact Input Action */
UPROPERTY(EditAnywhere, Category="Input")
UInputAction* InteractAction;
/** Toggle between third-person and first-person camera views. */
UPROPERTY(EditAnywhere, Category="Input")
UInputAction* ToggleCameraAction;
/** How far the player can interact with MVP objects. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Agrarian|Interaction", meta = (ClampMin = "100"))
float InteractionDistance = 450.0f;
/** Third-person spring arm distance used when returning from first person. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Agrarian|Camera", meta = (ClampMin = "0"))
float ThirdPersonCameraDistance = 400.0f;
/** Local first-person camera offset relative to the capsule root. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Agrarian|Camera")
FVector FirstPersonCameraOffset = FVector(0.0f, 0.0f, 72.0f);
/** True when this local character is using the optional first-person view. */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Agrarian|Camera", meta = (AllowPrivateAccess = "true"))
bool bFirstPersonCamera = false;
public:
/** Constructor */
AAgrarianGameCharacter();
protected:
/** Initialize input action bindings */
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
protected:
/** Called for movement input */
void Move(const FInputActionValue& Value);
/** Called for looking input */
void Look(const FInputActionValue& Value);
/** Called for interaction input */
void Interact();
/** Called for camera perspective toggle input */
void ToggleCameraPerspective();
/** Applies local camera presentation state. */
void SetFirstPersonCamera(bool bEnableFirstPerson);
public:
/** Handles move inputs from either controls or UI interfaces */
UFUNCTION(BlueprintCallable, Category="Input")
virtual void DoMove(float Right, float Forward);
/** Handles look inputs from either controls or UI interfaces */
UFUNCTION(BlueprintCallable, Category="Input")
virtual void DoLook(float Yaw, float Pitch);
/** Handles jump pressed inputs from either controls or UI interfaces */
UFUNCTION(BlueprintCallable, Category="Input")
virtual void DoJumpStart();
/** Handles jump pressed inputs from either controls or UI interfaces */
UFUNCTION(BlueprintCallable, Category="Input")
virtual void DoJumpEnd();
/** Attempts to interact with the object in front of the player. */
UFUNCTION(BlueprintCallable, Category="Agrarian|Interaction")
virtual void TryInteract();
/** Returns true when this local character is using first-person camera presentation. */
UFUNCTION(BlueprintPure, Category="Agrarian|Camera")
bool IsFirstPersonCamera() const { return bFirstPersonCamera; }
/** Server-authoritative interaction entry point. */
UFUNCTION(Server, Reliable)
void ServerInteract(AActor* TargetActor);
public:
/** Returns CameraBoom subobject **/
FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
/** Returns FollowCamera subobject **/
FORCEINLINE class UCameraComponent* GetFollowCamera() const { return FollowCamera; }
/** Returns SurvivalComponent subobject **/
FORCEINLINE UAgrarianSurvivalComponent* GetSurvivalComponent() const { return SurvivalComponent; }
/** Returns InventoryComponent subobject **/
FORCEINLINE UAgrarianInventoryComponent* GetInventoryComponent() const { return InventoryComponent; }
/** Returns CraftingComponent subobject **/
FORCEINLINE UAgrarianCraftingComponent* GetCraftingComponent() const { return CraftingComponent; }
/** Returns BuildingPlacementComponent subobject **/
FORCEINLINE UAgrarianBuildingPlacementComponent* GetBuildingPlacementComponent() const { return BuildingPlacementComponent; }
};