Compare commits
5 Commits
eb4ce4cb79
...
1a3516c263
Author | SHA1 | Date | |
---|---|---|---|
1a3516c263 | |||
cb0230d24f | |||
c1e4387adb | |||
ec818cfc55 | |||
8d8da3ddc1 |
@ -15,12 +15,10 @@ UEXPComponent::UEXPComponent()
|
||||
// ...
|
||||
}
|
||||
|
||||
void UEXPComponent::IncrementEXP(int value)
|
||||
void UEXPComponent::IncrementEXP(int Value)
|
||||
{
|
||||
int oldEXP = CurrentEXP;
|
||||
int oldLevel = CurrentLevel;
|
||||
|
||||
CurrentEXP += value;
|
||||
int OldLevel = CurrentLevel;
|
||||
CurrentEXP += Value;
|
||||
|
||||
if (NextLevelRow.Level >= 0)
|
||||
{
|
||||
@ -28,9 +26,10 @@ void UEXPComponent::IncrementEXP(int value)
|
||||
{
|
||||
CurrentLevel = NextLevelRow.Level;
|
||||
|
||||
if (FExpTableRow* newRow = LevelsTable->FindRow<FExpTableRow>(FName(*FString::FromInt(NextLevelRow.Level + 1)),"", true))
|
||||
if (FExpTableRow* NewRow = LevelsTable->FindRow<FExpTableRow>(
|
||||
FName(*FString::FromInt(NextLevelRow.Level + 1)), "", true))
|
||||
{
|
||||
NextLevelRow = *newRow;
|
||||
NextLevelRow = *NewRow;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -47,7 +46,7 @@ void UEXPComponent::IncrementEXP(int value)
|
||||
{
|
||||
CurrentLevel = FMath::Floor(CurrentEXP / 100.0f);
|
||||
|
||||
if (CurrentLevel != oldLevel)
|
||||
if (CurrentLevel != OldLevel)
|
||||
{
|
||||
OnEXPLevelUp.Broadcast(CurrentLevel);
|
||||
}
|
||||
@ -56,20 +55,19 @@ void UEXPComponent::IncrementEXP(int value)
|
||||
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
|
||||
}
|
||||
|
||||
void UEXPComponent::SetCurrentEXP(int value)
|
||||
void UEXPComponent::SetCurrentEXP(int Value)
|
||||
{
|
||||
int oldEXP = CurrentEXP;
|
||||
int oldLevel = CurrentLevel;
|
||||
|
||||
CurrentEXP = value;
|
||||
|
||||
int OldLevel = CurrentLevel;
|
||||
CurrentEXP = Value;
|
||||
NextLevelRow = FExpTableRow();
|
||||
|
||||
while (CurrentEXP < NextLevelRow.CumulativeExpForPreviousLevel && CurrentEXP < NextLevelRow.CumulativeExpForNextLevel)
|
||||
while (CurrentEXP < NextLevelRow.CumulativeExpForPreviousLevel && CurrentEXP < NextLevelRow.
|
||||
CumulativeExpForNextLevel)
|
||||
{
|
||||
if (FExpTableRow* newRow = LevelsTable->FindRow<FExpTableRow>(FName(*FString::FromInt(NextLevelRow.Level + 1)),"", true))
|
||||
if (FExpTableRow* NewRow = LevelsTable->FindRow<FExpTableRow>(FName(*FString::FromInt(NextLevelRow.Level + 1)),
|
||||
"", true))
|
||||
{
|
||||
NextLevelRow = *newRow;
|
||||
NextLevelRow = *NewRow;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -82,7 +80,7 @@ void UEXPComponent::SetCurrentEXP(int value)
|
||||
|
||||
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
|
||||
|
||||
if (CurrentLevel != oldLevel)
|
||||
if (CurrentLevel != OldLevel)
|
||||
{
|
||||
OnEXPLevelUp.Broadcast(CurrentLevel);
|
||||
}
|
||||
@ -102,9 +100,9 @@ void UEXPComponent::Reset()
|
||||
{
|
||||
if (LevelsTable)
|
||||
{
|
||||
if (FExpTableRow* newRow = LevelsTable->FindRow<FExpTableRow>(FName("1"), "", true))
|
||||
if (FExpTableRow* NewRow = LevelsTable->FindRow<FExpTableRow>(FName("1"), "", true))
|
||||
{
|
||||
NextLevelRow = *newRow;
|
||||
NextLevelRow = *NewRow;
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,15 +114,16 @@ void UEXPComponent::Reset()
|
||||
|
||||
float UEXPComponent::GetCurrentLevelPercent()
|
||||
{
|
||||
int adjustedCurrentExp = CurrentEXP - NextLevelRow.CumulativeExpForPreviousLevel;
|
||||
float res = static_cast<float>(adjustedCurrentExp) / static_cast<float>(NextLevelRow.ExpRequiredForNextLevel);
|
||||
int AdjustedCurrentExp = CurrentEXP - NextLevelRow.CumulativeExpForPreviousLevel;
|
||||
float CurrentLevelPercent = static_cast<float>(AdjustedCurrentExp) / static_cast<float>(NextLevelRow.
|
||||
ExpRequiredForNextLevel);
|
||||
|
||||
if (FMath::IsNaN(res))
|
||||
if (FMath::IsNaN(CurrentLevelPercent))
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
return res;
|
||||
return CurrentLevelPercent;
|
||||
}
|
||||
|
||||
// Called when the game starts
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "EXPComponent.generated.h"
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnEXPGainedDelegate, int, exp, float, currentLevelPercent);
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEXPLevelUpDelegate, int, level);
|
||||
|
||||
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
||||
@ -16,16 +17,16 @@ class VAMPIRES_API UEXPComponent : public UActorComponent
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(BlueprintAssignable, Category="EXP")
|
||||
FOnEXPGainedDelegate OnEXPGained;
|
||||
|
||||
UPROPERTY(BlueprintAssignable, Category="EXP")
|
||||
FOnEXPLevelUpDelegate OnEXPLevelUp;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Category="EXP")
|
||||
TObjectPtr<UDataTable> LevelsTable;
|
||||
|
||||
protected:
|
||||
private:
|
||||
int CurrentEXP = 0;
|
||||
|
||||
int CurrentLevel = 0;
|
||||
@ -37,10 +38,10 @@ public:
|
||||
UEXPComponent();
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void IncrementEXP(int value);
|
||||
void IncrementEXP(int Value);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void SetCurrentEXP(int value);
|
||||
void SetCurrentEXP(int Value);
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure)
|
||||
int GetCurrentEXP();
|
||||
@ -57,8 +58,4 @@ public:
|
||||
protected:
|
||||
// Called when the game starts
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
private:
|
||||
|
||||
void ProcessExp(int oldEXP, int oldLevel, int newEXP);
|
||||
};
|
||||
|
@ -13,9 +13,9 @@ void AEXPPickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, A
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||
const FHitResult& SweepResult)
|
||||
{
|
||||
if (UEXPComponent* expComponent = OtherActor->GetComponentByClass<UEXPComponent>())
|
||||
if (UEXPComponent* ExpComponent = OtherActor->GetComponentByClass<UEXPComponent>())
|
||||
{
|
||||
expComponent->IncrementEXP(PickupValue);
|
||||
ExpComponent->IncrementEXP(PickupValue);
|
||||
Super::OnInnerBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -47,12 +47,12 @@ UBehaviorTree* AEnemyCharacter::GetBehaviorTree()
|
||||
return BehaviorTree;
|
||||
}
|
||||
|
||||
void AEnemyCharacter::OnDamaged(FDamageInfo damageInfo)
|
||||
void AEnemyCharacter::OnDamaged(FDamageInfo DamageInfo)
|
||||
{
|
||||
// if (OnDamagedSound)
|
||||
// {
|
||||
if (OnDamagedSound)
|
||||
{
|
||||
UGameplayStatics::PlaySoundAtLocation(GetWorld(), OnDamagedSound, GetActorLocation());
|
||||
// }
|
||||
}
|
||||
|
||||
if (OnDamagedNiagaraSystem)
|
||||
{
|
||||
@ -60,22 +60,22 @@ void AEnemyCharacter::OnDamaged(FDamageInfo damageInfo)
|
||||
}
|
||||
}
|
||||
|
||||
void AEnemyCharacter::OnDeath(FDamageInfo damageInfo)
|
||||
void AEnemyCharacter::OnDeath(FDamageInfo DamageInfo)
|
||||
{
|
||||
if (PickupTemplate)
|
||||
{
|
||||
AGameModeBase* gamemode = UGameplayStatics::GetGameMode(GetWorld());
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(gamemode, UPools::StaticClass()))
|
||||
AGameModeBase* Gamemode = UGameplayStatics::GetGameMode(GetWorld());
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(Gamemode, UPools::StaticClass()))
|
||||
{
|
||||
if (AObjectPoolManager* objectPoolManager = IPools::Execute_GetPickupObjectPoolManager(gamemode))
|
||||
if (AObjectPoolManager* ObjectPoolManager = IPools::Execute_GetPickupObjectPoolManager(Gamemode))
|
||||
{
|
||||
AActor* pickup = objectPoolManager->GetObject();
|
||||
AActor* Pickup = ObjectPoolManager->GetObject();
|
||||
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(pickup, UPickupable::StaticClass()))
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(Pickup, UPickupable::StaticClass()))
|
||||
{
|
||||
FVector pickupLocation = GetActorLocation();
|
||||
pickup->SetActorLocation(pickupLocation);
|
||||
IPickupable::Execute_LoadDataFromDataAsset(pickup, PickupTemplate, pickupLocation);
|
||||
FVector PickupLocation = GetActorLocation();
|
||||
Pickup->SetActorLocation(PickupLocation);
|
||||
IPickupable::Execute_LoadDataFromDataAsset(Pickup, PickupTemplate, PickupLocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -92,17 +92,17 @@ void AEnemyCharacter::OnDeath(FDamageInfo damageInfo)
|
||||
}
|
||||
}
|
||||
|
||||
void AEnemyCharacter::LoadDataFromDataAsset_Implementation(UEnemyDataAsset* enemyDataAsset)
|
||||
void AEnemyCharacter::LoadDataFromDataAsset_Implementation(UEnemyDataAsset* EnemyDataAsset)
|
||||
{
|
||||
if (enemyDataAsset != nullptr)
|
||||
if (EnemyDataAsset != nullptr)
|
||||
{
|
||||
StaticMeshComponent->SetStaticMesh(enemyDataAsset->StaticMesh);
|
||||
BehaviorTree = enemyDataAsset->BehaviorTree;
|
||||
PickupTemplate = enemyDataAsset->PickupDataAsset;
|
||||
OnDamagedSound = enemyDataAsset->OnDamagedSoundBase;
|
||||
OnDeathSound = enemyDataAsset->OnDeathSoundBase;
|
||||
OnDamagedNiagaraSystem = enemyDataAsset->OnDamagedNiagaraSystem;
|
||||
OnDeathNiagaraSystem = enemyDataAsset->OnDeathNiagaraSystem;
|
||||
StaticMeshComponent->SetStaticMesh(EnemyDataAsset->StaticMesh);
|
||||
BehaviorTree = EnemyDataAsset->BehaviorTree;
|
||||
PickupTemplate = EnemyDataAsset->PickupDataAsset;
|
||||
OnDamagedSound = EnemyDataAsset->OnDamagedSoundBase;
|
||||
OnDeathSound = EnemyDataAsset->OnDeathSoundBase;
|
||||
OnDamagedNiagaraSystem = EnemyDataAsset->OnDamagedNiagaraSystem;
|
||||
OnDeathNiagaraSystem = EnemyDataAsset->OnDeathNiagaraSystem;
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,10 +129,10 @@ void AEnemyCharacter::SpawnController_Implementation()
|
||||
SpawnDefaultController();
|
||||
}
|
||||
|
||||
if (BehaviorTree != nullptr)
|
||||
if (AVampireAIController* VampireAIController = Cast<AVampireAIController>(Controller); VampireAIController &&
|
||||
BehaviorTree)
|
||||
{
|
||||
AVampireAIController* controller = Cast<AVampireAIController>(Controller);
|
||||
controller->RunBehaviorTree(BehaviorTree);
|
||||
VampireAIController->RunBehaviorTree(BehaviorTree);
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,9 +142,11 @@ UHealthComponent* AEnemyCharacter::GetEnemyHealthComponent_Implementation()
|
||||
}
|
||||
|
||||
void AEnemyCharacter::OnDamageBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||
const FHitResult& SweepResult)
|
||||
{
|
||||
if (Cast<ACharacter>(OtherActor) == UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) && !Player.Contains(OtherActor))
|
||||
if (Cast<ACharacter>(OtherActor) == UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) && !Player.
|
||||
Contains(OtherActor))
|
||||
{
|
||||
Player.Add(OtherActor);
|
||||
|
||||
@ -153,9 +155,10 @@ void AEnemyCharacter::OnDamageBeginOverlap(UPrimitiveComponent* OverlappedCompon
|
||||
}
|
||||
|
||||
void AEnemyCharacter::OnDamageEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
|
||||
{
|
||||
if (Cast<ACharacter>(OtherActor) == UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) && Player.Contains(OtherActor))
|
||||
if (Cast<ACharacter>(OtherActor) == UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) && Player.
|
||||
Contains(OtherActor))
|
||||
{
|
||||
Player.Remove(OtherActor);
|
||||
|
||||
@ -170,8 +173,8 @@ void AEnemyCharacter::ResetHealth()
|
||||
|
||||
void AEnemyCharacter::DamagePlayer()
|
||||
{
|
||||
for (auto player : Player)
|
||||
for (auto DamagedPlayer : Player)
|
||||
{
|
||||
UGameplayStatics::ApplyDamage(player, Damage, GetController(), this, nullptr);
|
||||
UGameplayStatics::ApplyDamage(DamagedPlayer, Damage, GetController(), this, nullptr);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "Interfaces/Enemyable.h"
|
||||
#include "EnemyCharacter.generated.h"
|
||||
|
||||
struct FDamageInfo;
|
||||
class USphereComponent;
|
||||
class UObjectPoolComponent;
|
||||
class UBehaviorTree;
|
||||
@ -20,7 +21,7 @@ class VAMPIRES_API AEnemyCharacter : public AVampireCharacter, public IEnemyable
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TSubclassOf<AEXPPickup> EXPPickupTemplate = nullptr;
|
||||
|
||||
@ -28,7 +29,7 @@ public:
|
||||
TObjectPtr<USphereComponent> DamageSphere = nullptr;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
float Damage = 5.0f;;
|
||||
float Damage = 5.0f;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
float AttackCooldown = 1.0f;
|
||||
@ -53,19 +54,20 @@ public:
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
public:
|
||||
UBehaviorTree* GetBehaviorTree();
|
||||
|
||||
UFUNCTION()
|
||||
virtual void OnDamaged(FDamageInfo damageInfo);
|
||||
virtual void OnDamaged(FDamageInfo DamageInfo);
|
||||
|
||||
UFUNCTION()
|
||||
virtual void OnDeath(FDamageInfo damageInfo);
|
||||
virtual void OnDeath(FDamageInfo DamageInfo);
|
||||
|
||||
protected:
|
||||
UFUNCTION()
|
||||
virtual void LoadDataFromDataAsset_Implementation(UEnemyDataAsset* enemyDataAsset) override;
|
||||
virtual void LoadDataFromDataAsset_Implementation(UEnemyDataAsset* EnemyDataAsset) override;
|
||||
|
||||
UFUNCTION()
|
||||
virtual void ResetData_Implementation() override;
|
||||
@ -81,12 +83,12 @@ public:
|
||||
|
||||
UFUNCTION()
|
||||
void OnDamageBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||
const FHitResult& SweepResult);
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||
const FHitResult& SweepResult);
|
||||
|
||||
UFUNCTION()
|
||||
void OnDamageEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
|
||||
int32 OtherBodyIndex);
|
||||
int32 OtherBodyIndex);
|
||||
|
||||
private:
|
||||
UFUNCTION()
|
||||
|
@ -19,24 +19,24 @@ class VAMPIRES_API UEnemyDataAsset : public UDataAsset
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<UStaticMesh> StaticMesh;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<UBehaviorTree> BehaviorTree = nullptr;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<UPickupDataAsset> PickupDataAsset = nullptr;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<USoundBase> OnDamagedSoundBase = nullptr;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<USoundBase> OnDeathSoundBase = nullptr;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<UNiagaraSystem> OnDamagedNiagaraSystem;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<UNiagaraSystem> OnDeathNiagaraSystem;
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -16,9 +16,9 @@ void AGoldPickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||
const FHitResult& SweepResult)
|
||||
{
|
||||
if (UGoldComponent* goldComponent = OtherActor->GetComponentByClass<UGoldComponent>())
|
||||
if (UGoldComponent* GoldComponent = OtherActor->GetComponentByClass<UGoldComponent>())
|
||||
{
|
||||
goldComponent->IncrementGold(PickupValue);
|
||||
GoldComponent->IncrementGold(PickupValue);
|
||||
Super::OnInnerBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,7 @@ class VAMPIRES_API AGoldPickup : public APickup
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
virtual void OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||
const FHitResult& SweepResult) override;
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||
const FHitResult& SweepResult) override;
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -10,44 +10,45 @@ void AObjectPoolManager::BeginPlay()
|
||||
Super::BeginPlay();
|
||||
}
|
||||
|
||||
void AObjectPoolManager::InitializeObjectPool(TSubclassOf<AActor> Object, const int InitialObjectPoolSize)
|
||||
void AObjectPoolManager::InitializeObjectPool(const TSubclassOf<AActor>& TemplateObject, const int InitialObjectPoolSize)
|
||||
{
|
||||
ObjectTemplate = Object;
|
||||
ObjectTemplate = TemplateObject;
|
||||
|
||||
for (int i = 0; i < InitialObjectPoolSize; i++)
|
||||
{
|
||||
if (AActor* object = GetWorld()->SpawnActor<AActor>(Object, FVector(100000.0f, 100000.0f, 0), FRotator(0, 0, 0)))
|
||||
if (AActor* Object = GetWorld()->SpawnActor<
|
||||
AActor>(TemplateObject, FVector(100000.0f, 100000.0f, 0), FRotator(0, 0, 0)))
|
||||
{
|
||||
SetObjectStatus(false, object);
|
||||
ObjectPool.Add(object);
|
||||
SetObjectStatus(false, Object);
|
||||
ObjectPool.Add(Object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AObjectPoolManager::InitializeObjectPool(UClass* Object, int InitialObjectPoolSize)
|
||||
void AObjectPoolManager::InitializeObjectPool(UClass* TemplateObject, int InitialObjectPoolSize)
|
||||
{
|
||||
for (int i = 0; i < InitialObjectPoolSize; i++)
|
||||
{
|
||||
if (AActor* object = GetWorld()->SpawnActor<AActor>(Object))
|
||||
if (AActor* Object = GetWorld()->SpawnActor<AActor>(TemplateObject))
|
||||
{
|
||||
SetObjectStatus(false, object);
|
||||
ObjectPool.Add(object);
|
||||
SetObjectStatus(false, Object);
|
||||
ObjectPool.Add(Object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AActor* AObjectPoolManager::GetObject(int startingOffset)
|
||||
AActor* AObjectPoolManager::GetObject(int StartingOffset)
|
||||
{
|
||||
int ObjectPoolSize = ObjectPool.Num();
|
||||
for (int i = startingOffset; i < ObjectPoolSize; i++)
|
||||
for (int i = StartingOffset; i < ObjectPoolSize; i++)
|
||||
{
|
||||
if (ObjectPool[i]->IsHidden())
|
||||
{
|
||||
SetObjectStatus(true, ObjectPool[i]);
|
||||
|
||||
if (UObjectPoolComponent* objectPoolComponent = ObjectPool[i]->GetComponentByClass<UObjectPoolComponent>())
|
||||
if (UObjectPoolComponent* ObjectPoolComponent = ObjectPool[i]->GetComponentByClass<UObjectPoolComponent>())
|
||||
{
|
||||
objectPoolComponent->OnRetrieve.ExecuteIfBound();
|
||||
ObjectPoolComponent->OnRetrieve.ExecuteIfBound();
|
||||
}
|
||||
|
||||
return ObjectPool[i];
|
||||
@ -59,19 +60,19 @@ AActor* AObjectPoolManager::GetObject(int startingOffset)
|
||||
return GetObject(ObjectPoolSize);
|
||||
}
|
||||
|
||||
void AObjectPoolManager::ReturnObject(AActor* object)
|
||||
void AObjectPoolManager::ReturnObject(AActor* Object)
|
||||
{
|
||||
SetObjectStatus(false, object);
|
||||
SetObjectStatus(false, Object);
|
||||
|
||||
if (UObjectPoolComponent* objectPoolComponent = object->GetComponentByClass<UObjectPoolComponent>())
|
||||
if (UObjectPoolComponent* ObjectPoolComponent = Object->GetComponentByClass<UObjectPoolComponent>())
|
||||
{
|
||||
objectPoolComponent->OnReturn.ExecuteIfBound();
|
||||
ObjectPoolComponent->OnReturn.ExecuteIfBound();
|
||||
}
|
||||
}
|
||||
|
||||
void AObjectPoolManager::SetObjectStatus(bool enabled, AActor* object)
|
||||
void AObjectPoolManager::SetObjectStatus(bool bEnabled, AActor* Object)
|
||||
{
|
||||
object->SetActorHiddenInGame(!enabled);
|
||||
object->SetActorTickEnabled(enabled);
|
||||
object->SetActorEnableCollision(enabled);
|
||||
Object->SetActorHiddenInGame(!bEnabled);
|
||||
Object->SetActorTickEnabled(bEnabled);
|
||||
Object->SetActorEnableCollision(bEnabled);
|
||||
}
|
||||
|
@ -15,17 +15,17 @@ class VAMPIRES_API AObjectPoolManager : public AActor
|
||||
TSubclassOf<AActor> ObjectTemplate;
|
||||
|
||||
public:
|
||||
void InitializeObjectPool(TSubclassOf<AActor> Object, int InitialObjectPoolSize = 400);
|
||||
void InitializeObjectPool(UClass* Object, int InitialObjectPoolSize = 400);
|
||||
void InitializeObjectPool(const TSubclassOf<AActor>& TemplateObject, int InitialObjectPoolSize = 400);
|
||||
void InitializeObjectPool(UClass* TemplateObject, int InitialObjectPoolSize = 400);
|
||||
|
||||
AActor* GetObject(int startingOffset = 0);
|
||||
AActor* GetObject(int StartingOffset = 0);
|
||||
|
||||
void ReturnObject(AActor* object);
|
||||
void ReturnObject(AActor* Object);
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
private:
|
||||
void SetObjectStatus(bool enabled, AActor* object);
|
||||
void SetObjectStatus(bool bEnabled, AActor* Object);
|
||||
};
|
||||
|
@ -42,8 +42,8 @@ APickup::APickup()
|
||||
TimelineComponent->SetTimelineLengthMode(TL_TimelineLength);
|
||||
TimelineComponent->SetPlaybackPosition(0.0f, false);
|
||||
|
||||
onTimelineCallback.BindUFunction(this, FName(TEXT("TimelineCallback")));
|
||||
onTimelineFinishedCallback.BindUFunction(this, FName(TEXT("TimelineFinishedCallback")));
|
||||
OnTimelineCallback.BindUFunction(this, FName(TEXT("TimelineCallback")));
|
||||
OnTimelineFinishedCallback.BindUFunction(this, FName(TEXT("TimelineFinishedCallback")));
|
||||
|
||||
NiagaraComponent = CreateDefaultSubobject<UNiagaraComponent>(TEXT("Niagara Component"));
|
||||
NiagaraComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
|
||||
@ -60,8 +60,8 @@ void APickup::BeginPlay()
|
||||
|
||||
if (CurveFloat != nullptr)
|
||||
{
|
||||
TimelineComponent->AddInterpFloat(CurveFloat, onTimelineCallback);
|
||||
TimelineComponent->SetTimelineFinishedFunc(onTimelineFinishedCallback);
|
||||
TimelineComponent->AddInterpFloat(CurveFloat, OnTimelineCallback);
|
||||
TimelineComponent->SetTimelineFinishedFunc(OnTimelineFinishedCallback);
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,8 +77,8 @@ void APickup::LoadDataFromDataAsset_Implementation(UPickupDataAsset* PickupDataA
|
||||
|
||||
if (CurveFloat != nullptr)
|
||||
{
|
||||
TimelineComponent->AddInterpFloat(CurveFloat, onTimelineCallback);
|
||||
TimelineComponent->SetTimelineFinishedFunc(onTimelineFinishedCallback);
|
||||
TimelineComponent->AddInterpFloat(CurveFloat, OnTimelineCallback);
|
||||
TimelineComponent->SetTimelineFinishedFunc(OnTimelineFinishedCallback);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -110,14 +110,14 @@ void APickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AAct
|
||||
UGameplayStatics::PlaySound2D(GetWorld(), PickupSoundBase);
|
||||
}
|
||||
|
||||
AGameModeBase* gamemode = UGameplayStatics::GetGameMode(GetWorld());
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(gamemode, UPools::StaticClass()))
|
||||
AGameModeBase* Gamemode = UGameplayStatics::GetGameMode(GetWorld());
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(Gamemode, UPools::StaticClass()))
|
||||
{
|
||||
if (AObjectPoolManager* objectPoolManager = IPools::Execute_GetProjectileObjectPoolManager(gamemode))
|
||||
if (AObjectPoolManager* ObjectPoolManager = IPools::Execute_GetProjectileObjectPoolManager(Gamemode))
|
||||
{
|
||||
TimelineComponent->Stop();
|
||||
ResetData_Implementation();
|
||||
objectPoolManager->ReturnObject(this);
|
||||
ObjectPoolManager->ReturnObject(this);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -131,18 +131,19 @@ void APickup::OnOuterBeginOverlap(UPrimitiveComponent* OverlappedComponent, AAct
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||
const FHitResult& SweepResult)
|
||||
{
|
||||
if (!TimelineComponent->IsPlaying() && UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) == Cast<ACharacter>(OtherActor))
|
||||
if (!TimelineComponent->IsPlaying() && UGameplayStatics::GetPlayerCharacter(GetWorld(), 0) == Cast<
|
||||
ACharacter>(OtherActor))
|
||||
{
|
||||
PlayTimeLine();
|
||||
}
|
||||
}
|
||||
|
||||
void APickup::TimelineCallback(float val)
|
||||
void APickup::TimelineCallback(float Value)
|
||||
{
|
||||
FVector actorLocation = PickupLocation;
|
||||
FVector playerLocation = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)->GetActorLocation();
|
||||
FVector location = FMath::Lerp(actorLocation, playerLocation, val);
|
||||
SetActorLocation(location);
|
||||
FVector ActorLocation = PickupLocation;
|
||||
FVector PlayerLocation = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)->GetActorLocation();
|
||||
FVector Location = FMath::Lerp(ActorLocation, PlayerLocation, Value);
|
||||
SetActorLocation(Location);
|
||||
}
|
||||
|
||||
void APickup::TimelineFinishedCallback()
|
||||
|
@ -18,7 +18,7 @@ class VAMPIRES_API APickup : public AActor, public IPickupable
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
int PickupValue = 1;
|
||||
|
||||
@ -44,8 +44,8 @@ public:
|
||||
TObjectPtr<UNiagaraComponent> NiagaraComponent = nullptr;
|
||||
|
||||
private:
|
||||
FOnTimelineFloat onTimelineCallback;
|
||||
FOnTimelineEventStatic onTimelineFinishedCallback;
|
||||
FOnTimelineFloat OnTimelineCallback;
|
||||
FOnTimelineEventStatic OnTimelineFinishedCallback;
|
||||
|
||||
FVector PickupLocation;
|
||||
|
||||
@ -72,7 +72,7 @@ protected:
|
||||
const FHitResult& SweepResult);
|
||||
|
||||
UFUNCTION()
|
||||
void TimelineCallback(float val);
|
||||
void TimelineCallback(float Value);
|
||||
|
||||
UFUNCTION()
|
||||
void TimelineFinishedCallback();
|
||||
|
@ -3,14 +3,9 @@
|
||||
|
||||
#include "PlayerCharacter.h"
|
||||
|
||||
#include "VampirePlayerController.h"
|
||||
#include "EnhancedInputComponent.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "EXPComponent.h"
|
||||
#include "GoldComponent.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "InputMappingContext.h"
|
||||
#include "WeaponInventoryComponent.h"
|
||||
#include "Components/WidgetComponent.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
@ -37,8 +32,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,33 +45,30 @@ void APlayerCharacter::BeginPlay()
|
||||
|
||||
if (CameraShakeCurve != nullptr)
|
||||
{
|
||||
CameraShakeTimelineComponent->AddInterpFloat(CameraShakeCurve, onTimelineCallback);
|
||||
CameraShakeTimelineComponent->SetTimelineFinishedFunc(onTimelineFinishedCallback);
|
||||
CameraShakeTimelineComponent->AddInterpFloat(CameraShakeCurve, OnTimelineCallback);
|
||||
CameraShakeTimelineComponent->SetTimelineFinishedFunc(OnTimelineFinishedCallback);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
auto PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
||||
FVector Location = GetActorLocation();
|
||||
if (Location.X < BottomRight.X || Location.X > TopLeft.X || Location.Y > BottomRight.Y || Location.Y < TopLeft.Y)
|
||||
{
|
||||
Location.X = FMath::Clamp(Location.X, BottomRight.X, TopLeft.X);
|
||||
Location.Y = FMath::Clamp(Location.Y, TopLeft.Y, BottomRight.Y);
|
||||
|
||||
FVector TopLeft, TopLeftDir;
|
||||
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);
|
||||
SetActorLocation(Location);
|
||||
}
|
||||
}
|
||||
|
||||
UEXPComponent* APlayerCharacter::GetEXPComponent()
|
||||
@ -89,7 +81,7 @@ UGoldComponent* APlayerCharacter::GetGoldComponent()
|
||||
return GoldComponent;
|
||||
}
|
||||
|
||||
void APlayerCharacter::OnDamaged(FDamageInfo damageInfo)
|
||||
void APlayerCharacter::OnDamaged(FDamageInfo DamageInfo)
|
||||
{
|
||||
if (OnDamagedSound)
|
||||
{
|
||||
@ -99,21 +91,20 @@ void APlayerCharacter::OnDamaged(FDamageInfo damageInfo)
|
||||
CameraShakeTimelineComponent->PlayFromStart();
|
||||
}
|
||||
|
||||
void APlayerCharacter::OnDeath(FDamageInfo damageInfo)
|
||||
void APlayerCharacter::OnDeath(FDamageInfo DamageInfo)
|
||||
{
|
||||
if (OnDeathSound)
|
||||
{
|
||||
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 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()
|
||||
@ -122,3 +113,19 @@ void APlayerCharacter::CameraShakeTimelineFinishedCallback()
|
||||
auto cameraActor = PlayerController->GetViewTarget();
|
||||
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);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "CoreMinimal.h"
|
||||
#include "VampireCharacter.h"
|
||||
#include "Components/TimelineComponent.h"
|
||||
#include "UnrealClient.h"
|
||||
#include "PlayerCharacter.generated.h"
|
||||
|
||||
struct FDamageInfo;
|
||||
@ -24,7 +25,7 @@ class VAMPIRES_API APlayerCharacter : public AVampireCharacter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
protected:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TObjectPtr<UEXPComponent> EXPComponent;
|
||||
|
||||
@ -44,19 +45,22 @@ public:
|
||||
float CameraShakeStrength = 100.0f;
|
||||
|
||||
private:
|
||||
|
||||
UPROPERTY()
|
||||
TObjectPtr<APlayerCameraManager> PlayerCameraManager = nullptr;
|
||||
|
||||
APlayerCharacter();
|
||||
FOnTimelineFloat OnTimelineCallback;
|
||||
FOnTimelineEventStatic OnTimelineFinishedCallback;
|
||||
|
||||
private:
|
||||
FOnTimelineFloat onTimelineCallback;
|
||||
FOnTimelineEventStatic onTimelineFinishedCallback;
|
||||
FTimerHandle ResizeViewportTimerDelegate;
|
||||
FVector TopLeft, TopLeftDir, BottomRight, BottomRightDir;
|
||||
|
||||
APlayerCharacter();
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
UEXPComponent* GetEXPComponent();
|
||||
@ -65,14 +69,19 @@ public:
|
||||
|
||||
private:
|
||||
UFUNCTION()
|
||||
virtual void OnDamaged(FDamageInfo damageInfo);
|
||||
virtual void OnDamaged(FDamageInfo DamageInfo);
|
||||
|
||||
UFUNCTION()
|
||||
virtual void OnDeath(FDamageInfo damageInfo);
|
||||
virtual void OnDeath(FDamageInfo DamageInfo);
|
||||
|
||||
UFUNCTION()
|
||||
void CameraShakeTimelineCallback(float val);
|
||||
void CameraShakeTimelineCallback(float Val);
|
||||
|
||||
UFUNCTION()
|
||||
void CameraShakeTimelineFinishedCallback();
|
||||
|
||||
UFUNCTION()
|
||||
void ResizeViewportTimerCallback();
|
||||
|
||||
void OnViewportResized(FViewport* ViewPort, uint32 val);
|
||||
};
|
||||
|
@ -60,7 +60,8 @@ void AProjectile::SetActorHiddenInGame(bool bNewHidden)
|
||||
}
|
||||
else
|
||||
{
|
||||
GetWorldTimerManager().SetTimer(ProjectileLifetimeTimerHandle, this, &AProjectile::ReturnProjectileToPool, ProjectileLifespan, true);
|
||||
GetWorldTimerManager().SetTimer(ProjectileLifetimeTimerHandle, this, &AProjectile::ReturnProjectileToPool,
|
||||
ProjectileLifespan, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,14 +104,14 @@ void AProjectile::OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedCompon
|
||||
|
||||
if (!EnemyHealthComponent->GetIsDead())
|
||||
{
|
||||
AController* ownerController = nullptr;
|
||||
if (AVampireCharacter* character = Cast<AVampireCharacter>(GetOwner()))
|
||||
AController* OwnerController = nullptr;
|
||||
if (AVampireCharacter* Character = Cast<AVampireCharacter>(GetOwner()))
|
||||
{
|
||||
ownerController = character->GetController();
|
||||
OwnerController = Character->GetController();
|
||||
}
|
||||
|
||||
AProjectileWeapon* ownerWeapon = Cast<AProjectileWeapon>(GetOwner());
|
||||
EnemyHealthComponent->TakeDamage(Enemy, ownerWeapon->GetDamage(), nullptr, ownerController, this);
|
||||
AProjectileWeapon* OwnerWeapon = Cast<AProjectileWeapon>(GetOwner());
|
||||
EnemyHealthComponent->TakeDamage(Enemy, OwnerWeapon->GetDamage(), nullptr, OwnerController, this);
|
||||
|
||||
RemainingDamageableEnemies--;
|
||||
|
||||
@ -124,14 +125,14 @@ void AProjectile::OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedCompon
|
||||
|
||||
void AProjectile::ReturnProjectileToPool()
|
||||
{
|
||||
AGameModeBase* gamemode = UGameplayStatics::GetGameMode(GetWorld());
|
||||
AGameModeBase* Gamemode = UGameplayStatics::GetGameMode(GetWorld());
|
||||
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(gamemode, UPools::StaticClass()))
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(Gamemode, UPools::StaticClass()))
|
||||
{
|
||||
if (AObjectPoolManager* objectPoolManager =
|
||||
IPools::Execute_GetProjectileObjectPoolManager(gamemode))
|
||||
if (AObjectPoolManager* ObjectPoolManager =
|
||||
IPools::Execute_GetProjectileObjectPoolManager(Gamemode))
|
||||
{
|
||||
objectPoolManager->ReturnObject(this);
|
||||
ObjectPoolManager->ReturnObject(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -10,7 +10,7 @@
|
||||
// Sets default values
|
||||
AVampireCharacter::AVampireCharacter()
|
||||
{
|
||||
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
// Create Health Component
|
||||
@ -29,8 +29,6 @@ AVampireCharacter::AVampireCharacter()
|
||||
void AVampireCharacter::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
@ -38,21 +36,21 @@ void AVampireCharacter::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
float newYaw = FMath::Atan2(PreviousMovementDirection.Y, PreviousMovementDirection.X) * 180.0f / PI;
|
||||
FQuat newRotation = FQuat::Slerp(StaticMeshComponent->GetComponentRotation().Quaternion(),
|
||||
FRotator(0.0f, newYaw, 0.0f).Quaternion(),
|
||||
float NewYaw = FMath::Atan2(PreviousMovementDirection.Y, PreviousMovementDirection.X) * 180.0f / PI;
|
||||
FQuat NewRotation = FQuat::Slerp(StaticMeshComponent->GetComponentRotation().Quaternion(),
|
||||
FRotator(0.0f, NewYaw, 0.0f).Quaternion(),
|
||||
DeltaTime * SlerpSpeed);
|
||||
StaticMeshComponent->SetRelativeRotation(newRotation);
|
||||
StaticMeshComponent->SetRelativeRotation(NewRotation);
|
||||
}
|
||||
|
||||
void AVampireCharacter::Input_Move_Implementation(FVector2D value)
|
||||
void AVampireCharacter::Input_Move_Implementation(FVector2D Value)
|
||||
{
|
||||
PreviousMovementDirection = value;
|
||||
PreviousMovementDirection = Value;
|
||||
|
||||
if (value.Size() != 0.0f)
|
||||
if (Value.Size() != 0.0f)
|
||||
{
|
||||
AddMovementInput({0.0f, 1.0f, 0.0f}, value.Y);
|
||||
AddMovementInput({1.0f, 0.0f, 0.0f}, value.X);
|
||||
AddMovementInput({0.0f, 1.0f, 0.0f}, Value.Y);
|
||||
AddMovementInput({1.0f, 0.0f, 0.0f}, Value.X);
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,4 +68,3 @@ UHealthComponent* AVampireCharacter::GetHealthComponent()
|
||||
{
|
||||
return HealthComponent;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
};
|
||||
|
@ -2,4 +2,3 @@
|
||||
|
||||
|
||||
#include "VampireGameInstance.h"
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Louis Hobbs | 2024-2025
|
||||
// Louis Hobbs | 2024-2025
|
||||
|
||||
#pragma once
|
||||
|
||||
@ -15,8 +15,8 @@ UCLASS()
|
||||
class VAMPIRES_API UVampireGameInstance : public UGameInstance
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
|
||||
public:
|
||||
UPROPERTY()
|
||||
TSubclassOf<AWeapon> StarterWeapon;
|
||||
|
||||
|
@ -24,6 +24,9 @@ class VAMPIRES_API AVampireGameMode : public AGameMode, public IPools
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
FOnEnemyDeathCountIncrementDelegate OnEnemyDeathCountIncrementDelegate;
|
||||
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TSubclassOf<AEnemyCharacter> EnemyTemplate;
|
||||
|
||||
@ -33,8 +36,6 @@ public:
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TSubclassOf<AEXPPickup> PickupTemplate;
|
||||
|
||||
FOnEnemyDeathCountIncrementDelegate OnEnemyDeathCountIncrementDelegate;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TArray<TObjectPtr<UEnemyDataAsset>> EnemyDataAssets;
|
||||
|
||||
@ -68,6 +69,7 @@ public:
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure)
|
||||
int GetEnemyDeathCount();
|
||||
|
||||
protected:
|
||||
UFUNCTION()
|
||||
void HandleOnEnemyDeath(FDamageInfo damageInfo);
|
||||
|
||||
@ -86,7 +88,6 @@ public:
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void EndGame();
|
||||
|
||||
protected:
|
||||
UFUNCTION()
|
||||
void SpawnEnemy();
|
||||
};
|
||||
|
@ -23,53 +23,55 @@ void AVampirePlayerController::OnPossess(APawn* aPawn)
|
||||
{
|
||||
Super::OnPossess(aPawn);
|
||||
|
||||
if (UEnhancedInputLocalPlayerSubsystem* subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()))
|
||||
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(
|
||||
GetLocalPlayer()))
|
||||
{
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(aPawn, UInputable::StaticClass()))
|
||||
{
|
||||
subsystem->AddMappingContext(IInputable::Execute_Input_GetInputMappingContext(aPawn), 0);
|
||||
Subsystem->AddMappingContext(IInputable::Execute_Input_GetInputMappingContext(aPawn), 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (PlayerHUD)
|
||||
{
|
||||
currentPlayerHUD = CreateWidget<UHUDWidget, AVampirePlayerController*>(this, PlayerHUD.Get());
|
||||
CurrentPlayerHUD = CreateWidget<UHUDWidget, AVampirePlayerController*>(this, PlayerHUD.Get());
|
||||
|
||||
if (UEXPComponent* expComponent = aPawn->GetComponentByClass<UEXPComponent>())
|
||||
if (UEXPComponent* ExpComponent = aPawn->GetComponentByClass<UEXPComponent>())
|
||||
{
|
||||
expComponent->OnEXPGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerEXPHUD);
|
||||
expComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerLevelHUD);
|
||||
expComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::ShowLevelUpScreen);
|
||||
UpdatePlayerEXPHUD(expComponent->GetCurrentEXP(), expComponent->GetCurrentLevelPercent());
|
||||
UpdatePlayerLevelHUD(expComponent->GetCurrentLevel());
|
||||
ExpComponent->OnEXPGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerEXPHUD);
|
||||
ExpComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerLevelHUD);
|
||||
ExpComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::ShowLevelUpScreen);
|
||||
UpdatePlayerEXPHUD(ExpComponent->GetCurrentEXP(), ExpComponent->GetCurrentLevelPercent());
|
||||
UpdatePlayerLevelHUD(ExpComponent->GetCurrentLevel());
|
||||
}
|
||||
|
||||
if (UGoldComponent* goldComponent = aPawn->GetComponentByClass<UGoldComponent>())
|
||||
if (UGoldComponent* GoldComponent = aPawn->GetComponentByClass<UGoldComponent>())
|
||||
{
|
||||
goldComponent->OnGoldGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdateGoldCountHUD);
|
||||
UpdateGoldCountHUD(goldComponent->GetCurrentGold());
|
||||
GoldComponent->OnGoldGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdateGoldCountHUD);
|
||||
UpdateGoldCountHUD(GoldComponent->GetCurrentGold());
|
||||
}
|
||||
|
||||
if (AVampireGameMode* gamemode = Cast<AVampireGameMode>(UGameplayStatics::GetGameMode(GetWorld())))
|
||||
if (AVampireGameMode* Gamemode = Cast<AVampireGameMode>(UGameplayStatics::GetGameMode(GetWorld())))
|
||||
{
|
||||
gamemode->OnEnemyDeathCountIncrementDelegate.AddDynamic(this, &AVampirePlayerController::UpdateKillCountHUD);
|
||||
UpdateKillCountHUD(gamemode->GetEnemyDeathCount());
|
||||
Gamemode->OnEnemyDeathCountIncrementDelegate.
|
||||
AddDynamic(this, &AVampirePlayerController::UpdateKillCountHUD);
|
||||
UpdateKillCountHUD(Gamemode->GetEnemyDeathCount());
|
||||
}
|
||||
|
||||
if (currentPlayerHUD)
|
||||
if (CurrentPlayerHUD)
|
||||
{
|
||||
currentPlayerHUD->AddToViewport();
|
||||
CurrentPlayerHUD->AddToViewport();
|
||||
}
|
||||
}
|
||||
|
||||
if (UVampireGameInstance* gameInstance = Cast<UVampireGameInstance>(GetGameInstance()))
|
||||
if (UVampireGameInstance* GameInstance = Cast<UVampireGameInstance>(GetGameInstance()))
|
||||
{
|
||||
UWeaponInventoryComponent* weaponInventoryComponent = aPawn->GetComponentByClass<
|
||||
UWeaponInventoryComponent* WeaponInventoryComponent = aPawn->GetComponentByClass<
|
||||
UWeaponInventoryComponent>();
|
||||
|
||||
if (weaponInventoryComponent && gameInstance->StarterWeapon)
|
||||
if (WeaponInventoryComponent && GameInstance->StarterWeapon)
|
||||
{
|
||||
weaponInventoryComponent->initialInventory.Add(gameInstance->StarterWeapon);
|
||||
WeaponInventoryComponent->InitialInventory.Add(GameInstance->StarterWeapon);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -78,7 +80,7 @@ void AVampirePlayerController::OnUnPossess()
|
||||
{
|
||||
Super::OnUnPossess();
|
||||
|
||||
GetWorld()->GetTimerManager().ClearTimer(pawnLifeTimeHandle);
|
||||
GetWorld()->GetTimerManager().ClearTimer(PawnLifeTimeHandle);
|
||||
}
|
||||
|
||||
void AVampirePlayerController::SetupInputComponent()
|
||||
@ -94,13 +96,13 @@ void AVampirePlayerController::SetupInputComponent()
|
||||
|
||||
void AVampirePlayerController::Move(const FInputActionValue& MovementInput)
|
||||
{
|
||||
FVector2D movement = MovementInput.Get<FVector2D>();
|
||||
FVector2D Movement = MovementInput.Get<FVector2D>();
|
||||
|
||||
if (APawn* pawn = GetPawn())
|
||||
{
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(pawn, UInputable::StaticClass()))
|
||||
{
|
||||
IInputable::Execute_Input_Move(pawn, movement);
|
||||
IInputable::Execute_Input_Move(pawn, Movement);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -119,26 +121,26 @@ void AVampirePlayerController::OnPause(const FInputActionValue& PauseInput)
|
||||
{
|
||||
if (SetPause(true))
|
||||
{
|
||||
currentPauseUI = CreateWidget<UPauseWidget, AVampirePlayerController*>(this, PauseUI.Get());
|
||||
if (currentPauseUI)
|
||||
CurrentPauseUI = CreateWidget<UPauseWidget, AVampirePlayerController*>(this, PauseUI.Get());
|
||||
if (CurrentPauseUI)
|
||||
{
|
||||
currentPauseUI->AddToViewport();
|
||||
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, currentPauseUI, EMouseLockMode::LockInFullscreen);
|
||||
CurrentPauseUI->AddToViewport();
|
||||
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, CurrentPauseUI, EMouseLockMode::LockInFullscreen);
|
||||
bShowMouseCursor = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AVampirePlayerController::UpdatePlayerEXPHUD(int exp, float currentLevelPercent)
|
||||
void AVampirePlayerController::UpdatePlayerEXPHUD(int Exp, float CurrentLevelPercent)
|
||||
{
|
||||
if (currentPlayerHUD)
|
||||
if (CurrentPlayerHUD)
|
||||
{
|
||||
currentPlayerHUD->UpdateEXPBar(currentLevelPercent);
|
||||
CurrentPlayerHUD->UpdateEXPBar(CurrentLevelPercent);
|
||||
}
|
||||
}
|
||||
|
||||
void AVampirePlayerController::ShowLevelUpScreen(int level)
|
||||
void AVampirePlayerController::ShowLevelUpScreen(int Level)
|
||||
{
|
||||
APawn* pawn = GetPawn();
|
||||
if (!pawn)
|
||||
@ -146,8 +148,8 @@ void AVampirePlayerController::ShowLevelUpScreen(int level)
|
||||
return;
|
||||
}
|
||||
|
||||
UEXPComponent* expComponent = pawn->GetComponentByClass<UEXPComponent>();
|
||||
if (!expComponent || expComponent->GetCurrentLevel() == 0)
|
||||
UEXPComponent* ExpComponent = pawn->GetComponentByClass<UEXPComponent>();
|
||||
if (!ExpComponent || ExpComponent->GetCurrentLevel() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -156,53 +158,54 @@ void AVampirePlayerController::ShowLevelUpScreen(int level)
|
||||
{
|
||||
if (SetPause(true))
|
||||
{
|
||||
currentLevelUpUI = CreateWidget<ULevelUpWidget, AVampirePlayerController*>(this, LevelUpUI.Get());
|
||||
if (currentLevelUpUI)
|
||||
CurrentLevelUpUI = CreateWidget<ULevelUpWidget, AVampirePlayerController*>(this, LevelUpUI.Get());
|
||||
if (CurrentLevelUpUI)
|
||||
{
|
||||
currentLevelUpUI->AddToViewport();
|
||||
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, currentLevelUpUI, EMouseLockMode::LockInFullscreen);
|
||||
CurrentLevelUpUI->AddToViewport();
|
||||
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, CurrentLevelUpUI,
|
||||
EMouseLockMode::LockInFullscreen);
|
||||
bShowMouseCursor = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AVampirePlayerController::UpdatePlayerLevelHUD(int level)
|
||||
void AVampirePlayerController::UpdatePlayerLevelHUD(int Level)
|
||||
{
|
||||
if (currentPlayerHUD)
|
||||
if (CurrentPlayerHUD)
|
||||
{
|
||||
currentPlayerHUD->UpdateLevelBlock(level);
|
||||
CurrentPlayerHUD->UpdateLevelBlock(Level);
|
||||
}
|
||||
}
|
||||
|
||||
void AVampirePlayerController::UpdateTimerHUD(float deltaTime)
|
||||
void AVampirePlayerController::UpdateTimerHUD(float DeltaTime)
|
||||
{
|
||||
if (currentPlayerHUD)
|
||||
if (CurrentPlayerHUD)
|
||||
{
|
||||
currentPlayerHUD->UpdateTimerBlock(deltaTime);
|
||||
CurrentPlayerHUD->UpdateTimerBlock(DeltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
void AVampirePlayerController::UpdateKillCountHUD(int killCount)
|
||||
void AVampirePlayerController::UpdateKillCountHUD(int KillCount)
|
||||
{
|
||||
if (currentPlayerHUD)
|
||||
if (CurrentPlayerHUD)
|
||||
{
|
||||
currentPlayerHUD->UpdateKillBlock(killCount);
|
||||
CurrentPlayerHUD->UpdateKillBlock(KillCount);
|
||||
}
|
||||
}
|
||||
|
||||
void AVampirePlayerController::UpdateGoldCountHUD(int goldCount)
|
||||
void AVampirePlayerController::UpdateGoldCountHUD(int GoldCount)
|
||||
{
|
||||
if (currentPlayerHUD)
|
||||
if (CurrentPlayerHUD)
|
||||
{
|
||||
currentPlayerHUD->UpdateGoldBlock(goldCount);
|
||||
CurrentPlayerHUD->UpdateGoldBlock(GoldCount);
|
||||
}
|
||||
}
|
||||
|
||||
void AVampirePlayerController::UpdateTimerHUDElement_Implementation(float deltaTime)
|
||||
void AVampirePlayerController::UpdateTimerHUDElement_Implementation(float DeltaTime)
|
||||
{
|
||||
if (currentPlayerHUD)
|
||||
if (CurrentPlayerHUD)
|
||||
{
|
||||
currentPlayerHUD->UpdateTimerBlock(deltaTime);
|
||||
CurrentPlayerHUD->UpdateTimerBlock(DeltaTime);
|
||||
}
|
||||
}
|
||||
|
@ -41,15 +41,15 @@ public:
|
||||
private:
|
||||
|
||||
UPROPERTY()
|
||||
TObjectPtr<UHUDWidget> currentPlayerHUD = nullptr;
|
||||
TObjectPtr<UHUDWidget> CurrentPlayerHUD = nullptr;
|
||||
|
||||
UPROPERTY()
|
||||
TObjectPtr<UPauseWidget> currentPauseUI = nullptr;
|
||||
TObjectPtr<UPauseWidget> CurrentPauseUI = nullptr;
|
||||
|
||||
UPROPERTY()
|
||||
TObjectPtr<ULevelUpWidget> currentLevelUpUI = nullptr;
|
||||
TObjectPtr<ULevelUpWidget> CurrentLevelUpUI = nullptr;
|
||||
|
||||
FTimerHandle pawnLifeTimeHandle;
|
||||
FTimerHandle PawnLifeTimeHandle;
|
||||
|
||||
protected:
|
||||
virtual void OnPossess(APawn* aPawn) override;
|
||||
@ -65,22 +65,22 @@ protected:
|
||||
void OnPause(const FInputActionValue& PauseInput);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdatePlayerEXPHUD(int exp, float currentLevelPercent);
|
||||
void UpdatePlayerEXPHUD(int Exp, float CurrentLevelPercent);
|
||||
|
||||
UFUNCTION()
|
||||
void ShowLevelUpScreen(int level);
|
||||
void ShowLevelUpScreen(int Level);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdatePlayerLevelHUD(int level);
|
||||
void UpdatePlayerLevelHUD(int Level);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void UpdateTimerHUD(float deltaTime);
|
||||
void UpdateTimerHUD(float DeltaTime);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateKillCountHUD(int killCount);
|
||||
void UpdateKillCountHUD(int KillCount);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateGoldCountHUD(int goldCount);
|
||||
void UpdateGoldCountHUD(int GoldCount);
|
||||
|
||||
virtual void UpdateTimerHUDElement_Implementation(float deltaTime) override;
|
||||
virtual void UpdateTimerHUDElement_Implementation(float DeltaTime) override;
|
||||
};
|
||||
|
@ -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();
|
||||
|
@ -25,37 +25,37 @@ void UWeaponInventoryComponent::BeginPlay()
|
||||
|
||||
void UWeaponInventoryComponent::InitializeInventory()
|
||||
{
|
||||
inventory.Empty();
|
||||
Inventory.Empty();
|
||||
|
||||
for (TSubclassOf<AWeapon> weapon : initialInventory)
|
||||
for (TSubclassOf<AWeapon> Weapon : InitialInventory)
|
||||
{
|
||||
if (IsValid(weapon))
|
||||
if (IsValid(Weapon))
|
||||
{
|
||||
AddWeaponToInventory(weapon);
|
||||
AddWeaponToInventory(Weapon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UWeaponInventoryComponent::AddWeaponToInventory(TSubclassOf<AWeapon> Weapon)
|
||||
void UWeaponInventoryComponent::AddWeaponToInventory(TSubclassOf<AWeapon> NewWeapon)
|
||||
{
|
||||
FActorSpawnParameters SpawnParameters;
|
||||
SpawnParameters.Owner = GetOwner();
|
||||
|
||||
AWeapon* weapon = GetWorld()->SpawnActor<AWeapon>(Weapon, SpawnParameters.Owner->GetTransform(), SpawnParameters);
|
||||
if (weapon->GetFollowPlayer())
|
||||
AWeapon* Weapon = GetWorld()->SpawnActor<AWeapon>(NewWeapon, SpawnParameters.Owner->GetTransform(), SpawnParameters);
|
||||
if (Weapon->GetFollowPlayer())
|
||||
{
|
||||
weapon->AttachToActor(GetOwner(), FAttachmentTransformRules::KeepWorldTransform);
|
||||
Weapon->AttachToActor(GetOwner(), FAttachmentTransformRules::KeepWorldTransform);
|
||||
}
|
||||
else
|
||||
{
|
||||
weapon->SetActorLocation(FVector::ZeroVector);
|
||||
Weapon->SetActorLocation(FVector::ZeroVector);
|
||||
}
|
||||
|
||||
inventory.Add(weapon);
|
||||
obtainableWeapons.Remove(Weapon);
|
||||
Inventory.Add(Weapon);
|
||||
ObtainableWeapons.Remove(NewWeapon);
|
||||
}
|
||||
|
||||
TArray<AWeapon*> UWeaponInventoryComponent::GetInventory()
|
||||
{
|
||||
return inventory;
|
||||
return Inventory;
|
||||
}
|
||||
|
@ -15,16 +15,15 @@ class VAMPIRES_API UWeaponInventoryComponent : public UActorComponent
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TArray<TSubclassOf<AWeapon>> ObtainableWeapons;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TArray<TSubclassOf<AWeapon>> obtainableWeapons;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TArray<TSubclassOf<AWeapon>> initialInventory;
|
||||
TArray<TSubclassOf<AWeapon>> InitialInventory;
|
||||
|
||||
private:
|
||||
UPROPERTY()
|
||||
TArray<TObjectPtr<AWeapon>> inventory;
|
||||
TArray<TObjectPtr<AWeapon>> Inventory;
|
||||
|
||||
public:
|
||||
// Sets default values for this component's properties
|
||||
@ -39,7 +38,7 @@ public:
|
||||
void InitializeInventory();
|
||||
|
||||
UFUNCTION()
|
||||
void AddWeaponToInventory(TSubclassOf<AWeapon> Weapon);
|
||||
void AddWeaponToInventory(TSubclassOf<AWeapon> NewWeapon);
|
||||
|
||||
UFUNCTION()
|
||||
TArray<AWeapon*> GetInventory();
|
||||
|
@ -27,7 +27,10 @@ void AFireWandWeapon::FireWeaponAction_Implementation()
|
||||
|
||||
bool AFireWandWeapon::UpgradeWeapon_Implementation()
|
||||
{
|
||||
if (!Super::UpgradeWeapon_Implementation()) return false;
|
||||
if (!Super::UpgradeWeapon_Implementation())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (CurrentLevel)
|
||||
{
|
||||
@ -67,26 +70,26 @@ void AFireWandWeapon::FireProjectile()
|
||||
{
|
||||
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);
|
||||
projectile->SetOwner(this);
|
||||
IProjectilable::Execute_LoadDataFromDataAsset(Projectile, ProjectileTemplate);
|
||||
Projectile->SetOwner(this);
|
||||
|
||||
AActor* target = OverlappedEnemies[FMath::RandRange(0, OverlappedEnemies.Num() - 1)];
|
||||
FVector direction = UKismetMathLibrary::GetDirectionUnitVector(
|
||||
GetActorLocation(), target->GetActorLocation());
|
||||
direction.Z = 0.0;
|
||||
direction.Normalize();
|
||||
AActor* Target = OverlappedEnemies[FMath::RandRange(0, OverlappedEnemies.Num() - 1)];
|
||||
FVector Direction = UKismetMathLibrary::GetDirectionUnitVector(
|
||||
GetActorLocation(), Target->GetActorLocation());
|
||||
Direction.Z = 0.0;
|
||||
Direction.Normalize();
|
||||
|
||||
IProjectilable::Execute_SetTargetDirection(projectile, direction);
|
||||
IProjectilable::Execute_SetTargetDirection(Projectile, Direction);
|
||||
}
|
||||
|
||||
Super::FireProjectile();
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#include "GarlicWeapon.h"
|
||||
|
||||
#include "MovieSceneTracksComponentTypes.h"
|
||||
#include "Components/SphereComponent.h"
|
||||
#include "vampires/EnemyCharacter.h"
|
||||
#include "vampires/HealthComponent.h"
|
||||
@ -20,7 +19,8 @@ AGarlicWeapon::AGarlicWeapon()
|
||||
|
||||
VisualEffectMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Visual Layout Mesh Component"));
|
||||
VisualEffectMeshComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
|
||||
VisualEffectMeshComponent->SetWorldScale3D(FVector(3.0f, 3.0f, 3.0f)); // This is to match the size of our sphere component
|
||||
// This is to match the size of our sphere component
|
||||
VisualEffectMeshComponent->SetWorldScale3D(FVector(3.0f, 3.0f, 3.0f));
|
||||
VisualEffectMeshComponent->SetCollisionProfileName("NoCollision");
|
||||
}
|
||||
|
||||
@ -41,15 +41,14 @@ void AGarlicWeapon::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AAc
|
||||
{
|
||||
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,
|
||||
overlappedEnemy),
|
||||
OverlappedEnemy),
|
||||
WeaponCooldown,
|
||||
true);
|
||||
GarlicOverlappedEnemies.Add(overlappedEnemy);
|
||||
GarlicOverlappedEnemies.Add(OverlappedEnemy);
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,22 +78,22 @@ void AGarlicWeapon::GarlicFireWeaponAction(FOverlappedEnemy EnemyCharacter)
|
||||
return;
|
||||
}
|
||||
|
||||
AController* ownerController = nullptr;
|
||||
if (AVampireCharacter* character = Cast<AVampireCharacter>(GetOwner()))
|
||||
AController* OwnerController = nullptr;
|
||||
if (AVampireCharacter* Character = Cast<AVampireCharacter>(GetOwner()))
|
||||
{
|
||||
ownerController = character->GetController();
|
||||
OwnerController = Character->GetController();
|
||||
}
|
||||
|
||||
EnemyHealthComponent->TakeDamage(EnemyCharacter.OverlappedEnemyCharacter, Damage, nullptr,
|
||||
ownerController, this);
|
||||
OwnerController, this);
|
||||
|
||||
if (!EnemyHealthComponent->GetIsDead())
|
||||
{
|
||||
FVector Direction = EnemyCharacter.OverlappedEnemyCharacter->GetActorLocation() - this->GetActorLocation();
|
||||
Direction.Normalize();
|
||||
Direction.Z = 0.0f;
|
||||
float distance = SphereComponent->GetScaledSphereRadius();
|
||||
Direction *= distance;
|
||||
float Distance = SphereComponent->GetScaledSphereRadius();
|
||||
Direction *= Distance;
|
||||
EnemyCharacter.OverlappedEnemyCharacter->SetActorLocation(
|
||||
EnemyCharacter.OverlappedEnemyCharacter->GetActorLocation() + Direction);
|
||||
}
|
||||
@ -102,48 +101,55 @@ void AGarlicWeapon::GarlicFireWeaponAction(FOverlappedEnemy EnemyCharacter)
|
||||
|
||||
bool AGarlicWeapon::UpgradeWeapon_Implementation()
|
||||
{
|
||||
if (!Super::UpgradeWeapon_Implementation()) return false;
|
||||
if (!Super::UpgradeWeapon_Implementation())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (CurrentLevel)
|
||||
{
|
||||
case 1:
|
||||
Range *= 1.4f;
|
||||
SphereComponent->SetSphereRadius(Range);
|
||||
Damage += 2.0f;
|
||||
VisualEffectMeshComponent->SetWorldScale3D(VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.4f);
|
||||
break;
|
||||
case 2:
|
||||
WeaponCooldown -= 0.1f;
|
||||
Damage += 1;
|
||||
break;
|
||||
case 3:
|
||||
Range *= 1.2f;
|
||||
SphereComponent->SetSphereRadius(Range);
|
||||
Damage += 1.0f;
|
||||
VisualEffectMeshComponent->SetWorldScale3D(VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f);
|
||||
break;
|
||||
case 4:
|
||||
WeaponCooldown -= 0.1f;
|
||||
Damage += 2;
|
||||
break;
|
||||
case 5:
|
||||
Range *= 1.2f;
|
||||
SphereComponent->SetSphereRadius(Range);
|
||||
Damage += 1.0f;
|
||||
VisualEffectMeshComponent->SetWorldScale3D(VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f);
|
||||
break;
|
||||
case 6:
|
||||
WeaponCooldown -= 0.1f;
|
||||
Damage += 1;
|
||||
break;
|
||||
case 7:
|
||||
Range *= 1.2f;
|
||||
SphereComponent->SetSphereRadius(Range);
|
||||
Damage += 1.0f;
|
||||
VisualEffectMeshComponent->SetWorldScale3D(VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
case 1:
|
||||
Range *= 1.4f;
|
||||
SphereComponent->SetSphereRadius(Range);
|
||||
Damage += 2.0f;
|
||||
VisualEffectMeshComponent->SetWorldScale3D(
|
||||
VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.4f);
|
||||
break;
|
||||
case 2:
|
||||
WeaponCooldown -= 0.1f;
|
||||
Damage += 1;
|
||||
break;
|
||||
case 3:
|
||||
Range *= 1.2f;
|
||||
SphereComponent->SetSphereRadius(Range);
|
||||
Damage += 1.0f;
|
||||
VisualEffectMeshComponent->SetWorldScale3D(
|
||||
VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f);
|
||||
break;
|
||||
case 4:
|
||||
WeaponCooldown -= 0.1f;
|
||||
Damage += 2;
|
||||
break;
|
||||
case 5:
|
||||
Range *= 1.2f;
|
||||
SphereComponent->SetSphereRadius(Range);
|
||||
Damage += 1.0f;
|
||||
VisualEffectMeshComponent->SetWorldScale3D(
|
||||
VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f);
|
||||
break;
|
||||
case 6:
|
||||
WeaponCooldown -= 0.1f;
|
||||
Damage += 1;
|
||||
break;
|
||||
case 7:
|
||||
Range *= 1.2f;
|
||||
SphereComponent->SetSphereRadius(Range);
|
||||
Damage += 1.0f;
|
||||
VisualEffectMeshComponent->SetWorldScale3D(
|
||||
VisualEffectMeshComponent->GetComponentTransform().GetScale3D() * 1.2f);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
ResetWeaponTimer();
|
||||
|
@ -27,7 +27,8 @@ UCLASS()
|
||||
class VAMPIRES_API AGarlicWeapon : public AWeapon
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
|
||||
protected:
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"), Category = "Weapon | Garlic")
|
||||
TObjectPtr<USphereComponent> SphereComponent;
|
||||
|
||||
@ -38,6 +39,7 @@ public:
|
||||
|
||||
private:
|
||||
float Range;
|
||||
|
||||
public:
|
||||
AGarlicWeapon();
|
||||
|
||||
|
@ -29,7 +29,10 @@ void AGunWeapon::FireWeaponAction_Implementation()
|
||||
|
||||
bool AGunWeapon::UpgradeWeapon_Implementation()
|
||||
{
|
||||
if (!Super::UpgradeWeapon_Implementation()) return false;
|
||||
if (!Super::UpgradeWeapon_Implementation())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (CurrentLevel)
|
||||
{
|
||||
@ -67,11 +70,11 @@ void AGunWeapon::FireProjectile()
|
||||
{
|
||||
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;
|
||||
GEngine->GameViewport->GetViewportSize(ViewportSize);
|
||||
@ -92,20 +95,20 @@ void AGunWeapon::FireProjectile()
|
||||
PlayerController->DeprojectScreenPositionToWorld(ViewportSize.X, ViewportSize.Y, BottomRight,
|
||||
BottomRightDir);
|
||||
|
||||
FVector actorLocation = GetActorLocation();
|
||||
TopLeft.Z = actorLocation.Z;
|
||||
TopRight.Z = actorLocation.Z;
|
||||
BottomLeft.Z = actorLocation.Z;
|
||||
BottomRight.Z = actorLocation.Z;
|
||||
FVector ActorLocation = GetActorLocation();
|
||||
TopLeft.Z = ActorLocation.Z;
|
||||
TopRight.Z = ActorLocation.Z;
|
||||
BottomLeft.Z = ActorLocation.Z;
|
||||
BottomRight.Z = ActorLocation.Z;
|
||||
|
||||
AActor* projectile = objectPoolManager->GetObject();
|
||||
SpawnProjectile(projectile, UKismetMathLibrary::GetDirectionUnitVector(actorLocation, TopLeft));
|
||||
projectile = objectPoolManager->GetObject();
|
||||
SpawnProjectile(projectile, UKismetMathLibrary::GetDirectionUnitVector(actorLocation, TopRight));
|
||||
projectile = objectPoolManager->GetObject();
|
||||
SpawnProjectile(projectile, UKismetMathLibrary::GetDirectionUnitVector(actorLocation, BottomLeft));
|
||||
projectile = objectPoolManager->GetObject();
|
||||
SpawnProjectile(projectile, UKismetMathLibrary::GetDirectionUnitVector(actorLocation, BottomRight));
|
||||
AActor* projectile = ObjectPoolManager->GetObject();
|
||||
SpawnProjectile(projectile, UKismetMathLibrary::GetDirectionUnitVector(ActorLocation, TopLeft));
|
||||
projectile = ObjectPoolManager->GetObject();
|
||||
SpawnProjectile(projectile, UKismetMathLibrary::GetDirectionUnitVector(ActorLocation, TopRight));
|
||||
projectile = ObjectPoolManager->GetObject();
|
||||
SpawnProjectile(projectile, UKismetMathLibrary::GetDirectionUnitVector(ActorLocation, BottomLeft));
|
||||
projectile = ObjectPoolManager->GetObject();
|
||||
SpawnProjectile(projectile, UKismetMathLibrary::GetDirectionUnitVector(ActorLocation, BottomRight));
|
||||
|
||||
Super::FireProjectile();
|
||||
}
|
||||
@ -113,12 +116,12 @@ void AGunWeapon::FireProjectile()
|
||||
}
|
||||
}
|
||||
|
||||
void AGunWeapon::SpawnProjectile(AActor* projectile, FVector direction)
|
||||
void AGunWeapon::SpawnProjectile(AActor* Projectile, const FVector& Direction)
|
||||
{
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(projectile, UProjectilable::StaticClass()))
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(Projectile, UProjectilable::StaticClass()))
|
||||
{
|
||||
IProjectilable::Execute_LoadDataFromDataAsset(projectile, ProjectileTemplate);
|
||||
projectile->SetOwner(this);
|
||||
IProjectilable::Execute_SetTargetDirection(projectile, direction);
|
||||
IProjectilable::Execute_LoadDataFromDataAsset(Projectile, ProjectileTemplate);
|
||||
Projectile->SetOwner(this);
|
||||
IProjectilable::Execute_SetTargetDirection(Projectile, Direction);
|
||||
}
|
||||
}
|
||||
|
@ -29,5 +29,5 @@ protected:
|
||||
virtual void FireProjectile() override;
|
||||
|
||||
private:
|
||||
void SpawnProjectile(AActor* projectile, FVector direction);
|
||||
void SpawnProjectile(AActor* Projectile, const FVector& Direction);
|
||||
};
|
||||
|
@ -27,35 +27,38 @@ void AKnifeWeapon::FireWeaponAction_Implementation()
|
||||
|
||||
bool AKnifeWeapon::UpgradeWeapon_Implementation()
|
||||
{
|
||||
if (!Super::UpgradeWeapon_Implementation()) return false;
|
||||
if (!Super::UpgradeWeapon_Implementation())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (CurrentLevel)
|
||||
{
|
||||
case 1:
|
||||
ProjectilesPerActivation++;
|
||||
break;
|
||||
case 2:
|
||||
ProjectilesPerActivation++;
|
||||
Damage += 5.0f;
|
||||
break;
|
||||
case 3:
|
||||
ProjectilesPerActivation++;
|
||||
break;
|
||||
case 4:
|
||||
ProjectileTemplate->DamageableEnemies++;
|
||||
break;
|
||||
case 5:
|
||||
ProjectilesPerActivation++;
|
||||
break;
|
||||
case 6:
|
||||
ProjectilesPerActivation++;
|
||||
Damage += 5.0f;
|
||||
break;
|
||||
case 7:
|
||||
ProjectileTemplate->DamageableEnemies++;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
case 1:
|
||||
ProjectilesPerActivation++;
|
||||
break;
|
||||
case 2:
|
||||
ProjectilesPerActivation++;
|
||||
Damage += 5.0f;
|
||||
break;
|
||||
case 3:
|
||||
ProjectilesPerActivation++;
|
||||
break;
|
||||
case 4:
|
||||
ProjectileTemplate->DamageableEnemies++;
|
||||
break;
|
||||
case 5:
|
||||
ProjectilesPerActivation++;
|
||||
break;
|
||||
case 6:
|
||||
ProjectilesPerActivation++;
|
||||
Damage += 5.0f;
|
||||
break;
|
||||
case 7:
|
||||
ProjectileTemplate->DamageableEnemies++;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -67,24 +70,24 @@ void AKnifeWeapon::FireProjectile()
|
||||
{
|
||||
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);
|
||||
projectile->SetOwner(this);
|
||||
IProjectilable::Execute_LoadDataFromDataAsset(Projectile, ProjectileTemplate);
|
||||
Projectile->SetOwner(this);
|
||||
|
||||
FVector direction = FVector(IInputable::Execute_Input_GetPreviousMovementDirection(GetOwner()),
|
||||
FVector Direction = FVector(IInputable::Execute_Input_GetPreviousMovementDirection(GetOwner()),
|
||||
0.0);
|
||||
direction.Normalize();
|
||||
Direction.Normalize();
|
||||
|
||||
IProjectilable::Execute_SetTargetDirection(projectile, direction);
|
||||
IProjectilable::Execute_SetTargetDirection(Projectile, Direction);
|
||||
}
|
||||
|
||||
Super::FireProjectile();
|
||||
|
@ -21,40 +21,40 @@ void ALightningRingWeapon::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;
|
||||
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(),
|
||||
target->GetActorLocation(),
|
||||
Target->GetActorLocation(),
|
||||
LightingBoltRadius,
|
||||
traceObjectTypes,
|
||||
AEnemyCharacter::StaticClass(),
|
||||
actorsToIgnore,
|
||||
hitResults);
|
||||
ActorsToIgnore,
|
||||
HitResults);
|
||||
|
||||
if (LightningEffectSystem)
|
||||
{
|
||||
float scale = FMath::FloorToFloat((CurrentLevel + 2.0f) / 2.0f);
|
||||
UNiagaraFunctionLibrary::SpawnSystemAtLocation(this, LightningEffectSystem, target->GetActorLocation(),
|
||||
GetActorRotation(), FVector(scale));
|
||||
float Scale = FMath::FloorToFloat((CurrentLevel + 2.0f) / 2.0f);
|
||||
UNiagaraFunctionLibrary::SpawnSystemAtLocation(this, LightningEffectSystem, Target->GetActorLocation(),
|
||||
GetActorRotation(), FVector(Scale));
|
||||
}
|
||||
|
||||
for (AActor* EnemyHitResult : hitResults)
|
||||
for (AActor* EnemyHitResult : HitResults)
|
||||
{
|
||||
UGameplayStatics::ApplyDamage(EnemyHitResult, Damage, nullptr, this, nullptr);
|
||||
}
|
||||
|
||||
targetableEnemies.Remove(target);
|
||||
TargetableEnemies.Remove(Target);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ class VAMPIRES_API ALightningRingWeapon : public AWeapon
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
protected:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon | Lightning Ring")
|
||||
int LightningBolts = 1;
|
||||
|
||||
@ -27,10 +27,8 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon | Lightning Ring")
|
||||
TObjectPtr<UNiagaraSystem> LightningEffectSystem;
|
||||
|
||||
public:
|
||||
ALightningRingWeapon();
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
|
@ -27,33 +27,36 @@ void AMagicWandWeapon::FireWeaponAction_Implementation()
|
||||
|
||||
bool AMagicWandWeapon::UpgradeWeapon_Implementation()
|
||||
{
|
||||
if (!Super::UpgradeWeapon_Implementation()) return false;
|
||||
if (!Super::UpgradeWeapon_Implementation())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (CurrentLevel)
|
||||
{
|
||||
case 1:
|
||||
ProjectilesPerActivation++;
|
||||
break;
|
||||
case 2:
|
||||
WeaponCooldown -= 0.2;
|
||||
break;
|
||||
case 3:
|
||||
ProjectilesPerActivation++;
|
||||
break;
|
||||
case 4:
|
||||
Damage += 10;
|
||||
break;
|
||||
case 5:
|
||||
ProjectilesPerActivation++;
|
||||
break;
|
||||
case 6:
|
||||
ProjectileTemplate->DamageableEnemies++;
|
||||
break;
|
||||
case 7:
|
||||
Damage += 10;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
case 1:
|
||||
ProjectilesPerActivation++;
|
||||
break;
|
||||
case 2:
|
||||
WeaponCooldown -= 0.2;
|
||||
break;
|
||||
case 3:
|
||||
ProjectilesPerActivation++;
|
||||
break;
|
||||
case 4:
|
||||
Damage += 10;
|
||||
break;
|
||||
case 5:
|
||||
ProjectilesPerActivation++;
|
||||
break;
|
||||
case 6:
|
||||
ProjectileTemplate->DamageableEnemies++;
|
||||
break;
|
||||
case 7:
|
||||
Damage += 10;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
ResetWeaponTimer();
|
||||
@ -65,30 +68,29 @@ void AMagicWandWeapon::FireProjectile()
|
||||
{
|
||||
if (ProjectileTemplate && OverlappedEnemies.Num() > 0)
|
||||
{
|
||||
float distance = 0.0f;
|
||||
AActor* nearestActor = UGameplayStatics::FindNearestActor(GetActorLocation(), OverlappedEnemies, distance);
|
||||
float Distance = 0.0f;
|
||||
|
||||
if (nearestActor)
|
||||
if (AActor* nearestActor = UGameplayStatics::FindNearestActor(GetActorLocation(), OverlappedEnemies, Distance))
|
||||
{
|
||||
AGameModeBase* gamemode = UGameplayStatics::GetGameMode(GetWorld());
|
||||
AGameModeBase* Gamemode = UGameplayStatics::GetGameMode(GetWorld());
|
||||
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(gamemode, UPools::StaticClass()))
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(Gamemode, UPools::StaticClass()))
|
||||
{
|
||||
if (AObjectPoolManager* objectPoolManager = IPools::Execute_GetProjectileObjectPoolManager(gamemode))
|
||||
if (AObjectPoolManager* ObjectPoolManager = IPools::Execute_GetProjectileObjectPoolManager(Gamemode))
|
||||
{
|
||||
AActor* projectile = objectPoolManager->GetObject();
|
||||
AActor* Projectile = ObjectPoolManager->GetObject();
|
||||
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(projectile, UProjectilable::StaticClass()))
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(Projectile, UProjectilable::StaticClass()))
|
||||
{
|
||||
IProjectilable::Execute_LoadDataFromDataAsset(projectile, ProjectileTemplate);
|
||||
projectile->SetOwner(this);
|
||||
IProjectilable::Execute_LoadDataFromDataAsset(Projectile, ProjectileTemplate);
|
||||
Projectile->SetOwner(this);
|
||||
|
||||
FVector direction = UKismetMathLibrary::GetDirectionUnitVector(
|
||||
FVector Direction = UKismetMathLibrary::GetDirectionUnitVector(
|
||||
GetActorLocation(), nearestActor->GetActorLocation());
|
||||
direction.Z = 0.0;
|
||||
direction.Normalize();
|
||||
Direction.Z = 0.0;
|
||||
Direction.Normalize();
|
||||
|
||||
IProjectilable::Execute_SetTargetDirection(projectile, direction);
|
||||
IProjectilable::Execute_SetTargetDirection(Projectile, Direction);
|
||||
}
|
||||
|
||||
Super::FireProjectile();
|
||||
|
@ -25,6 +25,6 @@ public:
|
||||
|
||||
virtual bool UpgradeWeapon_Implementation() override;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual void FireProjectile() override;
|
||||
};
|
||||
|
@ -36,7 +36,10 @@ void APentagramWeapon::FireWeaponAction_Implementation()
|
||||
|
||||
bool APentagramWeapon::UpgradeWeapon_Implementation()
|
||||
{
|
||||
if (!Super::UpgradeWeapon_Implementation()) return false;
|
||||
if (!Super::UpgradeWeapon_Implementation())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (CurrentLevel)
|
||||
{
|
||||
@ -71,20 +74,22 @@ bool APentagramWeapon::UpgradeWeapon_Implementation()
|
||||
}
|
||||
|
||||
void APentagramWeapon::OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||
const FHitResult& SweepResult)
|
||||
{
|
||||
if (APickup* Pickup = Cast<APickup>(OtherActor))
|
||||
if (APickup* Pickup = Cast<APickup>(OtherActor))
|
||||
{
|
||||
OverlappedPickups.Add(Pickup);
|
||||
}
|
||||
else
|
||||
{
|
||||
Super::OnWeaponBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
Super::OnWeaponBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep,
|
||||
SweepResult);
|
||||
}
|
||||
}
|
||||
|
||||
void APentagramWeapon::OnWeaponEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
|
||||
{
|
||||
if (APickup* Pickup = Cast<APickup>(OtherActor))
|
||||
{
|
||||
|
@ -17,7 +17,6 @@ class VAMPIRES_API APentagramWeapon : public AWeapon
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
private:
|
||||
TArray<TObjectPtr<APickup>> OverlappedPickups = TArray<TObjectPtr<APickup>>();
|
||||
|
||||
public:
|
||||
@ -25,11 +24,12 @@ public:
|
||||
|
||||
virtual void FireWeaponAction_Implementation() override;
|
||||
|
||||
bool UpgradeWeapon_Implementation() override;
|
||||
virtual bool UpgradeWeapon_Implementation() override;
|
||||
|
||||
virtual void OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) override;
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||
const FHitResult& SweepResult) override;
|
||||
|
||||
virtual void OnWeaponEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) override;
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) override;
|
||||
};
|
||||
|
@ -47,12 +47,12 @@ void ASwarmAgent::OnSwarmAgentBeginOverlap(UPrimitiveComponent* OverlappedCompon
|
||||
|
||||
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();
|
||||
EnemyHealthComponent->TakeDamage(Enemy, ownerWeapon->GetDamage(), nullptr, ownerController, this);
|
||||
AController* OwnerController = Character->GetController();
|
||||
EnemyHealthComponent->TakeDamage(Enemy, OwnerWeapon->GetDamage(), nullptr, OwnerController, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ class VAMPIRES_API ASwarmAgent : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
TObjectPtr<USphereComponent> SphereComponent = nullptr;
|
||||
|
||||
@ -27,7 +27,6 @@ public:
|
||||
// Sets default values for this actor's properties
|
||||
ASwarmAgent();
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
|
@ -40,7 +40,7 @@ void ASwarmWeapon::BeginPlay()
|
||||
TimelineComponent->PlayFromStart();
|
||||
}
|
||||
|
||||
void ASwarmWeapon::TimelineCallback(float val)
|
||||
void ASwarmWeapon::TimelineCallback(float Val)
|
||||
{
|
||||
float num = SwarmActors.Num();
|
||||
|
||||
@ -50,7 +50,7 @@ void ASwarmWeapon::TimelineCallback(float val)
|
||||
float offset = (actorIndex / num) * 360.0f;
|
||||
FVector CenterLocation = GetActorLocation();
|
||||
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);
|
||||
NewLocation.Z = 190.0f;
|
||||
SwarmActors[i]->SetActorLocation(NewLocation);
|
||||
|
@ -14,20 +14,20 @@ class VAMPIRES_API ASwarmWeapon : public AWeapon
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Weapon | Swarm")
|
||||
TObjectPtr<UTimelineComponent> TimelineComponent = nullptr;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon | Swarm")
|
||||
TObjectPtr<UCurveFloat> SwarmCurve;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon | Swarm")
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon | Swarm")
|
||||
float TimelinePlayRate = 1;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon | Swarm")
|
||||
TSubclassOf<ASwarmAgent> SwarmActor;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon | Swarm")
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon | Swarm")
|
||||
float Distance = 250.0f;
|
||||
|
||||
private:
|
||||
@ -45,7 +45,7 @@ protected:
|
||||
|
||||
public:
|
||||
UFUNCTION()
|
||||
void TimelineCallback(float val);
|
||||
void TimelineCallback(float Val);
|
||||
|
||||
virtual bool UpgradeWeapon_Implementation() override;
|
||||
|
||||
|
@ -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);
|
||||
if (timeSinceStart / 60 < 10)
|
||||
FString Mins = FString::FromInt(TimeSinceStart / 60);
|
||||
if (TimeSinceStart / 60 < 10)
|
||||
{
|
||||
mins = "0" + mins;
|
||||
Mins = "0" + Mins;
|
||||
}
|
||||
|
||||
FString secs = FString::FromInt(timeSinceStart % 60);
|
||||
if (timeSinceStart % 60 < 10)
|
||||
FString Secs = FString::FromInt(TimeSinceStart % 60);
|
||||
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)));
|
||||
}
|
||||
|
@ -16,8 +16,7 @@ class VAMPIRES_API UHUDWidget : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
protected:
|
||||
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
||||
UProgressBar* EXPbar;
|
||||
|
||||
@ -35,19 +34,19 @@ public:
|
||||
|
||||
void Init();
|
||||
|
||||
public:
|
||||
UFUNCTION()
|
||||
void UpdateEXPBar(float currentLevelPercent);
|
||||
void UpdateEXPBar(float CurrentLevelPercent);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateLevelBlock(int level);
|
||||
void UpdateLevelBlock(int Level);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateTimerBlock(float deltaTime);
|
||||
void UpdateTimerBlock(float DeltaTime);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateKillBlock(int killCount);
|
||||
void UpdateKillBlock(int KillCount);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateGoldBlock(int goldCount);
|
||||
|
||||
void UpdateGoldBlock(int GoldCount);
|
||||
};
|
||||
|
@ -12,23 +12,23 @@ void UHealthbarWidget::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({});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "HealthbarWidget.generated.h"
|
||||
|
||||
struct FDamageInfo;
|
||||
class UProgressBar;
|
||||
/**
|
||||
*
|
||||
@ -15,13 +16,13 @@ class VAMPIRES_API UHealthbarWidget : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
protected:
|
||||
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
||||
UProgressBar* HealthBar;
|
||||
TObjectPtr<UProgressBar> HealthBar;
|
||||
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
private:
|
||||
UFUNCTION()
|
||||
void UpdateHealthBar(FDamageInfo damageInfo);
|
||||
void UpdateHealthBar(FDamageInfo DamageInfo);
|
||||
};
|
||||
|
@ -40,50 +40,50 @@ void ULevelUpWidget::NativeConstruct()
|
||||
TArray<AWeapon*> Inventory = InventoryComponent->GetInventory();
|
||||
|
||||
// Get list of weapons that the player owns that can be upgraded
|
||||
TArray<UUpgradeButtonDataObject*> upgradeItems;
|
||||
for (AWeapon* weapon : Inventory)
|
||||
TArray<UUpgradeButtonDataObject*> UpgradeItems;
|
||||
for (AWeapon* Weapon : Inventory)
|
||||
{
|
||||
if (weapon->GetWeaponLevel() < weapon->GetUpgradeDescriptions().Num())
|
||||
if (Weapon->GetWeaponLevel() < Weapon->GetUpgradeDescriptions().Num())
|
||||
{
|
||||
UUpgradeButtonDataObject* Temp = NewObject<UUpgradeButtonDataObject>(this);
|
||||
Temp->SetData(weapon, this);
|
||||
upgradeItems.Add(Temp);
|
||||
Temp->SetData(Weapon, this);
|
||||
UpgradeItems.Add(Temp);
|
||||
}
|
||||
}
|
||||
|
||||
// Get list of weapons that the player can still obtain
|
||||
TArray<TSubclassOf<AWeapon>> ObtainableWeapons = InventoryComponent->obtainableWeapons;
|
||||
for (TSubclassOf<AWeapon> weapon : ObtainableWeapons)
|
||||
TArray<TSubclassOf<AWeapon>> ObtainableWeapons = InventoryComponent->ObtainableWeapons;
|
||||
for (TSubclassOf<AWeapon> Weapon : ObtainableWeapons)
|
||||
{
|
||||
UUpgradeButtonDataObject* Temp = NewObject<UUpgradeButtonDataObject>(this);
|
||||
Temp->SetData(weapon, this);
|
||||
upgradeItems.Add(Temp);
|
||||
Temp->SetData(Weapon, this);
|
||||
UpgradeItems.Add(Temp);
|
||||
}
|
||||
|
||||
// If no valid options exist, populate list with default options
|
||||
if (upgradeItems.Num() == 0)
|
||||
if (UpgradeItems.Num() == 0)
|
||||
{
|
||||
UUpgradeButtonDataObject* tempHealth = NewObject<UUpgradeButtonDataObject>(this);
|
||||
tempHealth->SetData(FText::FromString("Health"),
|
||||
FText::FromString("Recover 10% of your health"),
|
||||
nullptr,
|
||||
this);
|
||||
upgradeItems.Add(tempHealth);
|
||||
UUpgradeButtonDataObject* TempHealth = NewObject<UUpgradeButtonDataObject>(this);
|
||||
TempHealth->SetData(FText::FromString("Health"),
|
||||
FText::FromString("Recover 10% of your health"),
|
||||
nullptr,
|
||||
this);
|
||||
UpgradeItems.Add(TempHealth);
|
||||
|
||||
UUpgradeButtonDataObject* tempGold = NewObject<UUpgradeButtonDataObject>(this);
|
||||
tempGold->SetData(FText::FromString("Gold"),
|
||||
FText::FromString("Gain 10 gold"),
|
||||
nullptr,
|
||||
this);
|
||||
upgradeItems.Add(tempGold);
|
||||
UUpgradeButtonDataObject* TempGold = NewObject<UUpgradeButtonDataObject>(this);
|
||||
TempGold->SetData(FText::FromString("Gold"),
|
||||
FText::FromString("Gain 10 gold"),
|
||||
nullptr,
|
||||
this);
|
||||
UpgradeItems.Add(TempGold);
|
||||
}
|
||||
|
||||
// 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);
|
||||
UpgradesListView->AddItem(upgradeItems[rand]);
|
||||
upgradeItems.RemoveAt(rand);
|
||||
int Rand = FMath::RandRange(0, UpgradeItems.Num() - 1);
|
||||
UpgradesListView->AddItem(UpgradeItems[Rand]);
|
||||
UpgradeItems.RemoveAt(Rand);
|
||||
}
|
||||
}
|
||||
SetIsFocusable(true);
|
||||
@ -93,11 +93,11 @@ void ULevelUpWidget::ResumeButtonClicked()
|
||||
{
|
||||
RemoveFromParent();
|
||||
|
||||
if (APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
||||
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
||||
{
|
||||
UWidgetBlueprintLibrary::SetInputMode_GameOnly(playerController);
|
||||
playerController->bShowMouseCursor = false;
|
||||
playerController->SetPause(false);
|
||||
UWidgetBlueprintLibrary::SetInputMode_GameOnly(PlayerController);
|
||||
PlayerController->bShowMouseCursor = false;
|
||||
PlayerController->SetPause(false);
|
||||
}
|
||||
|
||||
SetIsFocusable(false);
|
||||
|
@ -17,8 +17,7 @@ class VAMPIRES_API ULevelUpWidget : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
protected:
|
||||
UPROPERTY(BlueprintReadWrite, meta=(BindWidget))
|
||||
UButton* ResumeButton;
|
||||
|
||||
@ -28,7 +27,6 @@ public:
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
private:
|
||||
|
||||
UFUNCTION()
|
||||
void ResumeButtonClicked();
|
||||
};
|
||||
|
@ -51,27 +51,14 @@ void UMainMenuWidget::NewGameButtonOnClicked()
|
||||
{
|
||||
RemoveFromParent();
|
||||
|
||||
UUserWidget* selectWeaponWidget = CreateWidget<UUserWidget, APlayerController*>(
|
||||
UUserWidget* SelectWeaponWidget = CreateWidget<UUserWidget, APlayerController*>(
|
||||
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()
|
||||
|
@ -17,7 +17,7 @@ class VAMPIRES_API UMainMenuWidget : public UVampireInteractiveWidget
|
||||
|
||||
// TODO: Add options menu
|
||||
|
||||
public:
|
||||
protected:
|
||||
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
||||
TObjectPtr<UButton> NewGameButton;
|
||||
|
||||
@ -38,7 +38,7 @@ public:
|
||||
|
||||
private:
|
||||
UPROPERTY()
|
||||
TObjectPtr<UUserWidget> currentNewGameWidget;
|
||||
TObjectPtr<UUserWidget> CurrentNewGameWidget;
|
||||
|
||||
public:
|
||||
virtual void NativeConstruct() override;
|
||||
|
@ -27,11 +27,11 @@ void UPauseWidget::ResumeButtonClicked()
|
||||
{
|
||||
RemoveFromParent();
|
||||
|
||||
if (APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
||||
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
||||
{
|
||||
UWidgetBlueprintLibrary::SetInputMode_GameOnly(playerController);
|
||||
playerController->bShowMouseCursor = false;
|
||||
playerController->SetPause(false);
|
||||
UWidgetBlueprintLibrary::SetInputMode_GameOnly(PlayerController);
|
||||
PlayerController->bShowMouseCursor = false;
|
||||
PlayerController->SetPause(false);
|
||||
}
|
||||
|
||||
SetIsFocusable(false);
|
||||
|
@ -16,7 +16,6 @@ class VAMPIRES_API UPauseWidget : public UUserWidget
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, meta=(BindWidget))
|
||||
UButton* ResumeButton;
|
||||
|
||||
@ -25,7 +24,6 @@ public:
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
private:
|
||||
|
||||
UFUNCTION()
|
||||
void ResumeButtonClicked();
|
||||
};
|
||||
|
@ -29,10 +29,10 @@ void USelectWeaponWidget::NativeConstruct()
|
||||
if (UpgradesListView)
|
||||
{
|
||||
// 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);
|
||||
Temp->SetData(weapon, this);
|
||||
Temp->SetData(Weapon, this);
|
||||
UpgradesListView->AddItem(Temp);
|
||||
}
|
||||
}
|
||||
@ -44,12 +44,12 @@ void USelectWeaponWidget::BackButtonClicked()
|
||||
{
|
||||
RemoveFromParent();
|
||||
|
||||
UUserWidget* selectWeaponWidget = CreateWidget<UUserWidget, APlayerController*>(
|
||||
UUserWidget* SelectWeaponWidget = CreateWidget<UUserWidget, APlayerController*>(
|
||||
UGameplayStatics::GetPlayerController(GetWorld(), 0), PreviousWidget);
|
||||
|
||||
if (selectWeaponWidget)
|
||||
if (SelectWeaponWidget)
|
||||
{
|
||||
selectWeaponWidget->AddToViewport();
|
||||
SelectWeaponWidget->AddToViewport();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ UCLASS()
|
||||
class VAMPIRES_API USelectWeaponWidget : public UVampireInteractiveWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
protected:
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, meta=(BindWidget))
|
||||
TObjectPtr<UButton> BackButton;
|
||||
@ -29,7 +29,7 @@ public:
|
||||
TObjectPtr<UListView> UpgradesListView;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TArray<TSubclassOf<AWeapon>> starterWeapons;
|
||||
TArray<TSubclassOf<AWeapon>> StarterWeapons;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
TSubclassOf<class UUserWidget> PreviousWidget;
|
||||
|
@ -5,29 +5,29 @@
|
||||
|
||||
#include "vampires/Weapon.h"
|
||||
|
||||
void UStarterWeaponButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* parent)
|
||||
void UStarterWeaponButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* ParentWidget)
|
||||
{
|
||||
WeaponName = Weapon->GetWeaponName();
|
||||
Description = Weapon->GetDescription();
|
||||
WeaponDescription = Weapon->GetDescription();
|
||||
WeaponIcon = Weapon->GetIcon();
|
||||
WeaponInstance = Weapon;
|
||||
Parent = parent;
|
||||
Parent = ParentWidget;
|
||||
}
|
||||
|
||||
void UStarterWeaponButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent)
|
||||
void UStarterWeaponButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* ParentWidget)
|
||||
{
|
||||
if (AWeapon* tempWeapon = NewObject<AWeapon>(this, Weapon))
|
||||
{
|
||||
SetData(tempWeapon, parent);
|
||||
SetData(tempWeapon, ParentWidget);
|
||||
WeaponTemplate = Weapon;
|
||||
}
|
||||
}
|
||||
|
||||
void UStarterWeaponButtonDataObject::SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon,
|
||||
UUserWidget* parent)
|
||||
void UStarterWeaponButtonDataObject::SetData(FText NewWeaponName, FText NewWeaponDescription, TObjectPtr<UTexture2D> NewWeaponIcon,
|
||||
UUserWidget* ParentWidget)
|
||||
{
|
||||
WeaponName = weaponName;
|
||||
Description = description;
|
||||
WeaponIcon = weaponIcon;
|
||||
Parent = parent;
|
||||
WeaponName = NewWeaponName;
|
||||
WeaponDescription = NewWeaponDescription;
|
||||
WeaponIcon = NewWeaponIcon;
|
||||
Parent = ParentWidget;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public:
|
||||
FText WeaponName;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
FText Description;
|
||||
FText WeaponDescription;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TObjectPtr<UTexture2D> WeaponIcon;
|
||||
@ -33,7 +33,7 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TObjectPtr<UUserWidget> Parent;
|
||||
|
||||
void SetData(AWeapon* Weapon, UUserWidget* parent);
|
||||
void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent);
|
||||
void SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon, UUserWidget* parent);
|
||||
void SetData(AWeapon* Weapon, UUserWidget* ParentWidget);
|
||||
void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* ParentWidget);
|
||||
void SetData(FText NewWeaponName, FText NewWeaponDescription, TObjectPtr<UTexture2D> NewWeaponIcon, UUserWidget* ParentWidget);
|
||||
};
|
||||
|
@ -18,12 +18,10 @@ void UStarterWeaponButtonWidget::NativeConstruct()
|
||||
|
||||
void UStarterWeaponButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
||||
{
|
||||
UStarterWeaponButtonDataObject* Item = Cast<UStarterWeaponButtonDataObject>(ListItemObject);
|
||||
|
||||
if (Item)
|
||||
if (UStarterWeaponButtonDataObject* Item = Cast<UStarterWeaponButtonDataObject>(ListItemObject))
|
||||
{
|
||||
WeaponNameTextBlock->SetText(Item->WeaponName);
|
||||
DescriptionTextBlock->SetText(Item->Description);
|
||||
DescriptionTextBlock->SetText(Item->WeaponDescription);
|
||||
WeaponIcon->SetBrushFromTexture(Item->WeaponIcon);
|
||||
Parent = Item->Parent;
|
||||
WeaponTemplate = Item->WeaponTemplate;
|
||||
@ -43,13 +41,13 @@ void UStarterWeaponButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObje
|
||||
|
||||
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))
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ class VAMPIRES_API UStarterWeaponButtonWidget : public UVampireInteractiveWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
|
||||
TObjectPtr<UButton> Body;
|
||||
|
||||
@ -39,7 +39,6 @@ public:
|
||||
UPROPERTY()
|
||||
TObjectPtr<UUserWidget> Parent;
|
||||
|
||||
protected:
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
virtual void NativeOnListItemObjectSet(UObject* ListItemObject) override;
|
||||
|
@ -5,32 +5,32 @@
|
||||
|
||||
#include "vampires/Weapon.h"
|
||||
|
||||
void UUpgradeButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* parent)
|
||||
void UUpgradeButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* ParentWidget)
|
||||
{
|
||||
WeaponName = Weapon->GetWeaponName();
|
||||
WeaponIcon = Weapon->GetIcon();
|
||||
WeaponInstance = Weapon;
|
||||
Parent = parent;
|
||||
Parent = ParentWidget;
|
||||
|
||||
if (Weapon->GetUpgradeDescriptions().Num() > Weapon->GetWeaponLevel())
|
||||
{
|
||||
Description = Weapon->GetUpgradeDescriptions()[Weapon->GetWeaponLevel()];
|
||||
WeaponDescription = Weapon->GetUpgradeDescriptions()[Weapon->GetWeaponLevel()];
|
||||
}
|
||||
}
|
||||
|
||||
void UUpgradeButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent)
|
||||
void UUpgradeButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* ParentWidget)
|
||||
{
|
||||
if (AWeapon* tempWeapon = NewObject<AWeapon>(this, Weapon))
|
||||
{
|
||||
SetData(tempWeapon, parent);
|
||||
SetData(tempWeapon, ParentWidget);
|
||||
}
|
||||
}
|
||||
|
||||
void UUpgradeButtonDataObject::SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon,
|
||||
UUserWidget* parent)
|
||||
void UUpgradeButtonDataObject::SetData(FText NewWeaponName, FText NewDescription, TObjectPtr<UTexture2D> NewWeaponIcon,
|
||||
UUserWidget* ParentWidget)
|
||||
{
|
||||
WeaponName = weaponName;
|
||||
Description = description;
|
||||
WeaponIcon = weaponIcon;
|
||||
Parent = parent;
|
||||
WeaponName = NewWeaponName;
|
||||
WeaponDescription = NewDescription;
|
||||
WeaponIcon = NewWeaponIcon;
|
||||
Parent = ParentWidget;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public:
|
||||
FText WeaponName;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
FText Description;
|
||||
FText WeaponDescription;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TObjectPtr<UTexture2D> WeaponIcon;
|
||||
@ -34,7 +34,7 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TObjectPtr<UUserWidget> Parent;
|
||||
|
||||
void SetData(AWeapon* Weapon, UUserWidget* parent);
|
||||
void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent);
|
||||
void SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon, UUserWidget* parent);
|
||||
void SetData(AWeapon* Weapon, UUserWidget* ParentWidget);
|
||||
void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* ParentWidget);
|
||||
void SetData(FText NewWeaponName, FText NewDescription, TObjectPtr<UTexture2D> NewWeaponIcon, UUserWidget* ParentWidget);
|
||||
};
|
||||
|
@ -22,12 +22,10 @@ void UUpgradeButtonWidget::NativeConstruct()
|
||||
|
||||
void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
||||
{
|
||||
UUpgradeButtonDataObject* Item = Cast<UUpgradeButtonDataObject>(ListItemObject);
|
||||
|
||||
if (Item)
|
||||
if (UUpgradeButtonDataObject* Item = Cast<UUpgradeButtonDataObject>(ListItemObject))
|
||||
{
|
||||
WeaponNameTextBlock->SetText(Item->WeaponName);
|
||||
DescriptionTextBlock->SetText(Item->Description);
|
||||
DescriptionTextBlock->SetText(Item->WeaponDescription);
|
||||
WeaponIcon->SetBrushFromTexture(Item->WeaponIcon);
|
||||
Parent = Item->Parent;
|
||||
|
||||
@ -83,7 +81,7 @@ void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
||||
|
||||
void UUpgradeButtonWidget::OnClicked()
|
||||
{
|
||||
APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
||||
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
||||
|
||||
switch (UpgradeType)
|
||||
{
|
||||
@ -92,31 +90,29 @@ void UUpgradeButtonWidget::OnClicked()
|
||||
break;
|
||||
|
||||
case NewWeapon:
|
||||
if (UWeaponInventoryComponent* Inventory = playerController->GetPawn()->GetComponentByClass<
|
||||
UWeaponInventoryComponent>())
|
||||
if (UWeaponInventoryComponent* Inventory = PlayerController->GetPawn()->GetComponentByClass<UWeaponInventoryComponent>())
|
||||
{
|
||||
Inventory->AddWeaponToInventory(WeaponTemplate);
|
||||
Inventory->obtainableWeapons.Remove(WeaponTemplate);
|
||||
Inventory->ObtainableWeapons.Remove(WeaponTemplate);
|
||||
}
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
@ -129,11 +125,11 @@ void UUpgradeButtonWidget::OnClicked()
|
||||
{
|
||||
Parent->RemoveFromParent();
|
||||
|
||||
if (playerController)
|
||||
if (PlayerController)
|
||||
{
|
||||
UWidgetBlueprintLibrary::SetInputMode_GameOnly(playerController);
|
||||
playerController->bShowMouseCursor = false;
|
||||
playerController->SetPause(false);
|
||||
UWidgetBlueprintLibrary::SetInputMode_GameOnly(PlayerController);
|
||||
PlayerController->bShowMouseCursor = false;
|
||||
PlayerController->SetPause(false);
|
||||
}
|
||||
|
||||
Parent->SetIsFocusable(false);
|
||||
|
@ -31,7 +31,7 @@ class VAMPIRES_API UUpgradeButtonWidget : public UVampireInteractiveWidget, publ
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
|
||||
TObjectPtr<UButton> Body;
|
||||
|
||||
@ -86,5 +86,4 @@ private:
|
||||
|
||||
UFUNCTION()
|
||||
void OnUnhoveredDelegate() { SetTextBlockUnhovered(WeaponNameTextBlock); SetTextBlockUnhovered(DescriptionTextBlock); }
|
||||
|
||||
};
|
||||
|
@ -7,11 +7,11 @@
|
||||
#include "GameFramework/GameUserSettings.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
void UVampireInteractiveWidget::SetReturnScreen(UUserWidget* userWidget)
|
||||
void UVampireInteractiveWidget::SetReturnScreen(UUserWidget* UserWidget)
|
||||
{
|
||||
if (userWidget)
|
||||
if (UserWidget)
|
||||
{
|
||||
PreviousScreen = userWidget;
|
||||
PreviousScreen = UserWidget;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,8 +15,7 @@ class VAMPIRES_API UVampireInteractiveWidget : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
TObjectPtr<USoundBase> ButtonHoveredSound;
|
||||
|
||||
@ -37,9 +36,8 @@ protected:
|
||||
TObjectPtr<UUserWidget> PreviousScreen;
|
||||
|
||||
public:
|
||||
|
||||
UFUNCTION()
|
||||
void SetReturnScreen(UUserWidget* userWidget);
|
||||
void SetReturnScreen(UUserWidget* UserWidget);
|
||||
|
||||
protected:
|
||||
UFUNCTION()
|
||||
|
Loading…
x
Reference in New Issue
Block a user