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()
|
||||
{
|
||||
if (CurrentAmmo == 0 || bIsReloading || !bCanShoot) return;
|
||||
if (!bIsHoldingGun || CurrentAmmo == 0 || bIsReloading || !bCanShoot) return;
|
||||
|
||||
APawn* PawnOwner = Cast<APawn>(PlayerCharacter);
|
||||
if (!PawnOwner || !PawnOwner->GetController()) return;
|
||||
|
|
@ -71,7 +71,7 @@ void UShootingComponent::Shoot()
|
|||
|
||||
void UShootingComponent::Reload()
|
||||
{
|
||||
if (bIsReloading) return;
|
||||
if (!bIsHoldingGun || bIsReloading) return;
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
bCanShoot = true;
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ void AExoPlayerController::Look(const FInputActionValue& InputActionValue)
|
|||
void AExoPlayerController::Interact()
|
||||
{
|
||||
if (InteractionComponent->InteractedActor)
|
||||
IInteractable::Execute_Interact(InteractionComponent->InteractedActor);
|
||||
IInteractable::Execute_Interact(InteractionComponent->InteractedActor, PlayerCharacter);
|
||||
}
|
||||
|
||||
void AExoPlayerController::PlayerJump()
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "CoreMinimal.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include <Characters/ExoPlayerCharacter.h>
|
||||
#include <Items/GunBase.h>
|
||||
#include "Interfaces/Damageable.h"
|
||||
#include "ShootingComponent.generated.h"
|
||||
|
||||
|
|
@ -18,27 +19,6 @@ public:
|
|||
// Sets default values for this component's properties
|
||||
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")
|
||||
bool bShowDebugLine = true;
|
||||
|
||||
|
|
@ -59,6 +39,12 @@ public:
|
|||
UFUNCTION(Category = "Shooting")
|
||||
void Reload();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Shooting")
|
||||
void PickUpGun(AGunBase* gunItem);
|
||||
|
||||
UFUNCTION(Category = "Shooting")
|
||||
void DropGun();
|
||||
|
||||
private:
|
||||
void ResetFireCooldown();
|
||||
|
||||
|
|
@ -68,9 +54,16 @@ private:
|
|||
|
||||
FTimerHandle ReloadTimer;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Shooting")
|
||||
bool bCanShoot = true;
|
||||
bool bIsHoldingGun = false;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Reloading")
|
||||
bool bCanShoot = true;
|
||||
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
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Characters/ExoPlayerCharacter.h"
|
||||
#include "UObject/Interface.h"
|
||||
#include "Interactable.generated.h"
|
||||
|
||||
|
|
@ -16,5 +17,5 @@ class EXO_API IInteractable
|
|||
|
||||
public:
|
||||
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Interaction")
|
||||
void Interact();
|
||||
void Interact(AExoPlayerCharacter* playerCharacter);
|
||||
};
|
||||
|
|
@ -15,6 +15,27 @@ public:
|
|||
// Sets default values for this actor's properties
|
||||
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:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user