text: // Fill out your copyright notice in the Description page of Project Settings.
  
  
  #include "Abilities/GASGA_CharacterJump.h"
  
  #include "GameFramework/Character.h"
  
  void UGASGA_CharacterJump::ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData)
  {
  	if (HasAuthorityOrPredictionKey(ActorInfo, &ActivationInfo))
  	{
  		if (!CommitAbility(Handle, ActorInfo, ActivationInfo))
  		{
  			CancelAbility(Handle, ActorInfo, ActivationInfo, true);
  		}
  
  		if (ACharacter* Character = CastChecked<ACharacter>(ActorInfo->AvatarActor.Get()))
  			Character->Jump();
  	}
  }
  
  bool UGASGA_CharacterJump::CanActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayTagContainer* SourceTags, const FGameplayTagContainer* TargetTags, FGameplayTagContainer* OptionalRelevantTags) const
  {
  	if (!Super::CanActivateAbility(Handle, ActorInfo, SourceTags, TargetTags, OptionalRelevantTags))
  	{
  		return false;
  	}
  
  	const ACharacter* Character = CastChecked<ACharacter>(ActorInfo->AvatarActor.Get(), ECastCheckedType::NullAllowed);
  	return Character && Character->CanJump();
  }
  
  void UGASGA_CharacterJump::InputReleased(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo)
  {
  	if (ActorInfo != NULL && ActorInfo->AvatarActor != NULL)
  	{
  		CancelAbility(Handle, ActorInfo, ActivationInfo, true);
  	}
  }
  
  void UGASGA_CharacterJump::CancelAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, bool bReplicateCancelAbility)
  {
  	if (ScopeLockCount > 0)
  	{
  		WaitingToExecute.Add(FPostLockDelegate::CreateUObject(this, &UGASGA_CharacterJump::CancelAbility, Handle, ActorInfo, ActivationInfo, bReplicateCancelAbility));
  		return;
  	}
  
  	Super::CancelAbility(Handle, ActorInfo, ActivationInfo, bReplicateCancelAbility);
  
  	if (ACharacter* Character = CastChecked<ACharacter>(ActorInfo->AvatarActor.Get()))
  		Character->StopJumping();
  }
  