Compare commits

..

No commits in common. "1a3516c263dbdf42e33eb0fb79f5242becb03e57" and "eb4ce4cb793b523797f835798c03b3fc1641b6fb" have entirely different histories.

72 changed files with 783 additions and 778 deletions

View File

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

View File

@ -8,7 +8,6 @@
#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))
@ -17,16 +16,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;
private: protected:
int CurrentEXP = 0; int CurrentEXP = 0;
int CurrentLevel = 0; int CurrentLevel = 0;
@ -38,10 +37,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();
@ -58,4 +57,8 @@ 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,6 +17,7 @@ class VAMPIRES_API AEXPPickup : public APickup
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
public:
virtual void OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, virtual void OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult) override; const FHitResult& SweepResult) override;

View File

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

View File

@ -8,7 +8,6 @@
#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;
@ -21,7 +20,7 @@ class VAMPIRES_API AEnemyCharacter : public AVampireCharacter, public IEnemyable
{ {
GENERATED_BODY() GENERATED_BODY()
protected: public:
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
TSubclassOf<AEXPPickup> EXPPickupTemplate = nullptr; TSubclassOf<AEXPPickup> EXPPickupTemplate = nullptr;
@ -29,7 +28,7 @@ protected:
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;
@ -54,20 +53,19 @@ 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(EditDefaultsOnly) UPROPERTY(BlueprintReadWrite, EditAnywhere)
TObjectPtr<UStaticMesh> StaticMesh; TObjectPtr<UStaticMesh> StaticMesh;
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
TObjectPtr<UBehaviorTree> BehaviorTree = nullptr; TObjectPtr<UBehaviorTree> BehaviorTree = nullptr;
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
TObjectPtr<UPickupDataAsset> PickupDataAsset = nullptr; TObjectPtr<UPickupDataAsset> PickupDataAsset = nullptr;
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
TObjectPtr<USoundBase> OnDamagedSoundBase = nullptr; TObjectPtr<USoundBase> OnDamagedSoundBase = nullptr;
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
TObjectPtr<USoundBase> OnDeathSoundBase = nullptr; TObjectPtr<USoundBase> OnDeathSoundBase = nullptr;
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
TObjectPtr<UNiagaraSystem> OnDamagedNiagaraSystem; TObjectPtr<UNiagaraSystem> OnDamagedNiagaraSystem;
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
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;
private: protected:
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,6 +17,7 @@ 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 bIsDead) void UHealthComponent::SetIsDead(bool isDead)
{ {
IsDead = bIsDead; IsDead = isDead;
} }
bool UHealthComponent::GetCanDamage() bool UHealthComponent::GetCanDamage()
@ -94,9 +94,9 @@ bool UHealthComponent::GetCanDamage()
return CanDamage; return CanDamage;
} }
void UHealthComponent::SetCanDamage(bool bCanDamage) void UHealthComponent::SetCanDamage(bool canDamage)
{ {
CanDamage = bCanDamage; CanDamage = canDamage;
} }

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 bIsDead); void SetIsDead(bool isDead);
UFUNCTION() UFUNCTION()
bool GetCanDamage(); bool GetCanDamage();
UFUNCTION() UFUNCTION()
void SetCanDamage(bool bCanDamage); void SetCanDamage(bool canDamage);
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,45 +10,44 @@ void AObjectPoolManager::BeginPlay()
Super::BeginPlay(); Super::BeginPlay();
} }
void AObjectPoolManager::InitializeObjectPool(const TSubclassOf<AActor>& TemplateObject, const int InitialObjectPoolSize) void AObjectPoolManager::InitializeObjectPool(TSubclassOf<AActor> Object, const int InitialObjectPoolSize)
{ {
ObjectTemplate = TemplateObject; ObjectTemplate = Object;
for (int i = 0; i < InitialObjectPoolSize; i++) for (int i = 0; i < InitialObjectPoolSize; i++)
{ {
if (AActor* Object = GetWorld()->SpawnActor< if (AActor* object = GetWorld()->SpawnActor<AActor>(Object, FVector(100000.0f, 100000.0f, 0), FRotator(0, 0, 0)))
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* TemplateObject, int InitialObjectPoolSize) void AObjectPoolManager::InitializeObjectPool(UClass* Object, int InitialObjectPoolSize)
{ {
for (int i = 0; i < InitialObjectPoolSize; i++) for (int i = 0; i < InitialObjectPoolSize; i++)
{ {
if (AActor* Object = GetWorld()->SpawnActor<AActor>(TemplateObject)) if (AActor* object = GetWorld()->SpawnActor<AActor>(Object))
{ {
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];
@ -60,19 +59,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 bEnabled, AActor* Object) void AObjectPoolManager::SetObjectStatus(bool enabled, AActor* object)
{ {
Object->SetActorHiddenInGame(!bEnabled); object->SetActorHiddenInGame(!enabled);
Object->SetActorTickEnabled(bEnabled); object->SetActorTickEnabled(enabled);
Object->SetActorEnableCollision(bEnabled); object->SetActorEnableCollision(enabled);
} }

View File

@ -15,17 +15,17 @@ class VAMPIRES_API AObjectPoolManager : public AActor
TSubclassOf<AActor> ObjectTemplate; TSubclassOf<AActor> ObjectTemplate;
public: public:
void InitializeObjectPool(const TSubclassOf<AActor>& TemplateObject, int InitialObjectPoolSize = 400); void InitializeObjectPool(TSubclassOf<AActor> Object, int InitialObjectPoolSize = 400);
void InitializeObjectPool(UClass* TemplateObject, int InitialObjectPoolSize = 400); void InitializeObjectPool(UClass* Object, 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 bEnabled, AActor* Object); void SetObjectStatus(bool enabled, 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,19 +131,18 @@ 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< if (!TimelineComponent->IsPlaying() && UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) == Cast<ACharacter>(OtherActor))
ACharacter>(OtherActor))
{ {
PlayTimeLine(); PlayTimeLine();
} }
} }
void APickup::TimelineCallback(float Value) void APickup::TimelineCallback(float val)
{ {
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, Value); FVector location = FMath::Lerp(actorLocation, playerLocation, val);
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()
protected: public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
int PickupValue = 1; int PickupValue = 1;
@ -44,8 +44,8 @@ protected:
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 Value); void TimelineCallback(float val);
UFUNCTION() UFUNCTION()
void TimelineFinishedCallback(); void TimelineFinishedCallback();

View File

@ -3,9 +3,14 @@
#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"
@ -32,8 +37,8 @@ APlayerCharacter::APlayerCharacter()
CameraShakeTimelineComponent->SetTimelineLengthMode(TL_TimelineLength); CameraShakeTimelineComponent->SetTimelineLengthMode(TL_TimelineLength);
CameraShakeTimelineComponent->SetPlaybackPosition(0.0f, false); CameraShakeTimelineComponent->SetPlaybackPosition(0.0f, false);
OnTimelineCallback.BindUFunction(this, FName(TEXT("CameraShakeTimelineCallback"))); onTimelineCallback.BindUFunction(this, FName(TEXT("CameraShakeTimelineCallback")));
OnTimelineFinishedCallback.BindUFunction(this, FName(TEXT("CameraShakeTimelineFinishedCallback"))); onTimelineFinishedCallback.BindUFunction(this, FName(TEXT("CameraShakeTimelineFinishedCallback")));
} }
void APlayerCharacter::BeginPlay() void APlayerCharacter::BeginPlay()
@ -45,30 +50,33 @@ 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);
FVector Location = GetActorLocation(); auto PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
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);
SetActorLocation(Location); FVector TopLeft, TopLeftDir;
} 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()
@ -81,7 +89,7 @@ UGoldComponent* APlayerCharacter::GetGoldComponent()
return GoldComponent; return GoldComponent;
} }
void APlayerCharacter::OnDamaged(FDamageInfo DamageInfo) void APlayerCharacter::OnDamaged(FDamageInfo damageInfo)
{ {
if (OnDamagedSound) if (OnDamagedSound)
{ {
@ -91,20 +99,21 @@ 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, cameraActor->SetActorLocation(FVector(FMath::RandRange(0.0f, CameraShakeStrength) * val, FMath::RandRange(0.0f, CameraShakeStrength) * val, 0.0f));
FMath::RandRange(0.0f, CameraShakeStrength) * Val, 0.0f));
} }
void APlayerCharacter::CameraShakeTimelineFinishedCallback() void APlayerCharacter::CameraShakeTimelineFinishedCallback()
@ -113,19 +122,3 @@ 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,7 +5,6 @@
#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;
@ -25,7 +24,7 @@ class VAMPIRES_API APlayerCharacter : public AVampireCharacter
{ {
GENERATED_BODY() GENERATED_BODY()
protected: public:
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<UEXPComponent> EXPComponent; TObjectPtr<UEXPComponent> EXPComponent;
@ -45,22 +44,19 @@ protected:
float CameraShakeStrength = 100.0f; float CameraShakeStrength = 100.0f;
private: private:
UPROPERTY()
TObjectPtr<APlayerCameraManager> PlayerCameraManager = nullptr; TObjectPtr<APlayerCameraManager> PlayerCameraManager = nullptr;
FOnTimelineFloat OnTimelineCallback;
FOnTimelineEventStatic OnTimelineFinishedCallback;
FTimerHandle ResizeViewportTimerDelegate;
FVector TopLeft, TopLeftDir, BottomRight, BottomRightDir;
APlayerCharacter(); APlayerCharacter();
private:
FOnTimelineFloat onTimelineCallback;
FOnTimelineEventStatic onTimelineFinishedCallback;
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();
@ -69,19 +65,14 @@ 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,8 +60,7 @@ void AProjectile::SetActorHiddenInGame(bool bNewHidden)
} }
else else
{ {
GetWorldTimerManager().SetTimer(ProjectileLifetimeTimerHandle, this, &AProjectile::ReturnProjectileToPool, GetWorldTimerManager().SetTimer(ProjectileLifetimeTimerHandle, this, &AProjectile::ReturnProjectileToPool, ProjectileLifespan, true);
ProjectileLifespan, true);
} }
} }
@ -104,14 +103,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--;
@ -125,14 +124,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,6 +49,7 @@ 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,9 +75,22 @@ void AVampireAIController::OnDamaged(FDamageInfo Info)
} }
} }
void AVampireAIController::OnDeath(FDamageInfo Info) void AVampireAIController::OnDeath(FDamageInfo info)
{ {
EnemyCharacter->OnDeath(Info); // TODO: Do stuff here
EnemyCharacter->OnDeath(info);
/*EnemyCharacter->DetachFromControllerPendingDestroy();
EnemyCharacter->GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
EnemyCharacter->GetCapsuleComponent()->SetCollisionResponseToAllChannels(ECR_Ignore);
if (UPawnMovementComponent* characterMovementComponent = EnemyCharacter->GetMovementComponent())
{
characterMovementComponent->StopMovementImmediately();
characterMovementComponent->StopActiveMovement();
characterMovementComponent->SetComponentTickEnabled(false);
}
GetWorldTimerManager().ClearTimer(PawnMoveToTimerHandle);
EnemyCharacter->SetLifeSpan(0.1f);*/
} }
void AVampireAIController::PawnMoveTo() void AVampireAIController::PawnMoveTo()

