Compare commits

...

5 Commits

Author SHA1 Message Date
baz
1a3516c263 Only get viewport information when viewport is resized 2025-07-31 01:32:24 +01:00
baz
cb0230d24f Gate Setting Actor Location Behind Bounds Check 2025-07-30 17:59:14 +01:00
baz
c1e4387adb Final quick refactor 2025-07-29 22:06:42 +01:00
baz
ec818cfc55 Quick widgets refactor 2025-07-28 23:42:39 +01:00
baz
8d8da3ddc1 Final weapons quick refactor 2025-07-28 23:12:31 +01:00
72 changed files with 778 additions and 783 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;
int oldLevel = CurrentLevel; CurrentEXP += Value;
CurrentEXP += value;
if (NextLevelRow.Level >= 0) if (NextLevelRow.Level >= 0)
{ {
@ -28,9 +26,10 @@ void UEXPComponent::IncrementEXP(int value)
{ {
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
{ {
@ -47,7 +46,7 @@ void UEXPComponent::IncrementEXP(int value)
{ {
CurrentLevel = FMath::Floor(CurrentEXP / 100.0f); CurrentLevel = FMath::Floor(CurrentEXP / 100.0f);
if (CurrentLevel != oldLevel) if (CurrentLevel != OldLevel)
{ {
OnEXPLevelUp.Broadcast(CurrentLevel); OnEXPLevelUp.Broadcast(CurrentLevel);
} }
@ -56,20 +55,19 @@ void UEXPComponent::IncrementEXP(int value)
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
{ {
@ -82,7 +80,7 @@ void UEXPComponent::SetCurrentEXP(int value)
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent()); OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
if (CurrentLevel != oldLevel) if (CurrentLevel != OldLevel)
{ {
OnEXPLevelUp.Broadcast(CurrentLevel); OnEXPLevelUp.Broadcast(CurrentLevel);
} }
@ -102,9 +100,9 @@ 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;
} }
} }
@ -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,7 +17,6 @@ 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,9 +142,11 @@ 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);
@ -155,7 +157,8 @@ void AEnemyCharacter::OnDamageBeginOverlap(UPrimitiveComponent* OverlappedCompon
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;

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

@ -17,7 +17,6 @@ class VAMPIRES_API AGoldPickup : 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

@ -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

@ -15,17 +15,17 @@ class VAMPIRES_API AObjectPoolManager : public 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);
} }
} }
@ -77,8 +77,8 @@ void APickup::LoadDataFromDataAsset_Implementation(UPickupDataAsset* PickupDataA
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,7 +18,7 @@ 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;
@ -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;
@ -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

@ -3,14 +3,9 @@
#include "PlayerCharacter.h" #include "PlayerCharacter.h"
#include "VampirePlayerController.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "EXPComponent.h" #include "EXPComponent.h"
#include "GoldComponent.h" #include "GoldComponent.h"
#include "HealthComponent.h" #include "HealthComponent.h"
#include "InputMappingContext.h"
#include "WeaponInventoryComponent.h"
#include "Components/WidgetComponent.h" #include "Components/WidgetComponent.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
@ -37,8 +32,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,33 +45,30 @@ 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;
// For some reason, we need a slight delay here. I need to investigate the exact reason, but this is a quick workaround
GEngine->GameViewport->Viewport->ViewportResizedEvent.AddUObject(this, &APlayerCharacter::OnViewportResized);
GetWorldTimerManager().SetTimer(ResizeViewportTimerDelegate, this, &APlayerCharacter::ResizeViewportTimerCallback,
0.01f, false);
} }
void APlayerCharacter::Tick(float DeltaTime) void APlayerCharacter::Tick(float DeltaTime)
{ {
Super::Tick(DeltaTime); Super::Tick(DeltaTime);
auto PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0); FVector Location = GetActorLocation();
if (Location.X < BottomRight.X || Location.X > TopLeft.X || Location.Y > BottomRight.Y || Location.Y < TopLeft.Y)
{
Location.X = FMath::Clamp(Location.X, BottomRight.X, TopLeft.X);
Location.Y = FMath::Clamp(Location.Y, TopLeft.Y, BottomRight.Y);
FVector TopLeft, TopLeftDir; SetActorLocation(Location);
FVector BottomRight, BottomRightDir; }
FVector2d ViewportSize;
GEngine->GameViewport->GetViewportSize(ViewportSize);
PlayerController->DeprojectScreenPositionToWorld(0, 0, TopLeft, TopLeftDir);
PlayerController->DeprojectScreenPositionToWorld(ViewportSize.X, ViewportSize.Y, BottomRight, BottomRightDir);
auto location = GetActorLocation();
location.X = FMath::Clamp(location.X, BottomRight.X, TopLeft.X);
location.Y = FMath::Clamp(location.Y, TopLeft.Y, BottomRight.Y);
SetActorLocation(location);
} }
UEXPComponent* APlayerCharacter::GetEXPComponent() UEXPComponent* APlayerCharacter::GetEXPComponent()
@ -89,7 +81,7 @@ UGoldComponent* APlayerCharacter::GetGoldComponent()
return GoldComponent; return GoldComponent;
} }
void APlayerCharacter::OnDamaged(FDamageInfo damageInfo) void APlayerCharacter::OnDamaged(FDamageInfo DamageInfo)
{ {
if (OnDamagedSound) if (OnDamagedSound)
{ {
@ -99,21 +91,20 @@ void APlayerCharacter::OnDamaged(FDamageInfo damageInfo)
CameraShakeTimelineComponent->PlayFromStart(); CameraShakeTimelineComponent->PlayFromStart();
} }
void APlayerCharacter::OnDeath(FDamageInfo damageInfo) void APlayerCharacter::OnDeath(FDamageInfo DamageInfo)
{ {
if (OnDeathSound) if (OnDeathSound)
{ {
UGameplayStatics::PlaySoundAtLocation(GetWorld(), OnDeathSound, GetActorLocation()); UGameplayStatics::PlaySoundAtLocation(GetWorld(), OnDeathSound, GetActorLocation());
} }
// TODO: End the game
} }
void APlayerCharacter::CameraShakeTimelineCallback(float val) 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()
@ -122,3 +113,19 @@ void APlayerCharacter::CameraShakeTimelineFinishedCallback()
auto cameraActor = PlayerController->GetViewTarget(); auto cameraActor = PlayerController->GetViewTarget();
cameraActor->SetActorLocation(FVector::ZeroVector); cameraActor->SetActorLocation(FVector::ZeroVector);
} }
void APlayerCharacter::ResizeViewportTimerCallback()
{
OnViewportResized(GEngine->GameViewport->Viewport, 0);
}
void APlayerCharacter::OnViewportResized(FViewport* ViewPort, uint32 val)
{
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
FVector2d ViewportSize;
GEngine->GameViewport->GetViewportSize(ViewportSize);
PlayerController->DeprojectScreenPositionToWorld(0, 0, TopLeft, TopLeftDir);
PlayerController->DeprojectScreenPositionToWorld(ViewportSize.X, ViewportSize.Y, BottomRight, BottomRightDir);
}

View File

@ -5,6 +5,7 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "VampireCharacter.h" #include "VampireCharacter.h"
#include "Components/TimelineComponent.h" #include "Components/TimelineComponent.h"
#include "UnrealClient.h"
#include "PlayerCharacter.generated.h" #include "PlayerCharacter.generated.h"
struct FDamageInfo; struct FDamageInfo;
@ -24,7 +25,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;
@ -44,19 +45,22 @@ public:
float CameraShakeStrength = 100.0f; float CameraShakeStrength = 100.0f;
private: private:
UPROPERTY()
TObjectPtr<APlayerCameraManager> PlayerCameraManager = nullptr; TObjectPtr<APlayerCameraManager> PlayerCameraManager = nullptr;
APlayerCharacter(); FOnTimelineFloat OnTimelineCallback;
FOnTimelineEventStatic OnTimelineFinishedCallback;
private: FTimerHandle ResizeViewportTimerDelegate;
FOnTimelineFloat onTimelineCallback; FVector TopLeft, TopLeftDir, BottomRight, BottomRightDir;
FOnTimelineEventStatic onTimelineFinishedCallback;
APlayerCharacter();
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
public: public:
virtual void Tick(float DeltaTime) override; virtual void Tick(float DeltaTime) override;
UEXPComponent* GetEXPComponent(); UEXPComponent* GetEXPComponent();
@ -65,14 +69,19 @@ public:
private: private:
UFUNCTION() UFUNCTION()
virtual void OnDamaged(FDamageInfo damageInfo); virtual void OnDamaged(FDamageInfo DamageInfo);
UFUNCTION() UFUNCTION()
virtual void OnDeath(FDamageInfo damageInfo); virtual void OnDeath(FDamageInfo DamageInfo);
UFUNCTION() UFUNCTION()
void CameraShakeTimelineCallback(float val); void CameraShakeTimelineCallback(float Val);
UFUNCTION() UFUNCTION()
void CameraShakeTimelineFinishedCallback(); void CameraShakeTimelineFinishedCallback();
UFUNCTION()
void ResizeViewportTimerCallback();
void OnViewportResized(FViewport* ViewPort, uint32 val);
}; };

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

