Skip to content

Commit

Permalink
Fix a potential division by 0 when calculating health, closes #129
Browse files Browse the repository at this point in the history
  • Loading branch information
funkydude committed Jan 31, 2023
1 parent d70fc49 commit 3d3fb34
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 36 deletions.
28 changes: 19 additions & 9 deletions Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ do
local collection, reset, blocked, started = {}, {}, {}, false
local count1, count2, count3 = #unitTable1, #unitTable2, #unitTable3
local UnitGUID, strsplit = UnitGUID, strsplit
local UnitHealth, UnitHealthMax = UnitHealth, UnitHealthMax
local SendAddonMessage = C_ChatInfo.SendAddonMessage
local curMod = nil

Expand All @@ -259,9 +260,12 @@ do
if guid then
local _, _, _, _, _, strid = strsplit("-", guid)
if strid and collection[strid] and not blocked[strid] then
blocked[strid] = true
local hp = UnitHealth(unit) / UnitHealthMax(unit) * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
local maxHP = UnitHealthMax(unit)
if maxHP > 0 then
blocked[strid] = true
local hp = UnitHealth(unit) / maxHP * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
end
end
end
end
Expand All @@ -275,9 +279,12 @@ do
if guid then
local _, _, _, _, _, strid = strsplit("-", guid)
if strid and collection[strid] and not blocked[strid] then
blocked[strid] = true
local hp = UnitHealth(unit) / UnitHealthMax(unit) * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
local maxHP = UnitHealthMax(unit)
if maxHP > 0 then
blocked[strid] = true
local hp = UnitHealth(unit) / maxHP * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
end
end
end
end
Expand Down Expand Up @@ -308,9 +315,12 @@ do
if guid then
local _, _, _, _, _, strid = strsplit("-", guid)
if strid and collection[strid] and not blocked[strid] then
blocked[strid] = true
local hp = UnitHealth(unit) / UnitHealthMax(unit) * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
local maxHP = UnitHealthMax(unit)
if maxHP > 0 then
blocked[strid] = true
local hp = UnitHealth(unit) / maxHP * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
end
end
end
end
Expand Down
28 changes: 19 additions & 9 deletions Core_BCC.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ do
local collection, reset, blocked, started = {}, {}, {}, false
local count1, count2, count3 = #unitTable1, #unitTable2, #unitTable3
local UnitGUID, strsplit = UnitGUID, strsplit
local UnitHealth, UnitHealthMax = UnitHealth, UnitHealthMax
local SendAddonMessage = C_ChatInfo.SendAddonMessage
local curMod = nil

Expand All @@ -259,9 +260,12 @@ do
if guid then
local _, _, _, _, _, strid = strsplit("-", guid)
if strid and collection[strid] and not blocked[strid] then
blocked[strid] = true
local hp = UnitHealth(unit) / UnitHealthMax(unit) * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
local maxHP = UnitHealthMax(unit)
if maxHP > 0 then
blocked[strid] = true
local hp = UnitHealth(unit) / maxHP * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
end
end
end
end
Expand All @@ -275,9 +279,12 @@ do
if guid then
local _, _, _, _, _, strid = strsplit("-", guid)
if strid and collection[strid] and not blocked[strid] then
blocked[strid] = true
local hp = UnitHealth(unit) / UnitHealthMax(unit) * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
local maxHP = UnitHealthMax(unit)
if maxHP > 0 then
blocked[strid] = true
local hp = UnitHealth(unit) / maxHP * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
end
end
end
end
Expand Down Expand Up @@ -308,9 +315,12 @@ do
if guid then
local _, _, _, _, _, strid = strsplit("-", guid)
if strid and collection[strid] and not blocked[strid] then
blocked[strid] = true
local hp = UnitHealth(unit) / UnitHealthMax(unit) * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
local maxHP = UnitHealthMax(unit)
if maxHP > 0 then
blocked[strid] = true
local hp = UnitHealth(unit) / maxHP * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
end
end
end
end
Expand Down
28 changes: 19 additions & 9 deletions Core_Vanilla.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ do
local collection, reset, blocked, started = {}, {}, {}, false
local count1, count2, count3 = #unitTable1, #unitTable2, #unitTable3
local UnitGUID, strsplit = UnitGUID, strsplit
local UnitHealth, UnitHealthMax = UnitHealth, UnitHealthMax
local SendAddonMessage = C_ChatInfo.SendAddonMessage
local curMod = nil