View File

@ -38,15 +38,18 @@ 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,6 +29,8 @@ AVampireCharacter::AVampireCharacter()
void AVampireCharacter::BeginPlay() void AVampireCharacter::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
} }
// Called every frame // Called every frame
@ -36,21 +38,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);
} }
} }
@ -68,3 +70,4 @@ 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,3 +2,4 @@
#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,9 +24,6 @@ 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;
@ -36,6 +33,8 @@ protected:
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
TSubclassOf<AEXPPickup> PickupTemplate; TSubclassOf<AEXPPickup> PickupTemplate;
FOnEnemyDeathCountIncrementDelegate OnEnemyDeathCountIncrementDelegate;
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
TArray<TObjectPtr<UEnemyDataAsset>> EnemyDataAssets; TArray<TObjectPtr<UEnemyDataAsset>> EnemyDataAssets;
@ -69,7 +68,6 @@ public:
UFUNCTION(BlueprintCallable, BlueprintPure) UFUNCTION(BlueprintCallable, BlueprintPure)
int GetEnemyDeathCount(); int GetEnemyDeathCount();
protected:
UFUNCTION() UFUNCTION()
void HandleOnEnemyDeath(FDamageInfo damageInfo); void HandleOnEnemyDeath(FDamageInfo damageInfo);
@ -88,6 +86,7 @@ protected:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void EndGame(); void EndGame();
protected:
UFUNCTION() UFUNCTION()
void SpawnEnemy(); void SpawnEnemy();
}; };

