protected override RecipeData GetBlueprintRecipe()
        {
            TechType ttLizardScale = Main.GetNitrogenTechtype("lavalizardscale");

            if (ttLizardScale == TechType.None)
            {
                return new RecipeData()
                       {
                       }
            }
            ;


            RecipeData recipe = new RecipeData()
            {
                craftAmount = 0,
                Ingredients = new List <Ingredient>(new Ingredient[]
                {
                    new Ingredient(Main.GetNitrogenTechtype("ReinforcedSuit2"), 1),
                    new Ingredient(TechType.HydrochloricAcid, 1),
                    new Ingredient(TechType.CreepvinePiece, 2),
                    new Ingredient(TechType.Aerogel, 1),
                    new Ingredient(TechType.Kyanite, 2),
                    new Ingredient(ttLizardScale, 2)
                })
            };

            recipe.LinkedItems.Add(TechTypeUtils.GetModTechType("NitrogenBrineSuit3"));

            return(recipe);
        }
示例#2
0
            public static bool TryGet(TechType originTech, out TechType recyclingTech, bool initialRun = false)
            {
                recyclingTech = TechType.None;
                if (originTech == TechType.None)
                {
                    return(false);
                }
                if (cache.TryGetValue(originTech, out recyclingTech))
                {
                    return(true);
                }
#if SUBNAUTICA
                RecipeData originData = CraftDataHandler.GetTechData(originTech);
#elif BELOWZERO
                RecipeData originData = CraftDataHandler.GetRecipeData(originTech);
#endif
                if (originData == null)
                {
                    if (!initialRun)
                    {
                        Logger.Log(Logger.Level.Error, $"Failed to load RecipeData for TechType '{originTech}'.");
                    }
                    return(false);
                }

                if (Config.IsBlacklisted(originTech))
                {
                    blacklist.Add(originTech);
                }
                recyclingTech     = CreateRecyclingData(originTech, originData);
                cache[originTech] = recyclingTech;

                return(true);
            }
        protected override RecipeData GetBlueprintRecipe()
        {
            TechType ttEelScale    = Main.GetNitrogenTechtype("rivereelscale");
            TechType ttLizardScale = Main.GetNitrogenTechtype("lavalizardscale");

            if (ttEelScale == TechType.None || ttLizardScale == TechType.None)
            {
                return new RecipeData()
                       {
                       }
            }
            ;

            RecipeData recipe = new RecipeData()
            {
                craftAmount = 0,
                Ingredients = new List <Ingredient>(new Ingredient[]
                {
                    new Ingredient(TechTypeUtils.GetModTechType("AcidGloves"), 1),
                    new Ingredient(TechType.AluminumOxide, 2),
                    new Ingredient(ttEelScale, 2),
                    new Ingredient(TechType.Kyanite, 2),
                    new Ingredient(ttLizardScale, 2)
                })
            };

            recipe.LinkedItems.Add(TechTypeUtils.GetModTechType("NitrogenBrineSuit3"));

            return(recipe);
        }
        // This is the recipe that uses an existing Rad Suit and Reinforced Dive Suit
        protected override RecipeData GetBlueprintRecipe()
        {
            RecipeData recipe = new RecipeData()
            {
                craftAmount = 0,
                Ingredients = new List <Ingredient>(new Ingredient[]
                {
                    new Ingredient(TechType.HydrochloricAcid, 1),
                    new Ingredient(TechType.CreepvinePiece, 2),
                    new Ingredient(TechType.Aerogel, 1),
                    new Ingredient(TechType.RadiationGloves, 1),
                    new Ingredient(TechType.RadiationHelmet, 1),
                    new Ingredient(TechType.RadiationSuit, 1),
                    new Ingredient(TechType.ReinforcedDiveSuit, 1),
                    new Ingredient(TechType.ReinforcedGloves, 1),
                    new Ingredient(TechType.AramidFibers, 1),
                    new Ingredient(TechType.WiringKit, 1)
                })
            };

            recipe.LinkedItems.Add(TechTypeUtils.GetModTechType("AcidSuit"));
            recipe.LinkedItems.Add(TechTypeUtils.GetModTechType("AcidHelmet"));
            recipe.LinkedItems.Add(TechTypeUtils.GetModTechType("AcidGloves"));

            return(recipe);
        }
        // This is the recipe that uses an existing Rebreather only
        protected override RecipeData GetBlueprintRecipe()
        {
            RecipeData recipe = new RecipeData()
            {
                craftAmount = 0,
                Ingredients = new List <Ingredient>(new Ingredient[]
                {
                    new Ingredient(TechType.HydrochloricAcid, 1),
                    new Ingredient(TechType.CreepvinePiece, 2),
                    new Ingredient(TechType.Aerogel, 1),
                    new Ingredient(TechType.Lead, 2),
                    new Ingredient(TechType.AramidFibers, 2),
                    new Ingredient(TechType.Diamond, 2),
                    new Ingredient(TechType.Titanium, 1),
                    new Ingredient(TechType.Rebreather, 1)
                })
            };

            recipe.LinkedItems.Add(TechTypeUtils.GetModTechType("AcidGloves"));
            recipe.LinkedItems.Add(TechTypeUtils.GetModTechType("AcidHelmet"));
            recipe.LinkedItems.Add(TechTypeUtils.GetModTechType("AcidSuit"));
            //recipe.LinkedItems.Add(Main.prefabGloves.TechType);
            //recipe.LinkedItems.Add(Main.prefabHelmet.TechType);
            //recipe.LinkedItems.Add(Main.prefabSuitMk1.TechType);

            return(recipe);
        }
        protected override RecipeData GetBlueprintRecipe()
        {
            RecipeData recipe = new RecipeData()
            {
                craftAmount = 1,
                Ingredients = new List <Ingredient>(new Ingredient[]
                {
                    new Ingredient(TechType.HydrochloricAcid, 1),
                    new Ingredient(TechType.CreepvinePiece, 2),
                    new Ingredient(TechType.Aerogel, 1),
                    new Ingredient(TechType.AramidFibers, 3),
                    new Ingredient(TechType.Diamond, 2),
                    new Ingredient(TechType.Titanium, 2),
                    new Ingredient(TechType.Lead, 2),
                    new Ingredient(TechType.WiringKit, 1)
                })
            };

            //recipe.LinkedItems.Add(AcidGlovesPrefab.TechTypeID);
            //recipe.LinkedItems.Add(AcidHelmetPrefab.TechTypeID);
            recipe.LinkedItems.Add(TechTypeUtils.GetModTechType("AcidGloves"));
            recipe.LinkedItems.Add(TechTypeUtils.GetModTechType("AcidHelmet"));

            return(recipe);
        }
