-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.lua
155 lines (132 loc) · 4.59 KB
/
config.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
local SkillUpProbability, core = ...
core.Config = {}
local Config = core.config
-- Print with color
function core:Print(...)
color = "cff00ccff"
local prefix = string.format('\124' .. color .. "SkillUpProbability:" .. '\124r')
DEFAULT_CHAT_FRAME:AddMessage(string.join(" ", prefix, tostringall(...)))
end
-- Get name of currently open trade skill
function core:GetProfessionName()
return select(1, GetTradeSkillLine())
end
-- Get level of currently open trade skill
function core:GetProfessionLevel()
return select(2, GetTradeSkillLine())
end
-- Get percentage chance of skill-up
function core:CalcChance(graySkill, playerSkill, yellowSkill)
--[[
graySkill -> The level at which said spell turns gray
yellowSkill -> The level at which said spell turns yellow
playerSkill -> The player's current level
--]]
local chance = (graySkill - playerSkill) / (graySkill - yellowSkill)
return chance
end
-- Round to a given amount of decimal places
function core:Round(n, decimalPlaces)
local mult = 10^(decimalPlaces or 0)
return math.floor(n * mult + 0.5) / mult
end
-- Check if a profession/spell pair exists
function core:TableHas(table, key)
return core.SpellData[table][key] ~= nil
end
-- Calculate the percentage chance of a spell giving a skill-up
function core:GetChance(skillName, profName, playerSkill)
--[[ Sometimes the hook on TradeSkillFrame_Update attempts to index profession/spell pairs that do not
-- exist, for example "Blacksmithing:Heavy Silk Bandage" or "First Aid:Silver Skeleton Key". I do not
-- know why this happens but I have added this check here to prevent it from throwing an error in-game,
-- as it does not actually affect the calculations of the add-on and is trivial ]]--
if (core:TableHas(profName, skillName) ~= true) then
return 0
else
local gray = core.SpellData[profName][skillName][4]
local green = core.SpellData[profName][skillName][3]
local yellow = core.SpellData[profName][skillName][2]
local orange = core.SpellData[profName][skillName][1]
local chance
if (playerSkill >= gray) then
chance = 0
return chance
else
chance = core:CalcChance(gray, playerSkill, yellow)
end
if (chance >= 1 or yellow == gray) then chance = 1 end
chance = core:Round((chance*100), 1)
return chance
end
end
-- For some reason, the skill header "other" is sometimes not recognised as a header, and causes a bug if not accounted for
function core:SkillIsOther(skillName, skillType)
if (skillName == 'Other' or skillType == 'Other') then
return 1
else
return 0
end
end
-- Find out if skill is a header
function core:SkillIsHeader(skillName, skillType)
if (skillName == 'header' or skillType == 'header') then
return 1
else
return 0
end
end
-- For updating profession information
function core:UpdateTradeSkill(i, profName)
local skillButton = _G['TradeSkillSkill'..i]
local skillIndex = skillButton:GetID()
local skillName, skillType, numAv, _, _, _ = GetTradeSkillInfo(skillIndex)
local playerSkill = core:GetProfessionLevel()
local chance
local isHeader = core:SkillIsHeader(skillName, skillType)
local isOther = core:SkillIsOther(skillName, skillType)
if (isHeader ~= 0 or isOther ~= 0 or not skillName) then
return
end
if (skillButton:IsShown()) then
chance = core:GetChance(skillName, profName, playerSkill)
if (chance > 0) then
if (numAv == 0) then
skillButton:SetText(" "..skillName.." ("..chance.."%)")
else
skillButton:SetText(" "..skillName.." ["..numAv.."] ("..chance.."%)")
end
return
end
end
end
-- For updating craft information (Enchanting)
function core:UpdateCraftSkill(i, profName)
--[[ Enchanting is the only profession that I am aware of that uses the craft API, but
-- I am not taking any chances. ]]--
if (profName ~= "Enchanting") then
return
end
local craftButton = _G['Craft'..i]
local craftIndex = craftButton:GetID()
local craftBtnSubText = _G['Craft'..i..'SubText']
local craftBtnText = _G['Craft'..i..'Text']
local craftName, craftSubName, craftType, numAv, _, _, _ = GetCraftInfo(craftIndex)
local craftLevel = select(2, GetCraftDisplaySkillLine())
local chance
local isHeader = core:SkillIsHeader(craftName, craftType)
local isOther = core:SkillIsOther(craftName, craftType)
if (isHeader ~= 0 or isOther ~= 0 or not craftName) then
return
end
if (craftButton:IsShown()) then
chance = core:GetChance(craftName, profName, craftLevel)
if (chance > 0) then
if (numAv == 0) then
craftButton:SetText(" "..craftName.." ("..chance.."%)")
else
craftButton:SetText(" "..craftName.." ["..numAv.."] ("..chance.."%)")
end
return
end
end
end