From f0d935b452f3a2245e9fb9e04a177aeaf72a77e2 Mon Sep 17 00:00:00 2001
From: Metious <71298690+Metious@users.noreply.github.com>
Date: Wed, 25 Oct 2023 14:02:05 +0330
Subject: [PATCH] Added hard-locking mechanism
---
Nautilus/Assets/Gadgets/ScanningGadget.cs | 24 ++++++++++++++++++++++-
Nautilus/Handlers/KnownTechHandler.cs | 14 +++++++++++++
Nautilus/Patchers/KnownTechPatcher.cs | 2 ++
3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/Nautilus/Assets/Gadgets/ScanningGadget.cs b/Nautilus/Assets/Gadgets/ScanningGadget.cs
index 6fc595daa..7f29e080d 100644
--- a/Nautilus/Assets/Gadgets/ScanningGadget.cs
+++ b/Nautilus/Assets/Gadgets/ScanningGadget.cs
@@ -17,7 +17,12 @@ public class ScanningGadget : Gadget
///
/// Classifies this item as buildable via the habitat builder.
///
- public bool IsBuildable { get; set; }
+ public bool IsBuildable { get; private set; }
+
+ ///
+ /// Marks this item as hard locked.
+ ///
+ public bool IsHardLocked { get; private set; }
///
/// The blueprint that must first be scanned or picked up to unlocked this item.
@@ -191,6 +196,18 @@ public ScanningGadget SetBuildable(bool isBuildable = true)
return this;
}
+ ///
+ /// Makes this item hard locked. Hard locked items are not unlocked by default even in creative and can't be unlocked using the `unlockall` command.
+ ///
+ /// Should this item be hard locked?
+ /// A reference to this instance after the operation has completed.
+ public ScanningGadget SetHardLocked(bool isHardLocked = true)
+ {
+ IsHardLocked = isHardLocked;
+
+ return this;
+ }
+
///
/// Adds an encyclopedia entry for this item in the PDA. This method does not ask for display text, for that you must use the .
/// The encyclopedia entry's key will be set as the TechType string.
@@ -363,5 +380,10 @@ protected internal override void Build()
{
KnownTechPatcher.LockedWithNoUnlocks.Add(prefab.Info.TechType);
}
+
+ if (IsHardLocked)
+ {
+ KnownTechHandler.SetHardLocked(prefab.Info.TechType);
+ }
}
}
\ No newline at end of file
diff --git a/Nautilus/Handlers/KnownTechHandler.cs b/Nautilus/Handlers/KnownTechHandler.cs
index 739c6a265..8b3e1ca38 100644
--- a/Nautilus/Handlers/KnownTechHandler.cs
+++ b/Nautilus/Handlers/KnownTechHandler.cs
@@ -38,6 +38,20 @@ public static void AddRequirementForUnlock(TechType blueprint, TechType requirem
Reinitialize();
}
+ ///
+ /// Makes the specified tech type hard locked. Hard locking means that the tech type will not be unlocked via the unlockall command and will not be unlocked by default
+ /// in creative.
+ ///
+ /// Calling this method will remove the specified item from being unlocked at start.
+ /// The tech type to set as hard locked.
+ ///
+ public static void SetHardLocked(TechType techType)
+ {
+ KnownTechPatcher.HardLocked.Add(techType);
+ KnownTechPatcher.UnlockedAtStart.Remove(techType);
+ Reinitialize();
+ }
+
internal static void AddAnalysisTech(KnownTech.AnalysisTech analysisTech)
{
if (analysisTech.techType != TechType.None)
diff --git a/Nautilus/Patchers/KnownTechPatcher.cs b/Nautilus/Patchers/KnownTechPatcher.cs
index 3d968bac1..0fc44187c 100644
--- a/Nautilus/Patchers/KnownTechPatcher.cs
+++ b/Nautilus/Patchers/KnownTechPatcher.cs
@@ -12,6 +12,7 @@ internal class KnownTechPatcher
internal static HashSet UnlockedAtStart = new();
internal static HashSet LockedWithNoUnlocks = new();
+ internal static HashSet HardLocked = new();
internal static HashSet RemovalTechs = new();
internal static IDictionary AnalysisTech = new SelfCheckingDictionary("AnalysisTech", AsStringFunction);
internal static IDictionary> BlueprintRequirements = new SelfCheckingDictionary>("BlueprintRequirements", AsStringFunction);
@@ -129,5 +130,6 @@ private static void GetAllUnlockablesPostfix(HashSet __result)
{
var filtered = CraftData.FilterAllowed(LockedWithNoUnlocks);
__result.AddRange(filtered);
+ __result.RemoveRange(HardLocked);
}
}
\ No newline at end of file