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,22 +15,21 @@ UEXPComponent::UEXPComponent()
// ... // ...
} }
void UEXPComponent::IncrementEXP(int value) void UEXPComponent::IncrementEXP(int Value)
{ {
int oldEXP = CurrentEXP; int OldLevel = CurrentLevel;
int oldLevel = CurrentLevel; CurrentEXP += Value;
CurrentEXP += value;
if (NextLevelRow.Level >= 0) if (NextLevelRow.Level >= 0)
{ {
if (CurrentEXP >= NextLevelRow.CumulativeExpForNextLevel) if (CurrentEXP >= NextLevelRow.CumulativeExpForNextLevel)
{ {
CurrentLevel = NextLevelRow.Level; 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 else
{ {
@ -39,37 +38,36 @@ void UEXPComponent::IncrementEXP(int value)
NextLevelRow.ExpRequiredForNextLevel += 16; NextLevelRow.ExpRequiredForNextLevel += 16;
NextLevelRow.CumulativeExpForNextLevel += NextLevelRow.ExpRequiredForNextLevel; NextLevelRow.CumulativeExpForNextLevel += NextLevelRow.ExpRequiredForNextLevel;
} }
OnEXPLevelUp.Broadcast(CurrentLevel); OnEXPLevelUp.Broadcast(CurrentLevel);
} }
} }
else else
{ {
CurrentLevel = FMath::Floor(CurrentEXP / 100.0f); CurrentLevel = FMath::Floor(CurrentEXP / 100.0f);
if (CurrentLevel != oldLevel) if (CurrentLevel != OldLevel)
{ {
OnEXPLevelUp.Broadcast(CurrentLevel); OnEXPLevelUp.Broadcast(CurrentLevel);
} }
} }
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent()); OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
} }
void UEXPComponent::SetCurrentEXP(int value) void UEXPComponent::SetCurrentEXP(int Value)
{ {
int oldEXP = CurrentEXP; int OldLevel = CurrentLevel;
int oldLevel = CurrentLevel; CurrentEXP = Value;
CurrentEXP = value;
NextLevelRow = FExpTableRow(); 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 else
{ {
@ -78,11 +76,11 @@ void UEXPComponent::SetCurrentEXP(int value)
NextLevelRow.ExpRequiredForNextLevel += 16; NextLevelRow.ExpRequiredForNextLevel += 16;
NextLevelRow.CumulativeExpForNextLevel += NextLevelRow.ExpRequiredForNextLevel; NextLevelRow.CumulativeExpForNextLevel += NextLevelRow.ExpRequiredForNextLevel;
} }
} }
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent()); OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
if (CurrentLevel != oldLevel) if (CurrentLevel != OldLevel)
{ {
OnEXPLevelUp.Broadcast(CurrentLevel); OnEXPLevelUp.Broadcast(CurrentLevel);
} }
@ -102,12 +100,12 @@ void UEXPComponent::Reset()
{ {
if (LevelsTable) if (LevelsTable)
{ {
if (FExpTableRow* newRow = LevelsTable->FindRow<FExpTableRow>(FName("1"), "", true)) if (FExpTableRow* NewRow = LevelsTable->FindRow<FExpTableRow>(FName("1"), "", true))
{ {
NextLevelRow = *newRow; NextLevelRow = *NewRow;
} }
} }
CurrentEXP = 0; CurrentEXP = 0;
CurrentLevel = 0; CurrentLevel = 0;
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent()); OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
@ -116,15 +114,16 @@ void UEXPComponent::Reset()
float UEXPComponent::GetCurrentLevelPercent() float UEXPComponent::GetCurrentLevelPercent()
{ {
int adjustedCurrentExp = CurrentEXP - NextLevelRow.CumulativeExpForPreviousLevel; int AdjustedCurrentExp = CurrentEXP - NextLevelRow.CumulativeExpForPreviousLevel;
float res = static_cast<float>(adjustedCurrentExp) / static_cast<float>(NextLevelRow.ExpRequiredForNextLevel); float CurrentLevelPercent = static_cast<float>(AdjustedCurrentExp) / static_cast<float>(NextLevelRow.
ExpRequiredForNextLevel);
if (FMath::IsNaN(res)) if (FMath::IsNaN(CurrentLevelPercent))
{ {
return 0.0f; return 0.0f;
} }
return res; return CurrentLevelPercent;
} }
// Called when the game starts // Called when the game starts

View File

@ -8,6 +8,7 @@
#include "EXPComponent.generated.h" #include "EXPComponent.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnEXPGainedDelegate, int, exp, float, currentLevelPercent); DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnEXPGainedDelegate, int, exp, float, currentLevelPercent);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEXPLevelUpDelegate, int, level); DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEXPLevelUpDelegate, int, level);
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
@ -16,16 +17,16 @@ class VAMPIRES_API UEXPComponent : public UActorComponent
GENERATED_BODY() GENERATED_BODY()
public: public:
UPROPERTY(BlueprintAssignable, Category="EXP") UPROPERTY(BlueprintAssignable, Category="EXP")
FOnEXPGainedDelegate OnEXPGained; FOnEXPGainedDelegate OnEXPGained;
UPROPERTY(BlueprintAssignable, Category="EXP") UPROPERTY(BlueprintAssignable, Category="EXP")
FOnEXPLevelUpDelegate OnEXPLevelUp; FOnEXPLevelUpDelegate OnEXPLevelUp;
UPROPERTY(EditDefaultsOnly, Category="EXP") UPROPERTY(EditDefaultsOnly, Category="EXP")
TObjectPtr<UDataTable> LevelsTable; TObjectPtr<UDataTable> LevelsTable;
protected: private:
int CurrentEXP = 0; int CurrentEXP = 0;
int CurrentLevel = 0; int CurrentLevel = 0;
@ -37,10 +38,10 @@ public:
UEXPComponent(); UEXPComponent();
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void IncrementEXP(int value); void IncrementEXP(int Value);
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void SetCurrentEXP(int value); void SetCurrentEXP(int Value);
UFUNCTION(BlueprintCallable, BlueprintPure) UFUNCTION(BlueprintCallable, BlueprintPure)
int GetCurrentEXP(); int GetCurrentEXP();
@ -57,8 +58,4 @@ public:
protected: protected:
// Called when the game starts // Called when the game starts
virtual void BeginPlay() override; 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, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult) 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); Super::OnInnerBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
} }
} }