View File

@ -23,55 +23,53 @@ void AVampirePlayerController::OnPossess(APawn* aPawn)
{ {
Super::OnPossess(aPawn); Super::OnPossess(aPawn);
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>( if (UEnhancedInputLocalPlayerSubsystem* subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()))
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. gamemode->OnEnemyDeathCountIncrementDelegate.AddDynamic(this, &AVampirePlayerController::UpdateKillCountHUD);
AddDynamic(this, &AVampirePlayerController::UpdateKillCountHUD); UpdateKillCountHUD(gamemode->GetEnemyDeathCount());
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);
} }
} }
} }
@ -80,7 +78,7 @@ void AVampirePlayerController::OnUnPossess()
{ {
Super::OnUnPossess(); Super::OnUnPossess();
GetWorld()->GetTimerManager().ClearTimer(PawnLifeTimeHandle); GetWorld()->GetTimerManager().ClearTimer(pawnLifeTimeHandle);
} }
void AVampirePlayerController::SetupInputComponent() void AVampirePlayerController::SetupInputComponent()
@ -96,13 +94,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);
} }
} }
} }
@ -121,26 +119,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)
@ -148,8 +146,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;
} }
@ -158,54 +156,53 @@ 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, UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, currentLevelUpUI, EMouseLockMode::LockInFullscreen);
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,11 +54,10 @@ protected:
private: private:
FTimerHandle WeaponTimerHandle; FTimerHandle WeaponTimerHandle;
protected: public:
// 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> NewWeapon) void UWeaponInventoryComponent::AddWeaponToInventory(TSubclassOf<AWeapon> Weapon)
{ {
FActorSpawnParameters SpawnParameters; FActorSpawnParameters SpawnParameters;
SpawnParameters.Owner = GetOwner(); SpawnParameters.Owner = GetOwner();
AWeapon* Weapon = GetWorld()->SpawnActor<AWeapon>(NewWeapon, SpawnParameters.Owner->GetTransform(), SpawnParameters); AWeapon* weapon = GetWorld()->SpawnActor<AWeapon>(Weapon, 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(NewWeapon); obtainableWeapons.Remove(Weapon);
} }
TArray<AWeapon*> UWeaponInventoryComponent::GetInventory() TArray<AWeapon*> UWeaponInventoryComponent::GetInventory()
{ {
return Inventory; return inventory;
} }

View File

@ -15,15 +15,16 @@ 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>> InitialInventory; TArray<TSubclassOf<AWeapon>> obtainableWeapons;
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
@ -38,7 +39,7 @@ public:
void InitializeInventory(); void InitializeInventory();
UFUNCTION() UFUNCTION()
void AddWeaponToInventory(TSubclassOf<AWeapon> NewWeapon); void AddWeaponToInventory(TSubclassOf<AWeapon> Weapon);
UFUNCTION() UFUNCTION()
TArray<AWeapon*> GetInventory(); TArray<AWeapon*> GetInventory();

View File

@ -27,10 +27,7 @@ void AFireWandWeapon::FireWeaponAction_Implementation()
bool AFireWandWeapon::UpgradeWeapon_Implementation() bool AFireWandWeapon::UpgradeWeapon_Implementation()
{ {
if (!Super::UpgradeWeapon_Implementation()) if (!Super::UpgradeWeapon_Implementation()) return false;
{
return false;
}
switch (CurrentLevel) switch (CurrentLevel)
{ {
@ -70,26 +67,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,6 +3,7 @@
#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"
@ -19,8 +20,7 @@ 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);
// This is to match the size of our sphere component VisualEffectMeshComponent->SetWorldScale3D(FVector(3.0f, 3.0f, 3.0f)); // 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,14 +41,15 @@ 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);
} }
} }
@ -78,22 +79,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);
} }
@ -101,10 +102,7 @@ void AGarlicWeapon::GarlicFireWeaponAction(FOverlappedEnemy EnemyCharacter)
bool AGarlicWeapon::UpgradeWeapon_Implementation() bool AGarlicWeapon::UpgradeWeapon_Implementation()
{ {
if (!Super::UpgradeWeapon_Implementation()) if (!Super::UpgradeWeapon_Implementation()) return false;
{
return false;
}
switch (CurrentLevel) switch (CurrentLevel)
{ {
@ -112,8 +110,7 @@ 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->SetWorldScale3D(VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.4f);
VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.4f);
break; break;
case 2: case 2:
WeaponCooldown -= 0.1f; WeaponCooldown -= 0.1f;
@ -123,8 +120,7 @@ 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->SetWorldScale3D(VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f);
VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f);
break; break;
case 4: case 4:
WeaponCooldown -= 0.1f; WeaponCooldown -= 0.1f;
@ -134,8 +130,7 @@ 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->SetWorldScale3D(VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f);
VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f);
break; break;
case 6: case 6:
WeaponCooldown -= 0.1f; WeaponCooldown -= 0.1f;
@ -145,8 +140,7 @@ 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->SetWorldScale3D(VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f);
VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f);
break; break;
default: default:
return false; return false;

