109 lines
2.9 KiB
C++
109 lines
2.9 KiB
C++
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "GameplayEffectTypes.h"
|
|
#include "Runtime/Launch/Resources/Version.h"
|
|
#if ENGINE_MINOR_VERSION < 5
|
|
#include "InstancedStruct.h"
|
|
#else
|
|
#include "StructUtils/InstancedStruct.h"
|
|
#endif
|
|
#include "GGA_GameplayEffectContext.generated.h"
|
|
|
|
|
|
/**
|
|
*
|
|
*/
|
|
USTRUCT()
|
|
struct GENERICGAMEPLAYABILITIES_API FGGA_GameplayEffectContext : public FGameplayEffectContext
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
virtual FGameplayEffectContext* Duplicate() const override;
|
|
virtual UScriptStruct* GetScriptStruct() const override;
|
|
virtual bool NetSerialize(FArchive& Ar, UPackageMap* Map, bool& bOutSuccess) override;
|
|
|
|
TArray<FInstancedStruct>& GetPayloads();
|
|
|
|
void AddOrOverwriteData(const FInstancedStruct& DataInstance);
|
|
const FInstancedStruct* FindPayloadByType(const UScriptStruct* PayloadType) const;
|
|
FInstancedStruct* FindPayloadByType(const UScriptStruct* PayloadType);
|
|
FInstancedStruct* FindOrAddPayloadByType(const UScriptStruct* PayloadType);
|
|
FInstancedStruct* AddPayloadByType(const UScriptStruct* PayloadType);
|
|
bool RemovePayloadByType(const UScriptStruct* PayloadType);
|
|
|
|
/** Find payload of a specific type in this context (mutable version). If not found, null will be returned. */
|
|
template <typename T>
|
|
T* FindMutablePayloadByType()
|
|
{
|
|
if (FInstancedStruct* FoundData = FindPayloadByType(T::StaticStruct()))
|
|
{
|
|
return FoundData->GetMutablePtr<T>();
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
/** Find payload of a specific type in this context. If not found, null will be returned. */
|
|
template <typename T>
|
|
const T* FindPayload() const
|
|
{
|
|
if (const FInstancedStruct* FoundData = FindPayloadByType(T::StaticStruct()))
|
|
{
|
|
return FoundData->GetPtr<T>();
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
/** Find payload of a specific type in this context. If not found, a new default instance will be added. */
|
|
template <typename T>
|
|
const T& FindOrAddPayload()
|
|
{
|
|
if (const T* ExistingData = FindPayload<T>())
|
|
{
|
|
return *ExistingData;
|
|
}
|
|
FInstancedStruct* NewData = AddPayloadByType(T::StaticStruct());
|
|
return NewData->Get<T>();
|
|
}
|
|
|
|
/** Find payload of a specific type in this context. (mutable version). If not found, a new default instance will be added. */
|
|
template <typename T>
|
|
T& FindOrAddMutablePayload()
|
|
{
|
|
if (T* ExistingData = FindMutablePayloadByType<T>())
|
|
{
|
|
return *ExistingData;
|
|
}
|
|
FInstancedStruct* NewData = AddPayloadByType(T::StaticStruct());
|
|
return NewData->GetMutable<T>();
|
|
}
|
|
|
|
template <typename T>
|
|
T* FindOrAddMutablePayloadPtr()
|
|
{
|
|
if (T* ExistingData = FindMutablePayloadByType<T>())
|
|
{
|
|
return ExistingData;
|
|
}
|
|
FInstancedStruct* NewData = AddPayloadByType(T::StaticStruct());
|
|
return NewData->GetMutablePtr<T>();
|
|
}
|
|
|
|
protected:
|
|
UPROPERTY()
|
|
TArray<FInstancedStruct> Payloads;
|
|
};
|
|
|
|
|
|
template <>
|
|
struct TStructOpsTypeTraits<FGGA_GameplayEffectContext> : TStructOpsTypeTraitsBase2<FGGA_GameplayEffectContext>
|
|
{
|
|
enum
|
|
{
|
|
WithNetSerializer = true,
|
|
WithCopy = true
|
|
};
|
|
};
|