diff --git a/Source/vampires/EXPComponent.cpp b/Source/vampires/EXPComponent.cpp index 909e706..3d4ce95 100644 --- a/Source/vampires/EXPComponent.cpp +++ b/Source/vampires/EXPComponent.cpp @@ -15,22 +15,21 @@ UEXPComponent::UEXPComponent() // ... } -void UEXPComponent::IncrementEXP(int value) +void UEXPComponent::IncrementEXP(int Value) { - int oldEXP = CurrentEXP; - int oldLevel = CurrentLevel; - - CurrentEXP += value; - + int OldLevel = CurrentLevel; + CurrentEXP += Value; + if (NextLevelRow.Level >= 0) { if (CurrentEXP >= NextLevelRow.CumulativeExpForNextLevel) { CurrentLevel = NextLevelRow.Level; - - if (FExpTableRow* newRow = LevelsTable->FindRow(FName(*FString::FromInt(NextLevelRow.Level + 1)),"", true)) + + if (FExpTableRow* NewRow = LevelsTable->FindRow( + FName(*FString::FromInt(NextLevelRow.Level + 1)), "", true)) { - NextLevelRow = *newRow; + NextLevelRow = *NewRow; } else { @@ -39,37 +38,36 @@ void UEXPComponent::IncrementEXP(int value) NextLevelRow.ExpRequiredForNextLevel += 16; NextLevelRow.CumulativeExpForNextLevel += NextLevelRow.ExpRequiredForNextLevel; } - + OnEXPLevelUp.Broadcast(CurrentLevel); } } else { CurrentLevel = FMath::Floor(CurrentEXP / 100.0f); - - if (CurrentLevel != oldLevel) + + if (CurrentLevel != OldLevel) { OnEXPLevelUp.Broadcast(CurrentLevel); } } - + OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent()); } -void UEXPComponent::SetCurrentEXP(int value) +void UEXPComponent::SetCurrentEXP(int Value) { - int oldEXP = CurrentEXP; - int oldLevel = CurrentLevel; - - CurrentEXP = value; - + int OldLevel = CurrentLevel; + CurrentEXP = Value; NextLevelRow = FExpTableRow(); - - while (CurrentEXP < NextLevelRow.CumulativeExpForPreviousLevel && CurrentEXP < NextLevelRow.CumulativeExpForNextLevel) + + while (CurrentEXP < NextLevelRow.CumulativeExpForPreviousLevel && CurrentEXP < NextLevelRow. + CumulativeExpForNextLevel) { - if (FExpTableRow* newRow = LevelsTable->FindRow(FName(*FString::FromInt(NextLevelRow.Level + 1)),"", true)) + if (FExpTableRow* NewRow = LevelsTable->FindRow(FName(*FString::FromInt(NextLevelRow.Level + 1)), + "", true)) { - NextLevelRow = *newRow; + NextLevelRow = *NewRow; } else { @@ -78,11 +76,11 @@ void UEXPComponent::SetCurrentEXP(int value) NextLevelRow.ExpRequiredForNextLevel += 16; NextLevelRow.CumulativeExpForNextLevel += NextLevelRow.ExpRequiredForNextLevel; } - } - + } + OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent()); - - if (CurrentLevel != oldLevel) + + if (CurrentLevel != OldLevel) { OnEXPLevelUp.Broadcast(CurrentLevel); } @@ -102,12 +100,12 @@ void UEXPComponent::Reset() { if (LevelsTable) { - if (FExpTableRow* newRow = LevelsTable->FindRow(FName("1"), "", true)) + if (FExpTableRow* NewRow = LevelsTable->FindRow(FName("1"), "", true)) { - NextLevelRow = *newRow; + NextLevelRow = *NewRow; } } - + CurrentEXP = 0; CurrentLevel = 0; OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent()); @@ -116,15 +114,16 @@ void UEXPComponent::Reset() float UEXPComponent::GetCurrentLevelPercent() { - int adjustedCurrentExp = CurrentEXP - NextLevelRow.CumulativeExpForPreviousLevel; - float res = static_cast(adjustedCurrentExp) / static_cast(NextLevelRow.ExpRequiredForNextLevel); + int AdjustedCurrentExp = CurrentEXP - NextLevelRow.CumulativeExpForPreviousLevel; + float CurrentLevelPercent = static_cast(AdjustedCurrentExp) / static_cast(NextLevelRow. + ExpRequiredForNextLevel); - if (FMath::IsNaN(res)) + if (FMath::IsNaN(CurrentLevelPercent)) { return 0.0f; } - return res; + return CurrentLevelPercent; } // Called when the game starts diff --git a/Source/vampires/EXPComponent.h b/Source/vampires/EXPComponent.h index af0ab55..7fb7906 100644 --- a/Source/vampires/EXPComponent.h +++ b/Source/vampires/EXPComponent.h @@ -8,6 +8,7 @@ #include "EXPComponent.generated.h" DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnEXPGainedDelegate, int, exp, float, currentLevelPercent); + DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEXPLevelUpDelegate, int, level); UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) @@ -16,16 +17,16 @@ class VAMPIRES_API UEXPComponent : public UActorComponent GENERATED_BODY() public: - UPROPERTY(BlueprintAssignable, Category="EXP") FOnEXPGainedDelegate OnEXPGained; + UPROPERTY(BlueprintAssignable, Category="EXP") FOnEXPLevelUpDelegate OnEXPLevelUp; UPROPERTY(EditDefaultsOnly, Category="EXP") TObjectPtr LevelsTable; -protected: +private: int CurrentEXP = 0; int CurrentLevel = 0; @@ -37,10 +38,10 @@ public: UEXPComponent(); UFUNCTION(BlueprintCallable) - void IncrementEXP(int value); + void IncrementEXP(int Value); UFUNCTION(BlueprintCallable) - void SetCurrentEXP(int value); + void SetCurrentEXP(int Value); UFUNCTION(BlueprintCallable, BlueprintPure) int GetCurrentEXP(); @@ -57,8 +58,4 @@ public: protected: // Called when the game starts virtual void BeginPlay() override; - -private: - - void ProcessExp(int oldEXP, int oldLevel, int newEXP); }; diff --git a/Source/vampires/EXPPickup.cpp b/Source/vampires/EXPPickup.cpp index ef13568..3004a2b 100644 --- a/Source/vampires/EXPPickup.cpp +++ b/Source/vampires/EXPPickup.cpp @@ -13,9 +13,9 @@ void AEXPPickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, A UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) { - if (UEXPComponent* expComponent = OtherActor->GetComponentByClass()) + if (UEXPComponent* ExpComponent = OtherActor->GetComponentByClass()) { - expComponent->IncrementEXP(PickupValue); + ExpComponent->IncrementEXP(PickupValue); Super::OnInnerBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); } } diff --git a/Source/vampires/EXPPickup.h b/Source/vampires/EXPPickup.h index 3424192..81f282b 100644 --- a/Source/vampires/EXPPickup.h +++ b/Source/vampires/EXPPickup.h @@ -17,8 +17,7 @@ class VAMPIRES_API AEXPPickup : public APickup protected: virtual void BeginPlay() override; -public: virtual void OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, - UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, - const FHitResult& SweepResult) override; + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, + const FHitResult& SweepResult) override; }; diff --git a/Source/vampires/EnemyCharacter.cpp b/Source/vampires/EnemyCharacter.cpp index f2b6968..e916d38 100644 --- a/Source/vampires/EnemyCharacter.cpp +++ b/Source/vampires/EnemyCharacter.cpp @@ -47,12 +47,12 @@ UBehaviorTree* AEnemyCharacter::GetBehaviorTree() return BehaviorTree; } -void AEnemyCharacter::OnDamaged(FDamageInfo damageInfo) +void AEnemyCharacter::OnDamaged(FDamageInfo DamageInfo) { - // if (OnDamagedSound) - // { + if (OnDamagedSound) + { UGameplayStatics::PlaySoundAtLocation(GetWorld(), OnDamagedSound, GetActorLocation()); - // } + } if (OnDamagedNiagaraSystem) { @@ -60,22 +60,22 @@ void AEnemyCharacter::OnDamaged(FDamageInfo damageInfo) } } -void AEnemyCharacter::OnDeath(FDamageInfo damageInfo) +void AEnemyCharacter::OnDeath(FDamageInfo DamageInfo) { if (PickupTemplate) { - AGameModeBase* gamemode = UGameplayStatics::GetGameMode(GetWorld()); - if (UKismetSystemLibrary::DoesImplementInterface(gamemode, UPools::StaticClass())) + AGameModeBase* Gamemode = UGameplayStatics::GetGameMode(GetWorld()); + if (UKismetSystemLibrary::DoesImplementInterface(Gamemode, UPools::StaticClass())) { - if (AObjectPoolManager* objectPoolManager = IPools::Execute_GetPickupObjectPoolManager(gamemode)) + if (AObjectPoolManager* ObjectPoolManager = IPools::Execute_GetPickupObjectPoolManager(Gamemode)) { - AActor* pickup = objectPoolManager->GetObject(); + AActor* Pickup = ObjectPoolManager->GetObject(); - if (UKismetSystemLibrary::DoesImplementInterface(pickup, UPickupable::StaticClass())) + if (UKismetSystemLibrary::DoesImplementInterface(Pickup, UPickupable::StaticClass())) { - FVector pickupLocation = GetActorLocation(); - pickup->SetActorLocation(pickupLocation); - IPickupable::Execute_LoadDataFromDataAsset(pickup, PickupTemplate, pickupLocation); + FVector PickupLocation = GetActorLocation(); + Pickup->SetActorLocation(PickupLocation); + IPickupable::Execute_LoadDataFromDataAsset(Pickup, PickupTemplate, PickupLocation); } } } @@ -92,17 +92,17 @@ void AEnemyCharacter::OnDeath(FDamageInfo damageInfo) } } -void AEnemyCharacter::LoadDataFromDataAsset_Implementation(UEnemyDataAsset* enemyDataAsset) +void AEnemyCharacter::LoadDataFromDataAsset_Implementation(UEnemyDataAsset* EnemyDataAsset) { - if (enemyDataAsset != nullptr) + if (EnemyDataAsset != nullptr) { - StaticMeshComponent->SetStaticMesh(enemyDataAsset->StaticMesh); - BehaviorTree = enemyDataAsset->BehaviorTree; - PickupTemplate = enemyDataAsset->PickupDataAsset; - OnDamagedSound = enemyDataAsset->OnDamagedSoundBase; - OnDeathSound = enemyDataAsset->OnDeathSoundBase; - OnDamagedNiagaraSystem = enemyDataAsset->OnDamagedNiagaraSystem; - OnDeathNiagaraSystem = enemyDataAsset->OnDeathNiagaraSystem; + StaticMeshComponent->SetStaticMesh(EnemyDataAsset->StaticMesh); + BehaviorTree = EnemyDataAsset->BehaviorTree; + PickupTemplate = EnemyDataAsset->PickupDataAsset; + OnDamagedSound = EnemyDataAsset->OnDamagedSoundBase; + OnDeathSound = EnemyDataAsset->OnDeathSoundBase; + OnDamagedNiagaraSystem = EnemyDataAsset->OnDamagedNiagaraSystem; + OnDeathNiagaraSystem = EnemyDataAsset->OnDeathNiagaraSystem; } } @@ -129,10 +129,10 @@ void AEnemyCharacter::SpawnController_Implementation() SpawnDefaultController(); } - if (BehaviorTree != nullptr) + if (AVampireAIController* VampireAIController = Cast(Controller); VampireAIController && + BehaviorTree) { - AVampireAIController* controller = Cast(Controller); - controller->RunBehaviorTree(BehaviorTree); + VampireAIController->RunBehaviorTree(BehaviorTree); } } @@ -142,20 +142,23 @@ UHealthComponent* AEnemyCharacter::GetEnemyHealthComponent_Implementation() } void AEnemyCharacter::OnDamageBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, - UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, + const FHitResult& SweepResult) { - if (Cast(OtherActor) == UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) && !Player.Contains(OtherActor)) + if (Cast(OtherActor) == UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) && !Player. + Contains(OtherActor)) { Player.Add(OtherActor); - + GetWorldTimerManager().SetTimer(DamageTimerHandle, this, &AEnemyCharacter::DamagePlayer, AttackCooldown, true); } } void AEnemyCharacter::OnDamageEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, - UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) { - if (Cast(OtherActor) == UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) && Player.Contains(OtherActor)) + if (Cast(OtherActor) == UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) && Player. + Contains(OtherActor)) { Player.Remove(OtherActor); @@ -170,8 +173,8 @@ void AEnemyCharacter::ResetHealth() void AEnemyCharacter::DamagePlayer() { - for (auto player : Player) + for (auto DamagedPlayer : Player) { - UGameplayStatics::ApplyDamage(player, Damage, GetController(), this, nullptr); + UGameplayStatics::ApplyDamage(DamagedPlayer, Damage, GetController(), this, nullptr); } } diff --git a/Source/vampires/EnemyCharacter.h b/Source/vampires/EnemyCharacter.h index 1a511c5..2c64dd0 100644 --- a/Source/vampires/EnemyCharacter.h +++ b/Source/vampires/EnemyCharacter.h @@ -8,6 +8,7 @@ #include "Interfaces/Enemyable.h" #include "EnemyCharacter.generated.h" +struct FDamageInfo; class USphereComponent; class UObjectPoolComponent; class UBehaviorTree; @@ -20,7 +21,7 @@ class VAMPIRES_API AEnemyCharacter : public AVampireCharacter, public IEnemyable { GENERATED_BODY() -public: +protected: UPROPERTY(EditDefaultsOnly) TSubclassOf EXPPickupTemplate = nullptr; @@ -28,7 +29,7 @@ public: TObjectPtr DamageSphere = nullptr; UPROPERTY(EditDefaultsOnly) - float Damage = 5.0f;; + float Damage = 5.0f; UPROPERTY(EditDefaultsOnly) float AttackCooldown = 1.0f; @@ -53,19 +54,20 @@ public: protected: virtual void BeginPlay() override; -public: virtual void Tick(float DeltaTime) override; +public: UBehaviorTree* GetBehaviorTree(); UFUNCTION() - virtual void OnDamaged(FDamageInfo damageInfo); + virtual void OnDamaged(FDamageInfo DamageInfo); UFUNCTION() - virtual void OnDeath(FDamageInfo damageInfo); - + virtual void OnDeath(FDamageInfo DamageInfo); + +protected: UFUNCTION() - virtual void LoadDataFromDataAsset_Implementation(UEnemyDataAsset* enemyDataAsset) override; + virtual void LoadDataFromDataAsset_Implementation(UEnemyDataAsset* EnemyDataAsset) override; UFUNCTION() virtual void ResetData_Implementation() override; @@ -81,12 +83,12 @@ public: UFUNCTION() void OnDamageBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, - UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, - const FHitResult& SweepResult); + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, + const FHitResult& SweepResult); UFUNCTION() void OnDamageEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, - int32 OtherBodyIndex); + int32 OtherBodyIndex); private: UFUNCTION() diff --git a/Source/vampires/EnemyDataAsset.h b/Source/vampires/EnemyDataAsset.h index c50a9e8..59ed299 100644 --- a/Source/vampires/EnemyDataAsset.h +++ b/Source/vampires/EnemyDataAsset.h @@ -19,24 +19,24 @@ class VAMPIRES_API UEnemyDataAsset : public UDataAsset GENERATED_BODY() public: - UPROPERTY(BlueprintReadWrite, EditAnywhere) + UPROPERTY(EditDefaultsOnly) TObjectPtr StaticMesh; - UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) + UPROPERTY(EditDefaultsOnly) TObjectPtr BehaviorTree = nullptr; - UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) + UPROPERTY(EditDefaultsOnly) TObjectPtr PickupDataAsset = nullptr; - - UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) + + UPROPERTY(EditDefaultsOnly) TObjectPtr OnDamagedSoundBase = nullptr; - UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) + UPROPERTY(EditDefaultsOnly) TObjectPtr OnDeathSoundBase = nullptr; - UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) + UPROPERTY(EditDefaultsOnly) TObjectPtr OnDamagedNiagaraSystem; - UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) + UPROPERTY(EditDefaultsOnly) TObjectPtr OnDeathNiagaraSystem; }; diff --git a/Source/vampires/GoldComponent.cpp b/Source/vampires/GoldComponent.cpp index 111158d..d6c7b8f 100644 --- a/Source/vampires/GoldComponent.cpp +++ b/Source/vampires/GoldComponent.cpp @@ -13,15 +13,15 @@ UGoldComponent::UGoldComponent() // ... } -void UGoldComponent::IncrementGold(int value) +void UGoldComponent::IncrementGold(int Value) { - CurrentGold += value; + CurrentGold += Value; OnGoldGained.Broadcast(CurrentGold); } -void UGoldComponent::SetCurrentGold(int value) +void UGoldComponent::SetCurrentGold(int Value) { - CurrentGold = value; + CurrentGold = Value; OnGoldGained.Broadcast(CurrentGold); } diff --git a/Source/vampires/GoldComponent.h b/Source/vampires/GoldComponent.h index 026dd3c..85687b5 100644 --- a/Source/vampires/GoldComponent.h +++ b/Source/vampires/GoldComponent.h @@ -16,7 +16,7 @@ class VAMPIRES_API UGoldComponent : public UActorComponent public: FOnGoldGainedDelegate OnGoldGained; -protected: +private: int CurrentGold = 0; public: @@ -24,10 +24,10 @@ public: UGoldComponent(); UFUNCTION() - void IncrementGold(int value); + void IncrementGold(int Value); UFUNCTION() - void SetCurrentGold(int value); + void SetCurrentGold(int Value); UFUNCTION() int GetCurrentGold(); diff --git a/Source/vampires/GoldPickup.cpp b/Source/vampires/GoldPickup.cpp index 0ac112d..fc8c630 100644 --- a/Source/vampires/GoldPickup.cpp +++ b/Source/vampires/GoldPickup.cpp @@ -16,9 +16,9 @@ void AGoldPickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) { - if (UGoldComponent* goldComponent = OtherActor->GetComponentByClass()) + if (UGoldComponent* GoldComponent = OtherActor->GetComponentByClass()) { - goldComponent->IncrementGold(PickupValue); + GoldComponent->IncrementGold(PickupValue); Super::OnInnerBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); } } diff --git a/Source/vampires/GoldPickup.h b/Source/vampires/GoldPickup.h index 1572b18..8d7daf9 100644 --- a/Source/vampires/GoldPickup.h +++ b/Source/vampires/GoldPickup.h @@ -13,12 +13,11 @@ UCLASS() class VAMPIRES_API AGoldPickup : public APickup { GENERATED_BODY() - + protected: virtual void BeginPlay() override; -public: virtual void OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, - UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, - const FHitResult& SweepResult) override; + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, + const FHitResult& SweepResult) override; }; diff --git a/Source/vampires/HealthComponent.cpp b/Source/vampires/HealthComponent.cpp index fde2871..69585a0 100644 --- a/Source/vampires/HealthComponent.cpp +++ b/Source/vampires/HealthComponent.cpp @@ -13,28 +13,28 @@ UHealthComponent::UHealthComponent() // ... } -void UHealthComponent::TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType, - AController* instigatedBy, AActor* damageCauser) +void UHealthComponent::TakeDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType, + AController* InstigatedBy, AActor* DamageCauser) { - if (damagedActor == nullptr || IsDead || !CanDamage) + if (DamagedActor == nullptr || IsDead || !CanDamage) { return; } - CurrentHealth -= damage; + CurrentHealth -= Damage; - OnDamaged.Broadcast({damagedActor, damage, damageType, instigatedBy, damageCauser}); + OnDamaged.Broadcast({DamagedActor, Damage, DamageType, InstigatedBy, DamageCauser}); if (CurrentHealth <= 0.0f) { IsDead = true; - OnDeath.Broadcast({damagedActor, damage, damageType, instigatedBy, damageCauser}); + OnDeath.Broadcast({DamagedActor, Damage, DamageType, InstigatedBy, DamageCauser}); } } -void UHealthComponent::IncrementHealth(float value) +void UHealthComponent::IncrementHealth(float Value) { - CurrentHealth += value; + CurrentHealth += Value; if (CurrentHealth > MaxHealth) { @@ -47,9 +47,9 @@ float UHealthComponent::GetMaxHealth() return MaxHealth; } -void UHealthComponent::SetMaxHealth(float value) +void UHealthComponent::SetMaxHealth(float Value) { - MaxHealth = value; + MaxHealth = Value; } float UHealthComponent::GetCurrentHealth() @@ -57,9 +57,9 @@ float UHealthComponent::GetCurrentHealth() return CurrentHealth; } -void UHealthComponent::SetCurrentHealth(float value) +void UHealthComponent::SetCurrentHealth(float Value) { - CurrentHealth = value; + CurrentHealth = Value; if (CurrentHealth > MaxHealth) { @@ -84,9 +84,9 @@ bool UHealthComponent::GetIsDead() return IsDead; } -void UHealthComponent::SetIsDead(bool isDead) +void UHealthComponent::SetIsDead(bool bIsDead) { - IsDead = isDead; + IsDead = bIsDead; } bool UHealthComponent::GetCanDamage() @@ -94,9 +94,9 @@ bool UHealthComponent::GetCanDamage() return CanDamage; } -void UHealthComponent::SetCanDamage(bool canDamage) +void UHealthComponent::SetCanDamage(bool bCanDamage) { - CanDamage = canDamage; + CanDamage = bCanDamage; } diff --git a/Source/vampires/HealthComponent.h b/Source/vampires/HealthComponent.h index ffff6f5..a2b4f95 100644 --- a/Source/vampires/HealthComponent.h +++ b/Source/vampires/HealthComponent.h @@ -56,44 +56,44 @@ public: UHealthComponent(); UFUNCTION() - virtual void TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType, - AController* instigatedBy, - AActor* damageCauser); + virtual void TakeDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType, + AController* InstigatedBy, + AActor* DamageCauser); UFUNCTION() float GetMaxHealth(); UFUNCTION() - void SetMaxHealth(float value); + void SetMaxHealth(float Value); UFUNCTION() float GetCurrentHealth(); UFUNCTION() - void SetCurrentHealth(float value); + void SetCurrentHealth(float Value); UFUNCTION() void ResetHealth(); UFUNCTION() - void RecoverHealth(float healing); + void RecoverHealth(float Healing); UFUNCTION() bool GetIsDead(); UFUNCTION() - void SetIsDead(bool isDead); + void SetIsDead(bool bIsDead); UFUNCTION() bool GetCanDamage(); UFUNCTION() - void SetCanDamage(bool canDamage); + void SetCanDamage(bool bCanDamage); protected: // Called when the game starts virtual void BeginPlay() override; UFUNCTION() - void IncrementHealth(float value); + void IncrementHealth(float Value); }; diff --git a/Source/vampires/ObjectPoolManager.cpp b/Source/vampires/ObjectPoolManager.cpp index 07bd8a1..1cbbc34 100644 --- a/Source/vampires/ObjectPoolManager.cpp +++ b/Source/vampires/ObjectPoolManager.cpp @@ -10,44 +10,45 @@ void AObjectPoolManager::BeginPlay() Super::BeginPlay(); } -void AObjectPoolManager::InitializeObjectPool(TSubclassOf Object, const int InitialObjectPoolSize) +void AObjectPoolManager::InitializeObjectPool(const TSubclassOf& TemplateObject, const int InitialObjectPoolSize) { - ObjectTemplate = Object; + ObjectTemplate = TemplateObject; for (int i = 0; i < InitialObjectPoolSize; i++) { - if (AActor* object = GetWorld()->SpawnActor(Object, FVector(100000.0f, 100000.0f, 0), FRotator(0, 0, 0))) + if (AActor* Object = GetWorld()->SpawnActor< + AActor>(TemplateObject, FVector(100000.0f, 100000.0f, 0), FRotator(0, 0, 0))) { - SetObjectStatus(false, object); - ObjectPool.Add(object); + SetObjectStatus(false, Object); + ObjectPool.Add(Object); } } } -void AObjectPoolManager::InitializeObjectPool(UClass* Object, int InitialObjectPoolSize) +void AObjectPoolManager::InitializeObjectPool(UClass* TemplateObject, int InitialObjectPoolSize) { for (int i = 0; i < InitialObjectPoolSize; i++) { - if (AActor* object = GetWorld()->SpawnActor(Object)) + if (AActor* Object = GetWorld()->SpawnActor(TemplateObject)) { - SetObjectStatus(false, object); - ObjectPool.Add(object); + SetObjectStatus(false, Object); + ObjectPool.Add(Object); } } } -AActor* AObjectPoolManager::GetObject(int startingOffset) +AActor* AObjectPoolManager::GetObject(int StartingOffset) { int ObjectPoolSize = ObjectPool.Num(); - for (int i = startingOffset; i < ObjectPoolSize; i++) + for (int i = StartingOffset; i < ObjectPoolSize; i++) { if (ObjectPool[i]->IsHidden()) { SetObjectStatus(true, ObjectPool[i]); - if (UObjectPoolComponent* objectPoolComponent = ObjectPool[i]->GetComponentByClass()) + if (UObjectPoolComponent* ObjectPoolComponent = ObjectPool[i]->GetComponentByClass()) { - objectPoolComponent->OnRetrieve.ExecuteIfBound(); + ObjectPoolComponent->OnRetrieve.ExecuteIfBound(); } return ObjectPool[i]; @@ -59,19 +60,19 @@ AActor* AObjectPoolManager::GetObject(int startingOffset) return GetObject(ObjectPoolSize); } -void AObjectPoolManager::ReturnObject(AActor* object) +void AObjectPoolManager::ReturnObject(AActor* Object) { - SetObjectStatus(false, object); + SetObjectStatus(false, Object); - if (UObjectPoolComponent* objectPoolComponent = object->GetComponentByClass()) + if (UObjectPoolComponent* ObjectPoolComponent = Object->GetComponentByClass()) { - objectPoolComponent->OnReturn.ExecuteIfBound(); + ObjectPoolComponent->OnReturn.ExecuteIfBound(); } } -void AObjectPoolManager::SetObjectStatus(bool enabled, AActor* object) +void AObjectPoolManager::SetObjectStatus(bool bEnabled, AActor* Object) { - object->SetActorHiddenInGame(!enabled); - object->SetActorTickEnabled(enabled); - object->SetActorEnableCollision(enabled); + Object->SetActorHiddenInGame(!bEnabled); + Object->SetActorTickEnabled(bEnabled); + Object->SetActorEnableCollision(bEnabled); } diff --git a/Source/vampires/ObjectPoolManager.h b/Source/vampires/ObjectPoolManager.h index adcf83b..ca2ba18 100644 --- a/Source/vampires/ObjectPoolManager.h +++ b/Source/vampires/ObjectPoolManager.h @@ -13,19 +13,19 @@ class VAMPIRES_API AObjectPoolManager : public AActor TArray> ObjectPool = TArray>(); TSubclassOf ObjectTemplate; - + public: - void InitializeObjectPool(TSubclassOf Object, int InitialObjectPoolSize = 400); - void InitializeObjectPool(UClass* Object, int InitialObjectPoolSize = 400); + void InitializeObjectPool(const TSubclassOf& TemplateObject, int InitialObjectPoolSize = 400); + void InitializeObjectPool(UClass* TemplateObject, int InitialObjectPoolSize = 400); - AActor* GetObject(int startingOffset = 0); + AActor* GetObject(int StartingOffset = 0); - void ReturnObject(AActor* object); + void ReturnObject(AActor* Object); protected: // Called when the game starts or when spawned virtual void BeginPlay() override; private: - void SetObjectStatus(bool enabled, AActor* object); + void SetObjectStatus(bool bEnabled, AActor* Object); }; diff --git a/Source/vampires/Pickup.cpp b/Source/vampires/Pickup.cpp index b44d83f..432b0b5 100644 --- a/Source/vampires/Pickup.cpp +++ b/Source/vampires/Pickup.cpp @@ -42,8 +42,8 @@ APickup::APickup() TimelineComponent->SetTimelineLengthMode(TL_TimelineLength); TimelineComponent->SetPlaybackPosition(0.0f, false); - onTimelineCallback.BindUFunction(this, FName(TEXT("TimelineCallback"))); - onTimelineFinishedCallback.BindUFunction(this, FName(TEXT("TimelineFinishedCallback"))); + OnTimelineCallback.BindUFunction(this, FName(TEXT("TimelineCallback"))); + OnTimelineFinishedCallback.BindUFunction(this, FName(TEXT("TimelineFinishedCallback"))); NiagaraComponent = CreateDefaultSubobject(TEXT("Niagara Component")); NiagaraComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform); @@ -60,8 +60,8 @@ void APickup::BeginPlay() if (CurveFloat != nullptr) { - TimelineComponent->AddInterpFloat(CurveFloat, onTimelineCallback); - TimelineComponent->SetTimelineFinishedFunc(onTimelineFinishedCallback); + TimelineComponent->AddInterpFloat(CurveFloat, OnTimelineCallback); + TimelineComponent->SetTimelineFinishedFunc(OnTimelineFinishedCallback); } } @@ -74,11 +74,11 @@ void APickup::LoadDataFromDataAsset_Implementation(UPickupDataAsset* PickupDataA PickupSoundBase = PickupDataAsset->PickupSoundBase; CurveFloat = PickupDataAsset->CurveFloat; PickupLocation = Location; - + if (CurveFloat != nullptr) { - TimelineComponent->AddInterpFloat(CurveFloat, onTimelineCallback); - TimelineComponent->SetTimelineFinishedFunc(onTimelineFinishedCallback); + TimelineComponent->AddInterpFloat(CurveFloat, OnTimelineCallback); + TimelineComponent->SetTimelineFinishedFunc(OnTimelineFinishedCallback); } } } @@ -110,14 +110,14 @@ void APickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AAct UGameplayStatics::PlaySound2D(GetWorld(), PickupSoundBase); } - AGameModeBase* gamemode = UGameplayStatics::GetGameMode(GetWorld()); - if (UKismetSystemLibrary::DoesImplementInterface(gamemode, UPools::StaticClass())) + AGameModeBase* Gamemode = UGameplayStatics::GetGameMode(GetWorld()); + if (UKismetSystemLibrary::DoesImplementInterface(Gamemode, UPools::StaticClass())) { - if (AObjectPoolManager* objectPoolManager = IPools::Execute_GetProjectileObjectPoolManager(gamemode)) + if (AObjectPoolManager* ObjectPoolManager = IPools::Execute_GetProjectileObjectPoolManager(Gamemode)) { TimelineComponent->Stop(); ResetData_Implementation(); - objectPoolManager->ReturnObject(this); + ObjectPoolManager->ReturnObject(this); } } else @@ -131,18 +131,19 @@ void APickup::OnOuterBeginOverlap(UPrimitiveComponent* OverlappedComponent, AAct UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) { - if (!TimelineComponent->IsPlaying() && UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) == Cast(OtherActor)) + if (!TimelineComponent->IsPlaying() && UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) == Cast< + ACharacter>(OtherActor)) { PlayTimeLine(); - } + } } -void APickup::TimelineCallback(float val) +void APickup::TimelineCallback(float Value) { - FVector actorLocation = PickupLocation; - FVector playerLocation = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)->GetActorLocation(); - FVector location = FMath::Lerp(actorLocation, playerLocation, val); - SetActorLocation(location); + FVector ActorLocation = PickupLocation; + FVector PlayerLocation = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)->GetActorLocation(); + FVector Location = FMath::Lerp(ActorLocation, PlayerLocation, Value); + SetActorLocation(Location); } void APickup::TimelineFinishedCallback() diff --git a/Source/vampires/Pickup.h b/Source/vampires/Pickup.h index a101371..35aacbf 100644 --- a/Source/vampires/Pickup.h +++ b/Source/vampires/Pickup.h @@ -18,10 +18,10 @@ class VAMPIRES_API APickup : public AActor, public IPickupable { GENERATED_BODY() -public: +protected: UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) int PickupValue = 1; - + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) TObjectPtr InnerSphereComponent = nullptr; @@ -44,8 +44,8 @@ public: TObjectPtr NiagaraComponent = nullptr; private: - FOnTimelineFloat onTimelineCallback; - FOnTimelineEventStatic onTimelineFinishedCallback; + FOnTimelineFloat OnTimelineCallback; + FOnTimelineEventStatic OnTimelineFinishedCallback; FVector PickupLocation; @@ -56,11 +56,11 @@ public: protected: // Called when the game starts or when spawned virtual void BeginPlay() override; - + virtual void LoadDataFromDataAsset_Implementation(UPickupDataAsset* PickupDataAsset, FVector Location) override; virtual void ResetData_Implementation() override; - + UFUNCTION() virtual void OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, @@ -72,7 +72,7 @@ protected: const FHitResult& SweepResult); UFUNCTION() - void TimelineCallback(float val); + void TimelineCallback(float Value); UFUNCTION() void TimelineFinishedCallback(); diff --git a/Source/vampires/PlayerCharacter.cpp b/Source/vampires/PlayerCharacter.cpp index 512a2f4..198d129 100644 --- a/Source/vampires/PlayerCharacter.cpp +++ b/Source/vampires/PlayerCharacter.cpp @@ -37,8 +37,8 @@ APlayerCharacter::APlayerCharacter() CameraShakeTimelineComponent->SetTimelineLengthMode(TL_TimelineLength); CameraShakeTimelineComponent->SetPlaybackPosition(0.0f, false); - onTimelineCallback.BindUFunction(this, FName(TEXT("CameraShakeTimelineCallback"))); - onTimelineFinishedCallback.BindUFunction(this, FName(TEXT("CameraShakeTimelineFinishedCallback"))); + OnTimelineCallback.BindUFunction(this, FName(TEXT("CameraShakeTimelineCallback"))); + OnTimelineFinishedCallback.BindUFunction(this, FName(TEXT("CameraShakeTimelineFinishedCallback"))); } void APlayerCharacter::BeginPlay() @@ -50,8 +50,8 @@ void APlayerCharacter::BeginPlay() if (CameraShakeCurve != nullptr) { - CameraShakeTimelineComponent->AddInterpFloat(CameraShakeCurve, onTimelineCallback); - CameraShakeTimelineComponent->SetTimelineFinishedFunc(onTimelineFinishedCallback); + CameraShakeTimelineComponent->AddInterpFloat(CameraShakeCurve, OnTimelineCallback); + CameraShakeTimelineComponent->SetTimelineFinishedFunc(OnTimelineFinishedCallback); } PlayerCameraManager = GetWorld()->GetFirstPlayerController()->PlayerCameraManager; @@ -62,7 +62,7 @@ void APlayerCharacter::Tick(float DeltaTime) Super::Tick(DeltaTime); auto PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0); - + FVector TopLeft, TopLeftDir; FVector BottomRight, BottomRightDir; @@ -113,7 +113,8 @@ void APlayerCharacter::CameraShakeTimelineCallback(float val) { auto PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0); auto cameraActor = PlayerController->GetViewTarget(); - cameraActor->SetActorLocation(FVector(FMath::RandRange(0.0f, CameraShakeStrength) * val, FMath::RandRange(0.0f, CameraShakeStrength) * val, 0.0f)); + cameraActor->SetActorLocation(FVector(FMath::RandRange(0.0f, CameraShakeStrength) * val, + FMath::RandRange(0.0f, CameraShakeStrength) * val, 0.0f)); } void APlayerCharacter::CameraShakeTimelineFinishedCallback() diff --git a/Source/vampires/PlayerCharacter.h b/Source/vampires/PlayerCharacter.h index a9bf3ff..2a9d21f 100644 --- a/Source/vampires/PlayerCharacter.h +++ b/Source/vampires/PlayerCharacter.h @@ -24,7 +24,7 @@ class VAMPIRES_API APlayerCharacter : public AVampireCharacter { GENERATED_BODY() -public: +protected: UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtr EXPComponent; @@ -36,7 +36,7 @@ public: UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) TObjectPtr CameraShakeTimelineComponent = nullptr; - + UPROPERTY(EditAnywhere) TObjectPtr CameraShakeCurve; @@ -44,14 +44,13 @@ public: float CameraShakeStrength = 100.0f; private: - + UPROPERTY() TObjectPtr PlayerCameraManager = nullptr; - + APlayerCharacter(); -private: - FOnTimelineFloat onTimelineCallback; - FOnTimelineEventStatic onTimelineFinishedCallback; + FOnTimelineFloat OnTimelineCallback; + FOnTimelineEventStatic OnTimelineFinishedCallback; protected: virtual void BeginPlay() override; diff --git a/Source/vampires/Projectile.cpp b/Source/vampires/Projectile.cpp index a0562b5..7215ca9 100644 --- a/Source/vampires/Projectile.cpp +++ b/Source/vampires/Projectile.cpp @@ -60,7 +60,8 @@ void AProjectile::SetActorHiddenInGame(bool bNewHidden) } else { - GetWorldTimerManager().SetTimer(ProjectileLifetimeTimerHandle, this, &AProjectile::ReturnProjectileToPool, ProjectileLifespan, true); + GetWorldTimerManager().SetTimer(ProjectileLifetimeTimerHandle, this, &AProjectile::ReturnProjectileToPool, + ProjectileLifespan, true); } } @@ -103,14 +104,14 @@ void AProjectile::OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedCompon if (!EnemyHealthComponent->GetIsDead()) { - AController* ownerController = nullptr; - if (AVampireCharacter* character = Cast(GetOwner())) + AController* OwnerController = nullptr; + if (AVampireCharacter* Character = Cast(GetOwner())) { - ownerController = character->GetController(); + OwnerController = Character->GetController(); } - AProjectileWeapon* ownerWeapon = Cast(GetOwner()); - EnemyHealthComponent->TakeDamage(Enemy, ownerWeapon->GetDamage(), nullptr, ownerController, this); + AProjectileWeapon* OwnerWeapon = Cast(GetOwner()); + EnemyHealthComponent->TakeDamage(Enemy, OwnerWeapon->GetDamage(), nullptr, OwnerController, this); RemainingDamageableEnemies--; @@ -124,14 +125,14 @@ void AProjectile::OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedCompon void AProjectile::ReturnProjectileToPool() { - AGameModeBase* gamemode = UGameplayStatics::GetGameMode(GetWorld()); + AGameModeBase* Gamemode = UGameplayStatics::GetGameMode(GetWorld()); - if (UKismetSystemLibrary::DoesImplementInterface(gamemode, UPools::StaticClass())) + if (UKismetSystemLibrary::DoesImplementInterface(Gamemode, UPools::StaticClass())) { - if (AObjectPoolManager* objectPoolManager = - IPools::Execute_GetProjectileObjectPoolManager(gamemode)) + if (AObjectPoolManager* ObjectPoolManager = + IPools::Execute_GetProjectileObjectPoolManager(Gamemode)) { - objectPoolManager->ReturnObject(this); + ObjectPoolManager->ReturnObject(this); } } } diff --git a/Source/vampires/Projectile.h b/Source/vampires/Projectile.h index 2fc87bb..47f00cf 100644 --- a/Source/vampires/Projectile.h +++ b/Source/vampires/Projectile.h @@ -49,7 +49,6 @@ protected: // Called when the game starts or when spawned virtual void BeginPlay() override; -public: virtual void SetActorHiddenInGame(bool bNewHidden) override; virtual void SetTargetDirection_Implementation(FVector Direction) override; diff --git a/Source/vampires/VampireAIController.cpp b/Source/vampires/VampireAIController.cpp index 3cb6b2f..7263ccb 100644 --- a/Source/vampires/VampireAIController.cpp +++ b/Source/vampires/VampireAIController.cpp @@ -54,10 +54,10 @@ void AVampireAIController::OnPossess(APawn* InPawn) PlayerCharacter = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0); - if (UBehaviorTree* bt = EnemyCharacter->GetBehaviorTree()) + if (UBehaviorTree* BT = EnemyCharacter->GetBehaviorTree()) { - DefaultBlackboard->InitializeBlackboard(*bt->BlackboardAsset); - BehaviorTree->StartTree(*bt); + DefaultBlackboard->InitializeBlackboard(*BT->BlackboardAsset); + BehaviorTree->StartTree(*BT); DefaultBlackboard->SetValueAsObject("SelfActor", EnemyCharacter); if (PlayerCharacter) @@ -67,7 +67,7 @@ void AVampireAIController::OnPossess(APawn* InPawn) } } -void AVampireAIController::OnDamaged(FDamageInfo info) +void AVampireAIController::OnDamaged(FDamageInfo Info) { if (EnemyCharacter->GetHealthComponent()->GetCurrentHealth() > 0.0f) { @@ -75,22 +75,9 @@ void AVampireAIController::OnDamaged(FDamageInfo info) } } -void AVampireAIController::OnDeath(FDamageInfo info) +void AVampireAIController::OnDeath(FDamageInfo Info) { - // TODO: Do stuff here - EnemyCharacter->OnDeath(info); - /*EnemyCharacter->DetachFromControllerPendingDestroy(); - EnemyCharacter->GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); - EnemyCharacter->GetCapsuleComponent()->SetCollisionResponseToAllChannels(ECR_Ignore); - - if (UPawnMovementComponent* characterMovementComponent = EnemyCharacter->GetMovementComponent()) - { - characterMovementComponent->StopMovementImmediately(); - characterMovementComponent->StopActiveMovement(); - characterMovementComponent->SetComponentTickEnabled(false); - } - GetWorldTimerManager().ClearTimer(PawnMoveToTimerHandle); - EnemyCharacter->SetLifeSpan(0.1f);*/ + EnemyCharacter->OnDeath(Info); } void AVampireAIController::PawnMoveTo() diff --git a/Source/vampires/VampireAIController.h b/Source/vampires/VampireAIController.h index f0a0f26..f911d60 100644 --- a/Source/vampires/VampireAIController.h +++ b/Source/vampires/VampireAIController.h @@ -38,18 +38,15 @@ public: protected: virtual void BeginPlay() override; -public: virtual void Tick(float DeltaTime) override; -protected: virtual void OnPossess(APawn* InPawn) override; -public: UFUNCTION() - virtual void OnDamaged(FDamageInfo info); + virtual void OnDamaged(FDamageInfo Info); UFUNCTION() - virtual void OnDeath(FDamageInfo info); + virtual void OnDeath(FDamageInfo Info); private: UFUNCTION() diff --git a/Source/vampires/VampireCharacter.cpp b/Source/vampires/VampireCharacter.cpp index 69e69b8..5fa9a96 100644 --- a/Source/vampires/VampireCharacter.cpp +++ b/Source/vampires/VampireCharacter.cpp @@ -10,7 +10,7 @@ // Sets default values AVampireCharacter::AVampireCharacter() { - // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. + // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; // Create Health Component @@ -22,15 +22,13 @@ AVampireCharacter::AVampireCharacter() //Create Weapon Inventory Component WeaponInventoryComponent = CreateDefaultSubobject(TEXT("Weapon Inventory Component")); - GetCharacterMovement()->SetPlaneConstraintNormal({0.0f, 0.0f, 1.0f}); + GetCharacterMovement()->SetPlaneConstraintNormal({0.0f, 0.0f, 1.0f}); } // Called when the game starts or when spawned void AVampireCharacter::BeginPlay() { Super::BeginPlay(); - - } // Called every frame @@ -38,21 +36,21 @@ void AVampireCharacter::Tick(float DeltaTime) { Super::Tick(DeltaTime); - float newYaw = FMath::Atan2(PreviousMovementDirection.Y, PreviousMovementDirection.X) * 180.0f / PI; - FQuat newRotation = FQuat::Slerp(StaticMeshComponent->GetComponentRotation().Quaternion(), - FRotator(0.0f, newYaw, 0.0f).Quaternion(), + float NewYaw = FMath::Atan2(PreviousMovementDirection.Y, PreviousMovementDirection.X) * 180.0f / PI; + FQuat NewRotation = FQuat::Slerp(StaticMeshComponent->GetComponentRotation().Quaternion(), + FRotator(0.0f, NewYaw, 0.0f).Quaternion(), DeltaTime * SlerpSpeed); - StaticMeshComponent->SetRelativeRotation(newRotation); + StaticMeshComponent->SetRelativeRotation(NewRotation); } -void AVampireCharacter::Input_Move_Implementation(FVector2D value) +void AVampireCharacter::Input_Move_Implementation(FVector2D Value) { - PreviousMovementDirection = value; - - if (value.Size() != 0.0f) + PreviousMovementDirection = Value; + + if (Value.Size() != 0.0f) { - AddMovementInput({0.0f, 1.0f, 0.0f}, value.Y); - AddMovementInput({1.0f, 0.0f, 0.0f}, value.X); + AddMovementInput({0.0f, 1.0f, 0.0f}, Value.Y); + AddMovementInput({1.0f, 0.0f, 0.0f}, Value.X); } } @@ -70,4 +68,3 @@ UHealthComponent* AVampireCharacter::GetHealthComponent() { return HealthComponent; } - diff --git a/Source/vampires/VampireCharacter.h b/Source/vampires/VampireCharacter.h index c32bb26..b81e49f 100644 --- a/Source/vampires/VampireCharacter.h +++ b/Source/vampires/VampireCharacter.h @@ -27,7 +27,7 @@ public: UPROPERTY(BlueprintReadWrite, EditAnywhere) float SlerpSpeed = 10.0f; - + protected: UPROPERTY(VisibleAnywhere) TObjectPtr HealthComponent; @@ -58,15 +58,15 @@ protected: // Called when the game starts or when spawned virtual void BeginPlay() override; -public: // Called every frame virtual void Tick(float DeltaTime) override; - virtual void Input_Move_Implementation(FVector2D value) override; + virtual void Input_Move_Implementation(FVector2D Value) override; virtual UInputMappingContext* Input_GetInputMappingContext_Implementation() override; virtual FVector2D Input_GetPreviousMovementDirection_Implementation() override; +public: UHealthComponent* GetHealthComponent(); }; diff --git a/Source/vampires/VampireGameInstance.cpp b/Source/vampires/VampireGameInstance.cpp index b5ad329..6c6fbe0 100644 --- a/Source/vampires/VampireGameInstance.cpp +++ b/Source/vampires/VampireGameInstance.cpp @@ -2,4 +2,3 @@ #include "VampireGameInstance.h" - diff --git a/Source/vampires/VampireGameInstance.h b/Source/vampires/VampireGameInstance.h index 15116b9..8c6bdd8 100644 --- a/Source/vampires/VampireGameInstance.h +++ b/Source/vampires/VampireGameInstance.h @@ -1,4 +1,4 @@ - // Louis Hobbs | 2024-2025 +// Louis Hobbs | 2024-2025 #pragma once @@ -15,11 +15,11 @@ UCLASS() class VAMPIRES_API UVampireGameInstance : public UGameInstance { GENERATED_BODY() -public: +public: UPROPERTY() TSubclassOf StarterWeapon; - + UPROPERTY(EditDefaultsOnly) TSoftObjectPtr MainMenuWorld; diff --git a/Source/vampires/VampireGameMode.h b/Source/vampires/VampireGameMode.h index c0475cb..755c921 100644 --- a/Source/vampires/VampireGameMode.h +++ b/Source/vampires/VampireGameMode.h @@ -24,6 +24,9 @@ class VAMPIRES_API AVampireGameMode : public AGameMode, public IPools GENERATED_BODY() public: + FOnEnemyDeathCountIncrementDelegate OnEnemyDeathCountIncrementDelegate; + +protected: UPROPERTY(EditDefaultsOnly) TSubclassOf EnemyTemplate; @@ -33,8 +36,6 @@ public: UPROPERTY(EditDefaultsOnly) TSubclassOf PickupTemplate; - FOnEnemyDeathCountIncrementDelegate OnEnemyDeathCountIncrementDelegate; - UPROPERTY(EditDefaultsOnly) TArray> EnemyDataAssets; @@ -68,6 +69,7 @@ public: UFUNCTION(BlueprintCallable, BlueprintPure) int GetEnemyDeathCount(); +protected: UFUNCTION() void HandleOnEnemyDeath(FDamageInfo damageInfo); @@ -86,7 +88,6 @@ public: UFUNCTION(BlueprintCallable) void EndGame(); -protected: UFUNCTION() void SpawnEnemy(); }; diff --git a/Source/vampires/VampirePlayerController.cpp b/Source/vampires/VampirePlayerController.cpp index fc12551..1035862 100644 --- a/Source/vampires/VampirePlayerController.cpp +++ b/Source/vampires/VampirePlayerController.cpp @@ -23,53 +23,55 @@ void AVampirePlayerController::OnPossess(APawn* aPawn) { Super::OnPossess(aPawn); - if (UEnhancedInputLocalPlayerSubsystem* subsystem = ULocalPlayer::GetSubsystem(GetLocalPlayer())) + if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem( + GetLocalPlayer())) { if (UKismetSystemLibrary::DoesImplementInterface(aPawn, UInputable::StaticClass())) { - subsystem->AddMappingContext(IInputable::Execute_Input_GetInputMappingContext(aPawn), 0); + Subsystem->AddMappingContext(IInputable::Execute_Input_GetInputMappingContext(aPawn), 0); } } - + if (PlayerHUD) { - currentPlayerHUD = CreateWidget(this, PlayerHUD.Get()); + CurrentPlayerHUD = CreateWidget(this, PlayerHUD.Get()); - if (UEXPComponent* expComponent = aPawn->GetComponentByClass()) + if (UEXPComponent* ExpComponent = aPawn->GetComponentByClass()) { - expComponent->OnEXPGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerEXPHUD); - expComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerLevelHUD); - expComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::ShowLevelUpScreen); - UpdatePlayerEXPHUD(expComponent->GetCurrentEXP(), expComponent->GetCurrentLevelPercent()); - UpdatePlayerLevelHUD(expComponent->GetCurrentLevel()); + ExpComponent->OnEXPGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerEXPHUD); + ExpComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerLevelHUD); + ExpComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::ShowLevelUpScreen); + UpdatePlayerEXPHUD(ExpComponent->GetCurrentEXP(), ExpComponent->GetCurrentLevelPercent()); + UpdatePlayerLevelHUD(ExpComponent->GetCurrentLevel()); } - if (UGoldComponent* goldComponent = aPawn->GetComponentByClass()) + if (UGoldComponent* GoldComponent = aPawn->GetComponentByClass()) { - goldComponent->OnGoldGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdateGoldCountHUD); - UpdateGoldCountHUD(goldComponent->GetCurrentGold()); + GoldComponent->OnGoldGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdateGoldCountHUD); + UpdateGoldCountHUD(GoldComponent->GetCurrentGold()); } - if (AVampireGameMode* gamemode = Cast(UGameplayStatics::GetGameMode(GetWorld()))) + if (AVampireGameMode* Gamemode = Cast(UGameplayStatics::GetGameMode(GetWorld()))) { - gamemode->OnEnemyDeathCountIncrementDelegate.AddDynamic(this, &AVampirePlayerController::UpdateKillCountHUD); - UpdateKillCountHUD(gamemode->GetEnemyDeathCount()); + Gamemode->OnEnemyDeathCountIncrementDelegate. + AddDynamic(this, &AVampirePlayerController::UpdateKillCountHUD); + UpdateKillCountHUD(Gamemode->GetEnemyDeathCount()); } - - if (currentPlayerHUD) + + if (CurrentPlayerHUD) { - currentPlayerHUD->AddToViewport(); + CurrentPlayerHUD->AddToViewport(); } } - if (UVampireGameInstance* gameInstance = Cast(GetGameInstance())) + if (UVampireGameInstance* GameInstance = Cast(GetGameInstance())) { - UWeaponInventoryComponent* weaponInventoryComponent = aPawn->GetComponentByClass< + UWeaponInventoryComponent* WeaponInventoryComponent = aPawn->GetComponentByClass< UWeaponInventoryComponent>(); - - if (weaponInventoryComponent && gameInstance->StarterWeapon) - { - weaponInventoryComponent->initialInventory.Add(gameInstance->StarterWeapon); + + if (WeaponInventoryComponent && GameInstance->StarterWeapon) + { + WeaponInventoryComponent->InitialInventory.Add(GameInstance->StarterWeapon); } } } @@ -78,7 +80,7 @@ void AVampirePlayerController::OnUnPossess() { Super::OnUnPossess(); - GetWorld()->GetTimerManager().ClearTimer(pawnLifeTimeHandle); + GetWorld()->GetTimerManager().ClearTimer(PawnLifeTimeHandle); } void AVampirePlayerController::SetupInputComponent() @@ -94,13 +96,13 @@ void AVampirePlayerController::SetupInputComponent() void AVampirePlayerController::Move(const FInputActionValue& MovementInput) { - FVector2D movement = MovementInput.Get(); + FVector2D Movement = MovementInput.Get(); if (APawn* pawn = GetPawn()) { if (UKismetSystemLibrary::DoesImplementInterface(pawn, UInputable::StaticClass())) { - IInputable::Execute_Input_Move(pawn, movement); + IInputable::Execute_Input_Move(pawn, Movement); } } } @@ -114,95 +116,96 @@ void AVampirePlayerController::OnPause(const FInputActionValue& PauseInput) IInputable::Execute_Input_Pause(pawn); } } - + if (PauseUI) { if (SetPause(true)) { - currentPauseUI = CreateWidget(this, PauseUI.Get()); - if (currentPauseUI) + CurrentPauseUI = CreateWidget(this, PauseUI.Get()); + if (CurrentPauseUI) { - currentPauseUI->AddToViewport(); - UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, currentPauseUI, EMouseLockMode::LockInFullscreen); + CurrentPauseUI->AddToViewport(); + UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, CurrentPauseUI, EMouseLockMode::LockInFullscreen); bShowMouseCursor = true; } - } + } } } -void AVampirePlayerController::UpdatePlayerEXPHUD(int exp, float currentLevelPercent) +void AVampirePlayerController::UpdatePlayerEXPHUD(int Exp, float CurrentLevelPercent) { - if (currentPlayerHUD) + if (CurrentPlayerHUD) { - currentPlayerHUD->UpdateEXPBar(currentLevelPercent); + CurrentPlayerHUD->UpdateEXPBar(CurrentLevelPercent); } } -void AVampirePlayerController::ShowLevelUpScreen(int level) +void AVampirePlayerController::ShowLevelUpScreen(int Level) { APawn* pawn = GetPawn(); if (!pawn) { return; } - - UEXPComponent* expComponent = pawn->GetComponentByClass(); - if (!expComponent || expComponent->GetCurrentLevel() == 0) + + UEXPComponent* ExpComponent = pawn->GetComponentByClass(); + if (!ExpComponent || ExpComponent->GetCurrentLevel() == 0) { return; } - + if (LevelUpUI) { if (SetPause(true)) { - currentLevelUpUI = CreateWidget(this, LevelUpUI.Get()); - if (currentLevelUpUI) + CurrentLevelUpUI = CreateWidget(this, LevelUpUI.Get()); + if (CurrentLevelUpUI) { - currentLevelUpUI->AddToViewport(); - UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, currentLevelUpUI, EMouseLockMode::LockInFullscreen); + CurrentLevelUpUI->AddToViewport(); + UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, CurrentLevelUpUI, + EMouseLockMode::LockInFullscreen); bShowMouseCursor = true; } - } + } } } -void AVampirePlayerController::UpdatePlayerLevelHUD(int level) +void AVampirePlayerController::UpdatePlayerLevelHUD(int Level) { - if (currentPlayerHUD) + if (CurrentPlayerHUD) { - currentPlayerHUD->UpdateLevelBlock(level); + CurrentPlayerHUD->UpdateLevelBlock(Level); } } -void AVampirePlayerController::UpdateTimerHUD(float deltaTime) +void AVampirePlayerController::UpdateTimerHUD(float DeltaTime) { - if (currentPlayerHUD) + if (CurrentPlayerHUD) { - currentPlayerHUD->UpdateTimerBlock(deltaTime); + CurrentPlayerHUD->UpdateTimerBlock(DeltaTime); } } -void AVampirePlayerController::UpdateKillCountHUD(int killCount) +void AVampirePlayerController::UpdateKillCountHUD(int KillCount) { - if (currentPlayerHUD) + if (CurrentPlayerHUD) { - currentPlayerHUD->UpdateKillBlock(killCount); + CurrentPlayerHUD->UpdateKillBlock(KillCount); } } -void AVampirePlayerController::UpdateGoldCountHUD(int goldCount) +void AVampirePlayerController::UpdateGoldCountHUD(int GoldCount) { - if (currentPlayerHUD) + if (CurrentPlayerHUD) { - currentPlayerHUD->UpdateGoldBlock(goldCount); + CurrentPlayerHUD->UpdateGoldBlock(GoldCount); } } -void AVampirePlayerController::UpdateTimerHUDElement_Implementation(float deltaTime) +void AVampirePlayerController::UpdateTimerHUDElement_Implementation(float DeltaTime) { - if (currentPlayerHUD) + if (CurrentPlayerHUD) { - currentPlayerHUD->UpdateTimerBlock(deltaTime); + CurrentPlayerHUD->UpdateTimerBlock(DeltaTime); } } diff --git a/Source/vampires/VampirePlayerController.h b/Source/vampires/VampirePlayerController.h index e3e0bb2..5a934b4 100644 --- a/Source/vampires/VampirePlayerController.h +++ b/Source/vampires/VampirePlayerController.h @@ -41,15 +41,15 @@ public: private: UPROPERTY() - TObjectPtr currentPlayerHUD = nullptr; + TObjectPtr CurrentPlayerHUD = nullptr; UPROPERTY() - TObjectPtr currentPauseUI = nullptr; + TObjectPtr CurrentPauseUI = nullptr; UPROPERTY() - TObjectPtr currentLevelUpUI = nullptr; + TObjectPtr CurrentLevelUpUI = nullptr; - FTimerHandle pawnLifeTimeHandle; + FTimerHandle PawnLifeTimeHandle; protected: virtual void OnPossess(APawn* aPawn) override; @@ -65,22 +65,22 @@ protected: void OnPause(const FInputActionValue& PauseInput); UFUNCTION() - void UpdatePlayerEXPHUD(int exp, float currentLevelPercent); + void UpdatePlayerEXPHUD(int Exp, float CurrentLevelPercent); UFUNCTION() - void ShowLevelUpScreen(int level); + void ShowLevelUpScreen(int Level); UFUNCTION() - void UpdatePlayerLevelHUD(int level); + void UpdatePlayerLevelHUD(int Level); UFUNCTION(BlueprintCallable) - void UpdateTimerHUD(float deltaTime); + void UpdateTimerHUD(float DeltaTime); UFUNCTION() - void UpdateKillCountHUD(int killCount); + void UpdateKillCountHUD(int KillCount); UFUNCTION() - void UpdateGoldCountHUD(int goldCount); + void UpdateGoldCountHUD(int GoldCount); - virtual void UpdateTimerHUDElement_Implementation(float deltaTime) override; + virtual void UpdateTimerHUDElement_Implementation(float DeltaTime) override; }; diff --git a/Source/vampires/Weapon.h b/Source/vampires/Weapon.h index 0781535..c6702b2 100644 --- a/Source/vampires/Weapon.h +++ b/Source/vampires/Weapon.h @@ -54,10 +54,11 @@ protected: private: FTimerHandle WeaponTimerHandle; -public: +protected: // Sets default values for this actor's AWeapon(); +public: UFUNCTION(BlueprintNativeEvent) bool UpgradeWeapon(); virtual bool UpgradeWeapon_Implementation(); diff --git a/Source/vampires/WeaponInventoryComponent.cpp b/Source/vampires/WeaponInventoryComponent.cpp index 2409dad..556901d 100644 --- a/Source/vampires/WeaponInventoryComponent.cpp +++ b/Source/vampires/WeaponInventoryComponent.cpp @@ -25,37 +25,37 @@ void UWeaponInventoryComponent::BeginPlay() void UWeaponInventoryComponent::InitializeInventory() { - inventory.Empty(); + Inventory.Empty(); - for (TSubclassOf weapon : initialInventory) + for (TSubclassOf Weapon : InitialInventory) { - if (IsValid(weapon)) + if (IsValid(Weapon)) { - AddWeaponToInventory(weapon); + AddWeaponToInventory(Weapon); } } } -void UWeaponInventoryComponent::AddWeaponToInventory(TSubclassOf Weapon) +void UWeaponInventoryComponent::AddWeaponToInventory(TSubclassOf NewWeapon) { FActorSpawnParameters SpawnParameters; SpawnParameters.Owner = GetOwner(); - - AWeapon* weapon = GetWorld()->SpawnActor(Weapon, SpawnParameters.Owner->GetTransform(), SpawnParameters); - if (weapon->GetFollowPlayer()) + + AWeapon* Weapon = GetWorld()->SpawnActor(NewWeapon, SpawnParameters.Owner->GetTransform(), SpawnParameters); + if (Weapon->GetFollowPlayer()) { - weapon->AttachToActor(GetOwner(), FAttachmentTransformRules::KeepWorldTransform); + Weapon->AttachToActor(GetOwner(), FAttachmentTransformRules::KeepWorldTransform); } else { - weapon->SetActorLocation(FVector::ZeroVector); + Weapon->SetActorLocation(FVector::ZeroVector); } - - inventory.Add(weapon); - obtainableWeapons.Remove(Weapon); + + Inventory.Add(Weapon); + ObtainableWeapons.Remove(NewWeapon); } TArray UWeaponInventoryComponent::GetInventory() { - return inventory; + return Inventory; } diff --git a/Source/vampires/WeaponInventoryComponent.h b/Source/vampires/WeaponInventoryComponent.h index 3c9d460..cae69e2 100644 --- a/Source/vampires/WeaponInventoryComponent.h +++ b/Source/vampires/WeaponInventoryComponent.h @@ -15,16 +15,15 @@ class VAMPIRES_API UWeaponInventoryComponent : public UActorComponent GENERATED_BODY() public: + UPROPERTY(EditAnywhere, BlueprintReadWrite) + TArray> ObtainableWeapons; UPROPERTY(EditAnywhere, BlueprintReadWrite) - TArray> obtainableWeapons; - - UPROPERTY(EditAnywhere, BlueprintReadWrite) - TArray> initialInventory; + TArray> InitialInventory; private: UPROPERTY() - TArray> inventory; + TArray> Inventory; public: // Sets default values for this component's properties @@ -39,7 +38,7 @@ public: void InitializeInventory(); UFUNCTION() - void AddWeaponToInventory(TSubclassOf Weapon); + void AddWeaponToInventory(TSubclassOf NewWeapon); UFUNCTION() TArray GetInventory(); diff --git a/Source/vampires/Widgets/LevelUpWidget.cpp b/Source/vampires/Widgets/LevelUpWidget.cpp index b0d239e..201635a 100644 --- a/Source/vampires/Widgets/LevelUpWidget.cpp +++ b/Source/vampires/Widgets/LevelUpWidget.cpp @@ -52,7 +52,7 @@ void ULevelUpWidget::NativeConstruct() } // Get list of weapons that the player can still obtain - TArray> ObtainableWeapons = InventoryComponent->obtainableWeapons; + TArray> ObtainableWeapons = InventoryComponent->ObtainableWeapons; for (TSubclassOf Weapon : ObtainableWeapons) { UUpgradeButtonDataObject* Temp = NewObject(this); diff --git a/Source/vampires/Widgets/UpgradeButtonWidget.cpp b/Source/vampires/Widgets/UpgradeButtonWidget.cpp index 9bfa62e..21ebbd9 100644 --- a/Source/vampires/Widgets/UpgradeButtonWidget.cpp +++ b/Source/vampires/Widgets/UpgradeButtonWidget.cpp @@ -93,7 +93,7 @@ void UUpgradeButtonWidget::OnClicked() if (UWeaponInventoryComponent* Inventory = PlayerController->GetPawn()->GetComponentByClass()) { Inventory->AddWeaponToInventory(WeaponTemplate); - Inventory->obtainableWeapons.Remove(WeaponTemplate); + Inventory->ObtainableWeapons.Remove(WeaponTemplate); } break;