unitysamples / LyraStarterGame /Source /LyraGame /AbilitySystem /Abilities /LyraAbilityCost_InventoryItem.cpp
Download LyraStarterGame/Source/LyraGame/AbilitySystem/Abilities/LyraAbilityCost_InventoryItem.cpp from Alexhas2/unitysamples: direct link, hf CLI and curl.
- Browser
- Download file 1.97 kB
-
https://huggingface.co/datasets/Alexhas2/unitysamples/resolve/main/LyraStarterGame/Source/LyraGame/AbilitySystem/Abilities/LyraAbilityCost_InventoryItem.cpp
- Command line
-
hf download hf://datasets/Alexhas2/unitysamples/LyraStarterGame/Source/LyraGame/AbilitySystem/Abilities/LyraAbilityCost_InventoryItem.cpp
-
curl -L -o LyraAbilityCost_InventoryItem.cpp https://huggingface.co/datasets/Alexhas2/unitysamples/resolve/main/LyraStarterGame/Source/LyraGame/AbilitySystem/Abilities/LyraAbilityCost_InventoryItem.cpp
1.97 kB
| // Copyright Epic Games, Inc. All Rights Reserved. | |
| ULyraAbilityCost_InventoryItem::ULyraAbilityCost_InventoryItem() | |
| { | |
| Quantity.SetValue(1.0f); | |
| } | |
| bool ULyraAbilityCost_InventoryItem::CheckCost(const ULyraGameplayAbility* Ability, const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, FGameplayTagContainer* OptionalRelevantTags) const | |
| { | |
| if (AController* PC = Ability->GetControllerFromActorInfo()) | |
| { | |
| if (ULyraInventoryManagerComponent* InventoryComponent = PC->GetComponentByClass<ULyraInventoryManagerComponent>()) | |
| { | |
| const int32 AbilityLevel = Ability->GetAbilityLevel(Handle, ActorInfo); | |
| const float NumItemsToConsumeReal = Quantity.GetValueAtLevel(AbilityLevel); | |
| const int32 NumItemsToConsume = FMath::TruncToInt(NumItemsToConsumeReal); | |
| return InventoryComponent->GetTotalItemCountByDefinition(ItemDefinition) >= NumItemsToConsume; | |
| } | |
| } | |
| return false; | |
| } | |
| void ULyraAbilityCost_InventoryItem::ApplyCost(const ULyraGameplayAbility* Ability, const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo) | |
| { | |
| if (ActorInfo->IsNetAuthority()) | |
| { | |
| if (AController* PC = Ability->GetControllerFromActorInfo()) | |
| { | |
| if (ULyraInventoryManagerComponent* InventoryComponent = PC->GetComponentByClass<ULyraInventoryManagerComponent>()) | |
| { | |
| const int32 AbilityLevel = Ability->GetAbilityLevel(Handle, ActorInfo); | |
| const float NumItemsToConsumeReal = Quantity.GetValueAtLevel(AbilityLevel); | |
| const int32 NumItemsToConsume = FMath::TruncToInt(NumItemsToConsumeReal); | |
| InventoryComponent->ConsumeItemsByDefinition(ItemDefinition, NumItemsToConsume); | |
| } | |
| } | |
| } | |
| } | |