Exemplo n.º 1
0
        internal void AddCompoundUnlock(TechType techType, List <TechType> compoundTechsForUnlock)
        {
            if (techType == TechType.None)
            {
                Logger.Error("Cannot Add Unlock to TechType.None!");
                return;
            }

            if (compoundTechsForUnlock.Contains(techType))
            {
                Logger.Error("Cannot Add Compound Unlock that contains itself!");
                return;
            }


            if (KnownTechPatcher.CompoundTech.TryGetValue(techType, out KnownTech.CompoundTech compoundTech))
            {
                Logger.Debug($"Compound Unlock already found for {techType.AsString()}, Overwriting.");
                compoundTech.dependencies = compoundTechsForUnlock;
            }
            else
            {
                Logger.Debug($"Adding Compound Unlock for {techType.AsString()}");
                KnownTechPatcher.CompoundTech.Add(techType, new KnownTech.CompoundTech()
                {
                    techType = techType, dependencies = compoundTechsForUnlock
                });
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Safely adds a new crafting node to the custom crafting tree of this fabricator.<para/>
        /// If the item has not been patched yet, its <see cref="Spawnable.Patch"/> method will first be invoked.
        /// </summary>
        /// <param name="item">The <see cref="Craftable"/> item to craft from this fabricator.</param>
        /// <param name="parentTabId">Optional. The parent tab of this craft node.<para/>
        /// When this value is null, the item's <see cref="Craftable.StepsToFabricatorTab"/> property will be checked instead.<para/>
        /// The craft node will be added to the root of the craft tree if both are null.</param>
        public void AddCraftNode(Craftable item, string parentTabId = null)
        {
            Logger.Debug($"'{item.ClassID}' will be added to the custom craft tree '{this.ClassID}'");
            OrderedCraftTreeActions.Add(() =>
            {
                if (item.TechType == TechType.None)
                {
                    Logger.Info($"'{item.ClassID} had to be patched early to obtain its TechType value for the custom craft tree '{this.ClassID}'");
                    item.Patch();
                }

                string[] stepsToParent = item.StepsToFabricatorTab;

                if (parentTabId == null)
                {
                    if (stepsToParent != null && stepsToParent.Length > 0)
                    {
                        int last    = stepsToParent.Length - 1;
                        parentTabId = stepsToParent[last];
                    }
                    else
                    {
                        parentTabId = RootNode;
                    }
                }

                ModCraftTreeLinkingNode parentTab = CraftTreeLinkingNodes[parentTabId];
                parentTab.AddCraftingNode(item.TechType);
            });
        }
Exemplo n.º 3
0
        internal void RemoveAnalysisTechEntry(TechType targetTechType)
        {
            foreach (KnownTech.AnalysisTech tech in KnownTechPatcher.AnalysisTech.Values)
            {
                if (tech.unlockTechTypes.Contains(targetTechType))
                {
                    Logger.Debug($"Removed {targetTechType.AsString()} from {tech.techType.AsString()} unlocks that was added by another mod!");
                    tech.unlockTechTypes.Remove(targetTechType);
                }
            }

            if (KnownTechPatcher.CompoundTech.TryGetValue(targetTechType, out var types))
            {
                Logger.Debug($"Removed Compound Unlock for {targetTechType.AsString()} that was added by another mod!");
                KnownTechPatcher.CompoundTech.Remove(targetTechType);
            }

            if (KnownTechPatcher.UnlockedAtStart.Contains(targetTechType))
            {
                Logger.Debug($"Removed UnlockedAtStart for {targetTechType.AsString()} that was added by another mod!");
                KnownTechPatcher.UnlockedAtStart.Remove(targetTechType);
            }

            if (!KnownTechPatcher.RemovalTechs.Contains(targetTechType))
            {
                KnownTechPatcher.RemovalTechs.Add(targetTechType);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Adds a new crafting node to the custom crafting tree of this fabricator.
 /// </summary>
 /// <param name="techType">The item to craft.</param>
 /// <param name="parentTabId">Optional. The parent tab of this craft node.<para/>
 /// When this value is null, the craft node will be added to the root of the craft tree.</param>
 public void AddCraftNode(TechType techType, string parentTabId = null)
 {
     Logger.Debug($"'{techType.AsString()}' will be added to the custom craft tree '{this.ClassID}'");
     OrderedCraftTreeActions.Add(() =>
     {
         ModCraftTreeLinkingNode parentTab = CraftTreeLinkingNodes[parentTabId ?? RootNode];
         parentTab.AddCraftingNode(techType);
     });
 }
Exemplo n.º 5
0
        private static void AddPrefabInternal(GameObject prefab, bool autoremove)
        {
            if (autoremove)
            {
                prefabs.Add(Tuple.Create(Time.time, prefab));
            }

            Logger.Debug($"ModPrefabCache: adding prefab {prefab}");
        }
Exemplo n.º 6
0
        public static void Patch(Harmony harmony)
        {
            Type creatureType = typeof(Creature);
            Type thisType     = typeof(FishPatcher);

            harmony.Patch(AccessTools.Method(typeof(Creature), nameof(Creature.Start)),
                          postfix: new HarmonyMethod(typeof(FishPatcher), nameof(FishPatcher.CreatureStart_Postfix)));

            Logger.Debug("CustomFishPatcher is done.");
        }
Exemplo n.º 7
0
            public void Update()
            {
                for (int i = prefabs.Count - 1; i >= 0; i--)
                {
                    if (Time.time < prefabs[i].Item1 + cleanDelay || Builder.prefab == prefabs[i].Item2)
                    {
                        continue;
                    }

                    Logger.Debug($"ModPrefabCache: removing prefab {prefabs[i].Item2}");

                    Destroy(prefabs[i].Item2);
                    prefabs.RemoveAt(i);
                }
            }
Exemplo n.º 8
0
 /// <summary>
 /// Safely attempts to add a new crafting node to the custom crafting tree of this fabricator.<para/>
 /// If the modded TechType is not found, the craft node will not be added.
 /// </summary>
 /// <param name="moddedTechType">The modded item to craft.</param>
 /// <param name="parentTabId">Optional. The parent tab of this craft node.<para/>
 /// When this value is null, the craft node will be added to the root of the craft tree.</param>
 public void AddCraftNode(string moddedTechType, string parentTabId = null)
 {
     Logger.Debug($"'{moddedTechType}' will be added to the custom craft tree '{this.ClassID}'");
     OrderedCraftTreeActions.Add(() =>
     {
         if (this.TechTypeHandler.TryGetModdedTechType(moddedTechType, out TechType techType))
         {
             ModCraftTreeLinkingNode parentTab = CraftTreeLinkingNodes[parentTabId ?? RootNode];
             parentTab.AddCraftingNode(techType);
         }
         else
         {
             Logger.Info($"Did not find a TechType value for '{moddedTechType}' to add to the custom craft tree '{this.ClassID}'");
         }
     });
 }
Exemplo n.º 9
0
        private void Update()
        {
            if (!initalized)
            {
                time       = Time.time + 1f;
                initalized = true;
            }

            var prefab = (GameObject)BuilderPrefab.GetValue(null);

            if (transform.position == new Vector3(-5000, -5000, -5000) && gameObject != prefab && Time.time > time)
            {
                Logger.Debug("Destroying object: " + gameObject);
                Destroy(gameObject);
            }
        }
        private static IPrefabRequest GetModPrefabAsync(string classId)
        {
            if (!ModPrefab.TryGetFromClassId(classId, out ModPrefab prefab))
            {
                return(null);
            }

            try
            {
                // trying sync method first
                if (prefab.GetGameObjectInternal() is GameObject go)
                {
                    return(new LoadedPrefabRequest(go));
                }
            }
            catch (Exception e)
            {
                Logger.Debug($"Caught exception while calling GetGameObject for {classId}, trying GetGameObjectAsync now. {Environment.NewLine}{e}");
            }

            return(new ModPrefabRequest(prefab));
        }
Exemplo n.º 11
0
        private void Update()
        {
            if (!initalized)
            {
                time       = Time.time + 1f;
                initalized = true;
            }

            if (Time.time > time && this.gameObject != Builder.prefab)
            {
                if (this.transform.position.y < -4500)
                {
                    Logger.Debug("Destroying object: " + this.gameObject);
                    Destroy(this.gameObject);
                }
                else
                {
                    Logger.Debug("Destroying Fixer for object: " + this.gameObject);
                    Destroy(this);
                }
            }
        }