Pet modifier

This commit is contained in:
Gonçalo Correia 2026-05-09 02:11:24 +01:00
parent 0d9ec1913d
commit ed1e696eb5
4 changed files with 67 additions and 6 deletions

View file

@ -2,7 +2,7 @@
## Title: AltSystem ## Title: AltSystem
## Notes: Enhances RP gameplay with a custom rolling system ## Notes: Enhances RP gameplay with a custom rolling system
## Author: Rukira ## Author: Rukira
## Version: 0.6 ## Version: 1.0
## Dependencies: totalRP3, totalRP3_Extended ## Dependencies: totalRP3, totalRP3_Extended
## SavedVariables: AltSystemDB ## SavedVariables: AltSystemDB

View file

@ -7,6 +7,7 @@ AltSystem.State = {
selectedItemIndex = 1, -- 1 = No item selectedItemIndex = 1, -- 1 = No item
selectedDefenseIndex = 1, -- 1 = Base armor selectedDefenseIndex = 1, -- 1 = Base armor
shieldEnabled = false, shieldEnabled = false,
petSummonEnabled = false,
announceEnabled = false, announceEnabled = false,
announceChannelIndex = 1, -- 1 = Emote, 2 = Party, 3 = Raid, 4 = Guild announceChannelIndex = 1, -- 1 = Emote, 2 = Party, 3 = Raid, 4 = Guild
} }
@ -39,6 +40,9 @@ function AltSystem:Init()
if AltSystemDB.announceChannelIndex then if AltSystemDB.announceChannelIndex then
AltSystem.State.announceChannelIndex = AltSystemDB.announceChannelIndex AltSystem.State.announceChannelIndex = AltSystemDB.announceChannelIndex
end end
if AltSystemDB.petSummonEnabled ~= nil then
AltSystem.State.petSummonEnabled = AltSystemDB.petSummonEnabled
end
-- Register slash command /altsystem -- Register slash command /altsystem
SLASH_ALTSYSTEM1 = "/altsystem" SLASH_ALTSYSTEM1 = "/altsystem"
@ -53,6 +57,7 @@ function AltSystem:Init()
AltSystemDB = AltSystemDB or {} AltSystemDB = AltSystemDB or {}
AltSystemDB.announceEnabled = AltSystem.State.announceEnabled AltSystemDB.announceEnabled = AltSystem.State.announceEnabled
AltSystemDB.announceChannelIndex = AltSystem.State.announceChannelIndex AltSystemDB.announceChannelIndex = AltSystem.State.announceChannelIndex
AltSystemDB.petSummonEnabled = AltSystem.State.petSummonEnabled
end) end)
print("|cff00ccffAltSystem|r loaded. Type /altsystem to open.") print("|cff00ccffAltSystem|r loaded. Type /altsystem to open.")

View file

