-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRunManager.lua
More file actions
5740 lines (5011 loc) · 186 KB
/
Copy pathRunManager.lua
File metadata and controls
5740 lines (5011 loc) · 186 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function CreateNewHero( prevRun, args )
local newHeroData = GetEligibleHero()
local newHero = DeepCopyTable( newHeroData )
newHero.SpeakerId = 1
newHero.Traits = {}
newHero.RecentTraits = {}
newHero.Health = newHero.MaxHealth
newHero.InvulnerableFlags = {}
newHero.PersistentInvulnerableFlags = {}
newHero.SuperMeter = 0
newHero.SuperMeterLimit = CalculateSuperMeter()
if args ~= nil and args.WeaponName ~= nil then
newHero.Weapons[args.WeaponName] = true
elseif prevRun ~= nil then
newHero.Weapons = ShallowCopyTable( prevRun.Hero.Weapons )
end
local damageIncrease = 1 + GetNumMetaUpgrades( "EnemyDamageShrineUpgrade" ) * ( MetaUpgradeData.EnemyDamageShrineUpgrade.ChangeValue - 1 )
AddIncomingDamageModifier( newHero,
{
Name = "EnemyDamageShrineUpgrade",
NonTrapDamageTakenMultiplier = damageIncrease
})
local trapDamageIncrease = 1 + GetNumMetaUpgrades( "TrapDamageShrineUpgrade" ) * ( MetaUpgradeData.TrapDamageShrineUpgrade.ChangeValue - 1 )
AddIncomingDamageModifier( newHero,
{
Name = "TrapDamageShrineUpgrade",
TrapDamageTakenMultiplier = trapDamageIncrease
})
newHero.RallyHealth.ConversionPercent = newHero.RallyHealth.ConversionPercent + ( GetNumMetaUpgrades( "RallyMetaUpgrade" ) * ( MetaUpgradeData.RallyMetaUpgrade.ChangeValue - 1 ))
if args ~= nil and args.TraitNames ~= nil then
for k, traitName in pairs( args.TraitNames ) do
AddTrait( newHero, traitName )
end
end
return newHero
end
function CalculateStartingMoney()
return GetTotalHeroTraitValue( "BonusMoney" ) + GetNumMetaUpgrades("MoneyMetaUpgrade") * MetaUpgradeData.MoneyMetaUpgrade.ChangeValue
end
function InitHeroLastStands( newHero )
for s = 1, GetNumMetaUpgrades("ExtraChanceMetaUpgrade" ) do
for i = 1, MetaUpgradeData["ExtraChanceMetaUpgrade"].ChangeValue do
AddLastStand({
Unit = newHero,
IncreaseMax = true,
Icon = "ExtraLifeZag",
WeaponName = "LastStandMetaUpgradeShield",
HealFraction = 0.5,
Silent = true
})
end
end
for s = 1, GetNumMetaUpgrades("ExtraChanceReplenishMetaUpgrade" ) do
for i = 1, MetaUpgradeData["ExtraChanceReplenishMetaUpgrade"].ChangeValue do
AddLastStand({
Name = "ExtraChanceReplenishMetaUpgrade",
Unit = newHero,
IncreaseMax = true,
Icon = "ExtraLifeReplenish",
WeaponName = "LastStandMetaUpgradeShield",
HealFraction = MetaUpgradeData.ExtraChanceReplenishMetaUpgrade.HealPercent,
Silent = true
})
end
end
end
function CalculateSuperMeter()
return 100 -- this will be something fancy some day
end
function IsTraitEligible( currentRun, traitData )
if traitData.MaxAmount ~= nil and traitData.MaxAmount <= GetTraitCount(CurrentRun.Hero, traitData) then
return false
end
if not IsGameStateEligible( currentRun, traitData ) then
return
end
return true
end
function GetEligibleHero()
local eligibleHeroes = { }
local runsComplete = GetCompletedRuns()
--DebugPrint({ Text = "GetEligibleHero - Runs Complete: "..tostring(runsComplete), LogOnly = true })
for heroKey, heroData in pairs( HeroData ) do
if heroData.RequiredMinCompletedRuns ~= nil and GetCompletedRuns() < heroData.RequiredMinCompletedRuns then
-- haven't completed enough runs
--DebugPrint({ Text = "GetEligibleHero - Unavailable: (not enough runs) "..tostring(heroKey), LogOnly = true })
elseif heroData.UnavailableAfterCompletedRuns ~= nil and GetCompletedRuns() >= heroData.UnavailableAfterCompletedRuns then
-- completed too many runs
--DebugPrint({ Text = "GetEligibleHero - Unavailable: (too many runs) "..tostring(heroKey), LogOnly = true })
else
--DebugPrint({ Text = "GetEligibleHero - Available: "..tostring(heroKey), LogOnly = true })
eligibleHeroes[heroKey] = heroData
end
end
local pickedHero = GetRandomValue( eligibleHeroes )
return pickedHero
end
function StartNewGame()
DebugAssert({ Condition = GameState == nil, "Overwriting existing game state!" })
GameState = {}
GameState.WeaponHistory = {}
GameState.WeaponsTouched = {}
GameState.WeaponsUnlocked = {}
GameState.RunHistory = {}
GameState.MetaUpgrades = {}
GameState.WeaponKills = {}
GameState.LootPickups = {}
GameState.TraitsTaken = {}
GameState.QuestsViewed = {}
GameState.QuestStatus = {}
GameState.Cosmetics = {}
GameState.CosmeticsViewed = {}
GameState.CosmeticsAdded = {}
GameState.MusicTracksViewed = {}
-- Default starting cosmetics
AddCosmetic( "Cosmetic_DrapesRed" )
AddCosmetic( "Cosmetic_LaurelsRed" )
AddCosmetic( "Cosmetic_WallWeaponBident" )
AddCosmetic( "Cosmetic_SouthHallTrimBrown" )
AddCosmetic( "Cosmetic_HouseCandles01" )
AddCosmetic( "/Music/MusicPlayer/MainThemeMusicPlayer" )
AddCosmetic( "/Music/MusicPlayer/MusicExploration4MusicPlayer" )
GameState.ScreensViewed = {}
GameState.NPCInteractions = {}
GameState.ItemInteractions = {}
GameState.EnemySpawns = {}
GameState.EnemyKills = {}
GameState.EnemyEliteAttributeKills = {}
GameState.EnemyDamage = {}
GameState.CompletedObjectiveSets = {}
GameState.ObjectivesCompleted = {}
GameState.ObjectivesFailed = {}
GameState.LastObjectiveCompletedRun = {}
GameState.LastObjectiveFailedRun = {}
GameState.HintsShown = {}
GameState.Resources = {}
GameState.LifetimeResourcesGained = {}
GameState.LifetimeResourcesSpent = {}
GameState.ShrinePointClearsComplete = {}
GameState.HeardGhostLines = {}
GameState.KeepsakeChambers = {}
GameState.ActiveMutators = {}
GameState.Onslaughts = {}
GameState.EncountersOccurredCache = {}
GameState.EncountersCompletedCache = {}
GameState.RoomCountCache = {}
GameState.WeaponUnlocks = {}
GameState.AssistUnlocks = {}
GameState.LastWeaponUpgradeData = {}
GameState.RecordClearedShrineThreshold = {}
GameState.RecordLastClearedShrineReward = {}
GameState.ClearedWithMetaUpgrades = {}
GameState.SpeechRecordContexts = {}
GameState.MetaUpgradesUnlocked = {}
GameState.MetaUpgradeStagesUnlocked = 0
GameState.MetaUpgradesSelected = {}
GameState.MetaUpgradeState = {}
for metaUpgradeName, metaUpgradeData in pairs( MetaUpgradeData ) do
if metaUpgradeData.Starting then
GameState.MetaUpgradesUnlocked[metaUpgradeName] = true
end
end
for k, metaUpgradeChoices in pairs( MetaUpgradeOrder ) do
GameState.MetaUpgradesSelected[k] = metaUpgradeChoices[1]
end
InitializeGiftData()
GameState.ReturnedRandomEligibleSourceNames = {}
GameState.PlayedRandomRunIntroData = {}
GameState.PlayedRandomRunOutroData = {}
GameState.Flags = {}
if GetConfigOptionValue({ Name = "KioskMode" }) then
GameState.Flags.KioskMode = true
else
GameState.Flags.DefaultMode = true
end
if GetConfigOptionValue({ Name = "HardMode" }) then
GameState.Flags.HardMode = true
for name, amount in pairs( HeroData.DefaultHero.HardModeForcedMetaUpgrades ) do
GameState.MetaUpgrades[name] = amount
end
for name, amount in pairs( HeroData.DefaultHero.HardModeStartingResources ) do
GameState.Resources[name] = (GameState.Resources[name] or 0) + round( amount )
--AddResource( name, amount, "HardMode", { Silent = true } )
end
end
GameState.EasyModeLevel = 0
if CurrentRun == nil then
StartNewRun()
end
end
function StartNewRun( prevRun, args )
SetupRunData()
ResetUI()
SessionState.NeedWeaponPickupBinkLoad = false
CurrentRun = {}
CurrentRun.DamageRecord = {}
CurrentRun.HealthRecord = {}
CurrentRun.ConsumableRecord = {}
CurrentRun.ActualHealthRecord = {}
CurrentRun.BlockTimerFlags = {}
CurrentRun.WeaponsFiredRecord = {}
if args ~= nil then
if args.RunOverrides ~= nil then
for key, value in pairs( args.RunOverrides ) do
CurrentRun[key] = value
end
end
CurrentRun.ForceNextEncounterData = args.Encounter
end
CurrentRun.Hero = CreateNewHero( prevRun, args )
if prevRun ~= nil and prevRun.BonusDarknessWeapon ~= nil and CurrentRun.Hero.Weapons[prevRun.BonusDarknessWeapon] then
if GameState.Cosmetics.UnusedWeaponBonusAddGems then
AddTrait( CurrentRun.Hero, "UnusedWeaponBonusTraitAddGems" )
else
AddTrait( CurrentRun.Hero, "UnusedWeaponBonusTrait" )
end
end
EquipKeepsake( CurrentRun.Hero, GameState.LastAwardTrait, { SkipNewTraitHighlight = true })
EquipAssist( CurrentRun.Hero, GameState.LastAssistTrait, { SkipNewTraitHighlight = true } )
EquipWeaponUpgrade( CurrentRun.Hero, { SkipTraitHighlight = true } )
CurrentRun.RoomHistory = {}
UpdateRunHistoryCache( CurrentRun )
CheckRunStartFlags( CurrentRun )
BuildMetaupgradeCache()
CurrentRun.RoomCreations = {}
CurrentRun.LootTypeHistory = {}
CurrentRun.NPCInteractions = {}
CurrentRun.AnimationState = {}
CurrentRun.EventState = {}
CurrentRun.ActivationRecord = {}
CurrentRun.SpeechRecord = {}
CurrentRun.TextLinesRecord = {}
CurrentRun.TriggerRecord = {}
CurrentRun.UseRecord = {}
CurrentRun.GiftRecord = {}
CurrentRun.HintRecord = {}
CurrentRun.EnemyUpgrades = {}
CurrentRun.BlockedEncounters = {}
CurrentRun.InvulnerableFlags = {}
CurrentRun.PhasingFlags = {}
-- CurrentRun.Money = CalculateStartingMoney()
CurrentRun.Money = 10000
CurrentRun.MoneySpent = 0
CurrentRun.MoneyRecord = {}
CurrentRun.BonusDarknessWeapon = GetRandomUnequippedWeapon()
CurrentRun.ActiveObjectives = {}
CurrentRun.RunDepthCache = 1
CurrentRun.GameplayTime = 0
CurrentRun.BiomeTime = 0
CurrentRun.ActiveBiomeTimer = GetNumMetaUpgrades("BiomeSpeedShrineUpgrade") > 0
CurrentRun.NumRerolls = GetNumMetaUpgrades( "RerollMetaUpgrade" ) + GetNumMetaUpgrades("RerollPanelMetaUpgrade")
CurrentRun.ThanatosSpawns = 0
CurrentRun.SupportAINames = {}
CurrentRun.Hero.TargetMetaRewardsAdjustSpeed = 10.0
CurrentRun.ClosedDoors = {}
CurrentRun.CompletedStyxWings = 0
CurrentRun.TargetShrinePointThreshold = GetCurrentRunClearedShrinePointThreshold( GetEquippedWeapon() )
CurrentRun.BannedEliteAttributes = {}
if ConfigOptionCache.EasyMode then
CurrentRun.EasyModeLevel = GameState.EasyModeLevel
end
InitHeroLastStands( CurrentRun.Hero )
InitializeRewardStores( CurrentRun )
SelectBannedEliteAttributes( CurrentRun )
-- rooms
RoomData["A_Boss01"].ForceNextRoom = "B_Boss01"
RoomData["B_Boss01"].ForceNextRoom = "C_Boss01"
RoomData["C_Boss01"].ForceNextRoom = "D_Boss01"
args = {RoomName = "A_Boss01"}
-- RoomData["A_Combat01"].ForceNextRoom = "A_Combat01"
-- args = {RoomName = "A_Combat01"}
if args ~= nil and args.RoomName ~= nil then
CurrentRun.CurrentRoom = CreateRoom( RoomData[args.RoomName], args )
else
CurrentRun.CurrentRoom = ChooseStartingRoom( CurrentRun, "Tartarus" )
end
-- boons
-- Athena
AddTraitToHero({TraitName = "AthenaRushTrait", Rarity = "Heroic" })
AddTraitToHero({TraitName = "AthenaSecondaryTrait"})
-- AddTraitToHero({TraitName = "AthenaShoutTrait"})
-- Artemis
-- Ares
-- AddTraitToHero({TraitName = "AresWeaponTrait"})
-- AddTraitToHero({TraitName = "AresSecondaryTrait"})
-- AddTraitToHero({TraitName = "AresRetaliateTrait"})
-- AddTraitToHero({TraitName = "IncreasedDamageTrait"})
-- AddTraitToHero({TraitName = "AresLoadCurseTrait"})
-- AddTraitToHero({TraitName = "AresLongCurseTrait"})
-- Hermes
AddTraitToHero({TraitName = "DodgeChanceTrait", Rarity = "Heroic" })
if(GetEquippedWeapon() == "GunWeapon") then
AddTraitToHero({TraitName = "BonusDashTrait", Rarity = "Heroic" })
AddTraitToHero({TraitName = "ZeusWeaponTrait", Rarity = "Heroic"})
AddTraitToHero({TraitName = "ZeusSecondaryTrait"})
AddTraitToHero({TraitName = "ZeusBoltAoETrait", Rarity = "Heroic"})
AddTraitToHero({TraitName = "ZeusBonusBoltTrait", Rarity = "Heroic"})
AddTraitToHero({TraitName = "ZeusBonusBounceTrait", Rarity = "Heroic"})
AddTraitToHero({TraitName = "ZeusChargedBoltTrait"})
AddTraitToHero({TraitName = "SuperGenerationTrait", Rarity = "Heroic"})
AddTraitToHero({TraitName = "OnWrathDamageBuffTrait", Rarity = "Heroic"})
AddTraitToHero({TraitName = "CriticalSuperGenerationTrait", Rarity = "Heroic"})
AddTraitToHero({TraitName = "CritBonusTrait", Rarity = "Heroic"})
AddTraitToHero({TraitName = "IncreasedDamageTrait", Rarity = "Heroic"})
AddTraitToHero({TraitName = "ArtemisSecondaryTrait"})
AddTraitToHero({TraitName = "AthenaShoutTrait", Rarity = "Heroic"})
AddTraitToHero({TraitName = "GunLoadedGrenadeLaserTrait"})
AddTraitToHero({TraitName = "GunLoadedGrenadeSpeedTrait"})
AddTraitToHero({TraitName = "GunLoadedGrenadeInfiniteAmmoTrait"})
AddTraitToHero({TraitName = "GunLoadedGrenadeWideTrait"})
end
if(GetEquippedWeapon() == "ShieldWeapon") then
AddTraitToHero({TraitName = "ShieldBashDamageTrait"})
AddTraitToHero({TraitName = "ShieldDashAOETrait"})
AddTraitToHero({TraitName = "ShieldChargeSpeedTrait"})
AddTraitToHero({TraitName = "ShieldPerfectRushTrait"})
AddTraitToHero({TraitName = "ShieldThrowElectiveCharge"})
AddTraitToHero({TraitName = "ShieldThrowEmpowerTrait"})
AddTraitToHero({TraitName = "ShieldBlockEmpowerTrait"})
AddTraitToHero({TraitName = "ShieldThrowRushTrait"})
end
return CurrentRun
end
function UpdateWeaponHistory(currentRun)
local eligibleMeleeWeapons = GetEligibleMeleeWeapons()
for index, weaponData in pairs(eligibleMeleeWeapons) do
local weaponName = weaponData.Name
if GameState.WeaponHistory[weaponName] == nil then
GameState.WeaponHistory[weaponName] = 0
end
if currentRun.Hero.Weapons[weaponName] then
GameState.WeaponHistory[weaponName] = 0
else
GameState.WeaponHistory[weaponName] = GameState.WeaponHistory[weaponName] + 1
end
end
end
function ChooseStartingRoom( currentRun, roomSetName )
if GetCompletedRuns() == 0 then
local forcedStartingRoom = GetMapName({ })
if forcedStartingRoom ~= nil and forcedStartingRoom ~= "" then
if RoomData[forcedStartingRoom] == nil then
forcedStartingRoom = "RoomOpening"
end
local startingRoom = CreateRoom( RoomData[forcedStartingRoom] )
return startingRoom
end
end
local eligibleRooms = {}
local forcedRooms = {}
for roomName, roomData in pairs( RoomSetData[roomSetName] ) do
if roomData.Starting and IsRoomEligible( currentRun, nil, roomData ) then
table.insert( eligibleRooms, roomData )
if IsRoomForced( currentRun, nil, roomData ) then
table.insert( forcedRooms, roomData )
end
end
end
local startingRoomData = nil
if not IsEmpty( forcedRooms ) then
startingRoomData = GetRandomValue( forcedRooms )
else
startingRoomData = GetRandomValue( eligibleRooms )
end
local startingRoom = CreateRoom( startingRoomData )
return startingRoom
end
function CreateRoom( roomData, args )
if args == nil then
args = {}
end
local room = DeepCopyTable( roomData )
room.SpawnPoints = {}
room.SpawnPointsUsed = {}
room.EliteAttributes = {}
room.VoiceLinesPlayed = {}
room.TextLinesRecord = {}
if args.RoomOverrides ~= nil then
for key, value in pairs( args.RoomOverrides ) do
room[key] = value
end
end
if not args.SkipChooseEncounter then
room.Encounter = ChooseEncounter( CurrentRun, room )
RecordEncounter( CurrentRun, room.Encounter )
end
if args.RewardStoreName == nil then
local roomName = room.GenusName or room.Name
if room.FirstClearRewardStore ~= nil and IsRoomFirstClearOverShrinePointThreshold( GetEquippedWeapon(), CurrentRun, roomName ) then
args.RewardStoreName = room.FirstClearRewardStore
else
args.RewardStoreName = room.ForcedRewardStore or "RunProgress"
end
end
if not args.SkipChooseReward then
room.RewardStoreName = args.RewardStoreName
room.ChosenRewardType = ChooseRoomReward( CurrentRun, room, args.RewardStoreName, args.PreviouslyChosenRewards )
SetupRoomReward( CurrentRun, room, args.PreviouslyChosenRewards )
end
local secretChance = room.SecretSpawnChance or RoomData.BaseRoom.SecretSpawnChance
for k, mutator in pairs( GameState.ActiveMutators ) do
if mutator.SecretSpawnChanceMultiplier ~= nil then
secretChance = secretChance * mutator.SecretSpawnChanceMultiplier
end
end
room.SecretChanceSuccess = RandomChance( secretChance )
local shrinePointDoorChance = room.ShrinePointDoorSpawnChance or RoomData.BaseRoom.ShrinePointDoorSpawnChance
room.ShrinePointDoorChanceSuccess = RandomChance( shrinePointDoorChance )
local challengeChance = room.ChallengeSpawnChance or RoomData.BaseRoom.ChallengeSpawnChance
for k, mutator in pairs( GameState.ActiveMutators ) do
if mutator.ChallengeSpawnChanceMultiplier ~= nil then
challengeChance = challengeChance * mutator.ChallengeSpawnChanceMultiplier
end
end
room.ChallengeChanceSuccess = RandomChance( challengeChance )
local wellShopChance = room.WellShopSpawnChance or RoomData.BaseRoom.WellShopSpawnChance
for k, mutator in pairs( GameState.ActiveMutators ) do
if mutator.ChallengeSpawnChanceMultiplier ~= nil then
wellShopChance = wellShopChance * mutator.WellShopSpawnChanceMultiplier
end
end
room.WellShopChanceSuccess = RandomChance( wellShopChance )
local sellTraitShopChance = room.SellTraitShopChance or RoomData.BaseRoom.SellTraitShopChance
for k, mutator in pairs( GameState.ActiveMutators ) do
if mutator.ChallengeSpawnChanceMultiplier ~= nil then
sellTraitShopChance = sellTraitShopChance * mutator.SellTraitShopChanceMultiplier
end
end
room.SellTraitShopChanceSuccess = RandomChance( sellTraitShopChance )
local fishingPointChance = room.FishingPointChance or RoomData.BaseRoom.FishingPointChance
for k, mutator in pairs( GameState.ActiveMutators ) do
if mutator.FishingPointChanceMultiplier ~= nil then
fishingPointChance = fishingPointChance * mutator.FishingPointChanceMultiplier
end
end
room.FishingPointChanceSuccess = RandomChance( fishingPointChance + GetTotalHeroTraitValue("FishingPointChanceBonus") )
if CurrentRun.RoomCreations[room.Name] == nil then
CurrentRun.RoomCreations[room.Name] = 0
end
CurrentRun.RoomCreations[room.Name] = CurrentRun.RoomCreations[room.Name] + 1
return room
end
function CheckPreviousReward( currentRun, room, previouslyChosenRewards, args )
if currentRun.CurrentRoom ~= nil then
if currentRun.CurrentRoom.DeferReward then
room.UseOptionalOverrides = currentRun.CurrentRoom.UseOptionalOverrides or currentRun.CurrentRoom.UseExitOverrides -- UseExitOverrides is for backwards compatability
room.ForceLootName = currentRun.CurrentRoom.ForceLootName
elseif currentRun.CurrentRoom.PersistentExitDoorRewards and args.Door ~= nil then
for roomIndex = #CurrentRun.RoomHistory, 1, -1 do
local prevRoom = CurrentRun.RoomHistory[roomIndex]
if currentRun.CurrentRoom.Name == prevRoom.Name and prevRoom.OfferedRewards ~= nil and prevRoom.OfferedRewards[args.Door.ObjectId] ~= nil then
room.UseOptionalOverrides = prevRoom.OfferedRewards[args.Door.ObjectId].UseOptionalOverrides or prevRoom.OfferedRewards[args.Door.ObjectId].UseExitOverrides -- UseExitOverrides is for backwards compatability
room.ForceLootName = prevRoom.OfferedRewards[args.Door.ObjectId].ForceLootName
return
end
end
end
end
end
function SetupRoomReward( currentRun, room, previouslyChosenRewards, args )
args = args or {}
CheckPreviousReward( currentRun, room, previouslyChosenRewards, args )
if room.ChosenRewardType == "Boon" and not room.ForceLootName then
local excludeLootNames = {}
if previouslyChosenRewards ~= nil then
for i, data in pairs( previouslyChosenRewards ) do
if data.RewardType == "Boon" then
table.insert( excludeLootNames, data.ForceLootName )
end
end
end
-- Pre-generate specific type
local lootData = ChooseLoot( excludeLootNames )
if not args.IgnoreForceLootName then
for k, trait in pairs( CurrentRun.Hero.Traits ) do
if trait ~= nil and trait.ForceBoonName ~= nil and trait.Uses > 0 and not Contains(excludeLootNames, trait.ForceBoonName) then
lootData = { Name = trait.ForceBoonName }
end
end
end
if lootData == nil then
room.ForceLootName = ChooseLoot().Name
else
room.ForceLootName = lootData.Name
end
elseif room.ChosenRewardType == "Devotion" then
local devotionEncounterName = GetRandomValue(room.DevotionEncounters)
local encounterData = EncounterData[devotionEncounterName]
local encounter = SetupEncounter( encounterData )
room.Encounter = encounter
RecordEncounter( currentRun, room.Encounter )
currentRun.LastDevotionDepth = currentRun.RunDepthCache
room.Encounter.LootAName = GetInteractedGodThisRun()
for k, trait in pairs( CurrentRun.Hero.Traits ) do
if trait ~= nil and trait.ForceBoonName ~= nil and trait.Uses > 0 and Contains(GetInteractedGodsThisRun(), trait.ForceBoonName) then
room.Encounter.LootAName = trait.ForceBoonName
end
end
room.Encounter.LootBName = GetInteractedGodThisRun( room.Encounter.LootAName )
end
end
function ChooseNextRoomData( currentRun, args )
args = args or {}
local currentRoom = currentRun.CurrentRoom
if(currentRoom.ForceNextRoom ~= nil) then
return RoomData[currentRoom.ForceNextRoom]
end
local roomSetName = currentRun.CurrentRoom.RoomSetName or "Tartarus"
if args.ForceNextRoomSet ~= nil then
roomSetName = args.ForceNextRoomSet
elseif currentRoom.NextRoomSet ~= nil then
roomSetName = GetRandomValue( currentRoom.NextRoomSet )
elseif currentRoom.UsePreviousRoomSet then
local previousRoom = GetPreviousRoom(currentRun) or currentRoom
roomSetName = previousRoom.RoomSetName or "Tartarus"
elseif currentRoom.NextRoomSetNoGenerate ~= nil then
roomSetName = GetRandomValue( currentRoom.NextRoomSetNoGenerate )
end
local roomDataSet = args.RoomDataSet or RoomSetData[roomSetName]
local nextRoomData = nil
if ForceNextRoom ~= nil and RoomData[ForceNextRoom] ~= nil then
nextRoomData = RoomData[ForceNextRoom]
elseif args.ForceNextRoom ~= nil and RoomData[args.ForceNextRoom] ~= nil then
nextRoomData = RoomData[args.ForceNextRoom]
elseif currentRoom.LinkedRoom ~= nil or currentRoom.LinkedRooms ~= nil or currentRoom.LinkedRoomByPactLevel then
local nextRoomName = currentRoom.LinkedRoom
if currentRoom.LinkedRooms ~= nil then
local eligibleRoomNames = {}
local forcedRoomNames = {}
for i, linkedRoomName in ipairs( CollapseTableOrdered( currentRoom.LinkedRooms ) ) do
if IsRoomEligible( currentRun, currentRoom, roomDataSet[linkedRoomName], args ) then
table.insert( eligibleRoomNames, linkedRoomName )
if IsRoomForced( currentRun, currentRoom, roomDataSet[linkedRoomName], args ) then
table.insert( forcedRoomNames, linkedRoomName )
end
end
end
if not IsEmpty( forcedRoomNames ) then
nextRoomName = GetRandomValue( forcedRoomNames )
else
nextRoomName = GetRandomValue( eligibleRoomNames )
end
elseif currentRoom.LinkedRoomByPactLevel then
local shrineLevel = GetNumMetaUpgrades( currentRoom.ShrineMetaUpgradeName )
nextRoomName = currentRoom.LinkedRoomByPactLevel[shrineLevel]
end
if nextRoomName ~= nil then
nextRoomData = roomDataSet[nextRoomName]
end
end
if nextRoomData == nil then
local eligibleRooms = {}
local forcedRooms = {}
for i, kvp in ipairs( CollapseTableAsOrderedKeyValuePairs( roomDataSet ) ) do
local roomName = kvp.Key
local roomData = kvp.Value
if IsRoomEligible( currentRun, currentRoom, roomData, args ) then
table.insert( eligibleRooms, roomData )
if IsRoomForced( currentRun, currentRoom, roomData, args ) then
table.insert( forcedRooms, roomData )
end
end
end
if not IsEmpty( forcedRooms ) then
nextRoomData = GetRandomValue( forcedRooms )
else
nextRoomData = GetRandomValue( eligibleRooms )
end
end
DebugAssert({ Condition = nextRoomData ~= nil, Text = "No eligible rooms for exit door!" })
return nextRoomData
end
function IsRoomForced( currentRun, currentRoom, nextRoomData, args )
if nextRoomData.AlwaysForce then
return true
end
if nextRoomData.ForceIfEncounterNotCompleted ~= nil and not HasEncounterBeenCompleted( nextRoomData.ForceIfEncounterNotCompleted ) then
return true
end
if nextRoomData.ForceIfUnseenForRuns ~= nil and not HasSeenRoomInNumRuns( nextRoomData.Name, nextRoomData.ForceIfUnseenForRuns ) then
DebugPrint({ Text = "Forcing = "..nextRoomData.Name })
return true
end
args = args or{}
local depthSkip = args.RoomsSkipped or 0
local currentRunDepth = currentRun.RunDepthCache + depthSkip
if nextRoomData.ForceAtRunDepth ~= nil and currentRunDepth == nextRoomData.ForceAtRunDepth then
return true
end
if nextRoomData.ForceAtRunDepthMin ~= nil and currentRunDepth >= nextRoomData.ForceAtRunDepthMin then
if currentRunDepth >= nextRoomData.ForceAtRunDepthMax then
return true
else
local forcedChance = 1 / (nextRoomData.ForceAtRunDepthMax - currentRunDepth)
if RandomChance( forcedChance ) then
return true
end
end
end
local currentBiomeDepth = currentRun.BiomeDepthCache + depthSkip
if nextRoomData.ForceAtBiomeDepth ~= nil and currentBiomeDepth == nextRoomData.ForceAtBiomeDepth then
return true
end
if nextRoomData.ForceAtBiomeDepthMin ~= nil and currentBiomeDepth >= nextRoomData.ForceAtBiomeDepthMin then
if currentBiomeDepth >= nextRoomData.ForceAtBiomeDepthMax then
return true
else
local forcedChance = 1 / (nextRoomData.ForceAtBiomeDepthMax - currentBiomeDepth)
if RandomChance( forcedChance ) then
return true
end
end
end
if currentRoom ~= nil and currentRoom.ForceWingEndMiniBoss and nextRoomData.WingEndMiniBoss and (currentRun.CompletedStyxWings < 4 or HasSeenRoomInRun(currentRun, "D_Reprieve01")) then
return true
end
if nextRoomData.ForceChanceByRemainingWings then
local chance = 1 / (5 - currentRun.CompletedStyxWings)
if RandomChance(chance) then
return true
end
end
return false
end
function IsRoomEligible( currentRun, currentRoom, nextRoomData, args )
if args == nil then
args = {}
end
if nextRoomData == nil then
return false
end
local excludedNames = args.ExcludedNames
local excludedTypes = args.ExcludedTypes
local excludedRewards = args.ExcludedRewards
local roomsSkipped = args.DepthSkip or 0
if nextRoomData.DebugOnly then
return false
end
if excludedNames ~= nil and excludedNames[nextRoomData.Name] then
return false
end
if excludedTypes ~= nil and excludedTypes[nextRoomData.Type] then
return false
end
if excludedRewards ~= nil and not IsEmpty(nextRoomData.RewardTypes) and ContainsAll(excludedRewards, nextRoomData.RewardTypes) then
return false
end
if nextRoomData.ForceAtBiomeDepth ~= nil and currentRun.BiomeDepthCache ~= nextRoomData.ForceAtBiomeDepth then
return false
end
if nextRoomData.ForceAtBiomeDepthMin ~= nil and currentRun.BiomeDepthCache < nextRoomData.ForceAtBiomeDepthMin then
return false
end
if currentRoom ~= nil then
if nextRoomData.Name == currentRoom.Name then
return false
end
if nextRoomData.Starting and not currentRoom.AllowNextRoomStarting then
return false
end
if nextRoomData.RequiresLinked then
if currentRoom.LinkedRoom ~= nextRoomData.Name and ( currentRoom.LinkedRooms == nil or not Contains( currentRoom.LinkedRooms, nextRoomData.Name ) ) then
return false
end
end
-- If in a MiniBoss wing and we are not a MiniBoss, we are ineligible (except Reprieve)
if currentRoom.RequireWingEndMiniBoss and nextRoomData.WingEndRoom and not nextRoomData.WingEndMiniBoss and not nextRoomData.AllowAsAnyWingEnd then
return false
end
-- If in a regular wing and we are a MiniBoss room, we are ineligible (except Reprieve)
if not currentRoom.RequireWingEndMiniBoss and nextRoomData.WingEndRoom and nextRoomData.WingEndMiniBoss and not nextRoomData.AllowAsAnyWingEnd then
return false
end
end
if nextRoomData.MaxAppearancesThisRun ~= nil and currentRun.RoomCountCache[nextRoomData.Name] ~= nil and currentRun.RoomCountCache[nextRoomData.Name] >= nextRoomData.MaxAppearancesThisRun then
return false
end
if nextRoomData.MaxAppearancesThisBiome ~= nil and currentRun.BiomeRoomCountCache[nextRoomData.Name] ~= nil and currentRun.BiomeRoomCountCache[nextRoomData.Name] >= nextRoomData.MaxAppearancesThisBiome then
return false
end
if nextRoomData.MaxCreationsThisRun ~= nil and currentRun.RoomCreations[nextRoomData.Name] ~= nil and currentRun.RoomCreations[nextRoomData.Name] >= nextRoomData.MaxCreationsThisRun then
return false
end
if not IsGameStateEligible( currentRun, nextRoomData , nextRoomData.GameStateRequirements, args) then
return false
end
return true
end
function GetNumRoomAppearances( roomHistory, nextRoomData )
if roomHistory == nil then
return 0
end
local numAppearances = 0
for roomOrder, roomData in pairs( roomHistory ) do
if roomData.Name == nextRoomData.Name then
numAppearances = numAppearances + 1
end
end
return numAppearances
end
function ChooseEncounter( currentRun, room )
DebugAssert({ Condition = room ~= nil, Text = "Choosing an encounter for a nil room!" })
local encounterData = nil
if ForceNextEncounter ~= nil then
DebugPrint({ Text = "ForceNextEncounter = "..tostring(ForceNextEncounter) })
encounterData = EncounterData[ForceNextEncounter]
encounterData.SkipIntroEncounterCheck = true
ForceNextEncounter = nil
elseif currentRun.ForceNextEncounterData ~= nil then
encounterData = currentRun.ForceNextEncounterData
elseif HasHeroTraitValue( "ForceThanatosEncounter" ) then
local legalEncounters = {}
for i, encounterName in pairs( EncounterSets.ThanatosEncounters ) do
if IsEncounterEligible( currentRun, room, EncounterData[encounterName] ) then
table.insert(legalEncounters, encounterName )
end
end
if not IsEmpty( legalEncounters ) then
UseHeroTraitsWithValue( "ForceThanatosEncounter", true )
encounterData = EncounterData[legalEncounters[1]]
end
end
if not encounterData then
local eligibleEncounters = {}
local forcedEncounters = {}
if room.LegalEncounters ~= nil then
for k, encounterName in pairs( room.LegalEncounters ) do
local encounterData = EncounterData[encounterName]
if IsEncounterEligible( currentRun, room, encounterData ) then
table.insert( eligibleEncounters, encounterData )
if IsEncounterForced( currentRun, room, encounterData ) then
table.insert( forcedEncounters, encounterData )
end
end
end
else
for encounterName, encounterData in pairs( EncounterData ) do
if IsEncounterEligible( currentRun, room, encounterData ) then
table.insert( eligibleEncounters, encounterData )
if IsEncounterForced( currentRun, room, encounterData ) then
table.insert( forcedEncounters, encounterData )
end
end
end
end
local roomName = room.Name
if roomName == nil then
roomName = GetKey(RoomData, room)
end
if roomName == nil then
roomName = tostring(room.HelpTextId)..":"..tostring(room.Type)..":"..tostring(room.LegalEncounters[1])
end
DebugAssert({ Condition = not IsEmpty( eligibleEncounters ) or not IsEmpty(forcedEncounters), Text = "No encounters available for "..tostring(roomName).."!" })
if not IsEmpty( forcedEncounters ) then
encounterData = GetRandomValue( forcedEncounters )
else
encounterData = GetRandomValue( eligibleEncounters )
end
if encounterData.EnemySet ~= nil then
for k, enemyName in pairs(encounterData.EnemySet) do
if EnemyData[enemyName].ForceIntroduction and not HasEncounterBeenCompleted(EnemyData[enemyName].RequiredIntroEncounter) then
encounterData = EncounterData[EnemyData[enemyName].RequiredIntroEncounter]
end
end
end
end
local encounter = SetupEncounter(encounterData, room)
return encounter
end
function SetupEncounter( encounterData, room )
local encounter = DeepCopyTable( encounterData )
room = room or CurrentRun.CurrentRoom
if room.RewardOverrides ~= nil and room.RewardOverrides.MakeHardEncounter then
encounter.IsHardEncounter = true
end
if encounter.Generated then
GenerateEncounter(CurrentRun, room, encounter)
end
-- Check if enemies need to be introduced
if encounter ~= nil and encounter.SpawnWaves ~= nil and not encounter.SkipIntroEncounterCheck then
for k, wave in pairs(encounter.SpawnWaves) do
for k, spawnData in pairs(wave.Spawns) do
local requiredIntroEncounterName = EnemyData[spawnData.Name].RequiredIntroEncounter
if requiredIntroEncounterName ~= nil and not HasEncounterBeenCompleted(requiredIntroEncounterName) and IsGameStateEligible( CurrentRun, EncounterData[requiredIntroEncounterName] ) then
encounter = DeepCopyTable(EncounterData[requiredIntroEncounterName])
if encounter.Generated then
GenerateEncounter(CurrentRun, room, encounter)
end
end
end
end
end
return encounter
end
function ChooseChallengeEncounter( room )
DebugAssert({ Condition = room ~= nil, Text = "Choosing a challenge for a nil room." })
local encounterName = room.ChallengeEncounterName
DebugAssert({ Condition = encounterName ~= nil, Text = "Room has no ChallengeEncounterName set." })
local encounter = DeepCopyTable( EncounterData[encounterName] )
if encounter.Generated then
GenerateEncounter(CurrentRun, room, encounter)
end
return encounter
end
function SetupShrineChallengeEnemySet( encounter )
local enemySetPrefix = "ShrineChallenge"
encounter.EnemySet = {}
local spawnOptionsSuperElite = ShallowCopyTable(EnemySets[enemySetPrefix.."SuperElite"])
local spawnOptionsFodder = ShallowCopyTable(EnemySets[enemySetPrefix.."Fodder"])
local enemiesAdded = 0
while not IsEmpty(spawnOptionsSuperElite) do
local newSpawnOption = RemoveRandomValue(spawnOptionsSuperElite)
if IsEnemyEligible(newSpawnOption, encounter, nil) then
table.insert(encounter.EnemySet, newSpawnOption)
enemiesAdded = enemiesAdded + 1
break
end
end
while enemiesAdded < encounter.MaxTypes and not IsEmpty(spawnOptionsFodder) do
newSpawnOption = RemoveRandomValue(spawnOptionsFodder)
if IsEnemyEligible(newSpawnOption, encounter, nil) then
table.insert(encounter.EnemySet, newSpawnOption)
enemiesAdded = enemiesAdded + 1
end
end
end
function GenerateEncounter( currentRun, room, encounter )
if encounter.IsHardEncounter and encounter.HardEncounterOverrideValues then
DebugPrint({ Text = "Overwriting for hard encounter" })
OverwriteTableKeys(encounter, encounter.HardEncounterOverrideValues)
end
if encounter.UseRoomEncounterEnemySet then
encounter.EnemySet = room.Encounter.EnemySet
end
-- Encounter Difficulty
local depthDifficultyRamp = encounter.DepthDifficultyRamp or 0.45
local difficultyModifer = encounter.DifficultyModifier or 0
-- resources
local metaPointStoreRamp = encounter.MetaPointStoreRamp or 0
encounter.MetaPointStore = math.ceil( currentRun.RunDepthCache * metaPointStoreRamp * GetTotalHeroTraitValue("RoomMetaPointMultiplier", { IsMultiplier = true }))
local moneyDropStoreRamp = encounter.MoneyDropCapDepthRamp or 0
encounter.MoneyDropStore = ( RandomInt( encounter.MoneyDropCapMin, encounter.MoneyDropCapMax ) + currentRun.RunDepthCache * moneyDropStoreRamp ) or 0
DebugPrint({ Text = "Encounter Money Store Cap: "..tostring( encounter.MoneyDropStore ) })
local baseDifficulty = encounter.BaseDifficulty or EncounterData.Generated.BaseDifficulty
if encounter.BaseDifficultyMin ~= nil and encounter.BaseDifficultyMax ~= nil then
baseDifficulty = RandomInt(encounter.BaseDifficultyMin, encounter.BaseDifficultyMax)
end
local depthMultiplier = currentRun.BiomeDepthCache
if encounter.UseRunDepth then
depthMultiplier = currentRun.RunDepthCache
end
encounter.DifficultyRating = baseDifficulty + depthMultiplier * depthDifficultyRamp + difficultyModifer
if encounter.DifficultyRatingShrineModifierName then
local modifierName = encounter.DifficultyRatingShrineModifierName
encounter.DifficultyRating = encounter.DifficultyRating * (GetNumMetaUpgrades(modifierName) * MetaUpgradeData[modifierName].ChangeValue )
else
encounter.DifficultyRating = encounter.DifficultyRating * (1 + GetNumMetaUpgrades("EnemyCountShrineUpgrade") * (MetaUpgradeData.EnemyCountShrineUpgrade.ChangeValue - 1 ) )
end