-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
8318 lines (7923 loc) · 272 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
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
--MOD
l = RegisterMod("Leon", 1)
local _log = {}
local game = Game()
local sfx = SFXManager()
local music = MusicManager()
local rng = RNG(); rng:SetSeed(Game():GetSeeds():GetStartSeed(), 0)
local config = Isaac.GetItemConfig()
local json = json or require("json")
local screensize = screensize or false
local isfullscreen = false
local cursorinbounds = true
lastcmd = autocmd or ''
autocmd = autocmd or ''
cmdbind = cmdbind or {}
--main data
l.data = {}; local gDAT = l.data
GUNMOD_VARS = {gunmode = false}; l.data.var = GUNMOD_VARS; local gVAR = GUNMOD_VARS;
--constants
include("for lua/constants"); l.data.con = gunmod_CONST; local gCON = gunmod_CONST
local EDF = gCON.EN.DF; local EAM = gCON.EN.AM; local ESP = gCON.EN.SP; local EIT = gCON.EN.IT;
local EFM = gCON.EN.FM; local ECP = gCON.EN.CP;
local CSP = gCON.Sprite;
local ammo = gCON.Ammodat;
--user settings (move later)
include("for lua/usersettings"); l.data.set = gunmod_SET; local gSET = gunmod_SET
--balance values
include("for lua/balance"); l.data.bal = gunmod_BAL; local gBAL = gunmod_BAL
--sound effects
include("for lua/sounds"); l.data.sfx = gunmod_SFX; local gSFX = gunmod_SFX; local snd = gSFX
--weapon data
include("for lua/weapons"); l.data.wep = gunmod_WEP; local gWEP = gunmod_WEP
local WEPT = gunmod_WEP.WeaponTypes
--item stats
include("for lua/items"); l.data.itm = gunmod_ITEMS; local gITM = gunmod_ITEMS
--pocket items
include("for lua/pocket"); l.data.poc = gunmod_POCKET; local gPOC = gunmod_POCKET
local pocket = gPOC.dat
--characters
include("for lua/isaacs"); l.data.chr = gunmod_CHR; local gCHR = gunmod_CHR
--dead sea scrolls
include("for lua/menu")
CL_white = Color(1, 1, 1, 1, 0, 0, 0)
CL_pencil = Color(54/255, 47/255, 45/255, 1, 0, 0, 0)
CL_pencil2 = Color(81/255, 70/255, 60/255, 1, 0, 0, 0)
CL_red = Color(94/255, 12/255, 12/255, 1, 0, 0, 0)
CL_blue = Color(44/255, 44/255, 60/255, 1, 0, 0, 0)
CL_green = Color(44/255, 60/255, 44/255, 1, 0, 0, 0)
local mouseinput = true
local padinput = false
local famcrit = {}
famcrit[3] = {3.5, 0} -- lil chubby
famcrit[6] = {4, 0} -- robo baby
famcrit[14] = {0, .5} -- dead bird
famcrit[15] = {0, .5} -- outline dead bird
famcrit[16] = {0, .5} -- daddy's foot
famcrit[17] = {0, .5} -- peeper's eye
famcrit[53] = {4, 0} -- robo baby 2.0
famcrit[59] = {10, .5} -- bob's brain
famcrit[61] = {10, 0} -- lil brimstone
famcrit[63] = {0, .33} -- lil haunt
famcrit[77] = {10, .5} -- ???'s only friend
famcrit[85] = {5, 0} -- lost fly
famcrit[87] = {5, 0} --- lil gurdy
famcrit[88] = {2, 0} -- bumbo
famcrit[96] = {2, 0} -- succubus
famcrit[118] = {2, 0} -- angry fly
--menu shit
local mfontdat = {}
mfontdat['a'] = {0,7,11}; mfontdat['b'] = {1,8,12}; mfontdat['c'] = {2,7,10};
mfontdat['d'] = {3,8,11}; mfontdat['e'] = {4,7,10}; mfontdat['f'] = {5,6,9};
mfontdat['g'] = {6,8,12}; mfontdat['h'] = {7,9,11}; mfontdat['i'] = {8,2,5};
mfontdat['j'] = {9,7,11}; mfontdat['k'] = {10,6,9}; mfontdat['l'] = {11,8,10};
mfontdat['m'] = {12,8,13}; mfontdat['n'] = {13,8,10}; mfontdat['o'] = {14,10,12};
mfontdat['p'] = {15,7,10}; mfontdat['q'] = {16,9,13}; mfontdat['r'] = {17,7,10};
mfontdat['s'] = {18,6,10}; mfontdat['t'] = {19,7,10}; mfontdat['u'] = {20,7,13};
mfontdat['v'] = {21,8,12}; mfontdat['w'] = {22,11,16}; mfontdat['x'] = {23,6,11};
mfontdat['y'] = {24,7,10}; mfontdat['z'] = {25,6,8}; mfontdat['0'] = {26,8,10};
mfontdat['1'] = {27,8,10}; mfontdat['2'] = {28,8,10}; mfontdat['3'] = {29,8,10};
mfontdat['4'] = {30,7,10}; mfontdat['5'] = {31,8,9}; mfontdat['6'] = {32,8,10};
mfontdat['7'] = {33,8,10}; mfontdat['8'] = {34,8,9}; mfontdat['9'] = {35,8,10};
mfontdat["'"] = {36,4,5}; mfontdat['"'] = {37,4,5}; mfontdat[':'] = {38,3,5};
mfontdat['/'] = {39,6,8}; mfontdat['.'] = {40,2,4}; mfontdat[','] = {41,3,5};
mfontdat['!'] = {42,4,6}; mfontdat['?'] = {43,6,8}; mfontdat['['] = {44,4,6};
mfontdat[']'] = {45,4,6}; mfontdat['('] = {44,4,6}; mfontdat[')'] = {45,4,6};
mfontdat['$'] = {46,6,8}; mfontdat['C'] = {47,6,8}; mfontdat['+'] = {48,6,8};
mfontdat['-'] = {49,6,8}; mfontdat['X'] = {50,6,8}; mfontdat['D'] = {51,6,8};
mfontdat['%'] = {52,6,8}; mfontdat['_'] = {53,4,5}; mfontdat[' '] = {53,6,8};
mfontdat['B'] = {1,12,16}; mfontdat['='] = {1,8,12};
local mmenudir = {
--LEVEL 1
main = {
title = 'paused!',
valign = 0,
buttons = {
--{str = 'aabbccddeeffgg'},
--{str = 'hhiijjkkllmmnn'},
--{str = 'ooppqqrrssttuu'},
--{str = 'vvwwxxyyzz1122'},
--{str = '33445566778899'},
--{str = '00:[]+-.,!'},
{str = 'resume game', action = 'resume'},
--{str = 'run stats', dest = 'stats'},
{str = 'inventory', dest = 'inventory'},
{str = 'settings', dest = 'settings'},
--{str = 'achievements', dest = 'achievements'},
{str = 'help', dest = 'help'},
--{str = 'test', dest = 'test'},
},
},
test = {
title = 'item lore',
},
inventory = {
title = 'inventory',
inventory = true,
valign = 1,
buttons = {},
pages = 0,
},
stats = {
title = 'stats',
},
settings = {
title = 'settings',
buttons = {
{str = 'gameplay', dest = 'gameplaysettings'},
{str = 'hud', dest = 'hudsettings'},
{str = 'misc', dest = 'miscsettings'},
},
},
gameplaysettings = {
title = 'gameplay settings',
savesettings = true,
buttons = {
{str = 'difficulty',
choices = {'wacky easy', 'easy', 'normal', 'hard', 'professional', 'hell'},
variable = 'Difficulty',
setting = 3,
},
{str = 'darkness',
choices = {'never', 'sometimes', 'always'},
variable = 'CurseOfDarkness',
setting = 2,
},
{str = 'damage spread',
choices = {'off', 'low', 'high'},
variable = 'DamageSpread',
setting = 1,
},
},
},
hudsettings = {
title = 'hud settings',
savesettings = true,
buttons = {
{str = 'bar style',
choices = {'thick', 'thin'},
variable = 'BarThin',
setting = 1,
},
{str = 'hud opacity',
choices = {'off', '25%', '50%', '75%', '100%'},
variable = 'HudOpacity',
setting = 3,
},
{str = 'show stats',
choices = {'never', 'in menu only', 'stat change', 'any change', 'always'},
variable = 'ShowStats',
setting = 3,
},
{str = 'custom cursor',
choices = {'never', 'fullscreen', 'always in gm', 'always'},
variable = 'ShowGunCursor',
setting = 3,
},
},
},
miscsettings = {
title = 'misc settings',
savesettings = true,
buttons = {
{str = 'merchant voice',
choices = {'never', 'some', 'spam', 'mega spam'},
variable = 'MerchantVoice',
setting = 2,
},
{str = 'gib limit',
choices = {'off', '10', '20', '30', '50', 'unlimited'},
variable = 'GoreLimit',
setting = 4,
},
{str = 'light saturation',
choices = {'0%', '50%', '75%', '100%', '150%', '200%'},
variable = 'LightingSaturation',
setting = 4,
},
{str = 'shot brightness',
choices = {'0%', '25%', '50%', '75%', '100%'},
variable = 'ShotFlashBrightness',
setting = 4,
},
},
},
help = {
title = 'help',
buttons = {{str = "????????????????????????????????????????????????????"}},
},
}
local mmenuvar = {
open = false,
item = mmenudir.main,
idle = false,
maskalpha = 1,
hadgun = false,
path = {},
}
--local font1 = Font(); font1:Load("font/pftempestasevencondensed.fnt")
local font1 = Font(); font1:Load("font/luaminioutlined.fnt")
local Controller = {
DPAD_LEFT = 0,
DPAD_RIGHT = 1,
DPAD_UP = 2,
DPAD_DOWN = 3,
BUTTON_LEFT = 4,
BUTTON_RIGHT = 5,
BUTTON_UP = 6,
BUTTON_DOWN = 7,
BUMPER_LEFT = 8,
TRIGGER_LEFT = 9,
ANALOGPRESS_LEFT = 10,
BUMPER_RIGHT = 11,
TRIGGER_RIGHT = 12,
ANALOGPRESS_RIGHT = 13,
SELECT = 14,
START = 15
}
---LOCAL FUNCTIONS
local function log(...)
local args = {...}
for _, v in ipairs(args) do
Isaac.ConsoleOutput(tostring(v) .. "\n")
Isaac.DebugString(tostring(v))
if type(v) == 'number' or type(v) == 'string' or type(v) == 'table' or 'boolean' then
table.insert(_log, tostring(v))
else
table.insert(_log, roundTo(v.X, .001)..', '..roundTo(v.Y, .001))
end
end
end
local function getScreenCenterPosition()
local room = game:GetRoom()
local centerOffset = (room:GetCenterPos()) - room:GetTopLeftPos()
local pos = room:GetCenterPos()
if centerOffset.X > 260 then
pos.X = pos.X - 260
end
if centerOffset.Y > 140 then
pos.Y = pos.Y - 140
end
return Isaac.WorldToRenderPosition(pos, false)
end
--good lerp
local function Lerp(aa, bb, cc)
return (aa + (bb - aa) * cc)
end
local function TLerp(aa, bb, cc)
local res = {}
for i, v in ipairs(aa) do
table.insert(res, (aa[i] + (bb[i] - aa[i]) * cc))
end
return res
end
--thing of math
local function approach(aa, bb, cc)
cc = cc or 1
if bb > aa then
return math.min(aa + cc, bb)
elseif bb < aa then
return math.max(aa - cc, bb)
else
return bb
end
end
--angular difference
local function angleDiff(aa, bb)
return (((aa - bb) + 180) % 360) - 180
end
--insert first
local function insertFirst(table, newval)
local cangrow = cangrow or false
for i, val in ipairs(table) do
if not val then
table[i] = newval
return i
end
end
return (#table + 1)
end
local function stringSplit(str, sep)
local ret = {}
while str do
local ind = string.find(str, sep)
local len = string.len(sep)
if ind then
table.insert(ret, string.sub(str, 1, ind - 1))
str = string.sub(str, ind + len, -1)
else
table.insert(ret, str)
str = nil
end
end
return ret
end
local function stringJoin(str, sep, start)
local ret = ''
for i = start or 1, #str do
ret = ret..str[i]
if i < #str then
ret = ret..sep
end
end
return ret
end
function isAny(func, ...)
local args = {...}
for i, arg in ipairs(args) do
if func(arg) then
return true
end
end
return false
end
function unPack(t, i)
i = i or 1
if t[i] ~= nil then
return t[i], unPack(t, i + 1)
end
end
function l:leonCmd(cmd, params)
local player = Isaac.GetPlayer(0)
local d = player:GetData()
local gun = d.mygun
local multi = string.find(cmd..' '..params, '; ') and cmd ~= 'bind'
if cmd ~= 'autocmd' and cmd~= 'auto' and cmd ~='bind' then
lastcmd = cmd..' '..params
end
if multi then
local multicmd = stringSplit(cmd..' '..params, '; ')
local fstring = multicmd[1]
local wasauto = false
for i, newcmd in ipairs(multicmd) do
Isaac.ExecuteCommand(newcmd)
if newcmd == 'auto' then
lastcmd = fstring
Isaac.ExecuteCommand('autocmd')
wasauto = true
elseif i > 1 then
fstring = fstring..'; '..newcmd
end
end
if cmd ~= 'autocmd' and not wasauto then
lastcmd = cmd..' '..params
end
elseif cmd == 'autocmd' then
if autocmd ~= lastcmd then
autocmd = lastcmd
Isaac.ConsoleOutput('Auto-input set to: '..autocmd..'\n')
else
autocmd = ''
Isaac.ConsoleOutput('Auto-input off.\n')
end
elseif cmd == 'bind' and params then
local params = stringSplit(params, ' ')
params[1] = string.upper(params[1])
local newbind = stringJoin(params, ' ', 2)
cmdbind[params[1] ] = newbind
Isaac.ConsoleOutput(newbind..' bound to '..params[1]..'.\n')
elseif cmd == 'unbind' and params then
if params == 'all' then
Isaac.ConsoleOutput('Unbound all.\n')
cmdbind = {}
else
Isaac.ConsoleOutput('Unbound '..params..'.\n')
params = string.upper(params)
cmdbind[params] = nil
end
elseif cmd == 'rlset' then
Isaac.ConsoleOutput('User settings reset.\n')
gunmod_SET = {}; gSET = {}
elseif cmd == 'ldebug' then
local rstr = params == 'r' or false
if gSET.DebugMode then
gSET.DebugMode = false
Isaac.ConsoleOutput('Debug mode off.\n')
else
gSET.DebugMode = true
Isaac.ConsoleOutput('Debug mode on.\n')
end
if rstr then
Isaac.ExecuteCommand("restart")
end
elseif cmd == 'lload' then
local continue = params and params == 'true' and true or false
l.loadData(continue)
elseif cmd == 'stat' and gun then
local params = stringSplit(params, ' ')
local sub, mod = params[#params], {}
for i = #params, 2, -1 do
mod = {}
mod[params[i - 1] ] = sub
sub = mod
end
l.gunMod(gun, mod)
l.gunSwitch(player, gun)
elseif cmd == 'mod' and gun then
local params = stringSplit(params, ' ')
local all = params[1] == 'all'
if all then
table.remove(params, 1)
end
for i, mod in ipairs(params) do
if all then
for i = 1, 4 do
gun = d.loadout[i]
if gun then
l.gunMod(gun, tonumber(mod))
local upgrade = gun.upgrade[#gun.mods]
if upgrade then
l.gunMod(gun, upgrade, {player = player, switch = true})
end
gun.clip = gun.clipsize
end
end
else
l.gunMod(gun, tonumber(mod))
local upgrade = gun.upgrade[#gun.mods]
if upgrade then
l.gunMod(gun, upgrade, {player = player, switch = true})
end
gun.clip = gun.clipsize
end
end
l.gunSwitch(player, gun)
elseif cmd == 'gun' then
local params = stringSplit(params, ' ')
local newgun = l.gunInit(params[1])
newgun.playerowned = true
if params[2] then for i = 1, tonumber(params[2]) do
l.gunMod(newgun, gITM.modlist[1 + rng:RandomInt(#gITM.modlist)])
local upgrade = newgun.upgrade[#newgun.mods]
if upgrade then
l.gunMod(newgun, upgrade, {player = player, switch = true})
end
end end
newgun.clip = newgun.clipsize
if not params[3] then
insertFirst(d.loadout, newgun)
else
d.loadout[tonumber(params[3])] = newgun
end
l.gunSwitch(player, newgun)
elseif cmd == 'toboss' then
if params then
Isaac.ExecuteCommand("stage "..params)
end
player:UseCard(5)
elseif cmd == 'lspawn' then
local spawns = {329, 118, 2, 245, 114, 360, 216, 8}
local center = game:GetRoom():GetCenterPos()
for i, spawn in ipairs(spawns) do
Isaac.Spawn(5, 100, spawn, center + Vector(-40, -80) + Vector((i-1)*40, 0), Vector(0, 0), nil)
end
local check = {"hg", "hy", "hr","hb"}
for i = 1, 4 do
for j, spawn in ipairs(check) do
Isaac.Spawn(5, 300, pocket[spawn].id, center + Vector(-200, 30) + Vector((i-1)*40, (j-1)*30), Vector(0, 0), nil)
end
end
check = {"am1", "am2", "am3", "am4", "am5", "am6", "am7"}
for i, spawn in ipairs(check) do
Isaac.Spawn(5, 300, pocket[spawn].id, center + Vector(-40, 120) + Vector((i-1)*40, 0), Vector(0, 0), nil)
end
check = {"gr", "gg", "gb"}
for i, spawn in ipairs(check) do
Isaac.Spawn(5, 300, pocket[spawn].id, center + Vector(80, 60) + Vector((i-1)*40, 0), Vector(0, 0), nil)
end
player.Position = center + Vector(-80, 0)
elseif cmd == 'lock' then
if gVAR.unlocks[params] ~= nil then
gVAR.unlocks[params] = false
Isaac.ConsoleOutput(params..' locked\n')
else
Isaac.ConsoleOutput(params..' is not an unlockable\n')
end
elseif cmd == 'unlock' then
if gVAR.unlocks[params] ~= nil then
gVAR.unlocks[params] = true
Isaac.ConsoleOutput(params..' unlocked\n')
else
Isaac.ConsoleOutput(params..' is not an unlockable\n')
end
elseif cmd == 'bscale' then
local scale = gunmod_BAL.bossscaler[Isaac.GetEntityTypeByName(params)]
Isaac.ConsoleOutput(params..' scale = '..(scale or 'nil')..'\n')
elseif cmd == 'overachiever' then
for i = 1, 999 do
Isaac.ExecuteCommand("achievement "..i)
end
end
end
l:AddCallback(ModCallbacks.MC_EXECUTE_CMD, l.leonCmd)
local function getPrice(object, pricetype)
local price = false
local discount = Isaac.GetPlayer(0):HasCollectible(64)
local bp = gBAL.buyprice
local sp = gBAL.sellprice
if pricetype == 'buy' then
if object.kind == EIT.gun then
price = (bp.gun + (#object.id.mods * bp.gunmod)) * object.id.buyprice
if object.id.name == "Rocket Launcher" then
price = bp.rpg
end
elseif object.kind == EIT.mod then
price = bp.mod
price = math.max(price, 5)
elseif object.kind == EIT.pocket then
price = (pocket[object.id].price or bp.pocket) + ((pocket[object.id].type == 'herb' and gVAR.herbtax) or 0)
price = math.max(price, 1)
end
if discount then
price = price - 3
end
price = price + (object.sellmod or 0)
price = math.max(price, 0)
elseif pricetype == 'sell' then
if object.kind == EIT.gun then
price = (sp.gun + (#object.id.mods * sp.gunmod)) * object.id.buyprice
--for i, mod in ipairs(object.id.mods) do
-- local mult = math.max(0, i-1)
-- price = price + (mult * sp.gunlvl)
--end
elseif object.kind == EIT.mod then
price = sp.mod
elseif object.kind == EIT.pocket then
price = (pocket[object.id].sell or sp.pocket)
end
price = math.max(price, 0)
price = price * -1
elseif pricetype == 'attach' then
if object.kind == EIT.gun then
price = bp.attach + (#object.id.mods * bp.attachlvl)
elseif object.kind == EIT.mod then
price = false
end
elseif pricetype == 'destroy' then -- repurposed into 'scrap'
price = -sp.scrap
for i, m in ipairs(object.id.mods) do
price = price - (i * 10)
end
end
return math.ceil(price)
end
--bit ops
local function bit(x,p)
return x * 2 ^ p
end
local function hasbit(x, p)
--return x % (p | p) >= p
return x | p ~= 0
end
local function setbit(x, p)
return hasbit(x, p) and x or x + p
end
local function clearbit(x, p)
return hasbit(x, p) and x - p or x
end
--goodest rounding
function roundTo(fig, place)
local place = place or 1
local result = math.floor((fig / place) + .5) * place
return (result == tonumber(string.format ("%.0f", result)) and tonumber(string.format ("%.0f", result))) or result
end
local acts = {}
acts[0] = ButtonAction.ACTION_LEFT
acts[1] = ButtonAction.ACTION_RIGHT
acts[2] = ButtonAction.ACTION_UP
acts[3] = ButtonAction.ACTION_DOWN
acts[4] = ButtonAction.ACTION_SHOOTLEFT
acts[5] = ButtonAction.ACTION_SHOOTRIGHT
acts[6] = ButtonAction.ACTION_SHOOTUP
acts[7] = ButtonAction.ACTION_SHOOTDOWN
local Controller = { -- thanks deadinfinity
DPAD_LEFT = 0,
DPAD_RIGHT = 1,
DPAD_UP = 2,
DPAD_DOWN = 3,
BUTTON_LEFT = 4,
BUTTON_RIGHT = 5,
BUTTON_UP = 6,
BUTTON_DOWN = 7,
BUMPER_LEFT = 8,
TRIGGER_LEFT = 9,
ANALOGPRESS_LEFT = 10,
BUMPER_RIGHT = 11,
TRIGGER_RIGHT = 12,
ANALOGPRESS_RIGHT = 13,
SELECT = 14,
START = 15
}
----FUNCTIONALITY
function l.getInput(pnum)
local player = Isaac.GetPlayer(pnum)
local d = player:GetData()
--init
if not d.input then
d.input = {
mode = 0,
face = Vector(0, 1),
timer = 0,
lastframe = 0,
action = 0,
actiontime = 0,
lastaimdir = Vector(0, 1),
aimpoint = Vector(0, 0),
lastactiveaimdir = Vector(0, 1),
mouse = mouseinput,
pad = padinput,
mousepress = 0,
menu = {mousepos = Vector(0, 0), drag = Vector(0, 0), holdup = 0, holddown = 0, holdleft = 0, holdright = 0},
knifepresstime = -100,
}
end
local input = player:GetData().input
local indx = player.ControllerIndex
input.mode = 0;
if (not mmenuvar.open) and CSP.Menu:IsFinished("Dissapear") then
--welcome to hell
input.mode = 1
local sx = (Input.GetActionValue(acts[4], indx) * -1) + (Input.GetActionValue(acts[5], indx))
local sy = (Input.GetActionValue(acts[6], indx) * -1) + (Input.GetActionValue(acts[7], indx))
input.mode = 0
--update frame
local shootinput = Vector(sx, sy) --player:GetShootingInput()
local shootinputang = shootinput:GetAngleDegrees()
local likelygamepad = shootinputang % 45 ~= 0 or (sx + sy) % 1 ~= 0
--log(player:GetMovementJoystick():Length() + player:GetShootingJoystick():Length() ~= 0)
if likelygamepad then
input.pad = true
input.mouse = false
end
local shootkeys = {Keyboard.KEY_UP, Keyboard.KEY_DOWN, Keyboard.KEY_LEFT, Keyboard.KEY_RIGHT}
for i = 1, 4 do
if Input.IsButtonTriggered(shootkeys[i], indx) then
input.pad = false
end
end
--log(Input.IsActionPressed(ButtonAction.ACTION_BOMB, 0) or Input.IsActionPressed(ButtonAction.ACTION_BOMB, 1))
local playerframe = false
if input.lastframe ~= player.FrameCount then
playerframe = true
end
input.lastframe = player.FrameCount
--ignore inputs on pause
if game:IsPaused() then
input.cantact = true
--input.cantshoot = true
--not paused
else
local keyboard = false
if (indx == 0 and gSET.Player1Keyboard) or (indx == 1 and gSET.Player2Keyboard) then
keyboard = true
end
--get control method
if keyboard then
if Input.IsMouseBtnPressed(Mouse.MOUSE_BUTTON_LEFT)
or Input.IsMouseBtnPressed(Mouse.MOUSE_BUTTON_MIDDLE)
or Input.IsMouseBtnPressed(Mouse.MOUSE_BUTTON_RIGHT) then
input.mouse = true
input.pad = false
end
if math.abs(shootinput.X) > gSET.DeadZone or math.abs(shootinput.Y) > gSET.DeadZone then
input.mouse = false
end
else
input.mouse = false
end
--main player only
if pnum == 0 then
--num keys
local numkeys = {Keyboard.KEY_0, Keyboard.KEY_1, Keyboard.KEY_2, Keyboard.KEY_3, Keyboard.KEY_4, Keyboard.KEY_5, Keyboard.KEY_6, Keyboard.KEY_7, Keyboard.KEY_8, Keyboard.KEY_9}
if playerframe then
input.numkey = false
end
for i=1, #numkeys do
if keyboard and Input.IsButtonTriggered(numkeys[i], indx) then
input.numkey = i - 1
end
end
--attache
local action = false
if Input.IsActionPressed(ButtonAction.ACTION_BOMB, indx) --[[or (Input.IsButtonPressed(Keyboard.KEY_LEFT_SHIFT, indx) and keyboard)]] then
action = true
end
if playerframe then
input.actionpress = false
input.actiontap = false
input.actionrelease = false
end
if action then
if input.action < 0 then
input.actionpress = true
end
input.action = math.max(input.action + 1, 1)
else
if input.action > 0 then
input.actiontime = input.action
input.actionrelease = true
end
input.action = math.min(input.action - 1, -1)
end
--cancel action
if playerframe and not action then
input.cantact = false
elseif input.cantact then
input.cantact = true
input.action = 0
input.actionpress = false
input.actionrelease = false
end
end
--aim direction
local shoot = false
if Input.IsMouseBtnPressed(Mouse.MOUSE_BUTTON_LEFT) and keyboard then
input.mousepress = math.max(0, input.mousepress + 1)
else
input.mousepress = 0
end
local aim = shootinput:Normalized() or Vector(0, 0)
local aimpress
input.aimpoint = player.Position
if math.abs(aim.X) <= gSET.DeadZone and math.abs(aim.Y) <= gSET.DeadZone then
if input.mouse then
aim = (Isaac.ScreenToWorld(Input.GetMousePosition()) - (d.aimfrompoint or player.Position)):Normalized()
input.aimpoint = Isaac.ScreenToWorld(Input.GetMousePosition())
else
input.aimpoint = player.Position + (aim * 40)
aim = false
end
end
if playerframe then
input.aimpress = false
input.shootpress = false
input.shootrelease = false
end
if aim then
if input.mouse then
if input.mousepress > 0 then
shoot = true
aimpress = aim
if input.mousepress == 1 then
input.aimpress = true
input.shootpress = true
end
end
else
shoot = true
aimpress = aim
if not input.aimdir then
input.aimpress = true
input.shootpress = true
end
end
end
if not shoot then
if input.shoot then
input.shootrelease = true
end
end
input.shoot = shoot
input.aimdir = aim
if not (d.mygun and d.mygun.lockrotwhenfiring and d.guncontrol.aiming) then
input.lastaimdir = aim or input.lastaimdir
end
if d.mygun and d.mygun.digitalaim then
input.lastaimdir = Vector.FromAngle(math.floor((input.lastaimdir:GetAngleDegrees() / 90) + 0.5) * 90)
end
input.lastactiveaimdir = aimpress or input.lastactiveaimdir
--cancel shooting
if playerframe and not (input.shoot or input.shootrelease) then
input.cantshoot = false
elseif input.cantshoot then
input.cantshoot = true
input.shootpress = false
input.shoot = false
end
--swap
if playerframe then
input.swap = false
input.swappress = false
end
if Input.IsActionPressed(ButtonAction.ACTION_DROP, indx) then
input.swap = true
end
if Input.IsActionTriggered(ButtonAction.ACTION_DROP, indx) then
input.swappress = true
end
--weapon skill
if playerframe then
input.skill = false
input.skillpress = false
end
if Input.IsButtonPressed(Keyboard.KEY_LEFT_SHIFT, indx) then
input.skill = true
end
if Input.IsButtonTriggered(Keyboard.KEY_LEFT_SHIFT, indx) then
input.skillpress = true
end
--reload
if playerframe then
input.reload = false
end
if (Input.IsButtonTriggered(Keyboard.KEY_R, indx) and keyboard)
or (Input.IsMouseBtnPressed(Mouse.MOUSE_BUTTON_MIDDLE) and keyboard) then
input.reload = true
end
--fullscreen
if playerframe then
input.fullscreen = false
end
if (Input.IsButtonTriggered(Keyboard.KEY_F, indx) and keyboard) then
input.fullscreen = true
isfullscreen = not isfullscreen
end
if (Input.IsButtonPressed(Keyboard.KEY_F, indx) and keyboard) then
input.holdfullscreen = input.holdfullscreen or 0 + 1
if input.holdfullscreen == 120 then
isfullscreen = not isfullscreen
end
else
input.holdfullscreen = 0
end
--quick knife
local wasknife = input.knife
if playerframe then
input.knifepress = false
input.knifedoublepress = false
end
if input.mouse and Input.IsMouseBtnPressed(Mouse.MOUSE_BUTTON_RIGHT) then
if not input.knife then
local prevtime = input.knifepresstime
input.knifepress = true
input.knifepresstime = game:GetFrameCount()
if input.knifepresstime - prevtime < 12 then
input.knifedoublepress = true
end
end
input.knife = true
elseif playerframe then
input.knife = false
end
--scroll wheel
if keyboard then
--never mind I guess there's no scroll wheel support
end
--test debug tests for testing
for i, bind in pairs(cmdbind) do
if Input.IsButtonTriggered(string.byte(i), indx) then
Isaac.ExecuteCommand(bind)
end
end
--timer
input.timer = input.timer + 1
local lad = input.lastaimdir:Normalized()
input.face = {
math.max(lad.X * -1, 0),
math.max(lad.X, 0),
math.max(lad.Y * -1, 0),
math.max(lad.Y, 0),
}
--
mouseinput = input.mouse
padinput = input.pad
end
end
--menu
if pnum == 0 then
local menu = input.menu
menu.toggle = false
menu.up = false
menu.down = false
menu.left = false
menu.right = false
menu.dleft = false
menu.dright = false
menu.confirm = false
menu.back = false
menu.click = false
menu.mousemove = false
if not game:IsPaused() then
if Input.GetMousePosition().X ~= menu.mousepos.X or Input.GetMousePosition().Y ~= menu.mousepos.Y then
menu.mousemove = true
end
if Input.IsMouseBtnPressed(Mouse.MOUSE_BUTTON_LEFT) then
menu.drag = menu.drag + (Input.GetMousePosition() - menu.mousepos)
if menu.drag.X < -25 then
menu.drag = Vector(0, 0)
menu.dright = true
elseif menu.drag.X > 25 then
menu.drag = Vector(0, 0)
menu.dleft = true
end
else
menu.drag = Vector(0, 0)
end
if Input.IsButtonTriggered(Keyboard.KEY_G, indx) or Input.IsButtonTriggered(Keyboard.KEY_I, indx) then
menu.toggle = true
end
if Input.IsButtonTriggered(Keyboard.KEY_UP, indx) or
Input.IsButtonTriggered(Keyboard.KEY_W, indx) or
(menu.holdup >= 18 and menu.holdup % 6 == 0) then
menu.up = true
end
if Input.IsButtonTriggered(Keyboard.KEY_DOWN, indx) or
Input.IsButtonTriggered(Keyboard.KEY_S, indx) or
(menu.holddown >= 18 and menu.holddown % 6 == 0) then
menu.down = true
end
if Input.IsButtonTriggered(Keyboard.KEY_LEFT, indx) or
Input.IsButtonTriggered(Keyboard.KEY_A, indx) or
(menu.holdleft >= 18 and menu.holdleft % 6 == 0) then
menu.left = true
end
if Input.IsButtonTriggered(Keyboard.KEY_RIGHT, indx) or
Input.IsButtonTriggered(Keyboard.KEY_D, indx) or
(menu.holdright >= 18 and menu.holdright % 6 == 0) then
menu.right = true
end
if Input.IsButtonTriggered(Keyboard.KEY_ENTER, indx) or
Input.IsButtonTriggered(Keyboard.KEY_E, indx) or
Input.IsButtonTriggered(Keyboard.KEY_SPACE, indx) then
menu.confirm = true
end
if Input.IsButtonTriggered(Keyboard.KEY_BACKSPACE, indx) or
Input.IsButtonTriggered(Keyboard.KEY_Q, indx) or
(Input.IsMouseBtnPressed(Mouse.MOUSE_BUTTON_RIGHT) and not menu.mouse2) then
menu.back = true
end
if (Input.IsMouseBtnPressed(Mouse.MOUSE_BUTTON_LEFT) and not menu.mouse1) then
menu.click = true
end
menu.holdup = ((Input.IsButtonPressed(Keyboard.KEY_UP, indx) or Input.IsButtonPressed(Keyboard.KEY_W, indx)) and menu.holdup + 1) or 0
menu.holddown = ((Input.IsButtonPressed(Keyboard.KEY_DOWN, indx) or Input.IsButtonPressed(Keyboard.KEY_S, indx)) and menu.holddown + 1) or 0
menu.holdleft = ((Input.IsButtonPressed(Keyboard.KEY_LEFT, indx) or Input.IsButtonPressed(Keyboard.KEY_A, indx)) and menu.holdleft + 1) or 0
menu.holdright = ((Input.IsButtonPressed(Keyboard.KEY_RIGHT, indx) or Input.IsButtonPressed(Keyboard.KEY_D, indx)) and menu.holdright + 1) or 0
end
menu.mouse1 = Input.IsMouseBtnPressed(Mouse.MOUSE_BUTTON_LEFT)