Compare commits

...

4 Commits

Author SHA1 Message Date
baz 8e1dd981ce Add Weapon Inventory Component to Player Character 2024-07-18 01:40:09 +01:00
baz f25e6366f5 Add Weapon Inventory Component 2024-07-18 01:39:58 +01:00
baz d185f032bb Add Weapon class 2024-07-18 01:39:49 +01:00
baz 686294ab41 Add parameters to Event Delegates 2024-07-18 01:39:27 +01:00
8 changed files with 176 additions and 11 deletions

View File

@ -17,14 +17,15 @@ void UEXPComponent::IncrementEXP(int value)
{ {
// TODO: I should be updating the level here // TODO: I should be updating the level here
CurrentEXP += value; CurrentEXP += value;
OnEXPGained.ExecuteIfBound(); OnEXPGained.ExecuteIfBound(value);
OnEXPLevelUp.ExecuteIfBound(CurrentLevel);
} }
void UEXPComponent::SetCurrentEXP(int value) void UEXPComponent::SetCurrentEXP(int value)
{ {
// TODO: I should be updating the level here // TODO: I should be updating the level here
CurrentEXP = value; CurrentEXP = value;
OnEXPGained.ExecuteIfBound(); OnEXPGained.ExecuteIfBound(value);
} }
int UEXPComponent::GetCurrentEXP() int UEXPComponent::GetCurrentEXP()
@ -41,6 +42,8 @@ void UEXPComponent::Reset()
{ {
CurrentEXP = 0; CurrentEXP = 0;
CurrentLevel = 0; CurrentLevel = 0;
OnEXPGained.ExecuteIfBound(CurrentEXP);
OnEXPLevelUp.ExecuteIfBound(CurrentLevel);
} }
// Called when the game starts // Called when the game starts

View File

@ -6,8 +6,8 @@
#include "Components/ActorComponent.h" #include "Components/ActorComponent.h"
#include "EXPComponent.generated.h" #include "EXPComponent.generated.h"
DECLARE_DELEGATE(FOnEXPGainedDelegate) DECLARE_DELEGATE_OneParam(FOnEXPGainedDelegate, int)
DECLARE_DELEGATE(FOnEXPLevelUpDelegate) DECLARE_DELEGATE_OneParam(FOnEXPLevelUpDelegate, int)
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class VAMPIRES_API UEXPComponent : public UActorComponent class VAMPIRES_API UEXPComponent : public UActorComponent

View File

@ -38,6 +38,9 @@ APlayerCharacter::APlayerCharacter()
GarlicSphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Garlic Sphere Component")); GarlicSphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Garlic Sphere Component"));
GarlicSphereComponent->SetupAttachment(RootComponent); GarlicSphereComponent->SetupAttachment(RootComponent);
GarlicSphereComponent->SetSphereRadius(150.0f); GarlicSphereComponent->SetSphereRadius(150.0f);
//Create Weapon Inventory Component
WeaponInventoryComponent = CreateDefaultSubobject<UWeaponInventoryComponent>(TEXT("Weapon Inventory Component"));
} }
void APlayerCharacter::BeginPlay() void APlayerCharacter::BeginPlay()

View File

@ -7,6 +7,7 @@
#include "EXPComponent.h" #include "EXPComponent.h"
#include "GoldComponent.h" #include "GoldComponent.h"
#include "VampireCharacter.h" #include "VampireCharacter.h"
#include "WeaponInventoryComponent.h"
#include "Camera/CameraComponent.h" #include "Camera/CameraComponent.h"
#include "Components/SphereComponent.h" #include "Components/SphereComponent.h"
#include "GameFramework/SpringArmComponent.h" #include "GameFramework/SpringArmComponent.h"
@ -41,20 +42,22 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
float GarlicUpdateTime = 1.0f; float GarlicUpdateTime = 1.0f;
protected:
UPROPERTY()
UEXPComponent* EXPComponent;
UPROPERTY(VisibleAnywhere) UPROPERTY(VisibleAnywhere)
USphereComponent* GarlicSphereComponent; USphereComponent* GarlicSphereComponent;
UPROPERTY() UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<AEnemyCharacter*> OverlappedEnemies; TArray<AEnemyCharacter*> OverlappedEnemies;
UPROPERTY() UPROPERTY(EditAnywhere, BlueprintReadWrite)
UEXPComponent* EXPComponent;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UGoldComponent* GoldComponent; UGoldComponent* GoldComponent;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UWeaponInventoryComponent* WeaponInventoryComponent;
private: private:
FTimerHandle GarlicTimerHandle; FTimerHandle GarlicTimerHandle;

View File

@ -0,0 +1,33 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Weapon.h"
#include "EXPComponent.h"
// Sets default values
AWeapon::AWeapon()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
}
// Called when the game starts or when spawned
void AWeapon::BeginPlay()
{
Super::BeginPlay();
GetWorldTimerManager().SetTimer(WeaponTimerHandle, this, &AWeapon::FireWeaponAction, WeaponCooldown, true);
UEXPComponent* expcomponent = GetOwner()->GetComponentByClass<UEXPComponent>();
if (expcomponent)
{
expcomponent->OnEXPLevelUp.BindUObject(this, &AWeapon::UpgradeWeapon);
}
}
void AWeapon::FireWeaponAction()
{
}
void AWeapon::UpgradeWeapon(int newLevel)
{
}

36
Source/vampires/Weapon.h Normal file
View File

@ -0,0 +1,36 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Weapon.generated.h"
UCLASS()
class VAMPIRES_API AWeapon : public AActor
{
GENERATED_BODY()
public:
UPROPERTY()
float WeaponCooldown = 1.0f;
private:
FTimerHandle WeaponTimerHandle;
public:
// Sets default values for this actor's properties
AWeapon();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
UFUNCTION(BlueprintCallable)
virtual void FireWeaponAction();
UFUNCTION()
virtual void UpgradeWeapon(int newLevel);
};

View File

@ -0,0 +1,46 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "WeaponInventoryComponent.h"
#include "Kismet/GameplayStatics.h"
// Sets default values for this component's properties
UWeaponInventoryComponent::UWeaponInventoryComponent()
{
// 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;
// ...
}
// Called when the game starts
void UWeaponInventoryComponent::BeginPlay()
{
Super::BeginPlay();
// ...
}
void UWeaponInventoryComponent::InitializeInventory()
{
inventory.Empty();
for (TSubclassOf<AWeapon> weapon : initialInventory)
{
AddWeaponToInventory(weapon);
}
}
void UWeaponInventoryComponent::AddWeaponToInventory(TSubclassOf<AWeapon> Weapon)
{
AWeapon* weapon = GetWorld()->SpawnActor<AWeapon>(Weapon);
weapon->SetActorTransform(GetOwner()->GetTransform());
weapon->SetOwner(GetOwner());
weapon->AttachToActor(GetOwner(), FAttachmentTransformRules::KeepRelativeTransform);
inventory.Add(weapon);
}

View File

@ -0,0 +1,41 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Weapon.h"
#include "Components/ActorComponent.h"
#include "WeaponInventoryComponent.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class VAMPIRES_API UWeaponInventoryComponent : public UActorComponent
{
GENERATED_BODY()
public:
UPROPERTY()
TArray<TSubclassOf<AWeapon>> initialInventory;
private:
UPROPERTY()
TArray<AWeapon*> inventory;
public:
// Sets default values for this component's properties
UWeaponInventoryComponent();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
UFUNCTION()
void InitializeInventory();
UFUNCTION()
void AddWeaponToInventory(TSubclassOf<AWeapon> Weapon);
};