Skip to content

Commit

Permalink
Recognize Bonus Damage on weapons
Browse files Browse the repository at this point in the history
  • Loading branch information
Anonomit committed Feb 29, 2024
1 parent c988ac1 commit 1e034ed
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 15 deletions.
49 changes: 43 additions & 6 deletions Config/OptionsTables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1080,21 +1080,48 @@ local function MakeExtraOptions(opts, categoryName)
do
local stat = "Damage"

local defaultText = format(DAMAGE_TEMPLATE, sampleDamage * (1-sampleVariance), sampleDamage * (1+sampleVariance))
local defaultText, formattedText, changed = GetFormattedText(stat, self.COLORS.WHITE, defaultText, self:ModifyWeaponDamage(defaultText, sampleDamage, 1))
local samples = {}
do
local min, max = self:Round(sampleDamage * (1-sampleVariance)), self:Round(sampleDamage * (1+sampleVariance))
local default1 = format(DAMAGE_TEMPLATE, min, max)
local default2 = format(PLUS_DAMAGE_TEMPLATE, min, max)

for _, v in ipairs{
{default1, self:ModifyWeaponDamage(default1, sampleDamage*2, 1, {min, max}), self:GetOption("hide", stat)},
{default2, self:ModifyWeaponDamageBonus(default2, {min, max}), self:GetOption("hide", stat) or self:GetOption("hide", "DamageBonus")},
} do
local defaultText = v[1]
local formattedText = v[2]
local hidden = v[3]

local originalColor = self.COLORS.WHITE
local color = self:GetOption("color", stat)
if hidden then
formattedText = self.stealthIcon .. self:MakeColorCode(self.COLORS.GRAY, self:StripColorCode(formattedText))
elseif self:GetOption("allow", "recolor") and self:GetOption("doRecolor", stat) and color ~= originalColor then
formattedText = self:MakeColorCode(color, formattedText)
else
formattedText = self:MakeColorCode(originalColor, formattedText)
end
defaultText = self:MakeColorCode(originalColor, defaultText)

tinsert(samples, {defaultText, formattedText})
end
end

local opts = GUI:CreateGroup(opts, stat, formattedText, self.L["Weapon Damage"])
local opts = GUI:CreateGroup(opts, stat, samples[1][2], self.L["Weapon Damage"])

do
local opts = CreateTitle(opts, defaultText, formattedText, changed, 1)
local opts = CreateSamples(opts, samples)
GUI:CreateNewline(opts)

-- Test
local option = GUI:CreateRange(opts, {"sampleDamage"}, L["Test"], nil, 0, 1000000, 0.5)
option.softMax = 1000
option.bigStep = 10
option.get = function(info) return sampleDamage end
option.set = function(info, val) sampleDamage = val end
local option = GUI:CreateRange(opts, {"sampleVariance"}, L["Test"], nil, 0, 1, 0.1)
local option = GUI:CreateRange(opts, {"sampleVariance"}, L["Test"], nil, 0, 1, 0.05)
option.isPercent = true
option.get = function(info) return sampleVariance end
option.set = function(info, val) sampleVariance = val end
Expand Down Expand Up @@ -1122,7 +1149,17 @@ local function MakeExtraOptions(opts, categoryName)
GUI:CreateReset(opts, {"damage", "variancePrefix"})
end

CreateHide(opts, stat)
do
local opts = GUI:CreateGroupBox(opts, self.L["Hide"])

GUI:CreateToggle(opts, {"hide", stat}, self.L["Hide"], nil, disabled)
GUI:CreateReset(opts, {"hide", stat})
GUI:CreateNewline(opts)

local disabled = self:GetOption("hide", stat)
GUI:CreateToggle(opts, {"hide", "DamageBonus"}, self.L["Bonus Damage"], L["Merge Bonus Damage into Weapon Damage"], disabled)
GUI:CreateReset(opts, {"hide", "DamageBonus"})
end
end

