RealtimeStyleTransferRuntime/Source/LyraGame/AbilitySystem/Abilities/LyraGameplayAbility_Jump.cpp

74 lines
2.3 KiB
C++
Raw Permalink Normal View History

2022-05-23 18:41:30 +00:00
// Copyright Epic Games, Inc. All Rights Reserved.
#include "LyraGameplayAbility_Jump.h"
2022-09-13 07:18:28 +00:00
#include "Abilities/GameplayAbilityTypes.h"
2022-05-23 18:41:30 +00:00
#include "Character/LyraCharacter.h"
2022-09-13 07:18:28 +00:00
#include "Containers/EnumAsByte.h"
#include "GameFramework/Actor.h"
#include "Templates/Casts.h"
#include "UObject/WeakObjectPtr.h"
#include "UObject/WeakObjectPtrTemplates.h"
struct FGameplayTagContainer;
2022-05-23 18:41:30 +00:00
ULyraGameplayAbility_Jump::ULyraGameplayAbility_Jump(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
InstancingPolicy = EGameplayAbilityInstancingPolicy::InstancedPerActor;
NetExecutionPolicy = EGameplayAbilityNetExecutionPolicy::LocalPredicted;
}
bool ULyraGameplayAbility_Jump::CanActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayTagContainer* SourceTags, const FGameplayTagContainer* TargetTags, FGameplayTagContainer* OptionalRelevantTags) const
{
if (!ActorInfo || !ActorInfo->AvatarActor.IsValid())
{
return false;
}
const ALyraCharacter* LyraCharacter = Cast<ALyraCharacter>(ActorInfo->AvatarActor.Get());
if (!LyraCharacter || !LyraCharacter->CanJump())
{
return false;
}
if (!Super::CanActivateAbility(Handle, ActorInfo, SourceTags, TargetTags, OptionalRelevantTags))
{
return false;
}
return true;
}
void ULyraGameplayAbility_Jump::EndAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, bool bReplicateEndAbility, bool bWasCancelled)
{
// Stop jumping in case the ability blueprint doesn't call it.
CharacterJumpStop();
Super::EndAbility(Handle, ActorInfo, ActivationInfo, bReplicateEndAbility, bWasCancelled);
}
void ULyraGameplayAbility_Jump::CharacterJumpStart()
{
if (ALyraCharacter* LyraCharacter = GetLyraCharacterFromActorInfo())
{
if (LyraCharacter->IsLocallyControlled() && !LyraCharacter->bPressedJump)
{
LyraCharacter->UnCrouch();
LyraCharacter->Jump();
}
}
}
void ULyraGameplayAbility_Jump::CharacterJumpStop()
{
if (ALyraCharacter* LyraCharacter = GetLyraCharacterFromActorInfo())
{
if (LyraCharacter->IsLocallyControlled() && LyraCharacter->bPressedJump)
{
LyraCharacter->StopJumping();
}
}
}