第一次提交
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
|
||||
#include "GGA_AbilitySystemGlobals.h"
|
||||
|
||||
#include "GameplayEffect.h"
|
||||
#include "GGA_GameplayEffectContext.h"
|
||||
#include "GGA_LogChannels.h"
|
||||
|
||||
void UGGA_AbilitySystemGlobals::GlobalPreGameplayEffectSpecApply(FGameplayEffectSpec& Spec, UAbilitySystemComponent* AbilitySystemComponent)
|
||||
{
|
||||
for (TScriptInterface Receiver : Receivers)
|
||||
{
|
||||
Receiver->ReceiveGlobalPreGameplayEffectSpecApply(Spec, AbilitySystemComponent);
|
||||
}
|
||||
}
|
||||
|
||||
FGameplayEffectContext* UGGA_AbilitySystemGlobals::AllocGameplayEffectContext() const
|
||||
{
|
||||
return new FGGA_GameplayEffectContext();
|
||||
}
|
||||
|
||||
const UAbilitySystemGlobals* UGGA_AbilitySystemGlobals::GetAbilitySystemGlobals()
|
||||
{
|
||||
if (const UAbilitySystemGlobals* ASG = IGameplayAbilitiesModule::Get().GetAbilitySystemGlobals())
|
||||
{
|
||||
return ASG;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const UAbilitySystemGlobals* UGGA_AbilitySystemGlobals::GetTypedAbilitySystemGloabls(TSubclassOf<UAbilitySystemGlobals> DesiredClass)
|
||||
{
|
||||
if (UClass* RealClass = DesiredClass)
|
||||
{
|
||||
if (const UAbilitySystemGlobals* ASG = IGameplayAbilitiesModule::Get().GetAbilitySystemGlobals())
|
||||
{
|
||||
if (ASG->GetClass()->IsChildOf(RealClass))
|
||||
{
|
||||
return ASG;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void UGGA_AbilitySystemGlobals::RegisterEventReceiver(TScriptInterface<IGGA_AbilitySystemGlobalsEventReceiver> NewReceiver)
|
||||
{
|
||||
UGGA_AbilitySystemGlobals* Globals = dynamic_cast<UGGA_AbilitySystemGlobals*>(&Get());
|
||||
|
||||
if (Globals != nullptr)
|
||||
{
|
||||
if (NewReceiver != nullptr && IsValid(NewReceiver.GetObject()) && !Globals->Receivers.Contains(NewReceiver))
|
||||
{
|
||||
Globals->Receivers.Add(NewReceiver);
|
||||
UE_LOG(LogGGA_AbilitySystem, VeryVerbose, TEXT("RegisterEventReceiver:%s"), *NewReceiver.GetObject()->GetName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UGGA_AbilitySystemGlobals::UnregisterEventReceiver(TScriptInterface<IGGA_AbilitySystemGlobalsEventReceiver> NewReceiver)
|
||||
{
|
||||
UGGA_AbilitySystemGlobals* Globals = dynamic_cast<UGGA_AbilitySystemGlobals*>(&Get());
|
||||
|
||||
if (Globals != nullptr)
|
||||
{
|
||||
if (NewReceiver != nullptr && IsValid(NewReceiver.GetObject()) && Globals->Receivers.Contains(NewReceiver))
|
||||
{
|
||||
Globals->Receivers.Remove(NewReceiver);
|
||||
UE_LOG(LogGGA_AbilitySystem, VeryVerbose, TEXT("UnregisterEventReceiver:%s"), *NewReceiver.GetObject()->GetName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TArray<UCurveTable*> UGGA_AbilitySystemGlobals::GetAttributeDefaultsTables() const
|
||||
{
|
||||
return GlobalAttributeDefaultsTables;
|
||||
}
|
||||
|
||||
void UGGA_AbilitySystemGlobals::InitAttributeSetDefaults(UAbilitySystemComponent* AbilitySystem, const FGGA_AttributeGroupName& GroupName, int32 Level, bool bInitialInit) const
|
||||
{
|
||||
if (GlobalAttributeSetInitter.IsValid())
|
||||
{
|
||||
if (FAttributeSetInitter* Initter = GetAttributeSetInitter())
|
||||
{
|
||||
if (GroupName.IsValid())
|
||||
{
|
||||
Initter->InitAttributeSetDefaults(AbilitySystem, GroupName.GetName(), Level, bInitialInit);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogGGA_AbilitySystem, Warning, TEXT("You don't have any GlobalAttributeSetDefaultsTableNames configured in your AbilitySystemGlobals setting."))
|
||||
}
|
||||
}
|
||||
|
||||
void UGGA_AbilitySystemGlobals::ApplyAttributeDefault(UAbilitySystemComponent* AbilitySystem, FGameplayAttribute& InAttribute, const FGGA_AttributeGroupName& GroupName, int32 Level) const
|
||||
{
|
||||
if (GlobalAttributeSetInitter.IsValid())
|
||||
{
|
||||
if (FAttributeSetInitter* Initter = GetAttributeSetInitter())
|
||||
{
|
||||
if (GroupName.IsValid())
|
||||
{
|
||||
Initter->ApplyAttributeDefault(AbilitySystem, InAttribute, GroupName.GetName(), Level);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogGGA_AbilitySystem, Warning, TEXT("You don't have any GlobalAttributeSetDefaultsTableNames configured in your AbilitySystemGlobals setting."))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void IGGA_AbilitySystemGlobalsEventReceiver::ReceiveGlobalPreGameplayEffectSpecApply(FGameplayEffectSpec& Spec, UAbilitySystemComponent* AbilitySystemComponent)
|
||||
{
|
||||
OnGlobalPreGameplayEffectSpecApply(Spec, AbilitySystemComponent);
|
||||
|
||||
FGameplayTagContainer DynamicTags;
|
||||
Execute_OnGlobalPreGameplayEffectSpecApply_Bp(_getUObject(), Spec, AbilitySystemComponent, DynamicTags);
|
||||
if (!DynamicTags.IsEmpty())
|
||||
{
|
||||
Spec.AppendDynamicAssetTags(DynamicTags);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
|
||||
#include "GGA_GameplayAbilityTargetData_Payload.h"
|
||||
@@ -0,0 +1,143 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
|
||||
#include "Globals/GGA_GameplayEffectContext.h"
|
||||
|
||||
FGameplayEffectContext* FGGA_GameplayEffectContext::Duplicate() const
|
||||
{
|
||||
FGGA_GameplayEffectContext* NewContext = new FGGA_GameplayEffectContext();
|
||||
*NewContext = *this;
|
||||
if (GetHitResult())
|
||||
{
|
||||
// Does a deep copy of the hit result
|
||||
NewContext->AddHitResult(*GetHitResult(), true);
|
||||
}
|
||||
return NewContext;
|
||||
}
|
||||
|
||||
UScriptStruct* FGGA_GameplayEffectContext::GetScriptStruct() const
|
||||
{
|
||||
return StaticStruct();
|
||||
}
|
||||
|
||||
//Reference this:https://www.thegames.dev/?p=62
|
||||
|
||||
bool FGGA_GameplayEffectContext::NetSerialize(FArchive& Ar, UPackageMap* Map, bool& bOutSuccess)
|
||||
{
|
||||
bool bCombinedSuccess = FGameplayEffectContext::NetSerialize(Ar, Map, bOutSuccess);
|
||||
|
||||
enum RepFlag
|
||||
{
|
||||
REP_ContextPayloads,
|
||||
REP_MAX
|
||||
};
|
||||
|
||||
uint16 RepBits = 0;
|
||||
if (Ar.IsSaving())
|
||||
{
|
||||
if (Payloads.Num() > 0)
|
||||
{
|
||||
RepBits |= 1 << REP_ContextPayloads;
|
||||
}
|
||||
}
|
||||
|
||||
Ar.SerializeBits(&RepBits, REP_MAX);
|
||||
if (RepBits & (1 << REP_ContextPayloads))
|
||||
{
|
||||
// or also check if Ar.IsSaving || Ar.IsLoading
|
||||
bCombinedSuccess &= SafeNetSerializeTArray_WithNetSerialize<31>(Ar, Payloads, Map);
|
||||
}
|
||||
|
||||
return bCombinedSuccess;
|
||||
}
|
||||
|
||||
TArray<FInstancedStruct>& FGGA_GameplayEffectContext::GetPayloads()
|
||||
{
|
||||
return Payloads;
|
||||
}
|
||||
|
||||
void FGGA_GameplayEffectContext::AddOrOverwriteData(const FInstancedStruct& DataInstance)
|
||||
{
|
||||
RemovePayloadByType(DataInstance.GetScriptStruct());
|
||||
Payloads.Add(DataInstance);
|
||||
}
|
||||
|
||||
const FInstancedStruct* FGGA_GameplayEffectContext::FindPayloadByType(const UScriptStruct* PayloadType) const
|
||||
{
|
||||
for (const FInstancedStruct& Payload : Payloads)
|
||||
{
|
||||
if (const UScriptStruct* CandidateStruct = Payload.GetScriptStruct())
|
||||
{
|
||||
if (CandidateStruct == PayloadType)
|
||||
{
|
||||
return &Payload;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FInstancedStruct* FGGA_GameplayEffectContext::FindPayloadByType(const UScriptStruct* PayloadType)
|
||||
{
|
||||
for (FInstancedStruct& Payload : Payloads)
|
||||
{
|
||||
if (const UScriptStruct* CandidateStruct = Payload.GetScriptStruct())
|
||||
{
|
||||
if (CandidateStruct == PayloadType)
|
||||
{
|
||||
return &Payload;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FInstancedStruct* FGGA_GameplayEffectContext::FindOrAddPayloadByType(const UScriptStruct* PayloadType)
|
||||
{
|
||||
if (FInstancedStruct* ExistingData = FindPayloadByType(PayloadType))
|
||||
{
|
||||
return ExistingData;
|
||||
}
|
||||
|
||||
return AddPayloadByType(PayloadType);
|
||||
}
|
||||
|
||||
FInstancedStruct* FGGA_GameplayEffectContext::AddPayloadByType(const UScriptStruct* PayloadType)
|
||||
{
|
||||
if (ensure(!FindPayloadByType(PayloadType)))
|
||||
{
|
||||
FInstancedStruct Data;
|
||||
Data.InitializeAs(PayloadType);
|
||||
AddOrOverwriteData(Data);
|
||||
return FindPayloadByType(PayloadType);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool FGGA_GameplayEffectContext::RemovePayloadByType(const UScriptStruct* PayloadType)
|
||||
{
|
||||
int32 IndexToRemove = -1;
|
||||
|
||||
for (int32 i = 0; i < Payloads.Num() && IndexToRemove < 0; ++i)
|
||||
{
|
||||
if (const UScriptStruct* CandidateStruct = Payloads[i].GetScriptStruct())
|
||||
{
|
||||
if (CandidateStruct == PayloadType)
|
||||
{
|
||||
IndexToRemove = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (IndexToRemove >= 0)
|
||||
{
|
||||
Payloads.RemoveAt(IndexToRemove);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user