View File

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

View File

@ -47,12 +47,12 @@ UBehaviorTree* AEnemyCharacter::GetBehaviorTree()
return BehaviorTree; return BehaviorTree;
} }
void AEnemyCharacter::OnDamaged(FDamageInfo damageInfo) void AEnemyCharacter::OnDamaged(FDamageInfo DamageInfo)
{ {
// if (OnDamagedSound) if (OnDamagedSound)
// { {
UGameplayStatics::PlaySoundAtLocation(GetWorld(), OnDamagedSound, GetActorLocation()); UGameplayStatics::PlaySoundAtLocation(GetWorld(), OnDamagedSound, GetActorLocation());
// } }
if (OnDamagedNiagaraSystem) if (OnDamagedNiagaraSystem)
{ {
@ -60,22 +60,22 @@ void AEnemyCharacter::OnDamaged(FDamageInfo damageInfo)
} }
} }
void AEnemyCharacter::OnDeath(FDamageInfo damageInfo) void AEnemyCharacter::OnDeath(FDamageInfo DamageInfo)
{ {
if (PickupTemplate) if (PickupTemplate)
{ {
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_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(); FVector PickupLocation = GetActorLocation();
pickup->SetActorLocation(pickupLocation); Pickup->SetActorLocation(PickupLocation);
IPickupable::Execute_LoadDataFromDataAsset(pickup, PickupTemplate, 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); StaticMeshComponent->SetStaticMesh(EnemyDataAsset->StaticMesh);
BehaviorTree = enemyDataAsset->BehaviorTree; BehaviorTree = EnemyDataAsset->BehaviorTree;
PickupTemplate = enemyDataAsset->PickupDataAsset; PickupTemplate = EnemyDataAsset->PickupDataAsset;
OnDamagedSound = enemyDataAsset->OnDamagedSoundBase; OnDamagedSound = EnemyDataAsset->OnDamagedSoundBase;
OnDeathSound = enemyDataAsset->OnDeathSoundBase; OnDeathSound = EnemyDataAsset->OnDeathSoundBase;
OnDamagedNiagaraSystem = enemyDataAsset->OnDamagedNiagaraSystem; OnDamagedNiagaraSystem = EnemyDataAsset->OnDamagedNiagaraSystem;
OnDeathNiagaraSystem = enemyDataAsset->OnDeathNiagaraSystem; OnDeathNiagaraSystem = EnemyDataAsset->OnDeathNiagaraSystem;
} }
} }
@ -129,10 +129,10 @@ void AEnemyCharacter::SpawnController_Implementation()
SpawnDefaultController(); SpawnDefaultController();
} }
if (BehaviorTree != nullptr) if (AVampireAIController* VampireAIController = Cast<AVampireAIController>(Controller); VampireAIController &&
BehaviorTree)
{ {
AVampireAIController* controller = Cast<AVampireAIController>(Controller); VampireAIController->RunBehaviorTree(BehaviorTree);
controller->RunBehaviorTree(BehaviorTree);
} }
} }
@ -142,20 +142,23 @@ UHealthComponent* AEnemyCharacter::GetEnemyHealthComponent_Implementation()
} }
void AEnemyCharacter::OnDamageBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, 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); Player.Add(OtherActor);
GetWorldTimerManager().SetTimer(DamageTimerHandle, this, &AEnemyCharacter::DamagePlayer, AttackCooldown, true); GetWorldTimerManager().SetTimer(DamageTimerHandle, this, &AEnemyCharacter::DamagePlayer, AttackCooldown, true);
} }
} }
void AEnemyCharacter::OnDamageEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, 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); Player.Remove(OtherActor);
@ -170,8 +173,8 @@ void AEnemyCharacter::ResetHealth()
void AEnemyCharacter::DamagePlayer() 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 "Interfaces/Enemyable.h"
#include "EnemyCharacter.generated.h" #include "EnemyCharacter.generated.h"
struct FDamageInfo;
class USphereComponent; class USphereComponent;
class UObjectPoolComponent; class UObjectPoolComponent;
class UBehaviorTree; class UBehaviorTree;
@ -20,7 +21,7 @@ class VAMPIRES_API AEnemyCharacter : public AVampireCharacter, public IEnemyable
{ {
GENERATED_BODY() GENERATED_BODY()
public: protected:
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
TSubclassOf<AEXPPickup> EXPPickupTemplate = nullptr; TSubclassOf<AEXPPickup> EXPPickupTemplate = nullptr;
@ -28,7 +29,7 @@ public:
TObjectPtr<USphereComponent> DamageSphere = nullptr; TObjectPtr<USphereComponent> DamageSphere = nullptr;
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
float Damage = 5.0f;; float Damage = 5.0f;
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
float AttackCooldown = 1.0f; float AttackCooldown = 1.0f;
@ -53,19 +54,20 @@ public:
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override; virtual void Tick(float DeltaTime) override;
public:
UBehaviorTree* GetBehaviorTree(); UBehaviorTree* GetBehaviorTree();
UFUNCTION() UFUNCTION()
virtual void OnDamaged(FDamageInfo damageInfo); virtual void OnDamaged(FDamageInfo DamageInfo);
UFUNCTION() UFUNCTION()
virtual void OnDeath(FDamageInfo damageInfo); virtual void OnDeath(FDamageInfo DamageInfo);
protected:
UFUNCTION() UFUNCTION()
virtual void LoadDataFromDataAsset_Implementation(UEnemyDataAsset* enemyDataAsset) override; virtual void LoadDataFromDataAsset_Implementation(UEnemyDataAsset* EnemyDataAsset) override;
UFUNCTION() UFUNCTION()
virtual void ResetData_Implementation() override; virtual void ResetData_Implementation() override;
@ -81,12 +83,12 @@ public:
UFUNCTION() UFUNCTION()
void OnDamageBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, void OnDamageBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult); const FHitResult& SweepResult);
UFUNCTION() UFUNCTION()
void OnDamageEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, void OnDamageEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex); int32 OtherBodyIndex);
private: private:
UFUNCTION() UFUNCTION()

