Final quick refactor

This commit is contained in:
baz 2025-07-29 22:06:42 +01:00
parent ec818cfc55
commit c1e4387adb
35 changed files with 342 additions and 357 deletions

View File

@ -15,12 +15,10 @@ UEXPComponent::UEXPComponent()
// ...
}
void UEXPComponent::IncrementEXP(int value)
void UEXPComponent::IncrementEXP(int Value)
{
int oldEXP = CurrentEXP;
int oldLevel = CurrentLevel;
CurrentEXP += value;
int OldLevel = CurrentLevel;
CurrentEXP += Value;
if (NextLevelRow.Level >= 0)
{
@ -28,9 +26,10 @@ void UEXPComponent::IncrementEXP(int value)
{
CurrentLevel = NextLevelRow.Level;
if (FExpTableRow* newRow = LevelsTable->FindRow<FExpTableRow>(FName(*FString::FromInt(NextLevelRow.Level + 1)),"", true))
if (FExpTableRow* NewRow = LevelsTable->FindRow<FExpTableRow>(
FName(*FString::FromInt(NextLevelRow.Level + 1)), "", true))
{
NextLevelRow = *newRow;
NextLevelRow = *NewRow;
}
else
{
@ -47,7 +46,7 @@ void UEXPComponent::IncrementEXP(int value)
{
CurrentLevel = FMath::Floor(CurrentEXP / 100.0f);
if (CurrentLevel != oldLevel)
if (CurrentLevel != OldLevel)
{
OnEXPLevelUp.Broadcast(CurrentLevel);
}
@ -56,20 +55,19 @@ void UEXPComponent::IncrementEXP(int value)
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
}
void UEXPComponent::SetCurrentEXP(int value)
void UEXPComponent::SetCurrentEXP(int Value)
{
int oldEXP = CurrentEXP;
int oldLevel = CurrentLevel;
CurrentEXP = value;
int OldLevel = CurrentLevel;
CurrentEXP = Value;
NextLevelRow = FExpTableRow();
while (CurrentEXP < NextLevelRow.CumulativeExpForPreviousLevel && CurrentEXP < NextLevelRow.CumulativeExpForNextLevel)
while (CurrentEXP < NextLevelRow.CumulativeExpForPreviousLevel && CurrentEXP < NextLevelRow.
CumulativeExpForNextLevel)
{
if (FExpTableRow* newRow = LevelsTable->FindRow<FExpTableRow>(FName(*FString::FromInt(NextLevelRow.Level + 1)),"", true))
if (FExpTableRow* NewRow = LevelsTable->FindRow<FExpTableRow>(FName(*FString::FromInt(NextLevelRow.Level + 1)),
"", true))
{
NextLevelRow = *newRow;
NextLevelRow = *NewRow;
}
else
{
@ -82,7 +80,7 @@ void UEXPComponent::SetCurrentEXP(int value)
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
if (CurrentLevel != oldLevel)
if (CurrentLevel != OldLevel)
{
OnEXPLevelUp.Broadcast(CurrentLevel);
}
@ -102,9 +100,9 @@ void UEXPComponent::Reset()
{
if (LevelsTable)
{
if (FExpTableRow* newRow = LevelsTable->FindRow<FExpTableRow>(FName("1"), "", true))
if (FExpTableRow* NewRow = LevelsTable->FindRow<FExpTableRow>(FName("1"), "", true))
{
NextLevelRow = *newRow;
NextLevelRow = *NewRow;
}
}
@ -116,15 +114,16 @@ void UEXPComponent::Reset()
float UEXPComponent::GetCurrentLevelPercent()
{
int adjustedCurrentExp = CurrentEXP - NextLevelRow.CumulativeExpForPreviousLevel;
float res = static_cast<float>(adjustedCurrentExp) / static_cast<float>(NextLevelRow.ExpRequiredForNextLevel);
int AdjustedCurrentExp = CurrentEXP - NextLevelRow.CumulativeExpForPreviousLevel;
float CurrentLevelPercent = static_cast<float>(AdjustedCurrentExp) / static_cast<float>(NextLevelRow.
ExpRequiredForNextLevel);
if (FMath::IsNaN(res))
if (FMath::IsNaN(CurrentLevelPercent))
{
return 0.0f;
}
return res;
return CurrentLevelPercent;
}
// Called when the game starts

View File

@ -8,6 +8,7 @@
#include "EXPComponent.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnEXPGainedDelegate, int, exp, float, currentLevelPercent);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEXPLevelUpDelegate, int, level);
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
@ -16,16 +17,16 @@ class VAMPIRES_API UEXPComponent : public UActorComponent
GENERATED_BODY()
public:
UPROPERTY(BlueprintAssignable, Category="EXP")
FOnEXPGainedDelegate OnEXPGained;
UPROPERTY(BlueprintAssignable, Category="EXP")
FOnEXPLevelUpDelegate OnEXPLevelUp;
UPROPERTY(EditDefaultsOnly, Category="EXP")
TObjectPtr<UDataTable> LevelsTable;
protected:
private:
int CurrentEXP = 0;
int CurrentLevel = 0;
@ -37,10 +38,10 @@ public:
UEXPComponent();
UFUNCTION(BlueprintCallable)
void IncrementEXP(int value);
void IncrementEXP(int Value);
UFUNCTION(BlueprintCallable)
void SetCurrentEXP(int value);
void SetCurrentEXP(int Value);
UFUNCTION(BlueprintCallable, BlueprintPure)
int GetCurrentEXP();
@ -57,8 +58,4 @@ public:
protected:
// Called when the game starts
virtual void BeginPlay() override;
private:
void ProcessExp(int oldEXP, int oldLevel, int newEXP);
};

View File

@ -13,9 +13,9 @@ void AEXPPickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, A
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult)
{
if (UEXPComponent* expComponent = OtherActor->GetComponentByClass<UEXPComponent>())
if (UEXPComponent* ExpComponent = OtherActor->GetComponentByClass<UEXPComponent>())
{
expComponent->IncrementEXP(PickupValue);
ExpComponent->IncrementEXP(PickupValue);
Super::OnInnerBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
}
}

View File

@ -17,8 +17,7 @@ class VAMPIRES_API AEXPPickup : public APickup
protected:
virtual void BeginPlay() override;
public:
virtual void OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult) override;
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult) override;
};

View File

@ -47,12 +47,12 @@ UBehaviorTree* AEnemyCharacter::GetBehaviorTree()
return BehaviorTree;
}
void AEnemyCharacter::OnDamaged(FDamageInfo damageInfo)
void AEnemyCharacter::OnDamaged(FDamageInfo DamageInfo)
{
// if (OnDamagedSound)
// {
if (OnDamagedSound)
{
UGameplayStatics::PlaySoundAtLocation(GetWorld(), OnDamagedSound, GetActorLocation());
// }
}
if (OnDamagedNiagaraSystem)
{
@ -60,22 +60,22 @@ void AEnemyCharacter::OnDamaged(FDamageInfo damageInfo)
}
}
void AEnemyCharacter::OnDeath(FDamageInfo damageInfo)
void AEnemyCharacter::OnDeath(FDamageInfo DamageInfo)
{
if (PickupTemplate)
{
AGameModeBase* gamemode = UGameplayStatics::GetGameMode(GetWorld());
if (UKismetSystemLibrary::DoesImplementInterface(gamemode, UPools::StaticClass()))
AGameModeBase* Gamemode = UGameplayStatics::GetGameMode(GetWorld());
if (UKismetSystemLibrary::DoesImplementInterface(Gamemode, UPools::StaticClass()))
{
if (AObjectPoolManager* objectPoolManager = IPools::Execute_GetPickupObjectPoolManager(gamemode))
if (AObjectPoolManager* ObjectPoolManager = IPools::Execute_GetPickupObjectPoolManager(Gamemode))
{
AActor* pickup = objectPoolManager->GetObject();
AActor* Pickup = ObjectPoolManager->GetObject();
if (UKismetSystemLibrary::DoesImplementInterface(pickup, UPickupable::StaticClass()))
if (UKismetSystemLibrary::DoesImplementInterface(Pickup, UPickupable::StaticClass()))
{
FVector pickupLocation = GetActorLocation();
pickup->SetActorLocation(pickupLocation);
IPickupable::Execute_LoadDataFromDataAsset(pickup, PickupTemplate, pickupLocation);
FVector PickupLocation = GetActorLocation();
Pickup->SetActorLocation(PickupLocation);
IPickupable::Execute_LoadDataFromDataAsset(Pickup, PickupTemplate, PickupLocation);
}
}
}
@ -92,17 +92,17 @@ void AEnemyCharacter::OnDeath(FDamageInfo damageInfo)
}
}
void AEnemyCharacter::LoadDataFromDataAsset_Implementation(UEnemyDataAsset* enemyDataAsset)
void AEnemyCharacter::LoadDataFromDataAsset_Implementation(UEnemyDataAsset* EnemyDataAsset)
{
if (enemyDataAsset != nullptr)
if (EnemyDataAsset != nullptr)
{
StaticMeshComponent->SetStaticMesh(enemyDataAsset->StaticMesh);
BehaviorTree = enemyDataAsset->BehaviorTree;
PickupTemplate = enemyDataAsset->PickupDataAsset;
OnDamagedSound = enemyDataAsset->OnDamagedSoundBase;
OnDeathSound = enemyDataAsset->OnDeathSoundBase;
OnDamagedNiagaraSystem = enemyDataAsset->OnDamagedNiagaraSystem;
OnDeathNiagaraSystem = enemyDataAsset->OnDeathNiagaraSystem;
StaticMeshComponent->SetStaticMesh(EnemyDataAsset->StaticMesh);
BehaviorTree = EnemyDataAsset->BehaviorTree;
PickupTemplate = EnemyDataAsset->PickupDataAsset;
OnDamagedSound = EnemyDataAsset->OnDamagedSoundBase;
OnDeathSound = EnemyDataAsset->OnDeathSoundBase;
OnDamagedNiagaraSystem = EnemyDataAsset->OnDamagedNiagaraSystem;
OnDeathNiagaraSystem = EnemyDataAsset->OnDeathNiagaraSystem;
}
}
@ -129,10 +129,10 @@ void AEnemyCharacter::SpawnController_Implementation()
SpawnDefaultController();
}
if (BehaviorTree != nullptr)
if (AVampireAIController* VampireAIController = Cast<AVampireAIController>(Controller); VampireAIController &&
BehaviorTree)
{
AVampireAIController* controller = Cast<AVampireAIController>(Controller);
controller->RunBehaviorTree(BehaviorTree);
VampireAIController->RunBehaviorTree(BehaviorTree);
}
}
@ -142,9 +142,11 @@ UHealthComponent* AEnemyCharacter::GetEnemyHealthComponent_Implementation()
}
void AEnemyCharacter::OnDamageBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult)
{
if (Cast<ACharacter>(OtherActor) == UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) && !Player.Contains(OtherActor))
if (Cast<ACharacter>(OtherActor) == UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) && !Player.
Contains(OtherActor))
{
Player.Add(OtherActor);
@ -153,9 +155,10 @@ void AEnemyCharacter::OnDamageBeginOverlap(UPrimitiveComponent* OverlappedCompon
}
void AEnemyCharacter::OnDamageEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
if (Cast<ACharacter>(OtherActor) == UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) && Player.Contains(OtherActor))
if (Cast<ACharacter>(OtherActor) == UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) && Player.
Contains(OtherActor))
{
Player.Remove(OtherActor);
@ -170,8 +173,8 @@ void AEnemyCharacter::ResetHealth()
void AEnemyCharacter::DamagePlayer()
{
for (auto player : Player)
for (auto DamagedPlayer : Player)
{
UGameplayStatics::ApplyDamage(player, Damage, GetController(), this, nullptr);
UGameplayStatics::ApplyDamage(DamagedPlayer, Damage, GetController(), this, nullptr);
}
}

View File

@ -8,6 +8,7 @@
#include "Interfaces/Enemyable.h"
#include "EnemyCharacter.generated.h"
struct FDamageInfo;
class USphereComponent;
class UObjectPoolComponent;
class UBehaviorTree;
@ -20,7 +21,7 @@ class VAMPIRES_API AEnemyCharacter : public AVampireCharacter, public IEnemyable
{
GENERATED_BODY()
public:
protected:
UPROPERTY(EditDefaultsOnly)
TSubclassOf<AEXPPickup> EXPPickupTemplate = nullptr;
@ -28,7 +29,7 @@ public:
TObjectPtr<USphereComponent> DamageSphere = nullptr;
UPROPERTY(EditDefaultsOnly)
float Damage = 5.0f;;
float Damage = 5.0f;
UPROPERTY(EditDefaultsOnly)
float AttackCooldown = 1.0f;
@ -53,19 +54,20 @@ public:
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
public:
UBehaviorTree* GetBehaviorTree();
UFUNCTION()
virtual void OnDamaged(FDamageInfo damageInfo);
virtual void OnDamaged(FDamageInfo DamageInfo);
UFUNCTION()
virtual void OnDeath(FDamageInfo damageInfo);
virtual void OnDeath(FDamageInfo DamageInfo);
protected:
UFUNCTION()
virtual void LoadDataFromDataAsset_Implementation(UEnemyDataAsset* enemyDataAsset) override;
virtual void LoadDataFromDataAsset_Implementation(UEnemyDataAsset* EnemyDataAsset) override;
UFUNCTION()
virtual void ResetData_Implementation() override;
@ -81,12 +83,12 @@ public:
UFUNCTION()
void OnDamageBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult);
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult);
UFUNCTION()
void OnDamageEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex);
int32 OtherBodyIndex);
private:
UFUNCTION()

