blaster/Source/Blaster/Components/CombatComponent.h

158 lines
3.4 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Blaster/HUD/BlasterHUD.h"
#include "Blaster/Types/CombatState.h"
#include "Blaster/Weapon/WeaponTypes.h"
#include "Components/ActorComponent.h"
#include "CombatComponent.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BLASTER_API UCombatComponent : public UActorComponent
{
GENERATED_BODY()
public:
UCombatComponent();
friend class ABlasterCharacter;
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
void EquipWeapon(class AWeapon* WeaponToEquip);
void Reload();
UFUNCTION(BlueprintCallable)
void FinishedReloading();
void FireButtonPressed(bool bPressed);
UFUNCTION(BlueprintCallable)
void ShotgunShellReload();
void JumpToShotgunEnd();
protected:
virtual void BeginPlay() override;
void SetAiming(bool bIsAiming);
UFUNCTION(Server, Reliable)
void ServerSetAiming(bool bIsAiming);
UFUNCTION()
void OnRep_EquippedWeapon();
void Fire();
UFUNCTION(Server, Reliable)
void ServerFire(const FVector_NetQuantize& TraceHitTarget);
UFUNCTION(NetMulticast, Reliable)
void MulticastFire(const FVector_NetQuantize& TraceHitTarget);
void TraceUnderCrosshairs(FHitResult& TraceHitResult);
void SetHUDCrosshairs(float DeltaTime);
UFUNCTION(Server, Reliable)
void ServerReload();
void HandleReload();
int32 AmountToReload();
private:
UPROPERTY()
class ABlasterCharacter* Character;
UPROPERTY()
class ABlasterPlayerController* Controller;
UPROPERTY()
class ABlasterHUD* HUD;
UPROPERTY(ReplicatedUsing=OnRep_EquippedWeapon)
class AWeapon* EquippedWeapon;
UPROPERTY(Replicated)
bool bAiming;
UPROPERTY(EditAnywhere)
float BaseWalkSpeed;
UPROPERTY(EditAnywhere)
float AimWalkSpeed;
bool bFireButtonPressed;
//HUD and Crosshairs
float CrosshairVelocityFactor;
float CrosshairInAirFactor;
float CrosshairAimFactor;
float CrosshairShootingFactor;
FHUDPackage HUDPackage;
// 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);
FVector HitTarget;
// Automatic fire
FTimerHandle FireTimer;
bool bCanFire = true;
void StartFireTimer();
void FireTimerFinished();
bool CanFire();
// Carried ammo for the currently equipped weapon
UPROPERTY(ReplicatedUsing=OnRep_CarriedAmmo)
int32 CarriedAmmo;
UFUNCTION()
void OnRep_CarriedAmmo();
TMap<EWeaponType, int32> CarriedAmmoMap;
UPROPERTY(EditAnywhere)
int32 StartingARAmmo = 30;
UPROPERTY(EditAnywhere)
int32 StartingRocketAmmo = 8;
UPROPERTY(EditAnywhere)
int32 StartingPistolAmmo = 15;
UPROPERTY(EditAnywhere)
int32 StartingSMGAmmo = 100;
UPROPERTY(EditAnywhere)
int32 StartingShotgunAmmo = 15;
UPROPERTY(EditAnywhere)
int32 StartingSniperAmmo = 15;
UPROPERTY(EditAnywhere)
int32 StartingGrenadeLauncherAmmo = 15;
void InitializeCarriedAmmo();
UPROPERTY(ReplicatedUsing=OnRep_CombatState)
ECombatState CombatState = ECombatState::ECS_Unoccupied;
UFUNCTION()
void OnRep_CombatState();
void UpdateAmmoValues();
void UpdateShotgunAmmoValues();
};