Add EXPComponent

This commit is contained in:
baz 2024-06-12 19:06:51 +01:00
parent a0a503f836
commit 8bf01234a0
4 changed files with 114 additions and 10 deletions

View File

@ -0,0 +1,52 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "EXPComponent.h"
// Sets default values for this component's properties
UEXPComponent::UEXPComponent()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = false;
// ...
}
void UEXPComponent::IncrementEXP(int value)
{
// TODO: I should be updating the level here
CurrentEXP += value;
OnEXPGained.ExecuteIfBound();
}
void UEXPComponent::SetCurrentEXP(int value)
{
// TODO: I should be updating the level here
CurrentEXP = value;
OnEXPGained.ExecuteIfBound();
}
int UEXPComponent::GetCurrentEXP()
{
return CurrentEXP;
}
int UEXPComponent::GetCurrentLevel()
{
return CurrentLevel;
}
void UEXPComponent::Reset()
{
CurrentEXP = 0;
CurrentLevel = 0;
}
// Called when the game starts
void UEXPComponent::BeginPlay()
{
Super::BeginPlay();
Reset();
}

View File

@ -0,0 +1,48 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "EXPComponent.generated.h"
DECLARE_DELEGATE(FOnEXPGainedDelegate)
DECLARE_DELEGATE(FOnEXPLevelUpDelegate)
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class VAMPIRES_API UEXPComponent : public UActorComponent
{
GENERATED_BODY()
public:
FOnEXPGainedDelegate OnEXPGained;
FOnEXPLevelUpDelegate OnEXPLevelUp;
protected:
int CurrentEXP = 0;
int CurrentLevel = 0;
public:
// Sets default values for this component's properties
UEXPComponent();
UFUNCTION()
void IncrementEXP(int value);
UFUNCTION()
void SetCurrentEXP(int value);
UFUNCTION()
int GetCurrentEXP();
UFUNCTION()
int GetCurrentLevel();
UFUNCTION()
void Reset();
protected:
// Called when the game starts
virtual void BeginPlay() override;
};

View File

@ -17,7 +17,7 @@ APlayerCharacter::APlayerCharacter()
CameraSpringArmComponent->bUsePawnControlRotation = false;
CameraSpringArmComponent->TargetArmLength = 1000;
CameraSpringArmComponent->bEnableCameraLag = false;
CameraSpringArmComponent->SocketOffset = { 0.0f, 0.0f, 0.0f };
CameraSpringArmComponent->SocketOffset = {0.0f, 0.0f, 0.0f};
CameraSpringArmComponent->SetRelativeRotation({-90.0, 0.0f, 0.0f});
// Create Camera
@ -29,6 +29,9 @@ APlayerCharacter::APlayerCharacter()
// Create Health Component
HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component"));
// Create EXP Component
EXPComponent = CreateDefaultSubobject<UEXPComponent>(TEXT("EXP Component"));
}
void APlayerCharacter::BeginPlay()
@ -42,12 +45,13 @@ void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCom
if (AVampirePlayerController* TankPlayerController = Cast<AVampirePlayerController>(GetController()))
{
if (UEnhancedInputLocalPlayerSubsystem* InputSystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(TankPlayerController->GetLocalPlayer()))
if (UEnhancedInputLocalPlayerSubsystem* InputSystem = ULocalPlayer::GetSubsystem<
UEnhancedInputLocalPlayerSubsystem>(TankPlayerController->GetLocalPlayer()))
{
if (!InputMappingContext.IsNull())
{
InputSystem->AddMappingContext(InputMappingContext.LoadSynchronous(), 0);
}
}
}
}
@ -66,7 +70,7 @@ void APlayerCharacter::MovementCallback(const FInputActionInstance& Instance)
if (vec2.Size() != 0.0f)
{
AddMovementInput({0.0f,1.0f,0.0f}, vec2.Y);
AddMovementInput({1.0f,0.0f,0.0f}, vec2.X);
AddMovementInput({0.0f, 1.0f, 0.0f}, vec2.Y);
AddMovementInput({1.0f, 0.0f, 0.0f}, vec2.X);
}
}

View File

@ -3,6 +3,7 @@
#pragma once
#include "CoreMinimal.h"
#include "EXPComponent.h"
#include "HealthComponent.h"
#include "VampireCharacter.h"
#include "Camera/CameraComponent.h"
@ -21,7 +22,6 @@ class VAMPIRES_API APlayerCharacter : public AVampireCharacter
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
USpringArmComponent* CameraSpringArmComponent = nullptr;
@ -34,11 +34,14 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
UInputAction* MovementAction;
protected:
UPROPERTY()
UHealthComponent* HealthComponent;
UPROPERTY()
UEXPComponent* EXPComponent;
public:
APlayerCharacter();
protected:
@ -48,9 +51,6 @@ public:
virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;
private:
UFUNCTION()
void MovementCallback(const FInputActionInstance& Instance);
};