-
Notifications
You must be signed in to change notification settings - Fork 0
/
debugkeys.lua
1739 lines (1588 loc) · 58.4 KB
/
debugkeys.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
local DebugNodes = CAN_USE_DBUI and require "dbui_no_package/debug_nodes" or nil
if CAN_USE_DBUI then
require "dbui_no_package/debug_entity"
require "dbui_no_package/debug_prefabs"
require "dbui_no_package/debug_audio"
require "dbui_no_package/debug_weather"
require "dbui_no_package/debug_skins"
require "dbui_no_package/debug_widget"
require "dbui_no_package/debug_player"
require "dbui_no_package/debug_input"
require "dbui_no_package/debug_strings"
require "dbui_no_package/debug_console"
require "dbui_no_package/debug_watch"
require "dbui_no_package/debug_anything"
require "dbui_no_package/debug_history"
end
require "consolecommands"
local fcts = {
string = function(value) return string.format('%q', value) end,
number = function(value) return value end,
boolean = function(value) return tostring(value) end,
['nil'] = function(value) return 'nil' end,
}
local function dumpvariabletostr(var)
local fct = fcts[type(var)]
assert(fct)
return fct(var)
end
local function d_c_spawn(prefab, count, dontselect)
if not TheWorld.ismastersim then
ConsoleRemote("c_spawn(%s,%s,%s)", {dumpvariabletostr(prefab), dumpvariabletostr(count), dumpvariabletostr(dontselect)})
else
c_spawn(prefab, count, dontselect)
end
end
local function d_c_give(prefab, count, dontselect)
if not TheWorld.ismastersim then
ConsoleRemote("c_give(%s,%s,%s)", {dumpvariabletostr(prefab), dumpvariabletostr(count), dumpvariabletostr(dontselect)})
else
c_give(prefab, count, dontselect)
end
end
local function d_c_remove(entity)
if not TheWorld.ismastersim then
local mouseentity = entity or TheInput:GetWorldEntityUnderMouse()
if TheWorld == nil or mouseentity == nil or mouseentity.Network == nil then
c_remove()
return
end
local networkid = mouseentity.Network:GetNetworkID()
local x, y, z = mouseentity.Transform:GetWorldPosition()
ConsoleRemote('d_removeentitywithnetworkid(%s, %s, %s, %s)', {dumpvariabletostr(networkid), dumpvariabletostr(x), dumpvariabletostr(y), dumpvariabletostr(z)})
else
c_remove(entity)
end
end
local function DebugKeyPlayer()
return (TheWorld and TheWorld.ismastersim and ConsoleCommandPlayer()) or nil
end
----this gets called by the frontend code if a rawkey event has not been consumed by the current screen
handlers = {}
function DoDebugKey(key, down)
if handlers[key] then
for k,v in ipairs(handlers[key]) do
if v(down) then
return true
end
end
end
end
--use this to register debug key handlers from within this file
function AddGameDebugKey(key, fn, down)
down = down or true
handlers[key] = handlers[key] or {}
table.insert( handlers[key], function(_down) if _down == down and inGamePlay then return fn() end end)
end
function AddGlobalDebugKey(key, fn, down)
down = down or true
handlers[key] = handlers[key] or {}
table.insert( handlers[key], function(_down) if _down == down then return fn() end end)
end
function SimBreakPoint()
if not TheSim:IsDebugPaused() then
TheSim:ToggleDebugPause()
end
end
function DoDebugMouse(button, down,x,y)
-- delcaring this here so that it doesn't crash on steam deck, look farther down for the real fucntion
end
function DoReload()
-- NOTES(JBK): Do not use dofile.
package.loaded["scripts/reload.lua"] = nil
require("scripts/reload.lua")
end
-------------------------------------DEBUG KEYS
if IsSteamDeck() then
return
end
local currentlySelected
global("c_ent")
global("c_ang")
local function Spawn(prefab)
--TheSim:LoadPrefabs({prefab})
return SpawnPrefab(prefab)
end
local userName = TheSim:GetUsersName()
--
-- Put your own username in here to enable "dprint"s to output to the log window
if CHEATS_ENABLED and userName == "My Username" then
global("CHEATS_KEEP_SAVE")
global("CHEATS_ENABLE_DPRINT")
global("DPRINT_USERNAME")
global("c_ps")
DPRINT_USERNAME = "My Username"
CHEATS_KEEP_SAVE = true
CHEATS_ENABLE_DPRINT = true
end
GLOBAL_KEY_BINDINGS =
{
{
binding = { key = KEY_HOME },
name = "Pause / Step Game",
fn = function()
if not TheSim:IsDebugPaused() then
print("Home key pressed PAUSING GAME")
TheSim:ToggleDebugPause()
else
print("Home key pressed STEPPING")
TheSim:Step()
end
end
},
{
binding = { key = KEY_HOME, CTRL=true },
name = "Toggle Pause Game",
fn = function()
print("Home key pressed TOGGLING")
TheSim:ToggleDebugPause()
end
},
{
--binding = { key = KEY_H, SHIFT=true },
name = function()
local on_off = TheFrontEnd.debugMenu.history:IsEnabled() and "OFF" or "ON"
return "Turn "..on_off.." History Recording"
end,
fn = function()
c_record()
end
},
{
binding = { key = KEY_G },
name = "God Mode",
fn = function()
c_godmode()
end
},
{
binding = { key = KEY_G, SHIFT=true },
name = "Super God Mode",
fn = function()
c_supergodmode()
end,
tooltip = "Also restores are health, hunger, sanity, moisture"
},
{
binding = { key = KEY_A, CTRL=true },
name = "Unlock All Recipes",
fn = function()
c_freecrafting()
end
},
{
binding = { key = KEY_F1 },
name = "Select Entity under mouse",
fn = function()
c_select()
if c_sel() ~= nil then
if c_sel().prefab == "beefalo" then
c_sel():DoPeriodicTask(1, function(inst)
--[[]
if inst.components.domesticatable ~= nil then
print("Tendencies:",
"default", inst.components.domesticatable.tendencies.DEFAULT or 'nil',
"ornery", inst.components.domesticatable.tendencies.ORNERY or 'nil',
"rider", inst.components.domesticatable.tendencies.RIDER or 'nil',
"pudgy", inst.components.domesticatable.tendencies.PUDGY or 'nil')
end
]]
end)
elseif c_sel():HasTag("player") then
c_sel():ListenForEvent("onattackother", function(inst)
--print("I DID ATTTACCCCKED")
end)
end
end
end
},
{
binding = { key = KEY_W, CTRL=true },
name = "Toggle IMGUI",
fn = function()
TheFrontEnd:ToggleImgui()
end
},
{
binding = { key = KEY_F10, SHIFT=true },
name = "Next Nightmare Phase",
fn = function()
if TheWorld ~= nil then
if not TheWorld.ismastersim then
ConsoleRemote('TheWorld:PushEvent("ms_nextnightmarephase")')
else
TheWorld:PushEvent("ms_nextnightmarephase")
end
end
end
},
{
binding = { key = KEY_F10 },
name = "Next Day Phase",
fn = function()
if TheWorld ~= nil then
if not TheWorld.ismastersim then
ConsoleRemote('TheWorld:PushEvent("ms_nextphase")')
else
TheWorld:PushEvent("ms_nextphase")
end
end
end
},
}
PROGRAMMER_KEY_BINDINGS =
{
{
binding = { key = KEY_F1, ALT=true },
name = "Select World",
fn = function()
c_select(TheWorld)
end
},
{
binding = { key = KEY_F1, CTRL=true },
name = "Toggle Perf Graph",
fn = function()
TheSim:TogglePerfGraph()
end
},
}
WINDOW_KEY_BINDINGS =
{
{
binding = { key = KEY_P, SHIFT=true },
name = "Prefabs",
fn = function()
if not TheFrontEnd:IsDebugPanelOpen(DebugNodes.DebugPrefabs.NodeName) then
TheFrontEnd:CreateDebugPanel( DebugNodes.DebugPrefabs() )
end
end
},
{
binding = { key = KEY_A, SHIFT=true },
name = "Audio",
fn = function()
if not TheFrontEnd:IsDebugPanelOpen(DebugNodes.DebugAudio.NodeName) then
TheFrontEnd:CreateDebugPanel( DebugNodes.DebugAudio() )
end
end
},
{
--binding = { key = KEY_W, SHIFT=true },
name = "UI",
fn = function()
if not TheFrontEnd:IsDebugPanelOpen(DebugNodes.DebugWidget.NodeName) then
TheFrontEnd:CreateDebugPanel( DebugNodes.DebugWidget() )
end
end
},
{
binding = { key = KEY_E, SHIFT=true },
name = "Entity",
fn = function()
if not TheFrontEnd:IsDebugPanelOpen(DebugNodes.DebugEntity.NodeName) then
TheFrontEnd:CreateDebugPanel( DebugNodes.DebugEntity() )
if GetDebugEntity() == nil then
--c_selectany_cycle()
end
end
end
},
{
binding = { key = KEY_C, SHIFT=true },
name = "Console",
fn = function()
if not TheFrontEnd:IsDebugPanelOpen(DebugNodes.DebugConsole.NodeName) then
TheFrontEnd:CreateDebugPanel( DebugNodes.DebugConsole() )
end
end
},
{
binding = { key = KEY_F, SHIFT=true },
name = "Watch",
fn = function()
if not TheFrontEnd:IsDebugPanelOpen(DebugNodes.DebugWatch.NodeName) then
TheFrontEnd:CreateDebugPanel( DebugNodes.DebugWatch() )
end
end
},
{
--binding = { key = KEY_H },
name = "History",
fn = function()
if not CAN_USE_DBUI or Profile:GetThreadedRenderEnabled() then
return
end
if not TheFrontEnd:IsDebugPanelOpen(DebugNodes.DebugHistory.NodeName) then
TheFrontEnd:CreateDebugPanel( DebugNodes.DebugHistory() )
end
end
},
{
name = "Anything",
fn = function()
if not TheFrontEnd:IsDebugPanelOpen( DebugNodes.DebugAnything.NodeName) then
TheFrontEnd:CreateDebugPanel( DebugNodes.DebugAnything() )
end
end,
},
{
--binding = { key = InputConstants.Keys.E, SHIFT = true },
name = "Brain",
fn = function()
if not TheFrontEnd:IsDebugPanelOpen( DebugNodes.DebugBrain.NodeName) then
TheFrontEnd:CreateDebugPanel( DebugNodes.DebugBrain() )
end
end,
},
{
name = "Player",
fn = function()
if not TheFrontEnd:IsDebugPanelOpen(DebugNodes.DebugPlayer.NodeName) then
TheFrontEnd:CreateDebugPanel( DebugNodes.DebugPlayer() )
end
end
},
{
name = "Weather",
fn = function()
if not TheFrontEnd:IsDebugPanelOpen(DebugNodes.DebugWeather.NodeName) then
TheFrontEnd:CreateDebugPanel( DebugNodes.DebugWeather() )
end
end
},
{
binding = { key = KEY_S, SHIFT=true, ALT=true },
name = "Skins",
fn = function()
if not TheFrontEnd:IsDebugPanelOpen(DebugNodes.DebugSkins.NodeName) then
TheFrontEnd:CreateDebugPanel( DebugNodes.DebugSkins() )
end
end
},
{
name = "Input",
fn = function()
if not TheFrontEnd:IsDebugPanelOpen(DebugNodes.DebugInput.NodeName) then
TheFrontEnd:CreateDebugPanel( DebugNodes.DebugInput() )
end
end
},
{
name = "Character Examine Strings",
fn = function()
if not TheFrontEnd:IsDebugPanelOpen(DebugNodes.DebugStrings.NodeName) then
TheFrontEnd:CreateDebugPanel( DebugNodes.DebugStrings() )
end
end
},
}
local function BindKeys( bindings )
for _,v in pairs(bindings) do
if v.binding then
AddGlobalDebugKey( v.binding.key,
function()
if (v.binding.CTRL and not TheInput:IsKeyDown(KEY_CTRL)) or
(v.binding.CTRL == nil and TheInput:IsKeyDown(KEY_CTRL)) then
return false
end
if (v.binding.SHIFT and not TheInput:IsKeyDown(KEY_SHIFT)) or
(v.binding.SHIFT == nil and TheInput:IsKeyDown(KEY_SHIFT)) then
return false
end
if (v.binding.ALT and not TheInput:IsKeyDown(KEY_ALT)) or
(v.binding.ALT == nil and TheInput:IsKeyDown(KEY_ALT)) then
return false
end
--print("Activating hotkey: "..v.name)
return v.fn()
end, v.down)
end
end
end
BindKeys( GLOBAL_KEY_BINDINGS )
BindKeys( PROGRAMMER_KEY_BINDINGS )
if CAN_USE_DBUI then
BindKeys( WINDOW_KEY_BINDINGS )
end
AddGlobalDebugKey(KEY_R, function()
if TheInput:IsKeyDown(KEY_CTRL) then
if TheInput:IsKeyDown(KEY_SHIFT) then
c_regenerateworld()
else
c_reset()
end
else
c_repeatlastcommand()
end
return true
end)
AddGameDebugKey(KEY_F2, function()
if c_sel() == TheWorld then
c_select(TheWorld.net)
else
c_select(TheWorld)
end
end)
AddGameDebugKey(KEY_F3, function()
for i=1,TheWorld.state.remainingdaysinseason do
if not TheWorld.ismastersim then
ConsoleRemote('TheWorld:PushEvent("ms_advanceseason")')
else
TheWorld:PushEvent("ms_advanceseason")
end
end
end)
AddGameDebugKey(KEY_I, function()
if TheInput:IsKeyDown(KEY_CTRL) and TheInput:IsKeyDown(KEY_SHIFT) then
TheInventory:Debug_LocalGift()
return true
elseif TheInput:IsKeyDown(KEY_CTRL) then
TheInventory:Debug_ForceHeartbeatGift("")
return true
elseif TheInput:IsKeyDown(KEY_SHIFT) then
d_c_spawn("researchlab")
return true
end
end)
AddGameDebugKey(KEY_B, function()
if TheInput:IsKeyDown(KEY_CTRL) and not TheInput:IsKeyDown(KEY_SHIFT) then
local pos = Vector3(ConsoleWorldPosition():Get())
local boat = TheWorld.Map:GetPlatformAtPoint(pos.x,pos.z)
if boat then
boat:PushEvent("spawnnewboatleak", {pt = pos, leak_size = "med_leak", playsoundfx = true})
end
elseif TheInput:IsKeyDown(KEY_SHIFT) then
local pos = Vector3(ConsoleWorldPosition():Get())
local bumpers = TheSim:FindEntities(pos.x, pos.y, pos.z, 1, {"boatbumper"})
for i, bumper in ipairs(bumpers) do
local health = bumper.components.health.maxhealth
if TheInput:IsKeyDown(KEY_CTRL) then
bumper.components.health:DoDelta(health * 0.2)
else
bumper:PushEvent("boatcollision")
bumper.components.health:DoDelta(-health * 0.2)
end
end
elseif TheInput:IsKeyDown(KEY_ALT) then
end
end)
AddGameDebugKey(KEY_F4, function()
if TheWorld and not TheWorld.ismastersim then
return
end
-- Spawn a ready-made base!
local pos = TheInput:GetWorldPosition()
local topleft = Vector3(pos.x - 15, 0, pos.z - 15)
local bottomright = Vector3(pos.x + 15, 0, pos.z + 15)
local width = bottomright-topleft
for i=0,width.x do
if i < width.x/2-1 or i > width.x/2+1 then
local wall = SpawnPrefab("wall_stone")
wall.Transform:SetPosition(topleft.x + i, 0, topleft.z)
wall = SpawnPrefab("wall_stone")
wall.Transform:SetPosition(bottomright.x - i, 0, bottomright.z)
end
end
for i=0,width.z do
if i < width.z/2-1 or i > width.z/2+1 then
local wall = SpawnPrefab("wall_wood")
wall.Transform:SetPosition(topleft.x, 0, topleft.z + i)
wall = SpawnPrefab("wall_hay")
wall.Transform:SetPosition(bottomright.x, 0, bottomright.z - i)
end
end
local items = {
"treasurechest",
"treasurechest",
"treasurechest",
"researchlab",
"researchlab",
"researchlab2",
"firepit",
"slow_farmplot",
"slow_farmplot",
"slow_farmplot",
"fast_farmplot",
"fast_farmplot",
"fast_farmplot",
"meatrack",
"meatrack",
"meatrack",
"meatrack",
"cookpot",
"cookpot",
"cookpot",
"cookpot",
"pighouse",
"birdcage",
"firesuppressor",
}
for i,v in ipairs(items) do
local pos = topleft + Vector3(width.x*math.random(), 0, width.z*math.random())
SpawnPrefab(items[i]).Transform:SetPosition(pos.x, pos.y, pos.z)
end
local group_items = {
"grass",
"berrybush",
"sapling",
"evergreen",
"evergreen",
}
for i,v in ipairs(group_items) do
local pos = topleft + Vector3(width.x*math.random(), 0, width.z*math.random())
for z=-2,2 do
for x=-2,2 do
local sub_pos = Vector3(pos.x + x, 0, pos.z + z)
SpawnPrefab(group_items[i]).Transform:SetPosition(sub_pos.x, sub_pos.y, sub_pos.z)
end
end
end
ConsoleCommandPlayer().components.inventory:Equip( d_c_spawn("backpack") ) -- do this first so other things can get put in it
ConsoleCommandPlayer().components.inventory:Equip( d_c_spawn("axe") )
ConsoleCommandPlayer().components.inventory:Equip( d_c_spawn("flowerhat") )
local invitems = {
carrot = 20,
berries = 20,
twigs = 20,
cutgrass = 20,
flint = 20,
rocks = 40,
log = 40,
spear = 2,
armorwood = 2,
footballhat = 1,
torch = 2,
axe = 1,
pickaxe = 1,
shovel = 1,
silk = 10,
spidergland = 5,
smallmeat = 8,
meat = 4,
meatballs = 4,
}
for k,v in pairs(invitems) do
d_c_give(k, v)
end
end)
AddGameDebugKey(KEY_F5, function()
if TheInput:IsKeyDown(KEY_CTRL) then
local pos = TheInput:GetWorldPosition()
local met = SpawnPrefab("shadowmeteor")
if TheInput:IsKeyDown(KEY_SHIFT) then
met:SetSize("large", 1)
else
met:SetSize("small", 1)
met:SetPeripheral(true)
end
met.Transform:SetPosition(pos.x, pos.y, pos.z)
elseif TheInput:IsKeyDown(KEY_SHIFT) then
local pos = TheInput:GetWorldPosition()
TheWorld:PushEvent("ms_sendlightningstrike", pos)
else
TheWorld:PushEvent("ms_setseasonlength", {season="autumn", length=12})
TheWorld:PushEvent("ms_setseasonlength", {season="winter", length=10})
TheWorld:PushEvent("ms_setseasonlength", {season="spring", length=12})
TheWorld:PushEvent("ms_setseasonlength", {season="summer", length=10})
end
return true
end)
AddGameDebugKey(KEY_F6, function()
-- F6 is used by the hot-reload functionality!
end)
AddGameDebugKey(KEY_F12, function()
--Removing this by Phil's request
--[[local positions = {}
for i = 1, 100 do
local s = i/32.0--(num/2) -- 32.0
local a = math.sqrt(s*512.0)
local b = math.sqrt(s)
table.insert(positions, Vector3(math.sin(a)*b, 0, math.cos(a)*b))
end
if DebugKeyPlayer() then
local pos = DebugKeyPlayer():GetPosition()
local delay = 0
for i = 1, #positions do
local sp = pos + (positions[i] * 1.2)
DebugKeyPlayer():DoTaskInTime(delay, function()
local prefab = SpawnPrefab("carrot_planted")
prefab.Transform:SetPosition(sp:Get())
end)
--delay = delay + 0.03
end
end]]
end)
AddGameDebugKey(KEY_F7, function()
local player = ConsoleCommandPlayer()
if player then
local x, y, z = player.Transform:GetWorldPosition()
if TheInput:IsKeyDown(KEY_SHIFT) and TheInput:IsKeyDown(KEY_CTRL) then
local idx = 0
local nidx = 1
local nextpoint = nil
nextpoint = function()
if TheWorld.topology.nodes[nidx] ~= nil then
if idx == 0 then
if TheWorld.topology.nodes[nidx].cent ~= nil then
c_teleport(TheWorld.topology.nodes[nidx].cent[1], 0, TheWorld.topology.nodes[nidx].cent[2], player)
end
else
if TheWorld.topology.nodes[nidx].poly ~= nil then
c_teleport(TheWorld.topology.nodes[nidx].poly[idx][1], 0, TheWorld.topology.nodes[nidx].poly[idx][2], player)
end
end
idx = idx + 1
if false then--idx <= #TheWorld.topology.nodes[nidx].poly then
-- continue
--nextpoint()
player:DoTaskInTime(0.0, nextpoint)
elseif nidx <= #TheWorld.topology.nodes then
nidx = nidx + 1
idx = 0
--nextpoint()
player:DoTaskInTime(0.0, nextpoint)
end
else
nidx = nidx + 1
--nextpoint()
player:DoTaskInTime(0.0, nextpoint)
end
end
nextpoint()
else
for i, node in ipairs(TheWorld.topology.nodes) do
if TheSim:WorldPointInPoly(x, z, node.poly) then
print("/********************\\")
print("Standing in", i)
print("id", TheWorld.topology.ids[i])
print("type", node.type)
print("story depth", TheWorld.topology.story_depths[i])
print("area", node.area)
print("tags", table.concat(node.tags or {}, ", "))
dumptable(TheWorld.generated.densities[ TheWorld.topology.ids[i] ])
if TheInput:IsKeyDown(KEY_SHIFT) and TheInput:IsKeyDown(KEY_CTRL) then
-- eat this, handled above
elseif TheInput:IsKeyDown(KEY_SHIFT) then
c_teleport(node.cent[1], 0, node.cent[2], player)
print("center", unpack(node.cent))
elseif TheInput:IsKeyDown(KEY_CTRL) then
print("poly size", #node.poly)
for _,v in ipairs(node.poly) do
print("\t", unpack(v))
end
local idx = 1
local nextpoint = nil
nextpoint = function()
c_teleport(node.poly[idx][1], 0, node.poly[idx][2], player)
idx = idx + 1
if idx <= #node.poly then
player:DoTaskInTime(0.3, nextpoint)
end
end
nextpoint()
elseif TheInput:IsKeyDown(KEY_ALT) then
print("densities")
if TheWorld.generated.densities[TheWorld.topology.ids[i]] == nil then
print("\t<nil>")
elseif GetTableSize(TheWorld.generated.densities[TheWorld.topology.ids[i]]) == 0 then
print("\t<zero densities>")
else
for k,v in pairs(TheWorld.generated.densities[TheWorld.topology.ids[i]]) do
print("\t",k,v)
end
end
end
print("\\********************/")
end
end
end
end
end)
---Spawn random items from the "items" table in a circles around me.
AddGameDebugKey(KEY_F8, function()
--Spawns a lot of prefabs around you in rings.
local items = {"flower"} --Which items spawn.
local player = DebugKeyPlayer()
if player == nil then
return true
end
local pt = Vector3(player.Transform:GetWorldPosition())
local theta = math.random() * TWOPI
local numrings = 10 --How many rings of stuff you spawn
local radius = 2 --Initial distance from player
local radius_step_distance = 1 --How much the radius increases per ring.
local itemdensity = 1 --(X items per unit)
local map = TheWorld.Map
local finalRad = (radius + (radius_step_distance * numrings))
local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, finalRad + 2)
local numspawned = 0
-- Walk the circle trying to find a valid spawn point
for i = 1, numrings do
local circ = TWOPI*radius
local numitems = circ * itemdensity
for i = 1, numitems do
numspawned = numspawned + 1
local offset = Vector3(radius * math.cos( theta ), 0, -radius * math.sin( theta ))
local wander_point = pt + offset
if map:IsPassableAtPoint(wander_point:Get()) then
local spawn = SpawnPrefab(GetRandomItem(items))
spawn.Transform:SetPosition(wander_point:Get())
end
theta = theta - (TWOPI / numitems)
end
radius = radius + radius_step_distance
end
print("Made: ".. numspawned .." items")
return true
end)
AddGameDebugKey(KEY_PAGEUP, function()
if TheInput:IsKeyDown(KEY_SHIFT) then
TheWorld:PushEvent("ms_deltawetness", 5)
elseif TheInput:IsKeyDown(KEY_CTRL) then
TheWorld:PushEvent("ms_deltamoisture", 100)
elseif TheInput:IsKeyDown(KEY_ALT) then
TheWorld:PushEvent("ms_setsnowlevel", TheWorld.state.snowlevel + .5)
else
TheWorld:PushEvent("ms_advanceseason")
end
return true
end)
AddGameDebugKey(KEY_PAGEDOWN, function()
if TheInput:IsKeyDown(KEY_SHIFT) then
TheWorld:PushEvent("ms_deltawetness", -5)
elseif TheInput:IsKeyDown(KEY_CTRL) then
TheWorld:PushEvent("ms_deltamoisture", -100)
elseif TheInput:IsKeyDown(KEY_ALT) then
TheWorld:PushEvent("ms_setsnowlevel", TheWorld.state.snowlevel - .5)
else
TheWorld:PushEvent("ms_retreatseason")
end
return true
end)
AddGameDebugKey(KEY_O, function()
if TheInput:IsKeyDown(KEY_SHIFT) then
print("Finding rooms with chester")
local Levels = require('map/levels')
local Tasks = require('map/tasks')
local TaskSets = require('map/tasksets')
local Rooms = require('map/rooms')
local locationdata = Levels.GetDataForLocation("cave")
local taskset = locationdata.overrides.task_set
local tasksetdata = TaskSets.GetGenTasks(taskset)
local taskcount = 0
local roomcount = 0
local tagcount = 0
for i,taskname in ipairs(ArrayUnion(tasksetdata.tasks, tasksetdata.optionaltasks)) do
taskcount = taskcount+1
local taskdata = Tasks.GetTaskByName(taskname)
for roomname,count in pairs(taskdata.room_choices) do
roomcount = roomcount + 1
local roomdata = Rooms.GetRoomByName(roomname)
if roomdata.tags then
tagcount = tagcount+1
for i,tag in ipairs(roomdata.tags) do
if tag == "Chester_Eyebone" then
print("FOUND CHESTER EYEBONE",taskname,roomname)
end
end
end
end
end
print("DONE", taskcount, roomcount, tagcount)
elseif TheInput:IsKeyDown(KEY_ALT) then
end
return true
end)
AddGameDebugKey(KEY_F9, function()
LongUpdate(TUNING.TOTAL_DAY_TIME*.25)
return true
end)
AddGameDebugKey(KEY_F11, function()
for k,v in pairs(Ents) do
if v.prefab == "carrot_planted" and v.components.pickable then
v.components.pickable:Pick()
end
end
return true
end)
local potatoparts = { "teleportato_ring", "teleportato_box", "teleportato_crank", "teleportato_potato", "teleportato_base", "adventure_portal" }
local potatoindex = 1
AddGameDebugKey(KEY_1, function()
if TheInput:IsKeyDown(KEY_CTRL) then
local MainCharacter = DebugKeyPlayer()
local part = nil
for k,v in pairs(Ents) do
if v.prefab == potatoparts[potatoindex] then
part = v
break
end
end
potatoindex = ((potatoindex) % #potatoparts)+1
if MainCharacter and part then
MainCharacter.Transform:SetPosition(part.Transform:GetWorldPosition())
end
return true
end
end)
AddGameDebugKey(KEY_X, function()
currentlySelected = TheInput:GetWorldEntityUnderMouse()
if TheInput:IsKeyDown(KEY_CTRL) then
local inventory = ConsoleCommandPlayer().components and ConsoleCommandPlayer().components.inventory
or ConsoleCommandPlayer().replica and ConsoleCommandPlayer().replica.inventory
or nil
if inventory then
c_select(inventory:GetEquippedItem(EQUIPSLOTS.HANDS))
end
elseif currentlySelected then
c_ent = currentlySelected
end
return true
end)
AddGlobalDebugKey(KEY_LEFTBRACKET, function()
if TheInput:IsKeyDown(KEY_CTRL) then
TheSim:SetTimeScale(1)
elseif TheInput:IsKeyDown(KEY_SHIFT) then
TheSim:SetTimeScale(0)
elseif TheInput:IsKeyDown(KEY_ALT) then
if ThePlayer and TheWorld.ismastersim then
local skilltreeupdater = ThePlayer.components.skilltreeupdater
local skilldefs = require("prefabs/skilltree_defs").SKILLTREE_DEFS[ThePlayer.prefab]
if skilldefs then
local player = ThePlayer
if c_sel() and c_sel():HasTag("player") then
player = c_sel()
end
for skill, data in pairs(skilldefs) do
skilltreeupdater:DeactivateSkill(skill)
end
skilltreeupdater:AddSkillXP(-skilltreeupdater:GetSkillXP())
end
end
else
TheSim:SetTimeScale(TheSim:GetTimeScale() - .25)
end
return true
end)
AddGlobalDebugKey(KEY_RIGHTBRACKET, function()
if TheInput:IsKeyDown(KEY_CTRL) then
TheSim:SetTimeScale(1)
elseif TheInput:IsKeyDown(KEY_SHIFT) then
TheSim:SetTimeScale(4)
elseif TheInput:IsKeyDown(KEY_ALT)then
local player = ThePlayer
if c_sel() and c_sel():HasTag("player") then
player = c_sel()
end
if player then
local skilltreeupdater = player.components.skilltreeupdater
local skilldefs = require("prefabs/skilltree_defs").SKILLTREE_DEFS[player.prefab]
if skilldefs then
skilltreeupdater:AddSkillXP(1)
end
end
else
TheSim:SetTimeScale(TheSim:GetTimeScale() + .25)
end
return true
end)
AddGameDebugKey(KEY_KP_PLUS, function()
local MainCharacter = DebugKeyPlayer()
if TheWorld ~= nil and not TheWorld.ismastersim then
if TheInput:IsKeyDown(KEY_CTRL) then
if TheInput:IsKeyDown(KEY_SHIFT) then
ConsoleRemote("ThePlayer.components.health:DoDelta(%d)", {50})
ConsoleRemote("c_sethunger(%d)", {1})
ConsoleRemote("c_sethealth(%d)", {1})
ConsoleRemote("c_setsanity(%d)", {1})
else
ConsoleRemote("ThePlayer.components.sanity:DoDelta(%d)", {5})
end
elseif TheInput:IsKeyDown(KEY_SHIFT) then
ConsoleRemote("ThePlayer.components.hunger:DoDelta(%d)", {25})
elseif TheInput:IsKeyDown(KEY_ALT) then
ConsoleRemote("ThePlayer.components.sanity:DoDelta(%d)", {25})
else
ConsoleRemote("ThePlayer.components.health:DoDelta(%d)", {25})
end
elseif MainCharacter ~= nil then
if TheInput:IsKeyDown(KEY_CTRL) then
if TheInput:IsKeyDown(KEY_SHIFT) then
MainCharacter.components.health:DoDelta(50, nil, "debug_key")
c_sethunger(1)
c_sethealth(1)
c_setsanity(1)
else
MainCharacter.components.sanity:DoDelta(5)
end
elseif TheInput:IsKeyDown(KEY_SHIFT) then
MainCharacter.components.hunger:DoDelta(25)
elseif TheInput:IsKeyDown(KEY_ALT) then
MainCharacter.components.sanity:DoDelta(25)