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:
Fetch Player Level:
Query the
Leveltable 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).
Check for Level-Up:
Compare
currentLevelwith the player’s previous level (previousLevel).If
currentLevel > previousLevel, trigger the level-up process.
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);Return Value:
Returns the player’s
currentLevel(int).
Example Usage:
Last updated