@ -29,8 +29,6 @@ AVampireCharacter::AVampireCharacter()
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

@ -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

@ -15,8 +15,8 @@ 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;

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);
} }
} }
} }
@ -119,26 +121,26 @@ void AVampirePlayerController::OnPause(const FInputActionValue& PauseInput)
{ {
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)
@ -146,8 +148,8 @@ void AVampirePlayerController::ShowLevelUpScreen(int level)
return; return;
} }
UEXPComponent* expComponent = pawn->GetComponentByClass<UEXPComponent>(); UEXPComponent* ExpComponent = pawn->GetComponentByClass<UEXPComponent>();
if (!expComponent || expComponent->GetCurrentLevel() == 0) if (!ExpComponent || ExpComponent->GetCurrentLevel() == 0)
{ {
return; return;
} }
@ -156,53 +158,54 @@ void AVampirePlayerController::ShowLevelUpScreen(int level)
{ {
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

@ -27,7 +27,10 @@ void AFireWandWeapon::FireWeaponAction_Implementation()
bool AFireWandWeapon::UpgradeWeapon_Implementation() bool AFireWandWeapon::UpgradeWeapon_Implementation()
{ {
if (!Super::UpgradeWeapon_Implementation()) return false; if (!Super::UpgradeWeapon_Implementation())
{
return false;
}
switch (CurrentLevel) switch (CurrentLevel)
{ {
@ -67,26 +70,26 @@ void AFireWandWeapon::FireProjectile()
{ {
if (ProjectileTemplate && OverlappedEnemies.Num() > 0) if (ProjectileTemplate && OverlappedEnemies.Num() > 0)
{ {
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))
{ {
AActor* projectile = objectPoolManager->GetObject(); AActor* Projectile = ObjectPoolManager->GetObject();
if (UKismetSystemLibrary::DoesImplementInterface(projectile, UProjectilable::StaticClass())) if (UKismetSystemLibrary::DoesImplementInterface(Projectile, UProjectilable::StaticClass()))
{ {
IProjectilable::Execute_LoadDataFromDataAsset(projectile, ProjectileTemplate); IProjectilable::Execute_LoadDataFromDataAsset(Projectile, ProjectileTemplate);
projectile->SetOwner(this); Projectile->SetOwner(this);
AActor* target = OverlappedEnemies[FMath::RandRange(0, OverlappedEnemies.Num() - 1)]; AActor* Target = OverlappedEnemies[FMath::RandRange(0, OverlappedEnemies.Num() - 1)];
FVector direction = UKismetMathLibrary::GetDirectionUnitVector( FVector Direction = UKismetMathLibrary::GetDirectionUnitVector(
GetActorLocation(), target->GetActorLocation()); GetActorLocation(), Target->GetActorLocation());
direction.Z = 0.0; Direction.Z = 0.0;
direction.Normalize(); Direction.Normalize();
IProjectilable::Execute_SetTargetDirection(projectile, direction); IProjectilable::Execute_SetTargetDirection(Projectile, Direction);
} }
Super::FireProjectile(); Super::FireProjectile();

View File

@ -3,7 +3,6 @@
#include "GarlicWeapon.h" #include "GarlicWeapon.h"
#include "MovieSceneTracksComponentTypes.h"
#include "Components/SphereComponent.h" #include "Components/SphereComponent.h"
#include "vampires/EnemyCharacter.h" #include "vampires/EnemyCharacter.h"
#include "vampires/HealthComponent.h" #include "vampires/HealthComponent.h"
@ -20,7 +19,8 @@ AGarlicWeapon::AGarlicWeapon()
VisualEffectMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Visual Layout Mesh Component")); VisualEffectMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Visual Layout Mesh Component"));
VisualEffectMeshComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform); VisualEffectMeshComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
VisualEffectMeshComponent->SetWorldScale3D(FVector(3.0f, 3.0f, 3.0f)); // This is to match the size of our sphere component // This is to match the size of our sphere component
VisualEffectMeshComponent->SetWorldScale3D(FVector(3.0f, 3.0f, 3.0f));
VisualEffectMeshComponent->SetCollisionProfileName("NoCollision"); VisualEffectMeshComponent->SetCollisionProfileName("NoCollision");
} }
@ -41,15 +41,14 @@ void AGarlicWeapon::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AAc
{ {
if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor)) if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor))
{ {
FOverlappedEnemy overlappedEnemy = FOverlappedEnemy(Enemy); FOverlappedEnemy OverlappedEnemy = FOverlappedEnemy(Enemy);
GetWorldTimerManager().SetTimer(OverlappedEnemy.OverlappedTimerHandle,
GetWorldTimerManager().SetTimer(overlappedEnemy.OverlappedTimerHandle,
FTimerDelegate::CreateUObject(this, &AGarlicWeapon::GarlicFireWeaponAction, FTimerDelegate::CreateUObject(this, &AGarlicWeapon::GarlicFireWeaponAction,
overlappedEnemy), OverlappedEnemy),
WeaponCooldown, WeaponCooldown,
true); true);
GarlicOverlappedEnemies.Add(overlappedEnemy); GarlicOverlappedEnemies.Add(OverlappedEnemy);
} }
} }
@ -79,22 +78,22 @@ void AGarlicWeapon::GarlicFireWeaponAction(FOverlappedEnemy EnemyCharacter)
return; return;
} }
AController* ownerController = nullptr; AController* OwnerController = nullptr;
if (AVampireCharacter* character = Cast<AVampireCharacter>(GetOwner())) if (AVampireCharacter* Character = Cast<AVampireCharacter>(GetOwner()))
{ {
ownerController = character->GetController(); OwnerController = Character->GetController();
} }
EnemyHealthComponent->TakeDamage(EnemyCharacter.OverlappedEnemyCharacter, Damage, nullptr, EnemyHealthComponent->TakeDamage(EnemyCharacter.OverlappedEnemyCharacter, Damage, nullptr,
ownerController, this); OwnerController, this);
if (!EnemyHealthComponent->GetIsDead()) if (!EnemyHealthComponent->GetIsDead())
{ {
FVector Direction = EnemyCharacter.OverlappedEnemyCharacter->GetActorLocation() - this->GetActorLocation(); FVector Direction = EnemyCharacter.OverlappedEnemyCharacter->GetActorLocation() - this->GetActorLocation();
Direction.Normalize(); Direction.Normalize();
Direction.Z = 0.0f; Direction.Z = 0.0f;
float distance = SphereComponent->GetScaledSphereRadius(); float Distance = SphereComponent->GetScaledSphereRadius();
Direction *= distance; Direction *= Distance;
EnemyCharacter.OverlappedEnemyCharacter->SetActorLocation( EnemyCharacter.OverlappedEnemyCharacter->SetActorLocation(
EnemyCharacter.OverlappedEnemyCharacter->GetActorLocation() + Direction); EnemyCharacter.OverlappedEnemyCharacter->GetActorLocation() + Direction);
} }
@ -102,7 +101,10 @@ void AGarlicWeapon::GarlicFireWeaponAction(FOverlappedEnemy EnemyCharacter)
bool AGarlicWeapon::UpgradeWeapon_Implementation() bool AGarlicWeapon::UpgradeWeapon_Implementation()
{ {
if (!Super::UpgradeWeapon_Implementation()) return false; if (!Super::UpgradeWeapon_Implementation())
{
return false;
}
switch (CurrentLevel) switch (CurrentLevel)
{ {
@ -110,7 +112,8 @@ bool AGarlicWeapon::UpgradeWeapon_Implementation()
Range *= 1.4f; Range *= 1.4f;
SphereComponent->SetSphereRadius(Range); SphereComponent->SetSphereRadius(Range);
Damage += 2.0f; Damage += 2.0f;
VisualEffectMeshComponent->SetWorldScale3D(VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.4f); VisualEffectMeshComponent->SetWorldScale3D(
VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.4f);
break; break;
case 2: case 2:
WeaponCooldown -= 0.1f; WeaponCooldown -= 0.1f;
@ -120,7 +123,8 @@ bool AGarlicWeapon::UpgradeWeapon_Implementation()
Range *= 1.2f; Range *= 1.2f;
SphereComponent->SetSphereRadius(Range); SphereComponent->SetSphereRadius(Range);
Damage += 1.0f; Damage += 1.0f;
VisualEffectMeshComponent->SetWorldScale3D(VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f); VisualEffectMeshComponent->SetWorldScale3D(
VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f);
break; break;
case 4: case 4:
WeaponCooldown -= 0.1f; WeaponCooldown -= 0.1f;
@ -130,7 +134,8 @@ bool AGarlicWeapon::UpgradeWeapon_Implementation()
Range *= 1.2f; Range *= 1.2f;
SphereComponent->SetSphereRadius(Range); SphereComponent->SetSphereRadius(Range);
Damage += 1.0f; Damage += 1.0f;
VisualEffectMeshComponent->SetWorldScale3D(VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f); VisualEffectMeshComponent->SetWorldScale3D(
VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f);
break; break;
case 6: case 6:
WeaponCooldown -= 0.1f; WeaponCooldown -= 0.1f;
@ -140,7 +145,8 @@ bool AGarlicWeapon::UpgradeWeapon_Implementation()
Range *= 1.2f; Range *= 1.2f;
SphereComponent->SetSphereRadius(Range); SphereComponent->SetSphereRadius(Range);
Damage += 1.0f; Damage += 1.0f;
VisualEffectMeshComponent->SetWorldScale3D(VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f); VisualEffectMeshComponent->SetWorldScale3D(
VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f);
break; break;
default: default:
return false; return false;

View File

@ -27,7 +27,8 @@ UCLASS()
class VAMPIRES_API AGarlicWeapon : public AWeapon class VAMPIRES_API AGarlicWeapon : public AWeapon
{ {
GENERATED_BODY() GENERATED_BODY()
public:
protected:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"), Category = "Weapon | Garlic") UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"), Category = "Weapon | Garlic")
TObjectPtr<USphereComponent> SphereComponent; TObjectPtr<USphereComponent> SphereComponent;
@ -38,6 +39,7 @@ public:
private: private:
float Range; float Range;
public: public:
AGarlicWeapon(); AGarlicWeapon();

View File

@ -29,7 +29,10 @@ void AGunWeapon::FireWeaponAction_Implementation()
bool AGunWeapon::UpgradeWeapon_Implementation() bool AGunWeapon::UpgradeWeapon_Implementation()
{ {
if (!Super::UpgradeWeapon_Implementation()) return false; if (!Super::UpgradeWeapon_Implementation())
{
return false;
}
switch (CurrentLevel) switch (CurrentLevel)
{ {
@ -67,11 +70,11 @@ void AGunWeapon::FireProjectile()
{ {
if (ProjectileTemplate && OverlappedEnemies.Num() > 0) if (ProjectileTemplate && OverlappedEnemies.Num() > 0)
{ {
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))
{ {
FVector2d ViewportSize; FVector2d ViewportSize;
GEngine->GameViewport->GetViewportSize(ViewportSize); GEngine->GameViewport->GetViewportSize(ViewportSize);
@ -92,20 +95,20 @@ void AGunWeapon::FireProjectile()
PlayerController->DeprojectScreenPositionToWorld(ViewportSize.X, ViewportSize.Y, BottomRight, PlayerController->DeprojectScreenPositionToWorld(ViewportSize.X, ViewportSize.Y, BottomRight,
BottomRightDir); BottomRightDir);
FVector actorLocation = GetActorLocation(); FVector ActorLocation = GetActorLocation();
TopLeft.Z = actorLocation.Z; TopLeft.Z = ActorLocation.Z;
TopRight.Z = actorLocation.Z; TopRight.Z = ActorLocation.Z;
BottomLeft.Z = actorLocation.Z; BottomLeft.Z = ActorLocation.Z;
BottomRight.Z = actorLocation.Z; BottomRight.Z = ActorLocation.Z;
AActor* projectile = objectPoolManager->GetObject(); AActor* projectile = ObjectPoolManager->GetObject();
SpawnProjectile(projectile, UKismetMathLibrary::GetDirectionUnitVector(actorLocation, TopLeft)); SpawnProjectile(projectile, UKismetMathLibrary::GetDirectionUnitVector(ActorLocation, TopLeft));
projectile = objectPoolManager->GetObject(); projectile = ObjectPoolManager->GetObject();
SpawnProjectile(projectile, UKismetMathLibrary::GetDirectionUnitVector(actorLocation, TopRight)); SpawnProjectile(projectile, UKismetMathLibrary::GetDirectionUnitVector(ActorLocation, TopRight));
projectile = objectPoolManager->GetObject(); projectile = ObjectPoolManager->GetObject();
SpawnProjectile(projectile, UKismetMathLibrary::GetDirectionUnitVector(actorLocation, BottomLeft)); SpawnProjectile(projectile, UKismetMathLibrary::GetDirectionUnitVector(ActorLocation, BottomLeft));
projectile = objectPoolManager->GetObject(); projectile = ObjectPoolManager->GetObject();
SpawnProjectile(projectile, UKismetMathLibrary::GetDirectionUnitVector(actorLocation, BottomRight)); SpawnProjectile(projectile, UKismetMathLibrary::GetDirectionUnitVector(ActorLocation, BottomRight));
Super::FireProjectile(); Super::FireProjectile();
} }
@ -113,12 +116,12 @@ void AGunWeapon::FireProjectile()
} }
} }
void AGunWeapon::SpawnProjectile(AActor* projectile, FVector direction) void AGunWeapon::SpawnProjectile(AActor* Projectile, const FVector& Direction)
{ {
if (UKismetSystemLibrary::DoesImplementInterface(projectile, UProjectilable::StaticClass())) if (UKismetSystemLibrary::DoesImplementInterface(Projectile, UProjectilable::StaticClass()))
{ {
IProjectilable::Execute_LoadDataFromDataAsset(projectile, ProjectileTemplate); IProjectilable::Execute_LoadDataFromDataAsset(Projectile, ProjectileTemplate);
projectile->SetOwner(this); Projectile->SetOwner(this);
IProjectilable::Execute_SetTargetDirection(projectile, direction); IProjectilable::Execute_SetTargetDirection(Projectile, Direction);
} }
} }

View File

@ -29,5 +29,5 @@ protected:
virtual void FireProjectile() override; virtual void FireProjectile() override;
private: private:
void SpawnProjectile(AActor* projectile, FVector direction); void SpawnProjectile(AActor* Projectile, const FVector& Direction);
}; };

View File

@ -27,7 +27,10 @@ void AKnifeWeapon::FireWeaponAction_Implementation()
bool AKnifeWeapon::UpgradeWeapon_Implementation() bool AKnifeWeapon::UpgradeWeapon_Implementation()
{ {
if (!Super::UpgradeWeapon_Implementation()) return false; if (!Super::UpgradeWeapon_Implementation())
{
return false;
}
switch (CurrentLevel) switch (CurrentLevel)
{ {
@ -67,24 +70,24 @@ void AKnifeWeapon::FireProjectile()
{ {
if (ProjectileTemplate && OverlappedEnemies.Num() > 0) if (ProjectileTemplate && OverlappedEnemies.Num() > 0)
{ {
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))
{ {
AActor* projectile = objectPoolManager->GetObject(); AActor* Projectile = ObjectPoolManager->GetObject();
if (UKismetSystemLibrary::DoesImplementInterface(projectile, UProjectilable::StaticClass())) if (UKismetSystemLibrary::DoesImplementInterface(Projectile, UProjectilable::StaticClass()))
{ {
IProjectilable::Execute_LoadDataFromDataAsset(projectile, ProjectileTemplate); IProjectilable::Execute_LoadDataFromDataAsset(Projectile, ProjectileTemplate);
projectile->SetOwner(this); Projectile->SetOwner(this);
FVector direction = FVector(IInputable::Execute_Input_GetPreviousMovementDirection(GetOwner()), FVector Direction = FVector(IInputable::Execute_Input_GetPreviousMovementDirection(GetOwner()),
0.0); 0.0);
direction.Normalize(); Direction.Normalize();
IProjectilable::Execute_SetTargetDirection(projectile, direction); IProjectilable::Execute_SetTargetDirection(Projectile, Direction);
} }
Super::FireProjectile(); Super::FireProjectile();

View File

@ -21,40 +21,40 @@ void ALightningRingWeapon::FireWeaponAction_Implementation()
{ {
Super::FireWeaponAction_Implementation(); Super::FireWeaponAction_Implementation();
TArray<AActor*> targetableEnemies = OverlappedEnemies; TArray<AActor*> TargetableEnemies = OverlappedEnemies;
for (int i = 0; i < LightningBolts && targetableEnemies.Num() > 0; i++) for (int i = 0; i < LightningBolts && TargetableEnemies.Num() > 0; i++)
{ {
AActor* target = targetableEnemies[FMath::RandRange(0, targetableEnemies.Num() - 1)]; AActor* Target = TargetableEnemies[FMath::RandRange(0, TargetableEnemies.Num() - 1)];
TArray<TEnumAsByte<EObjectTypeQuery>> traceObjectTypes; TArray<TEnumAsByte<EObjectTypeQuery>> traceObjectTypes;
traceObjectTypes.Add(UEngineTypes::ConvertToObjectType(ECC_Pawn)); traceObjectTypes.Add(UEngineTypes::ConvertToObjectType(ECC_Pawn));
TArray<AActor*> actorsToIgnore = TArray<AActor*>({GetOwner()}); TArray<AActor*> ActorsToIgnore = TArray<AActor*>({GetOwner()});
TArray<AActor*> hitResults; TArray<AActor*> HitResults;
UKismetSystemLibrary::SphereOverlapActors(GetWorld(), UKismetSystemLibrary::SphereOverlapActors(GetWorld(),
target->GetActorLocation(), Target->GetActorLocation(),
LightingBoltRadius, LightingBoltRadius,
traceObjectTypes, traceObjectTypes,
AEnemyCharacter::StaticClass(), AEnemyCharacter::StaticClass(),
actorsToIgnore, ActorsToIgnore,
hitResults); HitResults);
if (LightningEffectSystem) if (LightningEffectSystem)
{ {
float scale = FMath::FloorToFloat((CurrentLevel + 2.0f) / 2.0f); float Scale = FMath::FloorToFloat((CurrentLevel + 2.0f) / 2.0f);
UNiagaraFunctionLibrary::SpawnSystemAtLocation(this, LightningEffectSystem, target->GetActorLocation(), UNiagaraFunctionLibrary::SpawnSystemAtLocation(this, LightningEffectSystem, Target->GetActorLocation(),
GetActorRotation(), FVector(scale)); GetActorRotation(), FVector(Scale));
} }
for (AActor* EnemyHitResult : hitResults) for (AActor* EnemyHitResult : HitResults)
{ {
UGameplayStatics::ApplyDamage(EnemyHitResult, Damage, nullptr, this, nullptr); UGameplayStatics::ApplyDamage(EnemyHitResult, Damage, nullptr, this, nullptr);
} }
targetableEnemies.Remove(target); TargetableEnemies.Remove(Target);
} }
} }

View File

@ -17,7 +17,7 @@ class VAMPIRES_API ALightningRingWeapon : public AWeapon
{ {
GENERATED_BODY() GENERATED_BODY()
public: protected:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon | Lightning Ring") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon | Lightning Ring")
int LightningBolts = 1; int LightningBolts = 1;
@ -27,10 +27,8 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon | Lightning Ring") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon | Lightning Ring")
TObjectPtr<UNiagaraSystem> LightningEffectSystem; TObjectPtr<UNiagaraSystem> LightningEffectSystem;
public:
ALightningRingWeapon(); ALightningRingWeapon();
protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
public: public:

View File

@ -27,7 +27,10 @@ void AMagicWandWeapon::FireWeaponAction_Implementation()
bool AMagicWandWeapon::UpgradeWeapon_Implementation() bool AMagicWandWeapon::UpgradeWeapon_Implementation()
{ {
if (!Super::UpgradeWeapon_Implementation()) return false; if (!Super::UpgradeWeapon_Implementation())
{
return false;
}
switch (CurrentLevel) switch (CurrentLevel)
{ {
@ -65,30 +68,29 @@ void AMagicWandWeapon::FireProjectile()
{ {
if (ProjectileTemplate && OverlappedEnemies.Num() > 0) if (ProjectileTemplate && OverlappedEnemies.Num() > 0)
{ {
float distance = 0.0f; float Distance = 0.0f;
AActor* nearestActor = UGameplayStatics::FindNearestActor(GetActorLocation(), OverlappedEnemies, distance);
if (nearestActor) if (AActor* nearestActor = UGameplayStatics::FindNearestActor(GetActorLocation(), OverlappedEnemies, Distance))
{ {
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))
{ {
AActor* projectile = objectPoolManager->GetObject(); AActor* Projectile = ObjectPoolManager->GetObject();
if (UKismetSystemLibrary::DoesImplementInterface(projectile, UProjectilable::StaticClass())) if (UKismetSystemLibrary::DoesImplementInterface(Projectile, UProjectilable::StaticClass()))
{ {
IProjectilable::Execute_LoadDataFromDataAsset(projectile, ProjectileTemplate); IProjectilable::Execute_LoadDataFromDataAsset(Projectile, ProjectileTemplate);
projectile->SetOwner(this); Projectile->SetOwner(this);
FVector direction = UKismetMathLibrary::GetDirectionUnitVector( FVector Direction = UKismetMathLibrary::GetDirectionUnitVector(
GetActorLocation(), nearestActor->GetActorLocation()); GetActorLocation(), nearestActor->GetActorLocation());
direction.Z = 0.0; Direction.Z = 0.0;
direction.Normalize(); Direction.Normalize();
IProjectilable::Execute_SetTargetDirection(projectile, direction); IProjectilable::Execute_SetTargetDirection(Projectile, Direction);
} }
Super::FireProjectile(); Super::FireProjectile();

View File

@ -36,7 +36,10 @@ void APentagramWeapon::FireWeaponAction_Implementation()
bool APentagramWeapon::UpgradeWeapon_Implementation() bool APentagramWeapon::UpgradeWeapon_Implementation()
{ {
if (!Super::UpgradeWeapon_Implementation()) return false; if (!Super::UpgradeWeapon_Implementation())
{
return false;
}
switch (CurrentLevel) switch (CurrentLevel)
{ {
@ -71,7 +74,8 @@ bool APentagramWeapon::UpgradeWeapon_Implementation()
} }
void APentagramWeapon::OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, void APentagramWeapon::OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult)
{ {
if (APickup* Pickup = Cast<APickup>(OtherActor)) if (APickup* Pickup = Cast<APickup>(OtherActor))
{ {
@ -79,7 +83,8 @@ void APentagramWeapon::OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedCompo
} }
else else
{ {
Super::OnWeaponBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); Super::OnWeaponBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep,
SweepResult);
} }
} }

View File

@ -17,7 +17,6 @@ class VAMPIRES_API APentagramWeapon : public AWeapon
{ {
GENERATED_BODY() GENERATED_BODY()
private:
TArray<TObjectPtr<APickup>> OverlappedPickups = TArray<TObjectPtr<APickup>>(); TArray<TObjectPtr<APickup>> OverlappedPickups = TArray<TObjectPtr<APickup>>();
public: public:
@ -25,10 +24,11 @@ public:
virtual void FireWeaponAction_Implementation() override; virtual void FireWeaponAction_Implementation() override;
bool UpgradeWeapon_Implementation() override; virtual bool UpgradeWeapon_Implementation() override;
virtual void OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, virtual void OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) override; UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult) override;
virtual void OnWeaponEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, virtual void OnWeaponEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) override; UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) override;

View File

@ -47,12 +47,12 @@ void ASwarmAgent::OnSwarmAgentBeginOverlap(UPrimitiveComponent* OverlappedCompon
if (!EnemyHealthComponent->GetIsDead()) if (!EnemyHealthComponent->GetIsDead())
{ {
if (AWeapon* ownerWeapon = Cast<AWeapon>(GetOwner())) if (AWeapon* OwnerWeapon = Cast<AWeapon>(GetOwner()))
{ {
if (AVampireCharacter* character = Cast<AVampireCharacter>(ownerWeapon->GetOwner())) if (AVampireCharacter* Character = Cast<AVampireCharacter>(OwnerWeapon->GetOwner()))
{ {
AController* ownerController = character->GetController(); AController* OwnerController = Character->GetController();
EnemyHealthComponent->TakeDamage(Enemy, ownerWeapon->GetDamage(), nullptr, ownerController, this); EnemyHealthComponent->TakeDamage(Enemy, OwnerWeapon->GetDamage(), nullptr, OwnerController, this);
} }
} }
} }

View File

@ -14,7 +14,7 @@ class VAMPIRES_API ASwarmAgent : public AActor
{ {
GENERATED_BODY() GENERATED_BODY()
public: protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TObjectPtr<USphereComponent> SphereComponent = nullptr; TObjectPtr<USphereComponent> SphereComponent = nullptr;
@ -27,7 +27,6 @@ public:
// Sets default values for this actor's properties // Sets default values for this actor's properties
ASwarmAgent(); ASwarmAgent();
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;

View File

@ -40,7 +40,7 @@ void ASwarmWeapon::BeginPlay()
TimelineComponent->PlayFromStart(); TimelineComponent->PlayFromStart();
} }
void ASwarmWeapon::TimelineCallback(float val) void ASwarmWeapon::TimelineCallback(float Val)
{ {
float num = SwarmActors.Num(); float num = SwarmActors.Num();
@ -50,7 +50,7 @@ void ASwarmWeapon::TimelineCallback(float val)
float offset = (actorIndex / num) * 360.0f; float offset = (actorIndex / num) * 360.0f;
FVector CenterLocation = GetActorLocation(); FVector CenterLocation = GetActorLocation();
FVector Direction = FVector(0.0, 1, 0.0); FVector Direction = FVector(0.0, 1, 0.0);
FVector RotatedDirection = Direction.RotateAngleAxis(val * 360.0f + offset, FVector(0.0f, 0.0f, 1.0f)); FVector RotatedDirection = Direction.RotateAngleAxis(Val * 360.0f + offset, FVector(0.0f, 0.0f, 1.0f));
FVector NewLocation = CenterLocation + (RotatedDirection * Distance); FVector NewLocation = CenterLocation + (RotatedDirection * Distance);
NewLocation.Z = 190.0f; NewLocation.Z = 190.0f;
SwarmActors[i]->SetActorLocation(NewLocation); SwarmActors[i]->SetActorLocation(NewLocation);

View File

@ -14,20 +14,20 @@ class VAMPIRES_API ASwarmWeapon : public AWeapon
{ {
GENERATED_BODY() GENERATED_BODY()
public: protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Weapon | Swarm") UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Weapon | Swarm")
TObjectPtr<UTimelineComponent> TimelineComponent = nullptr; TObjectPtr<UTimelineComponent> TimelineComponent = nullptr;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon | Swarm") UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon | Swarm")
TObjectPtr<UCurveFloat> SwarmCurve; TObjectPtr<UCurveFloat> SwarmCurve;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon | Swarm") UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon | Swarm")
float TimelinePlayRate = 1; float TimelinePlayRate = 1;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon | Swarm") UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon | Swarm")
TSubclassOf<ASwarmAgent> SwarmActor; TSubclassOf<ASwarmAgent> SwarmActor;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon | Swarm") UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon | Swarm")
float Distance = 250.0f; float Distance = 250.0f;
private: private:
@ -45,7 +45,7 @@ protected:
public: public:
UFUNCTION() UFUNCTION()
void TimelineCallback(float val); void TimelineCallback(float Val);
virtual bool UpgradeWeapon_Implementation() override; virtual bool UpgradeWeapon_Implementation() override;

View File

@ -9,41 +9,41 @@ void UHUDWidget::Init()
{ {
} }
void UHUDWidget::UpdateEXPBar(float currentLevelPercent) void UHUDWidget::UpdateEXPBar(float CurrentLevelPercent)
{ {
EXPbar->SetPercent(currentLevelPercent); EXPbar->SetPercent(CurrentLevelPercent);
} }
void UHUDWidget::UpdateLevelBlock(int level) void UHUDWidget::UpdateLevelBlock(int Level)
{ {
LevelBlock->SetText(FText::FromString("LV" + FString::FromInt(level))); LevelBlock->SetText(FText::FromString("LV" + FString::FromInt(Level)));
} }
void UHUDWidget::UpdateTimerBlock(float deltaTime) void UHUDWidget::UpdateTimerBlock(float DeltaTime)
{ {
int timeSinceStart = FMath::FloorToInt(deltaTime); int TimeSinceStart = FMath::FloorToInt(DeltaTime);
FString mins = FString::FromInt(timeSinceStart / 60); FString Mins = FString::FromInt(TimeSinceStart / 60);
if (timeSinceStart / 60 < 10) if (TimeSinceStart / 60 < 10)
{ {
mins = "0" + mins; Mins = "0" + Mins;
} }
FString secs = FString::FromInt(timeSinceStart % 60); FString Secs = FString::FromInt(TimeSinceStart % 60);
if (timeSinceStart % 60 < 10) if (TimeSinceStart % 60 < 10)
{ {
secs = "0" + secs; Secs = "0" + Secs;
} }
TimerBLock->SetText(FText::FromString(mins + ":" + secs)); TimerBLock->SetText(FText::FromString(Mins + ":" + Secs));
} }
void UHUDWidget::UpdateKillBlock(int killCount) void UHUDWidget::UpdateKillBlock(int KillCount)
{ {
KillBLock->SetText(FText::FromString("Kills: " + FString::FromInt(killCount))); KillBLock->SetText(FText::FromString("Kills: " + FString::FromInt(KillCount)));
} }
void UHUDWidget::UpdateGoldBlock(int goldCount) void UHUDWidget::UpdateGoldBlock(int GoldCount)
{ {
GoldBLock->SetText(FText::FromString("Gold: " + FString::FromInt(goldCount))); GoldBLock->SetText(FText::FromString("Gold: " + FString::FromInt(GoldCount)));
} }

View File

@ -16,8 +16,7 @@ class VAMPIRES_API UHUDWidget : public UUserWidget
{ {
GENERATED_BODY() GENERATED_BODY()
public: protected:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UProgressBar* EXPbar; UProgressBar* EXPbar;
@ -35,19 +34,19 @@ public:
void Init(); void Init();
public:
UFUNCTION() UFUNCTION()
void UpdateEXPBar(float currentLevelPercent); void UpdateEXPBar(float CurrentLevelPercent);
UFUNCTION() UFUNCTION()
void UpdateLevelBlock(int level); void UpdateLevelBlock(int Level);
UFUNCTION() UFUNCTION()
void UpdateTimerBlock(float deltaTime); void UpdateTimerBlock(float DeltaTime);
UFUNCTION() UFUNCTION()
void UpdateKillBlock(int killCount); void UpdateKillBlock(int KillCount);
UFUNCTION() UFUNCTION()
void UpdateGoldBlock(int goldCount); void UpdateGoldBlock(int GoldCount);
}; };

View File

@ -12,23 +12,23 @@ void UHealthbarWidget::NativeConstruct()
{ {
Super::NativeConstruct(); Super::NativeConstruct();
if (ACharacter* character = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)) if (ACharacter* Character = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0))
{ {
if (UHealthComponent* healthComponent = character->FindComponentByClass<UHealthComponent>()) if (UHealthComponent* HealthComponent = Character->FindComponentByClass<UHealthComponent>())
{ {
healthComponent->OnDamaged.AddDynamic(this, &UHealthbarWidget::UpdateHealthBar); HealthComponent->OnDamaged.AddDynamic(this, &UHealthbarWidget::UpdateHealthBar);
UpdateHealthBar({}); UpdateHealthBar({});
} }
} }
} }
void UHealthbarWidget::UpdateHealthBar(FDamageInfo damageInfo) void UHealthbarWidget::UpdateHealthBar(FDamageInfo DamageInfo)
{ {
if (ACharacter* character = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)) if (ACharacter* Character = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0))
{ {
if (UHealthComponent* healthComponent = character->FindComponentByClass<UHealthComponent>()) if (UHealthComponent* HealthComponent = Character->FindComponentByClass<UHealthComponent>())
{ {
float percent = healthComponent->GetCurrentHealth() / healthComponent->GetMaxHealth(); float percent = HealthComponent->GetCurrentHealth() / HealthComponent->GetMaxHealth();
HealthBar->SetPercent(percent); HealthBar->SetPercent(percent);
} }
} }

View File

@ -6,6 +6,7 @@
#include "Blueprint/UserWidget.h" #include "Blueprint/UserWidget.h"
#include "HealthbarWidget.generated.h" #include "HealthbarWidget.generated.h"
struct FDamageInfo;
class UProgressBar; class UProgressBar;
/** /**
* *
@ -15,13 +16,13 @@ class VAMPIRES_API UHealthbarWidget : public UUserWidget
{ {
GENERATED_BODY() GENERATED_BODY()
public: protected:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UProgressBar* HealthBar; TObjectPtr<UProgressBar> HealthBar;
virtual void NativeConstruct() override; virtual void NativeConstruct() override;
private: private:
UFUNCTION() UFUNCTION()
void UpdateHealthBar(FDamageInfo damageInfo); void UpdateHealthBar(FDamageInfo DamageInfo);
}; };

View File

@ -40,50 +40,50 @@ void ULevelUpWidget::NativeConstruct()
TArray<AWeapon*> Inventory = InventoryComponent->GetInventory(); TArray<AWeapon*> Inventory = InventoryComponent->GetInventory();
// Get list of weapons that the player owns that can be upgraded // Get list of weapons that the player owns that can be upgraded
TArray<UUpgradeButtonDataObject*> upgradeItems; TArray<UUpgradeButtonDataObject*> UpgradeItems;
for (AWeapon* weapon : Inventory) for (AWeapon* Weapon : Inventory)
{ {
if (weapon->GetWeaponLevel() < weapon->GetUpgradeDescriptions().Num()) if (Weapon->GetWeaponLevel() < Weapon->GetUpgradeDescriptions().Num())
{ {
UUpgradeButtonDataObject* Temp = NewObject<UUpgradeButtonDataObject>(this); UUpgradeButtonDataObject* Temp = NewObject<UUpgradeButtonDataObject>(this);
Temp->SetData(weapon, this); Temp->SetData(Weapon, this);
upgradeItems.Add(Temp); UpgradeItems.Add(Temp);
} }
} }
// 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);
Temp->SetData(weapon, this); Temp->SetData(Weapon, this);
upgradeItems.Add(Temp); UpgradeItems.Add(Temp);
} }
// If no valid options exist, populate list with default options // If no valid options exist, populate list with default options
if (upgradeItems.Num() == 0) if (UpgradeItems.Num() == 0)
{ {
UUpgradeButtonDataObject* tempHealth = NewObject<UUpgradeButtonDataObject>(this); UUpgradeButtonDataObject* TempHealth = NewObject<UUpgradeButtonDataObject>(this);
tempHealth->SetData(FText::FromString("Health"), TempHealth->SetData(FText::FromString("Health"),
FText::FromString("Recover 10% of your health"), FText::FromString("Recover 10% of your health"),
nullptr, nullptr,
this); this);
upgradeItems.Add(tempHealth); UpgradeItems.Add(TempHealth);
UUpgradeButtonDataObject* tempGold = NewObject<UUpgradeButtonDataObject>(this); UUpgradeButtonDataObject* TempGold = NewObject<UUpgradeButtonDataObject>(this);
tempGold->SetData(FText::FromString("Gold"), TempGold->SetData(FText::FromString("Gold"),
FText::FromString("Gain 10 gold"), FText::FromString("Gain 10 gold"),
nullptr, nullptr,
this); this);
upgradeItems.Add(tempGold); UpgradeItems.Add(TempGold);
} }
// Select up to three random options from the list of options // Select up to three random options from the list of options
for (int i = 0; i < 3 && upgradeItems.Num() > 0; i++) for (int i = 0; i < 3 && UpgradeItems.Num() > 0; i++)
{ {
int rand = FMath::RandRange(0, upgradeItems.Num() - 1); int Rand = FMath::RandRange(0, UpgradeItems.Num() - 1);
UpgradesListView->AddItem(upgradeItems[rand]); UpgradesListView->AddItem(UpgradeItems[Rand]);
upgradeItems.RemoveAt(rand); UpgradeItems.RemoveAt(Rand);
} }
} }
SetIsFocusable(true); SetIsFocusable(true);
@ -93,11 +93,11 @@ void ULevelUpWidget::ResumeButtonClicked()
{ {
RemoveFromParent(); RemoveFromParent();
if (APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0)) if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
{ {
UWidgetBlueprintLibrary::SetInputMode_GameOnly(playerController); UWidgetBlueprintLibrary::SetInputMode_GameOnly(PlayerController);
playerController->bShowMouseCursor = false; PlayerController->bShowMouseCursor = false;
playerController->SetPause(false); PlayerController->SetPause(false);
} }
SetIsFocusable(false); SetIsFocusable(false);

View File

@ -17,8 +17,7 @@ class VAMPIRES_API ULevelUpWidget : public UUserWidget
{ {
GENERATED_BODY() GENERATED_BODY()
public: protected:
UPROPERTY(BlueprintReadWrite, meta=(BindWidget)) UPROPERTY(BlueprintReadWrite, meta=(BindWidget))
UButton* ResumeButton; UButton* ResumeButton;
@ -28,7 +27,6 @@ public:
virtual void NativeConstruct() override; virtual void NativeConstruct() override;
private: private:
UFUNCTION() UFUNCTION()
void ResumeButtonClicked(); void ResumeButtonClicked();
}; };

View File

@ -51,27 +51,14 @@ void UMainMenuWidget::NewGameButtonOnClicked()
{ {
RemoveFromParent(); RemoveFromParent();
UUserWidget* selectWeaponWidget = CreateWidget<UUserWidget, APlayerController*>( UUserWidget* SelectWeaponWidget = CreateWidget<UUserWidget, APlayerController*>(
UGameplayStatics::GetPlayerController(GetWorld(), 0), NewGameMenuWidget); UGameplayStatics::GetPlayerController(GetWorld(), 0), NewGameMenuWidget);
if (selectWeaponWidget) if (SelectWeaponWidget)
{ {
selectWeaponWidget->AddToViewport(); SelectWeaponWidget->AddToViewport();
} }
} }
// if (!NewGameLevel.IsNull())
// {
// UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), NewGameLevel);
// }
//
// if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
// {
// PlayerController->bShowMouseCursor = false;
// UWidgetBlueprintLibrary::SetInputMode_GameOnly(PlayerController);
// }
//
// SetIsFocusable(false);
} }
void UMainMenuWidget::QuitButtonOnClicked() void UMainMenuWidget::QuitButtonOnClicked()

View File

@ -17,7 +17,7 @@ class VAMPIRES_API UMainMenuWidget : public UVampireInteractiveWidget
// TODO: Add options menu // TODO: Add options menu
public: protected:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
TObjectPtr<UButton> NewGameButton; TObjectPtr<UButton> NewGameButton;
@ -38,7 +38,7 @@ public:
private: private:
UPROPERTY() UPROPERTY()
TObjectPtr<UUserWidget> currentNewGameWidget; TObjectPtr<UUserWidget> CurrentNewGameWidget;
public: public:
virtual void NativeConstruct() override; virtual void NativeConstruct() override;

View File

@ -27,11 +27,11 @@ void UPauseWidget::ResumeButtonClicked()
{ {
RemoveFromParent(); RemoveFromParent();
if (APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0)) if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
{ {
UWidgetBlueprintLibrary::SetInputMode_GameOnly(playerController); UWidgetBlueprintLibrary::SetInputMode_GameOnly(PlayerController);
playerController->bShowMouseCursor = false; PlayerController->bShowMouseCursor = false;
playerController->SetPause(false); PlayerController->SetPause(false);
} }
SetIsFocusable(false); SetIsFocusable(false);

View File

@ -16,7 +16,6 @@ class VAMPIRES_API UPauseWidget : public UUserWidget
GENERATED_BODY() GENERATED_BODY()
public: public:
UPROPERTY(BlueprintReadWrite, meta=(BindWidget)) UPROPERTY(BlueprintReadWrite, meta=(BindWidget))
UButton* ResumeButton; UButton* ResumeButton;
@ -25,7 +24,6 @@ public:
virtual void NativeConstruct() override; virtual void NativeConstruct() override;
private: private:
UFUNCTION() UFUNCTION()
void ResumeButtonClicked(); void ResumeButtonClicked();
}; };

View File

@ -29,10 +29,10 @@ void USelectWeaponWidget::NativeConstruct()
if (UpgradesListView) if (UpgradesListView)
{ {
// Get a list of weapons that the player owns that can be upgraded // Get a list of weapons that the player owns that can be upgraded
for (TSubclassOf<AWeapon> weapon : starterWeapons) for (TSubclassOf<AWeapon> Weapon : StarterWeapons)
{ {
UStarterWeaponButtonDataObject* Temp = NewObject<UStarterWeaponButtonDataObject>(this); UStarterWeaponButtonDataObject* Temp = NewObject<UStarterWeaponButtonDataObject>(this);
Temp->SetData(weapon, this); Temp->SetData(Weapon, this);
UpgradesListView->AddItem(Temp); UpgradesListView->AddItem(Temp);
} }
} }
@ -44,12 +44,12 @@ void USelectWeaponWidget::BackButtonClicked()
{ {
RemoveFromParent(); RemoveFromParent();
UUserWidget* selectWeaponWidget = CreateWidget<UUserWidget, APlayerController*>( UUserWidget* SelectWeaponWidget = CreateWidget<UUserWidget, APlayerController*>(
UGameplayStatics::GetPlayerController(GetWorld(), 0), PreviousWidget); UGameplayStatics::GetPlayerController(GetWorld(), 0), PreviousWidget);
if (selectWeaponWidget) if (SelectWeaponWidget)
{ {
selectWeaponWidget->AddToViewport(); SelectWeaponWidget->AddToViewport();
} }
} }
} }

View File

@ -17,7 +17,7 @@ UCLASS()
class VAMPIRES_API USelectWeaponWidget : public UVampireInteractiveWidget class VAMPIRES_API USelectWeaponWidget : public UVampireInteractiveWidget
{ {
GENERATED_BODY() GENERATED_BODY()
public: protected:
UPROPERTY(BlueprintReadWrite, meta=(BindWidget)) UPROPERTY(BlueprintReadWrite, meta=(BindWidget))
TObjectPtr<UButton> BackButton; TObjectPtr<UButton> BackButton;
@ -29,7 +29,7 @@ public:
TObjectPtr<UListView> UpgradesListView; TObjectPtr<UListView> UpgradesListView;
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
TArray<TSubclassOf<AWeapon>> starterWeapons; TArray<TSubclassOf<AWeapon>> StarterWeapons;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TSubclassOf<class UUserWidget> PreviousWidget; TSubclassOf<class UUserWidget> PreviousWidget;

View File

@ -5,29 +5,29 @@
#include "vampires/Weapon.h" #include "vampires/Weapon.h"
void UStarterWeaponButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* parent) void UStarterWeaponButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* ParentWidget)
{ {
WeaponName = Weapon->GetWeaponName(); WeaponName = Weapon->GetWeaponName();
Description = Weapon->GetDescription(); WeaponDescription = Weapon->GetDescription();
WeaponIcon = Weapon->GetIcon(); WeaponIcon = Weapon->GetIcon();
WeaponInstance = Weapon; WeaponInstance = Weapon;
Parent = parent; Parent = ParentWidget;
} }
void UStarterWeaponButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent) void UStarterWeaponButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* ParentWidget)
{ {
if (AWeapon* tempWeapon = NewObject<AWeapon>(this, Weapon)) if (AWeapon* tempWeapon = NewObject<AWeapon>(this, Weapon))
{ {
SetData(tempWeapon, parent); SetData(tempWeapon, ParentWidget);
WeaponTemplate = Weapon; WeaponTemplate = Weapon;
} }
} }
void UStarterWeaponButtonDataObject::SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon, void UStarterWeaponButtonDataObject::SetData(FText NewWeaponName, FText NewWeaponDescription, TObjectPtr<UTexture2D> NewWeaponIcon,
UUserWidget* parent) UUserWidget* ParentWidget)
{ {
WeaponName = weaponName; WeaponName = NewWeaponName;
Description = description; WeaponDescription = NewWeaponDescription;
WeaponIcon = weaponIcon; WeaponIcon = NewWeaponIcon;
Parent = parent; Parent = ParentWidget;
} }

View File

@ -19,7 +19,7 @@ public:
FText WeaponName; FText WeaponName;
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText Description; FText WeaponDescription;
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<UTexture2D> WeaponIcon; TObjectPtr<UTexture2D> WeaponIcon;
@ -33,7 +33,7 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<UUserWidget> Parent; TObjectPtr<UUserWidget> Parent;
void SetData(AWeapon* Weapon, UUserWidget* parent); void SetData(AWeapon* Weapon, UUserWidget* ParentWidget);
void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent); void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* ParentWidget);
void SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon, UUserWidget* parent); void SetData(FText NewWeaponName, FText NewWeaponDescription, TObjectPtr<UTexture2D> NewWeaponIcon, UUserWidget* ParentWidget);
}; };

View File

@ -18,12 +18,10 @@ void UStarterWeaponButtonWidget::NativeConstruct()
void UStarterWeaponButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject) void UStarterWeaponButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
{ {
UStarterWeaponButtonDataObject* Item = Cast<UStarterWeaponButtonDataObject>(ListItemObject); if (UStarterWeaponButtonDataObject* Item = Cast<UStarterWeaponButtonDataObject>(ListItemObject))
if (Item)
{ {
WeaponNameTextBlock->SetText(Item->WeaponName); WeaponNameTextBlock->SetText(Item->WeaponName);
DescriptionTextBlock->SetText(Item->Description); DescriptionTextBlock->SetText(Item->WeaponDescription);
WeaponIcon->SetBrushFromTexture(Item->WeaponIcon); WeaponIcon->SetBrushFromTexture(Item->WeaponIcon);
Parent = Item->Parent; Parent = Item->Parent;
WeaponTemplate = Item->WeaponTemplate; WeaponTemplate = Item->WeaponTemplate;
@ -43,13 +41,13 @@ void UStarterWeaponButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObje
void UStarterWeaponButtonWidget::OnClicked() void UStarterWeaponButtonWidget::OnClicked()
{ {
if (UVampireGameInstance* gameInstance = Cast<UVampireGameInstance>(GetGameInstance())) if (UVampireGameInstance* GameInstance = Cast<UVampireGameInstance>(GetGameInstance()))
{ {
gameInstance->StarterWeapon = WeaponTemplate; GameInstance->StarterWeapon = WeaponTemplate;
if (!gameInstance->GameWorld.IsNull()) if (!GameInstance->GameWorld.IsNull())
{ {
UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), gameInstance->GameWorld); UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), GameInstance->GameWorld);
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0)) if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
{ {

View File

@ -20,7 +20,7 @@ class VAMPIRES_API UStarterWeaponButtonWidget : public UVampireInteractiveWidget
{ {
GENERATED_BODY() GENERATED_BODY()
public: protected:
UPROPERTY(EditDefaultsOnly, meta=(BindWidget)) UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
TObjectPtr<UButton> Body; TObjectPtr<UButton> Body;
@ -39,7 +39,6 @@ public:
UPROPERTY() UPROPERTY()
TObjectPtr<UUserWidget> Parent; TObjectPtr<UUserWidget> Parent;
protected:
virtual void NativeConstruct() override; virtual void NativeConstruct() override;
virtual void NativeOnListItemObjectSet(UObject* ListItemObject) override; virtual void NativeOnListItemObjectSet(UObject* ListItemObject) override;

View File

@ -5,32 +5,32 @@
#include "vampires/Weapon.h" #include "vampires/Weapon.h"
void UUpgradeButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* parent) void UUpgradeButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* ParentWidget)
{ {
WeaponName = Weapon->GetWeaponName(); WeaponName = Weapon->GetWeaponName();
WeaponIcon = Weapon->GetIcon(); WeaponIcon = Weapon->GetIcon();
WeaponInstance = Weapon; WeaponInstance = Weapon;
Parent = parent; Parent = ParentWidget;
if (Weapon->GetUpgradeDescriptions().Num() > Weapon->GetWeaponLevel()) if (Weapon->GetUpgradeDescriptions().Num() > Weapon->GetWeaponLevel())
{ {
Description = Weapon->GetUpgradeDescriptions()[Weapon->GetWeaponLevel()]; WeaponDescription = Weapon->GetUpgradeDescriptions()[Weapon->GetWeaponLevel()];
} }
} }
void UUpgradeButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent) void UUpgradeButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* ParentWidget)
{ {
if (AWeapon* tempWeapon = NewObject<AWeapon>(this, Weapon)) if (AWeapon* tempWeapon = NewObject<AWeapon>(this, Weapon))
{ {
SetData(tempWeapon, parent); SetData(tempWeapon, ParentWidget);
} }
} }
void UUpgradeButtonDataObject::SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon, void UUpgradeButtonDataObject::SetData(FText NewWeaponName, FText NewDescription, TObjectPtr<UTexture2D> NewWeaponIcon,
UUserWidget* parent) UUserWidget* ParentWidget)
{ {
WeaponName = weaponName; WeaponName = NewWeaponName;
Description = description; WeaponDescription = NewDescription;
WeaponIcon = weaponIcon; WeaponIcon = NewWeaponIcon;
Parent = parent; Parent = ParentWidget;
} }

View File

@ -20,7 +20,7 @@ public:
FText WeaponName; FText WeaponName;
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText Description; FText WeaponDescription;
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<UTexture2D> WeaponIcon; TObjectPtr<UTexture2D> WeaponIcon;
@ -34,7 +34,7 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<UUserWidget> Parent; TObjectPtr<UUserWidget> Parent;
void SetData(AWeapon* Weapon, UUserWidget* parent); void SetData(AWeapon* Weapon, UUserWidget* ParentWidget);
void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent); void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* ParentWidget);
void SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon, UUserWidget* parent); void SetData(FText NewWeaponName, FText NewDescription, TObjectPtr<UTexture2D> NewWeaponIcon, UUserWidget* ParentWidget);
}; };

View File

@ -22,12 +22,10 @@ void UUpgradeButtonWidget::NativeConstruct()
void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject) void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
{ {
UUpgradeButtonDataObject* Item = Cast<UUpgradeButtonDataObject>(ListItemObject); if (UUpgradeButtonDataObject* Item = Cast<UUpgradeButtonDataObject>(ListItemObject))
if (Item)
{ {
WeaponNameTextBlock->SetText(Item->WeaponName); WeaponNameTextBlock->SetText(Item->WeaponName);
DescriptionTextBlock->SetText(Item->Description); DescriptionTextBlock->SetText(Item->WeaponDescription);
WeaponIcon->SetBrushFromTexture(Item->WeaponIcon); WeaponIcon->SetBrushFromTexture(Item->WeaponIcon);
Parent = Item->Parent; Parent = Item->Parent;
@ -83,7 +81,7 @@ void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
void UUpgradeButtonWidget::OnClicked() void UUpgradeButtonWidget::OnClicked()
{ {
APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0); APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
switch (UpgradeType) switch (UpgradeType)
{ {
@ -92,31 +90,29 @@ void UUpgradeButtonWidget::OnClicked()
break; break;
case NewWeapon: case NewWeapon:
if (UWeaponInventoryComponent* Inventory = playerController->GetPawn()->GetComponentByClass< if (UWeaponInventoryComponent* Inventory = PlayerController->GetPawn()->GetComponentByClass<UWeaponInventoryComponent>())
UWeaponInventoryComponent>())
{ {
Inventory->AddWeaponToInventory(WeaponTemplate); Inventory->AddWeaponToInventory(WeaponTemplate);
Inventory->obtainableWeapons.Remove(WeaponTemplate); Inventory->ObtainableWeapons.Remove(WeaponTemplate);
} }
break; break;
case Health: case Health:
if (playerController) if (PlayerController)
{ {
if (UHealthComponent* healthComponent = playerController->GetPawn()->GetComponentByClass< if (UHealthComponent* HealthComponent = PlayerController->GetPawn()->GetComponentByClass<UHealthComponent>())
UHealthComponent>())
{ {
healthComponent->RecoverHealth(healthComponent->GetMaxHealth() / 10.0f); HealthComponent->RecoverHealth(HealthComponent->GetMaxHealth() / 10.0f);
} }
} }
break; break;
case Gold: case Gold:
if (playerController) if (PlayerController)
{ {
if (UGoldComponent* goldComponent = playerController->GetPawn()->GetComponentByClass<UGoldComponent>()) if (UGoldComponent* GoldComponent = PlayerController->GetPawn()->GetComponentByClass<UGoldComponent>())
{ {
goldComponent->IncrementGold(10); GoldComponent->IncrementGold(10);
} }
} }
break; break;
@ -129,11 +125,11 @@ void UUpgradeButtonWidget::OnClicked()
{ {
Parent->RemoveFromParent(); Parent->RemoveFromParent();
if (playerController) if (PlayerController)
{ {
UWidgetBlueprintLibrary::SetInputMode_GameOnly(playerController); UWidgetBlueprintLibrary::SetInputMode_GameOnly(PlayerController);
playerController->bShowMouseCursor = false; PlayerController->bShowMouseCursor = false;
playerController->SetPause(false); PlayerController->SetPause(false);
} }
Parent->SetIsFocusable(false); Parent->SetIsFocusable(false);

View File

@ -31,7 +31,7 @@ class VAMPIRES_API UUpgradeButtonWidget : public UVampireInteractiveWidget, publ
{ {
GENERATED_BODY() GENERATED_BODY()
public: protected:
UPROPERTY(EditDefaultsOnly, meta=(BindWidget)) UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
TObjectPtr<UButton> Body; TObjectPtr<UButton> Body;
@ -86,5 +86,4 @@ private:
UFUNCTION() UFUNCTION()
void OnUnhoveredDelegate() { SetTextBlockUnhovered(WeaponNameTextBlock); SetTextBlockUnhovered(DescriptionTextBlock); } void OnUnhoveredDelegate() { SetTextBlockUnhovered(WeaponNameTextBlock); SetTextBlockUnhovered(DescriptionTextBlock); }
}; };

View File

@ -7,11 +7,11 @@
#include "GameFramework/GameUserSettings.h" #include "GameFramework/GameUserSettings.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
void UVampireInteractiveWidget::SetReturnScreen(UUserWidget* userWidget) void UVampireInteractiveWidget::SetReturnScreen(UUserWidget* UserWidget)
{ {
if (userWidget) if (UserWidget)
{ {
PreviousScreen = userWidget; PreviousScreen = UserWidget;
} }
} }

View File

@ -15,8 +15,7 @@ class VAMPIRES_API UVampireInteractiveWidget : public UUserWidget
{ {
GENERATED_BODY() GENERATED_BODY()
public: protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TObjectPtr<USoundBase> ButtonHoveredSound; TObjectPtr<USoundBase> ButtonHoveredSound;
@ -37,9 +36,8 @@ protected:
TObjectPtr<UUserWidget> PreviousScreen; TObjectPtr<UUserWidget> PreviousScreen;
public: public:
UFUNCTION() UFUNCTION()
void SetReturnScreen(UUserWidget* userWidget); void SetReturnScreen(UUserWidget* UserWidget);
protected: protected:
UFUNCTION() UFUNCTION()