View File

@ -19,24 +19,24 @@ class VAMPIRES_API UEnemyDataAsset : public UDataAsset
GENERATED_BODY() GENERATED_BODY()
public: public:
UPROPERTY(BlueprintReadWrite, EditAnywhere) UPROPERTY(EditDefaultsOnly)
TObjectPtr<UStaticMesh> StaticMesh; TObjectPtr<UStaticMesh> StaticMesh;
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) UPROPERTY(EditDefaultsOnly)
TObjectPtr<UBehaviorTree> BehaviorTree = nullptr; TObjectPtr<UBehaviorTree> BehaviorTree = nullptr;
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) UPROPERTY(EditDefaultsOnly)
TObjectPtr<UPickupDataAsset> PickupDataAsset = nullptr; TObjectPtr<UPickupDataAsset> PickupDataAsset = nullptr;
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) UPROPERTY(EditDefaultsOnly)
TObjectPtr<USoundBase> OnDamagedSoundBase = nullptr; TObjectPtr<USoundBase> OnDamagedSoundBase = nullptr;
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) UPROPERTY(EditDefaultsOnly)
TObjectPtr<USoundBase> OnDeathSoundBase = nullptr; TObjectPtr<USoundBase> OnDeathSoundBase = nullptr;
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) UPROPERTY(EditDefaultsOnly)
TObjectPtr<UNiagaraSystem> OnDamagedNiagaraSystem; TObjectPtr<UNiagaraSystem> OnDamagedNiagaraSystem;
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) UPROPERTY(EditDefaultsOnly)
TObjectPtr<UNiagaraSystem> OnDeathNiagaraSystem; 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); OnGoldGained.Broadcast(CurrentGold);
} }
void UGoldComponent::SetCurrentGold(int value) void UGoldComponent::SetCurrentGold(int Value)
{ {
CurrentGold = value; CurrentGold = Value;
OnGoldGained.Broadcast(CurrentGold); OnGoldGained.Broadcast(CurrentGold);
} }

View File

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

View File

@ -16,9 +16,9 @@ void AGoldPickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult) 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); Super::OnInnerBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
} }
} }

View File

