-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathbase.lua
More file actions
1815 lines (1405 loc) · 58.4 KB
/
base.lua
File metadata and controls
1815 lines (1405 loc) · 58.4 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
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
require("config")
require("patterns")
stateHelper = require("stateHelper")
tableHelper = require("tableHelper")
local BasePlayer = class("BasePlayer")
function BasePlayer:__init(pid, playerName)
self.dbPid = nil
self.data =
{
login = {
name = "",
passwordSalt = "",
passwordHash = ""
},
timestamps = {
creation = os.time(),
lastLogin = os.time(),
lastDisconnect = 0,
lastFixMe = 0,
lastSessionDuration = 0
},
settings = {
staffRank = 0,
difficulty = "default",
consoleAllowed = "default",
bedRestAllowed = "default",
wildernessRestAllowed = "default",
waitAllowed = "default",
enforcedLogLevel = "default",
physicsFramerate = "default"
},
character = {
race = "",
head = "",
hair = "",
gender = 1,
class = "",
birthsign = ""
},
location = {
cell = "",
regionName = "",
posX = 0,
posY = 0,
posZ = 0,
rotX = 0,
rotZ = 0
},
stats = {
level = 1,
levelProgress = 0,
healthBase = 1,
healthCurrent = 1,
magickaBase = 1,
magickaCurrent = 1,
fatigueBase = 1,
fatigueCurrent = 1
},
fame = {
bounty = 0,
reputation = 0
},
miscellaneous = {
markLocation = {
cell = "",
posX = 0,
posY = 0,
posZ = 0,
rotX = 0,
rotZ = 0
},
selectedSpell = ""
},
customClass = {},
attributes = {},
skills = {},
equipment = {},
inventory = {},
spellbook = {},
spellsActive = {},
cooldowns = {},
quickKeys = {},
shapeshift = {},
journal = {},
factionRanks = {},
factionExpulsion = {},
factionReputation = {},
topics = {},
books = {},
mapExplored = {},
ipAddresses = {},
recordLinks = {},
alliedPlayers = {},
destinationOverrides = {},
customVariables = {}
}
for index = 0, (tes3mp.GetAttributeCount() - 1) do
local attributeName = tes3mp.GetAttributeName(index)
self.data.attributes[attributeName] = {
base = 1,
damage = 0,
skillIncrease = 0
}
end
for index = 0, (tes3mp.GetSkillCount() - 1) do
local skillName = tes3mp.GetSkillName(index)
self.data.skills[skillName] = {
base = 1,
damage = 0,
progress = 0
}
end
if playerName == nil then
self.accountName = tes3mp.GetName(pid)
else
self.accountName = playerName
end
self.pid = pid
self.loggedIn = false
self.isNewlyRegistered = false
self.loginTimerId = nil
self.hasAccount = nil
self.cellsLoaded = {}
self.summons = {}
self.generatedRecordsReceived = {}
self.unresolvedEnchantments = {}
self.previousEquipment = {}
self.consoleCommandsQueued = {}
self.hasFinishedInitialTeleportation = false
end
function BasePlayer:Destroy()
if self.loginTimerId ~= nil then
tes3mp.StopTimer(self.loginTimerId)
self.loginTimerId = nil
end
self.loggedIn = false
self.hasAccount = nil
end
function BasePlayer:Kick()
self:Destroy()
tes3mp.Kick(self.pid)
end
function BasePlayer:GenerateSaltedHash(inputString)
self.data.login.passwordSalt = tes3mp.GenerateRandomString(64)
self.data.login.passwordHash = tes3mp.GetSHA256Hash(inputString .. self.data.login.passwordSalt)
end
-- Replace any plaintext passwords with an unpredictable serverside
-- salted hash of a predictable clientside salted hash
function BasePlayer:ConvertPlaintextPassword()
local inputHash = tes3mp.GetSHA256Hash(self.data.login.password)
inputHash = tes3mp.GetSHA256Hash(inputHash .. tes3mp.GetSHA256Hash(tes3mp.GetSHA256Hash(inputHash)))
self:GenerateSaltedHash(inputHash)
self.data.login.password = nil
end
function BasePlayer:Register(clientPasswordHash)
self.loggedIn = true
self.isNewlyRegistered = true
self:GenerateSaltedHash(clientPasswordHash)
self.data.settings.consoleAllowed = "default"
if not self.hasAccount then
tes3mp.SetCharGenStage(self.pid, 1, 4)
end
end
function BasePlayer:FinishLogin()
if self.hasAccount then
self:SaveIpAddress()
if self.data.timestamps == nil then
self.data.timestamps = {
creation = os.time(),
lastDisconnect = 0,
lastFixMe = 0,
lastSessionDuration = 0
}
end
self.data.timestamps.lastLogin = os.time()
self:LoadSettings()
self:LoadCharacter()
self:LoadClass()
self:LoadLevel()
self:LoadAttributes()
self:LoadSkills()
self:LoadStatsDynamic()
WorldInstance:LoadTime(self.pid, false)
WorldInstance:LoadWeather(self.pid, false)
if self.data.recordLinks == nil then self.data.recordLinks = {} end
-- Load high priority records linked to us, then load lower priority permanent
-- records and lower priority records linked to this player
for priorityLevel, recordStoreTypes in ipairs(config.recordStoreLoadOrder) do
for _, storeType in ipairs(recordStoreTypes) do
local recordStore = RecordStores[storeType]
if recordStore ~= nil then
-- Skip permanent records from high priority stores here because those
-- were already loaded upon first connecting to the server
if priorityLevel > 1 then
recordStore:LoadRecords(self.pid, recordStore.data.permanentRecords,
tableHelper.getArrayFromIndexes(recordStore.data.permanentRecords))
end
-- Load the generated records linked to us in this record store
if self.data.recordLinks[storeType] ~= nil then
recordStore:LoadGeneratedRecords(self.pid, recordStore.data.generatedRecords,
self.data.recordLinks[storeType])
end
end
end
end
self:CleanInventory()
self:LoadInventory()
self:LoadEquipment()
self:CleanSpellbook()
self:LoadSpellbook()
self:LoadSpellsActive()
self:LoadCooldowns()
self:LoadQuickKeys()
self:LoadBooks()
self:LoadShapeshift()
self:LoadMarkLocation()
self:LoadSelectedSpell()
if config.shareJournal == true then
WorldInstance:LoadJournal(self.pid)
else
self:LoadJournal()
end
if config.shareFactionRanks == true then
WorldInstance:LoadFactionRanks(self.pid)
else
self:LoadFactionRanks()
end
if config.shareFactionExpulsion == true then
WorldInstance:LoadFactionExpulsion(self.pid)
else
self:LoadFactionExpulsion()
end
if config.shareFactionReputation == true then
WorldInstance:LoadFactionReputation(self.pid)
else
self:LoadFactionReputation()
end
if config.shareTopics == true then
WorldInstance:LoadTopics(self.pid)
else
self:LoadTopics()
end
if config.shareBounty == true then
WorldInstance:LoadBounty(self.pid)
else
self:LoadBounty()
end
if config.shareReputation == true then
WorldInstance:LoadReputation(self.pid)
else
self:LoadReputation()
end
if config.shareKills == true then
WorldInstance:LoadKills(self.pid)
else
self:LoadKills(self.pid, false)
end
self:LoadSpecialStates()
if config.shareMapExploration == true then
WorldInstance:LoadMap(self.pid)
else
self:LoadMap()
end
self:LoadClientScriptVariables()
WorldInstance:LoadClientScriptVariables(self.pid)
self:LoadDestinationOverrides()
WorldInstance:LoadDestinationOverrides(self.pid)
self:LoadAllies()
self:LoadCell()
self.loggedIn = true
if self.data.alliedPlayers == nil then self.data.alliedPlayers = {} end
for _, otherAccountName in ipairs(self.data.alliedPlayers) do
if logicHandler.IsPlayerNameLoggedIn(otherAccountName) then
local otherPlayer = logicHandler.GetPlayerByName(otherAccountName)
otherPlayer:LoadAllies()
end
end
self:RunPlayerSpecificStartupScripts()
customEventHooks.triggerHandlers("OnPlayerFinishLogin", customEventHooks.makeEventStatus(true, true), {self.pid})
customEventHooks.triggerHandlers("OnPlayerAuthentified", customEventHooks.makeEventStatus(true, true), {self.pid})
end
end
function BasePlayer:EndCharGen()
self:SaveLogin()
self:SaveCharacter()
self:SaveClass(packetReader.GetPlayerPacketTables(self.pid, "PlayerClass"))
self:SaveStatsDynamic(packetReader.GetPlayerPacketTables(self.pid, "PlayerStatsDynamic"))
self:SaveEquipment(packetReader.GetPlayerPacketTables(self.pid, "PlayerEquipment"))
self:SaveShapeshift(packetReader.GetPlayerPacketTables(self.pid, "PlayerShapeshift"))
self:SaveIpAddress()
self:CreateAccount()
WorldInstance:LoadTime(self.pid, false)
WorldInstance:LoadWeather(self.pid, false, true)
local spawnUsed
if config.useInstancedSpawn == true and config.instancedSpawn ~= nil then
spawnUsed = tableHelper.shallowCopy(config.instancedSpawn)
local originalCellDescription = spawnUsed.cellDescription
spawnUsed.cellDescription = originalCellDescription .. " - Instance for " .. self.name
elseif config.noninstancedSpawn ~= nil then
spawnUsed = config.noninstancedSpawn
end
-- Load lower priority permanent records
for priorityLevel, recordStoreTypes in ipairs(config.recordStoreLoadOrder) do
if priorityLevel > 1 then
for _, storeType in ipairs(recordStoreTypes) do
local recordStore = RecordStores[storeType]
-- Load all the permanent records in this record store
recordStore:LoadRecords(self.pid, recordStore.data.permanentRecords,
tableHelper.getArrayFromIndexes(recordStore.data.permanentRecords))
end
end
end
if config.shareJournal == true then
WorldInstance:LoadJournal(self.pid)
end
if config.shareFactionRanks == true then
WorldInstance:LoadFactionRanks(self.pid)
end
if config.shareFactionExpulsion == true then
WorldInstance:LoadFactionExpulsion(self.pid)
end
if config.shareFactionReputation == true then
WorldInstance:LoadFactionReputation(self.pid)
end
if config.shareTopics == true then
WorldInstance:LoadTopics(self.pid)
end
if config.shareKills == true then
WorldInstance:LoadKills(self.pid)
else
self:LoadKills(self.pid, false)
end
if spawnUsed ~= nil and spawnUsed.cellDescription ~= nil then
tes3mp.SetCell(self.pid, spawnUsed.cellDescription)
tes3mp.SendCell(self.pid)
if spawnUsed.position ~= nil and spawnUsed.rotation ~= nil then
tes3mp.SetPos(self.pid, spawnUsed.position[1], spawnUsed.position[2], spawnUsed.position[3])
tes3mp.SetRot(self.pid, spawnUsed.rotation[1], spawnUsed.rotation[2])
tes3mp.SendPos(self.pid)
end
if spawnUsed.text then
tes3mp.MessageBox(self.pid, -1, spawnUsed.text)
end
if spawnUsed.items then
for _, item in pairs(spawnUsed.items) do
inventoryHelper.addItem(self.data.inventory, item.refId, item.count, item.charge,
item.enchantmentCharge, item.soul)
end
self:LoadItemChanges(spawnUsed.items, enumerations.inventory.ADD)
end
end
self:RunPlayerSpecificStartupScripts()
end
function BasePlayer:IsLoggedIn()
return self.loggedIn
end
function BasePlayer:IsServerStaff()
return self.data.settings.staffRank > 0
end
function BasePlayer:IsServerOwner()
return self.data.settings.staffRank == 3
end
function BasePlayer:IsAdmin()
return self.data.settings.staffRank >= 2
end
function BasePlayer:IsModerator()
return self.data.settings.staffRank >= 1
end
function BasePlayer:AddLinkToRecord(storeType, recordId)
if self.data.recordLinks == nil then self.data.recordLinks = {} end
local recordStore = RecordStores[storeType]
if recordStore ~= nil then
local recordLinks = self.data.recordLinks
if recordLinks[storeType] == nil then recordLinks[storeType] = {} end
if not tableHelper.containsValue(recordLinks[storeType], recordId) then
table.insert(recordLinks[storeType], recordId)
end
recordStore:AddLinkToPlayer(recordId, self)
recordStore:QuicksaveToDrive()
end
end
function BasePlayer:RemoveLinkToRecord(storeType, recordId)
local recordStore = RecordStores[storeType]
if recordStore ~= nil then
local recordLinks = self.data.recordLinks
if recordLinks ~= nil and recordLinks[storeType] ~= nil then
local linkIndex = tableHelper.getIndexByValue(recordLinks[storeType], recordId)
if linkIndex ~= nil then
recordLinks[storeType][linkIndex] = nil
tableHelper.cleanNils(recordLinks[storeType])
end
recordStore:RemoveLinkToPlayer(recordId, self)
recordStore:QuicksaveToDrive()
end
end
end
function BasePlayer:GetHealthCurrent()
self.data.stats.healthCurrent = tes3mp.GetHealthCurrent(self.pid)
return self.data.stats.healthCurrent
end
function BasePlayer:SetHealthCurrent(health)
self.data.stats.healthCurrent = health
tes3mp.SetHealthCurrent(self.pid, health)
end
function BasePlayer:GetHealthBase()
self.data.stats.healthBase = tes3mp.GetHealthBase(self.pid)
return self.data.stats.healthBase
end
function BasePlayer:SetHealthBase(health)
self.data.stats.healthBase = health
tes3mp.SetHealthBase(self.pid, health)
end
function BasePlayer:HasAccount()
return self.hasAccount
end
function BasePlayer:Message(message)
tes3mp.SendMessage(self.pid, message, false)
end
function BasePlayer:CreateAccount()
error("Not implemented")
end
function BasePlayer:SaveToDrive()
error("Not implemented")
end
function BasePlayer:LoadFromDrive()
error("Not implemented")
end
function BasePlayer:SaveLogin()
self.data.login.name = tes3mp.GetName(self.pid)
end
function BasePlayer:SaveIpAddress()
if self.data.ipAddresses == nil then
self.data.ipAddresses = {}
end
local ipAddress = tes3mp.GetIP(self.pid)
if not tableHelper.containsValue(self.data.ipAddresses, ipAddress) then
table.insert(self.data.ipAddresses, ipAddress)
end
end
function BasePlayer:ProcessDeath()
-- Clear this player's active spell effects
self.data.spellsActive = {}
local deathReason = "committed suicide"
if tes3mp.DoesPlayerHavePlayerKiller(self.pid) then
local killerPid = tes3mp.GetPlayerKillerPid(self.pid)
if self.pid ~= killerPid then
deathReason = "was killed by player " .. logicHandler.GetChatName(killerPid)
end
else
local killerName = tes3mp.GetPlayerKillerName(self.pid)
if killerName ~= "" then
deathReason = "was killed by " .. killerName
end
end
local message = logicHandler.GetChatName(self.pid) .. " " .. deathReason .. ".\n"
tes3mp.SendMessage(self.pid, message, true)
if config.playersRespawn then
self.resurrectTimerId = tes3mp.CreateTimerEx("OnDeathTimeExpiration",
time.seconds(config.deathTime), "is", self.pid, self.accountName)
tes3mp.StartTimer(self.resurrectTimerId)
else
tes3mp.SendMessage(self.pid, "You have died permanently.", false)
end
end
function BasePlayer:Resurrect()
local currentResurrectType = enumerations.resurrect.REGULAR
if config.respawnAtImperialShrine == true then
if config.respawnAtTribunalTemple == true then
if math.random() > 0.5 then
currentResurrectType = enumerations.resurrect.IMPERIAL_SHRINE
else
currentResurrectType = enumerations.resurrect.TRIBUNAL_TEMPLE
end
else
currentResurrectType = enumerations.resurrect.IMPERIAL_SHRINE
end
elseif config.respawnAtTribunalTemple == true then
currentResurrectType = enumerations.resurrect.TRIBUNAL_TEMPLE
elseif config.defaultRespawn ~= nil and config.defaultRespawn.cellDescription ~= nil then
currentResurrectType = enumerations.resurrect.REGULAR
tes3mp.SetCell(self.pid, config.defaultRespawn.cellDescription)
tes3mp.SendCell(self.pid)
if config.defaultRespawn.position ~= nil and config.defaultRespawn.rotation ~= nil then
tes3mp.SetPos(self.pid, config.defaultRespawn.position[1],
config.defaultRespawn.position[2], config.defaultRespawn.position[3])
tes3mp.SetRot(self.pid, config.defaultRespawn.rotation[1], config.defaultRespawn.rotation[2])
tes3mp.SendPos(self.pid)
end
end
local message = "You have been revived"
if currentResurrectType == enumerations.resurrect.IMPERIAL_SHRINE then
message = message .. " at the nearest Imperial shrine"
elseif currentResurrectType == enumerations.resurrect.TRIBUNAL_TEMPLE then
message = message .. " at the nearest Tribunal temple"
end
message = message .. ".\n"
-- Ensure that dying as a werewolf turns you back into your normal form
if self.data.shapeshift.isWerewolf == true then
self:SetWerewolfState(false)
end
-- Ensure that we unequip deadly items when applicable, to prevent an
-- infinite death loop
contentFixer.UnequipDeadlyItems(self.pid)
tes3mp.Resurrect(self.pid, currentResurrectType)
if config.deathPenaltyJailDays > 0 or config.bountyDeathPenalty then
local jailTime = 0
local resurrectionText = "You've been revived and brought back here, " ..
"but your skills have been affected by "
if config.bountyDeathPenalty then
local currentBounty = tes3mp.GetBounty(self.pid)
if currentBounty > 0 then
jailTime = jailTime + math.floor(currentBounty / 100)
resurrectionText = resurrectionText .. "your bounty"
end
end
if config.deathPenaltyJailDays > 0 then
if jailTime > 0 then
resurrectionText = resurrectionText .. " and "
end
jailTime = jailTime + config.deathPenaltyJailDays
resurrectionText = resurrectionText .. "your time spent incapacitated"
end
resurrectionText = resurrectionText .. ".\n"
tes3mp.Jail(self.pid, jailTime, true, true, "Recovering", resurrectionText)
end
if config.bountyResetOnDeath then
tes3mp.SetBounty(self.pid, 0)
tes3mp.SendBounty(self.pid)
self:SaveBounty()
end
tes3mp.SendMessage(self.pid, message, false)
end
function BasePlayer:DeleteSummons()
if self.summons ~= nil then
for summonUniqueIndex, summonRefId in pairs(self.summons) do
tes3mp.LogAppend(enumerations.log.INFO, "- removing player's summon " .. summonUniqueIndex ..
", refId " .. summonRefId)
local cell = logicHandler.GetCellContainingActor(summonUniqueIndex)
if cell ~= nil then
cell:DeleteObjectData(summonUniqueIndex)
logicHandler.DeleteObjectForEveryone(cell.description, summonUniqueIndex)
end
end
end
end
function BasePlayer:SaveDataByPacketType(packetType, playerPacket)
if packetType == "PlayerAttribute" then
self:SaveAttributes(playerPacket)
elseif packetType == "PlayerSkill" then
self:SaveSkills(playerPacket)
elseif packetType == "PlayerLevel" then
self:SaveLevel(playerPacket)
elseif packetType == "PlayerShapeshift" then
self:SaveShapeshift(playerPacket)
elseif packetType == "PlayerEquipment" then
self:SaveEquipment(playerPacket)
elseif packetType == "PlayerInventory" then
self:SaveInventory(playerPacket)
elseif packetType == "PlayerSpellbook" then
self:SaveSpellbook(playerPacket)
elseif packetType == "PlayerCooldowns" then
self:SaveCooldowns(playerPacket)
elseif packetType == "PlayerQuickKeys" then
self:SaveQuickKeys(playerPacket)
end
end
function BasePlayer:LoadCharacter()
tes3mp.SetRace(self.pid, self.data.character.race)
tes3mp.SetHead(self.pid, self.data.character.head)
tes3mp.SetHair(self.pid, self.data.character.hair)
tes3mp.SetIsMale(self.pid, self.data.character.gender)
if self.data.character.modelOverride ~= nil then
tes3mp.SetModel(self.pid, self.data.character.modelOverride)
end
tes3mp.SetBirthsign(self.pid, self.data.character.birthsign)
tes3mp.SendBaseInfo(self.pid)
end
function BasePlayer:SaveCharacter()
self.data.character.race = tes3mp.GetRace(self.pid)
self.data.character.head = tes3mp.GetHead(self.pid)
self.data.character.hair = tes3mp.GetHair(self.pid)
self.data.character.gender = tes3mp.GetIsMale(self.pid)
self.data.character.modelOverride = tes3mp.GetModel(self.pid)
self.data.character.birthsign = tes3mp.GetBirthsign(self.pid)
end
function BasePlayer:LoadClass()
if self.data.character.class ~= "custom" then
tes3mp.SetDefaultClass(self.pid, self.data.character.class)
elseif self.data.customClass ~= nil then
tes3mp.SetClassName(self.pid, self.data.customClass.name)
tes3mp.SetClassSpecialization(self.pid, self.data.customClass.specialization)
if self.data.customClass.description ~= nil then
tes3mp.SetClassDesc(self.pid, self.data.customClass.description)
end
local index = 0
for value in string.gmatch(self.data.customClass.majorAttributes, patterns.commaSplit) do
tes3mp.SetClassMajorAttribute(self.pid, index, tes3mp.GetAttributeId(value))
index = index + 1
end
index = 0
for value in string.gmatch(self.data.customClass.majorSkills, patterns.commaSplit) do
tes3mp.SetClassMajorSkill(self.pid, index, tes3mp.GetSkillId(value))
index = index + 1
end
index = 0
for value in string.gmatch(self.data.customClass.minorSkills, patterns.commaSplit) do
tes3mp.SetClassMinorSkill(self.pid, index, tes3mp.GetSkillId(value))
index = index + 1
end
end
tes3mp.SendClass(self.pid)
end
function BasePlayer:SaveClass(playerPacket)
self.data.character.class = playerPacket.character.class
if playerPacket.character.defaultClassState == 0 then
for key, value in pairs(playerPacket.customClass) do
self.data.customClass[key] = tableHelper.deepCopy(playerPacket.customClass[key])
end
end
end
function BasePlayer:LoadStatsDynamic()
local healthBase
if tes3mp.IsWerewolf(self.pid) then
healthBase = self.data.shapeshift.werewolfHealthBase
else
healthBase = self.data.stats.healthBase
end
tes3mp.SetHealthBase(self.pid, healthBase)
tes3mp.SetMagickaBase(self.pid, self.data.stats.magickaBase)
tes3mp.SetFatigueBase(self.pid, self.data.stats.fatigueBase)
tes3mp.SetHealthCurrent(self.pid, self.data.stats.healthCurrent)
tes3mp.SetMagickaCurrent(self.pid, self.data.stats.magickaCurrent)
tes3mp.SetFatigueCurrent(self.pid, self.data.stats.fatigueCurrent)
tes3mp.SendStatsDynamic(self.pid)
end
function BasePlayer:SaveStatsDynamic(playerPacket)
local healthBase = playerPacket.stats.healthBase
-- Sometimes, the player's base health gets set to 1 serverside;
-- use this temporary fix until we figure out why
if healthBase > 1 then
if tes3mp.IsWerewolf(self.pid) then
self.data.shapeshift.werewolfHealthBase = healthBase
else
self.data.stats.healthBase = healthBase
end
self.data.stats.magickaBase = playerPacket.stats.magickaBase
self.data.stats.fatigueBase = playerPacket.stats.fatigueBase
self.data.stats.healthCurrent = playerPacket.stats.healthCurrent
self.data.stats.magickaCurrent = playerPacket.stats.magickaCurrent
self.data.stats.fatigueCurrent = playerPacket.stats.fatigueCurrent
end
end
function BasePlayer:LoadAttributes()
for attributeName, value in pairs(self.data.attributes) do
local attributeId = tes3mp.GetAttributeId(attributeName)
if type(value) == "table" then
tes3mp.SetAttributeBase(self.pid, attributeId, value.base)
tes3mp.SetAttributeDamage(self.pid, attributeId, value.damage)
tes3mp.SetSkillIncrease(self.pid, attributeId, value.skillIncrease)
-- Maintain backwards compatibility with the old way of storing skills
elseif type(value) == "number" then
tes3mp.SetAttributeBase(self.pid, attributeId, value)
end
end
tes3mp.SendAttributes(self.pid)
end
function BasePlayer:SaveAttributes(playerPacket)
for attributeName in pairs(self.data.attributes) do
local attributeId = tes3mp.GetAttributeId(attributeName)
local attribute = playerPacket.attributes[attributeName]
local maxAttributeValue = config.maxAttributeValue
if attributeName == "Speed" then
maxAttributeValue = config.maxSpeedValue
end
if attribute.base > maxAttributeValue then
self:LoadAttributes()
local message = "Your base " .. attributeName .. " has exceeded the maximum allowed value " ..
"and been reset to its last recorded one.\n"
tes3mp.SendMessage(self.pid, message)
elseif (attribute.base + attribute.modifier) > maxAttributeValue then
tes3mp.ClearAttributeModifier(self.pid, attributeId)
tes3mp.SendAttributes(self.pid)
local message = "Your " .. attributeName .. " fortification has exceeded the maximum allowed " ..
"value and been removed.\n"
tes3mp.SendMessage(self.pid, message)
else
self.data.attributes[attributeName] = {
base = attribute.base,
damage = attribute.damage,
skillIncrease = attribute.skillIncrease
}
end
end
end
function BasePlayer:LoadSkills()
for skillName, value in pairs(self.data.skills) do
local skillId = tes3mp.GetSkillId(skillName)
if type(value) == "table" then
tes3mp.SetSkillBase(self.pid, skillId, value.base)
tes3mp.SetSkillDamage(self.pid, skillId, value.damage)
tes3mp.SetSkillProgress(self.pid, skillId, value.progress)
-- Maintain backwards compatibility with the old way of storing skills
elseif type(value) == "number" then
tes3mp.SetSkillBase(self.pid, skillId, value)
end
end
tes3mp.SendSkills(self.pid)
end
function BasePlayer:SaveSkills(playerPacket)
for skillName in pairs(self.data.skills) do
local skillId = tes3mp.GetSkillId(skillName)
local skill = playerPacket.skills[skillName]
local maxSkillValue = config.maxSkillValue
if skillName == "Acrobatics" then
maxSkillValue = config.maxAcrobaticsValue
end
if skill.base > maxSkillValue then
self:LoadSkills()
local message = "Your base " .. skillName .. " has exceeded the maximum allowed value " ..
"and been reset to its last recorded one.\n"
tes3mp.SendMessage(self.pid, message)
elseif (skill.base + skill.modifier) > maxSkillValue and not config.ignoreModifierWithMaxSkill then
tes3mp.ClearSkillModifier(self.pid, skillId)
tes3mp.SendSkills(self.pid)
local message = "Your " .. skillName .. " fortification has exceeded the maximum allowed " ..
"value and been removed.\n"
tes3mp.SendMessage(self.pid, message)
else
self.data.skills[skillName] = {
base = skill.base,
damage = skill.damage,
progress = skill.progress
}
end
end
end
function BasePlayer:LoadLevel()
if self.data.stats.level == nil then self.data.stats.level = 1 end
if self.data.stats.levelProgress == nil then self.data.stats.levelProgress = 0 end
tes3mp.SetLevel(self.pid, self.data.stats.level)
tes3mp.SetLevelProgress(self.pid, self.data.stats.levelProgress)
tes3mp.SendLevel(self.pid)
end
function BasePlayer:SaveLevel(playerPacket)
self.data.stats.level = playerPacket.stats.level
self.data.stats.levelProgress = playerPacket.stats.levelProgress
end
function BasePlayer:LoadShapeshift()
if self.data.shapeshift == nil then self.data.shapeshift = {} end
if self.data.shapeshift.scale == nil then self.data.shapeshift.scale = 1 end
if self.data.shapeshift.isWerewolf == nil then self.data.shapeshift.isWerewolf = false end
if self.data.shapeshift.creatureRefId == nil then self.data.shapeshift.creatureRefId = "" end
if self.data.shapeshift.displayCreatureName == nil then self.data.shapeshift.displayCreatureName = false end
tes3mp.SetScale(self.pid, self.data.shapeshift.scale)
tes3mp.SetWerewolfState(self.pid, self.data.shapeshift.isWerewolf)
tes3mp.SetCreatureRefId(self.pid, self.data.shapeshift.creatureRefId)
tes3mp.SetCreatureNameDisplayState(self.pid, self.data.shapeshift.displayCreatureName)
tes3mp.SendShapeshift(self.pid)
end
function BasePlayer:SaveShapeshift(playerPacket)
if self.data.shapeshift == nil then self.data.shapeshift = {} end
local newScale = playerPacket.shapeshift.scale
if newScale ~= self.data.shapeshift.scale then
tes3mp.LogMessage(enumerations.log.INFO, "Player " .. logicHandler.GetChatName(self.pid) ..
" has changed their scale to " .. newScale)
self.data.shapeshift.scale = newScale
end
self.data.shapeshift.isWerewolf = playerPacket.shapeshift.isWerewolf
end
function BasePlayer:LoadCell()
if self.data.location ~= nil then
local newCell = self.data.location.cell
if newCell ~= nil then
tes3mp.SetCell(self.pid, newCell)
local pos = { self.data.location.posX, self.data.location.posY, self.data.location.posZ }
local rot = { self.data.location.rotX, self.data.location.rotZ }
if pos[1] ~= nil and pos[2] ~= nil and pos[3] ~= nil then
tes3mp.SetPos(self.pid, pos[1], pos[2], pos[3])
end
if rot[1] ~= nil and rot[2] ~= nil then
tes3mp.SetRot(self.pid, rot[1], rot[2])
end
tes3mp.SendCell(self.pid)
tes3mp.SendPos(self.pid)
local regionName = self.data.location.regionName
if regionName ~= nil then
logicHandler.LoadRegionForPlayer(self.pid, regionName, true)
end
end
end
end
function BasePlayer:SaveCell(playerPacket)
if self.data.location == nil then self.data.location = {} end
-- Keep this around to update old player files
if self.data.mapExplored == nil then self.data.mapExplored = {} end
self.data.location.cell = playerPacket.location.cell
self.data.location.posX = playerPacket.location.posX