Skip to content

Commit

Permalink
Fix TR3 secret rewards
Browse files Browse the repository at this point in the history
On the Japanese version, secret rewards were still being included in normal item randomization because we weren't testing the version in every scenario. Made a subclass for this case to avoid duplicating the check everywhere.
  • Loading branch information
lahm86 committed Nov 12, 2023
1 parent dd10b7d commit e779724
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
4 changes: 2 additions & 2 deletions TRRandomizerCore/Randomizers/TR3/TR3ItemRandomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class TR3ItemRandomizer : BaseTR3Randomizer
private TR3Entity _unarmedLevelPistols;

// Secret reward items handled in separate class, so track the reward entities
private TRSecretMapping<TR2Entity> _secretMapping;
private TR3SecretMapping _secretMapping;

private readonly LocationPicker _picker;

Expand All @@ -46,7 +46,7 @@ public override void Randomize(int seed)
FindUnarmedLevelPistols(_levelInstance);

_picker.Initialise(_levelInstance.Name, GetItemLocationPool(_levelInstance, false), Settings, _generator);
_secretMapping = TRSecretMapping<TR2Entity>.Get(GetResourcePath($@"TR3\SecretMapping\{_levelInstance.Name}-SecretMapping.json"));
_secretMapping = TR3SecretMapping.Get(GetResourcePath($@"TR3\SecretMapping\{_levelInstance.Name}-SecretMapping.json"), IsJPVersion);

// #312 If this is the assault course, import required models. On failure, don't perform any item rando.
if (_levelInstance.IsAssault && !ImportAssaultModels(_levelInstance))
Expand Down
14 changes: 3 additions & 11 deletions TRRandomizerCore/Randomizers/TR3/TR3SecretRandomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private TRSecretRoom<TR2Entity> MakePlaceholderRewardRoom(TR3CombinedLevel level

private void ActualiseRewardRoom(TR3CombinedLevel level, TRSecretRoom<TR2Entity> placeholder)
{
TRSecretMapping<TR3Entity> secretMapping = TRSecretMapping<TR3Entity>.Get(GetResourcePath(@"TR3\SecretMapping\" + level.Name + "-SecretMapping.json"));
TR3SecretMapping secretMapping = TR3SecretMapping.Get(GetResourcePath($@"TR3\SecretMapping\{level.Name}-SecretMapping.json"), IsJPVersion);
if (secretMapping == null)
{
return;
Expand Down Expand Up @@ -213,19 +213,11 @@ private void ActualiseRewardRoom(TR3CombinedLevel level, TRSecretRoom<TR2Entity>
}
}

// Get the reward entities - Thames in JP version has different indices, so
// these are defined separately.
List<int> rewardEntities = secretMapping.RewardEntities;
if (IsJPVersion && secretMapping.JPRewardEntities != null)
{
rewardEntities = secretMapping.JPRewardEntities;
}

// Spread the rewards out fairly evenly across each defined position in the new room.
int rewardPositionCount = rewardRoom.RewardPositions.Count;
for (int i = 0; i < rewardEntities.Count; i++)
for (int i = 0; i < secretMapping.RewardEntities.Count; i++)
{
TR3Entity item = level.Data.Entities[rewardEntities[i]];
TR3Entity item = level.Data.Entities[secretMapping.RewardEntities[i]];
Location position = rewardRoom.RewardPositions[i % rewardPositionCount];

item.X = position.X;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private void RandomizeRewards(TR3CombinedLevel level)
return;
}

TRSecretMapping<TR2Entity> secretMapping = TRSecretMapping<TR2Entity>.Get(GetResourcePath(@"TR3\SecretMapping\" + level.Name + "-SecretMapping.json"));
TR3SecretMapping secretMapping = TR3SecretMapping.Get(GetResourcePath($@"TR3\SecretMapping\{level.Name}-SecretMapping.json"), IsJPVersion);

List<TR3Type> stdItemTypes = TR3TypeUtilities.GetStandardPickupTypes();
// A bit cruel as rewards?
Expand Down
23 changes: 23 additions & 0 deletions TRRandomizerCore/Secrets/TR3SecretMapping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Newtonsoft.Json;
using TREnvironmentEditor;
using TRLevelControl.Model;

namespace TRRandomizerCore.Secrets;

public class TR3SecretMapping : TRSecretMapping<TR3Entity>
{
public static TR3SecretMapping Get(string packPath, bool japaneseVersion)
{
if (!File.Exists(packPath))
{
return null;
}

TR3SecretMapping mapping = JsonConvert.DeserializeObject<TR3SecretMapping>(File.ReadAllText(packPath), EMEditorMapping.Converter);
if (japaneseVersion && mapping.JPRewardEntities != null)
{
mapping.RewardEntities = mapping.JPRewardEntities;
}
return mapping;
}
}

0 comments on commit e779724

Please sign in to comment.