@ -13,12 +13,11 @@ UCLASS()
class VAMPIRES_API AGoldPickup : public APickup class VAMPIRES_API AGoldPickup : public APickup
{ {
GENERATED_BODY() GENERATED_BODY()
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
public:
virtual void OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, virtual void OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult) override; const FHitResult& SweepResult) override;
}; };

View File

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

View File

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

View File

@ -10,44 +10,45 @@ void AObjectPoolManager::BeginPlay()
Super::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++) 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); SetObjectStatus(false, Object);
ObjectPool.Add(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++) for (int i = 0; i < InitialObjectPoolSize; i++)
{ {
if (AActor* object = GetWorld()->SpawnActor<AActor>(Object)) if (AActor* Object = GetWorld()->SpawnActor<AActor>(TemplateObject))
{ {
SetObjectStatus(false, object); SetObjectStatus(false, Object);
ObjectPool.Add(object); ObjectPool.Add(Object);
} }
} }
} }
AActor* AObjectPoolManager::GetObject(int startingOffset) AActor* AObjectPoolManager::GetObject(int StartingOffset)
{ {
int ObjectPoolSize = ObjectPool.Num(); int ObjectPoolSize = ObjectPool.Num();
for (int i = startingOffset; i < ObjectPoolSize; i++) for (int i = StartingOffset; i < ObjectPoolSize; i++)
{ {
if (ObjectPool[i]->IsHidden()) if (ObjectPool[i]->IsHidden())
{ {
SetObjectStatus(true, ObjectPool[i]); 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]; return ObjectPool[i];
@ -59,19 +60,19 @@ AActor* AObjectPoolManager::GetObject(int startingOffset)
return GetObject(ObjectPoolSize); 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->SetActorHiddenInGame(!bEnabled);
object->SetActorTickEnabled(enabled); Object->SetActorTickEnabled(bEnabled);
object->SetActorEnableCollision(enabled); Object->SetActorEnableCollision(bEnabled);
} }

View File

@ -13,19 +13,19 @@ class VAMPIRES_API AObjectPoolManager : public AActor
TArray<TObjectPtr<AActor>> ObjectPool = TArray<TObjectPtr<AActor>>(); TArray<TObjectPtr<AActor>> ObjectPool = TArray<TObjectPtr<AActor>>();
TSubclassOf<AActor> ObjectTemplate; TSubclassOf<AActor> ObjectTemplate;
public: public:
void InitializeObjectPool(TSubclassOf<AActor> Object, int InitialObjectPoolSize = 400); void InitializeObjectPool(const TSubclassOf<AActor>& TemplateObject, int InitialObjectPoolSize = 400);
void InitializeObjectPool(UClass* Object, 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: protected:
// Called when the game starts or when spawned // Called when the game starts or when spawned
virtual void BeginPlay() override; virtual void BeginPlay() override;
private: 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->SetTimelineLengthMode(TL_TimelineLength);
TimelineComponent->SetPlaybackPosition(0.0f, false); TimelineComponent->SetPlaybackPosition(0.0f, false);
onTimelineCallback.BindUFunction(this, FName(TEXT("TimelineCallback"))); OnTimelineCallback.BindUFunction(this, FName(TEXT("TimelineCallback")));
onTimelineFinishedCallback.BindUFunction(this, FName(TEXT("TimelineFinishedCallback"))); OnTimelineFinishedCallback.BindUFunction(this, FName(TEXT("TimelineFinishedCallback")));
NiagaraComponent = CreateDefaultSubobject<UNiagaraComponent>(TEXT("Niagara Component")); NiagaraComponent = CreateDefaultSubobject<UNiagaraComponent>(TEXT("Niagara Component"));
NiagaraComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform); NiagaraComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
@ -60,8 +60,8 @@ void APickup::BeginPlay()
if (CurveFloat != nullptr) if (CurveFloat != nullptr)
{ {
TimelineComponent->AddInterpFloat(CurveFloat, onTimelineCallback); TimelineComponent->AddInterpFloat(CurveFloat, OnTimelineCallback);
TimelineComponent->SetTimelineFinishedFunc(onTimelineFinishedCallback); TimelineComponent->SetTimelineFinishedFunc(OnTimelineFinishedCallback);
} }
} }
@ -74,11 +74,11 @@ void APickup::LoadDataFromDataAsset_Implementation(UPickupDataAsset* PickupDataA
PickupSoundBase = PickupDataAsset->PickupSoundBase; PickupSoundBase = PickupDataAsset->PickupSoundBase;
CurveFloat = PickupDataAsset->CurveFloat; CurveFloat = PickupDataAsset->CurveFloat;
PickupLocation = Location; PickupLocation = Location;
if (CurveFloat != nullptr) if (CurveFloat != nullptr)
{ {
TimelineComponent->AddInterpFloat(CurveFloat, onTimelineCallback); TimelineComponent->AddInterpFloat(CurveFloat, OnTimelineCallback);
TimelineComponent->SetTimelineFinishedFunc(onTimelineFinishedCallback); TimelineComponent->SetTimelineFinishedFunc(OnTimelineFinishedCallback);
} }
} }
} }
@ -110,14 +110,14 @@ void APickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AAct
UGameplayStatics::PlaySound2D(GetWorld(), PickupSoundBase); UGameplayStatics::PlaySound2D(GetWorld(), PickupSoundBase);
} }
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))
{ {
TimelineComponent->Stop(); TimelineComponent->Stop();
ResetData_Implementation(); ResetData_Implementation();
objectPoolManager->ReturnObject(this); ObjectPoolManager->ReturnObject(this);
} }
} }
else else
@ -131,18 +131,19 @@ void APickup::OnOuterBeginOverlap(UPrimitiveComponent* OverlappedComponent, AAct
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult) const FHitResult& SweepResult)
{ {
if (!TimelineComponent->IsPlaying() && UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) == Cast<ACharacter>(OtherActor)) if (!TimelineComponent->IsPlaying() && UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) == Cast<
ACharacter>(OtherActor))
{ {
PlayTimeLine(); PlayTimeLine();
} }
} }
void APickup::TimelineCallback(float val) void APickup::TimelineCallback(float Value)
{ {
FVector actorLocation = PickupLocation; FVector ActorLocation = PickupLocation;
FVector playerLocation = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)->GetActorLocation(); FVector PlayerLocation = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)->GetActorLocation();
FVector location = FMath::Lerp(actorLocation, playerLocation, val); FVector Location = FMath::Lerp(ActorLocation, PlayerLocation, Value);
SetActorLocation(location); SetActorLocation(Location);
} }
void APickup::TimelineFinishedCallback() void APickup::TimelineFinishedCallback()

