207 lines
5.7 KiB
C++
207 lines
5.7 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "WeaponTypes.h"
|
|
#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"),
|
|
EWS_EquippedSecondary UMETA(DisplayName = "Equipped Secondary"),
|
|
EWS_Dropped UMETA(DisplayName = "Dropped"),
|
|
|
|
EWS_MAX UMETA(DisplayName = "DefaultMAX")
|
|
};
|
|
|
|
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")
|
|
};
|
|
|
|
UCLASS()
|
|
class BLASTER_API AWeapon : public AActor
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
AWeapon();
|
|
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
|
|
virtual void OnRep_Owner() override;
|
|
void SetHUDAmmo();
|
|
void ShowPickupWidget(bool bShowWidget);
|
|
virtual void Fire(const FVector& HitTarget);
|
|
void Dropped();
|
|
void AddAmmo(int32 AmmoToAdd);
|
|
FVector TraceEndWithScatter(const FVector& HitTarget);
|
|
|
|
// 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;
|
|
|
|
// Zoom FOV while aiming
|
|
UPROPERTY(EditAnywhere)
|
|
float ZoomedFOV = 30.f;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
float ZoomInterpSpeed = 20.f;
|
|
|
|
// Automatic fire
|
|
|
|
UPROPERTY(EditAnywhere, Category = Combat)
|
|
bool bAutomatic = true;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
class USoundCue* EquipSound;
|
|
|
|
UPROPERTY(EditAnywhere, Category = Combat)
|
|
float FireDelay = .15f;
|
|
|
|
// Enable or disable custom depth
|
|
void EnableCustomDepth(bool bEnabled);
|
|
|
|
bool bDestroyWeapon = false;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
EFireType FireType;
|
|
|
|
UPROPERTY(EditAnywhere, Category = "Weapon Scatter")
|
|
bool bUseScatter = false;
|
|
|
|
protected:
|
|
virtual void BeginPlay() override;
|
|
|
|
virtual void OnWeaponStateSet();
|
|
virtual void OnEquipped();
|
|
virtual void OnDropped();
|
|
virtual void OnEquippedSecondary();
|
|
|
|
UFUNCTION()
|
|
virtual void OnSphereOverlap(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
int32 OtherBodyIndex,
|
|
bool bFromSweep,
|
|
const FHitResult& SweepResult
|
|
);
|
|
|
|
UFUNCTION()
|
|
virtual void OnSphereEndOverlap(
|
|
UPrimitiveComponent* OverlappedComponent,
|
|
AActor* OtherActor,
|
|
UPrimitiveComponent* OtherComp,
|
|
int32 OtherBodyIndex
|
|
);
|
|
|
|
// Trace end with scatter
|
|
|
|
UPROPERTY(EditAnywhere, Category = "Weapon Scatter")
|
|
float DistanceToSphere = 800.f;
|
|
|
|
UPROPERTY(EditAnywhere, Category = "Weapon Scatter")
|
|
float SphereRadius = 75.f;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
float Damage = 20.f;
|
|
|
|
UPROPERTY(Replicated, EditAnywhere)
|
|
bool bUseServerSideRewind = false;
|
|
|
|
UPROPERTY()
|
|
class ABlasterCharacter* OwnerCharacter;
|
|
|
|
UPROPERTY()
|
|
class ABlasterPlayerController* OwnerController;
|
|
|
|
UFUNCTION()
|
|
void OnPingTooHigh(bool bPingTooHigh);
|
|
|
|
private:
|
|
UPROPERTY(VisibleAnywhere, Category = "Weapon Properties")
|
|
USkeletalMeshComponent* WeaponMesh;
|
|
|
|
UPROPERTY(VisibleAnywhere, Category = "Weapon Properties")
|
|
class USphereComponent* AreaSphere;
|
|
|
|
UPROPERTY(ReplicatedUsing = OnRep_WeaponState, VisibleAnywhere, Category = "Weapon Properties")
|
|
EWeaponState WeaponState;
|
|
|
|
UFUNCTION()
|
|
void OnRep_WeaponState();
|
|
|
|
UPROPERTY(VisibleAnywhere, Category = "Weapon Properties")
|
|
class UWidgetComponent* PickupWidget;
|
|
|
|
UPROPERTY(EditAnywhere, Category = "Weapon Properties")
|
|
class UAnimationAsset* FireAnimation;
|
|
|
|
UPROPERTY(EditAnywhere, Category = "Weapon Properties")
|
|
TSubclassOf<class ACasing> CasingClass;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
int32 Ammo;
|
|
|
|
UFUNCTION(Client, Reliable) // Server to Client RPC
|
|
void ClientUpdateAmmo(int32 ServerAmmo);
|
|
|
|
UFUNCTION(Client, Reliable) // Server to Client RPC
|
|
void ClientAddAmmo(int32 AmmoToAdd);
|
|
|
|
void SpendRound();
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
int32 MagCapacity;
|
|
|
|
// The number of unprocessed server requests for ammo
|
|
// Incremented in SpendRound(), decremented in ClientUpdateAmmo()
|
|
int32 Sequence = 0;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
EWeaponType WeaponType;
|
|
|
|
public:
|
|
void SetWeaponState(EWeaponState State);
|
|
FORCEINLINE USphereComponent* GetAreaSphere() const { return AreaSphere; }
|
|
FORCEINLINE USkeletalMeshComponent* GetWeaponMesh() const { return WeaponMesh; };
|
|
FORCEINLINE float GetZoomedFOV() const { return ZoomedFOV; };
|
|
FORCEINLINE float GetZoomInterpSpeed() const { return ZoomInterpSpeed; };
|
|
FORCEINLINE EWeaponType GetWeaponType() const { return WeaponType; }
|
|
FORCEINLINE int32 GetAmmo() const { return Ammo; }
|
|
FORCEINLINE int32 GetMagCapacity() const { return MagCapacity; }
|
|
bool IsEmpty();
|
|
bool IsFull();
|
|
FORCEINLINE float GetDamage() const { return Damage; }
|
|
|
|
// 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; }
|
|
};
|