processXP

Function Purpose: Returns the current level of a player based on their XP and automatically awards level-up rewards if the player has advanced.

Input Parameters:

  • playerID (int): Unique identifier of the player.

  • xp (int): Current experience points of the player.

Process Flow:

  1. Fetch Player Level:

    • Query the Level table to determine the highest level the player qualifies for based on XP.

    SELECT levelId 
    FROM Level 
    WHERE xp <= @playerXP 
    ORDER BY levelId DESC 
    LIMIT 1;
    • Returns the player’s current level (currentLevel).

  2. Check for Level-Up:

    • Compare currentLevel with the player’s previous level (previousLevel).

    • If currentLevel > previousLevel, trigger the level-up process.

  3. Award Level Rewards:

    • Fetch rewards associated with the previous level:

    SELECT rewardID 
    FROM Rewards 
    WHERE level = @previousLevel;
    • For each rewardID, call the reward function:

    AwardLevelReward(playerID, rewardID);
  4. Return Value:

    • Returns the player’s currentLevel (int).

Example Usage:

Last updated