Skip to content
This repository has been archived by the owner on Mar 15, 2020. It is now read-only.

Commit

Permalink
Improved Hunters' crit and hit rate calculations (talents, ranged wea…
Browse files Browse the repository at this point in the history
…pon enchant).
  • Loading branch information
moh committed Oct 12, 2017
1 parent 4bde437 commit 1d2506c
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 10 deletions.
2 changes: 1 addition & 1 deletion BetterCharacterStats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ function BCS:SetRating(statFrame, ratingType)
frame.tooltipSubtext = L[BCS.playerClass .. "_MELEE_HIT_TOOLTIP"]
end
elseif ratingType == "RANGED" then
local rating = BCS:GetHitRating()
local rating = BCS:GetRangedHitRating()
if BCS.MELEEHIT[BCS.playerClass] then
if rating < BCS.MELEEHIT[BCS.playerClass][1] then
rating = colorNeg .. rating .. "%|r"
Expand Down
2 changes: 1 addition & 1 deletion BetterCharacterStats.toc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Interface: 11200
## Title: BetterCharacterStats
## Author: moh
## Version: 1.9
## Version: 1.10
## SavedVariablesPerCharacter: BCSConfig

BetterCharacterStats.xml
3 changes: 3 additions & 0 deletions Localization.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ BCS["L"] = {

["Increases your chance to hit with melee weapons by (%d)%%."] = "Increases your chance to hit with melee weapons by (%d)%%.",
["Increases your critical strike chance with ranged weapons by (%d)%%."] = "Increases your critical strike chance with ranged weapons by (%d)%%.",
["Increases hit chance by (%d)%% and increases the chance movement impairing effects will be resisted by an additional %d+%%."] = "Increases hit chance by (%d)%% and increases the chance movement impairing effects will be resisted by an additional %d+%%.",
["Increases your critical strike chance with all attacks by (%d)%%."] = "Increases your critical strike chance with all attacks by (%d)%%.",
["Increases spell damage and healing by up to (%d+)%% of your total Spirit."] = "Increases spell damage and healing by up to (%d+)%% of your total Spirit.",
["Reduces the chance that the opponent can resist your Frost and Fire spells by (%d)%%."] = "Reduces the chance that the opponent can resist your Frost and Fire spells by (%d)%%.",
["Reduces the chance that the opponent can resist your Arcane spells by (%d+)%%."] = "Reduces the chance that the opponent can resist your Arcane spells by (%d+)%%.",
Expand All @@ -35,6 +37,7 @@ BCS["L"] = {
["Healing Spells %+(%d+)"] = "Healing Spells %+(%d+)",

["Equip: Restores (%d+) mana per 5 sec."] = "Equip: Restores (%d+) mana per 5 sec.",
["+(%d)%% Hit"] = "+(%d)%% Hit",

-- Random Bonuses // https://wow.gamepedia.com/index.php?title=SuffixId&oldid=204406
["^%+(%d+) Damage and Healing Spells"] = "^%+(%d+) Damage and Healing Spells",
Expand Down
128 changes: 120 additions & 8 deletions helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ function BCS:GetPlayerAura(searchText, auraType)
end

local Cache_GetHitRating_Tab, Cache_GetHitRating_Talent
function BCS:GetHitRating()
local hit_debuff = 0
function BCS:GetHitRating(hitOnly)
local Hit_Set_Bonus = {}
local hit = 0;
local MAX_INVENTORY_SLOTS = 19;
Expand Down Expand Up @@ -117,15 +118,15 @@ function BCS:GetHitRating()
-- debuffs
_, _, hitFromAura = BCS:GetPlayerAura(L["Chance to hit reduced by (%d+)%%."], 'HARMFUL')
if hitFromAura then
hit = hit - tonumber(hitFromAura)
hit_debuff = hit_debuff + tonumber(hitFromAura)
end
_, _, hitFromAura = BCS:GetPlayerAura(L["Chance to hit decreased by (%d+)%% and %d+ Nature damage every %d+ sec."], 'HARMFUL')
if hitFromAura then
hit = hit - tonumber(hitFromAura)
hit_debuff = hit_debuff + tonumber(hitFromAura)
end
hitFromAura = BCS:GetPlayerAura(L["Lowered chance to hit."], 'HARMFUL')
if hitFromAura then
hit = hit - 25
hit_debuff = hit_debuff + 25
end

local MAX_TABS = GetNumTalentTabs()
Expand All @@ -137,17 +138,31 @@ function BCS:GetHitRating()
for line=1, MAX_LINES do
local left = getglobal(BCS_Prefix .. "TextLeft" .. line)
if left:GetText() then
-- rogues
local _,_, value = strfind(left:GetText(), L["Increases your chance to hit with melee weapons by (%d)%%."])
local name, iconTexture, tier, column, rank, maxRank, isExceptional, meetsPrereq = GetTalentInfo(Cache_GetHitRating_Tab, Cache_GetHitRating_Talent)
if value and rank > 0 then
hit = hit + tonumber(value)
line = MAX_LINES
end

-- hunters
_,_, value = strfind(left:GetText(), L["Increases hit chance by (%d)%% and increases the chance movement impairing effects will be resisted by an additional %d+%%."])
name, iconTexture, tier, column, rank, maxRank, isExceptional, meetsPrereq = GetTalentInfo(Cache_GetHitRating_Tab, Cache_GetHitRating_Talent)
if value and rank > 0 then
hit = hit + tonumber(value)
line = MAX_LINES
end
end
end

if hit < 0 then hit = 0 end
return hit
if not hitOnly then
hit = hit + hit_debuff
if hit < 0 then hit = 0 end
return hit
else
return hit
end
end

for tab=1, MAX_TABS do
Expand All @@ -160,6 +175,7 @@ function BCS:GetHitRating()
for line=1, MAX_LINES do
local left = getglobal(BCS_Prefix .. "TextLeft" .. line)
if left:GetText() then
-- rogues
local _,_, value = strfind(left:GetText(), L["Increases your chance to hit with melee weapons by (%d)%%."])
local name, iconTexture, tier, column, rank, maxRank, isExceptional, meetsPrereq = GetTalentInfo(tab, talent)
if value and rank > 0 then
Expand All @@ -172,14 +188,58 @@ function BCS:GetHitRating()
talent = MAX_TALENTS
tab = MAX_TABS
end

-- hunters
_,_, value = strfind(left:GetText(), L["Increases hit chance by (%d)%% and increases the chance movement impairing effects will be resisted by an additional %d+%%."])
name, iconTexture, tier, column, rank, maxRank, isExceptional, meetsPrereq = GetTalentInfo(tab, talent)
if value and rank > 0 then
hit = hit + tonumber(value)

Cache_GetHitRating_Tab = tab
Cache_GetHitRating_Talent = talent

line = MAX_LINES
talent = MAX_TALENTS
tab = MAX_TABS
end
end
end

end
end

if hit < 0 then hit = 0 end -- Dust Cloud OP
return hit
if not hitOnly then
hit = hit + hit_debuff
if hit < 0 then hit = 0 end -- Dust Cloud OP
return hit
else
return hit
end
end

function BCS:GetRangedHitRating()
local melee_hit = BCS:GetHitRating(true)
local ranged_hit = melee_hit
local debuff = hit_debuff

local hasItem = BCS_Tooltip:SetInventoryItem("player", 18) -- ranged enchant
if hasItem then
local MAX_LINES = BCS_Tooltip:NumLines()
for line=1, MAX_LINES do
local left = getglobal(BCS_Prefix .. "TextLeft" .. line)
if left:GetText() then
local _,_, value = strfind(left:GetText(), L["+(%d)%% Hit"])
if value then
ranged_hit = ranged_hit + tonumber(value)
line = MAX_LINES
end
end
end
end

ranged_hit = ranged_hit + debuff
if ranged_hit < 0 then ranged_hit = 0 end
return ranged_hit
end

function BCS:GetSpellHitRating()
Expand Down Expand Up @@ -282,8 +342,60 @@ function BCS:GetSpellHitRating()
end

local Cache_GetCritChance_SpellID, Cache_GetCritChance_BookType, Cache_GetCritChance_Line
local Cache_GetCritChance_Tab, Cache_GetCritChance_Talent
function BCS:GetCritChance()
local crit = 0
local _, class = UnitClass('player')

if class == 'HUNTER' then

local MAX_TABS = GetNumTalentTabs()
-- speedup
if Cache_GetCritChance_Tab and Cache_GetCritChance_Talent then
BCS_Tooltip:SetTalent(Cache_GetCritChance_Tab, Cache_GetCritChance_Talent)
local MAX_LINES = BCS_Tooltip:NumLines()

for line=1, MAX_LINES do
local left = getglobal(BCS_Prefix .. "TextLeft" .. line)
if left:GetText() then
local _,_, value = strfind(left:GetText(), L["Increases your critical strike chance with all attacks by (%d)%%."])
local name, iconTexture, tier, column, rank, maxRank, isExceptional, meetsPrereq = GetTalentInfo(Cache_GetCritChance_Tab, Cache_GetCritChance_Talent)
if value and rank > 0 then
crit = crit + tonumber(value)
line = MAX_LINES
end
end
end
else
for tab=1, MAX_TABS do
local MAX_TALENTS = GetNumTalents(tab)
for talent=1, MAX_TALENTS do
BCS_Tooltip:SetTalent(tab, talent);
local MAX_LINES = BCS_Tooltip:NumLines()

for line=1, MAX_LINES do
local left = getglobal(BCS_Prefix .. "TextLeft" .. line)
if left:GetText() then
local _,_, value = strfind(left:GetText(), L["Increases your critical strike chance with all attacks by (%d)%%."])
local name, iconTexture, tier, column, rank, maxRank, isExceptional, meetsPrereq = GetTalentInfo(tab, talent)
if value and rank > 0 then
crit = crit + tonumber(value)

Cache_GetCritChance_Tab = tab
Cache_GetCritChance_Talent = talent

line = MAX_LINES
talent = MAX_TALENTS
tab = MAX_TABS
end
end
end

end
end
end

end

-- speedup
if Cache_GetCritChance_SpellID and Cache_GetCritChance_BookType and Cache_GetCritChance_Line then
Expand Down

0 comments on commit 1d2506c

Please sign in to comment.