View File

@ -27,8 +27,7 @@ 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;
@ -39,7 +38,6 @@ protected:
private: private:
float Range; float Range;
public: public:
AGarlicWeapon(); AGarlicWeapon();

View File

@ -29,10 +29,7 @@ void AGunWeapon::FireWeaponAction_Implementation()
bool AGunWeapon::UpgradeWeapon_Implementation() bool AGunWeapon::UpgradeWeapon_Implementation()
{ {
if (!Super::UpgradeWeapon_Implementation()) if (!Super::UpgradeWeapon_Implementation()) return false;
{
return false;
}
switch (CurrentLevel) switch (CurrentLevel)
{ {
@ -70,11 +67,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);
@ -95,20 +92,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();
} }
@ -116,12 +113,12 @@ void AGunWeapon::FireProjectile()
} }
} }
void AGunWeapon::SpawnProjectile(AActor* Projectile, const FVector& Direction) void AGunWeapon::SpawnProjectile(AActor* projectile, 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, const FVector& Direction); void SpawnProjectile(AActor* projectile, FVector direction);
}; };

View File

@ -27,10 +27,7 @@ void AKnifeWeapon::FireWeaponAction_Implementation()
bool AKnifeWeapon::UpgradeWeapon_Implementation() bool AKnifeWeapon::UpgradeWeapon_Implementation()
{ {
if (!Super::UpgradeWeapon_Implementation()) if (!Super::UpgradeWeapon_Implementation()) return false;
{
return false;
}
switch (CurrentLevel) switch (CurrentLevel)
{ {
@ -70,24 +67,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()
protected: public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon | Lightning Ring") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon | Lightning Ring")
int LightningBolts = 1; int LightningBolts = 1;
@ -27,8 +27,10 @@ protected:
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,10 +27,7 @@ void AMagicWandWeapon::FireWeaponAction_Implementation()
bool AMagicWandWeapon::UpgradeWeapon_Implementation() bool AMagicWandWeapon::UpgradeWeapon_Implementation()
{ {
if (!Super::UpgradeWeapon_Implementation()) if (!Super::UpgradeWeapon_Implementation()) return false;
{
return false;
}
switch (CurrentLevel) switch (CurrentLevel)
{ {
@ -68,29 +65,30 @@ 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 (AActor* nearestActor = UGameplayStatics::FindNearestActor(GetActorLocation(), OverlappedEnemies, Distance)) if (nearestActor)
{ {
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,10 +36,7 @@ void APentagramWeapon::FireWeaponAction_Implementation()
bool APentagramWeapon::UpgradeWeapon_Implementation() bool APentagramWeapon::UpgradeWeapon_Implementation()
{ {
if (!Super::UpgradeWeapon_Implementation()) if (!Super::UpgradeWeapon_Implementation()) return false;
{
return false;
}
switch (CurrentLevel) switch (CurrentLevel)
{ {
@ -74,8 +71,7 @@ bool APentagramWeapon::UpgradeWeapon_Implementation()
} }
void APentagramWeapon::OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, void APentagramWeapon::OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
const FHitResult& SweepResult)
{ {
if (APickup* Pickup = Cast<APickup>(OtherActor)) if (APickup* Pickup = Cast<APickup>(OtherActor))
{ {
@ -83,8 +79,7 @@ void APentagramWeapon::OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedCompo
} }
else else
{ {
Super::OnWeaponBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, Super::OnWeaponBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
SweepResult);
} }
} }

View File

@ -17,6 +17,7 @@ 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:
@ -24,11 +25,10 @@ public:
virtual void FireWeaponAction_Implementation() override; virtual void FireWeaponAction_Implementation() override;
virtual bool UpgradeWeapon_Implementation() override; bool UpgradeWeapon_Implementation() override;
virtual void OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, virtual void OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) override;
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()
protected: public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TObjectPtr<USphereComponent> SphereComponent = nullptr; TObjectPtr<USphereComponent> SphereComponent = nullptr;
@ -27,6 +27,7 @@ protected:
// 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()
protected: public:
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(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon | Swarm") UPROPERTY(EditAnywhere, 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(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon | Swarm") UPROPERTY(EditAnywhere, 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,7 +16,8 @@ class VAMPIRES_API UHUDWidget : public UUserWidget
{ {
GENERATED_BODY() GENERATED_BODY()
protected: public:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UProgressBar* EXPbar; UProgressBar* EXPbar;
@ -34,19 +35,19 @@ protected:
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,7 +6,6 @@
#include "Blueprint/UserWidget.h" #include "Blueprint/UserWidget.h"
#include "HealthbarWidget.generated.h" #include "HealthbarWidget.generated.h"
struct FDamageInfo;
class UProgressBar; class UProgressBar;
/** /**
* *
@ -16,13 +15,13 @@ class VAMPIRES_API UHealthbarWidget : public UUserWidget
{ {
GENERATED_BODY() GENERATED_BODY()
protected: public:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
TObjectPtr<UProgressBar> HealthBar; 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,7 +17,8 @@ class VAMPIRES_API ULevelUpWidget : public UUserWidget
{ {
GENERATED_BODY() GENERATED_BODY()
protected: public:
UPROPERTY(BlueprintReadWrite, meta=(BindWidget)) UPROPERTY(BlueprintReadWrite, meta=(BindWidget))
UButton* ResumeButton; UButton* ResumeButton;
@ -27,6 +28,7 @@ protected:
virtual void NativeConstruct() override; virtual void NativeConstruct() override;
private: private:
UFUNCTION() UFUNCTION()
void ResumeButtonClicked(); void ResumeButtonClicked();
}; };

View File

@ -51,14 +51,27 @@ 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
protected: public:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
TObjectPtr<UButton> NewGameButton; TObjectPtr<UButton> NewGameButton;
@ -38,7 +38,7 @@ protected:
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,6 +16,7 @@ class VAMPIRES_API UPauseWidget : public UUserWidget
GENERATED_BODY() GENERATED_BODY()
public: public:
UPROPERTY(BlueprintReadWrite, meta=(BindWidget)) UPROPERTY(BlueprintReadWrite, meta=(BindWidget))
UButton* ResumeButton; UButton* ResumeButton;
@ -24,6 +25,7 @@ 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()
protected: public:
UPROPERTY(BlueprintReadWrite, meta=(BindWidget)) UPROPERTY(BlueprintReadWrite, meta=(BindWidget))
TObjectPtr<UButton> BackButton; TObjectPtr<UButton> BackButton;
@ -29,7 +29,7 @@ protected:
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* ParentWidget) void UStarterWeaponButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* parent)
{ {
WeaponName = Weapon->GetWeaponName(); WeaponName = Weapon->GetWeaponName();
WeaponDescription = Weapon->GetDescription(); Description = Weapon->GetDescription();
WeaponIcon = Weapon->GetIcon(); WeaponIcon = Weapon->GetIcon();
WeaponInstance = Weapon; WeaponInstance = Weapon;
Parent = ParentWidget; Parent = parent;
} }
void UStarterWeaponButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* ParentWidget) void UStarterWeaponButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent)
{ {
if (AWeapon* tempWeapon = NewObject<AWeapon>(this, Weapon)) if (AWeapon* tempWeapon = NewObject<AWeapon>(this, Weapon))
{ {
SetData(tempWeapon, ParentWidget); SetData(tempWeapon, parent);
WeaponTemplate = Weapon; WeaponTemplate = Weapon;
} }
} }
void UStarterWeaponButtonDataObject::SetData(FText NewWeaponName, FText NewWeaponDescription, TObjectPtr<UTexture2D> NewWeaponIcon, void UStarterWeaponButtonDataObject::SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon,
UUserWidget* ParentWidget) UUserWidget* parent)
{ {
WeaponName = NewWeaponName; WeaponName = weaponName;
WeaponDescription = NewWeaponDescription; Description = description;
WeaponIcon = NewWeaponIcon; WeaponIcon = weaponIcon;
Parent = ParentWidget; Parent = parent;
} }

View File

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

View File

@ -18,10 +18,12 @@ void UStarterWeaponButtonWidget::NativeConstruct()
void UStarterWeaponButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject) void UStarterWeaponButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
{ {
if (UStarterWeaponButtonDataObject* Item = Cast<UStarterWeaponButtonDataObject>(ListItemObject)) UStarterWeaponButtonDataObject* Item = Cast<UStarterWeaponButtonDataObject>(ListItemObject);
if (Item)
{ {
WeaponNameTextBlock->SetText(Item->WeaponName); WeaponNameTextBlock->SetText(Item->WeaponName);
DescriptionTextBlock->SetText(Item->WeaponDescription); DescriptionTextBlock->SetText(Item->Description);
WeaponIcon->SetBrushFromTexture(Item->WeaponIcon); WeaponIcon->SetBrushFromTexture(Item->WeaponIcon);
Parent = Item->Parent; Parent = Item->Parent;
WeaponTemplate = Item->WeaponTemplate; WeaponTemplate = Item->WeaponTemplate;
@ -41,13 +43,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()
protected: public:
UPROPERTY(EditDefaultsOnly, meta=(BindWidget)) UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
TObjectPtr<UButton> Body; TObjectPtr<UButton> Body;
@ -39,6 +39,7 @@ protected:
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* ParentWidget) void UUpgradeButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* parent)
{ {
WeaponName = Weapon->GetWeaponName(); WeaponName = Weapon->GetWeaponName();
WeaponIcon = Weapon->GetIcon(); WeaponIcon = Weapon->GetIcon();
WeaponInstance = Weapon; WeaponInstance = Weapon;
Parent = ParentWidget; Parent = parent;
if (Weapon->GetUpgradeDescriptions().Num() > Weapon->GetWeaponLevel()) if (Weapon->GetUpgradeDescriptions().Num() > Weapon->GetWeaponLevel())
{ {
WeaponDescription = Weapon->GetUpgradeDescriptions()[Weapon->GetWeaponLevel()]; Description = Weapon->GetUpgradeDescriptions()[Weapon->GetWeaponLevel()];
} }
} }
void UUpgradeButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* ParentWidget) void UUpgradeButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent)
{ {
if (AWeapon* tempWeapon = NewObject<AWeapon>(this, Weapon)) if (AWeapon* tempWeapon = NewObject<AWeapon>(this, Weapon))
{ {
SetData(tempWeapon, ParentWidget); SetData(tempWeapon, parent);
} }
} }
void UUpgradeButtonDataObject::SetData(FText NewWeaponName, FText NewDescription, TObjectPtr<UTexture2D> NewWeaponIcon, void UUpgradeButtonDataObject::SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon,
UUserWidget* ParentWidget) UUserWidget* parent)
{ {
WeaponName = NewWeaponName; WeaponName = weaponName;
WeaponDescription = NewDescription; Description = description;
WeaponIcon = NewWeaponIcon; WeaponIcon = weaponIcon;
Parent = ParentWidget; Parent = parent;
} }

View File

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

View File

@ -22,10 +22,12 @@ void UUpgradeButtonWidget::NativeConstruct()
void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject) void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
{ {
if (UUpgradeButtonDataObject* Item = Cast<UUpgradeButtonDataObject>(ListItemObject)) UUpgradeButtonDataObject* Item = Cast<UUpgradeButtonDataObject>(ListItemObject);
if (Item)
{ {
WeaponNameTextBlock->SetText(Item->WeaponName); WeaponNameTextBlock->SetText(Item->WeaponName);
DescriptionTextBlock->SetText(Item->WeaponDescription); DescriptionTextBlock->SetText(Item->Description);
WeaponIcon->SetBrushFromTexture(Item->WeaponIcon); WeaponIcon->SetBrushFromTexture(Item->WeaponIcon);
Parent = Item->Parent; Parent = Item->Parent;
@ -81,7 +83,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)
{ {
@ -90,29 +92,31 @@ void UUpgradeButtonWidget::OnClicked()
break; break;
case NewWeapon: case NewWeapon:
if (UWeaponInventoryComponent* Inventory = PlayerController->GetPawn()->GetComponentByClass<UWeaponInventoryComponent>()) if (UWeaponInventoryComponent* Inventory = playerController->GetPawn()->GetComponentByClass<
UWeaponInventoryComponent>())
{ {
Inventory->AddWeaponToInventory(WeaponTemplate); Inventory->AddWeaponToInventory(WeaponTemplate);
Inventory->ObtainableWeapons.Remove(WeaponTemplate); Inventory->obtainableWeapons.Remove(WeaponTemplate);
} }
break; break;
case Health: case Health:
if (PlayerController) if (playerController)
{ {
if (UHealthComponent* HealthComponent = PlayerController->GetPawn()->GetComponentByClass<UHealthComponent>()) if (UHealthComponent* healthComponent = playerController->GetPawn()->GetComponentByClass<
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;
@ -125,11 +129,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()
protected: public:
UPROPERTY(EditDefaultsOnly, meta=(BindWidget)) UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
TObjectPtr<UButton> Body; TObjectPtr<UButton> Body;
@ -86,4 +86,5 @@ 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,7 +15,8 @@ class VAMPIRES_API UVampireInteractiveWidget : public UUserWidget
{ {
GENERATED_BODY() GENERATED_BODY()
protected: public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TObjectPtr<USoundBase> ButtonHoveredSound; TObjectPtr<USoundBase> ButtonHoveredSound;
@ -36,8 +37,9 @@ protected:
TObjectPtr<UUserWidget> PreviousScreen; TObjectPtr<UUserWidget> PreviousScreen;
public: public:
UFUNCTION() UFUNCTION()
void SetReturnScreen(UUserWidget* UserWidget); void SetReturnScreen(UUserWidget* userWidget);
protected: protected:
UFUNCTION() UFUNCTION()