-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
306 lines (260 loc) · 10.4 KB
/
main.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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
LevelingFramework = {}
LevelingFramework.scriptName = "LevelingFramework"
LevelingFramework.initialConfig = require("custom.LevelingFramework.initialConfig")
local vanillaData = require("custom.LevelingFramework.vanillaData")
LevelingFramework.data = DataManager.loadData(
LevelingFramework.scriptName,
vanillaData
)
LevelingFramework.config = DataManager.loadConfiguration(
LevelingFramework.scriptName,
LevelingFramework.initialConfig.values,
LevelingFramework.initialConfig.keyOrder
)
tableHelper.fixNumericalKeys(LevelingFramework.config)
LevelingFramework.cachedClasses = {}
-- Constants
LevelingFramework.SPECIALIZATION_COMBAT = 0
LevelingFramework.SPECIALIZATION_MAGIC = 1
LevelingFramework.SPECIALIZATION_STEALTH = 2
-- Utility
function splitString(str, pattern)
local r = {}
for i in string.gmatch(str, pattern) do
table.insert(r, i)
end
return r
end
local splitPattern = "[^%s%p]+"
-- Methods
function LevelingFramework.importESPs()
if espParser == nil then
return
end
-- Load esp files if necessary
local loaded = espParser.isLoaded()
if not loaded then
espParser.loadFiles()
end
-- Parse skills
LevelingFramework.data.skills = {}
for _, record in pairs(espParser.getAllRecords("SKIL")) do
local skill = {}
local skillName = ""
for _, subRecord in pairs(record.subRecords) do
local data = subRecord.data
if data ~= nil then
if subRecord.name == "INDX" then
skillName = tes3mp.GetSkillName(espParser.getValue(data, "I", 1))
elseif subRecord.name == "SKDT" then
skill.attribute = tes3mp.GetAttributeName(espParser.getValue(data, "I", 1))
skill.specialization = espParser.getValue(data, "I", 5)
end
end
end
LevelingFramework.data.skills[skillName] = skill
end
-- Parse classes
LevelingFramework.data.classes = {}
for _, record in pairs(espParser.getAllRecords("CLAS")) do
local class = {}
local className = ""
for _, subRecord in pairs(record.subRecords) do
local data = subRecord.data
if subRecord.name == "NAME" then
className = espParser.getValue(data, "s", 1):lower()
elseif subRecord.name == "CLDT" then
class.majorAttributes = {
tes3mp.GetAttributeName(espParser.getValue(data, "I", 1)),
tes3mp.GetAttributeName(espParser.getValue(data, "I", 5)),
}
class.specialization = espParser.getValue(data, "I", 9)
class.minorSkills = {}
for i = 13, 46, 8 do
table.insert(
class.minorSkills,
tes3mp.GetSkillName(
espParser.getValue(data, "I", i)
)
)
end
class.majorSkills = {}
for i = 17, 50, 8 do
table.insert(
class.majorSkills,
tes3mp.GetSkillName(
espParser.getValue(data, "I", i)
)
)
end
end
end
LevelingFramework.data.classes[className] = class
end
-- Clean after if expected
if not loaded then
espParser.unloadFiles()
end
-- Save freshly loaded classes
DataManager.saveData(LevelingFramework.scriptName, LevelingFramework.data)
end
function LevelingFramework.getSkill(skillName)
return LevelingFramework.data.skills[skillName]
end
function LevelingFramework.getClass(pid)
local accountName = Players[pid].accountName
if LevelingFramework.cachedClasses[accountName] ~= nil then
return LevelingFramework.cachedClasses[accountName]
end
local player = Players[pid]
local className = player.data.character.class
if className == "custom" then
local class = player.data.customClass
local niceClass = {}
niceClass.majorAttributes = splitString(class.majorAttributes, splitPattern)
niceClass.majorSkills = splitString(class.majorSkills, splitPattern)
niceClass.minorSkills = splitString(class.minorSkills, splitPattern)
niceClass.specialization = class.specialization
niceClass.name = class.name
niceClass.description = class.description
LevelingFramework.cachedClasses[accountName] = niceClass
return niceClass
else
return LevelingFramework.data.classes[className]
end
end
function LevelingFramework.isMajorSkill(class, skillName)
return tableHelper.containsValue(class.majorSkills, skillName)
end
function LevelingFramework.isMinorSkill(class, skillName)
return tableHelper.containsValue(class.minorSkills, skillName)
end
function LevelingFramework.isSpecialized(class, skillName)
return class.specialization == LevelingFramework.getSkill(skillName).specialization
end
function LevelingFramework.progressLevel(pid, skillName, value)
local class = LevelingFramework.getClass(pid)
local progressLevel = value
local progressAttribute = value
if LevelingFramework.isMajorSkill(class, skillName) then
progressLevel = progressLevel * LevelingFramework.config.iLevelUpMajorMult
progressAttribute = progressAttribute * LevelingFramework.config.iLevelUpMajorMultAttribute
elseif LevelingFramework.isMinorSkill(class, skillName) then
progressLevel = progressLevel * LevelingFramework.config.iLevelUpMinorMult
progressAttribute = progressAttribute * LevelingFramework.config.iLevelUpMinorMultAttribute
else
progressLevel = 0
progressAttribute = progressAttribute * LevelingFramework.config.iLevelupMiscMultAttriubte
end
progressLevel = math.floor(progressLevel)
progressAttribute = math.floor(progressAttribute)
local player = Players[pid]
local skill = LevelingFramework.getSkill(skillName)
local attribute = player.data.attributes[skill.attribute]
attribute.skillIncrease = attribute.skillIncrease + progressAttribute
player.data.stats.levelProgress = player.data.stats.levelProgress + progressLevel
end
function LevelingFramework.skillProgressRequirement(pid, skillName)
local class = LevelingFramework.getClass(pid)
local skillLevel = Players[pid].data.skills[skillName].base
local requirement = 1 + skillLevel
if LevelingFramework.isMajorSkill(class, skillName) then
requirement = requirement * LevelingFramework.config.fMajorSkillBonus
elseif LevelingFramework.isMinorSkill(class, skillName) then
requirement = requirement * LevelingFramework.config.fMinorSkillBonus
else
requirement = requirement * LevelingFramework.config.fMiscSkillBonus
end
if LevelingFramework.isSpecialized(class, skillName) then
requirement = requirement * LevelingFramework.config.fSpecialSkillBonus
end
return math.floor(requirement)
end
function LevelingFramework.increaseSkill(pid, skillName, value, keepProgress)
local arguments = {
skillName = skillName,
value = value,
keepProgress = keepProgress
}
local eventStatus = customEventHooks.triggerValidators(
"LevelingFramework_OnSkillIncrease",
{pid, arguments}
)
if eventStatus.validDefaultHandler then
local oldReq, newReq
local skill = Players[pid].data.skills[arguments.skillName]
if arguments.keepProgress then
oldReq = LevelingFramework.skillProgressRequirement(pid, arguments.skillName)
end
skill.base = skill.base + arguments.value
if arguments.keepProgress then
newReq = LevelingFramework.skillProgressRequirement(pid, arguments.skillName)
skill.progress = skill.progress * newReq / oldReq
else
skill.progress = 0
end
LevelingFramework.progressLevel(pid, arguments.skillName, arguments.value)
end
customEventHooks.triggerHandlers(
"LevelingFramework_OnSkillIncrease",
eventStatus,
{pid, arguments}
)
end
function LevelingFramework.progressSkill(pid, skillName, progress, count)
count = count or 1
local skill = Players[pid].data.skills[skillName]
local progressCurrent = skill.progress
local skillIncrease = 0
while count > 0 do
local progressRequirement = LevelingFramework.skillProgressRequirement(pid, skillName)
local countToLevel = math.ceil( (progressRequirement - progressCurrent) / progress )
if countToLevel > count then
skill.progress = progressCurrent + progress * count
count = 0
else
skillIncrease = skillIncrease + 1
progressCurrent = 0
count = count - countToLevel
end
end
if skillIncrease > 0 then
LevelingFramework.increaseSkill(pid, skillName, skillIncrease)
end
end
-- Hooks
customEventHooks.registerHandler("OnServerPostInit", function()
if LevelingFramework.config.importESPs then
LevelingFramework.importESPs()
end
end)
customEventHooks.registerValidator("LevelingFramework_OnSkillIncrease", function(eventStatus, pid, arguments)
local skill = Players[pid].data.skills[arguments.skillName]
if skill.base + arguments.value > LevelingFramework.config.skillCap then
arguments.value = LevelingFramework.config.skillCap - skill.base
end
end)
customEventHooks.registerHandler("LevelingFramework_OnSkillIncrease", function(eventStatus, pid, arguments)
local skill = Players[pid].data.skills[arguments.skillName]
if skill.base == LevelingFramework.config.skillCap then
skill.progress = 0
end
if arguments.value > 0 and LevelingFramework.config.message.enabled then
tes3mp.MessageBox(
pid,
LevelingFramework.config.message.id,
string.format(
LevelingFramework.config.message.text,
LevelingFramework.config.skillNames[arguments.skillName],
skill.base
)
)
tes3mp.PlaySpeech(pid, LevelingFramework.config.message.sound)
end
end)
customCommandHooks.registerCommand("lfimportesps", function(pid, cmd)
LevelingFramework.importESPs()
tes3mp.SendMessage(pid, "Imported ESPs!")
end)
customCommandHooks.setRankRequirment("lfimportesps", LevelingFramework.config.cmdRank)
return LevelingFramework