Beispiel #1
0
        //private List<RecipeOverride> defaultRecipeOverrides

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

            foreach (RecipeOverride r in RecipeOverrides)
            {
                if (sFragment == r.overridden)
                {
                    outRecipe = new TechData();
                    foreach (StringIngredient s in r.replacements)
                    {
                        if (Enum.TryParse <TechType>(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);
        }
Beispiel #2
0
        public bool TrySubstituteIngredient(TechType tech, out List <Ingredient> Substitutes)
        {
            Substitutes = new List <Ingredient>();
            for (int i = 0; i < SubstitutionList.Count; i++)
            {
                if (tech.ToString() == SubstitutionList[i].replacedTech)
                {
                    //for (int j = 0; j < SubstitutionList[i].replacements.Count; j++)
                    foreach (StringIngredient si in SubstitutionList[i].replacements)
                    {
                        if (Enum.TryParse <TechType>(si.techType, out TechType tt))
                        {
                            Substitutes.Add(new Ingredient(tt, si.amount));
                        }
                        else
                        {
#if !RELEASE
                            Logger.Log(Logger.Level.Error, $"Failed to parse string '{si.techType}' as TechType; check to make sure the entry is spelled correctly, and using the correct case");
#endif
                        }
                    }
                    //Substitutes = SubstitutionList[i].replacements;
                    return(Substitutes.Count > 0);                      // It's possible every single entry in the list failed to parse; we don't want to return true in that instance. But this condition is an easy fix.
                }
            }

            // We only get this far if the tech to be replaced doesn't match this object's replacedTech.
            Substitutes = null;
            return(false);
        }
Beispiel #3
0
        static TechTypeExtensions()
        {
            Array values = Enum.GetValues(typeof(TechType));
            int   length = values.Length;

            TechTypeExtensions.stringsNormal       = new Dictionary <TechType, string>(length, TechTypeExtensions.sTechTypeComparer);
            TechTypeExtensions.stringsLowercase    = new Dictionary <TechType, string>(length, TechTypeExtensions.sTechTypeComparer);
            TechTypeExtensions.techTypesNormal     = new Dictionary <string, TechType>(length);
            TechTypeExtensions.techTypesIgnoreCase = new Dictionary <string, TechType>(length, StringComparer.InvariantCultureIgnoreCase);
            TechTypeExtensions.techTypeKeys        = new Dictionary <TechType, string>(length, TechTypeExtensions.sTechTypeComparer);
            TechTypeExtensions.keyTechTypes        = new Dictionary <string, TechType>(length);
            for (int i = 0; i < length; i++)
            {
                TechType techType = (TechType)values.GetValue(i);
                string   text     = techType.ToString();
                if (!TechTypeExtensions.stringsNormal.ContainsKey(techType))
                {
                    TechTypeExtensions.stringsNormal[techType]    = text;
                    TechTypeExtensions.stringsLowercase[techType] = text.ToLower();
                }
                if (!TechTypeExtensions.techTypesNormal.ContainsKey(text))
                {
                    TechTypeExtensions.techTypesNormal[text] = techType;
                }
                if (!TechTypeExtensions.techTypesIgnoreCase.ContainsKey(text))
                {
                    TechTypeExtensions.techTypesIgnoreCase[text] = techType;
                }
                int    num   = (int)techType;
                string text2 = num.ToString();
                TechTypeExtensions.techTypeKeys.Add(techType, text2);
                TechTypeExtensions.keyTechTypes.Add(text2, techType);
            }
        }
        private bool IsAllowedToAdd(Pickupable pickupable, bool verbose)
        {
            bool flag = false;

            if (_fridge.IsFull)
            {
                QuickLogger.Message(_storageIsFullMessage, true);
                return(false);
            }

            if (pickupable != null)
            {
                TechType techType = pickupable.GetTechType();

                QuickLogger.Debug(techType.ToString());

                if (pickupable.GetComponent <Eatable>() != null)
                {
                    flag = true;
                }
            }

            QuickLogger.Debug($"Adding Item {flag} || {verbose}");

            if (!flag && verbose)
            {
                QuickLogger.Message(_itemNotAllowedMessage, true);
                flag = false;
            }

            return(flag);
        }
        public bool IsAllowedToAdd(Pickupable pickupable, bool verbose)
        {
            bool flag = false;

            if (IsFull)
            {
                QuickLogger.Message(LanguageHelpers.GetLanguage("InventoryFull"), true);
                return(false);
            }

            if (pickupable != null)
            {
                TechType techType = pickupable.GetTechType();

                QuickLogger.Debug(techType.ToString());

                if (pickupable.GetComponent <Eatable>() != null)
                {
                    flag = true;
                }
            }

            QuickLogger.Debug($"Adding Item {flag} || {verbose}");

            if (!flag && verbose)
            {
                QuickLogger.Message(LanguageHelpers.GetLanguage("TimeCapsuleItemNotAllowed"), true);
                flag = false;
            }

            return(flag);
        }
        public static void ModifyRecipe(TechType craftedItem, TechData recipe)
        {
            Assert.AreNotEqual(craftedItem.ToString(), ((int)craftedItem).ToString(), "This API in intended only for use with standard, non-modded TechTypes.");
            // Only modded enums use the int string as their ToString value

            CraftDataHandler.SetTechData(craftedItem, recipe);
        }
Beispiel #7
0
 /// <summary>
 /// Outputs all information about this <see cref="Prefab"/> object for debugging
 /// </summary>
 /// <returns>The string to output to the console</returns>
 public string OutputDebug()
 {
     return
         ($"ExistingPrefabPath: {(ExistingPrefabPath ?? "null")}, " +
          $"InternalName: {(InternalName ?? "null")}, " +
          $"Item: {(Item != TechType.None ? Item.ToString() : "null")}" +
          $"NewPrefabPath: {(NewPrefabPath ?? "null")}");
 }
Beispiel #8
0
        public virtual void Patch()
        {
            Atlas.Sprite sprite = null;

            if (IconFilename != null)
            {
                string iconfilePath = $"./QMods/{IconFilename}/Assets/{IconFilename}.png";

                try
                {
                    sprite = ImageUtils.LoadSpriteFromFile(iconfilePath);
                }
                catch
                {
                    SNLogger.Log($"[{NameID}] ***ERROR! File [{iconfilePath}] not Found! ");
                }
            }
            else if (IconTechType != TechType.None)
            {
                try
                {
                    sprite = GetResourceIcon(IconTechType);
                }
                catch
                {
                    SNLogger.Log($"[{NameID}] ***ERROR! Resource TechType icon [{IconTechType.ToString()}] not Found! ");
                }
            }
            else
            {
                try
                {
                    sprite = GetResourceIcon(PrefabTemplate);
                }
                catch
                {
                    SNLogger.Log($"[{NameID}] ***ERROR! Resource template icon [{PrefabTemplate.ToString()}] not Found! ");
                }
            }


            TechType = TechTypeHandler.AddTechType(NameID, FriendlyName, Description, sprite, false);
            SpriteHandler.RegisterSprite(TechType, sprite);
            CraftTreeHandler.AddCraftingNode(FabricatorType, TechType, FabricatorTab);
            CraftDataHandler.SetTechData(TechType, GetRecipe());
            CraftDataHandler.AddToGroup(GroupForPDA, CategoryForPDA, TechType);
            CraftDataHandler.SetEquipmentType(TechType, TypeForEquipment);
            CraftDataHandler.SetQuickSlotType(TechType, TypeForQuickslot);
            CraftDataHandler.SetItemSize(TechType, ItemSize);
            CraftDataHandler.SetBackgroundType(TechType, BackgroundType);
            KnownTechHandler.SetAnalysisTechEntry(RequiredForUnlock, new TechType[1] {
                TechType
            }, $"{FriendlyName} blueprint discovered!");

            PrefabHandler.RegisterPrefab(this);
        }
        public static void CustomizeItemSize(TechType inventoryItem, int width, int height)
        {
            Assert.AreNotEqual(inventoryItem.ToString(), ((int)inventoryItem).ToString(), "This API in intended only for use with standard, non-modded TechTypes.");

            Assert.IsTrue(width > 0 && height > 0, "Values must be positive and non-zero");
            Assert.IsTrue(width < 6 && height < 6, "Values must be smaller than six to fit");
            // Value chosen for what should be the standard inventory size

            CraftDataHandler.SetItemSize(inventoryItem, width, height);
        }
Beispiel #10
0
 public float GetWeightForType(TechType targetTechType)
 {
     if (targetTechType.ToString() == this.weightedTechType)
     {
         return(this.weight);
     }
     else
     {
         return(1.0f);
     }
 }
Beispiel #11
0
        //private List<SSubstitutionEntry> defaultSubstitutionList

        public float GetWeightForTechType(TechType tech)
        {
            return(TechWeights.GetOrDefault(tech.ToString(), 1.0f));

            /*if (TechWeights.TryGetValue(tech.ToString(), out float weight))
             * {
             *      return weight;
             * }
             * else
             * {
             *      return 1.0f;
             * }*/
        }
        public virtual void Patch_B()
        {
            Atlas.Sprite sprite = null;

            if (IconFilename != null)
            {
                try
                {
                    sprite = ImageUtils.LoadSpriteFromFile($"./QMods/{IconFilename}/Assets/{IconFilename}.png");
                }
                catch
                {
                    SNLogger.Log($"[{_ClassID}] ***ERROR! File [{IconFilename}.png] not Found! ");
                }
            }
            else if (IconTechType != TechType.None)
            {
                try
                {
                    sprite = GetResourceIcon(IconTechType);
                }
                catch
                {
                    SNLogger.Log($"[{_ClassID}] ***ERROR! Resource TechType icon [{IconTechType.ToString()}] not Found! ");
                }
            }
            else
            {
                try
                {
                    sprite = GetResourceIcon(PrefabTemplate);
                }
                catch
                {
                    SNLogger.Log($"[{_ClassID}] ***ERROR! Resource template icon [{PrefabTemplate.ToString()}] not Found! ");
                }
            }


            TechType = TechTypeHandler.AddTechType(_ClassID, _FriendlyName, _Description, sprite, false);
            SpriteHandler.RegisterSprite(TechType, sprite);
            CraftDataHandler.SetTechData(TechType, GetRecipe());
            CraftDataHandler.AddToGroup(GroupForPDA, CategoryForPDA, TechType);
            KnownTechHandler.SetAnalysisTechEntry(RequiredForUnlock, new TechType[1] {
                TechType
            }, $"{_FriendlyName} blueprint discovered!");

            PrefabHandler.RegisterPrefab(this);
        }
        public static float ModifyDamage(TechType tt, float damage, DamageType type)
        {
            float baseDamage = damage;
            float damageMod  = 0f;

            Log.LogDebug($"Main.ModifyDamage called: tt = {tt.ToString()}, damage = {damage}; DamageType = {type}");
            //foreach (DamageResistance r in DamageResistances)
            if (DamageResistances.TryGetValue(tt, out Dictionary <DamageType, float> diList))
            {
                if (diList.TryGetValue(type, out float mult))
                {
                    Log.LogDebug($"Got damage multiplier of {mult}");
                    damageMod += baseDamage * mult;
                }
            }
            Log.LogDebug($"DamageMod = {damageMod}");
            return(damageMod);
        }
        public bool IsAllowedToAdd(Pickupable pickupable)
        {
            bool flag = false;

            if (pickupable != null)
            {
                TechType techType = pickupable.GetTechType();

                QuickLogger.Debug(techType.ToString());

                if (pickupable.GetComponent <Eatable>() != null)
                {
                    flag = true;
                }
            }

            return(flag);
        }
        public static void AddRecipe(TechType craftedItem, TechData recipe, CraftTree.Type craftTree, string path)
        {
            Assert.AreNotEqual(craftedItem.ToString(), ((int)craftedItem).ToString(), "This API in intended only for use with standard, non-modded TechTypes.");
            // Only modded enums use the int string as their ToString value

            //CraftTreeHandler.customNodes.Add(new CustomCraftNode(craftedItem, craftTree, path));
            CraftDataHandler.SetTechData(craftedItem, recipe);

            string[] steps = path.Split(CraftingNode.Splitter);

            if (steps.Length <= 1)
            {
                CraftTreeHandler.AddCraftingNode(craftTree, craftedItem);
            }
            else
            {
                CraftTreeHandler.AddCraftingNode(craftTree, craftedItem, steps);
            }

            KnownTechHandler.UnlockOnStart(craftedItem);
        }
        public object SetTechTurn(IDbConnection connection, TechType techType, UnitTurnOut input, UserMothershipDataModel mother, UserPremiumWorkModel premium)
        {
            var teches    = new BattleTeches(mother.TechProgress);
            var techesOut = teches.ConvertToTechesOut(false);
            var tech      = techesOut[techType];

            if (tech.Disabled)
            {
                throw new NotImplementedException(Error.TechDisabled);
            }
            tech.CalcResultPrice(premium.IsActive);
            var price = tech.BasePrice;

            if (input.ForCc)
            {
                var cc          = (int)price.Cc;
                var preResultCc = _storeService.BalanceCalcResultCc(connection, input.UserId, cc);
                ItemProgress.ProgressUpdateComplite(tech.Progress);
                mother.TechProgress = teches.ConvertToDbTeches();
                _mothershipService.AddOrUpdate(connection, mother);
                _storeService.AddOrUpdateBalance(connection, preResultCc);
                return(preResultCc.Quantity);
            }
            if (tech.Progress.IsProgress == true)
            {
                throw new Exception(Error.TechInProgress);
            }

            var bu = new BuildUpgrade(mother.Resources, tech.Progress, techType.ToString());

            var newBu = BuildUpgrade.SetUpgrade(bu, price);

            newBu.Progress.StartTime = UnixTime.UtcNow();
            mother.Resources         = newBu.StorageResources;
            tech.Progress.SetFromOther(newBu.Progress);
            mother.TechProgress = teches.ConvertToDbTeches();
            _mothershipService.AddOrUpdate(connection, mother);
            return(true);
        }
        private bool IsAllowedToAddContainer(Pickupable pickupable, bool verbose)
        {
            bool flag = false;

            if (pickupable != null)
            {
                TechType techType = pickupable.GetTechType();

                QuickLogger.Debug(techType.ToString());

                if (pickupable.GetComponent <Eatable>() != null)
                {
                    flag = Configuration.Configuration.AllowedRawItems.Any(x => x == techType);
                }
            }

            QuickLogger.Debug($"Adding Item {flag} || {verbose}");

            if (!flag && verbose)
            {
                QuickLogger.Error(SeaCookerBuildable.ItemNotAllowed());
            }
            return(flag);
        }
Beispiel #18
0
        public virtual void Patch()
        {
            Atlas.Sprite atlasSprite = null;

            if (IconFilePath != null)
            {
                try
                {
                    atlasSprite = ImageUtils.LoadSpriteFromFile(IconFilePath);
                }
                catch
                {
                    SNLogger.Error(NameID, $"File [{IconFilePath}] not Found!");
                }
            }
            else if (IconTechType != TechType.None)
            {
                try
                {
                    atlasSprite = GetResourceIcon(IconTechType);
                }
                catch
                {
                    SNLogger.Error(NameID, $"Resource TechType icon [{IconTechType.ToString()}] not Found!");
                }
            }
            else
            {
                try
                {
                    atlasSprite = GetResourceIcon(PrefabTemplate);
                }
                catch
                {
                    SNLogger.Error(NameID, $"Resource template icon [{PrefabTemplate.ToString()}] not Found!");
                }
            }

            TechType = TechTypeHandler.Main.AddTechType(NameID, FriendlyName, Description, atlasSprite, false);

            PrefabHandler.Main.RegisterPrefab(this);
            CraftDataHandler.Main.SetTechData(TechType, GetRecipe());
            SpriteHandler.Main.RegisterSprite(TechType, atlasSprite);
            CraftDataHandler.Main.SetItemSize(TechType, ItemSize);
            CraftDataHandler.Main.AddToGroup(GroupForPDA, CategoryForPDA, TechType);
            CraftDataHandler.Main.SetEquipmentType(TechType, TypeForEquipment);
            CraftDataHandler.Main.SetQuickSlotType(TechType, TypeForQuickslot);
            CraftDataHandler.Main.SetBackgroundType(TechType, BackgroundType);

            EncyData encyData = GetEncyclopediaData();

            if (encyData != null)
            {
                isEncyExists = true;

                PDAEncyclopedia.EntryData entryData = new PDAEncyclopedia.EntryData()
                {
                    key      = ClassID,
                    path     = EncyHelper.GetEncyPath(encyData.node),
                    nodes    = EncyHelper.GetEncyNodes(encyData.node),
                    unlocked = false,
                    popup    = GetUnitySprite(atlasSprite),
                    image    = encyData.image,
                    audio    = null,
                };

                PDAEncyclopediaHandler.Main.AddCustomEntry(entryData);

                LanguageHandler.Main.SetLanguageLine($"Ency_{ClassID}", encyData.title);
                LanguageHandler.Main.SetLanguageLine($"EncyDesc_{ClassID}", encyData.description);
            }

            if (RequiredForUnlock == TechType.None && _Fragment != null)
            {
                PDAScanner.EntryData scannerEntryData = new PDAScanner.EntryData()
                {
                    key              = _Fragment.TechType,
                    blueprint        = TechType,
                    destroyAfterScan = _Fragment.DestroyAfterScan,
                    encyclopedia     = isEncyExists ? ClassID : null,
                    isFragment       = true,
                    locked           = false,
                    scanTime         = _Fragment.ScanTime,
                    totalFragments   = _Fragment.TotalFragments
                };

                PDAHandler.Main.AddCustomScannerEntry(scannerEntryData);

                KnownTechHandler.Main.SetAnalysisTechEntry(TechType, new TechType[1] {
                    TechType
                }, GetUnitySprite(_Fragment.UnlockSprite));
            }
            else
            {
                KnownTechHandler.Main.SetAnalysisTechEntry(RequiredForUnlock, new TechType[1] {
                    TechType
                }, $"{FriendlyName} blueprint discovered!");
            }

            if (NewTabNode != null)
            {
                CraftTreeHandler.Main.AddTabNode(NewTabNode.craftTree, NewTabNode.uniqueName, NewTabNode.displayName, NewTabNode.sprite);
            }

            for (int i = 0; i < FabricatorTypes.Length; i++)
            {
                if (FabricatorTabs == null)
                {
                    CraftTreeHandler.Main.AddCraftingNode(FabricatorTypes[i], TechType);
                }
                else
                {
                    CraftTreeHandler.Main.AddCraftingNode(FabricatorTypes[i], TechType, FabricatorTabs[i]);
                }
            }
        }
        public static void Postfix(WaterPark __instance, WaterParkCreature creature)
        {
            List <WaterParkItem> items = __instance.items;

            if (!items.Contains(creature) || __instance.HasFreeSpace() || BaseBioReactor.GetCharge(creature.pickupable.GetTechType()) == -1)
            {
                return;
            }

            List <BaseBioReactor> baseBioReactors = __instance.gameObject.GetComponentInParent <SubRoot>().gameObject.GetComponentsInChildren <BaseBioReactor>().ToList();
            bool hasBred = false;

            foreach (WaterParkItem waterParkItem in items)
            {
                var      parkCreature         = waterParkItem as WaterParkCreature;
                TechType parkCreatureTechType = parkCreature?.pickupable?.GetTechType() ?? TechType.None;
                if (parkCreature != null && parkCreature != creature && parkCreature.GetCanBreed() && parkCreatureTechType == creature.pickupable.GetTechType() && !parkCreatureTechType.ToString().Contains("Egg"))
                {
                    if (BaseBioReactor.GetCharge(parkCreatureTechType) > -1)
                    {
                        if (QModServices.Main.ModPresent("FCSEnergySolutions"))
                        {
                            hasBred = AGT.TryBreedIntoAlterraGen(__instance, parkCreatureTechType, parkCreature);
                        }

                        if (!hasBred)
                        {
                            foreach (BaseBioReactor baseBioReactor in baseBioReactors)
                            {
                                if (baseBioReactor.container.HasRoomFor(parkCreature.pickupable))
                                {
                                    creature.ResetBreedTime();
                                    parkCreature.ResetBreedTime();
                                    hasBred = true;
                                    CoroutineHost.StartCoroutine(SpawnCreature(__instance, parkCreature, baseBioReactor.container));
                                    break;
                                }
                            }
                        }
                    }

                    creature.ResetBreedTime();
                    parkCreature.ResetBreedTime();
                    break;
                }
            }
        }
Beispiel #20
0
 internal CustomCraftTreeCraft(TechType techType)
     : base(techType.ToString(), TreeAction.Craft, techType)
 {
 }
Beispiel #21
0
 public static NitroxTechType ToDto(this TechType v)
 {
     return(new NitroxTechType(v.ToString()));
 }
Beispiel #22
0
 public static TechTypeModel Model(this TechType o)
 {
     return(new TechTypeModel(o.ToString()));
 }
Beispiel #23
0
        public static void AddSubstitution(TechType substituted, TechType substitution)
        {
            Substitutions.Add(new TechTypeSub(substituted, substitution));
            substitutionTargets.Add(substitution);
#if !RELEASE
            Logger.Log(Logger.Level.Debug, $"AddSubstitution: Added sub with substituted {substituted.ToString()} and substitution {substitution.ToString()}, new count {Substitutions.Count}");
#endif
        }
Beispiel #24
0
        // ReSharper disable once InconsistentNaming
        private static bool Prefix(WaterPark __instance, WaterParkCreature creature)
        {
            FishOverflowDistributor.Logger.LogTrace("WaterPark.TryBreed(WaterParkCreature) called.");

            //We only distribute when the WaterPark doesn't have any space left for bred creatures.
            //This is the only place in this method where we allow the original unpatched method to execute,
            //because the original method is never executed when there is no space left in the WaterPark.

            FishOverflowDistributor.Logger.LogTrace(
                $"__instance.HasFreeSpace() returns '{__instance.HasFreeSpace()}'.");

            if (__instance.HasFreeSpace())
            {
                return(true);
            }

            //using Harmony's Traverse class for reflection. Harmony caches MethodInfo, FieldInfo, etc. for further use and thus increases performance.
            var items = Traverse
                        .Create(__instance)
                        .Field("items")
                        .GetValue <List <WaterParkItem> >();

            if (items == null)
            {
                FishOverflowDistributor.Logger.LogError(
                    "FieldInfo or value for field 'items' in class 'WaterParkItem' with type 'List<WaterParkItem>' was null -> Should not happen, investigate!.");

                return(false);
            }


            FishOverflowDistributor.Logger.LogTrace("Checking if creature is contained in items");

            //Don't know why this check is needed. Maybe TryBreed gets called on fish which arent contained in this WaterPark instance.
            if (!items.Contains(creature))
            {
                return(false);
            }

            TechType creatureTechType = creature.pickupable.GetTechType();

            FishOverflowDistributor.Logger.LogTrace($"Creature Tech Type = {creatureTechType.ToString()}.");

            FishOverflowDistributor.Logger.LogTrace(
                "Checking whether creatureEggs.containsKey(creatureTechType)");

            //we don't want to distribute creature eggs
            if (WaterParkCreature.creatureEggs.ContainsKey(creatureTechType))
            {
                return(false);
            }

            FishOverflowDistributor.Logger.LogTrace(
                $"Waterpark '{__instance.gameObject.name}' contains creature '{creature.gameObject.name}' and has enough space for another one.");

            var secondCreature = items.Find(item =>
                                            item != creature &&
                                            item is WaterParkCreature &&

                                            // ReSharper disable once TryCastAlwaysSucceeds
                                            (item as WaterParkCreature).GetCanBreed() &&
                                            item.pickupable != null &&
                                            item.pickupable.GetTechType() == creatureTechType) as
                                 WaterParkCreature;

            if (secondCreature == null)
            {
                return(false);
            }

            FishOverflowDistributor.Logger.LogTrace(
                $"Waterpark contains two creatures '{creature.gameObject.name}' of TechType '{creatureTechType.ToString()}' which can breed with each other.");

            BaseBioReactor suitableReactor;

            try
            {
                //Get a reactor which has space for the item in the same base
                suitableReactor = SubnauticaSceneTraversalUtils
                                  .GetComponentsInSameBase <BaseBioReactor>(__instance.gameObject)
                                  .First(
                    reactor =>
                {
                    var itemsContainer = Traverse
                                         .Create(reactor)
                                         .Property("container")
                                         .GetValue <ItemsContainer>();

                    if (itemsContainer != null)
                    {
                        return(itemsContainer.HasRoomFor(
                                   creature.pickupable));
                    }

                    FishOverflowDistributor.Logger.LogTrace(
                        $"PropertyInfo or value for property 'container' in class 'BaseBioReactor' with type 'ItemsContainer' was null -> Should not happen, investigate!.");

                    return(false);
                });
            }
            catch (Exception)
            {
                return(false);
            }
            if (suitableReactor == null)
            {
                FishOverflowDistributor.Logger.LogTrace("Could not find suitable reactor");
                return(false);
            }

            //Reset breed time of the second creature so it can't be used to immediately breed again.
            secondCreature.ResetBreedTime();

            FishOverflowDistributor.Logger.LogTrace(
                $"Found suitable reactor '{suitableReactor.gameObject.name}'.");

            //Now we create a pickupable from the WaterParkCreature which we can add to the reactor's inventory.
            //Because the creature can't be taken out from the reactor inventory, we don't need to add WaterparkCreature component
            //to it. This would be needed so the game knows when you drop it outside, that it came from a waterpark.


            GameObject newCreature = CraftData.InstantiateFromPrefab(creatureTechType, false);

            newCreature.SetActive(false);
            newCreature.transform.position = creature.transform.position + Vector3.down;
            var pickupable = newCreature.EnsureComponent <Pickupable>();

            /*WaterParkCreatureParameters creatureParameters =
             *  WaterParkCreature.GetParameters(creatureTechType);
             *
             * newCreature.transform.localScale = creatureParameters.initialSize * Vector3.one;
             * var newCreatureComponent = newCreature.AddComponent<WaterParkCreature>();
             * newCreatureComponent.age = 0f;
             *
             * Traverse
             *  .Create(newCreatureComponent)
             *  .Field("parameters")
             *  .SetValue(creatureParameters);
             *
             * Pickupable pickupable = creatureParameters.isPickupableOutside
             *  ? newCreature.EnsureComponent<Pickupable>()
             *  : newCreature.GetComponent<Pickupable>();
             *
             * newCreature.setActive();*/

            pickupable = pickupable.Pickup(false);

            // pickupable.GetComponent<WaterParkItem>()?.SetWaterPark(null);

            var itemToAdd = new InventoryItem(pickupable);

            var reactorItemsContainer = Traverse
                                        .Create(suitableReactor)
                                        .Property("container")
                                        .GetValue <ItemsContainer>();

            if (reactorItemsContainer == null)
            {
                FishOverflowDistributor.Logger.LogError(
                    $"PropertyInfo or value for property 'container' in class 'BaseBioReactor' with type 'ItemsContainer' was null -> Should not happen, investigate!.");

                return(false);
            }

            reactorItemsContainer.AddItem(pickupable);

            return(false);
        }
Beispiel #25
0
 public static void AddDiveSuit(TechType diveSuit, float depth, float breathMultiplier = 1f, float minTempBonus = 0f)
 {
     Logger.Log(Logger.Level.Info, $"Received AddDiveSuit call with Dive Suit {diveSuit.ToString()}, depth {depth}, breathMultiplier {breathMultiplier} and minTempBonus {minTempBonus}");
     if (diveSuitDepths.TryGetValue(diveSuit, out float value)) // We don't actually care about the value here, just whether it exists
     {
         Logger.Log(Logger.Level.Error, $"Received duplicated AddDiveSuit call for TechType {diveSuit.ToString()}");
         return;
     }
     diveSuitDepths.Add(diveSuit, depth);
     if (minTempBonus > 0)
     {
         diveSuitMinTemps.Add(diveSuit, minTempBonus);
     }
     if (breathMultiplier != 1f)
     {
         diveSuitBreathModifiers.Add(diveSuit, breathMultiplier);
     }
 }
Beispiel #26
0
 /// <summary>
 /// Loads a custom item
 /// </summary>
 /// <param name="name">Item's internal name</param>
 /// <param name="languageName">Item's display name</param>
 /// <param name="languageTooltip">Item's tooltip</param>
 /// <param name="from">Item's ingredient</param>
 /// <param name="fromstring">Item's ingredient's name</param>
 /// <param name="inassetbundles">What assetbundle the sprite of the item is in</param>
 /// <param name="assetPath">The name of the sprite</param>
 /// <param name="alt_assetPath">The name of the alternative sprite</param>
 public static void Custom(string name, string languageName, string languageTooltip, TechType from, string alt_assetPath, string assetPath, InAssetBundles inassetbundles = InAssetBundles.All)
 {
     try
     {
         var _x              = 1;
         var _y              = 1;
         var _a              = 10;
         var _e              = true;
         var Config          = MI.Config.cfgfile;
         var moreingots      = Load.moreingots;
         var ingotsplus      = Load.ingotsplus;
         var moreingots_salt = Load.moreingots_salt;
         var ingotsplus_salt = Load.ingotsplus_salt;
         var fromstring      = from.ToString();
         Config.TryGet(ref _x, languageName, "Size", "x");
         Config.TryGet(ref _y, languageName, "Size", "y");
         Config.TryGet(ref _a, languageName, "Craft amount");
         Config.TryGet(ref _e, languageName, "Enabled");
         Log.Debug(languageName, Status.Start);
         if (_e == false)
         {
             Log.Debug(languageName, "Item is disabled");
             return;
         }
         Log.Debug(languageName, "Checking config data for errors... (0/6)");
         if (_x <= 0)
         {
             _x = 1;
             Config[languageName, "Size", "x"] = _x;
             Log.Warning(languageName, "X can't be less than 1");
             Log.Info(languageName, "X was set to 1");
         }
         Log.Debug(languageName, "Checking config data for errors... (1/6)");
         if (_x > 6)
         {
             _x = 1;
             Config[languageName, "Size", "x"] = _x;
             Log.Warning(languageName, "X can't be greater than 6");
             Log.Info(languageName, "X was set to 1");
         }
         Log.Debug(languageName, "Checking config data for errors... (2/6)");
         if (_y <= 0)
         {
             _y = 1;
             Config[languageName, "Size", "y"] = _y;
             Log.Warning(languageName, "Y can't be less than 1");
             Log.Info(languageName, "Y was set to 1");
         }
         Log.Debug(languageName, "Checking config data for errors... (3/6)");
         if (_y > 8)
         {
             _y = 1;
             Config[languageName, "Size", "y"] = _y;
             Log.Warning(languageName, "Y can't be greater than 8");
             Log.Info(languageName, "Y was set to 1");
         }
         Log.Debug(languageName, "Checking config data for errors... (4/6)");
         if (_a <= 0)
         {
             _a = 10;
             Config[languageName, "Craft amount"] = _a;
             Log.Warning(languageName, "Craft amount can't be less than 1");
             Log.Info(languageName, "Craft amount was set to 10");
         }
         Log.Debug(languageName, "Checking config data for errors... (5/6)");
         if (_a > 10)
         {
             _a = 10;
             Config[languageName, "Craft amount"] = _a;
             Log.Warning(languageName, "Craft amount can't be greater than 10");
             Log.Info(languageName, "Craft amount was set to 10");
         }
         Log.Debug(languageName, "Checking config data for errors... (6/6)");
         Log.Debug(languageName, "Error check complete");
         MI.Config.Save(languageName);
         Log.Debug(languageName, "Adding TechType...");
         var techType = TechTypePatcher.AddTechType(name, languageName, languageTooltip);
         Log.Debug(languageName, "TechType added");
         Log.Debug(languageName, "Loading TechDatas... (0/2)");
         var techData = new TechDataHelper
         {
             _craftAmount = 1,
             _ingredients = new List <IngredientHelper>()
             {
                 new IngredientHelper(from, _a)
             },
             _techType = techType
         };
         Log.Debug(languageName, "Loading TechDatas... (1/2)");
         var techDataB = new TechDataHelper
         {
             _craftAmount = _a,
             _ingredients = new List <IngredientHelper>()
             {
                 new IngredientHelper(techType, 1)
             },
             _techType = from
         };
         Log.Debug(languageName, "Loading TechDatas... (2/2)");
         Log.Debug(languageName, "TechDatas loaded");
         Log.Debug(languageName, "Adding unlock on start for " + from + "...");
         KnownTechPatcher.unlockedAtStart.Add(from);
         Log.Debug(languageName, "Unlock on start added for " + from);
         Log.Debug(languageName, "Adding TechTypes to the PDA Databank... (0/2)");
         CraftDataPatcher.AddToCustomGroup(TechGroup.Resources, TechCategory.BasicMaterials, techType);
         Log.Debug(languageName, "Adding TechTypes to the PDA Databank... (1/2)");
         CraftDataPatcher.AddToCustomGroup(TechGroup.Resources, TechCategory.BasicMaterials, from);
         Log.Debug(languageName, "Adding TechTypes to the PDA Databank... (2/2)");
         Log.Debug(languageName, "TechTypes added to the PDA Databank");
         Log.Debug(languageName, "Linking TechDatas with TechTypes... (0/2)");
         CraftDataPatcher.customTechData.Add(techType, techData);
         Log.Debug(languageName, "Linking TechDatas with TechTypes... (1/2)");
         CraftDataPatcher.customTechData.Add(from, techDataB);
         Log.Debug(languageName, "Linking TechDatas with TechTypes... (2/2)");
         Log.Debug(languageName, "TechDatas linked with TechTypes");
         Log.Debug(languageName, "Adding Fabricator nodes... (0/2)");
         CraftTreePatcher.customNodes.Add(new CustomCraftNode(techType, CraftScheme.Fabricator, "Resources/Craft/" + name));
         Log.Debug(languageName, "Adding Fabricator nodes... (1/2)");
         CraftTreePatcher.customNodes.Add(new CustomCraftNode(from, CraftScheme.Fabricator, "Resources/Unpack/" + fromstring));
         Log.Debug(languageName, "Adding Fabricator nodes... (2/2)");
         Log.Debug(languageName, "Fabricator nodes added");
         Log.Debug(languageName, "Applying item sizes...");
         CraftDataPatcher.customItemSizes[key : techType] = new Vector2int(_x, _y);
         Log.Debug(languageName, "Item sizes applied");
         Log.Debug(languageName, "Starting sprite loading...");
         if (inassetbundles == InAssetBundles.All)
         {
             if (MI.Config._alttextures)
             {
                 Log.Debug(languageName, "Asset bundle \"moreingots\" selected");
                 Log.Debug(languageName, "Obtaining sprite...");
                 if (moreingots.LoadAsset <Sprite>(alt_assetPath) == null)
                 {
                     Log.Error(languageName, "Sprite is null");
                     Log.Debug(languageName, Status.Stop);
                     return;
                 }
                 var alt_sprite = moreingots.LoadAsset <Sprite>(alt_assetPath);
                 Log.Debug(languageName, "Sprite obtained");
                 Log.Debug(languageName, "Applying sprite...");
                 CustomSpriteHandler.customSprites.Add(new CustomSprite(techType, alt_sprite));
                 Log.Debug(languageName, "Sprite applied");
             }
             else
             {
                 Log.Debug(languageName, "Asset bundle \"yenzen-ingotsplus\" selected");
                 Log.Debug(languageName, "Obtaining sprite...");
                 if (ingotsplus.LoadAsset <Sprite>(assetPath) == null)
                 {
                     Log.Error(languageName, "Sprite is null");
                     Log.Debug(languageName, Status.Stop);
                     return;
                 }
                 var sprite = ingotsplus.LoadAsset <Sprite>(assetPath);
                 Log.Debug(languageName, "Sprite obtained");
                 Log.Debug(languageName, "Applying sprite...");
                 CustomSpriteHandler.customSprites.Add(new CustomSprite(techType, sprite));
                 Log.Debug(languageName, "Sprite applied");
             }
         }
         if (inassetbundles == InAssetBundles.Salt)
         {
             if (MI.Config._alttextures)
             {
                 Log.Debug(languageName, "Asset bundle \"salt-alexejheroytb\" selected");
                 Log.Debug(languageName, "Obtaining sprite...");
                 if (moreingots_salt.LoadAsset <Sprite>(alt_assetPath) == null)
                 {
                     Log.Error(languageName, "Sprite is null");
                     Log.Debug(languageName, Status.Stop);
                     return;
                 }
                 var alt_sprite = moreingots_salt.LoadAsset <Sprite>(alt_assetPath);
                 Log.Debug(languageName, "Sprite obtained");
                 Log.Debug(languageName, "Applying sprite...");
                 CustomSpriteHandler.customSprites.Add(new CustomSprite(techType, alt_sprite));
                 Log.Debug(languageName, "Sprite applied");
             }
             else
             {
                 Log.Debug(languageName, "Asset bundle \"salt-yenzen\" selected");
                 Log.Debug(languageName, "Obtaining sprite...");
                 if (ingotsplus_salt.LoadAsset <Sprite>(assetPath) == null)
                 {
                     Log.Error(languageName, "Sprite is null");
                     Log.Debug(languageName, Status.Stop);
                     return;
                 }
                 var sprite = ingotsplus_salt.LoadAsset <Sprite>(assetPath);
                 Log.Debug(languageName, "Sprite obtained");
                 Log.Debug(languageName, "Applying sprite...");
                 CustomSpriteHandler.customSprites.Add(new CustomSprite(techType, sprite));
                 Log.Debug(languageName, "Sprite applied");
             }
         }
         if (inassetbundles == InAssetBundles.Sulphur)
         {
             Log.Debug(languageName, "Asset bundle \"sulphur\" selected");
             Log.Debug(languageName, "Obtaining sprite...");
             if (sulphur.LoadAsset <Sprite>(assetPath) == null)
             {
                 Log.Error(languageName, "Sprite is null");
                 Log.Debug(languageName, Status.Stop);
                 return;
             }
             var s_sprite = sulphur.LoadAsset <Sprite>(assetPath);
             Log.Debug(languageName, "Sprite obtained");
             Log.Debug(languageName, "Applying sprite...");
             CustomSpriteHandler.customSprites.Add(new CustomSprite(techType, s_sprite));
             Log.Debug(languageName, "Sprite applied");
         }
         Log.Debug(languageName, Status.Stop);
     }
     catch (Exception e)
     {
         Log.e(e);
     }
 }
 public static bool IsLeviathan(this TechType techType)
 {
     return(techType.ToString().Contains("Leviathan"));
 }
        public void AddNewTechObject(TechType techType)
        {
            SetDirty(true);

            GameObject newChild = null;

            OutputWindow_Log(MESSAGE_TEXT[MESSAGES.TRY_TO_ADD_A_TECH_OBJECT], (int)techType, techType.ToString());

            try
            {
                newChild = Instantiate(CraftData.GetPrefabForTechType(techType), Vector3.zero, Quaternion.Euler(Vector3.zero));
            }
            catch
            {
                OutputWindow_Log(WARNING_TEXT[WARNINGS.OBJECT_CANNOT_INSTANTIATE], LogType.Error, (int)techType, techType.ToString());
                SetDirty(false);
                return;
            }

            ReleaseObjectDrawing();

            newChild.transform.SetParent(baseObject.transform, false);
            newChild.transform.SetLocalsToZero();
            string objectName = newChild.name;

            newChild.name = "newChild_" + objectName;

            foreach (Component component in newChild.GetComponents <Component>())
            {
                Type componentType = component.GetType();

                bool isValid = false;

                foreach (Type type in ValidTypes)
                {
                    if (componentType == type)
                    {
                        isValid = true;
                        break;
                    }
                }

                if (isValid)
                {
                    if (componentType == typeof(Locomotion))
                    {
                        ((Locomotion)component).enabled = false;
                        OutputWindow_Log(MESSAGE_TEXT[MESSAGES.COMPONENT_STATE_MODIFIED], LogType.Warning, GetComponentShortType(component), "False");
                    }
                    if (componentType == typeof(SplineFollowing))
                    {
                        ((SplineFollowing)component).enabled = false;
                        OutputWindow_Log(MESSAGE_TEXT[MESSAGES.COMPONENT_STATE_MODIFIED], LogType.Warning, GetComponentShortType(component), "False");
                    }
                    if (componentType == typeof(SwimBehaviour))
                    {
                        ((SwimBehaviour)component).enabled = false;
                        OutputWindow_Log(MESSAGE_TEXT[MESSAGES.COMPONENT_STATE_MODIFIED], LogType.Warning, GetComponentShortType(component), "False");
                    }
                    if (componentType == typeof(LiveMixin))
                    {
                        ((LiveMixin)component).enabled = false;
                        OutputWindow_Log(MESSAGE_TEXT[MESSAGES.COMPONENT_STATE_MODIFIED], LogType.Warning, GetComponentShortType(component), "False");
                    }
                    continue;
                }
                else
                {
                    try
                    {
                        DestroyImmediate(component);
                        OutputWindow_Log(MESSAGE_TEXT[MESSAGES.COMPONENT_REMOVED], LogType.Warning, GetComponentShortType(component), newChild.name);
                    }
                    catch
                    {
                        OutputWindow_Log(MESSAGE_TEXT[MESSAGES.COMPONENT_CANNOT_REMOVED], LogType.Error, GetComponentShortType(component), newChild.name);
                    }
                }
            }

            RefreshTransformsList();
            OnObjectChange(newChild);

            OutputWindow_Log(MESSAGE_TEXT[MESSAGES.NEW_TECH_OBJECT_ADDED], newChild.name, newChild.transform.parent.name, newChild.transform.root.name);
        }
Beispiel #29
0
 public static NitroxModel.DataStructures.GameLogic.NitroxTechType ToDto(this TechType v)
 {
     return(new NitroxModel.DataStructures.GameLogic.NitroxTechType(v.ToString()));
 }
        public static GameObject GetPrefabForTechTypePatch(GameObject __result, TechType techType, bool verbose = true)
        {
            Logger.Log(Logger.Level.Debug, $"GetPrefabForTechTypePatch running: TechType {techType.ToString()}");
            if (Main.config.NewScannables.Contains(techType))
            {
                Logger.Log(Logger.Level.Debug, $"Found TechType in NewScannables list");
                if (__result.GetComponent <ResourceTracker>() == null)
                {
                    Logger.Log(Logger.Level.Debug, $"No existing ResourceTracker found");
                    ResourceTracker rt = __result.EnsureComponent <ResourceTracker>();
                    if (rt != null)
                    {
                        Logger.Log(Logger.Level.Debug, $"Added new ResourceTracker");
                        rt = __result.EnsureComponent <ResourceTracker>();
                        rt.prefabIdentifier = __result.GetComponent <PrefabIdentifier>();
                        rt.techType         = TechType.SeaDragon;
                        rt.overrideTechType = TechType.SeaDragon;
                        rt.rb         = __result.GetComponent <Rigidbody>();
                        rt.pickupable = __result.GetComponent <Pickupable>();
                    }
                }
            }
            else if (Main.config.NonScannables.Contains(techType))
            {
                Logger.Log(Logger.Level.Debug, $"Found TechType in NonScannables list");
                ResourceTracker rt = __result.GetComponent <ResourceTracker>();
                if (rt != null)
                {
                    Logger.Log(Logger.Level.Debug, $"Attempting to destroy existing ResourceTracker");
                    UnityEngine.Object.Destroy(rt);
                }
                else
                {
                    Logger.Log(Logger.Level.Debug, $"No ResourceTracker found in prefab");
                }
            }

            return(__result);
        }