2025-06-07 22:50:13 -04:00
|
|
|
---@diagnostic disable: duplicate-set-field
|
2025-04-28 09:17:43 -04:00
|
|
|
Skills = Skills or {}
|
|
|
|
|
|
2025-12-23 19:27:27 -05:00
|
|
|
local cachedXp = {}
|
2025-08-20 19:38:47 -04:00
|
|
|
|
2025-12-23 19:27:27 -05:00
|
|
|
function Skills.GetResourceName()
|
|
|
|
|
return "default"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---Calculate XP required for a level using RuneScape algorithm (with caching)
|
|
|
|
|
---@param level number
|
|
|
|
|
---@return number
|
|
|
|
|
function Skills.GetXPForLevel(level)
|
2025-08-20 19:38:47 -04:00
|
|
|
if not level or level < 1 then return 0 end
|
|
|
|
|
if level == 1 then return 0 end -- Level 1 requires 0 XP
|
|
|
|
|
|
2025-12-23 19:27:27 -05:00
|
|
|
if cachedXp[level] then return cachedXp[level] end
|
2025-08-20 19:38:47 -04:00
|
|
|
|
|
|
|
|
local xp = 0
|
|
|
|
|
for n = 1, level - 1 do
|
|
|
|
|
xp = xp + math.floor(n + 300 * (2 ^ (n / 7)))
|
|
|
|
|
end
|
|
|
|
|
local result = math.floor(xp / 4)
|
2025-12-23 19:27:27 -05:00
|
|
|
cachedXp[level] = result
|
2025-08-20 19:38:47 -04:00
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
end
|
|
|
|
|
|
2025-12-23 19:27:27 -05:00
|
|
|
---Create a skill (for initialization)
|
|
|
|
|
---@param name string
|
|
|
|
|
---@param maxLevel number
|
|
|
|
|
---@param baseXP number
|
|
|
|
|
---@return table
|
|
|
|
|
function Skills.Create(name, maxLevel, baseXP)
|
2025-08-20 19:38:47 -04:00
|
|
|
if not name then return end
|
|
|
|
|
Skills.All[name] = { name = name, maxLevel = maxLevel or 99, baseXP = baseXP or 50 }
|
|
|
|
|
return Skills.All[name]
|
|
|
|
|
end
|
|
|
|
|
|
2025-12-23 19:27:27 -05:00
|
|
|
---Get scaled XP based on player level
|
|
|
|
|
---@param baseXP number
|
|
|
|
|
---@param playerLevel number
|
|
|
|
|
---@return number
|
|
|
|
|
function Skills.GetScaledXP(baseXP, playerLevel)
|
2025-08-20 19:38:47 -04:00
|
|
|
return math.floor(baseXP * (1 + playerLevel * 0.05))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Get XP required to complete the current level
|
2025-12-23 19:27:27 -05:00
|
|
|
---@param level number
|
|
|
|
|
---@return number
|
|
|
|
|
function Skills.GetXPRequiredForLevel(level)
|
2025-08-20 19:38:47 -04:00
|
|
|
if not level or level < 1 then return 0 end
|
|
|
|
|
if level == 1 then return 83 end -- Level 1 to 2 requires 83 XP
|
|
|
|
|
return Skills.GetXPForLevel(level)
|
|
|
|
|
end
|
|
|
|
|
|
2025-06-19 15:25:35 -04:00
|
|
|
---This will get the skill level of the passed skill name. (returns 1 if not found)
|
2025-06-07 22:50:13 -04:00
|
|
|
---@param skillName string
|
|
|
|
|
---@return number
|
2025-12-23 19:27:27 -05:00
|
|
|
function Skills.GetSkillLevel(skillName)
|
2025-06-19 15:25:35 -04:00
|
|
|
if not skillName then return 0 end
|
2025-10-26 16:20:27 -04:00
|
|
|
local plyrSkills = Bridge.Framework.GetPlayerMetaData("community_bridge_skills")
|
2025-06-19 15:25:35 -04:00
|
|
|
if not plyrSkills or not plyrSkills[skillName] then return 1 end
|
|
|
|
|
return plyrSkills[skillName].level or 1
|
2025-05-10 00:01:56 -04:00
|
|
|
end
|
|
|
|
|
|
2025-08-20 19:38:47 -04:00
|
|
|
---This will get the skill xp of the passed skill name. (returns 1 if not found)
|
|
|
|
|
---@param skillName string
|
|
|
|
|
---@return number
|
2025-12-23 19:27:27 -05:00
|
|
|
function Skills.GetXP(skillName)
|
2025-08-20 19:38:47 -04:00
|
|
|
if not skillName then return 0 end
|
2025-10-26 16:20:27 -04:00
|
|
|
local plyrSkills = Bridge.Framework.GetPlayerMetaData("community_bridge_skills")
|
2025-08-20 19:38:47 -04:00
|
|
|
if not plyrSkills or not plyrSkills[skillName] then return 1 end
|
|
|
|
|
return plyrSkills[skillName].currentXP or 1
|
|
|
|
|
end
|
|
|
|
|
|
2025-05-10 00:01:56 -04:00
|
|
|
return Skills
|