// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "GameplayEffectTypes.h" #include "HAL/Platform.h" #include "UObject/Class.h" #include "UObject/WeakObjectPtr.h" #include "UObject/WeakObjectPtrTemplates.h" #include "LyraGameplayEffectContext.generated.h" class AActor; class FArchive; class ILyraAbilitySourceInterface; class UObject; class UPhysicalMaterial; USTRUCT() struct FLyraGameplayEffectContext : public FGameplayEffectContext { GENERATED_BODY() FLyraGameplayEffectContext() : FGameplayEffectContext() { } FLyraGameplayEffectContext(AActor* InInstigator, AActor* InEffectCauser) : FGameplayEffectContext(InInstigator, InEffectCauser) { } /** Returns the wrapped FLyraGameplayEffectContext from the handle, or nullptr if it doesn't exist or is the wrong type */ static LYRAGAME_API FLyraGameplayEffectContext* ExtractEffectContext(struct FGameplayEffectContextHandle Handle); /** Sets the object used as the ability source */ void SetAbilitySource(const ILyraAbilitySourceInterface* InObject, float InSourceLevel); /** Returns the ability source interface associated with the source object. Only valid on the authority. */ const ILyraAbilitySourceInterface* GetAbilitySource() const; virtual FGameplayEffectContext* Duplicate() const override { FLyraGameplayEffectContext* NewContext = new FLyraGameplayEffectContext(); *NewContext = *this; if (GetHitResult()) { // Does a deep copy of the hit result NewContext->AddHitResult(*GetHitResult(), true); } return NewContext; } virtual UScriptStruct* GetScriptStruct() const override { return FLyraGameplayEffectContext::StaticStruct(); } /** Overridden to serialize new fields */ virtual bool NetSerialize(FArchive& Ar, class UPackageMap* Map, bool& bOutSuccess) override; /** Returns the physical material from the hit result if there is one */ const UPhysicalMaterial* GetPhysicalMaterial() const; public: /** ID to allow the identification of multiple bullets that were part of the same cartridge */ UPROPERTY() int32 CartridgeID = -1; protected: /** Ability Source object (should implement ILyraAbilitySourceInterface). NOT replicated currently */ UPROPERTY() TWeakObjectPtr AbilitySourceObject; }; template<> struct TStructOpsTypeTraits : public TStructOpsTypeTraitsBase2 { enum { WithNetSerializer = true, WithCopy = true }; };