// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "Item.h" #include "AmmoType.h" #include "Engine/DataTable.h" #include "WeaponType.h" #include "Weapon.generated.h" class USoundCue; class UWidgetComponent; class UParticleSystem; USTRUCT(BlueprintType) struct FWeaponDataTable : public FTableRowBase { GENERATED_BODY() UPROPERTY(EditAnywhere, BlueprintReadWrite) EAmmoType AmmoType; UPROPERTY(EditAnywhere, BlueprintReadWrite) int32 WeaponAmmo; UPROPERTY(EditAnywhere, BlueprintReadWrite) int32 MagazineCapacity; UPROPERTY(EditAnywhere, BlueprintReadWrite) USoundCue* PickupSound; UPROPERTY(EditAnywhere, BlueprintReadWrite) USoundCue* EquipSound; UPROPERTY(EditAnywhere, BlueprintReadWrite) USkeletalMesh* ItemMesh; UPROPERTY(EditAnywhere, BlueprintReadWrite) FString ItemName; UPROPERTY(EditAnywhere, BlueprintReadWrite) UTexture2D* InventoryIcon; UPROPERTY(EditAnywhere, BlueprintReadWrite) UTexture2D* AmmoIcon; UPROPERTY(EditAnywhere, BlueprintReadWrite) UMaterialInstance* MaterialInstance; UPROPERTY(EditAnywhere, BlueprintReadWrite) int32 MaterialIndex; UPROPERTY(EditAnywhere, BlueprintReadWrite) FName ClipBoneName; UPROPERTY(EditAnywhere, BlueprintReadWrite) FName ReloadMontageSection; UPROPERTY(EditAnywhere, BlueprintReadWrite) TSubclassOf AnimBP; UPROPERTY(EditAnywhere, BlueprintReadWrite) UTexture2D* CrosshairsMiddle; UPROPERTY(EditAnywhere, BlueprintReadWrite) UTexture2D* CrosshairsLeft; UPROPERTY(EditAnywhere, BlueprintReadWrite) UTexture2D* CrosshairsRight; UPROPERTY(EditAnywhere, BlueprintReadWrite) UTexture2D* CrosshairsBottom; UPROPERTY(EditAnywhere, BlueprintReadWrite) UTexture2D* CrosshairsTop; UPROPERTY(EditAnywhere, BlueprintReadWrite) float AutoFireRate; UPROPERTY(EditAnywhere, BlueprintReadWrite) UParticleSystem* MuzzleFlash; UPROPERTY(EditAnywhere, BlueprintReadWrite) USoundCue* FireSound; UPROPERTY(EditAnywhere, BlueprintReadWrite) FName BoneToHide; UPROPERTY(EditAnywhere, BlueprintReadWrite) bool bAutomatic; UPROPERTY(EditAnywhere, BlueprintReadWrite) float Damage; UPROPERTY(EditAnywhere, BlueprintReadWrite) float HeadshotDamage; }; /** * */ UCLASS() class SHOOTER_API AWeapon : public AItem { GENERATED_BODY() public: AWeapon(); virtual void Tick(float DeltaTime) override; protected: void StopFalling(); virtual void OnConstruction(const FTransform& Transform) override; virtual void BeginPlay() override; void FinishMovingSlide(); void UpdateSlideDisplacement(); private: FTimerHandle ThrowWeaponTimer; float ThrowWeaponTime; bool bFalling; /** Ammo count for this weapon */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties", meta = (AllowPrivateAccess = "true")) int32 Ammo; /** Max ammo that our weapon can hold */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties", meta = (AllowPrivateAccess = "true")) int32 MagazineCapacity; /** Type of weapon */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties", meta = (AllowPrivateAccess = "true")) EWeaponType WeaponType; /** Type of ammo for this weapon */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties", meta = (AllowPrivateAccess = "true")) EAmmoType AmmoType; /** FName for the reload montage section */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties", meta = (AllowPrivateAccess = "true")) FName ReloadMontageSection; /** True when moving the clip while reloading */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Weapon Properties", meta = (AllowPrivateAccess = "true")) bool bMovingClip; /** FName for the clip bone */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties", meta = (AllowPrivateAccess = "true")) FName ClipBoneName; /** Data table for weapon properties */ UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = DataTable, meta = (AllowPrivateAccess = "true")) UDataTable* WeaponDataTable; int32 PreviousMaterialIndex; /** Textures for the weapon crosshairs */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = DataTable, meta = (AllowPrivateAccess = "true")) UTexture2D* CrosshairsMiddle; UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = DataTable, meta = (AllowPrivateAccess = "true")) UTexture2D* CrosshairsLeft; UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = DataTable, meta = (AllowPrivateAccess = "true")) UTexture2D* CrosshairsRight; UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = DataTable, meta = (AllowPrivateAccess = "true")) UTexture2D* CrosshairsBottom; UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = DataTable, meta = (AllowPrivateAccess = "true")) UTexture2D* CrosshairsTop; /** The speed at which automatic fire happens */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = DataTable, meta = (AllowPrivateAccess = "true")) float AutoFireRate; /** Particle system spawned at the BarrelSocket */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = DataTable, meta = (AllowPrivateAccess = "true")) UParticleSystem* MuzzleFlash; /** Sound played when the weapon is fired */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = DataTable, meta = (AllowPrivateAccess = "true")) USoundCue* FireSound; /** Name of the bone to hide on the weapon mesh */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = DataTable, meta = (AllowPrivateAccess = "true")) FName BoneToHide; /** Amount that the slide is pushed back during pistol fire */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Pistol, meta = (AllowPrivateAccess = "true")) float SlideDisplacement; /** Curve for the slide displacement */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Pistol, meta = (AllowPrivateAccess = "true")) UCurveFloat* SlideDisplacementCurve; /** Timer handle for updating SlideDisplacement */ FTimerHandle SlideTimer; /** Time for displacing the slide during pistol fire */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Pistol, meta = (AllowPrivateAccess = "true")) float SlideDisplacementTime; /** True when moving the pistol slide */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Pistol, meta = (AllowPrivateAccess = "true")) bool bMovingSlide; /** Max distance for the slide on the pistol */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Pistol, meta = (AllowPrivateAccess = "true")) float MaxSlideDisplacement; /** Max rotation for pistol recoil */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Pistol, meta = (AllowPrivateAccess = "true")) float MaxRecoilRotation; /** Amount that the pistol will rotate during pistol fire */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Pistol, meta = (AllowPrivateAccess = "true")) float RecoilRotation; /** True for auto gunfire */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties", meta = (AllowPrivateAccess = "true")) bool bAutomatic; /** Amount of damage caused by bullet */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties", meta = (AllowPrivateAccess = "true")) float Damage; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties", meta = (AllowPrivateAccess = "true")) float HeadshotDamage; public: /** Adds an impulse to the weapon */ void ThrowWeapon(); FORCEINLINE int32 GetAmmo() const { return Ammo; } /** Called from Character class when firing weapon */ void DecrementAmmo(); FORCEINLINE EWeaponType GetWeaponType() const { return WeaponType; } FORCEINLINE EAmmoType GetAmmoType() const { return AmmoType; } FORCEINLINE int32 GetMagazineCapacity() const { return MagazineCapacity; } FORCEINLINE FName GetReloadMontageSection() const { return ReloadMontageSection; } FORCEINLINE FName GetClipBoneName() const { return ClipBoneName; } FORCEINLINE float GetAutoFireRate() const { return AutoFireRate; } FORCEINLINE UParticleSystem* GetMuzzleFlash() const { return MuzzleFlash; } FORCEINLINE USoundCue* GetFireSound() const { return FireSound; } FORCEINLINE bool GetAutomatic() const { return bAutomatic; } FORCEINLINE float GetDamage() const { return Damage; } FORCEINLINE float GetHeadshotDamage() const { return HeadshotDamage; } void StartSlideTimer(); void ReloadAmmo(int32 Amount); FORCEINLINE void SetMovingClip(bool Move) { bMovingClip = Move; }; bool ClipIsFull(); };