示例#7
0
 public TankCraftHelper(TechType baseTank) : base(baseTank.AsString(false) + "RefillHelper", "Refilled " + Language.main.Get(baseTank), "Refilled " + Language.main.Get(baseTank))
 {
     Log.LogDebug($"{baseTank.AsString(false) + "RefillHelper"} constructor initialising; this.TechType == {this.TechType.AsString()}");
     OnFinishedPatching += () =>
     {
         Log.LogDebug($"{this.TechType.AsString(false)} OnFinishedPatching begin");
         RequiredUnlockDict[this.TechType] = baseTank;
         thisBaseTank = baseTank;
         Main.bannedTech.Add(this.TechType);
         Log.LogDebug($"{this.TechType.AsString(false)} adding crafting node");
         CraftTreeHandler.AddCraftingNode(CraftTree.Type.Fabricator, this.TechType, new string[] {
             "Personal",
             "TankRefill",
             this.TechType.AsString(false)
         });
         myRecipe = new RecipeData()
         {
             craftAmount = 0,
             Ingredients = new List <Ingredient>()
             {
                 new Ingredient(baseTank, 1)
             }
         };
         myRecipe.LinkedItems.Add(baseTank);
         Log.LogDebug($"{this.TechType.AsString(false)} OnFinishedPatching completed");
     };
 }
示例#8
0
        //private List<RecipeOverride> defaultRecipeOverrides

        public bool TryOverrideRecipe(TechType fragment, out RecipeData outRecipe)
        {
            string sFragment = fragment.ToString();

            foreach (RecipeOverride r in RecipeOverrides)
            {
                if (sFragment == r.overridden)
                {
                    outRecipe = new RecipeData();
                    foreach (StringIngredient s in r.replacements)
                    {
                        if (TechTypeUtils.TryGetModTechType(s.techType, out TechType t))
                        {
                            outRecipe.Ingredients.Add(new Ingredient(t, s.amount));
                        }
                        else
                        {
#if !RELEASE
                            Logger.Log(Logger.Level.Error, $"Could not parse {s.techType} as TechType; check the spelling and/or case");
#endif
                            outRecipe = null;
                            return(false);
                        }
                    }
                    return(true);
                }
            }
            outRecipe = null;
            return(false);
        }
