Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct set analysis tech entry behavior breaking change #504

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Nautilus/Assets/Gadgets/ScanningGadget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,25 +381,25 @@ protected internal override void Build()
PDAHandler.AddEncyclopediaEntry(EncyclopediaEntryData);
}

if (AnalysisTech is { })
{
KnownTechHandler.SetAnalysisTechEntry(AnalysisTech);
}

if (CompoundTechsForUnlock is { Count: > 0 })
{
KnownTechHandler.RemoveAllCurrentAnalysisTechEntry(prefab.Info.TechType);
KnownTechHandler.SetCompoundUnlock(prefab.Info.TechType, CompoundTechsForUnlock);
}

if (AnalysisTech is { })
{
KnownTechHandler.SetAnalysisTechEntry(AnalysisTech);
}

if (ScannerEntryData is { })
{
PDAHandler.AddCustomScannerEntry(ScannerEntryData);
}

if (RequiredForUnlock != TechType.None)
{
KnownTechHandler.AddRequirementForUnlock(prefab.Info.TechType, RequiredForUnlock);
KnownTechHandler.SetAnalysisTechEntry(RequiredForUnlock, new TechType[] { prefab.Info.TechType });
}

if (CompoundTechsForUnlock is { Count: > 0 } || RequiredForUnlock != TechType.None)
Expand Down
59 changes: 46 additions & 13 deletions Nautilus/Handlers/KnownTechHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ private static void Reinitialize()
public static void UnlockOnStart(TechType techType)
{
KnownTechPatcher.UnlockedAtStart.Add(techType);

bool removed = false;
var removalList = new List<string>();
KnownTechPatcher.DefaultRemovalTechs.ForEach((x) =>
{
if (x.Value.Remove(techType))
{
removed = true;
InternalLogger.Debug($"Removed {techType.AsString()} from {x.Key}'s DefaultRemovalTechs");
if (x.Value.Count > 0 )
{
removalList.Add(x.Key);
}
}
});

foreach (string key in removalList)
KnownTechPatcher.DefaultRemovalTechs.Remove(key);

if (removed)
InternalLogger.Debug($"Set {techType.AsString()} to Unlock On Start ");
Reinitialize();
}

