322 lines
8.4 KiB
C++
322 lines
8.4 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "Blaster/Interfaces/InteractWithCrosshairInterface.h"
|
|
#include "Blaster/Types/CombatState.h"
|
|
#include "Blaster/Types/TurningInPlace.h"
|
|
#include "Components/TimelineComponent.h"
|
|
#include "GameFramework/Character.h"
|
|
#include "Sound/SoundCue.h"
|
|
#include "BlasterCharacter.generated.h"
|
|
|
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnLeftGame);
|
|
|
|
UCLASS()
|
|
class BLASTER_API ABlasterCharacter : public ACharacter, public IInteractWithCrosshairInterface
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
ABlasterCharacter();
|
|
virtual void Tick(float DeltaTime) override;
|
|
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
|
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
|
|
virtual void PostInitializeComponents() override;
|
|
virtual void OnRep_ReplicatedMovement() override;
|
|
virtual void Destroyed() override;
|
|
void RotateInPlace(float DeltaTime);
|
|
|
|
// Play Montages
|
|
void PlayFireMontage(bool bAiming);
|
|
void PlayReloadMontage();
|
|
void PlayEliminatedMontage();
|
|
void PlayThrowGrenadeMontage();
|
|
void PlaySwapMontage();
|
|
|
|
void Eliminated(bool bPlayerLeftGame);
|
|
|
|
UFUNCTION(NetMulticast, Reliable)
|
|
void MulticastEliminated(bool bPlayerLeftGame);
|
|
|
|
UPROPERTY(Replicated)
|
|
bool bDisableGameplay = false;
|
|
|
|
UFUNCTION(BlueprintImplementableEvent)
|
|
void ShowSniperScopeWidget(bool bShowScope);
|
|
|
|
void UpdateHUDHealth();
|
|
void UpdateHUDShield();
|
|
void UpdateHUDAmmo();
|
|
|
|
void SpawnDefaultWeapon();
|
|
UPROPERTY()
|
|
TMap<FName, class UBoxComponent*> HitCollisionBoxes;
|
|
|
|
bool bFinishedSwapping = false;
|
|
|
|
UFUNCTION(Server, Reliable)
|
|
void ServerLeaveGame();
|
|
|
|
FOnLeftGame OnLeftGame;
|
|
protected:
|
|
virtual void BeginPlay() override;
|
|
|
|
void MoveForward(float Value);
|
|
void MoveRight(float Value);
|
|
void Turn(float Value);
|
|
void LookUp(float Value);
|
|
void EquipButtonPressed();
|
|
void ReloadButtonPressed();
|
|
void CrouchButtonPressed();
|
|
void AimButtonPressed();
|
|
void AimButtonReleased();
|
|
void GrenadeButtonPressed();
|
|
void CalculateAO_Pitch();
|
|
void AimOffset(float DeltaTime);
|
|
void SimProxiesTurn();
|
|
virtual void Jump() override;
|
|
void FireButtonPressed();
|
|
void FireButtonReleased();
|
|
void PlayHitReactMontage();
|
|
|
|
UFUNCTION()
|
|
void ReceiveDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType, class AController* InstigatorController, AActor* DamageCauser);
|
|
|
|
// Poll for any relevant classes and initialize them
|
|
void PollInit();
|
|
|
|
// Hit boxes used for server-side rewind
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
class UBoxComponent* head;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UBoxComponent* pelvis;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UBoxComponent* spine_02;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UBoxComponent* spine_03;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UBoxComponent* upperarm_l;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UBoxComponent* upperarm_r;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UBoxComponent* lowerarm_l;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UBoxComponent* lowerarm_r;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UBoxComponent* hand_l;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UBoxComponent* hand_r;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UBoxComponent* backpack;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UBoxComponent* blanket;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UBoxComponent* thigh_l;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UBoxComponent* thigh_r;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UBoxComponent* calf_l;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UBoxComponent* calf_r;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UBoxComponent* foot_l;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UBoxComponent* foot_r;
|
|
|
|
private:
|
|
|
|
UPROPERTY()
|
|
class ABlasterPlayerState* BlasterPlayerState;
|
|
|
|
UPROPERTY(VisibleAnywhere, Category="Camera")
|
|
class USpringArmComponent* CameraBoom;
|
|
|
|
UPROPERTY(VisibleAnywhere, Category="Camera")
|
|
class UCameraComponent* FollowCamera;
|
|
|
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
|
|
class UWidgetComponent* OverheadWidget;
|
|
|
|
UPROPERTY(ReplicatedUsing = OnRep_OverlappingWeapon)
|
|
class AWeapon* OverlappingWeapon;
|
|
|
|
UFUNCTION()
|
|
void OnRep_OverlappingWeapon(AWeapon* LastWeapon);
|
|
|
|
// Blaster Components
|
|
|
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
|
|
class UCombatComponent* Combat;
|
|
|
|
UPROPERTY(VisibleAnywhere)
|
|
class UBuffComponent* Buff;
|
|
|
|
UPROPERTY(VisibleAnywhere)
|
|
class ULagCompensationComponent* LagCompensation;
|
|
|
|
UFUNCTION(Server, Reliable)
|
|
void ServerEquipButtonPressed();
|
|
|
|
float AO_Yaw;
|
|
float InterpAO_Yaw;
|
|
float AO_Pitch;
|
|
FRotator StartingAimRotation;
|
|
|
|
ETurningInPlace TurningInPlace;
|
|
void TurnInPlace(float DeltaTime);
|
|
|
|
// Animation montages
|
|
|
|
UPROPERTY(EditAnywhere, Category = Combat)
|
|
class UAnimMontage* FireWeaponMontage;
|
|
|
|
UPROPERTY(EditAnywhere, Category = Combat)
|
|
class UAnimMontage* ReloadMontage;
|
|
|
|
UPROPERTY(EditAnywhere, Category = Combat)
|
|
class UAnimMontage* HitReactMontage;
|
|
|
|
UPROPERTY(EditAnywhere, Category = Combat)
|
|
class UAnimMontage* EliminatedMontage;
|
|
|
|
UPROPERTY(EditAnywhere, Category = Combat)
|
|
class UAnimMontage* ThrowGrenadeMontage;
|
|
|
|
UPROPERTY(EditAnywhere, Category = Combat)
|
|
class UAnimMontage* SwapMontage;
|
|
|
|
void HideCameraIfCharacterClose();
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
float CameraThreshold = 200.f;
|
|
|
|
bool bRotateRootBone;
|
|
float TurnThreshold = 0.8f;
|
|
FRotator ProxyRotationLastFrame;
|
|
FRotator ProxyRotation;
|
|
float ProxyYaw;
|
|
float TimeSinceLastMovementReplication;
|
|
float CalculateSpeed();
|
|
|
|
// Health
|
|
|
|
UPROPERTY(EditAnywhere, Category= "Player Stats")
|
|
float MaxHealth = 100.f;
|
|
|
|
UPROPERTY(ReplicatedUsing = OnRep_Health, VisibleAnywhere, Category= "Player Stats")
|
|
float Health = 100.f;
|
|
|
|
UFUNCTION()
|
|
void OnRep_Health(float LastHealth);
|
|
|
|
// Shield
|
|
|
|
UPROPERTY(EditAnywhere, Category= "Player Stats")
|
|
float MaxShield = 100.f;
|
|
|
|
UPROPERTY(ReplicatedUsing = OnRep_Shield, EditAnywhere, Category= "Player Stats")
|
|
float Shield = 0.f;
|
|
|
|
UFUNCTION()
|
|
void OnRep_Shield(float LastShield);
|
|
|
|
UPROPERTY()
|
|
class ABlasterPlayerController* BlasterPlayerController;
|
|
|
|
bool bEliminated = false;
|
|
|
|
UPROPERTY(EditDefaultsOnly)
|
|
float EliminationDelay = 2.f;
|
|
FTimerHandle EliminationTimer;
|
|
|
|
void EliminationTimerFinished();
|
|
|
|
bool bLeftGame = false;
|
|
|
|
// Dissolve effect
|
|
UPROPERTY(VisibleAnywhere)
|
|
UTimelineComponent* DissolveTimeline;
|
|
FOnTimelineFloat DissolveTrack;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UCurveFloat* DissolveCurve;
|
|
|
|
UFUNCTION()
|
|
void UpdateDissolveMaterial(float DissolveValue);
|
|
void StartDissolve();
|
|
|
|
// Dynamic instance that we can change at runtime
|
|
UPROPERTY(VisibleAnywhere, Category = Elimination)
|
|
UMaterialInstanceDynamic* DynamicDissolveMaterialInstance;
|
|
|
|
// Material instance set on the Blueprint, used with the dynamic material instance
|
|
UPROPERTY(EditAnywhere, Category = Elimination)
|
|
UMaterialInstance* DissolveMaterialInstance;
|
|
|
|
// Elimination bot
|
|
UPROPERTY(EditAnywhere)
|
|
UParticleSystem* EliminationBotEffect;
|
|
|
|
UPROPERTY(VisibleAnywhere)
|
|
UParticleSystemComponent* EliminationBotComponent;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
USoundCue* EliminationBotSound;
|
|
|
|
// Default weapon
|
|
UPROPERTY(EditAnywhere)
|
|
TSubclassOf<AWeapon> DefaultWeaponClass;
|
|
|
|
// Grenade
|
|
|
|
UPROPERTY(VisibleAnywhere)
|
|
UStaticMeshComponent* AttachedGrenade;
|
|
|
|
public:
|
|
void SetOverlappingWeapon(AWeapon* Weapon);
|
|
bool IsWeaponEquipped();
|
|
bool IsAiming();
|
|
FORCEINLINE float GetAO_Yaw() const { return AO_Yaw; }
|
|
FORCEINLINE float GetAO_Pitch() const { return AO_Pitch; }
|
|
AWeapon* GetPrimaryWeapon();
|
|
FORCEINLINE ETurningInPlace GetTurningInPlace() const { return TurningInPlace; }
|
|
FVector GetHitTarget() const;
|
|
FORCEINLINE UCameraComponent* GetFollowCamera() const { return FollowCamera; }
|
|
FORCEINLINE bool ShouldRotateRootBone() const { return bRotateRootBone; }
|
|
FORCEINLINE bool IsEliminated() const { return bEliminated; }
|
|
FORCEINLINE float GetHealth() const { return Health; }
|
|
FORCEINLINE void SetHealth(float Amount) { Health = Amount; }
|
|
FORCEINLINE float GetMaxHealth() const { return MaxHealth; }
|
|
FORCEINLINE float GetShield() const { return Shield; }
|
|
FORCEINLINE void SetShield(float Amount) { Shield = Amount; }
|
|
FORCEINLINE float GetMaxShield() const { return MaxShield; }
|
|
ECombatState GetCombatState() const;
|
|
FORCEINLINE UCombatComponent* GetCombat() const { return Combat; }
|
|
FORCEINLINE UBuffComponent* GetBuff() const { return Buff; }
|
|
FORCEINLINE bool GetDisableGameplay() const { return bDisableGameplay; }
|
|
FORCEINLINE UAnimMontage* GetReloadMontage() const { return ReloadMontage; }
|
|
FORCEINLINE UStaticMeshComponent* GetAttachedGrenade() const { return AttachedGrenade; }
|
|
bool IsLocallyReloading();
|
|
FORCEINLINE ULagCompensationComponent* GetLagCompensation() const { return LagCompensation; }
|
|
};
|