Skip to content

Commit

Permalink
Added AddRequirementForUnlock
Browse files Browse the repository at this point in the history
  • Loading branch information
Metious committed Sep 27, 2023
1 parent 9fe3f47 commit 972165b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
10 changes: 10 additions & 0 deletions Nautilus/Handlers/KnownTechHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ public static void UnlockOnStart(TechType techType)
KnownTechPatcher.UnlockedAtStart.Add(techType);
}

/// <summary>
/// Unlocks the <paramref name="blueprint"/> when the <paramref name="requirement"/> tech type is unlocked.
/// </summary>
/// <param name="blueprint">The blueprint to unlock.</param>
/// <param name="requirement">The tech type that will unlock the specified blueprint once unlocked.</param>
public static void AddRequirementForUnlock(TechType blueprint, TechType requirement)
{
KnownTechPatcher.BlueprintRequirements.GetOrAddNew(requirement).Add(blueprint);
}

internal static void AddAnalysisTech(KnownTech.AnalysisTech analysisTech)
{
if (analysisTech.techType != TechType.None)
Expand Down
29 changes: 21 additions & 8 deletions Nautilus/Patchers/KnownTechPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using Nautilus.Handlers;
using Nautilus.Utility;

namespace Nautilus.Patchers;
Expand All @@ -13,12 +14,11 @@ internal class KnownTechPatcher
internal static HashSet<TechType> UnlockedAtStart = new();
internal static HashSet<TechType> LockedWithNoUnlocks = 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);
internal static IDictionary<TechType, List<TechType>> RemoveFromSpecificTechs = new SelfCheckingDictionary<TechType, List<TechType>>("RemoveFromSpecificTechs", AsStringFunction);
internal static List<TechType> RemovalTechs = new();

private static FMODAsset UnlockSound;

public static void Patch(Harmony harmony)
{
harmony.Patch(AccessTools.Method(typeof(KnownTech), nameof(KnownTech.Initialize)),
Expand All @@ -35,12 +35,10 @@ internal static void InitializePrefix(PDAData data)
return;
}

data.defaultTech.AddRange(KnownTechPatcher.UnlockedAtStart);
data.defaultTech.AddRange(UnlockedAtStart);

foreach (var tech in KnownTechPatcher.AnalysisTech.Values)
foreach (var tech in AnalysisTech.Values)
{
data.defaultTech.Remove(tech.techType);

var index = data.analysisTech.FindIndex(analysisTech => analysisTech.techType == tech.techType);
if (index == -1)
{
Expand All @@ -52,12 +50,27 @@ internal static void InitializePrefix(PDAData data)
InternalLogger.Debug($"Replacing analysisTech for {tech.techType}");
data.analysisTech[index] = tech;
}

if (tech.unlockSound == null)
{
tech.unlockSound = KnownTechHandler.DefaultUnlockData.BlueprintUnlockSound;
}
}

foreach (var tech in KnownTechPatcher.CompoundTech.Values)
foreach (var blueprintRequirements in BlueprintRequirements)
{
data.defaultTech.Remove(tech.techType);
var index = data.analysisTech.FindIndex(tech => tech.techType == blueprintRequirements.Key);
if (index == -1)
{
InternalLogger.Error($"TechType '{blueprintRequirements.Key.AsString()}' does not have an analysis tech. Cancelling requirement addition.");
continue;
}

data.analysisTech[index].unlockTechTypes.AddRange(blueprintRequirements.Value);
}

foreach (var tech in CompoundTech.Values)
{
var index = data.compoundTech.FindIndex(compoundTech => compoundTech.techType == tech.techType);
if (index == -1)
{
Expand Down

0 comments on commit 972165b

Please sign in to comment.