local speedString = strGsub(format("%.2f", sampleSpeed), "%.", DECIMAL_SEPERATOR)
Expand Down
1 change: 1 addition & 0 deletions Locale/LocaleAutomatic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ L["End"] = KEY_END
L["Short Name"] = COMMUNITIES_SETTINGS_SHORT_NAME_LABEL
L["Show Item Level"] = SHOW_ITEM_LEVEL
L["Weapon Damage"] = DAMAGE_TOOLTIP
L["Bonus Damage"] = BONUS_DAMAGE
L["Speed"] = SPEED
L["Damage Per Second"] = ITEM_MOD_DAMAGE_PER_SECOND_SHORT
L["Trade"] = TRADE
Expand Down
11 changes: 6 additions & 5 deletions Locale/enUs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ L["Trainable Equipment"] = true
L["Equipment that a trainer can teach you to wear."] = true

-- weapon damage
L["Show Minimum and Maximum"] = true
L["Show Average"] = true
L["Show Variance"] = true
L["Variance Prefix"] = true
L["Show Percent"] = true
L["Show Minimum and Maximum"] = true
L["Show Average"] = true
L["Show Variance"] = true
L["Variance Prefix"] = true
L["Show Percent"] = true
L["Merge Bonus Damage into Weapon Damage"] = true