@ -4,6 +4,7 @@
AltSystem = AltSystem or {} AltSystem = AltSystem or {}
local pendingRollType = nil -- "attack" or "defense" 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 -- Get the TRP3 character first name, falling back to the WoW unit name
local function GetCharacterName() local function GetCharacterName()
@ -65,6 +66,7 @@ end
-- Perform a roll: triggers the WoW native /roll 20 command -- Perform a roll: triggers the WoW native /roll 20 command
function AltSystem:PerformRoll(rollType) function AltSystem:PerformRoll(rollType)
pendingPetRoll = nil
pendingRollType = rollType pendingRollType = rollType
RandomRoll(1, 20) RandomRoll(1, 20)
end end
@ -74,6 +76,20 @@ local rollListener = CreateFrame("Frame")
rollListener:RegisterEvent("CHAT_MSG_SYSTEM") rollListener:RegisterEvent("CHAT_MSG_SYSTEM")
rollListener:SetScript("OnEvent", function(self, event, message) 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 if not pendingRollType then return end
-- Match the roll result pattern: "PlayerName rolls X (1-20)" -- Match the roll result pattern: "PlayerName rolls X (1-20)"
@ -84,11 +100,18 @@ rollListener:SetScript("OnEvent", function(self, event, message)
local rollType = pendingRollType local rollType = pendingRollType
pendingRollType = nil 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) AltSystem:CalculateAndDisplayResult(rollType, rollValue)
end) end)
-- Calculate the final result based on the roll type and selected modifiers -- 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 -- Critical rolls bypass normal calculation
if rollValue == 1 then if rollValue == 1 then
if AltSystem.ResultText then if AltSystem.ResultText then
@ -134,9 +157,11 @@ function AltSystem:CalculateAndDisplayResult(rollType, rollValue)
local isBaseRoll = skill and skill.name == "Base roll" local isBaseRoll = skill and skill.name == "Base roll"
local petMod = petRollValue or 0
if rollType == "attack" then if rollType == "attack" then
-- Attack Roll = roll + skill modifier + item modifier -- Attack Roll = roll + skill modifier + item modifier + pet/summon modifier
total = rollValue + skillMod + itemMod total = rollValue + skillMod + itemMod + petMod
if not isBaseRoll then if not isBaseRoll then
breakdown = breakdown .. "\nSkill: " .. FormatModifier(skillMod) breakdown = breakdown .. "\nSkill: " .. FormatModifier(skillMod)
@ -146,6 +171,10 @@ function AltSystem:CalculateAndDisplayResult(rollType, rollValue)
breakdown = breakdown .. " | Item: " .. FormatModifier(itemMod) breakdown = breakdown .. " | Item: " .. FormatModifier(itemMod)
table.insert(modifiers, { name = item and item.name or "Item", value = itemMod }) table.insert(modifiers, { name = item and item.name or "Item", value = itemMod })
end end
if petMod ~= 0 then
breakdown = breakdown .. " | Pet: +" .. petMod
table.insert(modifiers, { name = "Pet", value = petMod })
end
breakdown = breakdown .. "\n|cffffd100Attack Total: " .. total .. "|r" breakdown = breakdown .. "\n|cffffd100Attack Total: " .. total .. "|r"
elseif rollType == "defense" then elseif rollType == "defense" then
@ -154,7 +183,7 @@ function AltSystem:CalculateAndDisplayResult(rollType, rollValue)
local defenseMod = defense and defense.modifier or 0 local defenseMod = defense and defense.modifier or 0
local shieldMod = state.shieldEnabled and AltSystem.Data.ShieldModifier 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 if not isBaseRoll then
breakdown = breakdown .. "\nSkill: " .. FormatModifier(skillMod) breakdown = breakdown .. "\nSkill: " .. FormatModifier(skillMod)
@ -170,6 +199,10 @@ function AltSystem:CalculateAndDisplayResult(rollType, rollValue)
breakdown = breakdown .. " | Shield: " .. FormatModifier(shieldMod) breakdown = breakdown .. " | Shield: " .. FormatModifier(shieldMod)
table.insert(modifiers, { name = "Shield", value = shieldMod }) table.insert(modifiers, { name = "Shield", value = shieldMod })
end end
if petMod ~= 0 then
breakdown = breakdown .. " | Pet: +" .. petMod
table.insert(modifiers, { name = "Pet", value = petMod })
end
breakdown = breakdown .. "\n|cff00ccffDefense Total: " .. total .. "|r" breakdown = breakdown .. "\n|cff00ccffDefense Total: " .. total .. "|r"
end end

25
UI.lua
View file

@ -5,7 +5,7 @@
AltSystem = AltSystem or {} AltSystem = AltSystem or {}
local WINDOW_WIDTH = 300 local WINDOW_WIDTH = 300
local WINDOW_HEIGHT = 440 local WINDOW_HEIGHT = 478
local PADDING = 12 local PADDING = 12
local ROW_HEIGHT = 30 local ROW_HEIGHT = 30
local LABEL_WIDTH = 80 local LABEL_WIDTH = 80
@ -191,6 +191,29 @@ function AltSystem:CreateMainFrame()
yPos = yPos - ROW_HEIGHT - 8 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 -- Announce checkbox + channel dropdown
------------------------- -------------------------