blaster/Source/Blaster/Weapon/Weapon.h

211 lines
5.8 KiB
C
Raw Normal View History

2022-04-29 22:26:35 +00:00
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
2022-05-09 19:07:33 +00:00
#include "WeaponTypes.h"
2022-04-29 22:26:35 +00:00
#include "GameFramework/Actor.h"
#include "Weapon.generated.h"
UENUM(BlueprintType)
enum class EWeaponState : uint8
{
EWS_Initial UMETA(DisplayName = "Initial State"),
EWS_Equipped UMETA(DisplayName = "Equipped"),
2022-05-25 13:24:29 +00:00
EWS_EquippedSecondary UMETA(DisplayName = "Equipped Secondary"),
2022-04-29 22:26:35 +00:00
EWS_Dropped UMETA(DisplayName = "Dropped"),
2022-04-30 11:09:28 +00:00
2022-04-29 22:26:35 +00:00
EWS_MAX UMETA(DisplayName = "DefaultMAX")
};
2022-05-26 12:03:51 +00:00
UENUM(BlueprintType)
enum class EFireType: uint8
{
EFT_HitScan UMETA(DisplayName = "HitScan Weapon"),
EFT_Projectile UMETA(DisplayName = "Projectile Weapon"),
EFT_Shotgun UMETA(DisplayName = "Shotgun Weapon"),
EFT_Max UMETA(DisplayName = "DefaultMax")
};
2022-04-29 22:26:35 +00:00
UCLASS()
class BLASTER_API AWeapon : public AActor
{
GENERATED_BODY()
2022-04-29 23:19:55 +00:00
public:
2022-04-29 22:26:35 +00:00
AWeapon();
2022-04-30 14:08:00 +00:00
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
2022-05-09 16:39:41 +00:00
virtual void OnRep_Owner() override;
void SetHUDAmmo();
2022-04-30 10:26:25 +00:00
void ShowPickupWidget(bool bShowWidget);
2022-05-05 10:51:14 +00:00
virtual void Fire(const FVector& HitTarget);
2022-05-08 17:31:58 +00:00
void Dropped();
2022-05-26 14:37:53 +00:00
void AddAmmo(int32 AmmoToAdd);
2022-05-26 12:03:51 +00:00
FVector TraceEndWithScatter(const FVector& HitTarget);
2022-04-30 10:26:25 +00:00
2022-05-05 15:57:57 +00:00
// Textures for the weapon crosshairs
UPROPERTY(EditAnywhere, Category= Crosshairs)
class UTexture2D* CrosshairsCenter;
UPROPERTY(EditAnywhere, Category= Crosshairs)
class UTexture2D* CrosshairsLeft;
UPROPERTY(EditAnywhere, Category= Crosshairs)
class UTexture2D* CrosshairsRight;
UPROPERTY(EditAnywhere, Category= Crosshairs)
class UTexture2D* CrosshairsTop;
UPROPERTY(EditAnywhere, Category= Crosshairs)
class UTexture2D* CrosshairsBottom;
2022-05-05 19:56:31 +00:00
// Zoom FOV while aiming
UPROPERTY(EditAnywhere)
float ZoomedFOV = 30.f;
UPROPERTY(EditAnywhere)
float ZoomInterpSpeed = 20.f;
2022-05-06 20:54:23 +00:00
// Automatic fire
UPROPERTY(EditAnywhere, Category = Combat)
bool bAutomatic = true;
2022-05-09 22:35:33 +00:00
UPROPERTY(EditAnywhere)
class USoundCue* EquipSound;
2022-05-06 20:54:23 +00:00
UPROPERTY(EditAnywhere, Category = Combat)
float FireDelay = .15f;
2022-05-20 23:58:19 +00:00
// Enable or disable custom depth
void EnableCustomDepth(bool bEnabled);
2022-05-23 23:16:06 +00:00
bool bDestroyWeapon = false;
2022-05-26 12:03:51 +00:00
UPROPERTY(EditAnywhere)
EFireType FireType;
UPROPERTY(EditAnywhere, Category = "Weapon Scatter")
bool bUseScatter = false;
2022-04-29 22:26:35 +00:00
protected:
virtual void BeginPlay() override;
2022-05-25 13:24:29 +00:00
virtual void OnWeaponStateSet();
virtual void OnEquipped();
virtual void OnDropped();
virtual void OnEquippedSecondary();
2022-04-29 23:19:55 +00:00
UFUNCTION()
virtual void OnSphereOverlap(
UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult& SweepResult
);
2022-04-30 10:26:25 +00:00
UFUNCTION()
virtual void OnSphereEndOverlap(
UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex
);
2022-04-29 23:19:55 +00:00
2022-05-26 12:29:39 +00:00
// Trace end with scatter
UPROPERTY(EditAnywhere, Category = "Weapon Scatter")
float DistanceToSphere = 800.f;
UPROPERTY(EditAnywhere, Category = "Weapon Scatter")
float SphereRadius = 75.f;
2022-05-27 16:36:56 +00:00
UPROPERTY(EditAnywhere)
float Damage = 20.f;
2022-05-29 12:11:11 +00:00
UPROPERTY(EditAnywhere)
float HeadShotDamage = 40.f;
2022-05-28 09:16:42 +00:00
UPROPERTY(Replicated, EditAnywhere)
2022-05-27 16:36:56 +00:00
bool bUseServerSideRewind = false;
UPROPERTY()
class ABlasterCharacter* OwnerCharacter;
UPROPERTY()
class ABlasterPlayerController* OwnerController;
2022-05-28 09:16:42 +00:00
UFUNCTION()
void OnPingTooHigh(bool bPingTooHigh);
2022-05-27 16:36:56 +00:00
2022-04-29 23:19:55 +00:00
private:
2022-05-19 17:13:21 +00:00
UPROPERTY(VisibleAnywhere, Category = "Weapon Properties")
2022-04-29 22:26:35 +00:00
USkeletalMeshComponent* WeaponMesh;
2022-05-19 17:13:21 +00:00
UPROPERTY(VisibleAnywhere, Category = "Weapon Properties")
2022-04-29 22:26:35 +00:00
class USphereComponent* AreaSphere;
2022-05-19 17:13:21 +00:00
UPROPERTY(ReplicatedUsing = OnRep_WeaponState, VisibleAnywhere, Category = "Weapon Properties")
2022-04-29 22:26:35 +00:00
EWeaponState WeaponState;
2022-04-30 14:08:00 +00:00
UFUNCTION()
void OnRep_WeaponState();
2022-05-19 17:13:21 +00:00
UPROPERTY(VisibleAnywhere, Category = "Weapon Properties")
2022-04-29 23:19:55 +00:00
class UWidgetComponent* PickupWidget;
2022-04-29 22:26:35 +00:00
2022-05-19 17:13:21 +00:00
UPROPERTY(EditAnywhere, Category = "Weapon Properties")
2022-05-04 20:27:26 +00:00
class UAnimationAsset* FireAnimation;
2022-05-05 13:49:24 +00:00
2022-05-19 17:13:21 +00:00
UPROPERTY(EditAnywhere, Category = "Weapon Properties")
2022-05-05 13:49:24 +00:00
TSubclassOf<class ACasing> CasingClass;
2022-05-09 16:39:41 +00:00
2022-05-26 14:37:53 +00:00
UPROPERTY(EditAnywhere)
2022-05-09 16:39:41 +00:00
int32 Ammo;
2022-05-26 14:37:53 +00:00
UFUNCTION(Client, Reliable) // Server to Client RPC
void ClientUpdateAmmo(int32 ServerAmmo);
2022-05-09 16:39:41 +00:00
2022-05-26 14:37:53 +00:00
UFUNCTION(Client, Reliable) // Server to Client RPC
void ClientAddAmmo(int32 AmmoToAdd);
2022-05-09 16:39:41 +00:00
void SpendRound();
UPROPERTY(EditAnywhere)
int32 MagCapacity;
2022-05-26 14:37:53 +00:00
// The number of unprocessed server requests for ammo
// Incremented in SpendRound(), decremented in ClientUpdateAmmo()
int32 Sequence = 0;
2022-05-09 19:07:33 +00:00
UPROPERTY(EditAnywhere)
EWeaponType WeaponType;
2022-05-05 15:57:57 +00:00
2022-04-29 23:19:55 +00:00
public:
2022-04-30 14:08:00 +00:00
void SetWeaponState(EWeaponState State);
FORCEINLINE USphereComponent* GetAreaSphere() const { return AreaSphere; }
2022-05-03 22:43:10 +00:00
FORCEINLINE USkeletalMeshComponent* GetWeaponMesh() const { return WeaponMesh; };
2022-05-05 19:56:31 +00:00
FORCEINLINE float GetZoomedFOV() const { return ZoomedFOV; };
FORCEINLINE float GetZoomInterpSpeed() const { return ZoomInterpSpeed; };
2022-05-09 19:07:33 +00:00
FORCEINLINE EWeaponType GetWeaponType() const { return WeaponType; }
2022-05-09 22:00:06 +00:00
FORCEINLINE int32 GetAmmo() const { return Ammo; }
FORCEINLINE int32 GetMagCapacity() const { return MagCapacity; }
2022-05-09 16:48:14 +00:00
bool IsEmpty();
2022-05-20 23:33:02 +00:00
bool IsFull();
2022-05-27 16:36:56 +00:00
FORCEINLINE float GetDamage() const { return Damage; }
2022-05-29 12:11:11 +00:00
FORCEINLINE float GetHeadShotDamage() const { return HeadShotDamage; }
2022-05-27 16:36:56 +00:00
// Convenience methods for WeaponType
FORCEINLINE bool IsPistol() const { return WeaponType == EWeaponType::EWT_Pistol; }
FORCEINLINE bool IsSMG() const { return WeaponType == EWeaponType::EWT_SubmachineGun; }
FORCEINLINE bool IsAR() const { return WeaponType == EWeaponType::EWT_AssaultRifle; }
FORCEINLINE bool IsShotgun() const { return WeaponType == EWeaponType::EWT_Shotgun; }
FORCEINLINE bool IsGrenadeLauncher() const { return WeaponType == EWeaponType::EWT_GrenadeLauncher; }
FORCEINLINE bool IsRocketLauncher() const { return WeaponType == EWeaponType::EWT_RocketLauncher; }
FORCEINLINE bool IsSniper() const { return WeaponType == EWeaponType::EWT_SniperRifle; }
2022-04-29 22:26:35 +00:00
};