示例#9
0
        public void PostPatch()
        {
            //patch crafting recipes
            //is there a more efficient way of doing this?
            var techDataBlade = new RecipeData()
            {
                craftAmount = 3,
                Ingredients = new List <Ingredient>()
                {
                    new Ingredient(TechType.Titanium, 3)
                }
            };

            CraftDataHandler.SetTechData(turbineBlade, techDataBlade);
            CraftTreeHandler.AddCraftingNode(CraftTree.Type.Fabricator, turbineBlade, new string[] { "Resources", "Electronics" });
            KnownTechHandler.SetAnalysisTechEntry(TechType.WiringKit, new TechType[] { turbineBlade });
            CraftDataHandler.SetItemSize(turbineBlade, new Vector2int(2, 1));
            //SetItemSize(turbineBlade, 2, 1);

            var techDataGen = new RecipeData()
            {
                craftAmount = 1,
                Ingredients = new List <Ingredient>()
                {
                    new Ingredient(TechType.WiringKit, 1),
                    new Ingredient(TechType.PowerCell, 1),
                    new Ingredient(TechType.Lubricant, 1)
                }
            };

            CraftDataHandler.SetTechData(turbineGenerator, techDataGen);
            KnownTechHandler.SetAnalysisTechEntry(TechType.WiringKit, new TechType[] { turbineGenerator });
            CraftTreeHandler.AddCraftingNode(CraftTree.Type.Fabricator, turbineGenerator, new string[] { "Resources", "Electronics" });
            CraftDataHandler.SetItemSize(turbineGenerator, new Vector2int(2, 2));
            //SetItemSize(turbineBlade, 2, 2);

            var techDataPole = new RecipeData()
            {
                craftAmount = 1,
                Ingredients = new List <Ingredient>()
                {
                    new Ingredient(TechType.Titanium, 4)
                }
            };

            CraftDataHandler.SetTechData(turbinePole, techDataPole);
            KnownTechHandler.SetAnalysisTechEntry(TechType.WiringKit, new TechType[] { turbinePole });
            CraftTreeHandler.AddCraftingNode(CraftTree.Type.Fabricator, turbinePole, new string[] { "Resources", "Electronics" });
            CraftDataHandler.SetItemSize(turbinePole, new Vector2int(1, 2));
            //SetItemSize(turbineBlade, 1, 2);

            //Add the databank entry.
            LanguageHandler.SetLanguageLine("Ency_WindTurbine", "Wind Turbine");
            LanguageHandler.SetLanguageLine("EncyDesc_WindTurbine", string.Format("A large generator suspended by 17.5 meter tall pole. The lightweight blades are rotated by the planet's strong air currents and efficiently converts the force into electrical energy. The generator contains a large internal battery that can hold up to {0} units of power. Unlike solar panels, these operate at roughly the same efficiency throughout the day. Orientation does not appear to affect power output. However certain places seem to simply have more wind than others. Power output also increases with altitude.", config.MaxPower));

            //This just isn't working for now. Maybe another update?
            //var windTool = new WindTool.WindToolPatch();
            //windTool.Patch();
        }
        public static void Postfix()
        {
            if (Main.config.Hardcore)
            {
                Dictionary <TechType, PDAScanner.EntryData> map = PDAScanner.mapping;
                foreach (TechType techType in Enum.GetValues(typeof(TechType)))
                {
                    RecipeData data = Main.GetData(techType);
                    map.TryGetValue(techType, out PDAScanner.EntryData entryData);

                    if (data is null && entryData != null && !entryData.isFragment && entryData.blueprint == TechType.None)
                    {
                        entryData.blueprint = techType;
                        entryData.locked    = true;
                        continue;
                    }

                    if (data != null && entryData is null && (data.ingredientCount == 0 || techType == TechType.Titanium))
                    {
                        map[techType] = new PDAScanner.EntryData()
                        {
                            key              = techType,
                            blueprint        = techType,
                            destroyAfterScan = false,
                            isFragment       = false,
                            locked           = true,
                            scanTime         = 2f,
                            totalFragments   = 1
                        };
                        continue;
                    }

                    if (data != null && entryData != null && !entryData.isFragment && entryData.blueprint == TechType.None && (data.ingredientCount == 0 || techType == TechType.Titanium))
                    {
                        entryData.blueprint = techType;
                        entryData.locked    = true;
                        continue;
                    }

                    if (data is null && entryData is null)
                    {
                        map[techType] = new PDAScanner.EntryData()
                        {
                            key              = techType,
                            blueprint        = techType,
                            destroyAfterScan = false,
                            isFragment       = false,
                            locked           = true,
                            scanTime         = 2f,
                            totalFragments   = 1
                        };
                        continue;
                    }
                }
            }
        }
        protected override RecipeData GetBlueprintRecipe()
        {
            if (!Main.HasNitrogenMod())
            {
                return new RecipeData()
                       {
                       }
            }
            ;

            TechType ttEelScale    = Main.GetNitrogenTechtype("rivereelscale");
            TechType ttLizardScale = Main.GetNitrogenTechtype("lavalizardscale");

            if (ttEelScale == TechType.None || ttLizardScale == TechType.None)
            {
                return new RecipeData()
                       {
                       }
            }
            ;

            RecipeData recipe = new RecipeData()
            {
                craftAmount = 1,
                Ingredients = new List <Ingredient>(new Ingredient[]
                {
                    new Ingredient(TechType.HydrochloricAcid, 1),
                    new Ingredient(TechType.CreepvinePiece, 2),
                    new Ingredient(TechType.Aerogel, 1),
                    new Ingredient(TechType.AramidFibers, 3),
                    new Ingredient(TechType.Diamond, 2),
                    new Ingredient(TechType.Titanium, 2),
                    new Ingredient(TechType.Lead, 2),
                    new Ingredient(TechType.WiringKit, 1),
                    new Ingredient(TechType.AluminumOxide, 2),
                    new Ingredient(ttEelScale, 2),
                    new Ingredient(TechType.Kyanite, 2),
                    new Ingredient(ttLizardScale, 2)
                })
            };

            recipe.LinkedItems.Add(TechTypeUtils.GetModTechType("AcidGloves"));
            recipe.LinkedItems.Add(TechTypeUtils.GetModTechType("AcidHelmet"));

            return(recipe);
        }
