diff --git a/UXAssist/Functions/TechFunctions.cs b/UXAssist/Functions/TechFunctions.cs index 0870e73..80dbacb 100644 --- a/UXAssist/Functions/TechFunctions.cs +++ b/UXAssist/Functions/TechFunctions.cs @@ -14,33 +14,11 @@ public static class TechFunctions I18N.Add("Batch buyout tech", "Batch buyout tech", "批量买断科技"); } - public static void GenerateTechListWithPrerequisites(GameHistoryData history, int techId, List techIdList) + private static void CheckTechUnlockProperties(GameHistoryData history, TechProto techProto, SortedList properties, List> techList, int maxLevel = 10000, bool withPrerequisites = true, HashSet seenTechs = null) { - var techProto = LDB.techs.Select(techId); - if (techProto == null || !techProto.Published) return; - var flag = true; - for (var i = 0; i < 2; i++) - { - foreach (var preTechId in (i == 1 ? techProto.PreTechsImplicit : techProto.PreTechs)) - { - if (!history.techStates.ContainsKey(preTechId) || history.techStates[preTechId].unlocked) continue; - if (history.techStates[preTechId].maxLevel > history.techStates[preTechId].curLevel) - { - flag = false; - } - GenerateTechListWithPrerequisites(history, preTechId, techIdList); - } - } - if (history.techStates.ContainsKey(techId) && !history.techStates[techId].unlocked && flag) - { - techIdList.Add(techId); - } - } - - private static void CheckTechUnlockProperties(GameHistoryData history, TechProto techProto, SortedList properties, List> techList, int maxLevel = 10000, bool withPrerequisites = true) - { - var techStates = history.techStates; var techID = techProto.ID; + if (seenTechs!.Contains(techID)) return; + var techStates = history.techStates; if (techStates == null || !techStates.TryGetValue(techID, out var value)) return; if (value.unlocked) return; @@ -51,18 +29,19 @@ public static class TechFunctions { var preProto = LDB.techs.Select(preid); if (preProto != null) - CheckTechUnlockProperties(history, preProto, properties, techList, techProto.PreTechsMax ? 10000 : preProto.Level, true); + CheckTechUnlockProperties(history, preProto, properties, techList, techProto.PreTechsMax ? 10000 : preProto.Level, true, seenTechs); } foreach (var preid in techProto.PreTechsImplicit) { var preProto = LDB.techs.Select(preid); if (preProto != null) - CheckTechUnlockProperties(history, preProto, properties, techList, techProto.PreTechsMax ? 10000 : preProto.Level, true); + CheckTechUnlockProperties(history, preProto, properties, techList, techProto.PreTechsMax ? 10000 : preProto.Level, true, seenTechs); } } if (value.curLevel < techProto.Level) value.curLevel = techProto.Level; techList.Add(new Tuple(techProto, value.curLevel, techProto.Level)); + seenTechs!.Add(techID); while (value.curLevel <= maxLvl) { if (techProto.PropertyOverrideItemArray != null) @@ -184,7 +163,7 @@ public static class TechFunctions techProtos.Add(techProto); } } - UnlockProtoWithMetadataAndPrompt([.. techProtos], 16, false); + UnlockProtoWithMetadataAndPrompt([.. techProtos], 16, true); } public static void UnlockProtoWithMetadataAndPrompt(TechProto[] techProtos, int toLevel, bool withPrerequisites = true) @@ -192,9 +171,10 @@ public static class TechFunctions var techList = new List>(); var properties = new SortedList(); var history = GameMain.history; + var seenTechs = new HashSet(); foreach (var techProto in techProtos) { - CheckTechUnlockProperties(history, techProto, properties, techList, toLevel, withPrerequisites); + CheckTechUnlockProperties(history, techProto, properties, techList, toLevel, withPrerequisites, seenTechs); } var propertySystem = DSPGame.propertySystem; var clusterSeedKey = history.gameData.GetClusterSeedKey(); diff --git a/UXAssist/Patches/FactoryPatch.cs b/UXAssist/Patches/FactoryPatch.cs index d370d13..398342e 100644 --- a/UXAssist/Patches/FactoryPatch.cs +++ b/UXAssist/Patches/FactoryPatch.cs @@ -2579,10 +2579,7 @@ public class FactoryPatch : PatchImpl foreach (var kvp in takeOutItems) { var added = mainPlayer.TryAddItemToPackage(kvp.Key, (int)(kvp.Value & 0xFFFFFFFF), (int)(kvp.Value >> 32), true, entityId); - if (added > 0) - { - UIItemup.Up(kvp.Key, added); - } + if (added > 0) UIItemup.Up(kvp.Key, added); } } } diff --git a/UXAssist/Patches/TechPatch.cs b/UXAssist/Patches/TechPatch.cs index 12e1253..db36121 100644 --- a/UXAssist/Patches/TechPatch.cs +++ b/UXAssist/Patches/TechPatch.cs @@ -134,6 +134,7 @@ public static class TechPatch _protoPatched = false; } + LDB.techs.Signature = ProtoSignature_0_10_30_3100.CalculateSignature(LDB.techs); var techTree = UIRoot.instance?.uiGame?.techTree; if (techTree != null && techTree.isActiveAndEnabled) techTree.OnPageChanged(); @@ -268,6 +269,7 @@ public static class TechPatch _originTechPosts.Clear(); _protoPatched = false; } + LDB.techs.Signature = ProtoSignature_0_10_30_3100.CalculateSignature(LDB.techs); var nodes = UIRoot.instance.uiGame.techTree.nodes; var history = GameMain.history; foreach (var item in nodes)