-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlibsota.lua
1229 lines (1045 loc) · 30.3 KB
/
libsota.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
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
-- libsota.0.4.8 by Catweazle Waldschrath
--[[
* libsota.lua
* Copyright (C) 2019 Michael Fritscher <[email protected]>
This file is part of libsota.
libsota is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libsota is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.";
]]
client = {
timeStarted = os.time(),
timeToLoad = 0,
timeInGame = 0,
timeDelta = 0,
fps = 0,
accuracy = 0,
isHitching = false,
isLoading = false,
_statEnum = {},
_statDescr = {},
screen = {
width = 0,
height = 0,
isFullScreen = false,
aspectRatio = 0,
_fsmul = 1,
},
api = {
luaVersion = "",
luaPath = "",
list = {},
isImplemented = function(name)
return client.api.list[name] ~= nil
end
},
mouse = {
button = {},
x = 0,
y = 0,
},
window = {
paperdoll = { name = "paperdoll", open = false, left = 0, top = 0, width = 267, height = 487 }
}
}
scene = {
name = "none",
maxPlayer = 0,
isPvp = false,
isPot = false,
timeInScene = 0,
timeToLoad = 0,
timeStarted = 0,
}
player = {
caption = "",
name = "none",
flag = "",
isPvp = false,
isAfk = false,
isGod = false,
isMoving = false,
isStill = false,
lastMoved = os.time(),
location = { x = 0, y = 0 , z = 0, scene = scene },
health = { current = 0, max = 0, percentage = 0 },
focus = { current = 0, max = 0, percentage = 0 },
xp = { producer = 0, adventurer = 0 },
inventory = {},
stat = function(index)
local ret = {
number = -1,
name = "invalid",
value = -999,
description = "",
}
if tonumber(index) == nil then
index = client._statEnum[index]
else
index = tonumber(index)
end
if index and index <= #client._statEnum then
ret.number = index
ret.name = client._statEnum[index]
ret.value = ShroudGetStatValueByNumber(index)
ret.description = client._statDescr[index]
end
return ret
end,
}
ui = {
version = "0.4.8",
timer = {
list = {},
add = function(timeout, once, callback, ...)
local index = #ui.timer.list + 1
local interval = nil
if not once then
interval = timeout
end
ui.timer.list[index] = {
_index = index,
time = os.time() + timeout,
interval = interval,
enabled = true,
callback = callback,
userdata = table.pack(...),
}
return index
end,
get = function(index)
return ui.timer.list[index]
end,
remove = function(index)
ui.timer.list[index] = nil
end,
enabled = function(index, enabled)
if enabled ~= nil then
ui.timer.list[index].enabled = enabled
end
return ui.timer.list[index].enabled
end,
pause = function(index)
ui.timer.list[index].enabled = false
end,
resume = function(index)
ui.timer.list[index].enabled = true
end,
toggle = function(index)
ui.timer.list[index].enabled = not ui.timer.list[index].enabled
end,
},
setTimeout = function(timeout, callback, ...)
return ui.timer.add(timeout, true, callback, ...)
end,
setInterval = function(interval, callback, ...)
return ui.timer.add(interval, false, callback, ...)
end,
handler = {
list = {},
add = function(name, callback)
local index = #ui.handler.list + 1
ui.handler.list[index] = {
_index = index,
name = name,
callback = callback,
}
return index
end,
remove = function(index)
ui.handler.list[index] = nil
end,
invoke = function(name, ...)
if not ui_initialized then return end
for _,h in next, ui.handler.list do
if h.name == name then
h.callback(...)
end
end
end,
},
onInit = function(callback)
return ui.handler.add("_init", callback)
end,
onStart = function(callback)
return ui.handler.add("_start", callback)
end,
onUpdate = function(callback)
return ui.handler.add("_update", callback)
end,
onConsoleInput = function(callback)
return ui.handler.add("_consoleInput", callback)
end,
onConsoleCommand = function(callback)
return ui.handler.add("_consoleCommand", callback)
end,
onSceneChanged = function(callback)
return ui.handler.add("_sceneChanged", callback)
end,
onPlayerChanged = function(callback)
return ui.handler.add("_playerChanged", callback)
end,
onPlayerMove = function(callback)
return ui.handler.add("_playerMove", callback)
end,
onPlayerMoveStart = function(callback)
return ui.handler.add("_playerMoveStart", callback)
end, -- deprecated
onPlayerMoveStop = function(callback)
return ui.handler.add("_playerMoveStop", callback)
end, -- deprecated
onPlayerIsStill = function(callback)
return ui.handler.add("_playerIsStill", callback)
end,
onPlayerDamage = function(callback)
return ui.handler.add("_playerDamage", callback)
end,
onPlayerInventory = function(callback)
return ui.handler.add("_playerInventory", callback)
end,
onClientWindow = function(callback)
return ui.handler.add("_clientWindow", callback)
end,
onClientIsHitching = function(callback)
return ui.handler.add("_clientIsHitching", callback)
end,
onClientIsLoading = function(callback)
return ui.handler.add("_clientIsLoading", callback)
end,
onMouseMove = function(callback)
return ui.handler.add("_mouseMove", callback)
end,
onMouseButton = function(callback)
return ui.handler.add("_mouseButton", callback)
end,
guiObject = {
add = function(left, top, width, height, drawFunc)
local index = #ui_guiObjectList + 1
ui_guiObjectList[index] = {
rect = { left = left or 0, top = top or 0, width = width or 0, height = height or 0 },
visible = false,
shownInScene = true,
shownInLoadScreen = false,
zIndex = 0,
}
local obj = {
guiDrawFunc = drawFunc,
guiObjectId = index,
rect = ui_guiObjectList[index].rect,
}
setmetatable(obj, {__index = ui.guiObject})
setmetatable(ui_guiObjectList[index], {__index = obj})
return obj
end,
remove = function(obj)
ui_guiObjectList[obj.guiObjectId] = nil
obj = nil
ui_drawListChanged = true
end,
shownInScene = function(obj, shown)
if shown ~= nil and shown ~= ui_guiObjectList[obj.guiObjectId].shownInScene then
ui_guiObjectList[obj.guiObjectId].shownInScene = shown
ui_drawListChanged = true
end
return ui_guiObjectList[obj.guiObjectId].shownInScene
end,
shownInLoadScreen = function(obj, shown)
if shown ~= nil and shown ~= ui_guiObjectList[obj.guiObjectId].shownInLoadScreen then
ui_guiObjectList[obj.guiObjectId].shownInLoadScreen = shown
ui_drawListChanged = true
end
return ui_guiObjectList[obj.guiObjectId].shownInLoadScreen
end,
zIndex = function(obj, zIndex)
if zIndex ~= nil and zIndex ~= ui_guiObjectList[obj.guiObjectId].zIndex then
ui_guiObjectList[obj.guiObjectId].zIndex = zIndex
ui_drawListChanged = true
end
return ui_guiObjectList[obj.guiObjectId].zIndex
end,
visible = function(obj, visible)
if visible ~= nil and visible ~= ui_guiObjectList[obj.guiObjectId].visible then
ui_guiObjectList[obj.guiObjectId].visible = visible
ui_drawListChanged = true
end
return ui_guiObjectList[obj.guiObjectId].visible
end,
toggle = function(obj)
obj:visible(not obj:visible())
end,
rect = function(obj, rect)
if type(rect) == "table" then
if rect.left then obj.rect.left = rect.left end
if rect.top then obj.rect.top = rect.top end
if rect.width then obj.rect.width = rect.width end
if rect.height then obj.rect.height = rect.height end
end
return obj.rect
end,
moveTo = function(obj, x, y)
obj.rect.left = x
obj.rect.top = y
end,
moveBy = function(obj, x, y)
obj.rect.left = obj.rect.left + x
obj.rect.top = obj.rect.top + y
end,
resizeTo = function(obj, w, h)
obj.rect.width = w
obj.rect.height = h
end,
resizeBy = function(obj, x, y)
obj.rect.width = obj.rect.width + x
obj.rect.height = obj.rect.height + y
end,
},
label = {
add = function(left, top, width, height, caption)
local l = ui.guiObject.add(left, top, width, height, ui.label.draw)
l.caption = caption or ""
setmetatable(l, {__index = ui.label})
return l
end,
draw = function(l)
ShroudGUILabel(l.rect.left, l.rect.top, l.rect.width, l.rect.height, l.caption)
end,
},
texture = {
_loaded = {},
add = function(left, top, filename, clamped, scaleMode, width, height)
if not ui.texture._loaded[tostring(filename)] then
local tid = ShroudLoadTexture(filename, clamped or false)
if tid < 0 then
print("ui.texture: Unable to load texture with filename '"..filename.."'")
return nil
end
local tw, th = ShroudGetTextureSize(tid)
ui.texture._loaded[tostring(filename)] = {
filename = filename,
id = tid,
width = tw,
height = th,
clamped = clamped or false,
}
end
local tex = ui.texture._loaded[tostring(filename)]
local t = ui.guiObject.add(left, top, width or tex.width, height or tex.height, ui.texture.draw)
t.texture = tex
t.scaleMode = scaleMode or -1
setmetatable(t, {__index = ui.texture})
return t
end,
draw = function(t)
ShroudDrawTexture(t.rect.left, t.rect.top, t.rect.width, t.rect.height, t.texture.id, t.scaleMode)
end,
clone = function(texture)
local t = ui.guiObject.add(texture.rect.left, texture.rect.top, texture.rect.width, texture.rect.height, texture.guiDrawFunc)
t.texture = texture.texture
t.scaleMode = texture.scaleMode
t.shownInScene = texture.shownInScene
t.shownInLoadScreen = texture.shownInLoadScreen
t.zIndex = texture.zIndex
setmetatable(t, {__index = ui.texture})
return t
end,
clamp = function(texture, clamped)
if clamped ~= nil and clamped ~= texture.texture.clamped then
texture.texture.clamped = clamped
ShroudSetTextureClamp(texture.texture.id, texture.texture.clamped)
end
return texture.texture.clamped
end,
scaleMode = function(texture, scaleMode)
if scaleMode ~= nil then
texture.scaleMode = scaleMode
end
return texture.scaleMode
end,
},
guiButton = {
add = function(left, top, texture, caption, tooltip, width, height)
local b = ui.guiObject.add(left, top, width, height, ui.guiButton.draw)
b.caption = caption or ""
b.tooltip = tooltip or ""
-- b.mode = false -- mode = repeat, click, off/false
if type(texture) == "table" and texture.texture and texture.texture.id then
b.texture = texture
else
print("ui.guiButton: "..type(texture).." is not a texture object.")
return nil
end
setmetatable(b, {__index = ui.guiButton})
return b
end,
draw = function(b)
ShroudButton(b.rect.left, b.rect.top, b.rect.width, b.rect.height, b.texture.texture.id, b.caption, b.tooltip)
end,
onClick = function(button, callback)
button.callback = callback
button.guiDrawFunc = function(b)
if ShroudButton(b.rect.left, b.rect.top, b.rect.width, b.rect.height, b.texture.texture.id, b.caption, b.tooltip) then
b.callback(ShroudMouseX - b.rect.left, ShroudMouseY - b.rect.top)
end
end
end,
onRepeat = function(button, callback)
button.callback = callback
button.guiDrawFunc = function(b)
if ShroudButtonRepeat(b.rect.left, b.rect.top, b.rect.width, b.rect.height, b.texture.texture.id, b.caption, b.tooltip) then
b.callback(ShroudMouseX - b.rect.left, ShroudMouseY - b.rect.top)
end
end
end,
},
shortcut = {
list = { pressed = {}, watch = {} },
add = function(action, ...)
local keys = {...}
local callback = keys[#keys]; keys[#keys] = nil
local key = keys[#keys]; keys[#keys] = nil
if not ui.shortcut.list[action][tostring(key)] then
ui.shortcut.list[action][tostring(key)] = {}
end
if type(callback) == "string" then
callback = ui.command.list[callback].callback
end
local id = #ui.shortcut.list[action][key] + 1
local index = { action = action, key = key, id = id }
ui.shortcut.list[action][key][id] = {
_index = index,
key = key,
keysHeld = keys,
callback = callback,
}
if type(callback) == string then
if ui.command.list[callback].shortcut then
ui.shortcut.remove(ui.command.list[callback].shortcut)
end
ui.command.list[callback].shortcut = index
end
return index
end,
remove = function(index)
ui.shortcut.list[index.action][index.key][index.id] = nil
if #ui.shortcut.list[index.action][index.key] == 0 then
ui.shortcut.list[index.action][index.key] = nil
end
end,
invoke = function(index)
ui.shortcut.list[index.action][index.key][index.id].callback()
end,
},
command = {
list = {},
add = function(command, callback)
ui.command.list[tostring(command)] = {
_command = command,
callback = callback,
shortcut = nil,
channel = nil,
sender = player.name,
receiver = nil,
}
return command
end,
remove = function(command)
if ui.command.list[command].shortcut then
ui.shortcut.remove(ui.command.list[command].shortcut)
end
ui.command.list[command] = nil
end,
invoke = function(command, ...)
if ... then
ui.command.list[command].callback(nil, unpack(...))
else
ui.command.list[command].callback()
end
end,
restrict = function(command, channel, sender, receiver)
if ui.command[command] then
ui.command[command].channel = channel
ui.command[command].sender = sender
ui.command[command].receiver = receiver
end
end
},
module = {
list = {},
add = function(modulename, prefix)
local part = {}
for p in modulename:gmatch("[^\\/.]+") do
part[#part + 1] = p
end
if part[#part] == "lua" then
part[#part] = nil
end
modulename = table.concat(part, ".")
if not ui.module.list[modulename] then
local filename = table.concat(part, "/")..".lua"
local f = nil
for _,inc in next, {"/","/lib/","/share/","/bin/","/include/"} do
f = io.open(ShroudLuaPath..inc..filename)
if f then break end
end
if not f then
print("ui.module: '",filename,"' not found")
return nil
end
local d = f:read("*a")
f:close()
local m,e = loadsafe(d, modulename, "bt", _G)
if not m then
print("ui.module: '",modulename,"': "..e)
return nil
end
ui.module.list[modulename] = {}
ui.module.list[modulename][0] = m
end
if prefix then
if prefix == true or prefix == "" then
prefix = modulename
else
part = {}
for p in prefix:gmatch("[^\\/.]+") do part[#part + 1] = p end
if part[#part] == "lua" then part[#part] = nil end
prefix = table.concat(part, ".")
end
if #part == 1 then
_G[part[1]] = ui.module.list[modulename][0]
else
local tree = {}
local leave = tree
for i=2,#part-1 do
if not leave[part[i]] then leave[part[i]] = {} end
leave = leave[part[i]]
end
leave[part[#part]] = ui.module.list[modulename][0]
_G[part[1]] = tree
end
ui.module.list[modulename][#ui.module.list[modulename] + 1] = part
end
return ui.module.list[modulename][0]
end,
get = function(modulename)
local part = {}
for p in modulename:gmatch("[^\\/.]+") do part[#part + 1] = p end
if part[#part] == "lua" then part[#part] = nil end
modulename = table.concat(part, ".")
return ui.module.list[tostring(modulename)][0]
end,
remove = function(modulename)
local part = {}
for p in modulename:gmatch("[^\\/.]+") do
part[#part + 1] = p
end
if part[#part] == "lua" then
part[#part] = nil
end
modulename = table.concat(part, ".")
ui.module.list[tostring(modulename)][0] = nil
for _,prefix in next, ui.module.list[tostring(modulename)] do
if #prefix == 1 then
_G[prefix[1]] = nil
else
local tree = _G[prefix[1]]
local leave = tree
for i=2,#prefix-1 do
if leave[prefix[i]] then leave = leave[prefix[i]] end
end
leave[prefix[#prefix]] = nil
_G[prefix[1]] = tree
end
end
ui.module.list[tostring(modulename)] = nil
end,
invoke = function(modulename, callback, ...)
local part = {}
for p in modulename:gmatch("[^\\/.]+") do
part[#part + 1] = p
end
if part[#part] == "lua" then
part[#part] = nil
end
modulename = table.concat(part, ".")
if ui.module.list[modulename] then
if callback then
return ui.module.list[modulename][0][tostring(callback)](...)
else
return ui.module.list[modulename][0](...)
end
else
print("ui.module: ",modulename," not found")
end
end,
},
verbosity = 0,
consoleLog = function(message, verbosity)
if not verbosity then
verbosity = 0
end
if ui.verbosity >= verbosity then
for l in message:gmatch("[^\n]+") do
ShroudConsoleLog(l)
end
end
end,
}
--setmetatable(ui.timer, {__index = ui.timer.list})
setmetatable(ui.label, {__index = ui.guiObject})
setmetatable(ui.texture, {__index = ui.guiObject})
setmetatable(ui.guiButton, {__index = ui.guiObject})
-- internal
ui_initialized = false
ui_client_ts = os.time()
ui_client_frame = 0
ui_guiObjectList = {}
ui_drawListChanged = false
local ui_drawInScene = {}
local ui_drawInLoadScreen = {}
local ui_callback_queue = {}
local ui_inventory_quantity = {}
local ui_inventory_durability = {}
local function ui_getPlayerName()
if player.caption ~= ShroudGetPlayerName() then
player.caption = ShroudGetPlayerName()
player.name = player.caption
player.flag = ""
player.isPvp = false
if player.name:byte(#player.name) == 93 then
player.name, player.flag = player.name:match("^(.-)(%[.-%])$")
player.isPvp = player.flag and player.flag:find("PVP") ~= nil
player.isAfk = player.flag and player.flag:find("AFK") ~= nil
player.isGod = player.flag and player.flag:find("God") ~= nil
end
ui.handler.invoke("_playerChanged", "caption")
end
end
local function ui_getPlayerChange()
local loc = { x = ShroudPlayerX, y = ShroudPlayerY, z = ShroudPlayerZ, scene = scene }
local isMoving = loc.x ~= player.location.x or loc.y ~= player.location.y or loc.z ~= player.location.z
if isMoving then
player.lastMoved = os.time()
end
local isStill = os.time() - player.lastMoved > 5
local invoke = isStill ~= player.isStill or isMoving ~= player.isMoving
player.isMoving = isMoving
player.isStill = isStill
player.location = loc
if invoke then
if isMoving then
ui.handler.invoke("_playerMoveStart") -- depricated
ui.handler.invoke("_playerMove", "start", loc)
ui.handler.invoke("_playerChanged", "moving")
elseif isStill then
ui.handler.invoke("_playerIsStill") -- depricated?
ui.handler.invoke("_playerMove", "stillness", loc) -- hm?
ui.handler.invoke("_playerChanged", "stillness")
else
ui.handler.invoke("_playerMoveStop") -- depricated
ui.handler.invoke("_playerMove", "stop", loc)
ui.handler.invoke("_playerChanged", "standing")
end
end
if isMoving then
ui.handler.invoke("_playerMove", "move", loc)
ui.handler.invoke("_playerChanged", "location", loc)
end
local health = { max = ShroudGetStatValueByNumber(30), current = ShroudPlayerCurrentHealth, percentage = 0 }
local focus = { max = ShroudGetStatValueByNumber(27), current = ShroudPlayerCurrentFocus, percentage = 0 }
health.percentage = health.current / health.max
focus.percentage = focus.current / focus.max
invoke = player.health.current ~= health.current or player.focus.current ~= focus.current
if invoke then
ui.handler.invoke("_playerDamage", health, focus)
ui.handler.invoke("_playerChanged", "damage", health, focus)
end
player.health = health
player.focus = focus
end
local function ui_getPlayerInventory()
local inventory = ShroudGetInventory()
local ret1 = {}
local ret2 = {}
local ret3 = {}
for _, item in next, inventory do
item = table.pack(item)
ret1[#ret1 + 1] = {
name = item[1],
durability = item[2],
primaryDurability = item[3],
maxDurability = item[4],
weight = item[5],
quantity = item[6],
value = item[7],
}
if not ret2[tostring(item[1])] then
ret2[tostring(item[1])] = 0
end
ret2[tostring(item[1])] = ret2[tostring(item[1])] + item[6]
end
local cs = { n = 0 }
for n, q in next, ui_inventory_quantity do
if not ret2[n] then
--print("Gegenstand entfernt: "..n.."Menge: "..q)
cs[n] = { quantity = q, action = "removed" }
cs.n = cs.n + 1
elseif ret2[n] ~= q then
--print("Gegenstand geändert: "..n.."Menge: "..(ret2[n] - q))
cs[n] = { quantity = ret2[n] - q, action = "changed" }
cs.n = cs.n + 1
end
end
for n, q in next, ret2 do
if not ui_inventory_quantity[n] then
--print("Gegenstand zugefügt: "..n.."Menge: "..q)
cs[n] = { quantity = q, action = "added" }
cs.n = cs.n + 1
end
end
player.inventory = ret1
ui_inventory_quantity = ret2
if cs.n > 0 then
cs.n = nil
ui.handler.invoke("_playerInventory", cs)
ui.handler.invoke("_playerChanged", "inventory", cs)
end
end
local function ui_getSceneName()
if scene.name ~= ShroudGetCurrentSceneName() then
scene.name = ShroudGetCurrentSceneName()
scene.maxPlayer = ShroudGetCurrentSceneMaxPlayerCount()
scene.isPvp = ShroudGetCurrentSceneIsPVP()
scene.isPot = ShroudGetCurrentSceneIsPOT()
scene.timeStarted = os.time()
ui.handler.invoke("_sceneChanged")
end
end
local function ui_initialize()
client.api.luaPath = ShroudLuaPath
client.api.luaVersion = _G._MOONSHARP.luacompat
for i,v in next, _G do
if i:find("^Shroud") then client.api.list[tostring(i)] = type(v) end
end
client.timeToLoad = ui_client_ts - client.timeStarted
client.screen.width = ShroudGetScreenX()
client.screen.height = ShroudGetScreenY()
client.screen.isFullScreen = ShroudGetFullScreen()
client.screen.aspectRatio = client.screen.width / client.screen.height
client.screen._fsmul = client.screen.height / 1080
for i=0, ShroudGetStatCount()-1, 1 do
local name = ShroudGetStatNameByNumber(i)
client._statEnum[tostring(name)] = i
client._statEnum[i] = name
client._statDescr[i] = ShroudGetStatDescriptionByNumber(i)
end
ui_getSceneName()
ui_getPlayerName()
ui_getPlayerChange()
ui_getPlayerInventory()
ShroudRegisterPeriodic("ui_timer_internal", "ui_timer_internal", 0.01, true)
ShroudRegisterPeriodic("ui_timer_user", "ui_timer_user", 0.120, true)
end
local function ui_buildDrawList()
local list = ui_guiObjectList
local ds = {}
local dl = {}
for _,o in next, list do
if o.visible and o.shownInScene then
ds[#ds + 1] = o
elseif o.visible and o.shownInLoadScreen then
dl[#dl + 1] = o
end
end
table.sort(ds, function(a, b) return a.zIndex < b.zIndex end)
table.sort(dl, function(a, b) return a.zIndex < b.zIndex end)
ui_drawInScene = ds
ui_drawInLoadScreen = dl
end
local function ui_queue(callback, ...)
local index = #ui_callback_queue + 1
if type(callback) == "function" then
ui_callback_queue[index] = {
callback = callback,
userdata = table.pack(...),
}
else
for _,h in next, ui.handler.list do
if h.name == callback then
ui_callback_queue[index] = {
callback = h.callback,
userdata = table.pack(...),
}
index = #ui_callback_queue + 1
end
end
end
end
-- shroud timers
local ui_timer_ts_fast = os.time()
local ui_timer_ts_slow = os.time()
function ui_timer_internal()
local ts = os.time()
if ts - ui_timer_ts_fast > 0.240 then
ui_timer_ts_fast = ts
ui_getPlayerChange()
end
if ts - ui_timer_ts_slow > 2 then
ui_timer_ts_slow = ts
-- watch player xp
player.xp.producer = ShroudGetPooledProducerExperience()
player.xp.adventurer = ShroudGetPooledAdventurerExperience()
-- watch player inventory
ui_getPlayerInventory()
end
-- queued callbacks
for i,q in next, ui_callback_queue do
q.callback(unpack(q.userdata))
ui_callback_queue[i] = nil
end
-- watch character sheet window (realtime)
local wo = ShroudIsCharacterSheetActive()
if wo then
local wx, wy = ShroudGetCharacterSheetPosition(); wx = wx - 860 -- bug
if wx ~= client.window.paperdoll.left or wy ~= client.window.paperdoll.top then
client.window.paperdoll.left, client.window.paperdoll.top = wx, wy
ui.handler.invoke("_clientWindow", "moved", client.window.paperdoll)
end
end
if wo ~= client.window.paperdoll.open then
client.window.paperdoll.open = wo
if wo then
ui.handler.invoke("_clientWindow", "opened", client.window.paperdoll)
else
ui.handler.invoke("_clientWindow", "closed", client.window.paperdoll)
end
end
end
function ui_timer_user()
local ts = os.time()
for _,t in next, ui.timer.list do
if t.enabled and ts >= t.time then
if t.interval then
t.time = ts + t.interval
else
ui.timer.list[t._index] = nil
end
if t.callback(unpack(t.userdata)) then ui.timer.list[t._index] = nil end
end
end
end
-- shroud callbacks
local button_ts = {} -- howto: clean up
local button_ts2 = {}
function ShroudOnConsoleInput(channel, sender, message)
ui_queue(function(...)
-- handle player flag changes
if (channel == "Story" or channel == "System") and message:find("PvP") then ui_getPlayerName() end
-- parse message
local src, dst, msg = message:match("^(.-) to (.-) %[.-:%s*(.*)$")
if sender == "" then
sender = src
end
if sender == "" then