InventoryLevel
Last modified: 26 September 2024Defines the item level, optionally applying upgradeable trait, which enables the Upgrade operation.
Upgradeable items are tagged as Inventory.Item.Trait.Upgradeable
.
Minimum and Maximum Values
An item's level must be between zero and whatever value is specified in the fragment as Maximum Level.
All values set to the SetLevel
or Upgrade
functions, or via the Upgrade Operation will always ensure that the incoming value is clamped to those limits.
Tracking Levels
The fragment provides the following ways to track an item's level:
Via the
GetLevel
function, for occasional queries on the current level.Via the
OnLevelChanged
delegate, which broadcasts each time the value changes.
Level Attributes
The Attribute Set included with this inventory system provides two attributes related to the item level, the Equipment Level and the Average Equipment Level.
This fragment works in conjunction with those fragments. Whenever an item is added to an equipment slot, thus initializing an equipment, it will contribute to both attributes, increasing the total and average equipment level.
Gameplay Effects
Other objects in the system can use the item level as the effect level for a Gameplay Effect that must be applied. This is very useful if you want to the magnitudes in your Gameplay Effect to scale based on the item's power.
Upgrade Operation
During an upgrade, the level can be modified in two ways: absolute or incremental value.
Absolute: The value provided in the operation replaces the current level.
Incremental: The value provided is added to the current level.
tip
Incremental updates can be useful when the current level is unknown, but it must be updated by a given amount.
void UInventoryExamples::Upgrade(UNinjaInventoryItem* Item, int32 Value, bIncrement)
{
const TInstancedStruct<FInventoryFragmentPayload>& Payload = UNinjaInventoryGameplayFunctionLibrary::CreateUpgradePayload(Item, Value, bIncrement);
InventoryManager->TryPerformOperation(Payload);
}
If your design requires a direct approach to upgrade an item, you can use the function exposed by the fragment. Please note that it becomes your responsibility to manage network authority.
void UWeaponManager::ImproveWeapon(UNinjaInventoryItem* Item, int32 Value, bIncrement)
{
UItemFragment_Level* LevelFragment = Item->FindFragment<UItemFragment_Level>();
if (bIncrement)
{
LevelFragment->Upgrade(Item, Value);
}
else
{
LevelFragment->SetLevel(Item, Value);
}
}
tip
For the upgrade operation you can always decide if you want to provide an absolute level or increment the level by a certain amount.