View File

@ -19,24 +19,24 @@ class VAMPIRES_API UEnemyDataAsset : public UDataAsset
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite, EditAnywhere)
UPROPERTY(EditDefaultsOnly)
TObjectPtr<UStaticMesh> StaticMesh;
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
UPROPERTY(EditDefaultsOnly)
TObjectPtr<UBehaviorTree> BehaviorTree = nullptr;
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
UPROPERTY(EditDefaultsOnly)
TObjectPtr<UPickupDataAsset> PickupDataAsset = nullptr;
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
UPROPERTY(EditDefaultsOnly)
TObjectPtr<USoundBase> OnDamagedSoundBase = nullptr;
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
UPROPERTY(EditDefaultsOnly)
TObjectPtr<USoundBase> OnDeathSoundBase = nullptr;
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
UPROPERTY(EditDefaultsOnly)
TObjectPtr<UNiagaraSystem> OnDamagedNiagaraSystem;
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
UPROPERTY(EditDefaultsOnly)
TObjectPtr<UNiagaraSystem> OnDeathNiagaraSystem;
};

View File

@ -13,15 +13,15 @@ UGoldComponent::UGoldComponent()
// ...
}
void UGoldComponent::IncrementGold(int value)
void UGoldComponent::IncrementGold(int Value)
{
CurrentGold += value;
CurrentGold += Value;
OnGoldGained.Broadcast(CurrentGold);
}
void UGoldComponent::SetCurrentGold(int value)
void UGoldComponent::SetCurrentGold(int Value)
{
CurrentGold = value;
CurrentGold = Value;
OnGoldGained.Broadcast(CurrentGold);
}

