Chat announce rolls

This commit is contained in:
Gonçalo Correia 2026-04-12 20:48:49 +01:00
parent e17370a89f
commit 907e0464ed
5 changed files with 154 additions and 2 deletions

View file

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

View file

@ -7,6 +7,16 @@ AltSystem.State = {
selectedItemIndex = 1, -- 1 = No item
selectedDefenseIndex = 1, -- 1 = Base armor
shieldEnabled = false,
announceEnabled = false,
announceChannelIndex = 1, -- 1 = Emote, 2 = Party, 3 = Raid, 4 = Guild
}
-- Channel definitions for announcing rolls
AltSystem.AnnounceChannels = {
{ name = "Emote (/e)", channel = "EMOTE" },
{ name = "Party (/p)", channel = "PARTY" },
{ name = "Raid (/ra)", channel = "RAID" },
{ name = "Guild (/g)", channel = "GUILD" },
}
-- Initialization on ADDON_LOADED
@ -21,12 +31,30 @@ frame:SetScript("OnEvent", function(self, event, arg1)
end)
function AltSystem:Init()
-- Load saved settings
AltSystemDB = AltSystemDB or {}
if AltSystemDB.announceEnabled ~= nil then
AltSystem.State.announceEnabled = AltSystemDB.announceEnabled
end
if AltSystemDB.announceChannelIndex then
AltSystem.State.announceChannelIndex = AltSystemDB.announceChannelIndex
end
-- Register slash command /altsystem
SLASH_ALTSYSTEM1 = "/altsystem"
SlashCmdList["ALTSYSTEM"] = function()
AltSystem:ToggleWindow()
end
-- Save settings on logout
local saveFrame = CreateFrame("Frame")
saveFrame:RegisterEvent("PLAYER_LOGOUT")
saveFrame:SetScript("OnEvent", function()
AltSystemDB = AltSystemDB or {}
AltSystemDB.announceEnabled = AltSystem.State.announceEnabled
AltSystemDB.announceChannelIndex = AltSystem.State.announceChannelIndex
end)
print("|cff00ccffAltSystem|r loaded. Type /altsystem to open.")
end

View file

@ -5,6 +5,49 @@ AltSystem = AltSystem or {}
local pendingRollType = nil -- "attack" or "defense"
-- Get the TRP3 character first name, falling back to the WoW unit name
local function GetCharacterName()
if TRP3_API and TRP3_API.profile and TRP3_API.profile.getData then
local ok, characteristics = pcall(TRP3_API.profile.getData, "player/characteristics")
if ok and characteristics and characteristics.FN and characteristics.FN ~= "" then
return characteristics.FN
end
end
return UnitName("player")
end
-- Build the modifier description string for the announce message
local function BuildModifierString(modifiers)
local parts = {}
for _, mod in ipairs(modifiers) do
if mod.value ~= 0 then
local sign = mod.value >= 0 and "+" or ""
table.insert(parts, sign .. mod.value .. " (" .. mod.name .. ")")
end
end
return table.concat(parts, " ")
end
-- Announce the roll result to the selected chat channel
local function AnnounceRoll(rollValue, modifiers, total)
if not AltSystem.State.announceEnabled then return end
local channelDef = AltSystem.AnnounceChannels[AltSystem.State.announceChannelIndex]
if not channelDef then return end
local name = GetCharacterName()
local modStr = BuildModifierString(modifiers)
local msg
if modStr ~= "" then
msg = name .. " rolled " .. rollValue .. " " .. modStr .. " = " .. total
else
msg = name .. " rolled " .. rollValue .. " = " .. total
end
SendChatMessage(msg, channelDef.channel)
end
-- Perform a roll: triggers the WoW native /roll 20 command
function AltSystem:PerformRoll(rollType)
pendingRollType = rollType
@ -36,11 +79,23 @@ function AltSystem:CalculateAndDisplayResult(rollType, rollValue)
if AltSystem.ResultText then
AltSystem.ResultText:SetText("|cffff0000Critical Failure|r")
end
if AltSystem.State.announceEnabled then
local channelDef = AltSystem.AnnounceChannels[AltSystem.State.announceChannelIndex]
if channelDef then
SendChatMessage(GetCharacterName() .. " rolled a Critical Failure!", channelDef.channel)
end
end
return
elseif rollValue == 20 then
if AltSystem.ResultText then
AltSystem.ResultText:SetText("|cff00ff00Critical Success|r")
end
if AltSystem.State.announceEnabled then
local channelDef = AltSystem.AnnounceChannels[AltSystem.State.announceChannelIndex]
if channelDef then
SendChatMessage(GetCharacterName() .. " rolled a Critical Success!", channelDef.channel)
end
end
return
end
@ -54,13 +109,17 @@ function AltSystem:CalculateAndDisplayResult(rollType, rollValue)
local total = rollValue
local breakdown = "Roll: " .. rollValue
local modifiers = {}
if rollType == "attack" then
-- Attack Roll = roll + skill modifier + item modifier
total = rollValue + skillMod + itemMod
breakdown = breakdown .. "\nSkill: " .. FormatModifier(skillMod)
table.insert(modifiers, { name = skill and skill.name or "Skill", value = skillMod })
if itemMod ~= 0 then
breakdown = breakdown .. " | Item: " .. FormatModifier(itemMod)
table.insert(modifiers, { name = item and item.name or "Item", value = itemMod })
end
breakdown = breakdown .. "\n|cffffd100Attack Total: " .. total .. "|r"
@ -73,12 +132,16 @@ function AltSystem:CalculateAndDisplayResult(rollType, rollValue)
total = rollValue + skillMod + itemMod + defenseMod + shieldMod
breakdown = breakdown .. "\nSkill: " .. FormatModifier(skillMod)
table.insert(modifiers, { name = skill and skill.name or "Skill", value = skillMod })
if itemMod ~= 0 then
breakdown = breakdown .. " | Item: " .. FormatModifier(itemMod)
table.insert(modifiers, { name = item and item.name or "Item", value = itemMod })
end
breakdown = breakdown .. "\nDefense: " .. FormatModifier(defenseMod)
table.insert(modifiers, { name = defense and defense.name or "Defense", value = defenseMod })
if shieldMod ~= 0 then
breakdown = breakdown .. " | Shield: " .. FormatModifier(shieldMod)
table.insert(modifiers, { name = "Shield", value = shieldMod })
end
breakdown = breakdown .. "\n|cff00ccffDefense Total: " .. total .. "|r"
end
@ -86,6 +149,8 @@ function AltSystem:CalculateAndDisplayResult(rollType, rollValue)
if AltSystem.ResultText then
AltSystem.ResultText:SetText(breakdown)
end
AnnounceRoll(rollValue, modifiers, total)
end
-- Format a modifier value with sign

