Files
community_bridge/modules/skills/_default/client.lua
T
MrNewb 444040dd39 This was crowleys commit and work - Refactor entity behaviors and improve particle handling
Refactored entity behavior triggers to simplify argument passing and added OnSet handler for particle behaviors. Improved particle effect management and event handling, updated locale and lib initialization in several modules, and fixed skill metadata access. Also streamlined point zone logic and menu/zone system initialization for better reliability.
2025-10-26 16:20:27 -04:00

74 lines
2.3 KiB
Lua

---@diagnostic disable: duplicate-set-field
Skills = Skills or {}
XP_CACHE = {}
-- Calculate XP required for a level using RuneScape algorithm (with caching)
Skills.GetXPForLevel = function(level)
if not level or level < 1 then return 0 end
if level == 1 then return 0 end -- Level 1 requires 0 XP
-- Check cache first
if XP_CACHE[level] then
return XP_CACHE[level]
end
-- Calculate and cache
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)
XP_CACHE[level] = result
return result
end
-- Create a skill (for initialization)
Skills.Create = function(name, maxLevel, baseXP)
if not name then return end
Skills.All[name] = { name = name, maxLevel = maxLevel or 99, baseXP = baseXP or 50 }
return Skills.All[name]
end
Skills.GetScaledXP = function(baseXP, playerLevel)
return math.floor(baseXP * (1 + playerLevel * 0.05))
end
-- Get XP required to complete the current level
Skills.GetXPRequiredForLevel = function(level)
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
---This will get the skill level of the passed skill name. (returns 1 if not found)
---@param skillName string
---@return number
Skills.GetSkillLevel = function(skillName)
if not skillName then return 0 end
local plyrSkills = Bridge.Framework.GetPlayerMetaData("community_bridge_skills")
if not plyrSkills or not plyrSkills[skillName] then return 1 end
return plyrSkills[skillName].level or 1
end
---This will get the skill xp of the passed skill name. (returns 1 if not found)
---@param skillName string
---@return number
Skills.GetXP = function(skillName)
if not skillName then return 0 end
local plyrSkills = Bridge.Framework.GetPlayerMetaData("community_bridge_skills")
if not plyrSkills or not plyrSkills[skillName] then return 1 end
return plyrSkills[skillName].currentXP or 1
end
Skills.GetResourceName = function()
return "default"
end
-- RegisterCommand("getfishingLevel", function(source, args)
-- local level = Skills.GetSkillLevel("fishing")
-- print("Client Fishing Level issssssssss " .. level)
-- end, false)
return Skills