Compare commits
	
		
			3 Commits
		
	
	
		
			3f089caa33
			...
			d9dba81c7e
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| d9dba81c7e | |||
| b8f08e83cc | |||
| b054db1478 | 
							
								
								
									
										
											BIN
										
									
								
								Content/Weapons/BP_ExampleWeapon.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Weapons/BP_ExampleWeapon.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/Weapons/FireWand/BP_FireWandWeapon.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Weapons/FireWand/BP_FireWandWeapon.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/Weapons/Knife/BP_KnifeWeapon.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Weapons/Knife/BP_KnifeWeapon.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -79,11 +79,11 @@ UGoldComponent* APlayerCharacter::GetGoldComponent() | |||||||
| 
 | 
 | ||||||
| void APlayerCharacter::MovementCallback(const FInputActionInstance& Instance) | void APlayerCharacter::MovementCallback(const FInputActionInstance& Instance) | ||||||
| { | { | ||||||
| 	FVector2D vec2 = Instance.GetValue().Get<FVector2D>(); | 	PreviousMovementDirection = Instance.GetValue().Get<FVector2D>(); | ||||||
| 
 | 
 | ||||||
| 	if (vec2.Size() != 0.0f) | 	if (PreviousMovementDirection.Size() != 0.0f) | ||||||
| 	{ | 	{ | ||||||
| 		AddMovementInput({0.0f, 1.0f, 0.0f}, vec2.Y); | 		AddMovementInput({0.0f, 1.0f, 0.0f}, PreviousMovementDirection.Y); | ||||||
| 		AddMovementInput({1.0f, 0.0f, 0.0f}, vec2.X); | 		AddMovementInput({1.0f, 0.0f, 0.0f}, PreviousMovementDirection.X); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -44,6 +44,8 @@ public: | |||||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite) | 	UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||||||
| 	UWeaponInventoryComponent* WeaponInventoryComponent; | 	UWeaponInventoryComponent* WeaponInventoryComponent; | ||||||
| 
 | 
 | ||||||
|  | 	FVector2D PreviousMovementDirection = FVector2d(1.0f, 0.0f); | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
| 	FTimerHandle GarlicTimerHandle; | 	FTimerHandle GarlicTimerHandle; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -3,8 +3,7 @@ | |||||||
| 
 | 
 | ||||||
| #include "Projectile.h" | #include "Projectile.h" | ||||||
| 
 | 
 | ||||||
| #include "EnemyCharacter.h" | #include "Weapons/ProjectileWeapon.h" | ||||||
| #include "Weapons/MagicWandWeapon.h" |  | ||||||
| 
 | 
 | ||||||
| // Sets default values
 | // Sets default values
 | ||||||
| AProjectile::AProjectile() | AProjectile::AProjectile() | ||||||
| @ -13,7 +12,7 @@ AProjectile::AProjectile() | |||||||
| 	PrimaryActorTick.bCanEverTick = true; | 	PrimaryActorTick.bCanEverTick = true; | ||||||
| 
 | 
 | ||||||
| 	SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component")); | 	SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component")); | ||||||
| 	SphereComponent->SetupAttachment(RootComponent); | 	SetRootComponent(SphereComponent); | ||||||
| 	SphereComponent->SetSphereRadius(50.0f); | 	SphereComponent->SetSphereRadius(50.0f); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -21,8 +20,8 @@ AProjectile::AProjectile() | |||||||
| void AProjectile::BeginPlay() | void AProjectile::BeginPlay() | ||||||
| { | { | ||||||
| 	Super::BeginPlay(); | 	Super::BeginPlay(); | ||||||
| 	AMagicWandWeapon* OwnerWeapon = Cast<AMagicWandWeapon>(GetOwner());  | 	AProjectileWeapon* OwnerWeapon = Cast<AProjectileWeapon>(GetOwner());  | ||||||
| 	SphereComponent->OnComponentBeginOverlap.AddDynamic(OwnerWeapon, &AMagicWandWeapon::OnProjectileBeginOverlap); | 	SphereComponent->OnComponentBeginOverlap.AddDynamic(OwnerWeapon, &AProjectileWeapon::OnProjectileBeginOverlap); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Called every frame
 | // Called every frame
 | ||||||
|  | |||||||
							
								
								
									
										39
									
								
								Source/vampires/Weapons/FireWandWeapon.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								Source/vampires/Weapons/FireWandWeapon.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,39 @@ | |||||||
|  | // Fill out your copyright notice in the Description page of Project Settings.
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | #include "FireWandWeapon.h" | ||||||
|  | 
 | ||||||
|  | #include "Kismet/KismetMathLibrary.h" | ||||||
|  | 
 | ||||||
|  | AFireWandWeapon::AFireWandWeapon() | ||||||
|  | { | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void AFireWandWeapon::BeginPlay() | ||||||
|  | { | ||||||
|  | 	Super::BeginPlay(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void AFireWandWeapon::FireWeaponAction_Implementation() | ||||||
|  | { | ||||||
|  | 	Super::FireWeaponAction_Implementation(); | ||||||
|  | 	 | ||||||
|  | 	if (IsValid(ProjectileTemplate) && OverlappedEnemies.Num() > 0) | ||||||
|  | 	{ | ||||||
|  | 		FActorSpawnParameters actorSpawnParameters; | ||||||
|  | 		actorSpawnParameters.Owner = this; | ||||||
|  | 		actorSpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; | ||||||
|  | 		actorSpawnParameters.TransformScaleMethod = ESpawnActorScaleMethod::MultiplyWithRoot; | ||||||
|  | 		 | ||||||
|  | 		AProjectile* projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(), | ||||||
|  | 																	  actorSpawnParameters); | ||||||
|  | 
 | ||||||
|  | 		AActor* target = OverlappedEnemies[FMath::RandRange(0, OverlappedEnemies.Num() - 1)]; | ||||||
|  | 		FVector direction = UKismetMathLibrary::GetDirectionUnitVector( | ||||||
|  | 			GetActorLocation(), target->GetActorLocation()); | ||||||
|  | 		direction.Z = 0.0; | ||||||
|  | 		direction.Normalize(); | ||||||
|  | 
 | ||||||
|  | 		projectile->TargetDirection = direction; | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										25
									
								
								Source/vampires/Weapons/FireWandWeapon.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								Source/vampires/Weapons/FireWandWeapon.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,25 @@ | |||||||
|  | // Fill out your copyright notice in the Description page of Project Settings.
 | ||||||
|  | 
 | ||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include "CoreMinimal.h" | ||||||
|  | #include "ProjectileWeapon.h" | ||||||
|  | #include "FireWandWeapon.generated.h" | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  *  | ||||||
|  |  */ | ||||||
|  | UCLASS() | ||||||
|  | class VAMPIRES_API AFireWandWeapon : public AProjectileWeapon | ||||||
|  | { | ||||||
|  | 	GENERATED_BODY() | ||||||
|  | 
 | ||||||
|  | public: | ||||||
|  | 	AFireWandWeapon(); | ||||||
|  | 
 | ||||||
|  | protected: | ||||||
|  | 	virtual void BeginPlay() override; | ||||||
|  | 
 | ||||||
|  | public: | ||||||
|  | 	virtual void FireWeaponAction_Implementation() override; | ||||||
|  | }; | ||||||
							
								
								
									
										37
									
								
								Source/vampires/Weapons/KnifeWeapon.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								Source/vampires/Weapons/KnifeWeapon.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,37 @@ | |||||||
|  | // Fill out your copyright notice in the Description page of Project Settings.
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | #include "KnifeWeapon.h" | ||||||
|  | 
 | ||||||
|  | #include "Kismet/GameplayStatics.h" | ||||||
|  | #include "vampires/PlayerCharacter.h" | ||||||
|  | 
 | ||||||
|  | AKnifeWeapon::AKnifeWeapon() | ||||||
|  | { | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void AKnifeWeapon::BeginPlay() | ||||||
|  | { | ||||||
|  | 	Super::BeginPlay(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void AKnifeWeapon::FireWeaponAction_Implementation() | ||||||
|  | { | ||||||
|  | 	Super::FireWeaponAction_Implementation(); | ||||||
|  | 
 | ||||||
|  | 	APlayerCharacter* playerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)); | ||||||
|  | 	if (IsValid(ProjectileTemplate) && playerCharacter) | ||||||
|  | 	{ | ||||||
|  | 		FActorSpawnParameters actorSpawnParameters; | ||||||
|  | 		actorSpawnParameters.Owner = this; | ||||||
|  | 		actorSpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; | ||||||
|  | 		actorSpawnParameters.TransformScaleMethod = ESpawnActorScaleMethod::MultiplyWithRoot; | ||||||
|  | 
 | ||||||
|  | 		AProjectile* projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(), | ||||||
|  | 		                                                              actorSpawnParameters); | ||||||
|  | 
 | ||||||
|  | 		FVector direction = FVector(playerCharacter->PreviousMovementDirection, 0.0); | ||||||
|  | 		direction.Normalize(); | ||||||
|  | 		projectile->TargetDirection = direction; | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										25
									
								
								Source/vampires/Weapons/KnifeWeapon.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								Source/vampires/Weapons/KnifeWeapon.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,25 @@ | |||||||
|  | // Fill out your copyright notice in the Description page of Project Settings.
 | ||||||
|  | 
 | ||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include "CoreMinimal.h" | ||||||
|  | #include "ProjectileWeapon.h" | ||||||
|  | #include "KnifeWeapon.generated.h" | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  *  | ||||||
|  |  */ | ||||||
|  | UCLASS() | ||||||
|  | class VAMPIRES_API AKnifeWeapon : public AProjectileWeapon | ||||||
|  | { | ||||||
|  | 	GENERATED_BODY() | ||||||
|  | 
 | ||||||
|  | public: | ||||||
|  | 	AKnifeWeapon(); | ||||||
|  | 
 | ||||||
|  | protected: | ||||||
|  | 	virtual void BeginPlay() override; | ||||||
|  | 
 | ||||||
|  | public: | ||||||
|  | 	virtual void FireWeaponAction_Implementation() override; | ||||||
|  | }; | ||||||
| @ -5,20 +5,14 @@ | |||||||
| 
 | 
 | ||||||
| #include "Kismet/GameplayStatics.h" | #include "Kismet/GameplayStatics.h" | ||||||
| #include "Kismet/KismetMathLibrary.h" | #include "Kismet/KismetMathLibrary.h" | ||||||
| #include "vampires/EnemyCharacter.h" |  | ||||||
| 
 | 
 | ||||||
| AMagicWandWeapon::AMagicWandWeapon() | AMagicWandWeapon::AMagicWandWeapon() | ||||||
| { | { | ||||||
| 	SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component")); |  | ||||||
| 	SphereComponent->SetupAttachment(RootComponent); |  | ||||||
| 	SphereComponent->SetSphereRadius(1000.0f); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void AMagicWandWeapon::BeginPlay() | void AMagicWandWeapon::BeginPlay() | ||||||
| { | { | ||||||
| 	Super::BeginPlay(); | 	Super::BeginPlay(); | ||||||
| 	SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &AMagicWandWeapon::OnWeaponBeginOverlap); |  | ||||||
| 	SphereComponent->OnComponentEndOverlap.AddDynamic(this, &AMagicWandWeapon::OnWeaponEndOverlap); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void AMagicWandWeapon::FireWeaponAction_Implementation() | void AMagicWandWeapon::FireWeaponAction_Implementation() | ||||||
| @ -36,8 +30,8 @@ void AMagicWandWeapon::FireWeaponAction_Implementation() | |||||||
| 			actorSpawnParameters.Owner = this; | 			actorSpawnParameters.Owner = this; | ||||||
| 			actorSpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; | 			actorSpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; | ||||||
| 			actorSpawnParameters.TransformScaleMethod = ESpawnActorScaleMethod::MultiplyWithRoot; | 			actorSpawnParameters.TransformScaleMethod = ESpawnActorScaleMethod::MultiplyWithRoot; | ||||||
| 
 | 			 | ||||||
| 			AProjectile* projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetTransform(), | 			AProjectile* projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetOwner()->GetTransform(), | ||||||
| 			                                                              actorSpawnParameters); | 			                                                              actorSpawnParameters); | ||||||
| 			FVector direction = UKismetMathLibrary::GetDirectionUnitVector( | 			FVector direction = UKismetMathLibrary::GetDirectionUnitVector( | ||||||
| 				GetActorLocation(), nearestActor->GetActorLocation()); | 				GetActorLocation(), nearestActor->GetActorLocation()); | ||||||
| @ -47,45 +41,3 @@ void AMagicWandWeapon::FireWeaponAction_Implementation() | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 |  | ||||||
| void AMagicWandWeapon::OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, |  | ||||||
|                                             UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, |  | ||||||
|                                             const FHitResult& SweepResult) |  | ||||||
| { |  | ||||||
| 	if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor)) |  | ||||||
| 	{ |  | ||||||
| 		OverlappedEnemies.Add(Enemy); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void AMagicWandWeapon::OnWeaponEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, |  | ||||||
|                                           UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) |  | ||||||
| { |  | ||||||
| 	if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor)) |  | ||||||
| 	{ |  | ||||||
| 		OverlappedEnemies.Remove(Enemy); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void AMagicWandWeapon::OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, |  | ||||||
|                                                 UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, |  | ||||||
|                                                 const FHitResult& SweepResult) |  | ||||||
| { |  | ||||||
| 	if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor)) |  | ||||||
| 	{ |  | ||||||
| 		UHealthComponent* EnemyHealthComponent = Enemy->GetHealthComponent(); |  | ||||||
| 
 |  | ||||||
| 		if (!EnemyHealthComponent->GetIsDead()) |  | ||||||
| 		{ |  | ||||||
| 			AController* ownerController = nullptr; |  | ||||||
| 			if (AVampireCharacter* character = Cast<AVampireCharacter>(GetOwner())) |  | ||||||
| 			{ |  | ||||||
| 				ownerController = character->GetController(); |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			EnemyHealthComponent->TakeDamage(Enemy, Damage, nullptr, ownerController, this); |  | ||||||
| 
 |  | ||||||
| 			OverlappedComponent->GetAttachmentRootActor()->Destroy(); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  | |||||||
| @ -3,29 +3,17 @@ | |||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
| #include "CoreMinimal.h" | #include "CoreMinimal.h" | ||||||
| #include "../Weapon.h" | #include "ProjectileWeapon.h" | ||||||
| #include "Components/SphereComponent.h" |  | ||||||
| #include "vampires/Projectile.h" |  | ||||||
| #include "MagicWandWeapon.generated.h" | #include "MagicWandWeapon.generated.h" | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  *  |  *  | ||||||
|  */ |  */ | ||||||
| UCLASS() | UCLASS() | ||||||
| class VAMPIRES_API AMagicWandWeapon : public AWeapon | class VAMPIRES_API AMagicWandWeapon : public AProjectileWeapon | ||||||
| { | { | ||||||
| 	GENERATED_BODY() | 	GENERATED_BODY() | ||||||
| 
 | 
 | ||||||
| public: |  | ||||||
| 	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) |  | ||||||
| 	USphereComponent* SphereComponent = nullptr; |  | ||||||
| 
 |  | ||||||
| 	UPROPERTY(EditAnywhere, Category = "Weapon Properties") |  | ||||||
| 	TSubclassOf<AProjectile> ProjectileTemplate = nullptr; |  | ||||||
| 
 |  | ||||||
| private: |  | ||||||
| 	TArray<AActor*> OverlappedEnemies = TArray<AActor*>(); |  | ||||||
| 	 |  | ||||||
| public: | public: | ||||||
| 	AMagicWandWeapon(); | 	AMagicWandWeapon(); | ||||||
| 
 | 
 | ||||||
| @ -34,17 +22,4 @@ protected: | |||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
| 	virtual void FireWeaponAction_Implementation() override; | 	virtual void FireWeaponAction_Implementation() override; | ||||||
| 
 |  | ||||||
| 	UFUNCTION() |  | ||||||
| 	void OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, |  | ||||||
| 						UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, |  | ||||||
| 						const FHitResult& SweepResult); |  | ||||||
| 
 |  | ||||||
| 	UFUNCTION() |  | ||||||
| 	void OnWeaponEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, |  | ||||||
| 					  int32 OtherBodyIndex); |  | ||||||
| 	 |  | ||||||
| 	UFUNCTION() |  | ||||||
| 	void OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, |  | ||||||
| 	UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult); |  | ||||||
| }; | }; | ||||||
|  | |||||||
							
								
								
									
										60
									
								
								Source/vampires/Weapons/ProjectileWeapon.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								Source/vampires/Weapons/ProjectileWeapon.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,60 @@ | |||||||
|  | // Fill out your copyright notice in the Description page of Project Settings.
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | #include "ProjectileWeapon.h" | ||||||
|  | 
 | ||||||
|  | #include "vampires/EnemyCharacter.h" | ||||||
|  | 
 | ||||||
|  | AProjectileWeapon::AProjectileWeapon() | ||||||
|  | { | ||||||
|  | 	SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component")); | ||||||
|  | 	SphereComponent->SetupAttachment(RootComponent); | ||||||
|  | 	SphereComponent->SetSphereRadius(1000.0f); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void AProjectileWeapon::BeginPlay() | ||||||
|  | { | ||||||
|  | 	Super::BeginPlay(); | ||||||
|  | 	SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &AProjectileWeapon::OnWeaponBeginOverlap); | ||||||
|  | 	SphereComponent->OnComponentEndOverlap.AddDynamic(this, &AProjectileWeapon::OnWeaponEndOverlap); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void AProjectileWeapon::OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, | ||||||
|  |                                              UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) | ||||||
|  | { | ||||||
|  | 	if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor)) | ||||||
|  | 	{ | ||||||
|  | 		OverlappedEnemies.Add(Enemy); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void AProjectileWeapon::OnWeaponEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, | ||||||
|  | 	UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) | ||||||
|  | { | ||||||
|  | 	if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor)) | ||||||
|  | 	{ | ||||||
|  | 		OverlappedEnemies.Remove(Enemy); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void AProjectileWeapon::OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, | ||||||
|  | 	UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) | ||||||
|  | { | ||||||
|  | 	if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor)) | ||||||
|  | 	{ | ||||||
|  | 		UHealthComponent* EnemyHealthComponent = Enemy->GetHealthComponent(); | ||||||
|  | 
 | ||||||
|  | 		if (!EnemyHealthComponent->GetIsDead()) | ||||||
|  | 		{ | ||||||
|  | 			AController* ownerController = nullptr; | ||||||
|  | 			if (AVampireCharacter* character = Cast<AVampireCharacter>(GetOwner())) | ||||||
|  | 			{ | ||||||
|  | 				ownerController = character->GetController(); | ||||||
|  | 			} | ||||||
|  | 
 | ||||||
|  | 			EnemyHealthComponent->TakeDamage(Enemy, Damage, nullptr, ownerController, this); | ||||||
|  | 
 | ||||||
|  | 			OverlappedComponent->GetAttachmentRootActor()->Destroy(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										46
									
								
								Source/vampires/Weapons/ProjectileWeapon.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								Source/vampires/Weapons/ProjectileWeapon.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,46 @@ | |||||||
|  | // Fill out your copyright notice in the Description page of Project Settings.
 | ||||||
|  | 
 | ||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include "CoreMinimal.h" | ||||||
|  | #include "../Weapon.h" | ||||||
|  | #include "vampires/Projectile.h" | ||||||
|  | #include "ProjectileWeapon.generated.h" | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  *  | ||||||
|  |  */ | ||||||
|  | UCLASS() | ||||||
|  | class VAMPIRES_API AProjectileWeapon : public AWeapon | ||||||
|  | { | ||||||
|  | 	GENERATED_BODY() | ||||||
|  | public: | ||||||
|  | 	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) | ||||||
|  | 	USphereComponent* SphereComponent = nullptr; | ||||||
|  | 
 | ||||||
|  | 	UPROPERTY(EditAnywhere, Category = "Weapon Properties") | ||||||
|  | 	TSubclassOf<AProjectile> ProjectileTemplate = nullptr; | ||||||
|  | 
 | ||||||
|  | protected: | ||||||
|  | 	TArray<AActor*> OverlappedEnemies = TArray<AActor*>(); | ||||||
|  | 	 | ||||||
|  | public: | ||||||
|  | 	AProjectileWeapon(); | ||||||
|  | 	 | ||||||
|  | protected: | ||||||
|  | 	virtual void BeginPlay() override; | ||||||
|  | 	 | ||||||
|  | public: | ||||||
|  | 	UFUNCTION() | ||||||
|  | 	void OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, | ||||||
|  | 						UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, | ||||||
|  | 						const FHitResult& SweepResult); | ||||||
|  | 
 | ||||||
|  | 	UFUNCTION() | ||||||
|  | 	void OnWeaponEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, | ||||||
|  | 					  int32 OtherBodyIndex); | ||||||
|  | 	 | ||||||
|  | 	UFUNCTION() | ||||||
|  | 	void OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, | ||||||
|  | 	UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult); | ||||||
|  | }; | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user