-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.lua
1286 lines (1146 loc) · 41.6 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
--StartDebug();
Agony = RegisterMod("The Agony of Isaac", 1);
local json = require("json")
--Constants
Agony.ETERNAL_SPAWN_CHANCE = 0.2 --Eternals spawn chance constant
--Register Agony's IDs
require("AgonyIDs")
Agony.ENUMS = require("ExtraEnums")
Agony.Pedestals = Agony.ENUMS.Pedestals --shortcuts
Agony.CocoonVariant = Agony.ENUMS.CocoonVariant
Agony.EnemySubTypes = Agony.ENUMS.EnemySubTypes
Agony.TearSubTypes = Agony.ENUMS.TearSubTypes
Agony.Callbacks = Agony.ENUMS.Callbacks
Agony.JumpVariant = Agony.ENUMS.JumpVariant
--Systems
require("code/Systems/HelperFunctions")
require("code/Systems/RoomFairness")
--SaveData
local newestSaveVer = 3
if Agony:HasData() then
saveData = json.decode(Agony:LoadData())
if saveData.saveVer == nil or saveData.saveVer ~= newestSaveVer then
saveData = {saveVer = newestSaveVer}
end
else
saveData = {saveVer = newestSaveVer}
end
saveData.theWay = saveData.theWay or {}
saveData.LSD = saveData.LSD or {}
saveData.bloodyNut = saveData.bloodyNut or {}
saveData.luckyEgg = saveData.luckyEgg or {}
saveData.despair = saveData.despair or {}
saveData.placeholder = saveData.placeholder or {}
saveData.cherry = saveData.cherry or {}
saveData.delusion = saveData.delusion or {}
saveData.saintsHood = saveData.saintsHood or {}
--unlocks and stuff
saveData.lockedItems = saveData.lockedItems or {}
saveData.unlockFlags = saveData.unlockFlags or {}
saveData.unlockFlags.Hannah = saveData.unlockFlags.Hannah or Agony.ENUMS.DefUnlockFlags
unlockBoss = nil
--respawnV2's vars
local ent_before = {};
local rspwn_allow = false;
saveData.spwn_list = saveData.spwn_list or {}; --either load list from save, or make an empty one
saveData.rseed_list = saveData.rseed_list or {};
local level_seed_backup = 666;
local redo = false;
local redo2 = false;
local glowingHourglass_allow = true;
local respawnIDs = { --holds all IDs that need to be respawned
-- EntityType.AGONY_ETYPE_TREASURE_HOARDER,
EntityType.AGONY_ETYPE_YELLOW_BLOCK
}
--spritesToRender table
spritesToRender = {}
--All custom pedestals that need to stay that way
pedestalsToRender = {}
--pickups
pickUpTable = {}
pickUpTree = {}
--tearProjectiles
tearTable = {}
--Helper Callbacks
callbackTable = {}
--Delayed Functions
local dfTime = 0
delayedFunctions = {}
--make the game save the saveData table
function Agony:SaveNow()
Isaac.SaveModData(Agony, json.encode(saveData));
end
--Eternal al list
local EternalsList = {}
function Agony:AddEternal(Type,Variant,Name,Danger)
if EternalsList[Type] == nil then
EternalsList[Type] = {[Variant] = {name = Name, danger = Danger or 20}}
else
EternalsList[Type][Variant] = {name = Name, danger = Danger or 20}
end
end
function Agony:getEternalList()
return EternalsList
end
function Agony:HasEternalSubtype(Type,Variant)
return EternalsList[Type] ~= nil and EternalsList[Type][Variant] ~= nil
end
function Agony:IsEternal(Type,Variant,Subtype)
return Agony:HasEternalSubtype(Type,Variant) and Subtype == 15
end
function Agony:IsEntityEternal(ent)
return Agony:HasEternalSubtype(ent.Type,ent.Variant) and ent.SubType == 15
end
function Agony:getEternal(Type,Variant)
if Agony:HasEternalSubtype(Type,Variant) then
return EternalsList[Type][Variant]
end
return nil
end
function Agony:respawnV2()
local room = Game():GetRoom();
local level = Game():GetLevel();
local level_seed = level:GetDungeonPlacementSeed(); --level identification
local room_seed = room:GetSpawnSeed(); --for room identification
--debug_text = tostring(room:IsClear()) .. " " .. tostring(room:IsFirstVisit()) --room_seed .. " | " .. level_seed .. " | GameFrmcnt: " .. Game():GetFrameCount();-- " | RoomFrmcnt: " .. room:GetFrameCount() .. " | GameFrmcnt: " .. Game():GetFrameCount() .. " | IsClear: " .. tostring(room:IsClear());
--debug_text = Isaac.LoadModData(Agony) .. " | " .. tostring(Isaac.HasModData(Agony));
if(Isaac.HasModData(Agony) == true and Game():GetFrameCount() > 1 and level_seed_backup == 666) then --restore data when continuing run after having the game closed
--spwn_list = string_totable(Isaac.LoadModData(Agony));
--saveData.spwn_list = ;
level_seed_backup = level_seed;
rspwn_allow = true;
end
if(Game():GetFrameCount() == 1 or (level_seed ~= level_seed_backup and Game():GetFrameCount() > 1)) then --reset vars and delete savedata when restarting run and entering a new level
saveData.spwn_list = {};
saveData.rseed_list = {};
rspwn_allow = false;
glowingHourglass_allow = true;
ent_before = {};
--Isaac.RemoveModData(Agony);
Agony:SaveNow();
level_seed_backup = level_seed;
end
for i = 1, #saveData.spwn_list, 6 do
--Isaac.RenderText(spwn_list[i], 400, 100 + ((i / 6) *10), 255, 0, 0, 255);
if (room:IsFirstVisit() == false and room:IsClear() == true and saveData.spwn_list[i] == room_seed and room:GetFrameCount() == 1) then
rspwn_allow = true;
end
end
for i=1, #saveData.rseed_list do
if (saveData.rseed_list[i] == room_seed) then
glowingHourglass_allow = false;
end
end
if (redo == true) then
local tmp = {};
for i=1, #saveData.spwn_list, 6 do
if (saveData.spwn_list[i] ~= room_seed) then --save all entries from other rooms
table.insert(tmp, 1, saveData.spwn_list[i]);
table.insert(tmp, 2, saveData.spwn_list[i+1]);
table.insert(tmp, 3, saveData.spwn_list[i+2]);
table.insert(tmp, 4, saveData.spwn_list[i+3]);
table.insert(tmp, 5, saveData.spwn_list[i+4]);
table.insert(tmp, 6, saveData.spwn_list[i+5]);
end
end
saveData.spwn_list = tmp; --removes all entries of the current room
redo = false;
redo2 = true; --allow recreation of entries in current room
end
if (room:IsFirstVisit() == false and room:IsClear() == true and rspwn_allow == true) then --run only if this room truly has been visited before and actually cleared (not skipped with e.g. bombs)
for i = 1, #saveData.spwn_list, 6 do
if (saveData.spwn_list[i] == room_seed) then
Isaac.Spawn(saveData.spwn_list[i+1], saveData.spwn_list[i+2], saveData.spwn_list[i+3], Vector(saveData.spwn_list[i+4], saveData.spwn_list[i+5]), Vector(0,0), Isaac.GetPlayer(0));
end
end
rspwn_allow = false; --avoid looping the respawn and remove
elseif ((room:IsFirstVisit() == true and room:GetFrameCount() == 1 and glowingHourglass_allow == true) or redo2 == true) then --check if new room has respawnable entity inside, only once on the first room entry
ent_before = Isaac.GetRoomEntities();
table.insert(saveData.rseed_list, 1 ,room_seed)
for i = 1, #ent_before do
for j=1, #respawnIDs do
if (ent_before[i].Type == respawnIDs[j]) then
table.insert(saveData.spwn_list, 1, room_seed);
table.insert(saveData.spwn_list, 2, ent_before[i].Type);
table.insert(saveData.spwn_list, 3, ent_before[i].Variant);
table.insert(saveData.spwn_list, 4, ent_before[i].SubType);
table.insert(saveData.spwn_list, 5, ent_before[i].Position.X);
table.insert(saveData.spwn_list, 6, ent_before[i].Position.Y);
end
end
end
--Isaac.SaveModData(Agony, table_tostring(spwn_list)); --save the latest table for the case of game exit
redo2 = false;
Agony:SaveNow();
elseif (room:GetFrameCount() > 10 and glowingHourglass_allow == false) then
glowingHourglass_allow = true;
end
end
--recreates entries for spwn_list of current room
function Agony:redoSpawnList()
redo = true;
end
--Caclulates DamagePerSecond for current Isaac-stats
--Doesn't account for tear-effects like burn, double shot
function Agony:calcDPS(player)
return (player.Damage / player.MaxFireDelay) * 30.0
end
--Caclulates DamagePerFrame for current Isaac-stats
--Doesn't account for tear-effects like burn, double shot
function Agony:calcDPF(player)
return player.Damage / player.MaxFireDelay
end
--Calculates the velocity a tear needs to have to hit a target Position
function Agony:calcTearVel(sourcePos, targetPos, multiplier)
return (targetPos - sourcePos):Normalized() * multiplier;
end
--returns the nearest Enemy
function Agony:getNearestEnemy(sourceEnt, whiteList, blackList)
whiteList = whiteList or {0}
blackList = blackList or {}
local entities = Isaac.GetRoomEntities();
local smallestDist = nil;
local nearestEnt = nil;
::redo::
if blackList.mode == "only_same_ent" then
local tmp = {}
for i=1, #entities do
if entities[i].Type == sourceEnt.Type and entities[i].Variant == sourceEnt.Variant and entities[i].SubType == sourceEnt.SubType then
table.insert(tmp, 1, entities[i])
end
end
entities = tmp
elseif blackList.mode == "only_whitelist" then
local tmp = {}
for i=1, #entities do
for j=1, #whiteList do
if entities[i].Type == whiteList[j] then
table.insert(tmp, 1, entities[i])
end
end
end
entities = tmp
elseif blackList.mode == nil then
for i=1, #blackList do
local tmp = {}
for j=1, #entities do
if entities[j].Type ~= blackList[i] then
table.insert(tmp, 1, entities[j])
end
end
entities = tmp
end
else
blackList.mode = nil
goto redo
end
for i = 1, #entities do
for j = 1, #whiteList do
if (entities[i].Index ~= sourceEnt.Index and (entities[i]:IsVulnerableEnemy() or entities[i].Type == whiteList[j])) then
if (smallestDist == nil or sourceEnt.Position:Distance(entities[i].Position) < smallestDist) then
smallestDist = sourceEnt.Position:Distance(entities[i].Position);
nearestEnt = entities[i];
end
end
end
end
if (nearestEnt == nil) then
return sourceEnt;
else
return nearestEnt;
end
end
--returns the furthest enemy
function Agony:getFurthestEnemy(sourceEnt, whiteList, blackList)
whiteList = whiteList or {0}
blackList = blackList or {}
local entities = Isaac.GetRoomEntities();
local largestDist = nil;
local furthestEnt = nil;
::redo::
if blackList.mode == "only_same_ent" then
local tmp = {}
for i=1, #entities do
if entities[i].Type == sourceEnt.Type and entities[i].Variant == sourceEnt.Variant and entities[i].SubType == sourceEnt.SubType then
table.insert(tmp, 1, entities[i])
end
end
entities = tmp
elseif blackList.mode == "only_whitelist" then
local tmp = {}
for i=1, #entities do
for j=1, #whiteList do
if entities[i].Type == whiteList[j] then
table.insert(tmp, 1, entities[i])
end
end
end
entities = tmp
elseif blackList.mode == nil then
for i=1, #blackList do
local tmp = {}
for j=1, #entities do
if entities[j].Type ~= blackList[i] then
table.insert(tmp, 1, entities[j])
end
end
entities = tmp
end
else
blackList.mode = nil
goto redo
end
for i = 1, #entities do
for j=1, #whiteList do
if entities[i].Index ~= sourceEnt.Index and (entities[i]:IsVulnerableEnemy() or entities[i].Type == whiteList[j]) then
if (largestDist == nil or sourceEnt.Position:Distance(entities[i].Position) > largestDist) then
largestDist = sourceEnt.Position:Distance(entities[i].Position);
furthestEnt = entities[i];
end
end
end
end
if (furthestEnt == nil) then
return sourceEnt;
else
return furthestEnt;
end
end
--Display Giant Book anim take 2
function Agony:AnimGiantBook(bookSprite, animName, customAnm2)
customAnm2 = customAnm2 or "giantbook.anm2"
local pos = Vector((640-128-48)/2, (460-128-48)/2)
local rS = {
[0] = "gfx/ui/giantbook/" .. tostring(bookSprite),
}
local aQ = {
{
Name = tostring(animName),
Loops = 1
},
--[[ some testing stuff for the rewritten addToRender()
{
Name = "Idle",
Loops = 3,
killLoop = 10
},
{
Name = "Shake",
Loops = -1,
killLoop = 120
}]]
}
Agony:addToRender("gfx/ui/giantbook/" .. tostring(customAnm2), aQ, pos, 30, rS)
end
--Render all sprites in spritesToRender
function Agony:renderSprites()
for _,spriteTable in pairs(spritesToRender) do
local sprite = spriteTable.Sprite
local renderPos = spriteTable.Position
local anims = spriteTable.Animations
local fps = spriteTable.fps or 60
::reload::
local animObj = anims[1]
if animObj ~= nil then
animObj.Name = tostring(animObj.Name)
--debug_text = tostring(animObj.Name) .. " " .. tostring(animObj.Loops) .. " " .. tostring(animObj.killLoop) .. " " .. tostring(Game():GetFrameCount())
if not sprite:IsPlaying(animObj.Name) and animObj.Loops > 0 then --play one loop
sprite:Play(animObj.Name, true)
animObj.Loops = animObj.Loops - 1
elseif sprite:IsFinished(animObj.Name) and animObj.Loops == 0 then --remove if no more loops
table.remove(anims, 1)
goto reload
elseif not sprite:IsPlaying(animObj.Name) and animObj.Loops < 0 and animObj.killLoop == nil then --loop forever if loop is negative and no killLoop is given
sprite:Play(animObj.Name, true)
elseif animObj.killLoop ~= nil and animObj.killLoop > 0 then --if killLoop is greater than zero, play until is zero
if animObj.killLoopBackup == nil then
animObj.killLoopBackup = animObj.killLoop
end
if not sprite:IsPlaying(animObj.Name) then
sprite:Play(animObj.Name, true)
end
if Game():GetFrameCount() % (60/fps) == 0 then --only count rendered frames
animObj.killLoop = animObj.killLoop - 1
end
elseif animObj.killLoop ~= nil and animObj.killLoop <= 0 then
if animObj.Loops > 0 then --start a new loop
sprite:Play(animObj.Name, true)
animObj.killLoop = animObj.killLoopBackup
animObj.Loops = animObj.Loops - 1
elseif animObj.Loops <= 0 then --remove if no more loops
table.remove(anims, 1)
goto reload
end
end
end
sprite:Render(renderPos, Vector(0,0), Vector(0,0))
if Game():GetFrameCount() % (60/fps) == 0 and not Game():IsPaused() then
sprite:Update()
end
if #anims == 0 then
spritesToRender[_] = nil
end
end
end
--Add sprite to render list
-- animQueue
-- / \
-- animTbl1 animTbl2
-- / | \
-- Name Loops *killLoop
--
function Agony:addToRender(anm2, animQueue, pos, fps, replaceGfx)
anm2 = tostring(anm2)
pos = pos or Vector(0,0)
fps = fps or 60
replaceGfx = replaceGfx or {}
local sprite = Sprite()
sprite:Load(anm2, false) --init sprite
for layerId, gfx in pairs(replaceGfx) do
sprite:ReplaceSpritesheet(layerId, tostring(gfx))
end
sprite:LoadGraphics() --replace spritesheets
spritesToRender[#spritesToRender+1] = { --add to tbl
Sprite = sprite,
Position = pos,
Animations = animQueue,
fps = fps
}
return spritesToRender[#spritesToRender].Sprite, #spritesToRender --returns sprite and the index in the table
end
--clears savedata on new run
function Agony:clearSaveData()
if Game():GetFrameCount() <= 1 then
for group,_ in pairs(saveData) do
if group ~= "saveVer" and group ~= "lockedItems" and group ~= "unlockFlags" then
saveData[group] = {}
end
end
Agony:SaveNow()
Isaac.DebugString("Reset Agony Savedata")
end
end
--fixes the bug bug that allowed charmed enemies to persist through rooms when restarting the game (#128 on git)
--this is a bug in the actual game, wtf nicolo, why do I have to fix this
function Agony:removeFriendlyEnemies()
local ents = Isaac.GetRoomEntities()
--debug_text = Game():GetFrameCount()
for _,entity in pairs(ents) do
if entity:HasEntityFlags(EntityFlag.FLAG_FRIENDLY | EntityFlag.FLAG_CHARM) and not (entity.Type == 23 and entity.Variant == 0 and entity.SubType == 1) then --not 23.0.1 because that's that leech item
entity:Remove()
end
end
end
function Agony:dataCopy(originData,targetData)
for k, v in pairs(originData) do
targetData[k] = v
end
end
--returns the items the player currently has
--a list of items can be specified to check if the player has any of these
function Agony:getCurrentItems(pool)
local itemCfg = Isaac.GetItemConfig()
local numCol = #(itemCfg:GetCollectibles())
if type(numCol) ~= "number" then
numCol = 9999 --Mac seems to have trouble with this number thing
end
pool = pool or {}
local currList = {}
local player = Isaac.GetPlayer(0)
for id=1, numCol do
if itemCfg:GetCollectible(id) ~= nil then
if #pool == 0 then
if player:HasCollectible(id) then
table.insert(currList, id)
end
else
for _, poolId in pairs(pool) do
if id == poolId and player:HasCollectible(id) then
table.insert(currList, id)
end
end
end
end
end
--debug_tbl1 = currList
return currList
end
--these are some Flag manipulation functions, they are similar to the EntityFlags functions
function Agony:AddFlags(flagSource, flags)
return flagSource | flags
end
function Agony:HasFlags(flagSource, flags)
return (flagSource & flags) ~= 0
end
function Agony:ClearFlags(flagSource, flags)
return flagSource & (~flags)
end
--gets the sprite path of a collectible
function Agony:getItemGfxFromId(id)
--id = tonumber(id) or 1
local item = Isaac.GetItemConfig():GetCollectible(id)
return item.GfxFileName
end
--loads a custom pedestal sprite
function Agony:loadCustomPedestal(ped, pType, data, index)
pType = pType or 0
index = index or #pedestalsToRender+1
data = data or ped:GetData()
local sprite = ped:GetSprite()
for k, v in pairs(data) do
ped:GetData()[k] = v
end
sprite:Load("gfx/Items/Pick Ups/Pedestals/animation.anm2", true)
sprite:ReplaceSpritesheet(1, Agony:getItemGfxFromId(ped.SubType))
sprite:LoadGraphics()
sprite:SetOverlayFrame("Alternates", pType)
sprite:Play("Idle")
pedestalsToRender[index] = {ped, pType, ped:GetData()}
end
--reload custom pedestal gfx when the item changes
function Agony:reloadPedestal()
for index, pedTbl in pairs(pedestalsToRender) do
local ped = pedTbl[1]
local pType = pedTbl[2]
local pData = pedTbl[3]
if ped:GetSprite():GetFilename() ~= "gfx/Items/Pick Ups/Pedestals/animation.anm2" then
Agony:loadCustomPedestal(ped, pType, pData, index)
end
if not ped:Exists() or ped:GetSprite():GetOverlayFrame() == 0 then
pedestalsToRender[index] = nil
end
end
end
function Agony:rotateTears()
local ents = Isaac.GetRoomEntities()
for i=1,#ents do
if ents[i].Type == EntityType.ENTITY_TEAR and
(ents[i].SubType == Agony.TearSubTypes.BIG_D
or ents[i].SubType == Agony.TearSubTypes.TOY_HAMMER
or ents[i].SubType == Agony.TearSubTypes.MILKMAN
or ents[i].SubType == Agony.TearSubTypes.TECH_LESS_THAN_3) then
if ents[i].Velocity.X > 0 then
ents[i]:GetSprite().Rotation = ents[i]:GetSprite().Rotation + 10
else
ents[i]:GetSprite().Rotation = ents[i]:GetSprite().Rotation - 10
end
end
end
end
function Agony:TransformationUpdate(player, trans, data, hasCostume)
if Game():GetFrameCount() == 1 then
trans.hasItem = false
trans.Items = {}
data.Items = {}
Agony:SaveNow()
end
for i = 1, #trans.requireditems do
if player:HasCollectible(trans.requireditems[i]) then
local isNew = true
for j = 1, #trans.Items do
if trans.Items[j] == trans.requireditems[i] then
isNew = false
end
end
if isNew then
table.insert(trans.Items, trans.requireditems[i])
data.Items = trans.Items
Agony:SaveNow()
end
end
end
if #trans.Items > 2 then
if trans.hasItem ~= true then
if hasCostume then
player:AddNullCostume(trans.costumeID)
end
trans.hasItem = true
--POOF!
local col = Color(255,255,255,255,0,0,0) -- Used to set the poof color
col:Reset()
Game():SpawnParticles(player.Position, EffectVariant.POOF01, 1, 1, col, 0)
end
end
end
--returns a velocity an entity must have to get closer to target
--this differs from calcTearVel() by adding small normalized vectors to an existing velocity and normalizing the result instead of just calculating a vector pointing from ent to target
--better suited for enemies because that way knockback has an effect on the enemy
function Agony:calcEntVel(ent, target, mul)
local fMul = 1
if ent:HasEntityFlags(EntityFlag.FLAG_FEAR) then
fMul = -1
end
return ent.Velocity:__add(target.Position:__sub(ent.Position):Normalized():__mul(fMul)):Normalized():__mul(mul)
end
--add a custom PickUp to the PickupHandler
--functions are optional, but it would make sense to pass a pickupF
function Agony:addPickup(type, var, sub, pickupF, spawnF, updateF)
local t = {
Type = type,
Variant = var,
SubType = sub,
onPickup = pickupF,
spawnPickup = spawnF,
onUpdate = updateF
}
--Tree structure
-- pickUpTree = table of variants
-- / \
-- varianta variantb = table of subtypes
-- / | \
-- subtypea sub_b sub_c = pickUp
--
if pickUpTree[type] == nil then
pickUpTree[type] = {}
end
if pickUpTree[type][var] == nil then
pickUpTree[type][var] = {}
end
pickUpTree[type][var][sub] = t
--Store for easy iteration
table.insert(pickUpTable, t)
end
--the main PickupHandler Function
--it runs the onPickup, spawnPickup and onUpdate functions of our custom PickUps
function Agony:updatePickups()
local ents = Isaac.GetRoomEntities()
local player = Isaac.GetPlayer(0)
local sound = SFXManager()
for _,ent in pairs(ents) do
local isAgonyPickup = false
--Check existence in pickUpTree
local variants = pickUpTree[ent.Type]
if variants ~= nil then
local subtypes = variants[ent.Variant]
if subtypes ~= nil then
local pickUpObj = subtypes[ent.SubType]
if pickUpObj ~= nil then
isAgonyPickup = true
local data = ent:GetData()
local sprite = ent:GetSprite()
--called every frame for the pickup, if an update function is given
if pickUpObj.onUpdate ~= nil then
pickUpObj:onUpdate(player, sound, data, sprite, ent)
end
--Pick up the PickUp and run the pickup code
if player.Position:Distance(ent.Position) <= player.Size + ent.Size + 8 and (data.Picked == nil or data.Picked == false) then
data.Picked = true
ent.EntityCollisionClass = EntityCollisionClass.ENTCOLL_NONE
ent.Velocity = Vector(0,0)
sprite:Play("Collect")
if pickUpObj.onPickup ~= nil then
pickUpObj:onPickup(player, sound, data, sprite, ent)
end
elseif data.Picked and sprite:GetFrame() == 6 then
ent:Remove()
end
end
end
end
--On pickup spawn
if isAgonyPickup == false and ent.FrameCount <= 1 then
for _, pickUpObj in pairs(pickUpTable) do
if pickUpObj.spawnPickup ~= nil then
pickUpObj:spawnPickup(ent, ent:GetDropRNG())
end
end
end
end
end
function Agony:TearConf()
local t = {}
t.TearFlags = 0
t.SpawnerEntity = nil
t.Height = -23
t.FallingAcceleration = 0
t.FallingSpeed = 0
t.Color = Color(1,1,1,1,0,0,0)
t.Data = {}
t.Scale = 1 --goes in 1/6 steps for the bigger tearsprite
t.Functions = {} --supported functions are onDeath, onUpdate and onHit
return t
end
function Agony:updateTears()
for i, tearObj in pairs(tearTable) do
local tear = tearObj[1]
local func = tearObj[2]
local player = Game():GetNearestPlayer(tear.Position)
local tData = tear:GetData()
if not tear:Exists() then
--run onDeath when the tear doesn't exist
if func ~= nil and func.onDeath ~= nil then
func:onDeath(tear.Position, tear.Velocity, tear.SpawnerEntity, tear)
end
tearTable[i] = nil
elseif player.Position:Distance(tear.Position) <= player.Size + tear.Size + 8 and tear.Height >= -30 then
player:TakeDamage(1, 0, EntityRef(tear), 0)
--run onHit when tear hits the player
if func ~= nil and func.onHit ~= nil then
func:onHit(tear)
end
--don't remove the tear if piercing
if not Agony:HasFlags(tear.TearFlags, TearFlags.TEAR_PIERCING) then
tear:Die()
end
elseif tData.Agony ~= nil and tData.Agony.homing then
tear.Velocity = Agony:calcTearVel(tear.Position, player.Position, tear.Velocity:Length())
end
--run onUpdate on every frame of existance
if tear:Exists() and func ~= nil and func.onUpdate ~= nil then
func:onUpdate(tear)
end
end
end
function Agony:deleteTears()
tearTable = {}
end
function Agony:fireTearProj(var, sub, pos, vel, tearConf)
local t = Isaac.Spawn(EntityType.ENTITY_TEAR, var, sub, pos, vel, tearConf.SpawnerEntity):ToTear()
t.SpawnerEntity = tearConf.SpawnerEntity
if tearConf.SpawnerEntity ~= nil then
t.SpawnerType = tearConf.SpawnerEntity.Type
t.SpawnerVariant = tearConf.SpawnerEntity.Variant
end
t.EntityCollisionClass = EntityCollisionClass.ENTCOLL_PLAYERONLY
t.TearFlags = tearConf.TearFlags or t.TearFlags
t.Height = tearConf.Height or -23
t.FallingAcceleration = tearConf.FallingAcceleration or 0
t.FallingSpeed = tearConf.FallingSpeed or 0
t.Color = tearConf.Color or t.Color
t.Scale = tearConf.Scale or 1
if tearConf.Data ~= nil then
Agony:dataCopy(tearConf.Data, t:GetData())
end
table.insert(tearTable, {t, tearConf.Functions})
end
function Agony:fireMonstroTearProj(var, sub, pos, vel, tearConf, num, rng, overrideConf)
overrideConf = overrideConf or {}
for i = 1, num do
local deg = rng:RandomInt(21)-10 -- -10 to 10
local speed = vel:Length() * (1+((rng:RandomInt(8)+1)/10))
--Monstro shot standards
tearConf.FallingAcceleration = overrideConf.FallingAcceleration or 0.5
tearConf.FallingSpeed = overrideConf.FallingSpeed or (-5 - rng:RandomInt(11)) -- -15 to -5
tearConf.Scale = overrideConf.Scale or (1 + (rng:RandomInt(5)-2)/6) -- 4/6 to 8/6
Agony:fireTearProj(var, sub, pos, vel:Normalized():Rotated(deg) * speed, tearConf)
end
end
--Kinda like Ministro. Not fully.
function Agony:fireMinistroTearProj(var, sub, pos, vel, tearConf, num, rng, overrideConf)
overrideConf = overrideConf or {}
for i = 1, num do
local deg = rng:RandomInt(32)-15 -- -10 to 10
local speed = vel:Length() * (rng:RandomFloat()+0.5)
--Monstro shot standards
tearConf.FallingAcceleration = overrideConf.FallingAcceleration or 0.8
tearConf.FallingSpeed = overrideConf.FallingSpeed or (-7 - rng:RandomInt(10))
tearConf.Scale = overrideConf.Scale or (1 + (rng:RandomInt(4)-2)/8)
Agony:fireTearProj(var, sub, pos, vel:Normalized():Rotated(deg) * speed, tearConf)
end
end
function Agony:fireIpecacTearProj(var, sub, pos, vel, tearConf, overrideConf)
overrideConf = overrideConf or {}
tearConf.TearFlags = tearConf.TearFlags or 0
if not Agony:HasFlags(tearConf.TearFlags, TearFlags.TEAR_EXPLOSIVE) then
tearConf.TearFlags = Agony:AddFlags(tearConf.TearFlags, TearFlags.TEAR_EXPLOSIVE)
end
--Ipecec tear standards
tearConf.Color = overrideConf.Color or Color(0.5, 1, 0.5, 1, 0, 0, 0)
tearConf.Height = overrideConf.Height or -35
tearConf.FallingAcceleration = overrideConf.FallingAcceleration or 0.6
tearConf.FallingSpeed = overrideConf.FallingSpeed or -10
tearConf.Scale = overrideConf.Scale or 1
tearConf.Scale = tearConf.Scale * (1 + 1/3)
Agony:fireTearProj(var, sub, pos, vel, tearConf)
end
function Agony:fireHomingTearProj(var, sub, pos, vel, tearConf, overrideConf)
overrideConf = overrideConf or {}
--Homing tear standards
tearConf.Color = overrideConf.Color or Color(1, 0.5, 1, 1, 0, 0, 0)
tearConf.Data.Agony = tearConf.Data.Agony or {}
tearConf.Data.Agony.homing = true
Agony:fireTearProj(var, sub, pos, vel, tearConf)
end
function Agony:addHelperCallback(callbackType, func, arg)
if callbackTable[callbackType] == nil then
callbackTable[callbackType] = {}
end
table.insert(callbackTable[callbackType], {func, arg})
end
function Agony:triggerCallback(callbackType, args, callbackArg)
if callbackTable[callbackType] ~= nil then
local t = callbackTable[callbackType]
for i = 1, #t do
local func = t[i][1]
local desiredArg = t[i][2] --the wanted argument passed in addHelperCallback()
if desiredArg == nil or callbackArg == desiredArg then --only run the function if the wanted argument is passed by updateHelperCallbacks()
func(args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10]) --pass up to 10 arguments to function
end
if args.cancel == true then
break
end
end
end
return args
end
function Agony:updateHelperCallbacks()
if callbackTable[Agony.Callbacks.ENTITY_SPAWN] ~= nil then
local ents = Isaac.GetRoomEntities()
for i = 1, #ents do
if ents[i].FrameCount <= 1 then
Agony:triggerCallback(Agony.Callbacks.ENTITY_SPAWN, {ents[i]}, ents[i].Type)
end
end
end
end
function Agony:getCurrTime()
return dfTime
end
--For example:
--addDelayedFunction(Agony:GetCurrTime() + 30, function (data) DO.STUFF end, {target=69})
--30 frames later
function Agony:addDelayedFunction(time, func, data, cancelOnRoomChange)
local t = {
time = time,
func = func,
data = data,
cancelOnRoom = cancelOnRoomChange
}
table.insert(delayedFunctions, t)
end
function Agony:updateDelayedFunctions()
for k,v in pairs(delayedFunctions) do
if v.time <= dfTime then
v.func(v.data)
delayedFunctions[k] = nil
end
end
dfTime = dfTime + 1
end
function Agony:cancelRoomFunctions()
for k,v in pairs(delayedFunctions) do
if v.cancelOnRoom == true then
delayedFunctions[k] = nil
end
end
end
function Agony:makeSplat(pos, var, size, ent)
if size > 1 then
local num = 2^(2+size) - 8 --calculate number of spawns
local power = 1 --used to know which ring we're on
for i=1, num do
local sub = 2^(2+power) - 8 --need to clean i of the previous ring's numbers for incPowerTrig
local cleanI = i-sub-1
local splatNum = 2^(2+power) --how many splats the current ring contains
if cleanI == splatNum then --start new ring
power = power+1
end
local step = math.pi*(i/(2+2^power)) --input of sin and cos
Isaac.Spawn(EntityType.ENTITY_EFFECT, var, 0, pos:__add(Vector(power*16*math.sin(step),power*16*math.cos(step))), Vector(0,0), ent)
end
else
Isaac.Spawn(EntityType.ENTITY_EFFECT, var, 0, pos, Vector(0,0), ent)
end
end
function Agony:getItemNameFromID(id)
--debug_text = tostring(Isaac.GetItemConfig():GetCollectible(id).Name)
if id > 0 then
return tostring(Isaac.GetItemConfig():GetCollectible(id).Name)
else
return "zero"
end
end
--originally wrote this for rerollLockedItems(), but then I thought of something way better
--[[function Agony:pickRandomCol(rng, poolType, includeLocked)
poolType = poolType or ItemPoolType.POOL_NULL
--local numCol = #(Isaac.GetItemConfig():GetCollectibles())
--if type(numCol) ~= "number" then
-- numCol = CollectibleType.NUM_COLLECTIBLES
--end
-- local col = 0
local col = Game():GetItemPool():GetCollectible(poolType, false, rng:GetSeed())
local colName = Agony:getItemNameFromID(col)
if not includeLocked then
while saveData.lockedItems[colName] do
col = Game():GetItemPool():GetCollectible(poolType, false, rng:GetSeed())
colName = Agony:getItemNameFromID(col)
end
end
return col
end]]
function Agony:removeLockedItems()
local itemPools = Game():GetItemPool()
for item, locked in pairs(saveData.lockedItems) do
if locked then
itemPools:RemoveCollectible(Isaac.GetItemIdByName(tostring(item)))
end