LEAP Documentation 40220
Documentation for the LEAP project
VehicleSeatComponent.h
Go to the documentation of this file.
1// Copyright Blue Isle Studios Inc 2018. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Components/ActorComponent.h"
7#include "WeaponComponent.h"
8#include "VehicleSeatComponent.generated.h"
9
13class UAfflictionInstance;
14
15DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOccupantChangedSignature, class UVehicleSeatComponent*, Seat, class AProjectXCharacter*, PreviousOccupant);
16
17UCLASS(Blueprintable, ClassGroup = (Custom), HideCategories = (ComponentTick, Collision, Tags, Variable, Activation, ComponentReplication, Cooking), meta = (BlueprintSpawnableComponent))
18class PROJECTX_API UVehicleSeatComponent : public UActorComponent
19{
20 GENERATED_UCLASS_BODY()
21
22public:
23
24 UFUNCTION(BlueprintCallable, Category = Seat)
25 FORCEINLINE bool IsDriverSeat() const { return bDriverSeat; }
26 UFUNCTION(BlueprintCallable, Category = Seat)
27 FORCEINLINE FName GetSeatName() const { return SeatName; }
28 FORCEINLINE void SetSeatName(const FName NewName) { SeatName = NewName; }
29 UFUNCTION(BlueprintCallable, Category = Seat)
30 FORCEINLINE AProjectXVehicle* GetVehicle() const { return VehicleOwner; }
31 UFUNCTION(BlueprintCallable, Category = Seat)
32 FORCEINLINE AProjectXCharacter* GetOccupant() const { return Occupant.Get(); }
33 UFUNCTION(BlueprintCallable, Category = Seat)
34 float GetDistanceFromPlayer(const AProjectXCharacter* Character) const;
35 UFUNCTION(Category = Seat)
36 bool GetUseCharacterBoundsWhenVisible() const { return bUseCharacterMeshBoundsWhenVisible;}
37 UFUNCTION(BlueprintCallable, Category = Seat)
38 FORCEINLINE bool ShouldOccupantBeHidden() const { return bHideOccupant; }
39 UFUNCTION(BlueprintCallable, Category = Seat)
40 void ToggleSeatAttachment(const bool bNewToggle) {bIsAttachedToSeat = bNewToggle;}
41 UFUNCTION(BlueprintCallable, Category = Seat)
42 void SetManualSeatOffset(const FVector NewOffset) { CurrentSeatOffset = NewOffset; }
43 UFUNCTION(BlueprintCallable, Category = Seat)
44 void ResetSeatOffset() { CurrentSeatOffset = SeatOffset; }
45 UFUNCTION(BlueprintCallable, Category = Seat)
46 virtual FTransform GetSeatTransform() const;
47 UFUNCTION(BlueprintCallable, Category = Seat)
48 virtual FVector GetSeatLocation() const;
49 UFUNCTION(BlueprintCallable, Category = Seat)
50 virtual FRotator GetSeatRotation() const;
51 UFUNCTION(BlueprintCallable, Category = Seat)
52 virtual FRotator GetLookDirection() const;
53
54 UFUNCTION(BlueprintCallable, Category = Seat)
55 virtual FTransform GetExitTransform() const;
56
57 UFUNCTION(BlueprintCallable, Category = Seat)
58 virtual bool CanEnterSeat(const AProjectXCharacter* Character) const;
59 UFUNCTION(BlueprintCallable, Category = Seat)
60 virtual bool HasOccupant() const;
61
62public:
63 virtual void BeginPlay() override;
64 virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
65
66 UFUNCTION()
67 virtual void TickOccupant(float DeltaTime);
68
69 UFUNCTION()
70 virtual bool EnterSeat(AProjectXCharacter* Character);
71 UFUNCTION()
72 virtual bool LeaveSeat(bool bForced = false, bool bEject = false);
73
74 UFUNCTION()
75 virtual void TickWeapon(float DeltaTime);
76
77 UFUNCTION(BlueprintCallable, Category = Seat)
78 virtual UWeaponComponent* GetWeaponComponent() const;
79
80 bool GetProjectileTransform(FTransform& Transform);
81
82public:
83 UPROPERTY(BlueprintAssignable, Category = Seat)
84 FOccupantChangedSignature OnOccupantChangedSignature;
85
86protected:
87 UFUNCTION()
88 virtual void OnRep_Occupant();
89
90 void UpdateOccupantWeapons(AProjectXCharacter* Character);
91 void RemoveInvalidAfflictions(AProjectXCharacter* Character);
92 void ToggleSeatAfflictions(AProjectXCharacter* Character, bool bEnterSeat);
93
94
95protected:
96
97 UPROPERTY()
98 AProjectXVehicle* VehicleOwner = NULL;
99
100 UPROPERTY(ReplicatedUsing = OnRep_Occupant)
101 TWeakObjectPtr<AProjectXCharacter> Occupant = NULL;
102 UPROPERTY()
103 TWeakObjectPtr<AProjectXCharacter> PreviousOccupant = NULL;
104
105 UPROPERTY(EditDefaultsOnly, Category = Seat)
106 bool bDriverSeat = false;
107
108 /* Name of the seat to be displayed in the UI */
109 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Seat, meta = (AllowPrivateAccess = true))
110 FName SeatName = NAME_None;
111 UPROPERTY(EditDefaultsOnly, Category = Seat)
112 FName SeatSocket = NAME_None;
113 /* If the Seat socket name should be searched on the parent vehicle instead (Subvehicles) */
114 UPROPERTY(EditDefaultsOnly, Category = Seat)
115 bool bUseSocketFromParentVehicle = false;
116 UPROPERTY(EditDefaultsOnly, Category = Seat)
117 FVector SeatOffset = FVector(0);
118 UPROPERTY(EditDefaultsOnly, Category = Seat)
119 FRotator SeatRotation = FRotator(0);
120 /* Third person Animation Instance for the occupant of this seat - Will be overridden if the seat has a weapon with a custom instance */
121 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Seat|Animation|Third Person")
122 TSubclassOf<UAnimInstance> AnimationClass3P;
123 /* If this is true, the relative location to the seat will be stored when the player enters it and the same location will be used when exiting the vehicle */
124 UPROPERTY(EditDefaultsOnly, Category = Seat)
125 bool bUseEnterLocationAsExitLocation = true;
126 /*position offset when exiting the vehicle*/
127 UPROPERTY(EditDefaultsOnly, Category = Seat)
128 FVector ExitOffset = FVector(0, 0, 160);
129 /* Vertical force applied when ejecting*/
130 UPROPERTY(EditDefaultsOnly, Category = Seat)
131 FVector EjectLaunchVelocity = FVector::ZeroVector;
132 /*How much of the vehicles velocity is carried over when exiting*/
133 UPROPERTY(EditDefaultsOnly, Category = Seat)
134 float LaunchVelocityExchangeRate = 1.0f;
135 /*Weapon Class used by this seat*/
136 UPROPERTY(EditDefaultsOnly, Category = Seat)
137 TArray<TSubclassOf<UWeaponInstanceVehicle>> WeaponClasses;
138 /*Socket that projectiles are spawned at*/
139 UPROPERTY(EditDefaultsOnly, Category = Seat)
140 FName ProjectileSocket = NAME_None;
141 /*Socket used to rotate the weapon*/
142 UPROPERTY(EditDefaultsOnly, Category = Seat)
143 FName MeshRotationSocket = NAME_None;
144 /*Should the occpuant be hidden while in the seat*/
145 UPROPERTY(EditDefaultsOnly, Category = Seat)
146 bool bHideOccupant = false;
147 /*If the occupant isn't hidden, should we use the character's mesh bounds instead? Some vehicle animations might move the character mesh too far away from the root where its capsule is, toggling this on would mean that instead of using the capsule the mesh will dictate its bounds instead. This should fix some issues with characters being culled from drastic angles in exchange of a performance cost */
148 UPROPERTY(EditDefaultsOnly, Category = Seat , meta = (EditCondition = "!bHideOccupant"))
149 bool bUseCharacterMeshBoundsWhenVisible = false;
150 /* Affliction to apply while in the seat*/
151 UPROPERTY(EditDefaultsOnly, Category = Seat)
152 TArray<TSubclassOf<UAfflictionInstance>> InvalidSeatAfflictions;
153 /* Affliction to apply while in the seat*/
154 UPROPERTY(EditDefaultsOnly, Category = Seat)
155 TArray<TSubclassOf<UAfflictionInstance>> SeatOccupantAfflictions;
156 UPROPERTY()
157 bool bOnlyTickWhenOccupied = true;
158
159private:
160 bool bIsAttachedToSeat = true;
161 float OccupantEntranceTime;
162 FVector CurrentSeatOffset = FVector::ZeroVector;
163 FVector CachedRelativeEntryLocation = FVector::ZeroVector;
164};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOccupantChangedSignature, class UVehicleSeatComponent *, Seat, class AProjectXCharacter *, PreviousOccupant)
Definition: ProjectXCharacter.h:128
Definition: ProjectXVehicle.h:56
Definition: WeaponInstanceVehicle.h:16