View File

@ -16,7 +16,7 @@ class VAMPIRES_API UGoldComponent : public UActorComponent
public:
FOnGoldGainedDelegate OnGoldGained;
protected:
private:
int CurrentGold = 0;
public:
@ -24,10 +24,10 @@ public:
UGoldComponent();
UFUNCTION()
void IncrementGold(int value);
void IncrementGold(int Value);
UFUNCTION()
void SetCurrentGold(int value);
void SetCurrentGold(int Value);
UFUNCTION()
int GetCurrentGold();

View File

@ -16,9 +16,9 @@ void AGoldPickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult)
{
if (UGoldComponent* goldComponent = OtherActor->GetComponentByClass<UGoldComponent>())
if (UGoldComponent* GoldComponent = OtherActor->GetComponentByClass<UGoldComponent>())
{
goldComponent->IncrementGold(PickupValue);
GoldComponent->IncrementGold(PickupValue);
Super::OnInnerBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
}
}

View File

@ -17,8 +17,7 @@ class VAMPIRES_API AGoldPickup : public APickup
protected:
virtual void BeginPlay() override;
public:
virtual void OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult) override;
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult) override;
};

View File

@ -13,28 +13,28 @@ UHealthComponent::UHealthComponent()
// ...
}
void UHealthComponent::TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType,
AController* instigatedBy, AActor* damageCauser)
void UHealthComponent::TakeDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType,
AController* InstigatedBy, AActor* DamageCauser)
{
if (damagedActor == nullptr || IsDead || !CanDamage)
if (DamagedActor == nullptr || IsDead || !CanDamage)
{
return;
}
CurrentHealth -= damage;
CurrentHealth -= Damage;
OnDamaged.Broadcast({damagedActor, damage, damageType, instigatedBy, damageCauser});
OnDamaged.Broadcast({DamagedActor, Damage, DamageType, InstigatedBy, DamageCauser});
if (CurrentHealth <= 0.0f)
{
IsDead = true;
OnDeath.Broadcast({damagedActor, damage, damageType, instigatedBy, damageCauser});
OnDeath.Broadcast({DamagedActor, Damage, DamageType, InstigatedBy, DamageCauser});
}
}
void UHealthComponent::IncrementHealth(float value)
void UHealthComponent::IncrementHealth(float Value)
{
CurrentHealth += value;
CurrentHealth += Value;
if (CurrentHealth > MaxHealth)
{
@ -47,9 +47,9 @@ float UHealthComponent::GetMaxHealth()
return MaxHealth;
}
void UHealthComponent::SetMaxHealth(float value)
void UHealthComponent::SetMaxHealth(float Value)
{
MaxHealth = value;
MaxHealth = Value;
}
float UHealthComponent::GetCurrentHealth()
@ -57,9 +57,9 @@ float UHealthComponent::GetCurrentHealth()
return CurrentHealth;
}
void UHealthComponent::SetCurrentHealth(float value)
void UHealthComponent::SetCurrentHealth(float Value)
{
CurrentHealth = value;
CurrentHealth = Value;
if (CurrentHealth > MaxHealth)
{
@ -84,9 +84,9 @@ bool UHealthComponent::GetIsDead()
return IsDead;
}
void UHealthComponent::SetIsDead(bool isDead)
void UHealthComponent::SetIsDead(bool bIsDead)
{
IsDead = isDead;
IsDead = bIsDead;
}
bool UHealthComponent::GetCanDamage()
@ -94,9 +94,9 @@ bool UHealthComponent::GetCanDamage()
return CanDamage;
}
void UHealthComponent::SetCanDamage(bool canDamage)
void UHealthComponent::SetCanDamage(bool bCanDamage)
{
CanDamage = canDamage;
CanDamage = bCanDamage;
}

View File

@ -56,44 +56,44 @@ public:
UHealthComponent();
UFUNCTION()
virtual void TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType,
AController* instigatedBy,
AActor* damageCauser);
virtual void TakeDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType,
AController* InstigatedBy,
AActor* DamageCauser);
UFUNCTION()
float GetMaxHealth();
UFUNCTION()
void SetMaxHealth(float value);
void SetMaxHealth(float Value);
UFUNCTION()
float GetCurrentHealth();
UFUNCTION()
void SetCurrentHealth(float value);
void SetCurrentHealth(float Value);
UFUNCTION()
void ResetHealth();
UFUNCTION()
void RecoverHealth(float healing);
void RecoverHealth(float Healing);
UFUNCTION()
bool GetIsDead();
UFUNCTION()
void SetIsDead(bool isDead);
void SetIsDead(bool bIsDead);
UFUNCTION()
bool GetCanDamage();
UFUNCTION()
void SetCanDamage(bool canDamage);
void SetCanDamage(bool bCanDamage);
protected:
// Called when the game starts
virtual void BeginPlay() override;
UFUNCTION()
void IncrementHealth(float value);
void IncrementHealth(float Value);
};

View File

