Roll tab
This commit is contained in:
parent
a4b2e69cc8
commit
ffc693a63c
4 changed files with 487 additions and 241 deletions
105
Roll.lua
105
Roll.lua
|
|
@ -27,10 +27,42 @@ local function BuildModifierString(modifiers)
|
|||
return table.concat(parts, " ")
|
||||
end
|
||||
|
||||
-- Build the log message string (always uses the non-emote format with character name)
|
||||
local function BuildLogMessage(rollValue, modifiers, total)
|
||||
local name = GetCharacterName()
|
||||
local modStr = BuildModifierString(modifiers)
|
||||
if modStr ~= "" then
|
||||
return name .. " rolled " .. rollValue .. " " .. modStr .. " = " .. total
|
||||
else
|
||||
return name .. " rolled " .. rollValue .. " = " .. total
|
||||
end
|
||||
end
|
||||
|
||||
-- Build the critical roll log message
|
||||
local function BuildCriticalLogMessage(isCriticalSuccess)
|
||||
local name = GetCharacterName()
|
||||
if isCriticalSuccess then
|
||||
return name .. " rolled a Critical Success!"
|
||||
else
|
||||
return name .. " rolled a Critical Failure!"
|
||||
end
|
||||
end
|
||||
|
||||
-- Add an entry to the roll log and refresh the UI
|
||||
local function AddLogEntry(text)
|
||||
local rollLog = AltSystem.State.rollLog
|
||||
table.insert(rollLog, { text = text, timestamp = time() })
|
||||
-- Cap at 100 entries
|
||||
if #rollLog > 100 then
|
||||
table.remove(rollLog, 1)
|
||||
end
|
||||
-- Refresh the log panel if it exists
|
||||
if AltSystem.RefreshLogPanel then
|
||||
AltSystem:RefreshLogPanel()
|
||||
end
|
||||
end
|
||||
|
||||
-- Send a message to the given channel.
|
||||
-- Note: EMOTE channel uses SendChatMessage like all others. The WoW API
|
||||
-- SendChatMessage(msg, "EMOTE") sends a proper /e emote from any context,
|
||||
-- unlike RunMacroText which is a protected function requiring a hardware event.
|
||||
local function SendToChannel(msg, channel)
|
||||
SendChatMessage(msg, channel)
|
||||
end
|
||||
|
|
@ -64,6 +96,24 @@ local function AnnounceRoll(rollValue, modifiers, total)
|
|||
SendToChannel(msg, channelDef.channel)
|
||||
end
|
||||
|
||||
-- Announce a critical roll result
|
||||
local function AnnounceCritical(isCriticalSuccess)
|
||||
if not AltSystem.State.announceEnabled then return end
|
||||
|
||||
local channelDef = AltSystem.AnnounceChannels[AltSystem.State.announceChannelIndex]
|
||||
if not channelDef then return end
|
||||
|
||||
local critText = isCriticalSuccess and "rolled a Critical Success!" or "rolled a Critical Failure!"
|
||||
local msg
|
||||
if channelDef.channel == "EMOTE" then
|
||||
msg = critText
|
||||
else
|
||||
msg = GetCharacterName() .. " " .. critText
|
||||
end
|
||||
|
||||
SendToChannel(msg, channelDef.channel)
|
||||
end
|
||||
|
||||
-- Perform a roll: triggers the WoW native /roll 20 command
|
||||
function AltSystem:PerformRoll(rollType)
|
||||
pendingPetRoll = nil
|
||||
|
|
@ -116,32 +166,12 @@ end)
|
|||
function AltSystem:CalculateAndDisplayResult(rollType, rollValue, petRollValue)
|
||||
-- Critical rolls bypass normal calculation
|
||||
if rollValue == 1 then
|
||||
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
|
||||
local critMsg = channelDef.channel == "EMOTE"
|
||||
and "rolled a Critical Failure!"
|
||||
or (GetCharacterName() .. " rolled a Critical Failure!")
|
||||
SendToChannel(critMsg, channelDef.channel)
|
||||
end
|
||||
end
|
||||
AddLogEntry(BuildCriticalLogMessage(false))
|
||||
AnnounceCritical(false)
|
||||
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
|
||||
local critMsg = channelDef.channel == "EMOTE"
|
||||
and "rolled a Critical Success!"
|
||||
or (GetCharacterName() .. " rolled a Critical Success!")
|
||||
SendToChannel(critMsg, channelDef.channel)
|
||||
end
|
||||
end
|
||||
AddLogEntry(BuildCriticalLogMessage(true))
|
||||
AnnounceCritical(true)
|
||||
return
|
||||
end
|
||||
|
||||
|
|
@ -153,7 +183,6 @@ function AltSystem:CalculateAndDisplayResult(rollType, rollValue, petRollValue)
|
|||
local itemMod = item and item.modifier or 0
|
||||
|
||||
local total = rollValue
|
||||
local breakdown = "Roll: " .. rollValue
|
||||
|
||||
local modifiers = {}
|
||||
|
||||
|
|
@ -166,18 +195,14 @@ function AltSystem:CalculateAndDisplayResult(rollType, rollValue, petRollValue)
|
|||
total = rollValue + skillMod + itemMod + petMod
|
||||
|
||||
if not isBaseRoll then
|
||||
breakdown = breakdown .. "\nSkill: " .. FormatModifier(skillMod)
|
||||
table.insert(modifiers, { name = skill and skill.name or "Skill", value = skillMod })
|
||||
end
|
||||
if itemMod ~= 0 then
|
||||
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
|
||||
-- Defense Roll = roll + skill modifier + item modifier + defense modifier + shield modifier
|
||||
|
|
@ -188,30 +213,26 @@ function AltSystem:CalculateAndDisplayResult(rollType, rollValue, petRollValue)
|
|||
total = rollValue + skillMod + itemMod + defenseMod + shieldMod + petMod
|
||||
|
||||
if not isBaseRoll then
|
||||
breakdown = breakdown .. "\nSkill: " .. FormatModifier(skillMod)
|
||||
table.insert(modifiers, { name = skill and skill.name or "Skill", value = skillMod })
|
||||
end
|
||||
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 defenseMod ~= 0 then
|
||||
table.insert(modifiers, { name = defense and defense.name or "Armor", value = defenseMod })
|
||||
end
|
||||
if shieldMod ~= 0 then
|
||||
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
|
||||
|
||||
if AltSystem.ResultText then
|
||||
AltSystem.ResultText:SetText(breakdown)
|
||||
end
|
||||
-- Add to log (always, regardless of announce setting)
|
||||
AddLogEntry(BuildLogMessage(rollValue, modifiers, total))
|
||||
|
||||
-- Announce to chat (if enabled)
|
||||
AnnounceRoll(rollValue, modifiers, total)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue