File size: 2,020 Bytes
7fd553e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | // Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameplayAbilitySpec.h"
#include "Abilities/GameplayAbility.h"
#include "LyraAbilityCost.generated.h"
class ULyraGameplayAbility;
/**
* ULyraAbilityCost
*
* Base class for costs that a LyraGameplayAbility has (e.g., ammo or charges)
*/
UCLASS(MinimalAPI, DefaultToInstanced, EditInlineNew, Abstract)
class ULyraAbilityCost : public UObject
{
GENERATED_BODY()
public:
ULyraAbilityCost()
{
}
/**
* Checks if we can afford this cost.
*
* A failure reason tag can be added to OptionalRelevantTags (if non-null), which can be queried
* elsewhere to determine how to provide user feedback (e.g., a clicking noise if a weapon is out of ammo)
*
* Ability and ActorInfo are guaranteed to be non-null on entry, but OptionalRelevantTags can be nullptr.
*
* @return true if we can pay for the ability, false otherwise.
*/
virtual bool CheckCost(const ULyraGameplayAbility* Ability, const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, FGameplayTagContainer* OptionalRelevantTags) const
{
return true;
}
/**
* Applies the ability's cost to the target
*
* Notes:
* - Your implementation don't need to check ShouldOnlyApplyCostOnHit(), the caller does that for you.
* - Ability and ActorInfo are guaranteed to be non-null on entry.
*/
virtual void ApplyCost(const ULyraGameplayAbility* Ability, const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo)
{
}
/** If true, this cost should only be applied if this ability hits successfully */
bool ShouldOnlyApplyCostOnHit() const { return bOnlyApplyCostOnHit; }
protected:
/** If true, this cost should only be applied if this ability hits successfully */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Costs)
bool bOnlyApplyCostOnHit = false;
};
|