@ -10,44 +10,45 @@ void AObjectPoolManager::BeginPlay()
Super::BeginPlay();
}
void AObjectPoolManager::InitializeObjectPool(TSubclassOf<AActor> Object, const int InitialObjectPoolSize)
void AObjectPoolManager::InitializeObjectPool(const TSubclassOf<AActor>& TemplateObject, const int InitialObjectPoolSize)
{
ObjectTemplate = Object;
ObjectTemplate = TemplateObject;
for (int i = 0; i < InitialObjectPoolSize; i++)
{
if (AActor* object = GetWorld()->SpawnActor<AActor>(Object, FVector(100000.0f, 100000.0f, 0), FRotator(0, 0, 0)))
if (AActor* Object = GetWorld()->SpawnActor<
AActor>(TemplateObject, FVector(100000.0f, 100000.0f, 0), FRotator(0, 0, 0)))
{
SetObjectStatus(false, object);
ObjectPool.Add(object);
SetObjectStatus(false, Object);
ObjectPool.Add(Object);
}
}
}
void AObjectPoolManager::InitializeObjectPool(UClass* Object, int InitialObjectPoolSize)
void AObjectPoolManager::InitializeObjectPool(UClass* TemplateObject, int InitialObjectPoolSize)
{
for (int i = 0; i < InitialObjectPoolSize; i++)
{
if (AActor* object = GetWorld()->SpawnActor<AActor>(Object))
if (AActor* Object = GetWorld()->SpawnActor<AActor>(TemplateObject))
{
SetObjectStatus(false, object);
ObjectPool.Add(object);
SetObjectStatus(false, Object);
ObjectPool.Add(Object);
}
}
}
AActor* AObjectPoolManager::GetObject(int startingOffset)
AActor* AObjectPoolManager::GetObject(int StartingOffset)
{
int ObjectPoolSize = ObjectPool.Num();
for (int i = startingOffset; i < ObjectPoolSize; i++)
for (int i = StartingOffset; i < ObjectPoolSize; i++)
{
if (ObjectPool[i]->IsHidden())
{
SetObjectStatus(true, ObjectPool[i]);
if (UObjectPoolComponent* objectPoolComponent = ObjectPool[i]->GetComponentByClass<UObjectPoolComponent>())
if (UObjectPoolComponent* ObjectPoolComponent = ObjectPool[i]->GetComponentByClass<UObjectPoolComponent>())
{
objectPoolComponent->OnRetrieve.ExecuteIfBound();
ObjectPoolComponent->OnRetrieve.ExecuteIfBound();
}
return ObjectPool[i];
@ -59,19 +60,19 @@ AActor* AObjectPoolManager::GetObject(int startingOffset)
return GetObject(ObjectPoolSize);
}
void AObjectPoolManager::ReturnObject(AActor* object)
void AObjectPoolManager::ReturnObject(AActor* Object)
{
SetObjectStatus(false, object);
SetObjectStatus(false, Object);
if (UObjectPoolComponent* objectPoolComponent = object->GetComponentByClass<UObjectPoolComponent>())
if (UObjectPoolComponent* ObjectPoolComponent = Object->GetComponentByClass<UObjectPoolComponent>())
{
objectPoolComponent->OnReturn.ExecuteIfBound();
ObjectPoolComponent->OnReturn.ExecuteIfBound();
}
}
void AObjectPoolManager::SetObjectStatus(bool enabled, AActor* object)
void AObjectPoolManager::SetObjectStatus(bool bEnabled, AActor* Object)
{
object->SetActorHiddenInGame(!enabled);
object->SetActorTickEnabled(enabled);
object->SetActorEnableCollision(enabled);
Object->SetActorHiddenInGame(!bEnabled);
Object->SetActorTickEnabled(bEnabled);
Object->SetActorEnableCollision(bEnabled);
}

View File

@ -15,17 +15,17 @@ class VAMPIRES_API AObjectPoolManager : public AActor
TSubclassOf<AActor> ObjectTemplate;
public:
void InitializeObjectPool(TSubclassOf<AActor> Object, int InitialObjectPoolSize = 400);
void InitializeObjectPool(UClass* Object, int InitialObjectPoolSize = 400);
void InitializeObjectPool(const TSubclassOf<AActor>& TemplateObject, int InitialObjectPoolSize = 400);
void InitializeObjectPool(UClass* TemplateObject, int InitialObjectPoolSize = 400);
AActor* GetObject(int startingOffset = 0);
AActor* GetObject(int StartingOffset = 0);
void ReturnObject(AActor* object);
void ReturnObject(AActor* Object);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
private:
void SetObjectStatus(bool enabled, AActor* object);
void SetObjectStatus(bool bEnabled, AActor* Object);
};

View File

@ -42,8 +42,8 @@ APickup::APickup()
TimelineComponent->SetTimelineLengthMode(TL_TimelineLength);
TimelineComponent->SetPlaybackPosition(0.0f, false);
onTimelineCallback.BindUFunction(this, FName(TEXT("TimelineCallback")));
onTimelineFinishedCallback.BindUFunction(this, FName(TEXT("TimelineFinishedCallback")));
OnTimelineCallback.BindUFunction(this, FName(TEXT("TimelineCallback")));
OnTimelineFinishedCallback.BindUFunction(this, FName(TEXT("TimelineFinishedCallback")));
NiagaraComponent = CreateDefaultSubobject<UNiagaraComponent>(TEXT("Niagara Component"));
NiagaraComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
@ -60,8 +60,8 @@ void APickup::BeginPlay()
if (CurveFloat != nullptr)
{
TimelineComponent->AddInterpFloat(CurveFloat, onTimelineCallback);
TimelineComponent->SetTimelineFinishedFunc(onTimelineFinishedCallback);
TimelineComponent->AddInterpFloat(CurveFloat, OnTimelineCallback);
TimelineComponent->SetTimelineFinishedFunc(OnTimelineFinishedCallback);
}
}
@ -77,8 +77,8 @@ void APickup::LoadDataFromDataAsset_Implementation(UPickupDataAsset* PickupDataA
if (CurveFloat != nullptr)
{
TimelineComponent->AddInterpFloat(CurveFloat, onTimelineCallback);
TimelineComponent->SetTimelineFinishedFunc(onTimelineFinishedCallback);
TimelineComponent->AddInterpFloat(CurveFloat, OnTimelineCallback);
TimelineComponent->SetTimelineFinishedFunc(OnTimelineFinishedCallback);
}
}
}
@ -110,14 +110,14 @@ void APickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AAct
UGameplayStatics::PlaySound2D(GetWorld(), PickupSoundBase);
}
AGameModeBase* gamemode = UGameplayStatics::GetGameMode(GetWorld());
if (UKismetSystemLibrary::DoesImplementInterface(gamemode, UPools::StaticClass()))
AGameModeBase* Gamemode = UGameplayStatics::GetGameMode(GetWorld());
if (UKismetSystemLibrary::DoesImplementInterface(Gamemode, UPools::StaticClass()))
{
if (AObjectPoolManager* objectPoolManager = IPools::Execute_GetProjectileObjectPoolManager(gamemode))
if (AObjectPoolManager* ObjectPoolManager = IPools::Execute_GetProjectileObjectPoolManager(Gamemode))
{
TimelineComponent->Stop();
ResetData_Implementation();
objectPoolManager->ReturnObject(this);
ObjectPoolManager->ReturnObject(this);
}
}
else
@ -131,18 +131,19 @@ void APickup::OnOuterBeginOverlap(UPrimitiveComponent* OverlappedComponent, AAct
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult)
{
if (!TimelineComponent->IsPlaying() && UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) == Cast<ACharacter>(OtherActor))
if (!TimelineComponent->IsPlaying() && UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) == Cast<
ACharacter>(OtherActor))
{
PlayTimeLine();
}
}
void APickup::TimelineCallback(float val)
void APickup::TimelineCallback(float Value)
{
FVector actorLocation = PickupLocation;
FVector playerLocation = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)->GetActorLocation();
FVector location = FMath::Lerp(actorLocation, playerLocation, val);
SetActorLocation(location);
FVector ActorLocation = PickupLocation;
FVector PlayerLocation = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)->GetActorLocation();
FVector Location = FMath::Lerp(ActorLocation, PlayerLocation, Value);
SetActorLocation(Location);
}
void APickup::TimelineFinishedCallback()