-- dps
L["Remove Brackets"] = true
Expand Down
13 changes: 13 additions & 0 deletions Operations/RecognizeLineTypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ local contexts = Addon:MakeLookupTable({
"Type",
"RedType",
"Damage",
"DamageBonus",
"DamagePerSecond",
"Armor",
"BonusArmor",
Expand Down Expand Up @@ -324,6 +325,18 @@ contextActions = Addon:Map({
return SetContext(i, tooltipData, line)
end
end,
DamageBonus = function(i, tooltipData, line)
if MatchesAny(line.textLeftTextStripped, PLUS_SINGLE_DAMAGE_TEMPLATE, PLUS_DAMAGE_TEMPLATE, PLUS_SINGLE_DAMAGE_TEMPLATE_WITH_SCHOOL, PLUS_DAMAGE_TEMPLATE_WITH_SCHOOL) then
local min, max = strMatch(line.textLeftTextStripped, "%+ ?(%d+) ?%- ?(%d+)")
if min then
tooltipData.damageBonus = {tonumber(min), tonumber(max)}
else
local n = tonumber(strMatch(line.textLeftTextStripped, "%+ ?(%d+)"))
tooltipData.damageBonus = {n, n}
end
return SetContext(i, tooltipData, line)
end
end,
DamagePerSecond = function(i, tooltipData, line)
local _, dps = MatchesAny(line.textLeftTextStripped, DPS_TEMPLATE)
if dps then
Expand Down
2 changes: 2 additions & 0 deletions Operations/RecolorLine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ function Addon:RecolorLine(tooltip, line, tooltipData)
elseif line.type == "Damage" then
Recolor("left", "Damage")
Recolor("right", "Speed")
elseif line.type == "DamageBonus" then
Recolor("left", "Damage")
elseif line.type == "DamagePerSecond" then
Recolor("left", "DamagePerSecond")
-- Speed bar colored through rewording
Expand Down
5 changes: 4 additions & 1 deletion Operations/RewordLine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@ function Addon:RewordLine(tooltip, line, tooltipData)
text = self:RewordBinding(text, line.bindType)
end,
Damage = function()
text = self:ModifyWeaponDamage(text, tooltipData.dps, tooltipData.speed)
text = self:ModifyWeaponDamage(text, tooltipData.dps, tooltipData.speed, tooltipData.damageBonus)
if not line.hideRight then
local rightText = self:ModifyWeaponSpeed(line.textRightText, tooltipData.speed, tooltipData.speedString)
if rightText ~= line.textRightText then
line.rewordRight = rightText
end
end
end,
DamageBonus = function()
text = self:ModifyWeaponDamageBonus(text, tooltipData.damageBonus)
end,
DamagePerSecond = function()
text = self:ModifyWeaponDamagePerSecond(text)
if not line.hideRight and tooltipData.speed then
Expand Down
68 changes: 65 additions & 3 deletions Operations/RewordWeaponStats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,64 @@ local strMatch = string.match
local strGsub = string.gsub
local strRep = string.rep

local defaultDamageBonus = {0, 0}

function Addon:ModifyWeaponDamage(text, dps, speed, damageBonus)
damageBonus = damageBonus or defaultDamageBonus

local showAverage = self:GetOption("allow", "reword") and self:GetOption("damage", "showAverage")
local showVariance = self:GetOption("allow", "reword") and self:GetOption("damage", "showVariance")
local showMinMax = self:GetOption("allow", "reword") and self:GetOption("damage", "showMinMax")

local minMax, min, gap, max = strMatch(text, "((%d+)( ?%- ?)(%d+))")
if min then
min, max = tonumber(min), tonumber(max)
local mid = dps * speed
if self:GetOption("hide", "DamageBonus") then
min = min + (damageBonus[1])
max = max + (damageBonus[2])
minMax = min .. gap .. max
else
mid = mid - (damageBonus[1] + damageBonus[2]) / 2
end

local average = showAverage and format("%d", mid) or nil
local usePercent = self:GetOption("damage", "variancePercent")

local varianceDecimal
if mid == 0 then
varianceDecimal = 0
else
varianceDecimal = max/mid
end
local variance = showVariance and format("%s%d%s", self:GetOption("damage", "variancePrefix"), usePercent and self:Round((varianceDecimal-1)*100, 5) or self:Round(max-mid, 1), usePercent and "%%" or "") or nil
local minMax = showMinMax and minMax or nil

local pattern
if average then
pattern = average
if variance then
pattern = format("%s %s", pattern, variance)
end
if minMax then
pattern = format("%s (%s)", pattern, minMax)
end
else
pattern = minMax
if variance then
pattern = format("%s (%s)", pattern, variance)
end
end

return strGsub(text, "%d+ ?%- ?%d+", pattern)
end
return text
end


function Addon:ModifyWeaponDamage(text, dps, speed)
function Addon:ModifyWeaponDamageBonus(text, damageBonus)
text = strGsub(text, " +", " ") -- Fix weird spacing (ex. 7730)

local showAverage = self:GetOption("allow", "reword") and self:GetOption("damage", "showAverage")
local showVariance = self:GetOption("allow", "reword") and self:GetOption("damage", "showVariance")
if not (showAverage or showVariance) then return text end -- no changes to make
Expand All @@ -20,10 +75,17 @@ function Addon:ModifyWeaponDamage(text, dps, speed)
local minMax, min, max = strMatch(text, "((%d+) ?%- ?(%d+))")
if min then
min, max = tonumber(min), tonumber(max)
local mid = dps * speed
local mid = (damageBonus[1] + damageBonus[2]) / 2
local average = showAverage and format("%d", mid) or nil
local usePercent = self:GetOption("damage", "variancePercent")
local variance = showVariance and format("%s%d%s", self:GetOption("damage", "variancePrefix"), usePercent and self:Round((max/mid-1)*100, 10) or self:Round(max-mid, 1), usePercent and "%%" or "") or nil

local varianceDecimal
if mid == 0 then
varianceDecimal = 0
else
varianceDecimal = max/mid
end
local variance = showVariance and format("%s%d%s", self:GetOption("damage", "variancePrefix"), usePercent and self:Round((varianceDecimal-1)*100, 5) or self:Round(max-mid, 1), usePercent and "%%" or "") or nil
local minMax = showMinMax and minMax or nil

local pattern
Expand Down
1 change: 1 addition & 0 deletions Stats/Stats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ do
self.statsInfo["Trainable"] = {color = self.COLORS.ORANGE}

self.statsInfo["Damage"] = {color = self.COLORS.WHITE}
self.statsInfo["DamageBonus"] = {color = self.COLORS.WHITE}
self.statsInfo["Speed"] = {color = self.COLORS.WHITE}

self.statsInfo["DamagePerSecond"] = {color = self.COLORS.WHITE}
Expand Down

0 comments on commit 1e034ed

Please sign in to comment.