Skip to content

Commit

Permalink
Ability Queue System
Browse files Browse the repository at this point in the history
  • Loading branch information
JediKnightChan committed May 11, 2023
1 parent 35ac514 commit d909652
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Config/DefaultGameplayTags.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ NetIndexFirstBitSegment=16
+GameplayTagList=(Tag="Ability.Type.Passive.Interaction",DevComment="")
+GameplayTagList=(Tag="Ability.Type.PriorityAction.ADS",DevComment="")
+GameplayTagList=(Tag="Ability.Type.PriorityAction.Evade",DevComment="")
+GameplayTagList=(Tag="Ability.Type.PriorityAction.Evade.JumpPack",DevComment="")
+GameplayTagList=(Tag="Ability.Type.PriorityAction.Evade.Rolling",DevComment="")
+GameplayTagList=(Tag="Ability.Type.PriorityAction.Grenade",DevComment="")
+GameplayTagList=(Tag="Ability.Type.PriorityAction.Reload",DevComment="")
+GameplayTagList=(Tag="Ability.Type.PriorityAction.WeaponFire",DevComment="")
Expand Down Expand Up @@ -88,6 +90,7 @@ NetIndexFirstBitSegment=16
+GameplayTagList=(Tag="Event.Movement.Reload",DevComment="")
+GameplayTagList=(Tag="Event.Movement.Sprint",DevComment="")
+GameplayTagList=(Tag="Event.Movement.WeaponFire",DevComment="")
+GameplayTagList=(Tag="Gameplay.Stun.StunImmunity",DevComment="")
+GameplayTagList=(Tag="Gameplay.Zone.StrongSpot",DevComment="")
+GameplayTagList=(Tag="Gameplay.Zone.Weakspot",DevComment="")
+GameplayTagList=(Tag="GameplayCue.Character.Attributes.EvasionStamina.Added",DevComment="")
Expand Down
24 changes: 22 additions & 2 deletions Source/ECR/Private/Gameplay/Character/ECRPawnControlComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ UECRPawnControlComponent::UECRPawnControlComponent(const FObjectInitializer& Obj
bPawnHasInitialized = false;
bReadyToBindInputs = false;
bMovementInputEnabled = true;

bListenForAbilityQueue = false;
AbilityQueueDeltaTime = 0;
}

void UECRPawnControlComponent::OnRegister()
Expand Down Expand Up @@ -257,9 +260,25 @@ void UECRPawnControlComponent::BindNativeActions(UECRInputComponent* ECRIC, cons
{
const FECRGameplayTags& GameplayTags = FECRGameplayTags::Get();
ECRIC->BindNativeAction(InputConfig, GameplayTags.InputTag_Look_Mouse, ETriggerEvent::Triggered, this,
&ThisClass::Input_LookMouse, /*bLogIfNotFound=*/ true);
&ThisClass::Input_LookMouse, /*bLogIfNotFound=*/ true);
ECRIC->BindNativeAction(InputConfig, GameplayTags.InputTag_Look_Stick, ETriggerEvent::Triggered, this,
&ThisClass::Input_LookStick, /*bLogIfNotFound=*/ false);
&ThisClass::Input_LookStick, /*bLogIfNotFound=*/ false);
}

void UECRPawnControlComponent::NotifyAbilityQueueSystem(UECRAbilitySystemComponent* ASC, const FGameplayTag& InputTag)
{
if (InputTag.IsValid() && bListenForAbilityQueue && AbilityQueueInputTags.HasTagExact(InputTag))
{
ASC->AbilityQueueSystemLastInputTag = InputTag;
ASC->AbilityQueueSystemLastInputTagTime = GetWorld()->GetTimeSeconds();
ASC->AbilityQueueSystemDeltaTime = AbilityQueueDeltaTime;
}
else
{
ASC->AbilityQueueSystemLastInputTag = {};
ASC->AbilityQueueSystemLastInputTagTime = 0;
ASC->AbilityQueueSystemDeltaTime = 0;
}
}


Expand Down Expand Up @@ -317,6 +336,7 @@ void UECRPawnControlComponent::Input_AbilityInputTagPressed(FGameplayTag InputTa
if (UECRAbilitySystemComponent* ECRASC = PawnExtComp->GetECRAbilitySystemComponent())
{
ECRASC->AbilityInputTagPressed(InputTag);
NotifyAbilityQueueSystem(ECRASC, InputTag);
}
}
}
Expand Down
24 changes: 23 additions & 1 deletion Source/ECR/Private/Gameplay/GAS/Abilities/ECRGameplayAbility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ AECRCharacter* UECRGameplayAbility::GetECRCharacterFromActorInfo() const