View File

@ -18,7 +18,7 @@ class VAMPIRES_API APickup : public AActor, public IPickupable
{
GENERATED_BODY()
public:
protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
int PickupValue = 1;
@ -44,8 +44,8 @@ public:
TObjectPtr<UNiagaraComponent> NiagaraComponent = nullptr;
private:
FOnTimelineFloat onTimelineCallback;
FOnTimelineEventStatic onTimelineFinishedCallback;
FOnTimelineFloat OnTimelineCallback;
FOnTimelineEventStatic OnTimelineFinishedCallback;
FVector PickupLocation;
@ -72,7 +72,7 @@ protected:
const FHitResult& SweepResult);
UFUNCTION()
void TimelineCallback(float val);
void TimelineCallback(float Value);
UFUNCTION()
void TimelineFinishedCallback();

View File

@ -37,8 +37,8 @@ APlayerCharacter::APlayerCharacter()
CameraShakeTimelineComponent->SetTimelineLengthMode(TL_TimelineLength);
CameraShakeTimelineComponent->SetPlaybackPosition(0.0f, false);
onTimelineCallback.BindUFunction(this, FName(TEXT("CameraShakeTimelineCallback")));
onTimelineFinishedCallback.BindUFunction(this, FName(TEXT("CameraShakeTimelineFinishedCallback")));
OnTimelineCallback.BindUFunction(this, FName(TEXT("CameraShakeTimelineCallback")));
OnTimelineFinishedCallback.BindUFunction(this, FName(TEXT("CameraShakeTimelineFinishedCallback")));
}
void APlayerCharacter::BeginPlay()
@ -50,8 +50,8 @@ void APlayerCharacter::BeginPlay()
if (CameraShakeCurve != nullptr)
{
CameraShakeTimelineComponent->AddInterpFloat(CameraShakeCurve, onTimelineCallback);
CameraShakeTimelineComponent->SetTimelineFinishedFunc(onTimelineFinishedCallback);
CameraShakeTimelineComponent->AddInterpFloat(CameraShakeCurve, OnTimelineCallback);
CameraShakeTimelineComponent->SetTimelineFinishedFunc(OnTimelineFinishedCallback);
}
PlayerCameraManager = GetWorld()->GetFirstPlayerController()->PlayerCameraManager;
@ -113,7 +113,8 @@ void APlayerCharacter::CameraShakeTimelineCallback(float val)
{
auto PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
auto cameraActor = PlayerController->GetViewTarget();
cameraActor->SetActorLocation(FVector(FMath::RandRange(0.0f, CameraShakeStrength) * val, FMath::RandRange(0.0f, CameraShakeStrength) * val, 0.0f));
cameraActor->SetActorLocation(FVector(FMath::RandRange(0.0f, CameraShakeStrength) * val,
FMath::RandRange(0.0f, CameraShakeStrength) * val, 0.0f));
}
void APlayerCharacter::CameraShakeTimelineFinishedCallback()

View File

@ -24,7 +24,7 @@ class VAMPIRES_API APlayerCharacter : public AVampireCharacter
{
GENERATED_BODY()
public:
protected:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<UEXPComponent> EXPComponent;
@ -44,14 +44,13 @@ public:
float CameraShakeStrength = 100.0f;
private:
UPROPERTY()
TObjectPtr<APlayerCameraManager> PlayerCameraManager = nullptr;
APlayerCharacter();
private:
FOnTimelineFloat onTimelineCallback;
FOnTimelineEventStatic onTimelineFinishedCallback;
FOnTimelineFloat OnTimelineCallback;
FOnTimelineEventStatic OnTimelineFinishedCallback;
protected:
virtual void BeginPlay() override;

View File

@ -60,7 +60,8 @@ void AProjectile::SetActorHiddenInGame(bool bNewHidden)
}
else
{
GetWorldTimerManager().SetTimer(ProjectileLifetimeTimerHandle, this, &AProjectile::ReturnProjectileToPool, ProjectileLifespan, true);
GetWorldTimerManager().SetTimer(ProjectileLifetimeTimerHandle, this, &AProjectile::ReturnProjectileToPool,
ProjectileLifespan, true);
}
}
@ -103,14 +104,14 @@ void AProjectile::OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedCompon
if (!EnemyHealthComponent->GetIsDead())
{
AController* ownerController = nullptr;
if (AVampireCharacter* character = Cast<AVampireCharacter>(GetOwner()))
AController* OwnerController = nullptr;
if (AVampireCharacter* Character = Cast<AVampireCharacter>(GetOwner()))
{
ownerController = character->GetController();
OwnerController = Character->GetController();
}
AProjectileWeapon* ownerWeapon = Cast<AProjectileWeapon>(GetOwner());
EnemyHealthComponent->TakeDamage(Enemy, ownerWeapon->GetDamage(), nullptr, ownerController, this);
AProjectileWeapon* OwnerWeapon = Cast<AProjectileWeapon>(GetOwner());
EnemyHealthComponent->TakeDamage(Enemy, OwnerWeapon->GetDamage(), nullptr, OwnerController, this);
RemainingDamageableEnemies--;
@ -124,14 +125,14 @@ void AProjectile::OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedCompon
void AProjectile::ReturnProjectileToPool()
{
AGameModeBase* gamemode = UGameplayStatics::GetGameMode(GetWorld());
AGameModeBase* Gamemode = UGameplayStatics::GetGameMode(GetWorld());
if (UKismetSystemLibrary::DoesImplementInterface(gamemode, UPools::StaticClass()))
if (UKismetSystemLibrary::DoesImplementInterface(Gamemode, UPools::StaticClass()))
{
if (AObjectPoolManager* objectPoolManager =
IPools::Execute_GetProjectileObjectPoolManager(gamemode))
if (AObjectPoolManager* ObjectPoolManager =
IPools::Execute_GetProjectileObjectPoolManager(Gamemode))
{
objectPoolManager->ReturnObject(this);
ObjectPoolManager->ReturnObject(this);
}
}
}

View File

@ -49,7 +49,6 @@ protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
virtual void SetActorHiddenInGame(bool bNewHidden) override;
virtual void SetTargetDirection_Implementation(FVector Direction) override;

View File

@ -54,10 +54,10 @@ void AVampireAIController::OnPossess(APawn* InPawn)
PlayerCharacter = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0);
if (UBehaviorTree* bt = EnemyCharacter->GetBehaviorTree())
if (UBehaviorTree* BT = EnemyCharacter->GetBehaviorTree())
{
DefaultBlackboard->InitializeBlackboard(*bt->BlackboardAsset);
BehaviorTree->StartTree(*bt);
DefaultBlackboard->InitializeBlackboard(*BT->BlackboardAsset);
BehaviorTree->StartTree(*BT);
DefaultBlackboard->SetValueAsObject("SelfActor", EnemyCharacter);
if (PlayerCharacter)
@ -67,7 +67,7 @@ void AVampireAIController::OnPossess(APawn* InPawn)
}
}
void AVampireAIController::OnDamaged(FDamageInfo info)
void AVampireAIController::OnDamaged(FDamageInfo Info)
{
if (EnemyCharacter->GetHealthComponent()->GetCurrentHealth() > 0.0f)
{
@ -75,22 +75,9 @@ void AVampireAIController::OnDamaged(FDamageInfo info)
}
}
void AVampireAIController::OnDeath(FDamageInfo info)
void AVampireAIController::OnDeath(FDamageInfo Info)
{
// TODO: Do stuff here
EnemyCharacter->OnDeath(info);
/*EnemyCharacter->DetachFromControllerPendingDestroy();
EnemyCharacter->GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
EnemyCharacter->GetCapsuleComponent()->SetCollisionResponseToAllChannels(ECR_Ignore);
if (UPawnMovementComponent* characterMovementComponent = EnemyCharacter->GetMovementComponent())
{
characterMovementComponent->StopMovementImmediately();
characterMovementComponent->StopActiveMovement();
characterMovementComponent->SetComponentTickEnabled(false);
}
GetWorldTimerManager().ClearTimer(PawnMoveToTimerHandle);
EnemyCharacter->SetLifeSpan(0.1f);*/
EnemyCharacter->OnDeath(Info);
}
void AVampireAIController::PawnMoveTo()

