From ed1e696eb5db61ed6d666d7f29b1b59a8283a8b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Correia?= Date: Sat, 9 May 2026 02:11:24 +0100 Subject: [PATCH] Pet modifier --- AltSystem.toc | 2 +- Core.lua | 5 +++++ Roll.lua | 41 +++++++++++++++++++++++++++++++++++++---- UI.lua | 25 ++++++++++++++++++++++++- 4 files changed, 67 insertions(+), 6 deletions(-) diff --git a/AltSystem.toc b/AltSystem.toc index b304469..0b03820 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.6 +## Version: 1.0 ## Dependencies: totalRP3, totalRP3_Extended ## SavedVariables: AltSystemDB diff --git a/Core.lua b/Core.lua index c5bb3a8..68c41ac 100644 --- a/Core.lua +++ b/Core.lua @@ -7,6 +7,7 @@ AltSystem.State = { selectedItemIndex = 1, -- 1 = No item selectedDefenseIndex = 1, -- 1 = Base armor shieldEnabled = false, + petSummonEnabled = false, announceEnabled = false, announceChannelIndex = 1, -- 1 = Emote, 2 = Party, 3 = Raid, 4 = Guild } @@ -39,6 +40,9 @@ function AltSystem:Init() if AltSystemDB.announceChannelIndex then AltSystem.State.announceChannelIndex = AltSystemDB.announceChannelIndex end + if AltSystemDB.petSummonEnabled ~= nil then + AltSystem.State.petSummonEnabled = AltSystemDB.petSummonEnabled + end -- Register slash command /altsystem SLASH_ALTSYSTEM1 = "/altsystem" @@ -53,6 +57,7 @@ function AltSystem:Init() AltSystemDB = AltSystemDB or {} AltSystemDB.announceEnabled = AltSystem.State.announceEnabled AltSystemDB.announceChannelIndex = AltSystem.State.announceChannelIndex + AltSystemDB.petSummonEnabled = AltSystem.State.petSummonEnabled end) print("|cff00ccffAltSystem|r loaded. Type /altsystem to open.") diff --git a/Roll.lua b/Roll.lua index 71b4438..1e98b0c 100644 --- a/Roll.lua +++ b/Roll.lua @@ -4,6 +4,7 @@ AltSystem = AltSystem or {} local pendingRollType = nil -- "attack" or "defense" +local pendingPetRoll = nil -- { rollType, mainRollValue } when awaiting pet/summon roll -- Get the TRP3 character first name, falling back to the WoW unit name local function GetCharacterName() @@ -65,6 +66,7 @@ end -- Perform a roll: triggers the WoW native /roll 20 command function AltSystem:PerformRoll(rollType) + pendingPetRoll = nil pendingRollType = rollType RandomRoll(1, 20) end @@ -74,6 +76,20 @@ local rollListener = CreateFrame("Frame") rollListener:RegisterEvent("CHAT_MSG_SYSTEM") rollListener:SetScript("OnEvent", function(self, event, message) + -- Phase 2: waiting for pet/summon roll result (1-5) + if pendingPetRoll then + local petRoll = message:match("rolls (%d+) %(1%-5%)") + if not petRoll then return end + + local petValue = tonumber(petRoll) + local info = pendingPetRoll + pendingPetRoll = nil + + AltSystem:CalculateAndDisplayResult(info.rollType, info.mainRollValue, petValue) + return + end + + -- Phase 1: waiting for main roll result (1-20) if not pendingRollType then return end -- Match the roll result pattern: "PlayerName rolls X (1-20)" @@ -84,11 +100,18 @@ rollListener:SetScript("OnEvent", function(self, event, message) local rollType = pendingRollType pendingRollType = nil + -- If pet/summon is enabled, trigger a second roll (1-5) + if AltSystem.State.petSummonEnabled then + pendingPetRoll = { rollType = rollType, mainRollValue = rollValue } + RandomRoll(1, 5) + return + end + AltSystem:CalculateAndDisplayResult(rollType, rollValue) end) -- Calculate the final result based on the roll type and selected modifiers -function AltSystem:CalculateAndDisplayResult(rollType, rollValue) +function AltSystem:CalculateAndDisplayResult(rollType, rollValue, petRollValue) -- Critical rolls bypass normal calculation if rollValue == 1 then if AltSystem.ResultText then @@ -134,9 +157,11 @@ function AltSystem:CalculateAndDisplayResult(rollType, rollValue) local isBaseRoll = skill and skill.name == "Base roll" + local petMod = petRollValue or 0 + if rollType == "attack" then - -- Attack Roll = roll + skill modifier + item modifier - total = rollValue + skillMod + itemMod + -- Attack Roll = roll + skill modifier + item modifier + pet/summon modifier + total = rollValue + skillMod + itemMod + petMod if not isBaseRoll then breakdown = breakdown .. "\nSkill: " .. FormatModifier(skillMod) @@ -146,6 +171,10 @@ function AltSystem:CalculateAndDisplayResult(rollType, rollValue) breakdown = breakdown .. " | Item: " .. FormatModifier(itemMod) table.insert(modifiers, { name = item and item.name or "Item", value = itemMod }) end + if petMod ~= 0 then + breakdown = breakdown .. " | Pet: +" .. petMod + table.insert(modifiers, { name = "Pet", value = petMod }) + end breakdown = breakdown .. "\n|cffffd100Attack Total: " .. total .. "|r" elseif rollType == "defense" then @@ -154,7 +183,7 @@ function AltSystem:CalculateAndDisplayResult(rollType, rollValue) local defenseMod = defense and defense.modifier or 0 local shieldMod = state.shieldEnabled and AltSystem.Data.ShieldModifier or 0 - total = rollValue + skillMod + itemMod + defenseMod + shieldMod + total = rollValue + skillMod + itemMod + defenseMod + shieldMod + petMod if not isBaseRoll then breakdown = breakdown .. "\nSkill: " .. FormatModifier(skillMod) @@ -170,6 +199,10 @@ function AltSystem:CalculateAndDisplayResult(rollType, rollValue) breakdown = breakdown .. " | Shield: " .. FormatModifier(shieldMod) table.insert(modifiers, { name = "Shield", value = shieldMod }) end + if petMod ~= 0 then + breakdown = breakdown .. " | Pet: +" .. petMod + table.insert(modifiers, { name = "Pet", value = petMod }) + end breakdown = breakdown .. "\n|cff00ccffDefense Total: " .. total .. "|r" end diff --git a/UI.lua b/UI.lua index 81b3bd3..c425d9d 100644 --- a/UI.lua +++ b/UI.lua @@ -5,7 +5,7 @@ AltSystem = AltSystem or {} local WINDOW_WIDTH = 300 -local WINDOW_HEIGHT = 440 +local WINDOW_HEIGHT = 478 local PADDING = 12 local ROW_HEIGHT = 30 local LABEL_WIDTH = 80 @@ -191,6 +191,29 @@ function AltSystem:CreateMainFrame() yPos = yPos - ROW_HEIGHT - 8 + ------------------------- + -- Pet/Summon checkbox + ------------------------- + local petLabel = f:CreateFontString(nil, "OVERLAY", "GameFontNormal") + petLabel:SetPoint("TOPLEFT", f, "TOPLEFT", PADDING, yPos) + petLabel:SetText("Pet:") + petLabel:SetWidth(LABEL_WIDTH) + petLabel:SetJustifyH("LEFT") + + local petCheck = CreateFrame("CheckButton", "AltSystemPetSummonCheck", f, "UICheckButtonTemplate") + petCheck:SetPoint("LEFT", petLabel, "RIGHT", -6, 0) + petCheck:SetChecked(AltSystem.State.petSummonEnabled) + + local petText = petCheck:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall") + petText:SetPoint("LEFT", petCheck, "RIGHT", 2, 0) + petText:SetText("+d5 modifier") + + petCheck:SetScript("OnClick", function(self) + AltSystem.State.petSummonEnabled = self:GetChecked() + end) + + yPos = yPos - ROW_HEIGHT - 8 + ------------------------- -- Announce checkbox + channel dropdown -------------------------