View File

@ -18,10 +18,10 @@ class VAMPIRES_API APickup : public AActor, public IPickupable
{ {
GENERATED_BODY() GENERATED_BODY()
public: protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
int PickupValue = 1; int PickupValue = 1;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TObjectPtr<USphereComponent> InnerSphereComponent = nullptr; TObjectPtr<USphereComponent> InnerSphereComponent = nullptr;
@ -44,8 +44,8 @@ public:
TObjectPtr<UNiagaraComponent> NiagaraComponent = nullptr; TObjectPtr<UNiagaraComponent> NiagaraComponent = nullptr;
private: private:
FOnTimelineFloat onTimelineCallback; FOnTimelineFloat OnTimelineCallback;
FOnTimelineEventStatic onTimelineFinishedCallback; FOnTimelineEventStatic OnTimelineFinishedCallback;
FVector PickupLocation; FVector PickupLocation;
@ -56,11 +56,11 @@ public:
protected: protected:
// Called when the game starts or when spawned // Called when the game starts or when spawned
virtual void BeginPlay() override; virtual void BeginPlay() override;
virtual void LoadDataFromDataAsset_Implementation(UPickupDataAsset* PickupDataAsset, FVector Location) override; virtual void LoadDataFromDataAsset_Implementation(UPickupDataAsset* PickupDataAsset, FVector Location) override;
virtual void ResetData_Implementation() override; virtual void ResetData_Implementation() override;
UFUNCTION() UFUNCTION()
virtual void OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, virtual void OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
@ -72,7 +72,7 @@ protected:
const FHitResult& SweepResult); const FHitResult& SweepResult);
UFUNCTION() UFUNCTION()
void TimelineCallback(float val); void TimelineCallback(float Value);
UFUNCTION() UFUNCTION()
void TimelineFinishedCallback(); void TimelineFinishedCallback();

View File