View File

@ -38,18 +38,15 @@ public:
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
protected:
virtual void OnPossess(APawn* InPawn) override;
public:
UFUNCTION()
virtual void OnDamaged(FDamageInfo info);
virtual void OnDamaged(FDamageInfo Info);
UFUNCTION()
virtual void OnDeath(FDamageInfo info);
virtual void OnDeath(FDamageInfo Info);
private:
UFUNCTION()

View File

@ -10,7 +10,7 @@
// Sets default values
AVampireCharacter::AVampireCharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
// Create Health Component
@ -29,8 +29,6 @@ AVampireCharacter::AVampireCharacter()
void AVampireCharacter::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
@ -38,21 +36,21 @@ void AVampireCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
float newYaw = FMath::Atan2(PreviousMovementDirection.Y, PreviousMovementDirection.X) * 180.0f / PI;
FQuat newRotation = FQuat::Slerp(StaticMeshComponent->GetComponentRotation().Quaternion(),
FRotator(0.0f, newYaw, 0.0f).Quaternion(),
float NewYaw = FMath::Atan2(PreviousMovementDirection.Y, PreviousMovementDirection.X) * 180.0f / PI;
FQuat NewRotation = FQuat::Slerp(StaticMeshComponent->GetComponentRotation().Quaternion(),
FRotator(0.0f, NewYaw, 0.0f).Quaternion(),
DeltaTime * SlerpSpeed);
StaticMeshComponent->SetRelativeRotation(newRotation);
StaticMeshComponent->SetRelativeRotation(NewRotation);
}
void AVampireCharacter::Input_Move_Implementation(FVector2D value)
void AVampireCharacter::Input_Move_Implementation(FVector2D Value)
{
PreviousMovementDirection = value;
PreviousMovementDirection = Value;
if (value.Size() != 0.0f)
if (Value.Size() != 0.0f)
{
AddMovementInput({0.0f, 1.0f, 0.0f}, value.Y);
AddMovementInput({1.0f, 0.0f, 0.0f}, value.X);
AddMovementInput({0.0f, 1.0f, 0.0f}, Value.Y);
AddMovementInput({1.0f, 0.0f, 0.0f}, Value.X);
}
}
@ -70,4 +68,3 @@ UHealthComponent* AVampireCharacter::GetHealthComponent()
{
return HealthComponent;
}

View File

@ -58,15 +58,15 @@ protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
virtual void Input_Move_Implementation(FVector2D value) override;
virtual void Input_Move_Implementation(FVector2D Value) override;
virtual UInputMappingContext* Input_GetInputMappingContext_Implementation() override;
virtual FVector2D Input_GetPreviousMovementDirection_Implementation() override;
public:
UHealthComponent* GetHealthComponent();
};

View File

@ -2,4 +2,3 @@
#include "VampireGameInstance.h"

View File

@ -1,4 +1,4 @@
// Louis Hobbs | 2024-2025
// Louis Hobbs | 2024-2025
#pragma once
@ -15,8 +15,8 @@ UCLASS()
class VAMPIRES_API UVampireGameInstance : public UGameInstance
{
GENERATED_BODY()
public:
public:
UPROPERTY()
TSubclassOf<AWeapon> StarterWeapon;

View File

@ -24,6 +24,9 @@ class VAMPIRES_API AVampireGameMode : public AGameMode, public IPools
GENERATED_BODY()
public:
FOnEnemyDeathCountIncrementDelegate OnEnemyDeathCountIncrementDelegate;
protected:
UPROPERTY(EditDefaultsOnly)
TSubclassOf<AEnemyCharacter> EnemyTemplate;
@ -33,8 +36,6 @@ public:
UPROPERTY(EditDefaultsOnly)
TSubclassOf<AEXPPickup> PickupTemplate;
FOnEnemyDeathCountIncrementDelegate OnEnemyDeathCountIncrementDelegate;
UPROPERTY(EditDefaultsOnly)
TArray<TObjectPtr<UEnemyDataAsset>> EnemyDataAssets;
@ -68,6 +69,7 @@ public:
UFUNCTION(BlueprintCallable, BlueprintPure)
int GetEnemyDeathCount();
protected:
UFUNCTION()
void HandleOnEnemyDeath(FDamageInfo damageInfo);
@ -86,7 +88,6 @@ public:
UFUNCTION(BlueprintCallable)
void EndGame();
protected:
UFUNCTION()
void SpawnEnemy();
};

View File