UECRPawnControlComponent* UECRGameplayAbility::GetHeroComponentFromActorInfo() const
{
return (CurrentActorInfo ? UECRPawnControlComponent::FindPawnControlComonent(CurrentActorInfo->AvatarActor.Get()) : nullptr);
return (CurrentActorInfo
? UECRPawnControlComponent::FindPawnControlComonent(CurrentActorInfo->AvatarActor.Get())
: nullptr);
}

void UECRGameplayAbility::ToggleInputDisabled(const bool NewInputDisabled)
Expand Down Expand Up @@ -252,6 +254,8 @@ void UECRGameplayAbility::EndAbility(const FGameplayAbilitySpecHandle Handle,
ClearCameraMode();

Super::EndAbility(Handle, ActorInfo, ActivationInfo, bReplicateEndAbility, bWasCancelled);

CheckAbilityQueue(ActorInfo);
}

bool UECRGameplayAbility::CheckCost(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo,
Expand Down Expand Up @@ -558,6 +562,24 @@ UECRPawnComponent_CharacterParts* UECRGameplayAbility::GetPawnCustomizationCompo
}


void UECRGameplayAbility::CheckAbilityQueue(const FGameplayAbilityActorInfo* ActorInfo) const
{
if (UECRAbilitySystemComponent* ASC = Cast<UECRAbilitySystemComponent>(ActorInfo->AbilitySystemComponent.Get()))
{
const double CurrentTime = GetWorld()->GetTimeSeconds();

if (ASC->AbilityQueueSystemLastInputTag.IsValid() && (ASC->AbilityQueueSystemDeltaTime == 0 || CurrentTime - ASC
->AbilityQueueSystemLastInputTagTime < ASC->AbilityQueueSystemDeltaTime))
{
ASC->AbilityInputTagPressed(ASC->AbilityQueueSystemLastInputTag);
}

ASC->AbilityQueueSystemLastInputTag = {};
ASC->AbilityQueueSystemLastInputTagTime = 0;
}
}