48
UI.lua
View file

@ -5,7 +5,7 @@
AltSystem = AltSystem or {}
local WINDOW_WIDTH = 300
local WINDOW_HEIGHT = 380
local WINDOW_HEIGHT = 440
local PADDING = 12
local ROW_HEIGHT = 30
local LABEL_WIDTH = 80
@ -154,6 +154,52 @@ function AltSystem:CreateMainFrame()
AltSystem.State.shieldEnabled = self:GetChecked()
end)
yPos = yPos - ROW_HEIGHT - 8
-------------------------
-- Announce checkbox + channel dropdown
-------------------------
local announceLabel = f:CreateFontString(nil, "OVERLAY", "GameFontNormal")
announceLabel:SetPoint("TOPLEFT", f, "TOPLEFT", PADDING, yPos)
announceLabel:SetText("Announce:")
announceLabel:SetWidth(LABEL_WIDTH)
announceLabel:SetJustifyH("LEFT")
local announceCheck = CreateFrame("CheckButton", "AltSystemAnnounceCheck", f, "UICheckButtonTemplate")
announceCheck:SetPoint("LEFT", announceLabel, "RIGHT", -6, 0)
announceCheck:SetChecked(AltSystem.State.announceEnabled)
-- Channel dropdown (shown only when announce is enabled)
local channelOptions = {}
for _, ch in ipairs(AltSystem.AnnounceChannels) do
table.insert(channelOptions, { text = ch.name })
end
local channelDropdown, getChannelIndex, setChannelIndex = CreateDropdown(
f, "AltSystemChannelDropdown", yPos, "", channelOptions,
AltSystem.State.announceChannelIndex,
function(index)
AltSystem.State.announceChannelIndex = index
end)
channelDropdown:SetPoint("LEFT", announceCheck, "RIGHT", 2, 0)
channelDropdown:SetWidth(130)
-- Show/hide channel dropdown based on checkbox state
local function UpdateChannelDropdownVisibility()
if AltSystem.State.announceEnabled then
channelDropdown:Show()
else
channelDropdown:Hide()
end
end
announceCheck:SetScript("OnClick", function(self)
AltSystem.State.announceEnabled = self:GetChecked()
UpdateChannelDropdownVisibility()
end)
UpdateChannelDropdownVisibility()
yPos = yPos - ROW_HEIGHT - 12
-------------------------

13
docs/3-announce.md Normal file
View file

@ -0,0 +1,13 @@
# Feature: Announcing rolls
- There should be a setting to allow announcing rolls in chat
- This setting can be enabled or disabled through a checkbox
- When enabled, a dropdown selection of channels should be shown:
- Emote (/e)
- Party (/p)
- Raid (/ra)
- Guild (/g)
- Selection and enabled/disabled state should be saved
- When enabled, rolls should be announced in the selected channel in the following format:
- "[Name] rolled [result of d20] + [modifier] = [total]"
- Modifiers should be shown with names in parentheses, for example "-2 (First Aid) +2 (Item)"
- Name should be the TRP character first name