feat: shooting properties depending on the gun
This commit is contained in:
parent
e70f96df2c
commit
f666cd7d45
Binary file not shown.
Binary file not shown.
BIN
Content/Blueprints/Items/ShotGun.uasset
Normal file
BIN
Content/Blueprints/Items/ShotGun.uasset
Normal file
Binary file not shown.
Binary file not shown.
|
|
@ -25,7 +25,7 @@ void UShootingComponent::BeginPlay()
|
||||||
|
|
||||||
void UShootingComponent::Shoot()
|
void UShootingComponent::Shoot()
|
||||||
{
|
{
|
||||||
if (CurrentAmmo == 0 || bIsReloading || !bCanShoot) return;
|
if (!bIsHoldingGun || CurrentAmmo == 0 || bIsReloading || !bCanShoot) return;
|
||||||
|
|
||||||
APawn* PawnOwner = Cast<APawn>(PlayerCharacter);
|
APawn* PawnOwner = Cast<APawn>(PlayerCharacter);
|
||||||
if (!PawnOwner || !PawnOwner->GetController()) return;
|
if (!PawnOwner || !PawnOwner->GetController()) return;
|
||||||
|
|
@ -71,7 +71,7 @@ void UShootingComponent::Shoot()
|
||||||
|
|
||||||
void UShootingComponent::Reload()
|
void UShootingComponent::Reload()
|
||||||
{
|
{
|
||||||
if (bIsReloading) return;
|
if (!bIsHoldingGun || bIsReloading) return;
|
||||||
|
|
||||||
bIsReloading = true;
|
bIsReloading = true;
|
||||||
|
|
||||||
|
|
@ -81,6 +81,31 @@ void UShootingComponent::Reload()
|
||||||
UE_LOG(LogTemp, Display, TEXT("Reloaded. Ammo: %d/%d"), CurrentAmmo, MaxAmmo); // Docelowo tutaj wywo<77>anie UI aktualizuj<75>ce stan ammo
|
UE_LOG(LogTemp, Display, TEXT("Reloaded. Ammo: %d/%d"), CurrentAmmo, MaxAmmo); // Docelowo tutaj wywo<77>anie UI aktualizuj<75>ce stan ammo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UShootingComponent::PickUpGun(AGunBase* gunItem)
|
||||||
|
{
|
||||||
|
if (bIsHoldingGun)
|
||||||
|
DropGun();
|
||||||
|
|
||||||
|
bIsHoldingGun = true;
|
||||||
|
|
||||||
|
MaxRange = gunItem->MaxRange;
|
||||||
|
DamageValue = gunItem->DamageValue;
|
||||||
|
FireRateCooldown = gunItem->FireRateCooldown;
|
||||||
|
RecoilForceMultiplier = gunItem->RecoilForceMultiplier;
|
||||||
|
ReloadTime = gunItem->ReloadTime;
|
||||||
|
CurrentAmmo = gunItem->CurrentAmmo;
|
||||||
|
MaxAmmo = gunItem->MaxAmmo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UShootingComponent::DropGun()
|
||||||
|
{
|
||||||
|
if (!bIsHoldingGun) return;
|
||||||
|
|
||||||
|
// TODO: Spawn gun actor
|
||||||
|
|
||||||
|
bIsHoldingGun = false;
|
||||||
|
}
|
||||||
|
|
||||||
void UShootingComponent::ResetFireCooldown()
|
void UShootingComponent::ResetFireCooldown()
|
||||||
{
|
{
|
||||||
bCanShoot = true;
|
bCanShoot = true;
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ void AExoPlayerController::Look(const FInputActionValue& InputActionValue)
|
||||||
void AExoPlayerController::Interact()
|
void AExoPlayerController::Interact()
|
||||||
{
|
{
|
||||||
if (InteractionComponent->InteractedActor)
|
if (InteractionComponent->InteractedActor)
|
||||||
IInteractable::Execute_Interact(InteractionComponent->InteractedActor);
|
IInteractable::Execute_Interact(InteractionComponent->InteractedActor, PlayerCharacter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AExoPlayerController::PlayerJump()
|
void AExoPlayerController::PlayerJump()
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "Components/ActorComponent.h"
|
#include "Components/ActorComponent.h"
|
||||||
#include <Characters/ExoPlayerCharacter.h>
|
#include <Characters/ExoPlayerCharacter.h>
|
||||||
|
#include <Items/GunBase.h>
|
||||||
#include "Interfaces/Damageable.h"
|
#include "Interfaces/Damageable.h"
|
||||||
#include "ShootingComponent.generated.h"
|
#include "ShootingComponent.generated.h"
|
||||||
|
|
||||||
|
|
@ -18,27 +19,6 @@ public:
|
||||||
// Sets default values for this component's properties
|
// Sets default values for this component's properties
|
||||||
UShootingComponent();
|
UShootingComponent();
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Shooting")
|
|
||||||
float MaxRange = 2000.0f;
|
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Shooting")
|
|
||||||
float DamageValue = 100.0f;
|
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Shooting")
|
|
||||||
float FireRateCooldown = 1.0f;
|
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Shooting")
|
|
||||||
float RecoilForceMultiplier = 1.0f;
|
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Shooting")
|
|
||||||
float ReloadTime = 3.0f;
|
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Ammo")
|
|
||||||
int32 CurrentAmmo = 10;
|
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Ammo")
|
|
||||||
int32 MaxAmmo = 10;
|
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debug")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debug")
|
||||||
bool bShowDebugLine = true;
|
bool bShowDebugLine = true;
|
||||||
|
|
||||||
|
|
@ -59,6 +39,12 @@ public:
|
||||||
UFUNCTION(Category = "Shooting")
|
UFUNCTION(Category = "Shooting")
|
||||||
void Reload();
|
void Reload();
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "Shooting")
|
||||||
|
void PickUpGun(AGunBase* gunItem);
|
||||||
|
|
||||||
|
UFUNCTION(Category = "Shooting")
|
||||||
|
void DropGun();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ResetFireCooldown();
|
void ResetFireCooldown();
|
||||||
|
|
||||||
|
|
@ -68,9 +54,16 @@ private:
|
||||||
|
|
||||||
FTimerHandle ReloadTimer;
|
FTimerHandle ReloadTimer;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Shooting")
|
bool bIsHoldingGun = false;
|
||||||
bool bCanShoot = true;
|
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Reloading")
|
bool bCanShoot = true;
|
||||||
bool bIsReloading = false;
|
bool bIsReloading = false;
|
||||||
|
|
||||||
|
float MaxRange = 2000.0f;
|
||||||
|
float DamageValue = 100.0f;
|
||||||
|
float FireRateCooldown = 1.0f;
|
||||||
|
float RecoilForceMultiplier = 1.0f;
|
||||||
|
float ReloadTime = 3.0f;
|
||||||
|
int32 CurrentAmmo = 10;
|
||||||
|
int32 MaxAmmo = 10;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "Characters/ExoPlayerCharacter.h"
|
||||||
#include "UObject/Interface.h"
|
#include "UObject/Interface.h"
|
||||||
#include "Interactable.generated.h"
|
#include "Interactable.generated.h"
|
||||||
|
|
||||||
|
|
@ -16,5 +17,5 @@ class EXO_API IInteractable
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Interaction")
|
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Interaction")
|
||||||
void Interact();
|
void Interact(AExoPlayerCharacter* playerCharacter);
|
||||||
};
|
};
|
||||||
|
|
@ -15,6 +15,27 @@ public:
|
||||||
// Sets default values for this actor's properties
|
// Sets default values for this actor's properties
|
||||||
AGunBase();
|
AGunBase();
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Shooting")
|
||||||
|
float MaxRange = 2000.0f;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Shooting")
|
||||||
|
float DamageValue = 100.0f;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Shooting")
|
||||||
|
float FireRateCooldown = 1.0f;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Shooting")
|
||||||
|
float RecoilForceMultiplier = 1.0f;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Shooting")
|
||||||
|
float ReloadTime = 3.0f;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Ammo")
|
||||||
|
int32 CurrentAmmo = 10;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Ammo")
|
||||||
|
int32 MaxAmmo = 10;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user