@ -37,8 +37,8 @@ APlayerCharacter::APlayerCharacter()
CameraShakeTimelineComponent->SetTimelineLengthMode(TL_TimelineLength); CameraShakeTimelineComponent->SetTimelineLengthMode(TL_TimelineLength);
CameraShakeTimelineComponent->SetPlaybackPosition(0.0f, false); CameraShakeTimelineComponent->SetPlaybackPosition(0.0f, false);
onTimelineCallback.BindUFunction(this, FName(TEXT("CameraShakeTimelineCallback"))); OnTimelineCallback.BindUFunction(this, FName(TEXT("CameraShakeTimelineCallback")));
onTimelineFinishedCallback.BindUFunction(this, FName(TEXT("CameraShakeTimelineFinishedCallback"))); OnTimelineFinishedCallback.BindUFunction(this, FName(TEXT("CameraShakeTimelineFinishedCallback")));
} }
void APlayerCharacter::BeginPlay() void APlayerCharacter::BeginPlay()
@ -50,8 +50,8 @@ void APlayerCharacter::BeginPlay()
if (CameraShakeCurve != nullptr) if (CameraShakeCurve != nullptr)
{ {
CameraShakeTimelineComponent->AddInterpFloat(CameraShakeCurve, onTimelineCallback); CameraShakeTimelineComponent->AddInterpFloat(CameraShakeCurve, OnTimelineCallback);
CameraShakeTimelineComponent->SetTimelineFinishedFunc(onTimelineFinishedCallback); CameraShakeTimelineComponent->SetTimelineFinishedFunc(OnTimelineFinishedCallback);
} }
PlayerCameraManager = GetWorld()->GetFirstPlayerController()->PlayerCameraManager; PlayerCameraManager = GetWorld()->GetFirstPlayerController()->PlayerCameraManager;
@ -62,7 +62,7 @@ void APlayerCharacter::Tick(float DeltaTime)
Super::Tick(DeltaTime); Super::Tick(DeltaTime);
auto PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0); auto PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
FVector TopLeft, TopLeftDir; FVector TopLeft, TopLeftDir;
FVector BottomRight, BottomRightDir; FVector BottomRight, BottomRightDir;
@ -113,7 +113,8 @@ void APlayerCharacter::CameraShakeTimelineCallback(float val)
{ {
auto PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0); auto PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
auto cameraActor = PlayerController->GetViewTarget(); 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() void APlayerCharacter::CameraShakeTimelineFinishedCallback()

View File

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

View File

@ -60,7 +60,8 @@ void AProjectile::SetActorHiddenInGame(bool bNewHidden)
} }
else 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()) if (!EnemyHealthComponent->GetIsDead())
{ {
AController* ownerController = nullptr; AController* OwnerController = nullptr;
if (AVampireCharacter* character = Cast<AVampireCharacter>(GetOwner())) if (AVampireCharacter* Character = Cast<AVampireCharacter>(GetOwner()))
{ {
ownerController = character->GetController(); OwnerController = Character->GetController();
} }
AProjectileWeapon* ownerWeapon = Cast<AProjectileWeapon>(GetOwner()); AProjectileWeapon* OwnerWeapon = Cast<AProjectileWeapon>(GetOwner());
EnemyHealthComponent->TakeDamage(Enemy, ownerWeapon->GetDamage(), nullptr, ownerController, this); EnemyHealthComponent->TakeDamage(Enemy, OwnerWeapon->GetDamage(), nullptr, OwnerController, this);
RemainingDamageableEnemies--; RemainingDamageableEnemies--;
@ -124,14 +125,14 @@ void AProjectile::OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedCompon
void AProjectile::ReturnProjectileToPool() 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 = if (AObjectPoolManager* ObjectPoolManager =
IPools::Execute_GetProjectileObjectPoolManager(gamemode)) 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 // Called when the game starts or when spawned
virtual void BeginPlay() override; virtual void BeginPlay() override;
public:
virtual void SetActorHiddenInGame(bool bNewHidden) override; virtual void SetActorHiddenInGame(bool bNewHidden) override;
virtual void SetTargetDirection_Implementation(FVector Direction) override; virtual void SetTargetDirection_Implementation(FVector Direction) override;

View File

@ -54,10 +54,10 @@ void AVampireAIController::OnPossess(APawn* InPawn)
PlayerCharacter = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0); PlayerCharacter = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0);
if (UBehaviorTree* bt = EnemyCharacter->GetBehaviorTree()) if (UBehaviorTree* BT = EnemyCharacter->GetBehaviorTree())
{ {
DefaultBlackboard->InitializeBlackboard(*bt->BlackboardAsset); DefaultBlackboard->InitializeBlackboard(*BT->BlackboardAsset);
BehaviorTree->StartTree(*bt); BehaviorTree->StartTree(*BT);
DefaultBlackboard->SetValueAsObject("SelfActor", EnemyCharacter); DefaultBlackboard->SetValueAsObject("SelfActor", EnemyCharacter);
if (PlayerCharacter) 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) 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->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);*/
} }
void AVampireAIController::PawnMoveTo() void AVampireAIController::PawnMoveTo()

View File

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

View File

@ -10,7 +10,7 @@
// Sets default values // Sets default values
AVampireCharacter::AVampireCharacter() 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; PrimaryActorTick.bCanEverTick = true;
// Create Health Component // Create Health Component
@ -22,15 +22,13 @@ AVampireCharacter::AVampireCharacter()
//Create Weapon Inventory Component //Create Weapon Inventory Component
WeaponInventoryComponent = CreateDefaultSubobject<UWeaponInventoryComponent>(TEXT("Weapon Inventory Component")); WeaponInventoryComponent = CreateDefaultSubobject<UWeaponInventoryComponent>(TEXT("Weapon Inventory Component"));
GetCharacterMovement()->SetPlaneConstraintNormal({0.0f, 0.0f, 1.0f}); GetCharacterMovement()->SetPlaneConstraintNormal({0.0f, 0.0f, 1.0f});
} }
// Called when the game starts or when spawned // Called when the game starts or when spawned
void AVampireCharacter::BeginPlay() void AVampireCharacter::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
} }
// Called every frame // Called every frame
@ -38,21 +36,21 @@ void AVampireCharacter::Tick(float DeltaTime)
{ {
Super::Tick(DeltaTime); Super::Tick(DeltaTime);
float newYaw = FMath::Atan2(PreviousMovementDirection.Y, PreviousMovementDirection.X) * 180.0f / PI; float NewYaw = FMath::Atan2(PreviousMovementDirection.Y, PreviousMovementDirection.X) * 180.0f / PI;
FQuat newRotation = FQuat::Slerp(StaticMeshComponent->GetComponentRotation().Quaternion(), FQuat NewRotation = FQuat::Slerp(StaticMeshComponent->GetComponentRotation().Quaternion(),
FRotator(0.0f, newYaw, 0.0f).Quaternion(), FRotator(0.0f, NewYaw, 0.0f).Quaternion(),
DeltaTime * SlerpSpeed); 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({0.0f, 1.0f, 0.0f}, Value.Y);
AddMovementInput({1.0f, 0.0f, 0.0f}, value.X); AddMovementInput({1.0f, 0.0f, 0.0f}, Value.X);
} }
} }
@ -70,4 +68,3 @@ UHealthComponent* AVampireCharacter::GetHealthComponent()
{ {
return HealthComponent; return HealthComponent;
} }

