diff --git a/Content/Player/BP_PlayerCharacter.uasset b/Content/Player/BP_PlayerCharacter.uasset index d0be04b..3ebe29e 100644 --- a/Content/Player/BP_PlayerCharacter.uasset +++ b/Content/Player/BP_PlayerCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:63c52d9b60aa76b546b5aeed774b52fcff5670b5335f2d4342a84836ab46c109 -size 31377 +oid sha256:ed02c56d36c506445c70988784cdd74204c3f299291a6ff66bb020d348dccb67 +size 32477 diff --git a/Source/vampires/PlayerCharacter.cpp b/Source/vampires/PlayerCharacter.cpp index 5b51953..a3df768 100644 --- a/Source/vampires/PlayerCharacter.cpp +++ b/Source/vampires/PlayerCharacter.cpp @@ -7,6 +7,7 @@ #include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" #include "InputMappingContext.h" +#include "Kismet/GameplayStatics.h" APlayerCharacter::APlayerCharacter() { @@ -29,11 +30,20 @@ APlayerCharacter::APlayerCharacter() // Create EXP Component EXPComponent = CreateDefaultSubobject(TEXT("EXP Component")); + + // Create Garlic Sphere Component + GarlicSphereComponent = CreateDefaultSubobject(TEXT("Garlic Sphere Component")); + GarlicSphereComponent->SetupAttachment(RootComponent); + GarlicSphereComponent->SetSphereRadius(150.0f); } void APlayerCharacter::BeginPlay() { Super::BeginPlay(); + + GarlicSphereComponent->OnComponentBeginOverlap.AddDynamic(this, &APlayerCharacter::OnGarlicBeginOverlap); + GarlicSphereComponent->OnComponentEndOverlap.AddDynamic(this, &APlayerCharacter::OnGarlicEndOverlap); + GetWorldTimerManager().SetTimer(GarlicTimerHandle, this, &APlayerCharacter::GarlicUpdate, GarlicUpdateTime, true); } void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) @@ -71,3 +81,46 @@ void APlayerCharacter::MovementCallback(const FInputActionInstance& Instance) AddMovementInput({1.0f, 0.0f, 0.0f}, vec2.X); } } + +void APlayerCharacter::OnGarlicBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, + const FHitResult& SweepResult) +{ + if (AEnemyCharacter* Enemy = Cast(OtherActor)) + { + OverlappedEnemies.Add(Enemy); + } +} + +void APlayerCharacter::OnGarlicEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) +{ + if (AEnemyCharacter* Enemy = Cast(OtherActor)) + { + OverlappedEnemies.Remove(Enemy); + } +} + +void APlayerCharacter::GarlicUpdate() +{ + for (int i = 0; i < OverlappedEnemies.Num(); i++) + { + bool deadCheck = false; + UHealthComponent* EnemyHealthComponent = OverlappedEnemies[i]->GetHealthComponent(); + + if (!EnemyHealthComponent->GetIsDead()) + { + if (EnemyHealthComponent->GetCurrentHealth() < GarlicDamage) + { + deadCheck = true; + } + + EnemyHealthComponent->TakeDamage(OverlappedEnemies[i], GarlicDamage, nullptr, GetController(), this); + } + + if (deadCheck) + { + i -= 1; + } + } +} diff --git a/Source/vampires/PlayerCharacter.h b/Source/vampires/PlayerCharacter.h index e8bfc18..bbb29ac 100644 --- a/Source/vampires/PlayerCharacter.h +++ b/Source/vampires/PlayerCharacter.h @@ -3,9 +3,11 @@ #pragma once #include "CoreMinimal.h" +#include "EnemyCharacter.h" #include "EXPComponent.h" #include "VampireCharacter.h" #include "Camera/CameraComponent.h" +#include "Components/SphereComponent.h" #include "GameFramework/SpringArmComponent.h" #include "PlayerCharacter.generated.h" @@ -33,11 +35,25 @@ public: UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UInputAction* MovementAction; -protected: + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + float GarlicDamage = 51.0f; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + float GarlicUpdateTime = 1.0f; + +protected: UPROPERTY() UEXPComponent* EXPComponent; + UPROPERTY(VisibleAnywhere) + USphereComponent* GarlicSphereComponent; + + UPROPERTY() + TArray OverlappedEnemies; + +private: + FTimerHandle GarlicTimerHandle; + public: APlayerCharacter(); @@ -50,4 +66,16 @@ public: private: UFUNCTION() void MovementCallback(const FInputActionInstance& Instance); + + UFUNCTION() + void OnGarlicBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, + const FHitResult& SweepResult); + + UFUNCTION() + void OnGarlicEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, + int32 OtherBodyIndex); + + UFUNCTION() + void GarlicUpdate(); };