File size: 3,166 Bytes
7fd553e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | // Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "Components/ControllerComponent.h"
#include "GameplayTagContainer.h"
#include "LyraWeaponStateComponent.generated.h"
class UObject;
struct FFrame;
struct FGameplayAbilityTargetDataHandle;
struct FGameplayEffectContextHandle;
struct FHitResult;
// Hit markers are shown for ranged weapon impacts in the reticle
// A 'successful' hit marker is shown for impacts that damaged an enemy
struct FLyraScreenSpaceHitLocation
{
/** Hit location in viewport screenspace */
FVector2D Location;
FGameplayTag HitZone;
bool bShowAsSuccess = false;
};
struct FLyraServerSideHitMarkerBatch
{
FLyraServerSideHitMarkerBatch() { }
FLyraServerSideHitMarkerBatch(uint8 InUniqueId) :
UniqueId(InUniqueId)
{ }
TArray<FLyraScreenSpaceHitLocation> Markers;
uint8 UniqueId = 0;
};
// Tracks weapon state and recent confirmed hit markers to display on screen
UCLASS()
class ULyraWeaponStateComponent : public UControllerComponent
{
GENERATED_BODY()
public:
ULyraWeaponStateComponent(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
UFUNCTION(Client, Reliable)
void ClientConfirmTargetData(uint16 UniqueId, bool bSuccess, const TArray<uint8>& HitReplaces);
void AddUnconfirmedServerSideHitMarkers(const FGameplayAbilityTargetDataHandle& InTargetData, const TArray<FHitResult>& FoundHits);
/** Updates this player's last damage instigated time */
void UpdateDamageInstigatedTime(const FGameplayEffectContextHandle& EffectContext);
/** Gets the array of most recent locations this player instigated damage, in screen-space */
void GetLastWeaponDamageScreenLocations(TArray<FLyraScreenSpaceHitLocation>& WeaponDamageScreenLocations)
{
WeaponDamageScreenLocations = LastWeaponDamageScreenLocations;
}
/** Returns the elapsed time since the last (outgoing) damage hit notification occurred */
double GetTimeSinceLastHitNotification() const;
int32 GetUnconfirmedServerSideHitMarkerCount() const
{
return UnconfirmedServerSideHitMarkers.Num();
}
protected:
// This is called to filter hit results to determine whether they should be considered as a successful hit or not
// The default behavior is to treat it as a success if being done to a team actor that belongs to a different team
// to the owning controller's pawn
virtual bool ShouldShowHitAsSuccess(const FHitResult& Hit) const;
virtual bool ShouldUpdateDamageInstigatedTime(const FGameplayEffectContextHandle& EffectContext) const;
void ActuallyUpdateDamageInstigatedTime();
private:
/** Last time this controller instigated weapon damage */
double LastWeaponDamageInstigatedTime = 0.0;
/** Screen-space locations of our most recently instigated weapon damage (the confirmed hits) */
TArray<FLyraScreenSpaceHitLocation> LastWeaponDamageScreenLocations;
/** The unconfirmed hits */
TArray<FLyraServerSideHitMarkerBatch> UnconfirmedServerSideHitMarkers;
};
|