示例#12
0
        public override RecipeData GetBlueprintRecipe()
        {
            var partsList = new List <Ingredient>()
            {
                new Ingredient(baseBattery.TechType, 2),
                new Ingredient(TechType.Silicone, 1),
            };

            CreateIngredients(this.Parts, partsList);

            var batteryBlueprint = new RecipeData
            {
                craftAmount = 1,
                Ingredients = partsList
            };

            return(batteryBlueprint);
        }
        protected override RecipeData GetBlueprintRecipe()
        {
            RecipeData recipe = new RecipeData()
            {
                craftAmount = 0,
                Ingredients = new List <Ingredient>(new Ingredient[]
                {
                    new Ingredient(Main.GetNitrogenTechtype("ReinforcedSuit3"), 1),
                    new Ingredient(TechType.HydrochloricAcid, 1),
                    new Ingredient(TechType.CreepvinePiece, 2),
                    new Ingredient(TechType.Aerogel, 1)
                })
            };

            recipe.LinkedItems.Add(TechTypeUtils.GetModTechType("NitrogenBrineSuit3"));

            return(recipe);
        }
        protected override RecipeData GetBlueprintRecipe()
        {
            RecipeData recipe = new RecipeData()
            {
                craftAmount = 1,
                Ingredients = new List <Ingredient>(new Ingredient[]
                {
                    new Ingredient(TechType.DiamondBlade, 1),
                    new Ingredient(TechType.Battery, 1),
                    new Ingredient(TechType.Diamond, 1),
                    new Ingredient(TechType.Quartz, 1),
                    new Ingredient(TechType.Aerogel, 1),
                    new Ingredient(TechType.Magnetite, 1),
                    new Ingredient(TechType.WiringKit, 1)
                })
            };

            return(recipe);
        }
示例#15
0
        public virtual RecipeData GetBlueprintRecipe()
        {
            var partsList = new List <Ingredient>();

            CreateIngredients(this.Parts, partsList);

            if (partsList.Count == 0)
            {
                partsList.Add(new Ingredient(TechType.Titanium, 1));
            }

            var batteryBlueprint = new RecipeData
            {
                craftAmount = 1,
                Ingredients = partsList
            };

            return(batteryBlueprint);
        }
        protected override RecipeData GetBlueprintRecipe()
        {
            RecipeData recipe = new RecipeData()
            {
                craftAmount = 0,
                Ingredients = new List <Ingredient>(new Ingredient[]
                {
                    new Ingredient(Main.GetNitrogenTechtype("ReinforcedSuit2"), 1),
                    new Ingredient(TechType.HydrochloricAcid, 1),
                    new Ingredient(TechType.FiberMesh, 1),
                    new Ingredient(TechType.Aerogel, 1)
                }),
                LinkedItems = new List <TechType>()
                {
                    TechTypeUtils.GetModTechType("NitrogenBrineSuit2")
                }
            };

            return(recipe);
        }
        protected override RecipeData GetBlueprintRecipe()
        {
            if (!Main.HasNitrogenMod())
            {
                return new RecipeData()
                       {
                       }
            }
            ;

            TechType ttEelScale    = Main.GetNitrogenTechtype("rivereelscale");
            TechType ttLizardScale = Main.GetNitrogenTechtype("lavalizardscale");

            if (ttEelScale == TechType.None || ttLizardScale == TechType.None)
            {
                return new RecipeData()
                       {
                       }
            }
            ;

            RecipeData recipe = new RecipeData()
            {
                craftAmount = 1,
                Ingredients = new List <Ingredient>(new Ingredient[]
                {
                    new Ingredient(TechTypeUtils.GetModTechType("NitrogenBrineSuit2"), 1),
                    new Ingredient(TechType.Kyanite, 2),
                    new Ingredient(ttLizardScale, 2)
                }),
                //LinkedItems = new List<TechType>()
                //{
                //    TechTypeUtils.GetModTechType("AcidGloves"),
                //    TechTypeUtils.GetModTechType("AcidHelmet")
                //}
            };



            return(recipe);
        }
