diff --git a/AltSystem.toc b/AltSystem.toc index 3e5feca..b304469 100644 --- a/AltSystem.toc +++ b/AltSystem.toc @@ -2,7 +2,7 @@ ## Title: AltSystem ## Notes: Enhances RP gameplay with a custom rolling system ## Author: Rukira -## Version: 0.5 +## Version: 0.6 ## Dependencies: totalRP3, totalRP3_Extended ## SavedVariables: AltSystemDB diff --git a/Data.lua b/Data.lua index 6dc2a35..19d5ca9 100644 --- a/Data.lua +++ b/Data.lua @@ -6,6 +6,7 @@ AltSystem.Data = {} -- Skill levels and their modifiers AltSystem.Data.SkillLevels = { + ["Inept"] = -4, ["Novice"] = -2, ["Adept"] = 0, ["Expert"] = 2, @@ -15,13 +16,9 @@ AltSystem.Data.SkillLevels = { -- The "Base roll" entry is always the first (default) skill local BASE_ROLL_ENTRY = { name = "Base roll", level = "Base", modifier = 0 } --- The "Inept" entry is always the second skill -local UNSKILLED_ENTRY = { name = "Inept", level = "Inept", modifier = -4 } - -- Default/fallback skill list used when no TRP3 profile skills are found local DEFAULT_SKILLS = { { name = "Base roll", level = "Base", modifier = 0 }, - { name = "Inept", level = "Inept", modifier = -4 }, { name = "Novice Skill", level = "Novice", modifier = -2 }, { name = "Adept Skill", level = "Adept", modifier = 0 }, { name = "Expert Skill", level = "Expert", modifier = 2 }, @@ -29,25 +26,49 @@ local DEFAULT_SKILLS = { } -- Valid skill level keywords that must appear in the trait's right field (RT) -local VALID_SKILL_KEYWORDS = { "Novice", "Adept", "Expert", "Master" } +local VALID_SKILL_KEYWORDS = { "Inept", "Novice", "Adept", "Expert", "Master" } + +-- Expected numeric value ranges for each skill keyword +local SKILL_KEYWORD_RANGES = { + ["Novice"] = { min = 1, max = 5 }, + ["Adept"] = { min = 6, max = 10 }, + ["Expert"] = { min = 11, max = 19 }, + ["Master"] = { min = 20, max = 20 }, +} -- 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 +-- Returns the matched keyword if found, nil otherwise. +local function FindSkillKeyword(rightText) + if not rightText or rightText == "" then return nil end for _, keyword in ipairs(VALID_SKILL_KEYWORDS) do if rightText:find(keyword) then - return true + return keyword end end - return false + return nil end --- 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 +-- Check whether the numeric value matches the expected range for the given keyword. +-- Returns a warning string if mismatched, or nil if everything is fine. +local function CheckSkillMismatch(keyword, numericValue) + if not keyword or keyword == "Inept" then return nil end + local range = SKILL_KEYWORD_RANGES[keyword] + if not range then return nil end + if not numericValue or numericValue <= 0 then return nil end + if numericValue < range.min or numericValue > range.max then + return "Skill is marked as " .. keyword .. " (" .. range.min .. "-" .. range.max .. "), but the profile has a value of " .. numericValue .. "." + end + return nil +end +-- Determine the skill level from the trait's right text and numeric value (V2 field, 0-20 range). +-- If the trait is marked as Inept, always returns "Inept" with -4 modifier regardless of numeric value. +-- Otherwise returns the level string and modifier based on numeric value, or nil if the value is 0 or absent. +local function ParseSkillLevel(rightText, numericValue) + if rightText and rightText:find("Inept") then + return "Inept", AltSystem.Data.SkillLevels["Inept"] + end + 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 @@ -60,14 +81,13 @@ local function ParseSkillLevel(numericValue) end -- Fetch skills from the current TRP3 profile's personality traits. --- Returns an array of skill entries, always starting with "Base roll" and "Inept". +-- Returns an array of skill entries, always starting with "Base roll". +-- Traits marked as Inept get a -4 modifier regardless of their numeric value. -- Falls back to the default list if no profile or no valid skills are found. function AltSystem.Data:RefreshSkills() local skills = {} - - -- Always add Base roll as the first entry, then Inept + -- Always add Base roll as the first entry table.insert(skills, { name = BASE_ROLL_ENTRY.name, level = BASE_ROLL_ENTRY.level, modifier = BASE_ROLL_ENTRY.modifier }) - table.insert(skills, { name = UNSKILLED_ENTRY.name, level = UNSKILLED_ENTRY.level, modifier = UNSKILLED_ENTRY.modifier }) local foundAny = false @@ -79,14 +99,16 @@ function AltSystem.Data:RefreshSkills() local skillName = trait.LT local numericValue = trait.V2 - if skillName and skillName ~= "" and HasSkillKeyword(trait.RT) then - local level, modifier = ParseSkillLevel(numericValue) + local keyword = FindSkillKeyword(trait.RT) + if skillName and skillName ~= "" and keyword then + local level, modifier = ParseSkillLevel(trait.RT, numericValue) if level and modifier then foundAny = true table.insert(skills, { name = skillName, level = level, modifier = modifier, + warning = CheckSkillMismatch(keyword, numericValue), }) end end diff --git a/UI.lua b/UI.lua index 8b7e8d8..81b3bd3 100644 --- a/UI.lua +++ b/UI.lua @@ -83,18 +83,53 @@ function AltSystem:CreateMainFrame() -- Skill dropdown ------------------------- local skillOptions = BuildSkillOptions() + local UpdateSkillWarning -- forward declaration local skillDropdown, getSkillIndex, setSkillIndex = CreateDropdown( f, "AltSystemSkillDropdown", yPos, "Skill:", skillOptions, AltSystem.State.selectedSkillIndex, function(index) AltSystem.State.selectedSkillIndex = index + UpdateSkillWarning(index) end) + -- Warning icon for skill mismatch (shown next to dropdown when value doesn't match keyword) + local skillWarning = CreateFrame("Frame", nil, f) + skillWarning:SetSize(20, 20) + skillWarning:SetPoint("LEFT", skillDropdown, "RIGHT", 4, 0) + + local skillWarningIcon = skillWarning:CreateTexture(nil, "ARTWORK") + skillWarningIcon:SetAllPoints() + skillWarningIcon:SetAtlas("services-icon-warning") + + skillWarning:SetScript("OnEnter", function(self) + if self.tooltipText then + GameTooltip:SetOwner(self, "ANCHOR_RIGHT") + GameTooltip:SetText(self.tooltipText, 1, 0.82, 0) + GameTooltip:Show() + end + end) + skillWarning:SetScript("OnLeave", function() + GameTooltip:Hide() + end) + skillWarning:Hide() + + -- Update the warning icon visibility based on the currently selected skill + UpdateSkillWarning = function(index) + local skill = AltSystem.Data.Skills[index] + if skill and skill.warning then + skillWarning.tooltipText = skill.warning + skillWarning:Show() + else + skillWarning:Hide() + end + end + -- Store references for refreshing AltSystem.SkillDropdown = skillDropdown AltSystem.GetSkillIndex = getSkillIndex AltSystem.SetSkillIndex = setSkillIndex + AltSystem.UpdateSkillWarning = UpdateSkillWarning yPos = yPos - ROW_HEIGHT - 8 ------------------------- @@ -256,11 +291,14 @@ end function AltSystem:RefreshSkillDropdown() AltSystem.Data:RefreshSkills() - -- Reset selection to 1 (Inept) since the skill list may have changed + -- Reset selection to 1 (Base roll) since the skill list may have changed AltSystem.State.selectedSkillIndex = 1 if AltSystem.SetSkillIndex then AltSystem.SetSkillIndex(1) end + if AltSystem.UpdateSkillWarning then + AltSystem.UpdateSkillWarning(1) + end -- Rebuild the dropdown menu with the new skill list if AltSystem.SkillDropdown then @@ -275,6 +313,9 @@ function AltSystem:RefreshSkillDropdown() if AltSystem.SetSkillIndex then AltSystem.SetSkillIndex(data) end + if AltSystem.UpdateSkillWarning then + AltSystem.UpdateSkillWarning(data) + end end, i ) diff --git a/docs/2-skills.md b/docs/2-skills.md index f118ffe..cd4429d 100644 --- a/docs/2-skills.md +++ b/docs/2-skills.md @@ -3,13 +3,13 @@ - The skills are defined in the TRP profile as 'Personality traits' - For each trait: - the left field represents the skill name - - the right field must contain a valid skill keyword (Novice, Adept, Expert, Master) — traits without one of these keywords are omitted + - the right field must contain a valid skill keyword (Inept, Novice, Adept, Expert, Master) — traits without one of these keywords are omitted + - if the right field contains "Inept", the trait always gets a -4 modifier regardless of its numeric value - the first numeric value (V2) determines the skill level based on these ranges: - Novice: 1-5 - Adept: 6-10 - Expert: 11-19 - Master: 20 - should a skill have a value of 0 or no value, it should be omitted from the list -- The list should have a default selected value of "Inept" which corresponds to a -4 modifier - In case no skills are found in the profile, or no profile is selected, a default list should be displayed - - Inept, Novice Skill, Adept Skill, Expert Skill, Master Skill \ No newline at end of file + - Base roll, Novice Skill, Adept Skill, Expert Skill, Master Skill \ No newline at end of file