Expand All @@ -48,7 +69,7 @@ public static void AddRequirementForUnlock(TechType blueprint, TechType requirem
public static void SetHardLocked(TechType techType)
{
KnownTechPatcher.HardLocked.Add(techType);
KnownTechPatcher.UnlockedAtStart.Remove(techType);
RemoveDefaultUnlock(techType);
Reinitialize();
}

Expand Down Expand Up @@ -140,24 +161,25 @@ internal static void RemoveAnalysisSpecific(TechType targetTechType, List<TechTy
{
foreach (TechType techType in techTypes)
{
if (KnownTechPatcher.RemoveFromSpecificTechs.TryGetValue(techType, out List<TechType> types))
{
if (!types.Contains(targetTechType))
{
types.Add(targetTechType);
}
}
if (KnownTechPatcher.AnalysisTech.TryGetValue(techType, out var analysisTech) && analysisTech.unlockTechTypes.Remove(targetTechType))
InternalLogger.Debug($"Removed unlock for {targetTechType.AsString()} from {techType} that was added by another mod.");

if (KnownTechPatcher.RemoveFromSpecificTechs.TryGetValue(techType, out HashSet<TechType> types))
types.Add(targetTechType);
else
{
KnownTechPatcher.RemoveFromSpecificTechs[techType] = new List<TechType>() { targetTechType };
}
KnownTechPatcher.RemoveFromSpecificTechs[techType] = new HashSet<TechType>() { targetTechType };
}

Reinitialize();
}

internal static void RemoveAnalysisTechEntry(TechType targetTechType)
{
if (KnownTechPatcher.AnalysisTech.Remove(targetTechType))
{
InternalLogger.Debug($"Removed Analysis Tech for {targetTechType.AsString()} that was added by another mod!");
}

foreach (KnownTech.AnalysisTech tech in KnownTechPatcher.AnalysisTech.Values)
{
if (tech.unlockTechTypes.Remove(targetTechType))
Expand Down Expand Up @@ -186,6 +208,7 @@ internal static void RemoveAnalysisTechEntry(TechType targetTechType)
/// Allows you to define which TechTypes are unlocked when a certain TechType is unlocked, i.e., "analysed".
/// If there is already an existing AnalysisTech entry for a TechType, all the TechTypes in "techTypesToUnlock" will be
/// added to the existing AnalysisTech entry unlocks.
/// ***Note: This will not remove any original unlock and if you need to do so you should use <see cref="RemoveAllCurrentAnalysisTechEntry"/> before calling this method.
/// </summary>
/// <param name="techTypeToBeAnalysed">This TechType is the criteria for all of the "unlock TechTypes"; when this TechType is unlocked, so are all the ones in that list</param>
/// <param name="techTypesToUnlock">The TechTypes that will be unlocked when "techTypeToSet" is unlocked.</param>
Expand All @@ -198,6 +221,7 @@ public static void SetAnalysisTechEntry(TechType techTypeToBeAnalysed, IEnumerab
/// Allows you to define which TechTypes are unlocked when a certain TechType is unlocked, i.e., "analysed".
/// If there is already an existing AnalysisTech entry for a TechType, all the TechTypes in "techTypesToUnlock" will be
/// added to the existing AnalysisTech entry unlocks.
/// ***Note: This will not remove any original unlock and if you need to do so you should use <see cref="RemoveAllCurrentAnalysisTechEntry"/> before calling this method.
/// </summary>
/// <param name="techTypeToBeAnalysed">This TechType is the criteria for all of the "unlock TechTypes"; when this TechType is unlocked, so are all the ones in that list</param>
/// <param name="techTypesToUnlock">The TechTypes that will be unlocked when "techTypeToSet" is unlocked.</param>
Expand All @@ -211,6 +235,7 @@ public static void SetAnalysisTechEntry(TechType techTypeToBeAnalysed, IEnumerab
/// Allows you to define which TechTypes are unlocked when a certain TechType is unlocked, i.e., "analysed".
/// If there is already an existing AnalysisTech entry for a TechType, all the TechTypes in "techTypesToUnlock" will be
/// added to the existing AnalysisTech entry unlocks.
/// ***Note: This will not remove any original unlock and if you need to do so you should use <see cref="RemoveAllCurrentAnalysisTechEntry"/> before calling this method.
/// </summary>
/// <param name="techTypeToBeAnalysed">This TechType is the criteria for all of the "unlock TechTypes"; when this TechType is unlocked, so are all the ones in that list</param>
/// <param name="techTypesToUnlock">The TechTypes that will be unlocked when "techTypeToSet" is unlocked.</param>
Expand All @@ -224,6 +249,7 @@ public static void SetAnalysisTechEntry(TechType techTypeToBeAnalysed, IEnumerab
/// Allows you to define which TechTypes are unlocked when a certain TechType is unlocked, i.e., "analysed".
/// If there is already an exisitng AnalysisTech entry for a TechType, all the TechTypes in "techTypesToUnlock" will be
/// added to the existing AnalysisTech entry unlocks.
/// ***Note: This will not remove any original unlock and if you need to do so you should use <see cref="RemoveAllCurrentAnalysisTechEntry"/> before calling this method.
/// </summary>
/// <param name="techTypeToBeAnalysed">This TechType is the criteria for all of the "unlock TechTypes"; when this TechType is unlocked, so are all the ones in that list</param>
/// <param name="techTypesToUnlock">The TechTypes that will be unlocked when "techTypeToSet" is unlocked.</param>
Expand All @@ -237,6 +263,7 @@ public static void SetAnalysisTechEntry(TechType techTypeToBeAnalysed, IEnumerab
/// Allows you to define which TechTypes are unlocked when a certain TechType is unlocked, i.e., "analysed".
/// If there is already an existing AnalysisTech entry for a TechType, all the TechTypes in "techTypesToUnlock" will be
/// added to the existing AnalysisTech entry unlocks.
/// ***Note: This will not remove any original unlock and if you need to do so you should use <see cref="RemoveAllCurrentAnalysisTechEntry"/> before calling this method.
/// </summary>
/// <param name="techTypeToBeAnalysed">This TechType is the criteria for all of the "unlock TechTypes"; when this TechType is unlocked, so are all the ones in that list</param>
/// <param name="techTypesToUnlock">The TechTypes that will be unlocked when "techTypeToSet" is unlocked.</param>
Expand All @@ -251,6 +278,7 @@ public static void SetAnalysisTechEntry(TechType techTypeToBeAnalysed, IEnumerab
/// Allows you to define which TechTypes are unlocked when a certain TechType is unlocked, i.e., "analysed".
/// If there is already an existing AnalysisTech entry for a TechType, all the TechTypes in "techTypesToUnlock" will be
/// added to the existing AnalysisTech entry unlocks.
/// ***Note: This will not remove any original unlock and if you need to do so you should use <see cref="RemoveAllCurrentAnalysisTechEntry"/> before calling this method.
/// </summary>
/// <param name="techTypeToBeAnalysed">This TechType is the criteria for all of the "unlock TechTypes"; when this TechType is unlocked, so are all the ones in that list</param>
/// <param name="techTypesToUnlock">The TechTypes that will be unlocked when "techTypeToSet" is unlocked.</param>
Expand All @@ -265,6 +293,7 @@ public static void SetAnalysisTechEntry(TechType techTypeToBeAnalysed, IEnumerab
/// Allows you to define which TechTypes are unlocked when a certain TechType is unlocked, i.e., "analysed".
/// If there is already an existing AnalysisTech entry for a TechType, all the TechTypes in "techTypesToUnlock" will be
/// added to the existing AnalysisTech entry unlocks.
/// ***Note: This will not remove any original unlock and if you need to do so you should use <see cref="RemoveAllCurrentAnalysisTechEntry"/> before calling this method.
/// </summary>
/// <param name="techTypeToBeAnalysed">This TechType is the criteria for all of the "unlock TechTypes"; when this TechType is unlocked, so are all the ones in that list</param>
/// <param name="techTypesToUnlock">The TechTypes that will be unlocked when "techTypeToSet" is unlocked.</param>
Expand All @@ -279,6 +308,7 @@ public static void SetAnalysisTechEntry(TechType techTypeToBeAnalysed, IEnumerab
/// Allows you to define which TechTypes are unlocked when a certain TechType is unlocked, i.e., "analysed".
/// If there is already an existing AnalysisTech entry for a TechType, all the TechTypes in <see cref="KnownTech.AnalysisTech.unlockTechTypes"/> will be
/// added to the existing AnalysisTech entry unlocks.
/// ***Note: This will not remove any original unlock and if you need to do so you should use <see cref="RemoveAllCurrentAnalysisTechEntry"/> before calling this method.
/// </summary>
/// <param name="analysisTech">The analysis tech entry to add.</param>
public static void SetAnalysisTechEntry(KnownTech.AnalysisTech analysisTech)
Expand All @@ -290,6 +320,7 @@ public static void SetAnalysisTechEntry(KnownTech.AnalysisTech analysisTech)
/// Allows you to define which TechTypes are unlocked when a certain TechType is unlocked, i.e., "analysed".
/// If there is already an existing AnalysisTech entry for a TechType, all the TechTypes in "techTypesToUnlock" will be
/// added to the existing AnalysisTech entry unlocks.
/// ***Note: This will not remove any original unlock and if you need to do so you should use <see cref="RemoveAllCurrentAnalysisTechEntry"/> before calling this method.
/// </summary>
/// <param name="techTypeToBeAnalysed">This TechType is the criteria for all of the "unlock TechTypes"; when this TechType is unlocked, so are all the ones in that list</param>
/// <param name="techTypesToUnlock">The TechTypes that will be unlocked when "techTypeToSet" is unlocked.</param>
Expand All @@ -303,7 +334,7 @@ public static void SetAnalysisTechEntry(TechType techTypeToBeAnalysed, IEnumerab

/// <summary>
/// Allows you to set up a custom Compound Unlock requiring multiple techtypes to be unlocked before 1 is.
/// ***Note: This will not remove any original unlock and if you need to do so you should use <see cref="RemoveAnalysisTechEntryFromSpecific"/> or <see cref="RemoveAllCurrentAnalysisTechEntry"/>
/// ***Note: This will not remove any original unlock and if you need to do so you should use <see cref="RemoveAllCurrentAnalysisTechEntry"/> before calling this method.
/// </summary>
/// <param name="techType"></param>
/// <param name="compoundTechsForUnlock"></param>
Expand Down Expand Up @@ -344,10 +375,12 @@ 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 = new HashSet<TechType>();
techTypes.Add(techType);

KnownTechPatcher.DefaultRemovalTechs[modName] = techTypes;
if (KnownTechPatcher.UnlockedAtStart.Remove(techType))
InternalLogger.Debug($"Removed Default unlock for {techType} that was added by another mod.");
Reinitialize();
}

Expand Down
Loading
Loading