示例#18
0
            private static string LoadRecyclingTooltip(TechType originTech, RecipeData data)
            {
                if (IsBlackListed(originTech))
                {
                    return(nonRecyclableTooltip);
                }

                if (data == null)
                {
                    return(nonRecyclableTooltip);
                }
                var ings = new Dictionary <TechType, int>();

                for (var i = 0; i < data.linkedItemCount; i++)
                {
                    var item = data.GetLinkedItem(i);
                    ings[item] = ings.ContainsKey(item) ? (ings[item] + 1) : 1;
                }

                var builder = new System.Text.StringBuilder();

                foreach (var ing in ings)
                {
                    builder.Append(Language.main.Get(ing.Key.AsString()));
                    if (ing.Value > 1)
                    {
                        builder.Append(" (x");
                        builder.Append(ing.Value);
                        builder.Append(')');
                    }
                    builder.Append(", ");
                }
                if (builder.Length >= 2)
                {
                    builder.Length -= 2;
                }
                var ingList = builder.ToString();

                return(FormatWithFallback(recycleTooltip, "{0}", ingList));
            }
        public static void Postfix(TechType techType, ref bool __result)
        {
            if (Main.config.Hardcore && GameModeUtils.RequiresBlueprints() && __result)
            {
                if (!QModServices.Main.ModPresent("UITweaks"))
                {
                    RecipeData data            = Main.GetData(techType);
                    int        ingredientCount = data?.ingredientCount ?? 0;
                    for (int i = 0; i < ingredientCount; i++)
                    {
                        Ingredient ingredient = data.Ingredients[i];
                        if (!blackList.Contains(techType) && !CrafterLogic.IsCraftRecipeUnlocked(ingredient.techType))
                        {
                            __result = false;
                            return;
                        }
                    }
                }
                else
                {
#if SN1
                    if (CraftData.techData.TryGetValue(techType, out CraftData.TechData data))
                    {
                        int ingredientCount = data?.ingredientCount ?? 0;
                        for (int i = 0; i < ingredientCount; i++)
                        {
                            IIngredient ingredient = data.GetIngredient(i);
                            if (!blackList.Contains(techType) && !CrafterLogic.IsCraftRecipeUnlocked(ingredient.techType))
                            {
                                __result = false;
                                return;
                            }
                        }
                    }
#elif BZ
#endif
                }
            }
        }
示例#20
0
        protected override RecipeData GetBlueprintRecipe()
        {
            RecipeData recipe = new RecipeData()
            {
                craftAmount = 1,
                Ingredients = new List <Ingredient>(new Ingredient[]
                {
#if SUBNAUTICA_STABLE
                    new Ingredient(TechType.DiamondBlade, 1),
                    new Ingredient(TechType.Diamond, 1),
#elif BELOWZERO
                    new Ingredient(TechType.Knife, 1),
                    new Ingredient(TechType.Diamond, 2),
#endif
                    new Ingredient(TechType.Battery, 1),
                    new Ingredient(TechType.Quartz, 1),
                    new Ingredient(TechType.Aerogel, 1),
                    new Ingredient(TechType.Magnetite, 1),
                    new Ingredient(TechType.WiringKit, 1)
                })
            };

            return(recipe);
        }
