This repository has been archived by the owner on Apr 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TownsfolkUtil.lua
183 lines (161 loc) · 5.23 KB
/
TownsfolkUtil.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
local L = LibStub("AceLocale-3.0"):GetLocale("TownsfolkTracker")
-- Lua APIs
local pairs, table = pairs, table
-- WoW APIs
local UnitLevel, UnitGUID = UnitLevel, UnitGUID
local GetPlayerInfoByGUID = GetPlayerInfoByGUID
function TownsfolkUtil_GetPlayerLevel()
return UnitLevel("player");
end
function TownsfolkUtil_GetPlayerClass()
local playerGUID = UnitGUID("player");
local _, englishClass = GetPlayerInfoByGUID(playerGUID);
return englishClass;
end
function TownsfolkUtil_GetPlayerFaction()
local englishFaction = UnitFactionGroup("player");
return englishFaction;
end
function TownsfolkUtil_GetPlayerDungeonRecommendation(playerLevel, lowLevelBound, highLevelBound)
if (playerLevel < lowLevelBound) then
return 4
end
if (playerLevel > highLevelBound) then
return 0
end
local levelRange = highLevelBound - lowLevelBound
local modifiedLevel = playerLevel - lowLevelBound
local levelGroup = modifiedLevel / levelRange
if (levelGroup > 0.66) then
return 1
end
if (levelGroup > 0.33) then
return 2
end
return 3
end
function TownsfolkUtil_DungeonAttunement(attunement, alwaysShow)
local r, g, b = 1, 0, 0
if (attunement.item) then
local count = GetItemCount(attunement.item, false, false)
if (count == 0 or alwaysShow) then
if (count > 0) then
g, b = 1, 1
end
GameTooltip:AddLine(format(" " .. L["Requires %s"], L[attunement.name]), r, g, b)
end
end
if (attunement.quest) then
local complete = false
if (type(attunement.quest) == "number") then
complete = IsQuestComplete(attunement.quest)
else
for questId in pairs(attunement.quest) do
if (not complete) then
complete = IsQuestComplete(questId)
end
end
end
if (not complete or alwaysShow) then
if (complete) then
g, b = 1, 1
end
GameTooltip:AddLine(format(" " .. L["Complete %s"], L[attunement.name]), r, g, b)
end
end
end
function TownsfolkUtil_IsInstanceType(folktype)
return folktype == TF_DUNGEON or folktype == TF_RAID
end
function TownsfolkUtil_IsTrainerType(folktype)
return folktype == TF_PROFESSION_TRAINER or folktype == TF_CLASS_TRAINER
end
function TownsfolkUtil_PairsByKeys(t, f)
local a = {}
for n in pairs(t) do table.insert(a, n) end
table.sort(a, f)
local i = 0 -- iterator variable
local iter = function() -- iterator function
i = i + 1
if a[i] == nil then return nil
else return a[i], t[a[i]]
end
end
return iter
end
function TownsfolkUtil_GetTrainerTitle(trainerType)
if (trainerType == TF_CLASS.DRUID) then
return "Druid Trainer"
elseif (trainerType == TF_CLASS.DRUID) then
return "Druid Trainer"
elseif (trainerType == TF_CLASS.HUNTER) then
return "Hunter Trainer"
elseif (trainerType == TF_CLASS.MAGE) then
return "Mage Trainer"
elseif (trainerType == TF_CLASS.PALADIN) then
return "Paladin Trainer"
elseif (trainerType == TF_CLASS.PRIEST) then
return "Priest Trainer"
elseif (trainerType == TF_CLASS.ROGUE) then
return "Rogue Trainer"
elseif (trainerType == TF_CLASS.SHAMAN) then
return "Shaman Trainer"
elseif (trainerType == TF_CLASS.WARLOCK) then
return "Warlock Trainer"
elseif (trainerType == TF_CLASS.WARRIOR) then
return "Warrior Trainer"
elseif (trainerType == TF_PROFESSION.WEAPON) then
return "Weapon Master"
elseif (trainerType == TF_PROFESSION.RIDING) then
return "Riding Instructor"
else
return trainerType .. " Trainer"
end
end
function TownsfolkUtil_GetTrainerTag(trainerType, expertise, branch)
local profession
-- profession
if (trainerType == TF_PROFESSION.TAILORING) then
profession = "Tailor"
elseif (trainerType == TF_PROFESSION.LEATHERWORKING) then
profession = "Leatherworker"
elseif (trainerType == TF_PROFESSION.BLACKSMITHING) then
profession = "Blacksmith"
elseif (trainerType == TF_PROFESSION.ALCHEMY) then
profession = "Alchemist"
elseif (trainerType == TF_PROFESSION.ENGINEERING) then
profession = "Engineer"
elseif (trainerType == TF_PROFESSION.ENCHANTING) then
profession = "Enchanter"
else
profession = trainerType
end
if (branch == TF_PROFESSION_BRANCH.ARMORSMITH or branch == TF_PROFESSION_BRANCH.WEAPONSMITH) then
return branch
end
if (branch) then
return expertise .. " " .. branch .. " " .. profession
else
return expertise .. " " .. profession
end
end
function TownsfolkUtil_MenuLabel(label)
local info = Lib_UIDropDownMenu_CreateInfo()
info.text, info.notCheckable, info.isTitle = label, true, true
return info
end
function TownsfolkUtil_ContainsValue(table, value)
for _, val in pairs(table) do
if (val == value) then
return true
end
end
return false
end
function TownsfolkUtil_CopyTable(table)
local newTable = {}
for key, val in pairs(table) do
newTable[key] = val
end
return newTable
end