@ -23,53 +23,55 @@ void AVampirePlayerController::OnPossess(APawn* aPawn)
{
Super::OnPossess(aPawn);
if (UEnhancedInputLocalPlayerSubsystem* subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()))
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(
GetLocalPlayer()))
{
if (UKismetSystemLibrary::DoesImplementInterface(aPawn, UInputable::StaticClass()))
{
subsystem->AddMappingContext(IInputable::Execute_Input_GetInputMappingContext(aPawn), 0);
Subsystem->AddMappingContext(IInputable::Execute_Input_GetInputMappingContext(aPawn), 0);
}
}
if (PlayerHUD)
{
currentPlayerHUD = CreateWidget<UHUDWidget, AVampirePlayerController*>(this, PlayerHUD.Get());
CurrentPlayerHUD = CreateWidget<UHUDWidget, AVampirePlayerController*>(this, PlayerHUD.Get());
if (UEXPComponent* expComponent = aPawn->GetComponentByClass<UEXPComponent>())
if (UEXPComponent* ExpComponent = aPawn->GetComponentByClass<UEXPComponent>())
{
expComponent->OnEXPGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerEXPHUD);
expComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerLevelHUD);
expComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::ShowLevelUpScreen);
UpdatePlayerEXPHUD(expComponent->GetCurrentEXP(), expComponent->GetCurrentLevelPercent());
UpdatePlayerLevelHUD(expComponent->GetCurrentLevel());
ExpComponent->OnEXPGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerEXPHUD);
ExpComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerLevelHUD);
ExpComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::ShowLevelUpScreen);
UpdatePlayerEXPHUD(ExpComponent->GetCurrentEXP(), ExpComponent->GetCurrentLevelPercent());
UpdatePlayerLevelHUD(ExpComponent->GetCurrentLevel());
}
if (UGoldComponent* goldComponent = aPawn->GetComponentByClass<UGoldComponent>())
if (UGoldComponent* GoldComponent = aPawn->GetComponentByClass<UGoldComponent>())
{
goldComponent->OnGoldGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdateGoldCountHUD);
UpdateGoldCountHUD(goldComponent->GetCurrentGold());
GoldComponent->OnGoldGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdateGoldCountHUD);
UpdateGoldCountHUD(GoldComponent->GetCurrentGold());
}
if (AVampireGameMode* gamemode = Cast<AVampireGameMode>(UGameplayStatics::GetGameMode(GetWorld())))
if (AVampireGameMode* Gamemode = Cast<AVampireGameMode>(UGameplayStatics::GetGameMode(GetWorld())))
{
gamemode->OnEnemyDeathCountIncrementDelegate.AddDynamic(this, &AVampirePlayerController::UpdateKillCountHUD);
UpdateKillCountHUD(gamemode->GetEnemyDeathCount());
Gamemode->OnEnemyDeathCountIncrementDelegate.
AddDynamic(this, &AVampirePlayerController::UpdateKillCountHUD);
UpdateKillCountHUD(Gamemode->GetEnemyDeathCount());
}
if (currentPlayerHUD)
if (CurrentPlayerHUD)
{
currentPlayerHUD->AddToViewport();
CurrentPlayerHUD->AddToViewport();
}
}
if (UVampireGameInstance* gameInstance = Cast<UVampireGameInstance>(GetGameInstance()))
if (UVampireGameInstance* GameInstance = Cast<UVampireGameInstance>(GetGameInstance()))
{
UWeaponInventoryComponent* weaponInventoryComponent = aPawn->GetComponentByClass<
UWeaponInventoryComponent* WeaponInventoryComponent = aPawn->GetComponentByClass<
UWeaponInventoryComponent>();
if (weaponInventoryComponent && gameInstance->StarterWeapon)
if (WeaponInventoryComponent && GameInstance->StarterWeapon)
{
weaponInventoryComponent->initialInventory.Add(gameInstance->StarterWeapon);
WeaponInventoryComponent->InitialInventory.Add(GameInstance->StarterWeapon);
}
}
}
@ -78,7 +80,7 @@ void AVampirePlayerController::OnUnPossess()
{
Super::OnUnPossess();
GetWorld()->GetTimerManager().ClearTimer(pawnLifeTimeHandle);
GetWorld()->GetTimerManager().ClearTimer(PawnLifeTimeHandle);
}
void AVampirePlayerController::SetupInputComponent()
@ -94,13 +96,13 @@ void AVampirePlayerController::SetupInputComponent()
void AVampirePlayerController::Move(const FInputActionValue& MovementInput)
{
FVector2D movement = MovementInput.Get<FVector2D>();
FVector2D Movement = MovementInput.Get<FVector2D>();
if (APawn* pawn = GetPawn())
{
if (UKismetSystemLibrary::DoesImplementInterface(pawn, UInputable::StaticClass()))
{
IInputable::Execute_Input_Move(pawn, movement);
IInputable::Execute_Input_Move(pawn, Movement);
}
}
}
@ -119,26 +121,26 @@ void AVampirePlayerController::OnPause(const FInputActionValue& PauseInput)
{
if (SetPause(true))
{
currentPauseUI = CreateWidget<UPauseWidget, AVampirePlayerController*>(this, PauseUI.Get());
if (currentPauseUI)
CurrentPauseUI = CreateWidget<UPauseWidget, AVampirePlayerController*>(this, PauseUI.Get());
if (CurrentPauseUI)
{
currentPauseUI->AddToViewport();
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, currentPauseUI, EMouseLockMode::LockInFullscreen);
CurrentPauseUI->AddToViewport();
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, CurrentPauseUI, EMouseLockMode::LockInFullscreen);
bShowMouseCursor = true;
}
}
}
}
void AVampirePlayerController::UpdatePlayerEXPHUD(int exp, float currentLevelPercent)
void AVampirePlayerController::UpdatePlayerEXPHUD(int Exp, float CurrentLevelPercent)
{
if (currentPlayerHUD)
if (CurrentPlayerHUD)
{
currentPlayerHUD->UpdateEXPBar(currentLevelPercent);
CurrentPlayerHUD->UpdateEXPBar(CurrentLevelPercent);
}
}
void AVampirePlayerController::ShowLevelUpScreen(int level)
void AVampirePlayerController::ShowLevelUpScreen(int Level)
{
APawn* pawn = GetPawn();
if (!pawn)
@ -146,8 +148,8 @@ void AVampirePlayerController::ShowLevelUpScreen(int level)
return;
}
UEXPComponent* expComponent = pawn->GetComponentByClass<UEXPComponent>();
if (!expComponent || expComponent->GetCurrentLevel() == 0)
UEXPComponent* ExpComponent = pawn->GetComponentByClass<UEXPComponent>();
if (!ExpComponent || ExpComponent->GetCurrentLevel() == 0)
{
return;
}
@ -156,53 +158,54 @@ void AVampirePlayerController::ShowLevelUpScreen(int level)
{
if (SetPause(true))
{
currentLevelUpUI = CreateWidget<ULevelUpWidget, AVampirePlayerController*>(this, LevelUpUI.Get());
if (currentLevelUpUI)
CurrentLevelUpUI = CreateWidget<ULevelUpWidget, AVampirePlayerController*>(this, LevelUpUI.Get());
if (CurrentLevelUpUI)
{
currentLevelUpUI->AddToViewport();
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, currentLevelUpUI, EMouseLockMode::LockInFullscreen);
CurrentLevelUpUI->AddToViewport();
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, CurrentLevelUpUI,
EMouseLockMode::LockInFullscreen);
bShowMouseCursor = true;
}
}
}
}
void AVampirePlayerController::UpdatePlayerLevelHUD(int level)
void AVampirePlayerController::UpdatePlayerLevelHUD(int Level)
{
if (currentPlayerHUD)
if (CurrentPlayerHUD)
{
currentPlayerHUD->UpdateLevelBlock(level);
CurrentPlayerHUD->UpdateLevelBlock(Level);
}
}
void AVampirePlayerController::UpdateTimerHUD(float deltaTime)
void AVampirePlayerController::UpdateTimerHUD(float DeltaTime)
{
if (currentPlayerHUD)
if (CurrentPlayerHUD)
{
currentPlayerHUD->UpdateTimerBlock(deltaTime);
CurrentPlayerHUD->UpdateTimerBlock(DeltaTime);
}
}
void AVampirePlayerController::UpdateKillCountHUD(int killCount)
void AVampirePlayerController::UpdateKillCountHUD(int KillCount)
{
if (currentPlayerHUD)
if (CurrentPlayerHUD)
{
currentPlayerHUD->UpdateKillBlock(killCount);
CurrentPlayerHUD->UpdateKillBlock(KillCount);
}
}
void AVampirePlayerController::UpdateGoldCountHUD(int goldCount)
void AVampirePlayerController::UpdateGoldCountHUD(int GoldCount)
{
if (currentPlayerHUD)
if (CurrentPlayerHUD)
{
currentPlayerHUD->UpdateGoldBlock(goldCount);
CurrentPlayerHUD->UpdateGoldBlock(GoldCount);
}
}
void AVampirePlayerController::UpdateTimerHUDElement_Implementation(float deltaTime)
void AVampirePlayerController::UpdateTimerHUDElement_Implementation(float DeltaTime)
{
if (currentPlayerHUD)
if (CurrentPlayerHUD)
{
currentPlayerHUD->UpdateTimerBlock(deltaTime);
CurrentPlayerHUD->UpdateTimerBlock(DeltaTime);
}
}