Expand All @@ -259,9 +260,12 @@ do
if guid then
local _, _, _, _, _, strid = strsplit("-", guid)
if strid and collection[strid] and not blocked[strid] then
blocked[strid] = true
local hp = UnitHealth(unit) / UnitHealthMax(unit) * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
local maxHP = UnitHealthMax(unit)
if maxHP > 0 then
blocked[strid] = true
local hp = UnitHealth(unit) / maxHP * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
end
end
end
end
Expand All @@ -275,9 +279,12 @@ do
if guid then
local _, _, _, _, _, strid = strsplit("-", guid)
if strid and collection[strid] and not blocked[strid] then
blocked[strid] = true
local hp = UnitHealth(unit) / UnitHealthMax(unit) * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
local maxHP = UnitHealthMax(unit)
if maxHP > 0 then
blocked[strid] = true
local hp = UnitHealth(unit) / maxHP * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
end
end
end
end
Expand Down Expand Up @@ -308,9 +315,12 @@ do
if guid then
local _, _, _, _, _, strid = strsplit("-", guid)
if strid and collection[strid] and not blocked[strid] then
blocked[strid] = true
local hp = UnitHealth(unit) / UnitHealthMax(unit) * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
local maxHP = UnitHealthMax(unit)
if maxHP > 0 then
blocked[strid] = true
local hp = UnitHealth(unit) / maxHP * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
end
end
end
end
Expand Down
28 changes: 19 additions & 9 deletions Core_Wrath.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ do
local collection, reset, blocked, started = {}, {}, {}, false
local count1, count2, count3 = #unitTable1, #unitTable2, #unitTable3
local UnitGUID, strsplit = UnitGUID, strsplit
local UnitHealth, UnitHealthMax = UnitHealth, UnitHealthMax
local SendAddonMessage = C_ChatInfo.SendAddonMessage
local curMod = nil

Expand All @@ -259,9 +260,12 @@ do
if guid then
local _, _, _, _, _, strid = strsplit("-", guid)
if strid and collection[strid] and not blocked[strid] then
blocked[strid] = true
local hp = UnitHealth(unit) / UnitHealthMax(unit) * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
local maxHP = UnitHealthMax(unit)
if maxHP > 0 then
blocked[strid] = true
local hp = UnitHealth(unit) / maxHP * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
end
end
end
end
Expand All @@ -275,9 +279,12 @@ do
if guid then
local _, _, _, _, _, strid = strsplit("-", guid)
if strid and collection[strid] and not blocked[strid] then
blocked[strid] = true
local hp = UnitHealth(unit) / UnitHealthMax(unit) * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
local maxHP = UnitHealthMax(unit)
if maxHP > 0 then
blocked[strid] = true
local hp = UnitHealth(unit) / maxHP * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
end
end
end
end
Expand Down Expand Up @@ -308,9 +315,12 @@ do
if guid then
local _, _, _, _, _, strid = strsplit("-", guid)
if strid and collection[strid] and not blocked[strid] then
blocked[strid] = true
local hp = UnitHealth(unit) / UnitHealthMax(unit) * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
local maxHP = UnitHealthMax(unit)
if maxHP > 0 then
blocked[strid] = true
local hp = UnitHealth(unit) / maxHP * 100
SendAddonMessage("Capping", format("%s:%.1f", strid, hp), "INSTANCE_CHAT")
end
end
end
end
Expand Down

0 comments on commit 3d3fb34

Please sign in to comment.