View File

@ -27,7 +27,7 @@ public:
UPROPERTY(BlueprintReadWrite, EditAnywhere) UPROPERTY(BlueprintReadWrite, EditAnywhere)
float SlerpSpeed = 10.0f; float SlerpSpeed = 10.0f;
protected: protected:
UPROPERTY(VisibleAnywhere) UPROPERTY(VisibleAnywhere)
TObjectPtr<UHealthComponent> HealthComponent; TObjectPtr<UHealthComponent> HealthComponent;
@ -58,15 +58,15 @@ protected:
// Called when the game starts or when spawned // Called when the game starts or when spawned
virtual void BeginPlay() override; virtual void BeginPlay() override;
public:
// Called every frame // Called every frame
virtual void Tick(float DeltaTime) override; 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 UInputMappingContext* Input_GetInputMappingContext_Implementation() override;
virtual FVector2D Input_GetPreviousMovementDirection_Implementation() override; virtual FVector2D Input_GetPreviousMovementDirection_Implementation() override;
public:
UHealthComponent* GetHealthComponent(); UHealthComponent* GetHealthComponent();
}; };

View File

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

View File

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

View File

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

View File

@ -23,53 +23,55 @@ void AVampirePlayerController::OnPossess(APawn* aPawn)
{ {
Super::OnPossess(aPawn); Super::OnPossess(aPawn);
if (UEnhancedInputLocalPlayerSubsystem* subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer())) if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(
GetLocalPlayer()))
{ {
if (UKismetSystemLibrary::DoesImplementInterface(aPawn, UInputable::StaticClass())) if (UKismetSystemLibrary::DoesImplementInterface(aPawn, UInputable::StaticClass()))
{ {
subsystem->AddMappingContext(IInputable::Execute_Input_GetInputMappingContext(aPawn), 0); Subsystem->AddMappingContext(IInputable::Execute_Input_GetInputMappingContext(aPawn), 0);
} }
} }
if (PlayerHUD) 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->OnEXPGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerEXPHUD);
expComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerLevelHUD); ExpComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerLevelHUD);
expComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::ShowLevelUpScreen); ExpComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::ShowLevelUpScreen);
UpdatePlayerEXPHUD(expComponent->GetCurrentEXP(), expComponent->GetCurrentLevelPercent()); UpdatePlayerEXPHUD(ExpComponent->GetCurrentEXP(), ExpComponent->GetCurrentLevelPercent());
UpdatePlayerLevelHUD(expComponent->GetCurrentLevel()); UpdatePlayerLevelHUD(ExpComponent->GetCurrentLevel());
} }
if (UGoldComponent* goldComponent = aPawn->GetComponentByClass<UGoldComponent>()) if (UGoldComponent* GoldComponent = aPawn->GetComponentByClass<UGoldComponent>())
{ {
goldComponent->OnGoldGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdateGoldCountHUD); GoldComponent->OnGoldGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdateGoldCountHUD);
UpdateGoldCountHUD(goldComponent->GetCurrentGold()); 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); Gamemode->OnEnemyDeathCountIncrementDelegate.
UpdateKillCountHUD(gamemode->GetEnemyDeathCount()); 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>(); 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(); Super::OnUnPossess();
GetWorld()->GetTimerManager().ClearTimer(pawnLifeTimeHandle); GetWorld()->GetTimerManager().ClearTimer(PawnLifeTimeHandle);
} }
void AVampirePlayerController::SetupInputComponent() void AVampirePlayerController::SetupInputComponent()
@ -94,13 +96,13 @@ void AVampirePlayerController::SetupInputComponent()
void AVampirePlayerController::Move(const FInputActionValue& MovementInput) void AVampirePlayerController::Move(const FInputActionValue& MovementInput)
{ {
FVector2D movement = MovementInput.Get<FVector2D>(); FVector2D Movement = MovementInput.Get<FVector2D>();
if (APawn* pawn = GetPawn()) if (APawn* pawn = GetPawn())
{ {
if (UKismetSystemLibrary::DoesImplementInterface(pawn, UInputable::StaticClass())) if (UKismetSystemLibrary::DoesImplementInterface(pawn, UInputable::StaticClass()))
{ {
IInputable::Execute_Input_Move(pawn, movement); IInputable::Execute_Input_Move(pawn, Movement);
} }
} }
} }
@ -114,95 +116,96 @@ void AVampirePlayerController::OnPause(const FInputActionValue& PauseInput)
IInputable::Execute_Input_Pause(pawn); IInputable::Execute_Input_Pause(pawn);
} }
} }
if (PauseUI) if (PauseUI)
{ {
if (SetPause(true)) if (SetPause(true))
{ {
currentPauseUI = CreateWidget<UPauseWidget, AVampirePlayerController*>(this, PauseUI.Get()); CurrentPauseUI = CreateWidget<UPauseWidget, AVampirePlayerController*>(this, PauseUI.Get());
if (currentPauseUI) if (CurrentPauseUI)
{ {
currentPauseUI->AddToViewport(); CurrentPauseUI->AddToViewport();
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, currentPauseUI, EMouseLockMode::LockInFullscreen); UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, CurrentPauseUI, EMouseLockMode::LockInFullscreen);
bShowMouseCursor = true; 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(); APawn* pawn = GetPawn();
if (!pawn) if (!pawn)
{ {
return; return;
} }
UEXPComponent* expComponent = pawn->GetComponentByClass<UEXPComponent>(); UEXPComponent* ExpComponent = pawn->GetComponentByClass<UEXPComponent>();
if (!expComponent || expComponent->GetCurrentLevel() == 0) if (!ExpComponent || ExpComponent->GetCurrentLevel() == 0)
{ {
return; return;
} }
if (LevelUpUI) if (LevelUpUI)
{ {
if (SetPause(true)) if (SetPause(true))
{ {
currentLevelUpUI = CreateWidget<ULevelUpWidget, AVampirePlayerController*>(this, LevelUpUI.Get()); CurrentLevelUpUI = CreateWidget<ULevelUpWidget, AVampirePlayerController*>(this, LevelUpUI.Get());
if (currentLevelUpUI) if (CurrentLevelUpUI)
{ {
currentLevelUpUI->AddToViewport(); CurrentLevelUpUI->AddToViewport();
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, currentLevelUpUI, EMouseLockMode::LockInFullscreen); UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, CurrentLevelUpUI,
EMouseLockMode::LockInFullscreen);
bShowMouseCursor = true; 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: private:
UPROPERTY() UPROPERTY()
TObjectPtr<UHUDWidget> currentPlayerHUD = nullptr; TObjectPtr<UHUDWidget> CurrentPlayerHUD = nullptr;
UPROPERTY() UPROPERTY()
TObjectPtr<UPauseWidget> currentPauseUI = nullptr; TObjectPtr<UPauseWidget> CurrentPauseUI = nullptr;
UPROPERTY() UPROPERTY()
TObjectPtr<ULevelUpWidget> currentLevelUpUI = nullptr; TObjectPtr<ULevelUpWidget> CurrentLevelUpUI = nullptr;
FTimerHandle pawnLifeTimeHandle; FTimerHandle PawnLifeTimeHandle;
protected: protected:
virtual void OnPossess(APawn* aPawn) override; virtual void OnPossess(APawn* aPawn) override;
@ -65,22 +65,22 @@ protected:
void OnPause(const FInputActionValue& PauseInput); void OnPause(const FInputActionValue& PauseInput);
UFUNCTION() UFUNCTION()
void UpdatePlayerEXPHUD(int exp, float currentLevelPercent); void UpdatePlayerEXPHUD(int Exp, float CurrentLevelPercent);
UFUNCTION() UFUNCTION()
void ShowLevelUpScreen(int level); void ShowLevelUpScreen(int Level);
UFUNCTION() UFUNCTION()
void UpdatePlayerLevelHUD(int level); void UpdatePlayerLevelHUD(int Level);
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void UpdateTimerHUD(float deltaTime); void UpdateTimerHUD(float DeltaTime);
UFUNCTION() UFUNCTION()
void UpdateKillCountHUD(int killCount); void UpdateKillCountHUD(int KillCount);
UFUNCTION() 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: private:
FTimerHandle WeaponTimerHandle; FTimerHandle WeaponTimerHandle;
public: protected:
// Sets default values for this actor's // Sets default values for this actor's
AWeapon(); AWeapon();
public:
UFUNCTION(BlueprintNativeEvent) UFUNCTION(BlueprintNativeEvent)
bool UpgradeWeapon(); bool UpgradeWeapon();
virtual bool UpgradeWeapon_Implementation(); virtual bool UpgradeWeapon_Implementation();

View File

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

View File

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

View File

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

View File

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