void UECRGameplayAbility::LoadMontages()
{
TArray<FSoftObjectPath> MontagesToLoad;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ UE_DEFINE_GAMEPLAY_TAG(TAG_Gameplay_AbilityInputBlocked, "Gameplay.AbilityInputB
UECRAbilitySystemComponent::UECRAbilitySystemComponent(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
AbilityQueueSystemLastInputTag = {};
AbilityQueueSystemLastInputTagTime = 0;
AbilityQueueSystemDeltaTime = 0;

InputPressedSpecHandles.Reset();
InputReleasedSpecHandles.Reset();
InputHeldSpecHandles.Reset();
Expand Down Expand Up @@ -402,7 +406,7 @@ void UECRAbilitySystemComponent::ClearAllResettingOnDeathAbilities()
// Get all activatable abilities
TArray<FGameplayAbilitySpecHandle> OutSpecHandles;
GetAllAbilities(OutSpecHandles);

for (const FGameplayAbilitySpecHandle CurrentSpecHandle : OutSpecHandles)
{
const FGameplayAbilitySpec* AbilitySpec = FindAbilitySpecFromHandle(CurrentSpecHandle);
Expand Down
14 changes: 14 additions & 0 deletions Source/ECR/Public/Gameplay/Character/ECRPawnControlComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Gameplay/Camera/ECRCameraMode.h"
#include "GameplayTagContainer.h"
#include "GameplayAbilitySpec.h"
#include "Gameplay/GAS/ECRAbilitySet.h"
#include "Input/ECRMappableConfigPair.h"
#include "ECRPawnControlComponent.generated.h"

Expand Down Expand Up @@ -67,6 +68,8 @@ class UECRPawnControlComponent : public UECRPawnComponent
virtual void InitializePlayerInput(UInputComponent* PlayerInputComponent);
virtual void BindNativeActions(UECRInputComponent* ECRIC, const UECRInputConfig* InputConfig);

void NotifyAbilityQueueSystem(UECRAbilitySystemComponent* ASC, const FGameplayTag& InputTag);

void Input_AbilityInputTagPressed(FGameplayTag InputTag);
void Input_AbilityInputTagReleased(FGameplayTag InputTag);

Expand All @@ -76,6 +79,10 @@ class UECRPawnControlComponent : public UECRPawnComponent
TSubclassOf<UECRCameraMode> DetermineCameraMode() const;

protected:
/** List of input tags handled by ability queue system */
UPROPERTY(EditAnywhere)
FGameplayTagContainer AbilityQueueInputTags;

/**
* Input Configs that should be added to this player when initalizing the input.
*
Expand All @@ -99,4 +106,11 @@ class UECRPawnControlComponent : public UECRPawnComponent

// True if movement input enabled (by default)
bool bMovementInputEnabled;

public:
// True when should listen for ability queue
bool bListenForAbilityQueue;

// Delta time for ability queue system
double AbilityQueueDeltaTime;
};
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class UECRGameplayAbility : public UGameplayAbility
virtual void ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo,
const FGameplayAbilityActivationInfo ActivationInfo,
const FGameplayEventData* TriggerEventData) override;

virtual void EndAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo,
const FGameplayAbilityActivationInfo ActivationInfo, bool bReplicateEndAbility,
bool bWasCancelled) override;
Expand Down Expand Up @@ -199,7 +200,10 @@ class UECRGameplayAbility : public UGameplayAbility
void OnCharacterPartsChanged(UECRPawnComponent_CharacterParts* ComponentWithChangedParts);

UECRPawnComponent_CharacterParts* GetPawnCustomizationComponent() const;
protected:

/** Check for ability queue on ASC, if need to activate any queued ability */
void CheckAbilityQueue(const FGameplayAbilityActorInfo* ActorInfo) const;

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Animation")
TMap<FName, FECRAnimMontageSelectionSet> AbilityMontageSelection;

Expand Down
12 changes: 12 additions & 0 deletions Source/ECR/Public/Gameplay/GAS/ECRAbilitySystemComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,16 @@ class UECRAbilitySystemComponent : public UAbilitySystemComponent

// Number of abilities running in each activation group.
int32 ActivationGroupCounts[(uint8)EECRAbilityActivationGroup::MAX];

public:
// Ability Queue System

// Latest input tag received
FGameplayTag AbilityQueueSystemLastInputTag;

// Time when received
double AbilityQueueSystemLastInputTagTime;

// Delta time
double AbilityQueueSystemDeltaTime;
};
35 changes: 35 additions & 0 deletions Source/ECR/Public/Input/AnimNotifyState_ECRAbilityQueueListen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "AnimNotifyState_ECRAbilityQueueListen.h"

#include "Gameplay/Character/ECRPawnControlComponent.h"

void UAnimNotifyState_ECRAbilityQueueListen::NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation)
{
AActor* Actor = MeshComp->GetOwner();
if (!Actor->HasLocalNetOwner())
{
return;
}

if (UECRPawnControlComponent* PCC = Actor->FindComponentByClass<UECRPawnControlComponent>())
{
PCC->bListenForAbilityQueue = false;
PCC->AbilityQueueDeltaTime = 0;
}
}

void UAnimNotifyState_ECRAbilityQueueListen::NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation,
float TotalDuration,
const FAnimNotifyEventReference& EventReference)
{
AActor* Actor = MeshComp->GetOwner();
if (!Actor->HasLocalNetOwner())
{
return;
}

if (UECRPawnControlComponent* PCC = Actor->FindComponentByClass<UECRPawnControlComponent>())
{
PCC->bListenForAbilityQueue = true;
PCC->AbilityQueueDeltaTime = AbilityQueueDeltaTime;
}
}
28 changes: 28 additions & 0 deletions Source/ECR/Public/Input/AnimNotifyState_ECRAbilityQueueListen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyleft: All rights reversed

#pragma once

#include "CoreMinimal.h"
#include "FMODBlueprintStatics.h"
#include "Animation/AnimNotifies/AnimNotifyState.h"
#include "AnimNotifyState_ECRAbilityQueueListen.generated.h"


/**
* UAnimNotifyState_ECRAbilityQueueListen
*
* Set bListenForAbilityQueue to true on PawnControlComponent while active
*/
UCLASS()
class ECR_API UAnimNotifyState_ECRAbilityQueueListen : public UAnimNotifyState
{
GENERATED_BODY()

UPROPERTY(EditAnywhere, BlueprintReadOnly, meta=(AllowPrivateAccess="true"))
double AbilityQueueDeltaTime = 0;

public:
virtual void NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override;
virtual void NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float TotalDuration,
const FAnimNotifyEventReference& EventReference) override;
};

0 comments on commit d909652

Please sign in to comment.