Skip to content

Commit c6d9bd7

Browse files
committed
Move puzzle reassignment
Puzzle2 reassignment to continue to support the dragon in every level is now moved to pre-processing.
1 parent cf7fbf6 commit c6d9bd7

File tree

4 files changed

+34
-94
lines changed

4 files changed

+34
-94
lines changed

TRRandomizerCore/Editors/TR2ClassicEditor.cs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ protected override int GetSaveTarget(int numLevels)
8080
// TRX pre-processing
8181
target += numLevels;
8282

83-
if (Settings.ReassignPuzzleItems)
84-
{
85-
// For TR2ModelAdjuster
86-
target += numLevels;
87-
}
88-
8983
if (Settings.RandomizeEnemies)
9084
{
9185
// 3 for multithreading cross-level work
@@ -187,6 +181,7 @@ protected override void SaveImpl(AbstractTRScriptEditor scriptEditor, TRSaveMoni
187181
SaveMonitor = monitor,
188182
TextureMonitor = textureMonitor,
189183
ItemFactory = itemFactory,
184+
Settings = Settings,
190185
}.Run();
191186
}
192187

@@ -206,21 +201,6 @@ protected override void SaveImpl(AbstractTRScriptEditor scriptEditor, TRSaveMoni
206201
}.Randomize(Settings.SecretSeed);
207202
}
208203

209-
if (!monitor.IsCancelled && Settings.ReassignPuzzleItems)
210-
{
211-
// P2 items are converted to P3 in case the dragon is present as the dagger type is hardcoded.
212-
// Must take place before enemy randomization. OG P2 key items must be zoned based on being P3.
213-
monitor.FireSaveStateBeginning(TRSaveCategory.Custom, "Adjusting level models");
214-
new TR2ModelAdjuster
215-
{
216-
ScriptEditor = scriptEditor,
217-
Levels = levels,
218-
BasePath = wipDirectory,
219-
BackupPath = backupDirectory,
220-
SaveMonitor = monitor
221-
}.AdjustModels();
222-
}
223-
224204
if (!monitor.IsCancelled && Settings.RandomizeItems)
225205
{
226206
monitor.FireSaveStateBeginning(TRSaveCategory.Custom, "Randomizing items");

TRRandomizerCore/Processors/TR2/TR2ModelAdjuster.cs

Lines changed: 0 additions & 72 deletions
This file was deleted.

TRRandomizerCore/Processors/TR2/TR2XPreProcessor.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using TRLevelControl.Model;
2+
using TRRandomizerCore.Editors;
23
using TRRandomizerCore.Helpers;
34
using TRRandomizerCore.Processors.Shared;
45
using TRRandomizerCore.Processors.TR2;
@@ -13,6 +14,7 @@ public class TR2XPreProcessor : TR2LevelProcessor
1314

1415
public required TR2TextureMonitorBroker TextureMonitor { get; set; }
1516
public required ItemFactory<TR2Entity> ItemFactory { get; set; }
17+
public required RandomizerSettings Settings { get; set; }
1618

1719
public void Run()
1820
{
@@ -22,7 +24,7 @@ public void Run()
2224
new TR2XDataTask() { TextureMonitor = TextureMonitor },
2325
new TR2XFixLaraTask() { TextureMonitor = TextureMonitor },
2426
new TR2XEnemyTask() { ItemFactory = ItemFactory },
25-
new TR2XPickupTask(),
27+
new TR2XPickupTask() { ReassignPuzzleItems = Settings.ReassignPuzzleItems },
2628
};
2729

2830
var commonProcessor = new TRXCommonProcessor(ScriptEditor, _minTR2XVersion);

TRRandomizerCore/Processors/TR2/Tasks/TR2XPickupTask.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class TR2XPickupTask : ITR2ProcessorTask
1010
private static readonly PickupInfo _info =
1111
JsonUtils.ReadFile<PickupInfo>("Resources/TR2/pickup_info.json");
1212

13+
public bool ReassignPuzzleItems { get; set; }
14+
1315
public void Run(TR2CombinedLevel level)
1416
{
1517
var typeTargets = _info.LevelTargets.TryGetValue(level.Name, out var levelTypes)
@@ -20,6 +22,34 @@ public void Run(TR2CombinedLevel level)
2022
ScalePickup(type, level.Data.Models[type], factor);
2123
FixPickup(type, level.Data.Models[type], level.Name);
2224
}
25+
26+
AlterPuzzles(level);
27+
}
28+
29+
private void AlterPuzzles(TR2CombinedLevel level)
30+
{
31+
if (level.Is(TR2LevelNames.LAIR) || !ReassignPuzzleItems)
32+
{
33+
return;
34+
}
35+
36+
// P2 items are converted to P3 in case the dragon is present to ensure the dagger can be safely imported.
37+
// OG P2 key items must be zoned based on being P3.
38+
foreach (var (oldType, newType) in new Dictionary<TR2Type, TR2Type>
39+
{
40+
[TR2Type.Puzzle2_M_H] = TR2Type.Puzzle3_M_H,
41+
[TR2Type.PuzzleHole2] = TR2Type.PuzzleHole3,
42+
[TR2Type.PuzzleDone2] = TR2Type.PuzzleDone3,
43+
})
44+
{
45+
level.Data.Models.ChangeKey(oldType, newType);
46+
level.Data.Entities.FindAll(e => e.TypeID == oldType)
47+
.ForEach(e => e.TypeID = newType);
48+
}
49+
50+
level.Data.Sprites.ChangeKey(TR2Type.Puzzle2_S_P, TR2Type.Puzzle3_S_P);
51+
level.Data.Entities.FindAll(e => e.TypeID == TR2Type.Puzzle2_S_P)
52+
.ForEach(e => e.TypeID = TR2Type.Puzzle3_S_P);
2353
}
2454

2555
public static void ScalePickup(TR2Type type, TRModel model, float factor)

0 commit comments

Comments
 (0)