View File

@ -41,15 +41,15 @@ public:
private:
UPROPERTY()
TObjectPtr<UHUDWidget> currentPlayerHUD = nullptr;
TObjectPtr<UHUDWidget> CurrentPlayerHUD = nullptr;
UPROPERTY()
TObjectPtr<UPauseWidget> currentPauseUI = nullptr;
TObjectPtr<UPauseWidget> CurrentPauseUI = nullptr;
UPROPERTY()
TObjectPtr<ULevelUpWidget> currentLevelUpUI = nullptr;
TObjectPtr<ULevelUpWidget> CurrentLevelUpUI = nullptr;
FTimerHandle pawnLifeTimeHandle;
FTimerHandle PawnLifeTimeHandle;
protected:
virtual void OnPossess(APawn* aPawn) override;
@ -65,22 +65,22 @@ protected:
void OnPause(const FInputActionValue& PauseInput);
UFUNCTION()
void UpdatePlayerEXPHUD(int exp, float currentLevelPercent);
void UpdatePlayerEXPHUD(int Exp, float CurrentLevelPercent);
UFUNCTION()
void ShowLevelUpScreen(int level);
void ShowLevelUpScreen(int Level);
UFUNCTION()
void UpdatePlayerLevelHUD(int level);
void UpdatePlayerLevelHUD(int Level);
UFUNCTION(BlueprintCallable)
void UpdateTimerHUD(float deltaTime);
void UpdateTimerHUD(float DeltaTime);
UFUNCTION()
void UpdateKillCountHUD(int killCount);
void UpdateKillCountHUD(int KillCount);
UFUNCTION()
void UpdateGoldCountHUD(int goldCount);
void UpdateGoldCountHUD(int GoldCount);
virtual void UpdateTimerHUDElement_Implementation(float deltaTime) override;
virtual void UpdateTimerHUDElement_Implementation(float DeltaTime) override;
};

View File

@ -54,10 +54,11 @@ protected:
private:
FTimerHandle WeaponTimerHandle;
public:
protected:
// Sets default values for this actor's
AWeapon();
public:
UFUNCTION(BlueprintNativeEvent)
bool UpgradeWeapon();
virtual bool UpgradeWeapon_Implementation();

View File

@ -25,37 +25,37 @@ void UWeaponInventoryComponent::BeginPlay()
void UWeaponInventoryComponent::InitializeInventory()
{
inventory.Empty();
Inventory.Empty();
for (TSubclassOf<AWeapon> weapon : initialInventory)
for (TSubclassOf<AWeapon> Weapon : InitialInventory)
{
if (IsValid(weapon))
if (IsValid(Weapon))
{
AddWeaponToInventory(weapon);
AddWeaponToInventory(Weapon);
}
}
}
void UWeaponInventoryComponent::AddWeaponToInventory(TSubclassOf<AWeapon> Weapon)
void UWeaponInventoryComponent::AddWeaponToInventory(TSubclassOf<AWeapon> NewWeapon)
{
FActorSpawnParameters SpawnParameters;
SpawnParameters.Owner = GetOwner();
AWeapon* weapon = GetWorld()->SpawnActor<AWeapon>(Weapon, SpawnParameters.Owner->GetTransform(), SpawnParameters);
if (weapon->GetFollowPlayer())
AWeapon* Weapon = GetWorld()->SpawnActor<AWeapon>(NewWeapon, SpawnParameters.Owner->GetTransform(), SpawnParameters);
if (Weapon->GetFollowPlayer())
{
weapon->AttachToActor(GetOwner(), FAttachmentTransformRules::KeepWorldTransform);
Weapon->AttachToActor(GetOwner(), FAttachmentTransformRules::KeepWorldTransform);
}
else
{
weapon->SetActorLocation(FVector::ZeroVector);
Weapon->SetActorLocation(FVector::ZeroVector);
}
inventory.Add(weapon);
obtainableWeapons.Remove(Weapon);
Inventory.Add(Weapon);
ObtainableWeapons.Remove(NewWeapon);
}
TArray<AWeapon*> UWeaponInventoryComponent::GetInventory()
{
return inventory;
return Inventory;
}

View File

@ -15,16 +15,15 @@ class VAMPIRES_API UWeaponInventoryComponent : public UActorComponent
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<TSubclassOf<AWeapon>> ObtainableWeapons;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<TSubclassOf<AWeapon>> obtainableWeapons;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<TSubclassOf<AWeapon>> initialInventory;
TArray<TSubclassOf<AWeapon>> InitialInventory;
private:
UPROPERTY()
TArray<TObjectPtr<AWeapon>> inventory;
TArray<TObjectPtr<AWeapon>> Inventory;
public:
// Sets default values for this component's properties
@ -39,7 +38,7 @@ public:
void InitializeInventory();
UFUNCTION()
void AddWeaponToInventory(TSubclassOf<AWeapon> Weapon);
void AddWeaponToInventory(TSubclassOf<AWeapon> NewWeapon);
UFUNCTION()
TArray<AWeapon*> GetInventory();

View File

@ -52,7 +52,7 @@ void ULevelUpWidget::NativeConstruct()
}
// Get list of weapons that the player can still obtain
TArray<TSubclassOf<AWeapon>> ObtainableWeapons = InventoryComponent->obtainableWeapons;
TArray<TSubclassOf<AWeapon>> ObtainableWeapons = InventoryComponent->ObtainableWeapons;
for (TSubclassOf<AWeapon> Weapon : ObtainableWeapons)
{
UUpgradeButtonDataObject* Temp = NewObject<UUpgradeButtonDataObject>(this);

View File

@ -93,7 +93,7 @@ void UUpgradeButtonWidget::OnClicked()
if (UWeaponInventoryComponent* Inventory = PlayerController->GetPawn()->GetComponentByClass<UWeaponInventoryComponent>())
{
Inventory->AddWeaponToInventory(WeaponTemplate);
Inventory->obtainableWeapons.Remove(WeaponTemplate);
Inventory->ObtainableWeapons.Remove(WeaponTemplate);
}
break;