Skip to content

Commit

Permalink
feat: Add Remove default unlock request system. (SubnauticaModding#495)
Browse files Browse the repository at this point in the history
* Add logging to show when adding unlocks to an AnalysisTech

* Create method to remove default unlocks.
  • Loading branch information
MrPurple6411 authored Nov 4, 2023
1 parent 485f5a3 commit 817d644
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Nautilus/Handlers/KnownTechHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,21 @@ public static void RemoveAllCurrentAnalysisTechEntry(TechType targetTechType)
RemoveAnalysisTechEntry(targetTechType);
}

/// <summary>
/// Allows you to remove a <see cref="TechType"/> from being unlocked by default.
/// </summary>
/// <param name="techType"></param>
public static void RemoveDefaultUnlock(TechType techType)
{
var modName = ReflectionHelper.CallingAssemblyByStackTrace().GetName().Name;
if (!KnownTechPatcher.DefaultRemovalTechs.TryGetValue(modName, out var techTypes))
techTypes = new List<TechType>();
techTypes.Add(techType);

KnownTechPatcher.DefaultRemovalTechs[modName] = techTypes;
Reinitialize();
}

/// <summary>
/// References to generic unlock sounds and unlock messages for the Known Tech system, matching those used in the base game.
/// </summary>
Expand Down
22 changes: 21 additions & 1 deletion Nautilus/Patchers/KnownTechPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal class KnownTechPatcher
internal static HashSet<TechType> LockedWithNoUnlocks = new();
internal static HashSet<TechType> HardLocked = new();
internal static HashSet<TechType> RemovalTechs = new();
internal static Dictionary<string, List<TechType>> DefaultRemovalTechs = new();
internal static IDictionary<TechType, KnownTech.AnalysisTech> AnalysisTech = new SelfCheckingDictionary<TechType, KnownTech.AnalysisTech>("AnalysisTech", AsStringFunction);
internal static IDictionary<TechType, List<TechType>> BlueprintRequirements = new SelfCheckingDictionary<TechType, List<TechType>>("BlueprintRequirements", AsStringFunction);
internal static IDictionary<TechType, KnownTech.CompoundTech> CompoundTech = new SelfCheckingDictionary<TechType, KnownTech.CompoundTech>("CompoundTech", AsStringFunction);
Expand Down Expand Up @@ -49,7 +50,25 @@ internal static void Reinitialize()

private static void InitializePrefix(PDAData data)
{
data.defaultTech.AddRange(UnlockedAtStart);
foreach (var unlockedTech in UnlockedAtStart)
{
if (!data.defaultTech.Contains(unlockedTech))
{
data.defaultTech.Add(unlockedTech);
InternalLogger.Debug($"Setting {unlockedTech.AsString()} to be unlocked at start.");
}
}

foreach (var removalTechsByMod in DefaultRemovalTechs)
{
foreach (var removalTech in removalTechsByMod.Value)
{
if (data.defaultTech.Remove(removalTech))
{
InternalLogger.Debug($"{removalTechsByMod.Key} removed {removalTech.AsString()} from unlocking at start.");
}
}
}

foreach (var tech in AnalysisTech.Values)
{
Expand Down Expand Up @@ -80,6 +99,7 @@ private static void InitializePrefix(PDAData data)
continue;
}

InternalLogger.Debug($"Adding TechTypes to be unlocked by {blueprintRequirements.Key}: {blueprintRequirements.Value.Join((techType) => techType.AsString())}");
data.analysisTech[index].unlockTechTypes.AddRange(blueprintRequirements.Value);
}

Expand Down

0 comments on commit 817d644

Please sign in to comment.