示例#21
0
            public TankType(TechType tank, float baseO2capacity, Sprite sprite = null, bool bUnlockAtStart = false, float speedModifier = 1f)
            {
                Logger.Log(Logger.Level.Debug, $"Registering tank TechType.{tank.AsString()}");
                if (sprite != null)
                {
                    this.sprite = sprite;
                }
                else
                {
                    this.sprite = SpriteManager.Get(tank);
                }
                string tankName = Language.main.Get(tank);

                this.BaseO2Capacity = baseO2capacity;
                this.speedModifier  = speedModifier;
                if (Main.config.bManualRefill)
                {
                    //new TankCraftHelper(tank).Patch();
                    this.refillTechType = TechTypeHandler.AddTechType((tank.AsString(false) + "Refill"), tankName + " Refill", "Refilled " + tankName, false);
                    KnownTechHandler.SetAnalysisTechEntry(tank, new TechType[] { this.refillTechType });
                    SpriteHandler.RegisterSprite(this.refillTechType, this.sprite);
                    var techData = new RecipeData()
                    {
                        craftAmount = 0,
                        Ingredients = new List <Ingredient>()
                        {
                            new Ingredient(tank, 1)
                        }
                    };
                    techData.LinkedItems.Add(tank);

                    CraftDataHandler.SetTechData(this.refillTechType, techData);
                    CraftTreeHandler.AddCraftingNode(CraftTree.Type.Fabricator, this.refillTechType, new string[] {
                        "Personal",
                        "TankRefill"
                    });
#if SUBNAUTICA_STABLE
                    if (CraftData.GetCraftTime(tank, out float craftTime))
#elif BELOWZERO
                    if (TechData.GetCraftTime(tank, out float craftTime))
#endif
                    {
                        Logger.Log(Logger.Level.Debug, $"Setting crafting time of {craftTime} for TechType.{this.refillTechType.AsString()}");
                        CraftDataHandler.SetCraftingTime(this.refillTechType, craftTime);
                    }
                    else
                    {
                        Logger.Log(Logger.Level.Debug, $"Couldn't find crafting time for TechType.{tank}");
                    }

                    if (!Main.bannedTech.Contains(this.refillTechType))
                    {
                        Main.bannedTech.Add(this.refillTechType);
                    }
                    if (bUnlockAtStart)
                    {
                        KnownTechHandler.UnlockOnStart(this.refillTechType);
                    }
                }
                else
                {
                    this.refillTechType = TechType.None;
                }
            }
        private static bool PreAddToInventory(TechType techType, int num = 1, bool noMessage = false, bool spawnIfCantAdd = true)
        {
            if (techType == TechType.Titanium && num == 2 && !noMessage && spawnIfCantAdd)
            {
                TechType   scannedFragment = TechType.None;
                RecipeData recipe          = null;
                if (BlueprintHandTargetPatches.bIsDatabox)
                {
                    //if (!Main.config.bInterceptDataboxes)
                    //    return true;

                    scannedFragment = BlueprintHandTargetPatches.databoxUnlock;
                    if (Main.config.TryOverrideRecipe(scannedFragment, out recipe))
                    {
#if !RELEASE
                        Logger.Log(Logger.Level.Debug, $"Using OverrideRecipe: {Json.JsonConvert.SerializeObject(recipe, Json.Formatting.Indented)}");
#endif
                    }
                    else
                    {
                        recipe = CraftDataHandler.GetTechData(scannedFragment);
                    }
                }
                else
                {
                    scannedFragment = PDAScanner.scanTarget.techType;
#if !RELEASE
                    Logger.Log(Logger.Level.Debug, $"Intercepting scan of fragment {scannedFragment.ToString()}");
#endif

                    if (PartsFromScanning.Main.config.TryOverrideRecipe(scannedFragment, out recipe))
                    {
#if !RELEASE
                        Logger.Log(Logger.Level.Debug, $"Using OverrideRecipe: {Json.JsonConvert.SerializeObject(recipe, Json.Formatting.Indented)}");
#endif
                    }
                    else if ((int)scannedFragment > 1112 && (int)scannedFragment < 1117)
                    {
                        // TechTypes 1113 to 1116 are Cyclops fragments, which have no blueprint associated, so we need to process them specially.
                        recipe = new RecipeData();

                        /*CyclopsHullFragment = 1113,
                         * CyclopsBridgeFragment = 1114,
                         * CyclopsEngineFragment = 1115,
                         * CyclopsDockingBayFragment = 1116,*/

                        switch ((int)scannedFragment)
                        {
                        case 1113:
                            recipe.Ingredients.Add(new Ingredient(TechType.PlasteelIngot, 2));
                            recipe.Ingredients.Add(new Ingredient(TechType.Lead, 1));
                            break;

                        case 1114:
                            recipe.Ingredients.Add(new Ingredient(TechType.EnameledGlass, 3));
                            break;

                        case 1115:
                            recipe.Ingredients.Add(new Ingredient(TechType.Lubricant, 1));
                            recipe.Ingredients.Add(new Ingredient(TechType.AdvancedWiringKit, 1));
                            recipe.Ingredients.Add(new Ingredient(TechType.Lead, 1));
                            break;

                        case 1116:
                            recipe.Ingredients.Add(new Ingredient(TechType.PlasteelIngot, 2));
                            break;
                        }
                        recipe.Ingredients.Add(new Ingredient(TechType.Lead, 1));
                        recipe.Ingredients.Add(new Ingredient(TechType.PlasteelIngot, 1));
#if !RELEASE
                        Logger.Log(Logger.Level.Debug, $"Using recipe from manual override: {Json.JsonConvert.SerializeObject(recipe, Json.Formatting.Indented)}");
#endif
                    }
                    else
                    {
                        PDAScanner.EntryData entryData = PDAScanner.GetEntryData(scannedFragment);
                        if (entryData == null) // Sanity check; this should always be true
                        {
#if !RELEASE
                            Logger.Log(Logger.Level.Debug, $"Failed to find EntryData for fragment");
#endif

                            /*CraftData.AddToInventory(TechType.Titanium);
                             * CraftData.AddToInventory(TechType.Titanium); // Adding them one-by-one so as to prevent it being caught by this very routine.*/
                            return(true);
                        }
                        //Logger.Log(Logger.Level.Debug, $"Found entryData {entryData.ToString()}");
#if !RELEASE
                        Logger.Log(Logger.Level.Debug, $"Found entryData {Json.JsonConvert.SerializeObject(entryData, Json.Formatting.Indented)}");
#endif


                        //CraftData.AddToInventory(TechType.Titanium);
                        //CraftData.AddToInventory(TechType.Copper);
#if SUBNAUTICA_STABLE
                        recipe = CraftDataHandler.GetTechData(entryData.blueprint);
#elif BELOWZERO
                        recipe = CraftDataHandler.GetRecipeData(entryData.blueprint);
#endif
                        if (recipe == null)
                        {
#if !RELEASE
                            Logger.Log(Logger.Level.Debug, $"Failed to find blueprint for EntryData");
#endif

                            /*CraftData.AddToInventory(TechType.Titanium);
                             * CraftData.AddToInventory(TechType.Titanium); // One-by-one again, as above.*/
                            return(true);
                        }
                        //Logger.Log(Logger.Level.Debug, $"Found recipe {recipe.ToString()}");
#if !RELEASE
                        Logger.Log(Logger.Level.Debug, $"Using recipe from EntryData: {Json.JsonConvert.SerializeObject(recipe, Json.Formatting.Indented)}");
#endif
                    }
                }

                for (int i = 0; i < recipe.Ingredients.Count; i++)
                {
                    if (PartsFromScanning.Main.config.TrySubstituteIngredient(recipe.Ingredients[i].techType, out List <Ingredient> Substitutes))
                    {
                        foreach (Ingredient sub in Substitutes)
                        {
                            recipe.Ingredients.Add(sub);
                        }
                        recipe.Ingredients.RemoveAt(i); // Remove the current ingredient...
                        i--;                            // ...and make sure the loop continues at the item after this, not the one after that.
                    }
                }

                // I believe the easiest way to get a random item from the blueprint would be to make a list of techTypes; if an ingredient is used twice in the recipe, it will appear in the list twice.
                // That way, we can generate a random number where 0<=rnd<list.count, and select that item.
                List <TechType> bp = new List <TechType> {
                };
                for (int i = 0; i < recipe.Ingredients.Count; i++)
                {
                    for (int j = 0; j < recipe.Ingredients[i].amount; j++)
                    {
                        bp.Add(recipe.Ingredients[i].techType);
                    }
                }

                // Now build up weights
                List <WeightedItem> BlueprintPairs = new List <WeightedItem>();
                float TotalWeight = 0f;
                //Logger.Log(Logger.Level.Error, "Unidentified Vehicle Type!");
                for (int i = 0; i < bp.Count; i++)
                {
                    float thisWeight = Main.config.GetWeightForTechType(bp[i]);
                    TotalWeight += thisWeight;
                    WeightedItem thisWeightedItem = new WeightedItem(TotalWeight, bp[i]);
#if !RELEASE
                    Logger.Log(Logger.Level.Debug, $"Adding item to drop list, TechType = {thisWeightedItem.tech.ToString()},   this weight = {thisWeight}, cumulative weight = {thisWeightedItem.Weight}");
#endif
                    BlueprintPairs.Add(thisWeightedItem);
                }

                // Now we should be able to pick a few random numbers between 0 and the list's total weight, and add those. We want to remove that entry afterwards, but that's not a big ask.
                System.Random rng            = new System.Random();
                int           numIngredients = Math.Min(PartsFromScanning.Main.config.GenerateGiftValue(), BlueprintPairs.Count);
#if !RELEASE
                Logger.Log(Logger.Level.Debug, $"Generated a value for this scan of {numIngredients} components.");
#endif

                int    awards = 0;
                double r;
                for (int i = 0; i < numIngredients && BlueprintPairs.Count > 0; i++)
                {
                    r = rng.NextDouble() * TotalWeight;
                    for (int j = 0; j < BlueprintPairs.Count; j++)
                    {
                        //                                               This part is for sanity checking
                        //                                   ___________________________|______________________________
                        //                                  /                                                          \
                        if (r < BlueprintPairs[j].Weight || ((j + 1) == BlueprintPairs.Count && awards < numIngredients))
                        {
                            AddInventory(BlueprintPairs[j].tech, 1, false, true);
                            //CraftData.AddToInventory(BlueprintPairs[j].tech, 1, false, true);
                            awards++;
                            TotalWeight -= Main.config.GetWeightForTechType(BlueprintPairs[j].tech);
                            BlueprintPairs.RemoveAt(j);
                            break;
                        }
                    }
                }
                return(false);
            }
            return(true);
        }
