// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "Blaster/HUD/BlasterHUD.h" #include "Blaster/Weapon/WeaponTypes.h" #include "Components/ActorComponent.h" #include "CombatComponent.generated.h" #define TRACE_LENGTH 80000 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& OutLifetimeProps) const override; void EquipWeapon(class AWeapon* WeaponToEquip); protected: virtual void BeginPlay() override; void SetAiming(bool bIsAiming); UFUNCTION(Server, Reliable) void ServerSetAiming(bool bIsAiming); UFUNCTION() void OnRep_EquippedWeapon(); void Fire(); void FireButtonPressed(bool bPressed); 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); 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 CarriedAmmoMap; };