Better skill detection
This commit is contained in:
parent
9e629aec31
commit
3e4ac9888a
2 changed files with 35 additions and 20 deletions
45
Data.lua
45
Data.lua
|
|
@ -24,24 +24,35 @@ local DEFAULT_SKILLS = {
|
|||
{ name = "Master Skill", level = "Master", modifier = 4 },
|
||||
}
|
||||
|
||||
-- Parse the skill level from the right-side text of a TRP3 personality trait.
|
||||
-- The level keyword must appear at the start of the string; anything after it is ignored.
|
||||
-- Returns the level string and modifier, or nil if not recognized.
|
||||
local function ParseSkillLevel(rightText)
|
||||
if not rightText or rightText == "" then return nil, nil end
|
||||
-- Valid skill level keywords that must appear in the trait's right field (RT)
|
||||
local VALID_SKILL_KEYWORDS = { "Novice", "Adept", "Expert", "Master" }
|
||||
|
||||
-- Trim leading/trailing whitespace
|
||||
local trimmed = rightText:match("^%s*(.-)%s*$")
|
||||
if not trimmed or trimmed == "" then return nil, nil end
|
||||
|
||||
-- Check if the text starts with a recognized level keyword
|
||||
for _, levelName in ipairs({"Master", "Expert", "Adept", "Novice"}) do
|
||||
if trimmed == levelName or trimmed:match("^" .. levelName .. "[%s%p]") then
|
||||
return levelName, AltSystem.Data.SkillLevels[levelName]
|
||||
-- Check if the trait's right text field contains a valid skill keyword.
|
||||
-- Returns true if any keyword is found, false otherwise.
|
||||
local function HasSkillKeyword(rightText)
|
||||
if not rightText or rightText == "" then return false end
|
||||
for _, keyword in ipairs(VALID_SKILL_KEYWORDS) do
|
||||
if rightText:find(keyword) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
return nil, nil
|
||||
-- Determine the skill level from the trait's numeric value (V2 field, 0-20 range).
|
||||
-- Returns the level string and modifier, or nil if the value is 0 or absent.
|
||||
local function ParseSkillLevel(numericValue)
|
||||
if not numericValue or numericValue <= 0 then return nil, nil end
|
||||
|
||||
if numericValue >= 20 then
|
||||
return "Master", AltSystem.Data.SkillLevels["Master"]
|
||||
elseif numericValue >= 11 then
|
||||
return "Expert", AltSystem.Data.SkillLevels["Expert"]
|
||||
elseif numericValue >= 6 then
|
||||
return "Adept", AltSystem.Data.SkillLevels["Adept"]
|
||||
else
|
||||
return "Novice", AltSystem.Data.SkillLevels["Novice"]
|
||||
end
|
||||
end
|
||||
|
||||
-- Fetch skills from the current TRP3 profile's personality traits.
|
||||
|
|
@ -61,10 +72,10 @@ function AltSystem.Data:RefreshSkills()
|
|||
if ok and characteristics and characteristics.PS then
|
||||
for _, trait in ipairs(characteristics.PS) do
|
||||
local skillName = trait.LT
|
||||
local rightText = trait.RT
|
||||
local numericValue = trait.V2
|
||||
|
||||
if skillName and skillName ~= "" then
|
||||
local level, modifier = ParseSkillLevel(rightText)
|
||||
if skillName and skillName ~= "" and HasSkillKeyword(trait.RT) then
|
||||
local level, modifier = ParseSkillLevel(numericValue)
|
||||
if level and modifier then
|
||||
foundAny = true
|
||||
table.insert(skills, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue