-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
executable file
·215 lines (183 loc) · 7.14 KB
/
main.lua
File metadata and controls
executable file
·215 lines (183 loc) · 7.14 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
--------------------------------------- RepCheck ---------------------------------------
-------------------------- The one stop shop to Check yo' ReP --------------------------
-- This file holds the core functions of RepCheck
-- Current Function of the Addon, you ask?!
-- Upon login you will be greeted by a nice "Hello World!"
-- If you type '/RepCheck' you will see all the factions in your current zone
-- When you character increased their rep with any faction
-- You will be shown your completed percent with that faction
-- And see a progress bar. ex:
-- RepCheck: Reputation with Netherwing is 80% to Exalted
-- RepCheck: ████████████████░░░░
-----------------------------------------------------------------------------------------
-- core is the root of the addon. Everything will come off of core.
-- any added function, databases, etc.. will stem off of core
core = LibStub("AceAddon-3.0"):NewAddon("RepCheck", "AceConsole-3.0", "AceEvent-3.0")
-- LibStub is what you will use to manage your addon
----- makes for easy versioning
----- manages libraries
-- console will allow you to print data in the chat screen
-- good for error logging and debugging
-- using console will print in this format:
-- console.Print("Hello world from console")
-- 'Hello world from console:'
-- vs.
-- core also has it's own Print
-- good for addon announcements/general info
-- core.Print will print in this format:
-- corePrint("Hello world from core")
-- 'RepCheck: "Hello world from core"'
-- NOTE: to print values in a table
-- for f in pairs(faction) do print(faction[f]) end
-- to print values in an array use ipairs
console = LibStub("AceConsole-3.0")
core:RegisterChatCommand("RepCheck", "RepCheckSlashProcessorFunc")
core.factions = {}
core.quests = {}
-- Code that you want to run when the addon is first loaded
function core:OnInitialize()
core:customPrint("Hello, world! Thanks for installing RepCheck!")
core:RegisterEvent("CHAT_MSG_COMBAT_FACTION_CHANGE", core.onFactionIncrease)
-- core.db = LibStub("AceDB-3.0"):New("RepCheckDB", core.defaults, true)
core:RegisterEvent("PLAYER_ENTERING_WORLD")
end
function core:PLAYER_ENTERING_WORLD()
core:UnregisterEvent("PLAYER_ENTERING_WORLD")
core.factions = core:getAllFactions()
-- core.quests = core:getQuestsInGossipRange()
end
function core:getAllFactions()
local factions = {}
-- GetNumFactions returns the number of avaliable factions
-- While i is less then the value GetNumFaction() returns
-- We will GetFactionInfo(index) for each faction
-- We extract that from the function
-- Then apply it to our new faction
-- Then add that faction into our factions
for i = 1, GetNumFactions() do
local name, -- name of the faction
_,
standingId, -- get the status name (Revered, Exalted)
barMin, -- this value refers to the starting point of the reputation status
barMax, -- this is the value to get you to the next reputation status
barValue, -- the total amount of points you hav for this faction
_, _,
isHeader, -- a header is a category such as: Horde, Burning Crusades, etc...
_, _, _, _,
factionId, -- id specific to the faction
_, _ = GetFactionInfo(i)
if not isHeader and factionId ~= nil then
if barValue == nil then
barValue = 0
end
local nextStatusId = standingId + 1
if nextStatusId > MAX_REPUTATION_REACTION then
nextStatusId = MAX_REPUTATION_REACTION
end
local statusName = _G["FACTION_STANDING_LABEL" .. standingId]
local nextStatusName = _G["FACTION_STANDING_LABEL" .. nextStatusId]
-- gets the current amount of points you have at this reputation status
local currentValue = barValue - barMin
-- gets the percent completed and rounds it to the nearest full number
local percentCompleted = math.ceil((currentValue / (barMax - barMin)) * 100)
-- checks if the percent is nan
-- if it is the reputation is at Exalted so set it to max
if tostring(percentCompleted) == "nan" then
percentCompleted = 100
nextStatusName = MAX_REPUTATION_COMPLETED
end
local faction = {
factionId = factionId,
index = i,
name = name,
barMax = barMax,
barMin = barMin,
barValue = barValue,
percentCompleted = percentCompleted,
currentValue = currentValue,
statusName = statusName,
nextStatusName = nextStatusName
}
factions[name] = faction
end
end
return factions
end
function core:onFactionIncrease(a, b)
if FACTION_STANDING_INCREASED ~= nil then
pattern = string.gsub(string.gsub(FACTION_STANDING_INCREASED, "(%%s)", "(.+)"), "(%%d)", "(.+)")
_, _, name, increase = string.find(a, pattern)
end
if FACTION_STANDING_DECREASED ~= nil then
pattern = string.gsub(string.gsub(FACTION_STANDING_INCREASED, "(%%s)", "(.+)"), "(%%d)", "(.+)")
_, _, name, increase = string.find(a, pattern)
end
if name ~= nil then
faction = core.factions[name]
progressBar = core:formatProgressBar(faction.percentCompleted)
repMessage =
string.format(
REPUTATION_GAINED_MESSAGE,
faction.name,
faction.percentCompleted,
faction.nextStatusName
)
core:customPrint(repMessage)
core:customPrint(progressBar)
end
end
function core:formatProgressBar(percent)
local completedBar = "" .. LIGHT_GREEN
local uncompletedBar = "" .. SUB_WHITE
for i = 1, 19 do
if i < (percent / 5) then
completedBar = completedBar .. COMPLETED_BLOCK_CHAR
else
uncompletedBar = uncompletedBar .. UNCOMPLETED_BLOCK_CHAR
end
end
return completedBar .. uncompletedBar
end
-- Use this print function to purposefully show data in the console
-- This will always ensure that 'RepCheck:' will be prepended
function core:customPrint(msg)
core.Print(REP_CHECK, msg)
end
--------------------------------- This section deals with anything quest related ---------------------------------
function core:getQuestsInGossipRange()
console.Print("in getQuestInGossipRange")
numberOfQuests = GetNumGossipAvailableQuests()
console.Print("numberOfQuests", numberOfQuests)
if numberOfQuests == nil then
core:customPrint(NO_QUESTS_FOUND)
end
for i = 1, numberOfQuests do
quest = SelectGossipAvailableQuest(i)
core:customPrint("quest", quest)
end
end
---------------------- Code that will run when you type in '/RepCheck' in your chat terminal ---------------------
function core:RepCheckSlashProcessorFunc()
-- returns to name of the instance or zone
zoneName = GetRealZoneText()
if zoneName == nil then
return core:customPrint(ZONE_ERROR)
end
factions = zonesFactions[zoneName]
if factions == nil then
return core:customPrint(FACTIONS_NOT_FOUND)
end
for i in pairs(factions) do
faction = core.factions[factions[i]]
if faction == nil then
return core:customPrint(FACTIONS_NOT_FOUND)
end
percent = faction.percentCompleted
if percent == nil then
return core:customPrint("percent is nil")
end
progressBar = core:formatProgressBar(faction.percentCompleted)
core:customPrint(faction.name)
return core:customPrint(progressBar)
end
end