Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
v1.1.11 (#7)
Browse files Browse the repository at this point in the history
* Adjustments

* Adjustments

* Update version

* Adjust deactivations and actor spawning

* Adjustments in all features to enhance readability and actor spawning

* Adjustments to avoid packaging errors

* const!! 0.0

* Code adjustments to enhance visualization in any screen size (remove unnecessary line breaks

* Add const specifier to var init

* Adjust validation on remove and spawning delegate removal

* Update info
  • Loading branch information
lucoiso authored Sep 15, 2022
1 parent acb55ad commit 447abd2
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 217 deletions.
Binary file modified ModularFeatures_ExtraActions.uplugin
Binary file not shown.
61 changes: 19 additions & 42 deletions Source/Private/GameFeatureAction_AddAbilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,22 @@ void UGameFeatureAction_AddAbilities::AddToWorld(const FWorldContext& WorldConte
{
using FHandlerDelegate = UGameFrameworkComponentManager::FExtensionHandlerDelegate;

const FHandlerDelegate ExtensionHandlerDelegate =
FHandlerDelegate::CreateUObject(this, &UGameFeatureAction_AddAbilities::HandleActorExtension);
const FHandlerDelegate ExtensionHandlerDelegate = FHandlerDelegate::CreateUObject(this, &UGameFeatureAction_AddAbilities::HandleActorExtension);

ActiveRequests.Add(ComponentManager->AddExtensionHandler(TargetPawnClass, ExtensionHandlerDelegate));
}
}

void UGameFeatureAction_AddAbilities::HandleActorExtension(AActor* Owner, const FName EventName)
{
UE_LOG(LogGameplayFeaturesExtraActions, Display,
TEXT("Event %s sent by Actor %s for ability management."),
*EventName.ToString(), *Owner->GetName());
UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("Event %s sent by Actor %s for ability management."), *EventName.ToString(), *Owner->GetName());

if (EventName == UGameFrameworkComponentManager::NAME_ExtensionRemoved
|| EventName == UGameFrameworkComponentManager::NAME_ReceiverRemoved)
if (EventName == UGameFrameworkComponentManager::NAME_ExtensionRemoved || EventName == UGameFrameworkComponentManager::NAME_ReceiverRemoved)
{
RemoveActorAbilities(Owner);
}

else if (EventName == UGameFrameworkComponentManager::NAME_ExtensionAdded
|| EventName == UGameFrameworkComponentManager::NAME_GameActorReady)
else if (EventName == UGameFrameworkComponentManager::NAME_ExtensionAdded || EventName == UGameFrameworkComponentManager::NAME_GameActorReady)
{
if (ActiveExtensions.Contains(Owner) || !ActorHasAllRequiredTags(Owner, RequireTags))
{
Expand Down Expand Up @@ -98,19 +93,13 @@ void UGameFeatureAction_AddAbilities::AddActorAbilities(AActor* TargetActor, con
{
FActiveAbilityData& NewAbilityData = ActiveExtensions.FindOrAdd(TargetActor);

const uint32 InputID =
InputIDEnumerationClass.LoadSynchronous()->GetValueByName(Ability.InputIDValueName,
EGetByNameFlags::CheckAuthoredName);
const uint32 InputID = InputIDEnumerationClass.LoadSynchronous()->GetValueByName(Ability.InputIDValueName, EGetByNameFlags::CheckAuthoredName);

const TSubclassOf<UGameplayAbility> AbilityToAdd = Ability.AbilityClass.LoadSynchronous();

UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Adding ability %s to Actor %s."),
*FString(__func__), *AbilityToAdd->GetName(), *TargetActor->GetName());
UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Adding ability %s to Actor %s."), *FString(__func__), *AbilityToAdd->GetName(), *TargetActor->GetName());

const FGameplayAbilitySpec NewAbilitySpec(AbilityToAdd,
Ability.AbilityLevel,
InputID,
TargetActor);
const FGameplayAbilitySpec NewAbilitySpec(AbilityToAdd, Ability.AbilityLevel, InputID, TargetActor);

if (const FGameplayAbilitySpecHandle NewSpecHandle = AbilitySystemComponent->GiveAbility(NewAbilitySpec);
NewSpecHandle.IsValid())
Expand All @@ -119,20 +108,16 @@ void UGameFeatureAction_AddAbilities::AddActorAbilities(AActor* TargetActor, con

if (!Ability.InputAction.IsNull())
{
if (IAbilityInputBinding* const SetupInputInterface = ModularFeaturesHelper::GetAbilityInputBindingInterface(TargetActor, InputBindingOwner))
if (const IAbilityInputBinding* const SetupInputInterface = ModularFeaturesHelper::GetAbilityInputBindingInterface(TargetActor, InputBindingOwner))
{
UInputAction* AbilityInput = Ability.InputAction.LoadSynchronous();
IAbilityInputBinding::Execute_SetupAbilityInputBinding(SetupInputInterface->_getUObject(),
AbilityInput,
InputID);
UInputAction* const AbilityInput = Ability.InputAction.LoadSynchronous();
IAbilityInputBinding::Execute_SetupAbilityInputBinding(SetupInputInterface->_getUObject(), AbilityInput, InputID);

NewAbilityData.InputReference.Add(AbilityInput);
}
else
{
UE_LOG(LogGameplayFeaturesExtraActions, Error,
TEXT("%s: Failed to setup input binding for ability %s on Actor %s."),
*FString(__func__), *AbilityToAdd->GetName(), *TargetActor->GetName());
UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to setup input binding for ability %s on Actor %s."), *FString(__func__), *AbilityToAdd->GetName(), *TargetActor->GetName());
}
}

Expand All @@ -141,40 +126,34 @@ void UGameFeatureAction_AddAbilities::AddActorAbilities(AActor* TargetActor, con
}
else
{
UE_LOG(LogGameplayFeaturesExtraActions, Error,
TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."),
*FString(__func__), *TargetActor->GetName());
UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName());
}
}

void UGameFeatureAction_AddAbilities::RemoveActorAbilities(AActor* TargetActor)
{
if (TargetActor->GetLocalRole() != ROLE_Authority)
if (!IsValid(TargetActor))
{
ActiveExtensions.Remove(TargetActor);
return;
}

if (!IsValid(TargetActor))
if (TargetActor->GetLocalRole() != ROLE_Authority)
{
ActiveExtensions.Remove(TargetActor);
return;
}

const FActiveAbilityData ActiveAbilities = ActiveExtensions.FindRef(TargetActor);

if constexpr (&ActiveAbilities == nullptr)
{
UE_LOG(LogGameplayFeaturesExtraActions, Warning,
TEXT("%s: No active abilities found for Actor %s."),
*FString(__func__), *TargetActor->GetName());
UE_LOG(LogGameplayFeaturesExtraActions, Warning, TEXT("%s: No active abilities found for Actor %s."), *FString(__func__), *TargetActor->GetName());
}
else
{
if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentByActor(TargetActor))
{
UE_LOG(LogGameplayFeaturesExtraActions, Display,
TEXT("%s: Removing associated abilities from Actor %s."),
*FString(__func__), *TargetActor->GetName());
UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Removing associated abilities from Actor %s."), *FString(__func__), *TargetActor->GetName());

for (const FGameplayAbilitySpecHandle& SpecHandle : ActiveAbilities.SpecHandle)
{
Expand All @@ -185,7 +164,7 @@ void UGameFeatureAction_AddAbilities::RemoveActorAbilities(AActor* TargetActor)
}
}

if (IAbilityInputBinding* const SetupInputInterface = ModularFeaturesHelper::GetAbilityInputBindingInterface(TargetActor, InputBindingOwner))
if (const IAbilityInputBinding* const SetupInputInterface = ModularFeaturesHelper::GetAbilityInputBindingInterface(TargetActor, InputBindingOwner))
{
for (const UInputAction* const& InputRef : ActiveAbilities.InputReference)
{
Expand All @@ -198,9 +177,7 @@ void UGameFeatureAction_AddAbilities::RemoveActorAbilities(AActor* TargetActor)
}
else if (IsValid(GetWorld()) && IsValid(GetWorld()->GetGameInstance()))
{
UE_LOG(LogGameplayFeaturesExtraActions, Error,
TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."),
*FString(__func__), *TargetActor->GetName());
UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName());
}
}

Expand Down
41 changes: 14 additions & 27 deletions Source/Private/GameFeatureAction_AddAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,22 @@ void UGameFeatureAction_AddAttribute::AddToWorld(const FWorldContext& WorldConte
{
using FHandlerDelegate = UGameFrameworkComponentManager::FExtensionHandlerDelegate;

const FHandlerDelegate ExtensionHandlerDelegate =
FHandlerDelegate::CreateUObject(this, &UGameFeatureAction_AddAttribute::HandleActorExtension);
const FHandlerDelegate ExtensionHandlerDelegate = FHandlerDelegate::CreateUObject(this, &UGameFeatureAction_AddAttribute::HandleActorExtension);

ActiveRequests.Add(ComponentManager->AddExtensionHandler(TargetPawnClass, ExtensionHandlerDelegate));
}
}

void UGameFeatureAction_AddAttribute::HandleActorExtension(AActor* Owner, const FName EventName)
{
UE_LOG(LogGameplayFeaturesExtraActions, Display,
TEXT("Event %s sent by Actor %s for attribute management."),
*EventName.ToString(), *Owner->GetName());
UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("Event %s sent by Actor %s for attribute management."), *EventName.ToString(), *Owner->GetName());

if (EventName == UGameFrameworkComponentManager::NAME_ExtensionRemoved
|| EventName == UGameFrameworkComponentManager::NAME_ReceiverRemoved)
if (EventName == UGameFrameworkComponentManager::NAME_ExtensionRemoved || EventName == UGameFrameworkComponentManager::NAME_ReceiverRemoved)
{
RemoveAttribute(Owner);
}

else if (EventName == UGameFrameworkComponentManager::NAME_ExtensionAdded
|| EventName == UGameFrameworkComponentManager::NAME_GameActorReady)
else if (EventName == UGameFrameworkComponentManager::NAME_ExtensionAdded || EventName == UGameFrameworkComponentManager::NAME_GameActorReady)
{
if (ActiveExtensions.Contains(Owner) || !ActorHasAllRequiredTags(Owner, RequireTags))
{
Expand All @@ -87,12 +82,12 @@ void UGameFeatureAction_AddAttribute::AddAttribute(AActor* TargetActor)
{
return;
}

if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentByActor(TargetActor))
{
if (const TSubclassOf<UAttributeSet> SetType = Attribute.LoadSynchronous())
{
UAttributeSet* NewSet = NewObject<UAttributeSet>(AbilitySystemComponent->GetOwnerActor(), SetType);
UAttributeSet* const NewSet = NewObject<UAttributeSet>(AbilitySystemComponent->GetOwnerActor(), SetType);

if (!InitializationData.IsNull())
{
Expand All @@ -102,9 +97,7 @@ void UGameFeatureAction_AddAttribute::AddAttribute(AActor* TargetActor)
AbilitySystemComponent->AddAttributeSetSubobject(NewSet);
AbilitySystemComponent->ForceReplication();

UE_LOG(LogGameplayFeaturesExtraActions, Display,
TEXT("%s: Attribute %s added to Actor %s."), *FString(__func__),
*SetType->GetName(), *TargetActor->GetName());
UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Attribute %s added to Actor %s."), *FString(__func__), *SetType->GetName(), *TargetActor->GetName());

ActiveExtensions.Add(TargetActor, NewSet);
}
Expand All @@ -115,42 +108,36 @@ void UGameFeatureAction_AddAttribute::AddAttribute(AActor* TargetActor)
}
else
{
UE_LOG(LogGameplayFeaturesExtraActions, Error,
TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."),
*FString(__func__), *TargetActor->GetName());
UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName());
}
}

void UGameFeatureAction_AddAttribute::RemoveAttribute(AActor* TargetActor)
{
if (TargetActor->GetLocalRole() != ROLE_Authority)
if (!IsValid(TargetActor))
{
ActiveExtensions.Remove(TargetActor);
return;
}

if (!IsValid(TargetActor))
if (TargetActor->GetLocalRole() != ROLE_Authority)
{
ActiveExtensions.Remove(TargetActor);
return;
}

if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentByActor(TargetActor))
{
if (UAttributeSet* const AttributeToRemove = ActiveExtensions.FindRef(TargetActor).Get();
AbilitySystemComponent->GetSpawnedAttributes_Mutable().Remove(AttributeToRemove) != 0)
{
UE_LOG(LogGameplayFeaturesExtraActions, Display,
TEXT("%s: Attribute %s removed from Actor %s."), *FString(__func__),
*AttributeToRemove->GetName(), *TargetActor->GetName());
UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Attribute %s removed from Actor %s."), *FString(__func__), *AttributeToRemove->GetName(), *TargetActor->GetName());

AbilitySystemComponent->ForceReplication();
}
}
else if (IsValid(GetWorld()) && IsValid(GetWorld()->GetGameInstance()))
{
UE_LOG(LogGameplayFeaturesExtraActions, Error,
TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."),
*FString(__func__), *TargetActor->GetName());
UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName());
}

ActiveExtensions.Remove(TargetActor);
Expand Down
45 changes: 14 additions & 31 deletions Source/Private/GameFeatureAction_AddEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,22 @@ void UGameFeatureAction_AddEffects::AddToWorld(const FWorldContext& WorldContext
{
using FHandlerDelegate = UGameFrameworkComponentManager::FExtensionHandlerDelegate;

const FHandlerDelegate ExtensionHandlerDelegate =
FHandlerDelegate::CreateUObject(this, &UGameFeatureAction_AddEffects::HandleActorExtension);
const FHandlerDelegate ExtensionHandlerDelegate = FHandlerDelegate::CreateUObject(this, &UGameFeatureAction_AddEffects::HandleActorExtension);

ActiveRequests.Add(ComponentManager->AddExtensionHandler(TargetPawnClass, ExtensionHandlerDelegate));
}
}

void UGameFeatureAction_AddEffects::HandleActorExtension(AActor* Owner, const FName EventName)
{
UE_LOG(LogGameplayFeaturesExtraActions, Display,
TEXT("Event %s sent by Actor %s for effects management."),
*EventName.ToString(), *Owner->GetName());
UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("Event %s sent by Actor %s for effects management."), *EventName.ToString(), *Owner->GetName());

if (EventName == UGameFrameworkComponentManager::NAME_ExtensionRemoved
|| EventName == UGameFrameworkComponentManager::NAME_ReceiverRemoved)
if (EventName == UGameFrameworkComponentManager::NAME_ExtensionRemoved || EventName == UGameFrameworkComponentManager::NAME_ReceiverRemoved)
{
RemoveEffects(Owner);
}

else if (EventName == UGameFrameworkComponentManager::NAME_ExtensionAdded
|| EventName == UGameFrameworkComponentManager::NAME_GameActorReady)
else if (EventName == UGameFrameworkComponentManager::NAME_ExtensionAdded || EventName == UGameFrameworkComponentManager::NAME_GameActorReady)
{
if (ActiveExtensions.Contains(Owner) || !ActorHasAllRequiredTags(Owner, RequireTags))
{
Expand All @@ -90,53 +85,44 @@ void UGameFeatureAction_AddEffects::AddEffects(AActor* TargetActor, const FEffec
{
return;
}

if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentByActor(TargetActor))
{
TArray<FActiveGameplayEffectHandle>& SpecData = ActiveExtensions.FindOrAdd(TargetActor);

const TSubclassOf<UGameplayEffect> EffectClass = Effect.EffectClass.LoadSynchronous();

UE_LOG(LogGameplayFeaturesExtraActions, Display,
TEXT("%s: Adding effect %s level %u to Actor %s with %u SetByCaller params."),
*FString(__func__), *EffectClass->GetName(), Effect.EffectLevel,
*TargetActor->GetName(), Effect.SetByCallerParams.Num());
UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Adding effect %s level %u to Actor %s with %u SetByCaller params."), *FString(__func__), *EffectClass->GetName(), Effect.EffectLevel, *TargetActor->GetName(), Effect.SetByCallerParams.Num());

const FGameplayEffectSpecHandle SpecHandle =
AbilitySystemComponent->MakeOutgoingSpec(EffectClass,
Effect.EffectLevel,
AbilitySystemComponent->MakeEffectContext());
const FGameplayEffectSpecHandle SpecHandle = AbilitySystemComponent->MakeOutgoingSpec(EffectClass, Effect.EffectLevel, AbilitySystemComponent->MakeEffectContext());

for (const TPair<FGameplayTag, float>& SetByCallerParam : Effect.SetByCallerParams)
{
SpecHandle.Data.Get()->SetSetByCallerMagnitude(SetByCallerParam.Key, SetByCallerParam.Value);
}

const FActiveGameplayEffectHandle NewActiveEffect =
AbilitySystemComponent->ApplyGameplayEffectSpecToSelf(*SpecHandle.Data.Get());
const FActiveGameplayEffectHandle NewActiveEffect = AbilitySystemComponent->ApplyGameplayEffectSpecToSelf(*SpecHandle.Data.Get());

SpecData.Add(NewActiveEffect);

ActiveExtensions.Add(TargetActor, SpecData);
}
else
{
UE_LOG(LogGameplayFeaturesExtraActions, Error,
TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."),
*FString(__func__), *TargetActor->GetName());
UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName());
}
}

void UGameFeatureAction_AddEffects::RemoveEffects(AActor* TargetActor)
{
if (TargetActor->GetLocalRole() != ROLE_Authority)
if (!IsValid(TargetActor))
{
ActiveExtensions.Remove(TargetActor);
return;
}

if (!IsValid(TargetActor))
if (TargetActor->GetLocalRole() != ROLE_Authority)
{
ActiveExtensions.Remove(TargetActor);
return;
}

Expand All @@ -145,8 +131,7 @@ void UGameFeatureAction_AddEffects::RemoveEffects(AActor* TargetActor)
{
if (UAbilitySystemComponent* const AbilitySystemComponent = ModularFeaturesHelper::GetAbilitySystemComponentByActor(TargetActor))
{
UE_LOG(LogGameplayFeaturesExtraActions, Display,
TEXT("%s: Removing effects from Actor %s."), *FString(__func__), *TargetActor->GetName());
UE_LOG(LogGameplayFeaturesExtraActions, Display, TEXT("%s: Removing effects from Actor %s."), *FString(__func__), *TargetActor->GetName());

for (const FActiveGameplayEffectHandle& EffectHandle : ActiveEffects)
{
Expand All @@ -158,9 +143,7 @@ void UGameFeatureAction_AddEffects::RemoveEffects(AActor* TargetActor)
}
else if (IsValid(GetWorld()) && IsValid(GetWorld()->GetGameInstance()))
{
UE_LOG(LogGameplayFeaturesExtraActions, Error,
TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."),
*FString(__func__), *TargetActor->GetName());
UE_LOG(LogGameplayFeaturesExtraActions, Error, TEXT("%s: Failed to find AbilitySystemComponent on Actor %s."), *FString(__func__), *TargetActor->GetName());
}
}

Expand Down
Loading

0 comments on commit 447abd2

Please sign in to comment.