Player Progressions

Player progressions are progressions that the player is currently on, your game may have many progressions but the player doesn't necessarily progress through all of them at a given time, some may need to be unlocked or may be mutually exclusive.

Starting a progression for a player is as easy as just starting to add points to it or using our RegisterPlayerProgression (Unity only) method. That progression will then be listed when retrieving progressions for that player.

Registering Player Progressions

string progressionKey = "global_exp";

LootLockerSDKManager.RegisterPlayerProgression(progressionKey, (response) =>
{
    if(!response.success)
    {
        Debug.Log("Error Regisering progression!");
        Debug.Log(response.errorData.ToString());
        return;
    }
    
    Debug.Log("Progression Registered successfully!");
});

Retrieving player progressions

Retrieving a single player progression using the progression key

string progressionKey = "mage";

LootLockerSDKManager.GetPlayerProgression(progressionKey, response =>
{
    if (!response.success) {
        Debug.Log("Failed: " + response.Error);
    }
    
    // Output the player level and show how much points are needed to progress to the next tier
    Debug.Log($"The player is currently level {response.step}");
    if (response.next_threshold != null)
    {
        Debug.Log($"Points needed to reach next level: {response.next_threshold - response.points}");
    }
});

Retrieving all player progressions

LootLockerSDKManager.GetPlayerProgressions(response =>
{
    if (!response.success) {
        Debug.Log("Failed: " + response.Error);
    }

    // Output the player level and show how much points are needed to progress to the next tier for all player progressions
    foreach (var playerProgression in response.items)
    {
        Debug.Log($"Current level in {playerProgression.progression_name} is {playerProgression.step}");
        if (playerProgression.next_threshold != null)
        {
            Debug.Log($"Points needed to reach next level in {playerProgression.progression_name}: {playerProgression.next_threshold - playerProgression.points}");
        }
    }
});

Retrieving player progressions using count

Count can be used to limit the number of entries returned.

int count = 20;

LootLockerSDKManager.GetPlayerProgressions(count, response =>
{
    if (!response.success) {
        Debug.Log("Failed: " + response.Error);
    }

    // Output the player level and show how much points are needed to progress to the next tier for all player progressions
    foreach (var playerProgression in response.items)
    {
        Debug.Log($"Current level in {playerProgression.progression_name} is {playerProgression.step}");
        if (playerProgression.next_threshold != null)
        {
            Debug.Log($"Points needed to reach next level in {playerProgression.progression_name}: {playerProgression.next_threshold - playerProgression.points}");
        }
    }
});

Paginating through player progressions

You can use "after" parameter to paginate if the player is on many progressions.

int numberOfItemsPerPage = 10;
LootLockerPaginatedPlayerProgressionsResponse playerProgressions;

void Start()
{
    LootLockerSDKManager.StartGuestSession(_ =>
    {
        // Fetch the initial player progressions list
        LootLockerSDKManager.GetPlayerProgressions(numberOfItemsPerPage, response =>
        {
            if (!response.success)
            {
                Debug.Log("Failed: " + response.Error);
            }

            if (response.pagination.total == 0)
            {
                Debug.Log("Your player does not have any progressions, start them by giving some exp to the player");
            }

            playerProgressions = response;
        });
    });
}

void Update()
{
    if (playerProgressions == null) return;

    // Fetch the next page if more player progressions exist
    if (Input.GetKeyDown(KeyCode.RightArrow) && playerProgressions.pagination.next_cursor != null)
    {
        LootLockerSDKManager.GetPlayerProgressions(numberOfItemsPerPage, playerProgressions.pagination.next_cursor, response =>
        {
            if (!response.success)
            {
                Debug.Log("Failed: " + response.Error);
            }
            
            playerProgressions = response;
            Debug.Log($"Paginating right, got {playerProgressions.items.Count} player progressions");
        });
    }
    
    // Fetch the previous page if we are not on the first page
    if (Input.GetKeyDown(KeyCode.LeftArrow) && playerProgressions.pagination.previous_cursor != null)
    {
        LootLockerSDKManager.GetPlayerProgressions(numberOfItemsPerPage, playerProgressions.pagination.previous_cursor, response =>
        {
            if (!response.success)
            {
                Debug.Log("Failed: " + response.Error);
            }

            playerProgressions = response;
            Debug.Log($"Paginating left, got {playerProgressions.items.Count} player progressions");
        });
    }
}

Interacting with player progressions

Adding points to a player progression

If the player leveled up, awarded_tiers fields will contain acquired rewards.

string progressionKey = "mage";
ulong amountOfPoints = 100;

LootLockerSDKManager.AddPointsToPlayerProgression(progressionKey, amountOfPoints, response =>
{
    if (!response.success) {
        Debug.Log("Failed: " + response.Error);
    }

    // If the awarded_tiers array contains any items that means the player leveled up
    // There can also be multiple level-ups at once
    if (response.awarded_tiers.Any())
    {
        foreach (var awardedTier in response.awarded_tiers)
        {
            Debug.Log($"Reached level {awardedTier.step}!");

            foreach (var assetReward in awardedTier.rewards.asset_rewards)
            {
                Debug.Log($"Rewarded with an asset, id: {assetReward.asset_id}!");
            }
            
            foreach (var progressionPointsReward in awardedTier.rewards.progression_points_rewards)
            {
                Debug.Log($"Rewarded with {progressionPointsReward.amount} bonus points in {progressionPointsReward.progression_name} progression!");
            }
            
            foreach (var progressionResetReward in awardedTier.rewards.progression_reset_rewards)
            {
                Debug.Log($"Progression {progressionResetReward.progression_name} has been reset as a reward!");
            }
        }
    }
});

Subtracting points from a player progression

string progressionKey = "mage";
ulong amountOfPoints = 10;

LootLockerSDKManager.SubtractPointsFromPlayerProgression(progressionKey, amountOfPoints, response =>
{
    if (!response.success) {
        Debug.Log("Failed: " + response.Error);
    }
    
    // Output the amount of points the player has after subtracting points
    Debug.Log($"Player now has {response.points} points in {response.progression_name} progression");
});

Resetting a player progression

Resets the player progression points to 0, effectively returning the player to level 1, if you want to remove the progression from a player see below.

string progressionKey = "mage";

LootLockerSDKManager.ResetPlayerProgression(progressionKey, response =>
{
    if (!response.success) {
        Debug.Log("Failed: " + response.Error);
    }
    
    // Player level is now 1 
    Debug.Log($"Player is level {response.step} since the {response.progression_name} was reset");
});

Deleting a player progression

Completely removes a player progression, it will no longer be listed when retrieving player progressions.

string progressionKey = "mage";

LootLockerSDKManager.DeletePlayerProgression(progressionKey, response =>
{
    if (!response.success) {
        Debug.Log("Failed: " + response.Error);
    }
    
    // Trying to fetch the deleted player progression will result in a "Not Found" error
    LootLockerSDKManager.GetPlayerProgression(progressionKey, response =>
    {
        if (!response.success) {
            Debug.Log("Failed: " + response.Error);
        }
    }
});

Last updated