示例#23
0
            private static TechType CreateRecyclingData(TechType originTech, RecipeData originData)
            {
                if (IsBlackListed(originTech))
                {
                    TechType blackListedTech = TechTypeHandler.AddTechType($"Defabricated{originTech}", LoadRecyclingText(originTech), LoadRecyclingTooltip(originTech, null), SpriteManager.Get(originTech), true);
                    CraftDataHandler.SetTechData(blackListedTech, new RecipeData(new List <Ingredient>()));
                    blacklist.Add(blackListedTech);
                    return(blackListedTech);
                }

                var ingredients = new Dictionary <TechType, int>();

                if (originData.craftAmount > 0)
                {
                    ingredients[originTech] = originData.craftAmount;
                }
                for (var i = 0; i < originData.linkedItemCount; i++)
                {
                    var item = originData.LinkedItems[i];
                    ingredients[item] = ingredients.ContainsKey(item) ? (ingredients[item] + 1) : 1;
                }
                var resIngs = new List <Ingredient>();

                ingredients.ForEach(x => resIngs.Add(new Ingredient(x.Key, x.Value)));

                var linkedItems = new List <TechType>();

                for (var i = 0; i < originData.ingredientCount; i++)
                {
                    var ing    = originData.Ingredients[i];
                    var amount = Mathf.FloorToInt(ing.amount * Config.GetYield(ing.techType));
                    for (var j = 0; j < amount; j++)
                    {
                        linkedItems.Add(ing.techType);
                    }
                }
                RecipeData Data = new RecipeData()
                {
                    craftAmount = 0, Ingredients = resIngs, LinkedItems = linkedItems
                };
                DefabricatedPrefab defabricatedPrefab = new DefabricatedPrefab($"Defabricated{originTech}", LoadRecyclingText(originTech), LoadRecyclingTooltip(originTech, Data), originTech, Data);

                defabricatedPrefab.Patch();
                KnownTech.Add(defabricatedPrefab.TechType);

#if SUBNAUTICA
                Dictionary <string, Atlas> nameToAtlas = AccessTools.Field(typeof(Atlas), "nameToAtlas").GetValue(null) as Dictionary <string, Atlas>;

                foreach (Atlas atlas in nameToAtlas.Values)
                {
                    Atlas.Sprite sprite = atlas.GetSprite(originTech.AsString());
                    if (sprite != null)
                    {
                        atlas.nameToSprite[defabricatedPrefab.TechType.AsString()] = sprite;
                        break;
                    }
                }
#elif BELOWZERO
                Dictionary <string, Dictionary <string, Sprite> > atlases = AccessTools.Field(typeof(SpriteManager), "atlases").GetValue(null) as Dictionary <string, Dictionary <string, Sprite> >;

                foreach (Dictionary <string, Sprite> atlas in atlases.Values)
                {
                    if (atlas.TryGetValue(originTech.AsString(), out Sprite sprite))
                    {
                        atlas[defabricatedPrefab.TechType.AsString()] = sprite;
                        break;
                    }
                }
#endif
                if (IsBlackListed(originTech))
                {
                    blacklist.Add(defabricatedPrefab.TechType);
                }

                return(defabricatedPrefab.TechType);
            }
示例#24
0
 public DefabricatedPrefab(string classId, string friendlyName, string description, TechType original, RecipeData data) : base(classId, friendlyName, description)
 {
     Original   = original;
     recipeData = data;
 }