blaster/Source/Blaster/Components/CombatComponent.h

202 lines
4.4 KiB
C
Raw Normal View History

2022-04-30 11:09:28 +00:00
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
2022-05-05 20:46:35 +00:00
#include "Blaster/HUD/BlasterHUD.h"
2022-05-09 21:16:55 +00:00
#include "Blaster/Types/CombatState.h"
2022-05-09 17:35:28 +00:00
#include "Blaster/Weapon/WeaponTypes.h"
2022-04-30 11:09:28 +00:00
#include "Components/ActorComponent.h"
2022-05-22 12:11:35 +00:00
#include "Blaster/Weapon/Projectile.h"
2022-04-30 11:09:28 +00:00
#include "CombatComponent.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BLASTER_API UCombatComponent : public UActorComponent
{
GENERATED_BODY()
public:
UCombatComponent();
friend class ABlasterCharacter;
2022-04-30 14:48:34 +00:00
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
2022-04-30 11:09:28 +00:00
void EquipWeapon(class AWeapon* WeaponToEquip);
2022-05-09 20:19:20 +00:00
void Reload();
2022-05-09 21:16:55 +00:00
UFUNCTION(BlueprintCallable)
void FinishedReloading();
2022-05-09 22:00:06 +00:00
2022-05-10 14:03:35 +00:00
void FireButtonPressed(bool bPressed);
2022-05-20 23:33:02 +00:00
UFUNCTION(BlueprintCallable)
void ShotgunShellReload();
void JumpToShotgunEnd();
2022-05-21 10:13:03 +00:00
UFUNCTION(BlueprintCallable)
void ThrowGrenadeFinished();
2022-05-21 15:03:30 +00:00
UFUNCTION(BlueprintCallable)
void LaunchGrenade();
2022-05-22 12:26:02 +00:00
UFUNCTION(Server, Reliable)
void ServerLaunchGrenade(const FVector_NetQuantize& Target);
2022-05-22 13:21:17 +00:00
FORCEINLINE int32 GetGrenades() const { return Grenades; }
2022-05-22 20:56:28 +00:00
void PickupAmmo(EWeaponType WeaponType, int32 AmmoAmount);
2022-05-20 23:33:02 +00:00
2022-04-30 11:09:28 +00:00
protected:
virtual void BeginPlay() override;
2022-04-30 15:38:03 +00:00
void SetAiming(bool bIsAiming);
UFUNCTION(Server, Reliable)
void ServerSetAiming(bool bIsAiming);
2022-04-30 11:09:28 +00:00
2022-05-02 13:40:33 +00:00
UFUNCTION()
void OnRep_EquippedWeapon();
2022-05-06 20:54:23 +00:00
void Fire();
2022-05-02 13:40:33 +00:00
2022-05-04 20:57:45 +00:00
UFUNCTION(Server, Reliable)
2022-05-05 12:29:21 +00:00
void ServerFire(const FVector_NetQuantize& TraceHitTarget);
2022-05-04 20:57:45 +00:00
UFUNCTION(NetMulticast, Reliable)
2022-05-05 12:29:21 +00:00
void MulticastFire(const FVector_NetQuantize& TraceHitTarget);
2022-05-04 22:39:17 +00:00
void TraceUnderCrosshairs(FHitResult& TraceHitResult);
2022-05-05 15:57:57 +00:00
void SetHUDCrosshairs(float DeltaTime);
2022-05-09 20:19:20 +00:00
UFUNCTION(Server, Reliable)
void ServerReload();
2022-05-09 21:16:55 +00:00
void HandleReload();
2022-05-09 22:00:06 +00:00
int32 AmountToReload();
2022-05-21 10:13:03 +00:00
void ThrowGrenade();
UFUNCTION(Server, Reliable)
void ServerThrowGrenade();
2022-05-22 12:11:35 +00:00
UPROPERTY(EditAnywhere)
TSubclassOf<class AProjectile> GrenadeClass;
void DropEquippedWeapon();
void AttachActorToRightHand(AActor* ActorToAttach);
void AttachActorToLeftHand(AActor* ActorToAttach);
void UpdateCarriedAmmo();
void PlayEquipWeaponSound();
void ReloadEmptyWeapon();
2022-05-21 15:03:30 +00:00
void ShowAttachedGrenade(bool bShowGrenade);
2022-04-30 11:09:28 +00:00
private:
2022-05-09 15:16:41 +00:00
UPROPERTY()
2022-04-30 11:09:28 +00:00
class ABlasterCharacter* Character;
2022-05-09 15:16:41 +00:00
UPROPERTY()
2022-05-05 15:57:57 +00:00
class ABlasterPlayerController* Controller;
2022-05-09 15:16:41 +00:00
UPROPERTY()
2022-05-05 15:57:57 +00:00
class ABlasterHUD* HUD;
2022-04-30 14:48:34 +00:00
2022-05-02 13:40:33 +00:00
UPROPERTY(ReplicatedUsing=OnRep_EquippedWeapon)
2022-04-30 11:09:28 +00:00
class AWeapon* EquippedWeapon;
2022-04-30 15:38:03 +00:00
UPROPERTY(Replicated)
bool bAiming;
2022-05-03 17:50:47 +00:00
UPROPERTY(EditAnywhere)
float BaseWalkSpeed;
UPROPERTY(EditAnywhere)
float AimWalkSpeed;
2022-05-04 20:13:31 +00:00
bool bFireButtonPressed;
2022-05-05 16:48:17 +00:00
2022-05-05 19:56:31 +00:00
//HUD and Crosshairs
2022-05-05 16:48:17 +00:00
float CrosshairVelocityFactor;
float CrosshairInAirFactor;
2022-05-05 20:13:12 +00:00
float CrosshairAimFactor;
float CrosshairShootingFactor;
2022-05-05 20:46:35 +00:00
FHUDPackage HUDPackage;
2022-05-05 19:56:31 +00:00
// Aiming and FOV
// Field of view when not aiming; set to the camera's base FOV in BeginPlay
float DefaultFOV;
UPROPERTY(EditAnywhere, Category = Combat)
float ZoomedFOV = 30.f;
float CurrentFOV;
UPROPERTY(EditAnywhere, Category = Combat)
float ZoomInterpSpeed = 20.f;
void InterpFOV(float DeltaTime);
2022-05-05 18:14:17 +00:00
FVector HitTarget;
2022-05-06 20:54:23 +00:00
// Automatic fire
FTimerHandle FireTimer;
bool bCanFire = true;
void StartFireTimer();
void FireTimerFinished();
2022-05-09 16:48:14 +00:00
bool CanFire();
2022-05-09 17:35:28 +00:00
// Carried ammo for the currently equipped weapon
UPROPERTY(ReplicatedUsing=OnRep_CarriedAmmo)
int32 CarriedAmmo;
UFUNCTION()
void OnRep_CarriedAmmo();
TMap<EWeaponType, int32> CarriedAmmoMap;
2022-05-09 19:07:33 +00:00
2022-05-22 20:56:28 +00:00
UPROPERTY(EditAnywhere)
int32 MaxCarriedAmmo = 500;
2022-05-09 19:07:33 +00:00
UPROPERTY(EditAnywhere)
int32 StartingARAmmo = 30;
2022-05-18 12:44:39 +00:00
UPROPERTY(EditAnywhere)
int32 StartingRocketAmmo = 8;
2022-05-19 17:13:21 +00:00
UPROPERTY(EditAnywhere)
int32 StartingPistolAmmo = 15;
2022-05-19 18:51:50 +00:00
UPROPERTY(EditAnywhere)
2022-05-20 14:29:14 +00:00
int32 StartingSMGAmmo = 100;
2022-05-19 18:51:50 +00:00
2022-05-20 10:10:21 +00:00
UPROPERTY(EditAnywhere)
int32 StartingShotgunAmmo = 15;
2022-05-20 12:59:40 +00:00
UPROPERTY(EditAnywhere)
int32 StartingSniperAmmo = 15;
2022-05-20 14:29:14 +00:00
UPROPERTY(EditAnywhere)
int32 StartingGrenadeLauncherAmmo = 15;
2022-05-09 19:07:33 +00:00
void InitializeCarriedAmmo();
2022-05-09 21:16:55 +00:00
UPROPERTY(ReplicatedUsing=OnRep_CombatState)
ECombatState CombatState = ECombatState::ECS_Unoccupied;
UFUNCTION()
void OnRep_CombatState();
2022-05-20 23:33:02 +00:00
void UpdateAmmoValues();
void UpdateShotgunAmmoValues();
2022-05-22 13:21:17 +00:00
UPROPERTY(ReplicatedUsing = OnRep_Grenades)
int32 Grenades = 4;
UFUNCTION()
void OnRep_Grenades();
UPROPERTY(EditAnywhere)
int32 MaxGrenades = 4;
void UpdateHUDGrenades();
2022-04-30 11:09:28 +00:00
};