Skip to content

Commit

Permalink
Added hard-locking mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
Metious committed Oct 25, 2023
1 parent 955c640 commit f0d935b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
24 changes: 23 additions & 1 deletion Nautilus/Assets/Gadgets/ScanningGadget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ public class ScanningGadget : Gadget
/// <summary>
/// Classifies this item as buildable via the habitat builder.
/// </summary>
public bool IsBuildable { get; set; }
public bool IsBuildable { get; private set; }

/// <summary>
/// Marks this item as hard locked.
/// </summary>
public bool IsHardLocked { get; private set; }

/// <summary>
/// The blueprint that must first be scanned or picked up to unlocked this item.
Expand Down Expand Up @@ -191,6 +196,18 @@ public ScanningGadget SetBuildable(bool isBuildable = true)
return this;
}

/// <summary>
/// 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.
/// </summary>
/// <param name="isHardLocked">Should this item be hard locked?</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public ScanningGadget SetHardLocked(bool isHardLocked = true)
{
IsHardLocked = isHardLocked;

return this;
}

/// <summary>
/// <para>Adds an encyclopedia entry for this item in the PDA. This method does not ask for display text, for that you must use the <see cref="LanguageHandler"/>.</para>
/// <para>The encyclopedia entry's key will be set as the TechType string.</para>
Expand Down Expand Up @@ -363,5 +380,10 @@ protected internal override void Build()
{
KnownTechPatcher.LockedWithNoUnlocks.Add(prefab.Info.TechType);
}

if (IsHardLocked)
{
KnownTechHandler.SetHardLocked(prefab.Info.TechType);
}
}
}
14 changes: 14 additions & 0 deletions Nautilus/Handlers/KnownTechHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ public static void AddRequirementForUnlock(TechType blueprint, TechType requirem
Reinitialize();
}

/// <summary>
/// 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.
/// </summary>
/// <remarks>Calling this method will remove the specified item from being unlocked at start.</remarks>
/// <param name="techType">The tech type to set as hard locked.</param>
/// <seealso cref="UnlockOnStart"/>
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)
Expand Down
2 changes: 2 additions & 0 deletions Nautilus/Patchers/KnownTechPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal class KnownTechPatcher

internal static HashSet<TechType> UnlockedAtStart = new();
internal static HashSet<TechType> LockedWithNoUnlocks = new();
internal static HashSet<TechType> HardLocked = new();
internal static HashSet<TechType> RemovalTechs = 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);
Expand Down Expand Up @@ -129,5 +130,6 @@ private static void GetAllUnlockablesPostfix(HashSet<TechType> __result)
{
var filtered = CraftData.FilterAllowed(LockedWithNoUnlocks);
__result.AddRange(filtered);
__result.RemoveRange(HardLocked);
}
}

0 comments on commit f0d935b

Please sign in to comment.